两者有什么区别,如果有,首选哪一个?
不是真的;这取决于您使用的 PKI 配置文件。 PKI 和 X509 是狂野的、狂野的、西部的。
如果您在组织内部运行私有 PKI,那么如何操作并不重要。选择一些东西并始终如一地去做。
在网络上,它通常是 PKIX,并在 RFC 5280,Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile 中指定。根据 4.1.2.6,主题:
Conforming implementations generating new certificates with
electronic mail addresses MUST use the rfc822Name in the subject
alternative name extension (Section 4.2.1.6) to describe such
identities. Simultaneous inclusion of the emailAddress attribute in
the subject distinguished name to support legacy implementations is
deprecated but permitted.
然后是第 4.2.1.6 节,主题备用名称:
When the subjectAltName extension contains an Internet mail address,
the address MUST be stored in the rfc822Name. The format of an
rfc822Name is a "Mailbox" as defined in Section 4.1.2 of [RFC2821].
A Mailbox has the form "Local-part@Domain". Note that a Mailbox has
no phrase (such as a common name) before it, has no comment (text
surrounded in parentheses) after it, and is not surrounded by "<" and
">".
请注意,它不使用rfc822:user@domain.test 或email:user@domain.test。就像我说的,它是狂野的西部。你应该为任何事情做好准备。
您还拥有 CA/浏览器论坛及其颁发证书的标准。感兴趣的两个文件是:
但他们推迟到 RFC 5280。
您看到的rfc822: 和email: 可能是由软件添加用于演示的。例如,要使用 OpenSSL 枚举 SAN,您的函数看起来类似于:
void print_san_name(X509* const cert)
{
int success = 0;
GENERAL_NAMES* names = NULL;
unsigned char* utf8 = NULL;
do
{
if(!cert) break; /* failed */
names = X509_get_ext_d2i(cert, NID_subject_alt_name, 0, 0 );
if(!names) break;
int i = 0, count = sk_GENERAL_NAME_num(names);
if(!count) break; /* failed */
for( i = 0; i < count; ++i )
{
GENERAL_NAME* entry = sk_GENERAL_NAME_value(names, i);
if(!entry) continue;
if(GEN_DNS == entry->type)
{
int len1 = 0, len2 = -1;
len1 = ASN1_STRING_to_UTF8(&utf8, entry->d.dNSName);
if(utf8) {
len2 = (int)strlen((const char*)utf8);
}
if(len1 != len2) {
fprintf(stderr, "Strlen and ASN1_STRING size do not match (embedded null?):"
" %d vs %d\n", len2, len1);
/* Handle error */
}
/* Do something with utf8 */
if(utf8) {
OPENSSL_free(utf8), utf8 = NULL;
}
}
else if(GEN_EMAIL == entry->type)
{
...
}
...
}
} while (0);
if(names)
GENERAL_NAMES_free(names);
if(utf8)
OPENSSL_free(utf8);
}
(对不起,我没有一个提取IA5Strings方便的例子)。
在上面,请注意类型:GEN_DNS 或通用 DNS 名称。这用于www.example.com 之类的名称。 OpenSSL 有其中一些类型,以下来自x509v3.h:
#define GEN_OTHERNAME 0
#define GEN_EMAIL 1
#define GEN_DNS 2
#define GEN_X400 3
#define GEN_DIRNAME 4
#define GEN_EDIPARTY 5
#define GEN_URI 6
#define GEN_IPADD 7
#define GEN_RID 8
您的证书查看器或演示软件可能显示rfc822: 或email:,因为它遇到了GEN_EMAIL 类型。
当你查看 OpenSSL 的配置文件时,你会看到,例如:
...
[ v3_ca ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer:always
subjectAltName = email:myEmail@email.com
issuerAltName = issuer:copy
email:不是逐字复制到 SAN 中。相反,它告诉 OpenSSL 对该字段使用 GEN_EMAIL 类型。
如果您的证书查看器或演示软件没有添加前缀,那么它可能会解析一个 Distinguished Named。
至于专有名称中的内容,Peter Gutmann 很久以前告诉我(摘自他的电子邮件):“在 DN 中添加您想要的任何内容,只显示有用的部分”。就像我说的,这里是狂野的西部。
电子邮件地址也可能显示在 OID 下。例如,1.2.840.113549.1.9.1 arc。这是对 SAN 的补充。这就是为什么下面的图片有标签“电子邮件地址”的原因。
Peter Gutmann 有一个X509 Style Guide。摘自他的描述:它描述了各种 X.509 证书实现细节和陷阱,提供了关于做什么和不做什么的建议,最后列出了在现有实现中需要注意的已知错误和问题列表。
最后,这是由 Startcom 颁发的用户证书。他们提供免费证书,并在需要时向您收取撤销费用(因为这是成本所在)。这与其他 CA 截然相反,他们预先收取撤销费用并在不需要时将其放入口袋;)
首先是X509证书:
其次是使用 Gutmann 的 dumpasn1 转储证书(从 www.cs.auckland.ac.nz/~pgut001 获取 dumpasn1.c 和 dumpasn1.cfg;使用 gcc dumpasn1.c -o dumpasn1 编译;并复制到 @987654348 @)。注意没有rfc822: 或email: 前缀: