从证书(公钥)中提取CSR请求的参数

从证书(公钥)中提取CSR请求的参数

是否可以提取创建 CSR 期间使用的值(例如使用 openssl)?

换句话说,公钥(.crt 文件)是否包含以下数据:
C=?、ST=?、L=?、O=?、OU=?、CN=?、name=?、emailAddress=?

答案1

openssl req -in request.csr -text -noout将打印请求的文本版本,例如

$ openssl req -in bigexponent.csr -text -noout
Certificate Request:
    Data:
        Version: 0 (0x0)
        Subject: C=US, ST=Washington, L=Redmond, O=Microsoft Corporation, OU=.NET Framework (CoreFX), CN=localhost
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:
                    00:af:81:c1:cb:d8:20:3f:62:4a:53:9e:d6:60:81:
                    75:37:23:93:a2:83:7d:48:90:e4:8a:19:de:d3:69:
                    73:11:56:20:96:8d:6b:e0:d3:da:a3:8a:a7:77:be:
                    02:ee:0b:6b:93:b7:24:e8:dc:c1:2b:63:2b:4f:a8:
                    0b:bc:92:5b:ce:62:4f:4c:a7:cc:60:63:06:b3:94:
                    03:e2:8c:93:2d:24:dd:54:6f:fe:4e:f6:a3:7f:10:
                    77:0b:22:15:ea:8c:bb:5b:f4:27:e8:c4:d8:9b:79:
                    eb:33:83:75:10:0c:5f:83:e5:5d:e9:b4:46:6d:df:
                    be:ee:42:53:9a:ef:33:ef:18:7b:77:60:c3:b1:a1:
                    b2:10:3c:2d:81:44:56:4a:0c:10:39:a0:9c:85:cf:
                    6b:59:74:eb:51:6f:c8:d6:62:3c:94:ae:3a:5a:0b:
                    b3:b4:c7:92:95:7d:43:23:91:56:6c:f3:e2:a5:2a:
                    fb:0c:14:2b:9e:06:81:b8:97:26:71:af:2b:82:dd:
                    39:0a:39:b9:39:cf:71:95:68:68:7e:49:90:a6:30:
                    50:ca:77:68:dc:d6:b3:78:84:2f:18:fd:b1:f6:d9:
                    ff:09:6b:af:7b:eb:98:dc:f9:30:d6:6f:cf:d5:03:
                    f5:8d:41:bf:f4:62:12:e2:4e:3a:fc:45:ea:42:bd:
                    88:47
                Exponent: 8589935681 (0x200000441)
        Attributes:
        Requested Extensions:
            X509v3 Subject Alternative Name:
                IP Address:127.0.0.1, IP Address:0:0:0:0:0:0:0:1, DNS:localhost
    Signature Algorithm: sha256WithRSAEncryption
         3b:ca:e7:e0:2d:3a:82:84:35:11:0c:8a:65:19:7f:f1:a0:27:
         ec:5a:ca:37:eb:e2:9b:6e:70:93:a4:bd:ca:9b:da:8e:24:4d:
         c0:58:46:aa:9f:18:6d:2e:bb:df:64:74:bb:09:ec:f5:a3:c1:
         1f:3a:7e:56:d9:d4:89:c3:d4:ae:2d:cf:5d:52:ab:fc:df:ed:
         6d:46:23:af:7c:7d:2e:52:a1:89:bc:4a:0b:fc:5e:b9:6e:c1:
         58:a9:6b:29:2d:f6:e4:ad:ca:e5:23:3a:7e:15:98:44:4e:23:
         f7:32:52:6b:71:17:22:66:e4:57:06:f9:0e:fa:b0:94:5a:75:
         d4:46:f0:a6:54:7c:78:8d:d8:1a:d6:f4:d1:e7:fd:0e:88:84:
         08:3a:f5:20:03:d9:cd:38:b3:a1:40:f2:e5:52:cf:3f:bf:0b:
         4c:77:1e:57:45:c6:da:6f:26:dc:fd:0f:eb:87:b9:fd:d2:f4:
         72:4a:09:de:1f:b4:c5:5e:43:9f:43:c6:e3:7a:86:6b:a1:94:
         94:b2:10:d2:94:69:9b:3c:95:7c:6d:d2:2e:9b:63:db:ae:3b:
         5a:e6:29:19:f0:ea:3d:f3:04:c7:dd:9e:0b:ba:0e:70:53:60:
         5f:d0:66:a7:88:42:61:59:bb:93:7c:58:e5:a1:10:46:1d:c9:
         36:4c:a7:ca

如果你只是想要通过类似的东西获得的请求主题

$ openssl req -in bigexponent.csr -noout -subject
subject=/C=US/ST=Washington/L=Redmond/O=Microsoft Corporation/OU=.NET Framework (CoreFX)/CN=localhost

对于任何更具体的内容,您需要解析文本,或切换到程序模型。

同样,如果您想要从分配的证书中获取数据,则可以使用该openssl x509命令。但请注意,颁发的证书实际上不必与证书请求有任何共同之处(公钥将是相同的,除非 CA 为您提供了带有新证书的新私钥……但这并不常见(并且“不好”))。

$ openssl x509 -in bigexponent.cer -noout -text
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: 11195357966677484939 (0x9b5de6c15126a58b)
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: C=US, ST=Washington, L=Redmond, O=Microsoft Corporation, OU=.NET Framework (CoreFX), CN=localhost
        Validity
            Not Before: Mar  2 01:48:00 2016 GMT
            Not After : Mar  2 01:48:00 2017 GMT
        Subject: C=US, ST=Washington, L=Redmond, O=Microsoft Corporation, OU=.NET Framework (CoreFX), CN=localhost
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:
                    00:af:81:c1:cb:d8:20:3f:62:4a:53:9e:d6:60:81:
                    75:37:23:93:a2:83:7d:48:90:e4:8a:19:de:d3:69:
                    73:11:56:20:96:8d:6b:e0:d3:da:a3:8a:a7:77:be:
                    02:ee:0b:6b:93:b7:24:e8:dc:c1:2b:63:2b:4f:a8:
                    0b:bc:92:5b:ce:62:4f:4c:a7:cc:60:63:06:b3:94:
                    03:e2:8c:93:2d:24:dd:54:6f:fe:4e:f6:a3:7f:10:
                    77:0b:22:15:ea:8c:bb:5b:f4:27:e8:c4:d8:9b:79:
                    eb:33:83:75:10:0c:5f:83:e5:5d:e9:b4:46:6d:df:
                    be:ee:42:53:9a:ef:33:ef:18:7b:77:60:c3:b1:a1:
                    b2:10:3c:2d:81:44:56:4a:0c:10:39:a0:9c:85:cf:
                    6b:59:74:eb:51:6f:c8:d6:62:3c:94:ae:3a:5a:0b:
                    b3:b4:c7:92:95:7d:43:23:91:56:6c:f3:e2:a5:2a:
                    fb:0c:14:2b:9e:06:81:b8:97:26:71:af:2b:82:dd:
                    39:0a:39:b9:39:cf:71:95:68:68:7e:49:90:a6:30:
                    50:ca:77:68:dc:d6:b3:78:84:2f:18:fd:b1:f6:d9:
                    ff:09:6b:af:7b:eb:98:dc:f9:30:d6:6f:cf:d5:03:
                    f5:8d:41:bf:f4:62:12:e2:4e:3a:fc:45:ea:42:bd:
                    88:47
                Exponent: 8589935681 (0x200000441)
        X509v3 extensions:
            X509v3 Subject Key Identifier:
                78:A5:C7:5D:51:66:73:31:D5:A9:69:24:11:4C:9B:5F:A0:0D:7B:CB
            X509v3 Authority Key Identifier:
                keyid:78:A5:C7:5D:51:66:73:31:D5:A9:69:24:11:4C:9B:5F:A0:0D:7B:CB

            X509v3 Basic Constraints:
                CA:TRUE
    Signature Algorithm: sha256WithRSAEncryption
         77:75:6d:05:ff:a6:ad:fe:d5:b6:d4:af:b5:40:84:0c:6d:01:
         cf:6b:3f:a6:c9:73:df:d6:1f:ca:a0:a8:14:fa:1e:24:69:01:
         9d:94:b1:d8:56:d0:7d:d2:b9:5b:85:50:df:d2:08:59:53:a4:
         94:b9:9e:fc:ba:a7:98:2c:e7:71:98:4f:9d:4a:44:5f:fe:e0:
         62:e8:a0:49:73:6a:39:fd:99:4e:1f:da:0a:5d:c2:b5:b0:e5:
         7a:0b:10:c4:1b:c7:fe:6a:40:b2:4f:85:97:73:02:59:3e:60:
         b9:8d:d4:81:1d:47:d9:48:ed:f8:d6:e6:b5:af:80:a1:82:74:
         96:e2:0b:fd:24:0e:46:76:74:50:4d:4e:47:03:33:1d:64:70:
         5c:36:fb:6e:14:ba:bf:d9:cb:ee:c4:4b:33:a8:d7:b3:64:79:
         90:0f:3c:5b:ba:b6:9c:5e:45:3d:18:07:83:e2:50:80:51:b9:
         98:c0:38:e4:62:25:71:d2:ab:89:1d:89:8e:54:58:82:8c:f1:
         86:79:51:7d:28:db:ca:bf:72:e8:13:07:bf:d7:21:b7:3d:db:
         17:51:12:3f:99:d8:fc:0d:53:37:98:c4:db:d1:47:19:d5:d8:
         a8:5b:00:a1:44:a3:67:67:7b:48:89:1a:9b:56:f0:45:33:48:
         11:ba:cb:7a

(如果您收到类似的错误Expecting: TRUSTED CERTIFICATE,则说明您的证书被编码为二进制,而 OpenSSL 需要 PEM;因此添加-inform der

相关内容