如何为使用OpenSSL生成的证书提供多行证书名称(CN) [英] How to give a multiline certificate name (CN) for a certificate generated using OpenSSL

查看:83
本文介绍了如何为使用OpenSSL生成的证书提供多行证书名称(CN)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照以下步骤使用OpenSSL生成自签名证书:

I am generating a self-signed certificate using OpenSSL following the steps here Create PKCS#12 file with self-signed certificate via OpenSSL in Windows for my Android App.

openssl req -x509 -days 365 -subj"/CN =此处需要多行" -newkeyrsa:1024 -keyout mycert.pem -out mycert.pem

openssl req -x509 -days 365 -subj "/CN=MULTI LINE NEEDED HERE" -newkey rsa:1024 -keyout mycert.pem -out mycert.pem

在这里,主题由诸如国家,州等的cmd提示填充.我希望为CN属性提供多行值.如何在命令行中做到这一点?

Here the subject is populated by the prompts by cmd like Country, State etc. I wish to give a multiple line value for CN attribute. How do I do that in command line?

推荐答案

...当我想要多个域名时该怎么办?例如www.google.com和www.yahoo.com?

... what about the case when I want multiple domain names? like www.google.com and www.yahoo.com?

以下是向证书添加多个DNS名称的方法.您必须通过主题备用名称(SAN)添加它们.

Here's how to add multiple DNS names to a certificate. You have to add them through Subject Alternate Names (SAN).

根据您的情况,在 alternate_names 部分下添加 www.google.com www.yahoo.com .

In your case, add www.google.com and www.yahoo.com under the section alternate_names.

(我不确定这是答案还是评论.我仍然不清楚您是否想通过添加 CRLF Common Name ;或者如果您只想向证书添加多个DNS名称).

(I'm not sure if this is an answer or a comment. I'm still not clear if you want to attempt to break PKI things by adding the CRLF to the Common Name; or if you only want to add multiple DNS names to a certificate).

第一

$ touch example-com.conf

第二

将以下内容添加到配置文件中.调整它以适合您的口味.

Add the following to the configuration file. Tune it to suit your taste.

[ req ]
default_bits        = 2048
default_keyfile     = server-key.pem
distinguished_name  = subject
req_extensions      = extensions
x509_extensions     = extensions
string_mask         = utf8only

[ subject ]
countryName         = Country Name (2 letter code)
countryName_default     = US

stateOrProvinceName     = State or Province Name (full name)
stateOrProvinceName_default = NY

localityName            = Locality Name (eg, city)
localityName_default        = New York

organizationName         = Organization Name (eg, company)
organizationName_default    = Example, LLC

commonName          = Common Name (e.g. server FQDN or YOUR name)
commonName_default      = Example, LLC

emailAddress            = Email Address
emailAddress_default        = test@example.com

[ extensions ]

subjectKeyIdentifier        = hash
authorityKeyIdentifier  = keyid,issuer

basicConstraints        = CA:FALSE
keyUsage            = nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage    = serverAuth
subjectAltName          = @alternate_names
nsComment           = "OpenSSL Generated Certificate"

[ alternate_names ]

DNS.1       = example.com
DNS.2       = www.example.com
DNS.3       = mail.example.com
DNS.4       = ftp.example.com

第三

使用以下命令生成证书.它为每个请求生成一个新密钥.调整它以适合您的口味.例如,如果省略 -x509 ,则会获得CSR而不是证书.

Generate the certificate with the following. It generates a new key with each request. Tune it to suit your taste. For example, if you omit -x509 you get a CSR rather than a certificate.

$ openssl req -config example-com.conf -new -x509 -newkey rsa:2048 -nodes \
        -keyout example-com.key.pem -days 365 -out example-com.cert.pem

第四

使用以下内容检查证书.

Examine the certificate with the following.

$ openssl x509 -in example-com.cert.pem -text -noout

您将在SAN中看到多个DNS名称.

You will see the multiple DNS names in the SAN.

$ openssl x509 -in example-com.cert.pem -text -noout
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: 15695764655789201623 (0xd9d28ecb727258d7)
    Signature Algorithm: sha1WithRSAEncryption
        Issuer: C=US, ST=NY, L=New York, CN=Example, LLC/emailAddress=test@example.com
        Validity
            Not Before: May 10 22:34:14 2014 GMT
            Not After : May 10 22:34:14 2015 GMT
        Subject: C=US, ST=NY, L=New York, CN=Example, LLC/emailAddress=test@example.com
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:
                    00:9a:a4:93:67:26:79:6f:dd:9a:25:0a:11:66:f6:
                    5a:04:36:66:5f:46:fd:b3:ee:08:ac:e4:92:88:12:
                    92:ea:ec:9b:62:6c:5d:ec:8c:4f:c6:0c:e9:99:c4:
                    77:70:3e:52:fc:25:9d:74:56:2d:49:08:9c:8f:b3:
                    82:ea:9e:b2:60:52:69:59:7f:c8:14:15:74:ef:f6:
                    80:6c:7f:1d:b4:b8:55:89:7f:d7:e4:0a:94:9e:3f:
                    fe:b6:64:fa:7a:9a:f6:43:46:53:f2:e3:b0:8f:92:
                    ca:83:6d:00:1d:57:9a:73:b9:f9:14:11:2b:fc:2d:
                    36:b5:ed:95:73:c3:28:7d:4b:86:97:88:85:cd:d6:
                    32:b7:e3:db:ea:3b:9a:7c:5a:c9:b0:6b:38:ac:e4:
                    44:e6:95:57:6a:f0:05:7a:5c:86:e0:46:4a:83:b2:
                    78:59:38:42:9c:84:c6:8b:ee:04:cc:8b:e5:29:3a:
                    45:6f:0e:8c:cd:6e:35:e9:f8:f7:fb:f2:a5:8a:e2:
                    53:77:b2:59:33:64:9a:1d:98:d6:4e:2d:e6:73:cb:
                    18:fc:86:4f:e7:bf:3b:14:79:92:32:e0:63:40:d3:
                    16:b6:33:f6:42:fc:59:6c:a4:8c:ed:86:68:3e:14:
                    64:da:16:66:85:42:ef:73:8a:c1:f9:6f:a2:b0:92:
                    d0:fb
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Subject Key Identifier: 
                B5:CE:04:1D:D9:10:85:FF:2E:FD:AA:AA:CB:36:7A:1E:14:66:69:EA
            X509v3 Authority Key Identifier: 
                keyid:B5:CE:04:1D:D9:10:85:FF:2E:FD:AA:AA:CB:36:7A:1E:14:66:69:EA
            X509v3 Basic Constraints: 
                CA:FALSE
            X509v3 Key Usage: 
                Digital Signature, Non Repudiation, Key Encipherment
            X509v3 Extended Key Usage: 
                TLS Web Server Authentication
            X509v3 Subject Alternative Name: 
                DNS:example.com, DNS:www.example.com, DNS:mail.example.com, DNS:ftp.example.com
            Netscape Comment: 
                OpenSSL Generated Certificate
    Signature Algorithm: sha1WithRSAEncryption
         32:a0:28:21:8b:a8:46:d5:89:5e:10:b7:b6:35:cb:a8:2e:4a:
         a4:10:3d:4c:1d:3f:8a:b2:7d:2e:53:e5:4f:b5:c7:9c:14:84:
         ad:11:51:01:f2:41:80:6e:23:10:ed:d6:cc:38:48:15:ff:d8:
         17:6c:09:b0:1e:b7:ed:c0:1a:6d:41:74:48:63:05:46:85:61:
         bd:ac:ab:36:0e:70:a1:e5:2b:1d:3b:02:0b:00:31:74:d3:5e:
         0c:88:9b:ac:e8:c7:3d:22:22:90:01:c3:c0:f0:1e:e5:0a:4c:
         b1:0f:ab:6b:39:5c:af:fc:34:53:ef:fd:38:35:9b:15:63:57:
         f9:89:f0:f6:b8:5a:c7:e1:a6:ab:03:b0:b5:5a:c9:f1:b6:02:
         41:ba:f8:5b:58:f4:ed:4c:57:df:69:3f:55:25:57:4d:39:da:
         94:8a:36:27:f1:a8:db:59:c3:47:65:9d:db:7c:5d:0f:39:4a:
         6a:a8:b6:12:7b:2e:41:16:b5:ed:b9:33:aa:a0:74:d3:1c:3f:
         a4:4a:c8:0b:e3:37:13:f0:97:38:c5:4d:6c:62:d5:16:31:c3:
         c9:d9:48:91:d1:e6:3f:33:0e:24:0d:96:80:a3:80:b4:09:32:
         30:4c:e2:c2:d8:d3:3d:76:98:f0:5e:70:e0:ec:4a:ba:2e:97:
         44:4a:75:f2

这篇关于如何为使用OpenSSL生成的证书提供多行证书名称(CN)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆