两者之间有什么区别吗?如果有的话,首选哪一种?
并不真地;这取决于您使用的 PKI 配置文件。 PKI 和 X509 是狂野的、狂野的、西方的。
如果您在组织内部运行私有 PKI,那么如何操作并不重要。选择某件事并坚持不懈地去做。
在网络上通常是 PKIX 并在 RFC 5280 中指定,互联网 X.509 公钥基础设施证书和证书吊销列表 (CRL) 配置文件。根据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:[email protected]
or email:[email protected]
。就像我说的,这是狂野的西部。你应该为任何事情做好准备。
您还可以使用 CA/浏览器论坛及其颁发证书的标准。感兴趣的两个文件是:
但他们还是遵循 RFC 5280。
The rfc822:
and 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
handy).
在上面,注意类型: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:
or email:
因为它遇到了一个类型GEN_EMAIL
.
当您查看 OpenSSL 的配置文件时,您将看到,例如:
...
[ v3_ca ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer:always
subjectAltName = email:[email protected]
issuerAltName = issuer:copy
The email:
is not逐字复制到 SAN 中。相反,它告诉 OpenSSL 使用GEN_EMAIL
为该字段键入。
如果您的证书查看器或演示软件是not添加前缀,那么它可能会解析一个杰出的名字。
至于专有名称中的内容,Peter Gutmann 很久以前告诉我(摘自他的电子邮件):“在 DN 中粘贴您想要的任何内容,并仅显示有用的部分”。就像我说的,这是狂野的西部。
电子邮件地址也可能显示在 OID 下。例如,1.2.840.113549.1.9.1弧线。这是对 SAN 的补充。这就是为什么下图带有“电子邮件地址”标签的原因。
彼得·古特曼有一个X509 风格指南。取自他的描述:它描述了各种 X.509 证书实现细节和陷阱,提供了有关该做什么和不该做什么的建议,并以在现有实现中需要注意的已知错误和问题列表作为结束。
最后,这是Startcom颁发的用户证书。他们提供免费证书,并在需要时向您收取撤销费用(因为这就是成本所在)。这与其他 CA 完全相反,其他 CA 预先收取撤销费用,如果不需要则将其收入囊中;)
首先是X509证书:
![enter image description here](https://i.stack.imgur.com/yNwSg.png)
第二个是使用 Gutmann 转储证书dumpasn1
(从 www.cs.auckland.ac.nz/~pgut001 获取 dumpasn1.c 和 dumpasn1.cfg;使用以下命令进行编译gcc dumpasn1.c -o dumpasn1
;并复制到/usr/local/bin
)。注意没有rfc822:
or email:
prefix:
![enter image description here](https://i.stack.imgur.com/wYIPk.png)