Extrair parâmetros da solicitação de CSR do certificado (chave pública)

0

É possível extrair valores usados durante a criação do CSR (por exemplo, usando o openssl)?

Em outras palavras, a chave pública (arquivo .crt) contém os seguintes dados:
C = ?, ST =?, L =?, O = ?, OU = ?, CN = ?, nome = ?, emailAddress =?

    
por Maxim 06.12.2017 / 15:05

1 resposta

2

openssl req -in request.csr -text -noout imprimirá uma versão textual da solicitação, por exemplo,

$ 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

Se você quiser apenas o assunto da solicitação que pode ser obtido por algo como

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

Para algo mais específico do que isso, você precisará analisar o texto ou alternar para um modelo programático.

Da mesma forma, se você estiver querendo os dados do certificado atribuído, use o comando openssl x509 . Mas cuidado, pois um certificado emitido não precisa realmente ter nada em comum com o pedido de certificado (a chave pública será a mesma, a menos que a CA tenha lhe dado uma nova chave privada com o novo certificado ... mas isso não é comum ( e "não é bom")).

$ 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

(Se você receber um erro como Expecting: TRUSTED CERTIFICATE , seu certificado será codificado como binário, quando o OpenSSL esperar o PEM; portanto, adicione -inform der )

    
por 06.12.2017 / 16:25