Skip to content

Commit

Permalink
feat(pki): add support of flatten rdn structure
Browse files Browse the repository at this point in the history
  • Loading branch information
amphineko committed Jun 1, 2024
1 parent ff65e38 commit f4f865e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
28 changes: 28 additions & 0 deletions packages/supervisor/src/pki/pkijs/rdn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { RelativeDistinguishedNames } from "@yonagi/common/types/pki/RelativeDistinguishedNames"
import * as asn1js from "asn1js"
import * as pkijs from "pkijs"

import { OID_CommonName, OID_OrganizationName } from "../consts"

export class ExtendedRelativeDistinguishedNames extends pkijs.RelativeDistinguishedNames {
toSchema(): asn1js.Sequence {
return new asn1js.Sequence({
value: Array.from(this.typesAndValues, (element) => new asn1js.Set({ value: [element.toSchema()] })),
})
}
}

export function convertRdnToPkijsRdn(rdn: RelativeDistinguishedNames): ExtendedRelativeDistinguishedNames {
return new ExtendedRelativeDistinguishedNames({
typesAndValues: [
new pkijs.AttributeTypeAndValue({
type: OID_CommonName,
value: new asn1js.BmpString({ value: rdn.commonName }),
}),
new pkijs.AttributeTypeAndValue({
type: OID_OrganizationName,
value: new asn1js.BmpString({ value: rdn.organizationName }),
}),
],
})
}
16 changes: 1 addition & 15 deletions packages/supervisor/src/pki/pkijs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as pkijs from "pkijs"

import { PkijsCertificate } from "."
import { CryptoEngineShim } from "./cryptoEngine"
import { convertRdnToPkijsRdn } from "./rdn"
import { CreateCertificateProps, ExtendedKeyUsages, KeyUsages } from ".."
import { OID_ClientAuth, OID_CommonName, OID_KP_EapOverLan, OID_OrganizationName, OID_ServerAuth } from "../consts"

Expand Down Expand Up @@ -64,21 +65,6 @@ function createKeyUsageExt(keyUsages: KeyUsages): pkijs.Extension {
})
}

function convertRdnToPkijsRdn(rdn: RelativeDistinguishedNames): pkijs.RelativeDistinguishedNames {
return new pkijs.RelativeDistinguishedNames({
typesAndValues: [
new pkijs.AttributeTypeAndValue({
type: OID_CommonName,
value: new asn1js.BmpString({ value: rdn.commonName }),
}),
new pkijs.AttributeTypeAndValue({
type: OID_OrganizationName,
value: new asn1js.BmpString({ value: rdn.organizationName }),
}),
],
})
}

export function convertPkijsRdnToRdn(rdn: pkijs.RelativeDistinguishedNames): RelativeDistinguishedNames {
return F.pipe(
E.Do,
Expand Down

0 comments on commit f4f865e

Please sign in to comment.