Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes and new support for multi-value attributes #20

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

pkazmier
Copy link

[Disclaimer: This is my first piece of Elixir code. Be gentle please.]

This PR includes:

  • Fix to use a fixed order when printing the aggregated subject/issuer string. Maps are unordered, so it was only by chance that the existing tests passed. When I started working on this code, the tests failed immediately until I realized what was going on. So, now the aggregated string is created using a fixed order of attributes. The order I picked was to match how your unit tests were written (assuming that was your desired order).

  • Fully backwards compatible: Add new support for attributes that appear more than once in the subject/issuer RDN sequences. This happens with Entrust certificates where their issuing cert contains two OU attributes. The previous behavior was to simply discard all but the last value. The new code doesn't change this default behavior, but introduces a multivalue: true option on the parser functions to correctly handle this situation. This requires changing the values of the subject/issuer maps to lists. See commit message for more details. I've added a new cert and several new tests as part of this change.

  • Small tweaks to the build, which may or may not be the right way to handle things. As I mentioned, this is my first foray into Elixir. I couldn't get the project to build without updating those two files.

  • Fix a previous refactoring error by someone perhaps? parse_pem had an option called return_base64, which was passed along to parse_der, which did not use that option. It looks like it was renamed to serialize in parse_der, so this fix just updates the name of the option in parse_pem.

pkazmier added 4 commits June 30, 2024 10:43
It was by pure chance the tests passed before as maps are unordered, so
iterating over the map to create the aggregate string will vary. This
change makes the order of the aggregated string fixed. I used the same
order that was expected in the tests.
Fully backwards compatible feature enhancement.

The RDN sequence for both subject and issuer is allowed to contain the
same attribute more than once. For example, Entrust certificates have
two OU attributes. Passing the new `multivalue: true` option to either
of the parse functions yields this output, where values for the subject
and issuer are now lists. In the example below, you can see both of the
OU values. Further, the aggregated string also includes both now.

    %{
      aggregated: "/C=US/CN=Entrust Certification Authority - L1K/O=Entrust, Inc./OU=See www.entrust.net/legal-terms, (c) 2012 Entrust, Inc. - for authorized use only",
      CN: ["Entrust Certification Authority - L1K"],
      C: ["US"],
      L: [],
      ST: [],
      O: ["Entrust, Inc."],
      OU: ["See www.entrust.net/legal-terms",
       "(c) 2012 Entrust, Inc. - for authorized use only"],
      emailAddress: []
    }

Without the `multivalue` option, it parses is it did prior to this
change dropping all but the last of the duplicated attributes, which is
broken technically. In the spirit of backwards compatibility, however,
it parses the same as before:

    %{
      aggregated: "/C=US/CN=Entrust Certification Authority - L1K/O=Entrust, Inc./OU=(c) 2012 Entrust, Inc. - for authorized use only",
      emailAddress: nil,
      CN: "Entrust Certification Authority - L1K",
      OU: "(c) 2012 Entrust, Inc. - for authorized use only",
      O: "Entrust, Inc.",
      ST: nil,
      L: nil,
      C: "US"
    }
This is my first foray into Elixir and the first code I've ever written,
so I'm not too familiar with the build system, but I was unable to do
anything until I made these changes.
It looks like someone refactored their code, but forgot to update the
new name of this option in the parse_pem function definition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant