Skip to content

X509ExtensionFactory generates incorrect extension for subjectAltName #134

Closed
@roadrunner2

Description

@roadrunner2

The extension generated for subjectAltName by X509ExtensionFactory is missing a sequence. Take this code snippet:

extensions = OpenSSL::X509::ExtensionFactory.new
ext = extensions.create_extension("subjectAltName", "email:foo@bar.com,DNS:a.b.com")
File.open("/tmp/san.ext", "w") { |f| f.print(ext.to_der) }

The DER of this extension should look like (and does so under MRI)

   0 30   31: SEQUENCE {
   2 06    3:   OBJECT IDENTIFIER subjectAltName (2 5 29 17)
   7 04   24:   OCTET STRING, encapsulates {
   9 30   22:       SEQUENCE {
  11 81   11:         [1] 'foo@bar.com'
  24 82    7:         [2] 'a.b.com'
            :         }
            :       }
            :   }

But the actual DER of the created extension under JRuby is

   0 30   32: SEQUENCE {
   2 06    3:   OBJECT IDENTIFIER subjectAltName (2 5 29 17)
   7 04   25:   OCTET STRING, encapsulates {
   9 81   23:       [1] 'foo@bar.com,DNS:a.b.com'
            :       }
            :   }

Note the missing sequence, and the fact that both values are in one string.

The core issues are that X509ExtensionFactory.parseSubjectAltName() returns a GeneralName instead of a GeneralNames (sequence of GeneralName), and that it fails to parse multiple names properly.

Due to the missing sequence, it's currently completely impossible to generate a (valid) certificate with a subject-alt-name extension.

Lastly, pull request #123 appears to be related to this.

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