Skip to content

Add an OpenSSL::X509::Extension#inspect method #515

Open
@postmodern

Description

@postmodern

Not being able to inspect the contents of OpenSSL::X509::Extension objects is confusing.

Current Output

cert.extensions
=> 
[#<OpenSSL::X509::Extension:0x00007f8ef961b798>,      
 #<OpenSSL::X509::Extension:0x00007f8ef961b770>,      
 #<OpenSSL::X509::Extension:0x00007f8ef961b748>,      
 #<OpenSSL::X509::Extension:0x00007f8ef961b720>,      
 #<OpenSSL::X509::Extension:0x00007f8ef961b6f8>,      
 #<OpenSSL::X509::Extension:0x00007f8ef961b6d0>,      
 #<OpenSSL::X509::Extension:0x00007f8ef961b6a8>,      
 #<OpenSSL::X509::Extension:0x00007f8ef961b680>,      
 #<OpenSSL::X509::Extension:0x00007f8ef961b658>,      
 #<OpenSSL::X509::Extension:0x00007f8ef961b630>]

Proposed New Output

cert.extensions
# => [#<OpenSSL::X509::Extension: @oid="authorityKeyIdentifier" @value="keyid:B7:6B:A2:EA:A8:AA:84:8C:79:EA:B4:DA:0F:98:B2:C5:95:76:B9:F4\n" @critical=false>,
#<OpenSSL::X509::Extension: @oid="subjectKeyIdentifier" @value="F7:2A:09:D0:24:5B:11:71:EE:BA:BE:F4:3E:1C:3D:56:12:88:16:BB" @critical=false>,
#<OpenSSL::X509::Extension: @oid="subjectAltName" @value="DNS:www.example.org, DNS:example.net, DNS:example.edu, DNS:example.com, DNS:example.org, DNS:www.example.com, DNS:www.example.edu, DNS:www.example.net" @critical=false>,
#<OpenSSL::X509::Extension: @oid="keyUsage" @value="Digital Signature, Key Encipherment" @critical=true>,
#<OpenSSL::X509::Extension: @oid="extendedKeyUsage" @value="TLS Web Server Authentication, TLS Web Client Authentication" @critical=false>,
#<OpenSSL::X509::Extension: @oid="crlDistributionPoints" @value="\nFull Name:\n  URI:http://crl3.digicert.com/DigiCertTLSRSASHA2562020CA1-4.crl\n\nFull Name:\n  URI:http://crl4.digicert.com/DigiCertTLSRSASHA2562020CA1-4.crl\n" @critical=false>,
#<OpenSSL::X509::Extension: @oid="certificatePolicies" @value="Policy: 2.23.140.1.2.2\n  CPS: http://www.digicert.com/CPS\n" @critical=false>,
#<OpenSSL::X509::Extension: @oid="authorityInfoAccess" @value="OCSP - URI:http://ocsp.digicert.com\nCA Issuers - URI:http://cacerts.digicert.com/DigiCertTLSRSASHA2562020CA1-1.crt\n" @critical=false>,
#<OpenSSL::X509::Extension: @oid="basicConstraints" @value="CA:FALSE" @critical=false>,
#<OpenSSL::X509::Extension: @oid="ct_precert_scts" @value="Signed Certificate Timestamp:\n    Version   : v1 (0x0)\n    Log ID    : E8:3E:D0:DA:3E:F5:06:35:32:E7:57:28:BC:89:6B:C9:\n                03:D3:CB:D1:11:6B:EC:EB:69:E1:77:7D:6D:06:BD:6E\n    Timestamp : Mar 14 22:48:46.197 2022 GMT\n    Extensions: none\n    Signature : ecdsa-with-SHA256\n                30:44:02:20:31:78:F3:53:EB:46:7F:BD:32:53:3D:5A:\n                F2:88:6C:D7:AC:BC:42:34:94:2A:B5:E5:0B:92:0B:81:\n                10:C6:C6:FE:02:20:47:74:30:BC:82:C9:21:60:14:7E:\n                F4:9F:25:0F:F3:32:6A:AB:D8:90:DA:9D:61:3C:BB:36:\n                C2:E0:45:9B:73:00\nSigned Certificate Timestamp:\n    Version   : v1 (0x0)\n    Log ID    : 35:CF:19:1B:BF:B1:6C:57:BF:0F:AD:4C:6D:42:CB:BB:\n                B6:27:20:26:51:EA:3F:E1:2A:EF:A8:03:C3:3B:D6:4C\n    Timestamp : Mar 14 22:48:46.204 2022 GMT\n    Extensions: none\n    Signature : ecdsa-with-SHA256\n                30:44:02:20:3B:29:4F:1C:24:50:1A:44:A1:E0:3E:22:\n                89:4D:63:03:8A:97:D6:31:9B:09:3C:D7:AC:9D:D0:ED:\n                88:24:F6:5C:02:20:15:F1:35:A1:A0:E2:E2:8A:A1:8A:\n                9D:8D:36:09:D7:06:5C:EC:C0:CC:2E:ED:4F:A9:BB:3A:\n                D2:C0:92:ED:BE:58\nSigned Certificate Timestamp:\n    Version   : v1 (0x0)\n    Log ID    : B3:73:77:07:E1:84:50:F8:63:86:D6:05:A9:DC:11:09:\n                4A:79:2D:B1:67:0C:0B:87:DC:F0:03:0E:79:36:A5:9A\n    Timestamp : Mar 14 22:48:46.215 2022 GMT\n    Extensions: none\n    Signature : ecdsa-with-SHA256\n                30:45:02:20:29:1E:EA:C0:F2:D0:6F:A5:13:DB:E4:BB:\n                C3:BB:90:B1:BB:03:65:F6:55:5F:F8:3C:16:40:6D:02:\n                5B:5A:4E:90:02:21:00:CB:76:D7:9D:44:D1:8D:86:EC:\n                D8:A4:1E:A0:98:10:72:76:1B:52:42:2E:58:64:BB:29:\n                16:F6:95:1E:97:96:D7" @critical=false>]

Proposed Code

module OpenSSL
  module X509
    class Extension

      def inspect
        "#<#{self.class}: @oid=#{oid.inspect} @value=#{value.inspect} @critical=#{critical?.inspect}>"
      end

    end
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions