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

Distinguished Name implementation #314

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

Conversation

rviau42
Copy link
Contributor

@rviau42 rviau42 commented Apr 30, 2021

Due to the structure change, this Pull Request can introduce breaking changes

Distinguished Name implementation

Add DistinguishedName class which contains a collection of RelativeDistinguishedName
according to RFC5280 and X.501.

Subject and Issuer properties in Certificate, CRL, OCSP, ... classes doesn't accept Array anymore but Array.

Instead of:

	certificate.issuer.typesAndValues.push(new AttributeTypeAndValue({
		type: "2.5.4.6", // Country name
		value: new asn1js.PrintableString({ value: "RU" })
	}));
	certificate.issuer.typesAndValues.push(new AttributeTypeAndValue({
		type: "2.5.4.3", // Common name
		value: new asn1js.BmpString({ value: "Test" })
	}));

You must declare these fields with:

	certificate.issuer.relativeDistinguishedNames.push(new RelativeDistinguishedNames({
		typesAndValues: [new AttributeTypeAndValue({
			type: "2.5.4.6", // Country name
			value: new asn1js.PrintableString({ value: "RU" })
		})]
	}));
	certificate.issuer.relativeDistinguishedNames.push(new RelativeDistinguishedNames({
		typesAndValues: [new AttributeTypeAndValue({
			type: "2.5.4.3", // Common name
			value: new asn1js.BmpString({ value: "Test" })
		})]
	}));

DN toString()

For debugging purpose or more, it could be useful to get a string representation of DNs.
DistinguishedName.toString() prodives a String representation of DN almost conformed to RFC4514

To achieve to this conversion, there is a new Map containing the most common OID used for DN, based on RFC4519(https://tools.ietf.org/html/rfc4519): AttributeTypeDictionnary
The 57 OID described in section #2 AttributeType and section #3 ObjectClass are retrieved.

certificate.issuer.relativeDistinguishedNames.push(new RelativeDistinguishedNames({
    typesAndValues: [
        new AttributeTypeAndValue({
            type: "2.5.4.6", // Country name
            value: new asn1js.PrintableString({ value: "RU" })
        }),
        new AttributeTypeAndValue({
            type: "2.5.4.7", // Location
            value: new asn1js.PrintableString({ value: "Moscow" })
        }),
    ]
}));
certificate.issuer.relativeDistinguishedNames.push(new RelativeDistinguishedNames({
    typesAndValues: [new AttributeTypeAndValue({
        type: "2.5.4.3", // Common name
        value: new asn1js.BmpString({ value: 'John "Jim" Smith, III' })
    })]
}));

console.log(certificate.issuer.toString())
// EXPECTED: C=RU+L=Moscow,CN=John \"Jim\" Smith\, III

@rviau42 rviau42 marked this pull request as ready for review April 30, 2021 15:51
@rmhrisk rmhrisk requested a review from microshine April 30, 2021 17:12
examples/OCSPRequestComplexExample/es6.js Outdated Show resolved Hide resolved
src/AttributeTypeAndValue.js Outdated Show resolved Hide resolved
src/AttributeTypeAndValue.js Outdated Show resolved Hide resolved
src/AttributeTypeDictionnary.js Outdated Show resolved Hide resolved
examples/CertificateComplexExample/es6.js Outdated Show resolved Hide resolved
examples/CertificateComplexExample/es6.js Show resolved Hide resolved
@rviau42 rviau42 requested a review from microshine May 7, 2021 08:57
Copy link
Contributor

@microshine microshine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rviau42 Thanks. Update looks good. All tests are successfully passed.

src/CertificateChainValidationEngine.js Show resolved Hide resolved
@rviau42 rviau42 requested a review from microshine May 14, 2021 16:02
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.

3 participants