0

I have created public, private keys and a self signed certificate with the following commands:

openssl genrsa -out private-key.pem 3072
openssl rsa -in private-key.pem -pubout -out public-key.pem
openssl req -new -x509 -key private-key.pem -out cert.pem -days 360

Certificate output: openssl x509 -in cert.pem -text

Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            35:66:2d:64:53:3a:89:cf:47:28:b4:fe:24:42:11:c7:3c:ca:b9:d8
        Signature Algorithm: sha256WithRSAEncryption
        Issuer: C = AU, ST = Some-State, L = Vilnius, O = Internet Widgits Pty Ltd
        Validity
            Not Before: Apr 21 17:28:12 2022 GMT
            Not After : Apr 16 17:28:12 2023 GMT
        Subject: C = AU, ST = Some-State, L = Vilnius, O = Internet Widgits Pty Ltd
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                RSA Public-Key: (3072 bit)
                Modulus:
                    00:d9:fc:2b:61:a7:cb:66:a1:8e:f2:ff:c8:a3:1c:
                    af:3d:c9:69:d3:f1:80:e8:c7:2b:f2:03:8c:ea:b6:
                    34:69:8b:ed:57:58:a9:d1:96:3d:bf:75:ea:b1:8a:
                    7e:18:f4:c8:78:8d:f3:0e:3c:f0:43:cb:fc:cb:3e:
                    fa:a7:51:ee:41:de:07:dc:1f:d4:46:78:c3:30:31:
                    0f:84:11:72:32:80:11:06:5d:60:22:7c:d2:3e:a0:
                    69:5b:ef:b4:10:f7:23:b5:52:64:d8:77:27:2c:19:
                    d6:ed:43:4b:d3:6b:3e:4b:04:68:ac:d0:70:e5:db:
                    c0:54:b4:c8:03:fc:bf:7d:25:8b:87:05:ed:58:e8:
                    e9:21:7b:6d:6b:31:55:17:6c:0b:0a:03:10:44:88:
                    9c:0e:a8:f3:07:e3:17:ec:36:d3:c6:f6:79:e0:93:
                    a9:39:80:c0:ff:ff:0f:b9:25:fb:54:a7:e3:df:42:
                    5a:67:c5:c7:c5:1d:64:0e:58:59:0b:36:a0:c3:99:
                    f8:f3:2f:ac:96:04:dd:b1:07:20:52:ba:de:86:fa:
                    37:c6:9a:64:76:7d:fa:b1:ff:f2:71:45:e9:40:4f:
                    ac:e3:3c:17:bd:0d:6b:8a:96:e0:24:75:7c:52:d1:
                    f0:7c:63:2a:83:d3:2c:3b:6d:cc:f0:3d:9c:ac:a7:
                    6f:f4:c2:83:c8:a8:9c:11:79:9d:d0:ae:b9:fb:4b:
                    e8:18:86:6c:d7:c1:a0:e1:cd:55:25:ed:73:a2:74:
                    46:04:b4:6e:88:ba:67:63:ba:02:8f:30:e5:2d:9e:
                    a5:9f:87:e0:c2:fc:19:a4:03:94:ca:54:2a:b0:2e:
                    59:3b:1f:e6:80:ff:20:a4:8c:2f:84:bd:b6:98:19:
                    c9:1f:ca:14:63:6c:f1:e9:89:f6:17:4a:7a:90:72:
                    04:76:2a:2f:df:98:c5:74:0a:5b:4c:c3:42:84:09:
                    15:2c:f6:11:f4:58:4e:7d:d5:85:03:8a:75:fc:35:
                    5c:67:60:b7:6a:b1:92:40:c4:d7
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Subject Key Identifier:
                69:02:1B:D7:9F:82:62:DC:EF:6F:BE:C7:F1:EF:3D:1C:7A:57:FD:43
            X509v3 Authority Key Identifier:
                keyid:69:02:1B:D7:9F:82:62:DC:EF:6F:BE:C7:F1:EF:3D:1C:7A:57:FD:43

            X509v3 Basic Constraints: critical
                CA:TRUE
    Signature Algorithm: sha256WithRSAEncryption
         78:5c:ee:01:d1:dc:3d:6c:71:65:fe:f6:bb:23:a5:81:3c:60:
         d0:3f:3b:5b:ef:fc:7a:32:05:67:de:fd:f8:59:93:16:99:d2:
         5c:2f:27:80:64:6c:0e:b1:13:4e:26:1e:7a:99:23:7e:50:06:
         77:ae:ac:7c:ae:36:85:d9:02:f0:a9:b9:17:38:f4:03:3c:de:
         87:d4:db:f2:28:4c:40:0e:05:d2:b4:e7:6a:ff:1e:81:ef:48:
         d5:2e:e4:af:6d:f6:47:dd:b6:c5:65:f1:dd:83:72:7c:f5:77:
         19:b4:84:1a:8f:8a:0e:f8:06:27:3d:78:72:f1:14:12:90:47:
         a5:b8:09:f3:15:8d:9c:ae:cb:07:fb:e1:0c:6f:56:cb:cc:ca:
         9f:d9:cb:e5:ad:30:ea:b4:71:14:8d:92:08:c9:00:00:23:54:
         d8:a2:31:2d:e4:a4:10:49:2e:77:1d:a6:3d:cf:27:3f:bc:8d:
         12:69:36:78:9b:7c:0a:72:02:0e:52:2e:7e:85:40:46:13:d3:
         2c:c1:e5:d7:92:33:23:66:b6:fb:55:e2:62:47:96:c2:3c:7c:
         1d:83:a2:ca:83:66:1b:85:8a:65:d6:2d:82:e2:8e:ff:e7:4f:
         d4:e2:d4:75:ee:1b:e7:77:5c:66:09:01:f8:80:41:77:d8:11:
         53:f7:c7:de:b4:d6:24:58:39:56:c9:b3:8d:69:2a:bb:2b:83:
         d3:a3:23:42:17:73:f7:d6:38:8c:e5:b7:53:d0:e9:03:88:50:
         72:78:76:0d:67:b2:02:ba:63:e8:5a:09:a9:b1:88:83:f1:b1:
         d5:6d:d3:f4:1f:99:10:a6:cd:62:ab:13:43:f3:e4:68:0c:b6:
         bb:5d:61:6f:f2:ec:1d:d3:e6:b9:39:30:8d:f2:b2:4d:e3:5a:
         bd:27:51:3e:25:5b:aa:d6:a1:74:18:27:e0:78:31:7b:ff:be:
         75:4f:78:25:36:2c:0f:51:da:32:32:6a:b3:28:0f:19:0c:03:
         47:da:09:94:b7:6c

I need to check this certificate signature with public key that certificate contains. What kind of operation is it and how I can achieve this? I can see the signature and public key in HEX mode in the certificate. How can I use them?

RoraΖ
  • 12,317
  • 4
  • 51
  • 83
vico
  • 249
  • 2
  • 6

1 Answers1

1

Since you're using OpenSSL

openssl verify -check_ss_sig -CAfile cert.pem cert.pem 

If you mean you want to do it 'by hand' so that you see the exact data being signed (but still with OpenSSL), the output from x509 -text is not sufficient because it does not fully represent everything in the certificate body. The cert.pem file (or its DER equivalent) is sufficient. See Manually walking through the signature validation of a certificate (disclosure: partly mine) for the procedure on a CA-issued (not self-signed) cert, but you can use the same procedure on self-signed just by using your own public key in place of the CA/issuer's public key in the last step.

dave_thompson_085
  • 9,759
  • 1
  • 24
  • 28