Go to the documentation of this file.
60 #include <gtest/gtest.h>
67 #include "../internal.h"
71 static const char *
const names[] = {
72 "a",
"b",
".",
"*",
"@",
73 ".a",
"a.",
".b",
"b.",
".*",
"*.",
"*@",
"@*",
"a@",
"@a",
"b@",
"..",
74 "-example.com",
"example-.com",
75 "@@",
"**",
"*.com",
"*com",
"*.*.com",
"*com",
"com*",
"*example.com",
76 "*@example.com",
"test@*.example.com",
"example.com",
"www.example.com",
77 "test.www.example.com",
"*.example.com",
"*.www.example.com",
78 "test.*.example.com",
"www.*.com",
79 ".www.example.com",
"*www.example.com",
80 "example.net",
"xn--rger-koa.example.com",
81 "*.xn--rger-koa.example.com",
"www.xn--rger-koa.example.com",
82 "*.good--example.com",
"www.good--example.com",
83 "*.xn--bar.com",
"xn--foo.xn--bar.com",
84 "a.example.com",
"b.example.com",
85 "postmaster@example.com",
"Postmaster@example.com",
86 "postmaster@EXAMPLE.COM",
91 "set CN: host: [*.example.com] matches [a.example.com]",
92 "set CN: host: [*.example.com] matches [b.example.com]",
93 "set CN: host: [*.example.com] matches [www.example.com]",
94 "set CN: host: [*.example.com] matches [xn--rger-koa.example.com]",
95 "set CN: host: [*.www.example.com] matches [test.www.example.com]",
96 "set CN: host: [*.www.example.com] matches [.www.example.com]",
97 "set CN: host: [*www.example.com] matches [www.example.com]",
98 "set CN: host: [test.www.example.com] matches [.www.example.com]",
99 "set CN: host: [*.xn--rger-koa.example.com] matches [www.xn--rger-koa.example.com]",
100 "set CN: host: [*.xn--bar.com] matches [xn--foo.xn--bar.com]",
101 "set CN: host: [*.good--example.com] matches [www.good--example.com]",
102 "set CN: host-no-wildcards: [*.www.example.com] matches [.www.example.com]",
103 "set CN: host-no-wildcards: [test.www.example.com] matches [.www.example.com]",
104 "set emailAddress: email: [postmaster@example.com] does not match [Postmaster@example.com]",
105 "set emailAddress: email: [postmaster@EXAMPLE.COM] does not match [Postmaster@example.com]",
106 "set emailAddress: email: [Postmaster@example.com] does not match [postmaster@example.com]",
107 "set emailAddress: email: [Postmaster@example.com] does not match [postmaster@EXAMPLE.COM]",
108 "set dnsName: host: [*.example.com] matches [www.example.com]",
109 "set dnsName: host: [*.example.com] matches [a.example.com]",
110 "set dnsName: host: [*.example.com] matches [b.example.com]",
111 "set dnsName: host: [*.example.com] matches [xn--rger-koa.example.com]",
112 "set dnsName: host: [*.www.example.com] matches [test.www.example.com]",
113 "set dnsName: host-no-wildcards: [*.www.example.com] matches [.www.example.com]",
114 "set dnsName: host-no-wildcards: [test.www.example.com] matches [.www.example.com]",
115 "set dnsName: host: [*.www.example.com] matches [.www.example.com]",
116 "set dnsName: host: [*www.example.com] matches [www.example.com]",
117 "set dnsName: host: [test.www.example.com] matches [.www.example.com]",
118 "set dnsName: host: [*.xn--rger-koa.example.com] matches [www.xn--rger-koa.example.com]",
119 "set dnsName: host: [*.xn--bar.com] matches [xn--foo.xn--bar.com]",
120 "set dnsName: host: [*.good--example.com] matches [www.good--example.com]",
121 "set rfc822Name: email: [postmaster@example.com] does not match [Postmaster@example.com]",
122 "set rfc822Name: email: [Postmaster@example.com] does not match [postmaster@example.com]",
123 "set rfc822Name: email: [Postmaster@example.com] does not match [postmaster@EXAMPLE.COM]",
124 "set rfc822Name: email: [postmaster@EXAMPLE.COM] does not match [Postmaster@example.com]",
130 const char *
const *
p;
132 if (strcmp(
msg, *
p) == 0)
149 nid = va_arg(ap,
int);
152 name = va_arg(ap,
const char *);
154 (
unsigned char *)
name, -1, -1, 1))
176 GENERAL_NAMES *gens = NULL;
181 gens = sk_GENERAL_NAME_new_null();
187 type = va_arg(ap,
int);
190 name = va_arg(ap,
const char *);
209 sk_GENERAL_NAME_push(gens,
gen);
320 const char *nameincert,
int match,
const char *
name)
326 fn->name,
op, nameincert,
327 match ?
"matches" :
"does not match",
name);
337 const char *
const *pname =
names;
340 size_t namelen = strlen(*pname);
341 char *
name = (
char *)malloc(namelen);
348 fprintf(
stderr,
"internal error in X509_check_host\n");
350 }
else if (
fn->host) {
351 if (
ret == 1 && !samename)
353 if (
ret == 0 && samename)
363 fprintf(
stderr,
"internal error in X509_check_host\n");
365 }
else if (
fn->host) {
366 if (
ret == 1 && !samename)
368 if (
ret == 0 && samename)
377 if (
ret && !samename)
379 if (!
ret && samename && strchr(nameincert,
'@') != NULL)
393 const char *
const *pname =
names;
397 if (strcmp(pfn->
name,
"set CN") == 0 &&
399 reinterpret_cast<const unsigned char*
>(*pname),
#define NID_pkcs9_emailAddress
static int set_cn1(X509 *crt, const char *name)
OPENSSL_EXPORT void ASN1_IA5STRING_free(ASN1_IA5STRING *str)
static int set_cn(X509 *crt,...)
TEST(X509V3Test, NameTest)
#define X509_NAME_add_entry_by_NID
unsigned char match[65280+2]
static int set_altname(X509 *crt,...)
#define X509_set_subject_name
static int set_cn3(X509 *crt, const char *name)
static const char *const names[]
static const char *const exceptions[]
#define x509v3_looks_like_dns_name
static int set_email_and_cn(X509 *crt, const char *name)
static void run_cert(X509 *crt, const char *nameincert, const struct set_name_fn *fn)
static void check_message(const struct set_name_fn *fn, const char *op, const char *nameincert, int match, const char *name)
static const struct set_name_fn name_fns[]
OPENSSL_EXPORT void GENERAL_NAME_set0_value(GENERAL_NAME *a, int type, void *value)
static void * OPENSSL_memcpy(void *dst, const void *src, size_t n)
int(* fn)(X509 *, const char *)
OPENSSL_EXPORT GENERAL_NAME * gen
#define GENERAL_NAMES_free
#define GENERAL_NAME_free
static int set_email1(X509 *crt, const char *name)
static int set_email3(X509 *crt, const char *name)
UniquePtr< SSL_SESSION > ret
#define OPENSSL_strcasecmp
static int set_email2(X509 *crt, const char *name)
#define ASSERT_TRUE(condition)
static int set_cn_and_email(X509 *crt, const char *name)
#define NID_subject_alt_name
static int set_altname_email(X509 *crt, const char *name)
#define X509_CHECK_FLAG_NO_WILDCARDS
#define X509_add1_ext_i2d
static int is_exception(const char *msg)
static int set_altname_dns(X509 *crt, const char *name)
OPENSSL_EXPORT ASN1_IA5STRING * ASN1_IA5STRING_new(void)
static int set_cn2(X509 *crt, const char *name)
static X509 * make_cert(void)
grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:50