1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
import * as asn1js from "asn1js";
import * as OID from "./ObjectIdentifiers";
import * as Schema from "./Schema";
export type ExtensionParsedValue = (Schema.SchemaCompatible & {
parsingError?: string;
}) | Schema.SchemaType;
export interface ExtensionValueType {
name: string;
type: ExtensionValueConstructor;
}
export interface ExtensionValueConstructor {
new(params?: { schema: any; }): Schema.SchemaCompatible;
}
export class ExtensionValueFactory {
public static types?: Record<string, ExtensionValueType>;
private static getItems(): Record<string, ExtensionValueType> {
if (!this.types) {
this.types = {};
// Register wellknown extensions
ExtensionValueFactory.register(OID.id_SubjectAltName, "SubjectAltName", AltName);
ExtensionValueFactory.register(OID.id_IssuerAltName, "IssuerAltName", AltName);
ExtensionValueFactory.register(OID.id_AuthorityKeyIdentifier, "AuthorityKeyIdentifier", AuthorityKeyIdentifier);
ExtensionValueFactory.register(OID.id_BasicConstraints, "BasicConstraints", BasicConstraints);
ExtensionValueFactory.register(OID.id_MicrosoftCaVersion, "MicrosoftCaVersion", CAVersion);
ExtensionValueFactory.register(OID.id_CertificatePolicies, "CertificatePolicies", CertificatePolicies);
ExtensionValueFactory.register(OID.id_MicrosoftAppPolicies, "CertificatePoliciesMicrosoft", CertificatePolicies);
ExtensionValueFactory.register(OID.id_MicrosoftCertTemplateV2, "MicrosoftCertTemplateV2", CertificateTemplate);
ExtensionValueFactory.register(OID.id_CRLDistributionPoints, "CRLDistributionPoints", CRLDistributionPoints);
ExtensionValueFactory.register(OID.id_FreshestCRL, "FreshestCRL", CRLDistributionPoints);
ExtensionValueFactory.register(OID.id_ExtKeyUsage, "ExtKeyUsage", ExtKeyUsage);
ExtensionValueFactory.register(OID.id_CertificateIssuer, "CertificateIssuer", GeneralNames);
ExtensionValueFactory.register(OID.id_AuthorityInfoAccess, "AuthorityInfoAccess", InfoAccess);
ExtensionValueFactory.register(OID.id_SubjectInfoAccess, "SubjectInfoAccess", InfoAccess);
ExtensionValueFactory.register(OID.id_IssuingDistributionPoint, "IssuingDistributionPoint", IssuingDistributionPoint);
ExtensionValueFactory.register(OID.id_NameConstraints, "NameConstraints", NameConstraints);
ExtensionValueFactory.register(OID.id_PolicyConstraints, "PolicyConstraints", PolicyConstraints);
ExtensionValueFactory.register(OID.id_PolicyMappings, "PolicyMappings", PolicyMappings);
ExtensionValueFactory.register(OID.id_PrivateKeyUsagePeriod, "PrivateKeyUsagePeriod", PrivateKeyUsagePeriod);
ExtensionValueFactory.register(OID.id_QCStatements, "QCStatements", QCStatements);
ExtensionValueFactory.register(OID.id_SignedCertificateTimestampList, "SignedCertificateTimestampList", SignedCertificateTimestampList);
ExtensionValueFactory.register(OID.id_SubjectDirectoryAttributes, "SubjectDirectoryAttributes", SubjectDirectoryAttributes);
}
return this.types;
}
public static fromBER(id: string, raw: BufferSource): ExtensionParsedValue | null {
const asn1 = asn1js.fromBER(raw);
if (asn1.offset === -1) {
return null;
}
const item = this.find(id);
if (item) {
try {
return new item.type({ schema: asn1.result });
} catch (ex) {
const res: ExtensionParsedValue = new item.type();
res.parsingError = `Incorrectly formatted value of extension ${item.name} (${id})`;
return res;
}
}
return asn1.result;
}
public static find(id: string): ExtensionValueType | null {
const types = this.getItems();
return types[id] || null;
}
public static register(id: string, name: string, type: ExtensionValueConstructor) {
this.getItems()[id] = { name, type };
}
}
import { AltName } from "./AltName";
import { AuthorityKeyIdentifier } from "./AuthorityKeyIdentifier";
import { BasicConstraints } from "./BasicConstraints";
import { CAVersion } from "./CAVersion";
import { CertificatePolicies } from "./CertificatePolicies";
import { CertificateTemplate } from "./CertificateTemplate";
import { CRLDistributionPoints } from "./CRLDistributionPoints";
import { ExtKeyUsage } from "./ExtKeyUsage";
import { GeneralNames } from "./GeneralNames";
import { InfoAccess } from "./InfoAccess";
import { IssuingDistributionPoint } from "./IssuingDistributionPoint";
import { NameConstraints } from "./NameConstraints";
import { PolicyConstraints } from "./PolicyConstraints";
import { PolicyMappings } from "./PolicyMappings";
import { PrivateKeyUsagePeriod } from "./PrivateKeyUsagePeriod";
import { QCStatements } from "./QCStatements";
import { SignedCertificateTimestampList } from "./SignedCertificateTimestampList";
import { SubjectDirectoryAttributes } from "./SubjectDirectoryAttributes";
|