@peculiar/x509
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -6,2 +6,3 @@ export * from "./authority_key_identifier"; | ||
export * from "./subject_key_identifier"; | ||
export * from "./subject_alt_name"; | ||
export * from "./extension_factory"; |
@@ -28,3 +28,9 @@ import { Certificate } from "@peculiar/asn1-x509"; | ||
getExtension<T extends Extension>(type: string): T | null; | ||
getExtension<T extends Extension>(type: { | ||
new (raw: BufferSource): T; | ||
}): T | null; | ||
getExtensions<T extends Extension>(type: string): T[]; | ||
getExtensions<T extends Extension>(type: { | ||
new (raw: BufferSource): T; | ||
}): T[]; | ||
verify(params: X509CertificateVerifyParams, crypto?: Crypto): Promise<boolean>; | ||
@@ -31,0 +37,0 @@ getThumbprint(crypto?: Crypto): Promise<ArrayBuffer>; |
@@ -145,3 +145,2 @@ /*! | ||
names.register("T", "2.5.4.12"); | ||
const special = [",", "+", "\"", "\\", "<", ">", ";", "#", " "]; | ||
function replaceUnknownCharacter(text, char) { | ||
@@ -206,17 +205,8 @@ return `\\${pvtsutils.Convert.ToHex(pvtsutils.Convert.FromUtf8String(char)).toUpperCase()}`; | ||
const asn = new asn1X509.Name(); | ||
let subAttribute = false; | ||
for (let i = 0; i < data.length; i++) { | ||
let char = data[i]; | ||
let type = ""; | ||
for (i; i < data.length; i++) { | ||
char = data[i]; | ||
if (char === "=") { | ||
i++; | ||
break; | ||
} | ||
if (char === " ") { | ||
continue; | ||
} | ||
type += char; | ||
} | ||
const regex = /(\d\.[\d.]*\d|[A-Z]+)=(((?:").*?(?<!\\)(?:"))|([^"].*?))((?<!\\)[,+])/g; | ||
let matches = null; | ||
let level = ","; | ||
while (matches = regex.exec(`${data},`)) { | ||
let [, type, value] = matches; | ||
const next = matches[5]; | ||
if (!/[\d.]+/.test(type)) { | ||
@@ -228,49 +218,16 @@ type = names.get(type) || ""; | ||
} | ||
let value = ""; | ||
let valueType = ValueType.simple; | ||
for (i; i < data.length; i++) { | ||
char = data[i]; | ||
if (value === "") { | ||
if (char === "#") { | ||
valueType = ValueType.hexadecimal; | ||
continue; | ||
} | ||
else if (char === "\"") { | ||
valueType = ValueType.quoted; | ||
continue; | ||
} | ||
} | ||
if (valueType === ValueType.quoted && char === "\"") { | ||
while (i++ < data.length) { | ||
char = data[i]; | ||
if (data === "," || char === "+") { | ||
break; | ||
} | ||
if (data === " ") { | ||
continue; | ||
} | ||
throw new Error("Cannot parse name from string. Incorrect character after quoted attribute value"); | ||
} | ||
break; | ||
} | ||
else if ((valueType === ValueType.simple || valueType === ValueType.hexadecimal) && (char === "," || char === "+")) { | ||
break; | ||
} | ||
if (char === "\\") { | ||
char = data[++i]; | ||
if (!special.includes(char)) { | ||
const hex = `${data[i++]}${data[i]}`; | ||
if (!/[0-9a-f]{2}/i.test(hex)) { | ||
throw new Error("Cannot parse name from string. Escaped hexadecimal value doesn't match to regular pattern"); | ||
} | ||
char = String.fromCharCode(parseInt(hex, 16)); | ||
} | ||
} | ||
value += char; | ||
} | ||
const attr = new asn1X509.AttributeTypeAndValue({ type }); | ||
if (valueType === ValueType.hexadecimal) { | ||
attr.value.anyValue = pvtsutils.Convert.FromHex(value); | ||
if (value.charAt(0) === "#") { | ||
attr.value.anyValue = pvtsutils.Convert.FromHex(value.slice(1)); | ||
} | ||
else { | ||
const quotedMatches = /(?:")(.*?)(?<!\\)(?:")/.exec(value); | ||
if (quotedMatches) { | ||
value = quotedMatches[1]; | ||
} | ||
value = value | ||
.replace(/\\0a/ig, "\n") | ||
.replace(/\\0d/ig, "\r") | ||
.replace(/\\0g/ig, "\t") | ||
.replace(/\\(.)/g, "$1"); | ||
if (type === names.get("E") || type === names.get("DC")) { | ||
@@ -283,3 +240,3 @@ attr.value.ia5String = value; | ||
} | ||
if (subAttribute) { | ||
if (level === "+") { | ||
asn[asn.length - 1].push(attr); | ||
@@ -290,3 +247,3 @@ } | ||
} | ||
subAttribute = char === "+"; | ||
level = next; | ||
} | ||
@@ -530,3 +487,3 @@ return asn; | ||
let algorithm = "SHA-1"; | ||
if (args.length === 1 && !((_a = args[0]) === null || _a === void 0 ? void 0 : _a.subtle)) { | ||
if (args.length >= 1 && !((_a = args[0]) === null || _a === void 0 ? void 0 : _a.subtle)) { | ||
algorithm = args[0] || algorithm; | ||
@@ -579,5 +536,12 @@ crypto = args[1] || cryptoProvider.get(); | ||
for (const ext of this.extensions) { | ||
if (ext.type === type) { | ||
return ext; | ||
if (typeof type === "string") { | ||
if (ext.type === type) { | ||
return ext; | ||
} | ||
} | ||
else { | ||
if (ext instanceof type) { | ||
return ext; | ||
} | ||
} | ||
} | ||
@@ -587,3 +551,10 @@ return null; | ||
getExtensions(type) { | ||
return this.extensions.filter(o => o.type === type); | ||
return this.extensions.filter(o => { | ||
if (typeof type === "string") { | ||
return o.type === type; | ||
} | ||
else { | ||
return o instanceof type; | ||
} | ||
}); | ||
} | ||
@@ -607,3 +578,3 @@ async verify(params, crypto = cryptoProvider.get()) { | ||
let algorithm = "SHA-1"; | ||
if (args.length === 1 && !((_a = args[0]) === null || _a === void 0 ? void 0 : _a.subtle)) { | ||
if (args.length >= 1 && !((_a = args[0]) === null || _a === void 0 ? void 0 : _a.subtle)) { | ||
algorithm = args[0] || algorithm; | ||
@@ -750,2 +721,165 @@ crypto = args[1] || crypto; | ||
class OtherName extends AsnData { | ||
constructor(...args) { | ||
let raw; | ||
if (pvtsutils.BufferSourceConverter.isBufferSource(args[0])) { | ||
raw = pvtsutils.BufferSourceConverter.toArrayBuffer(args[0]); | ||
} | ||
else { | ||
const type = args[0]; | ||
const value = pvtsutils.BufferSourceConverter.toArrayBuffer(args[1]); | ||
raw = asn1Schema.AsnConvert.serialize(new asn1X509.OtherName({ typeId: type, value })); | ||
} | ||
super(raw, asn1X509.OtherName); | ||
} | ||
onInit(asn) { | ||
this.type = asn.typeId; | ||
this.value = asn.value; | ||
} | ||
toJSON() { | ||
return { | ||
type: this.type, | ||
value: pvtsutils.Convert.ToHex(this.value), | ||
}; | ||
} | ||
} | ||
class SubjectAlternativeNameExtension extends Extension { | ||
constructor(...args) { | ||
if (pvtsutils.BufferSourceConverter.isBufferSource(args[0])) { | ||
super(args[0]); | ||
} | ||
else { | ||
const data = args[0] || {}; | ||
const value = new asn1X509.SubjectAlternativeName(); | ||
for (const item of data.dns || []) { | ||
value.push(new asn1X509.GeneralName({ | ||
dNSName: item, | ||
})); | ||
} | ||
for (const item of data.email || []) { | ||
value.push(new asn1X509.GeneralName({ | ||
rfc822Name: item, | ||
})); | ||
} | ||
for (const item of data.guid || []) { | ||
const matches = /([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})/i.exec(item); | ||
if (!matches) { | ||
throw new Error("Cannot parse GUID value. Value doesn't match to regular expression"); | ||
} | ||
const hex = matches | ||
.slice(1) | ||
.map((o, i) => { | ||
if (i < 3) { | ||
return pvtsutils.Convert.ToHex(new Uint8Array(pvtsutils.Convert.FromHex(o)).reverse()); | ||
} | ||
return o; | ||
}) | ||
.join(""); | ||
value.push(new asn1X509.GeneralName({ | ||
otherName: new asn1X509.OtherName({ | ||
typeId: SubjectAlternativeNameExtension.GUID, | ||
value: asn1Schema.AsnConvert.serialize(new asn1Schema.OctetString(pvtsutils.Convert.FromHex(hex))), | ||
}), | ||
})); | ||
} | ||
for (const item of data.ip || []) { | ||
value.push(new asn1X509.GeneralName({ | ||
iPAddress: item, | ||
})); | ||
} | ||
for (const item of data.url || []) { | ||
value.push(new asn1X509.GeneralName({ | ||
uniformResourceIdentifier: item, | ||
})); | ||
} | ||
for (const item of data.upn || []) { | ||
value.push(new asn1X509.GeneralName({ | ||
otherName: new asn1X509.OtherName({ | ||
typeId: SubjectAlternativeNameExtension.UPN, | ||
value: asn1Schema.AsnConvert.serialize(asn1Schema.AsnUtf8StringConverter.toASN(item)) | ||
}), | ||
})); | ||
} | ||
for (const item of data.registeredId || []) { | ||
value.push(new asn1X509.GeneralName({ | ||
registeredID: item, | ||
})); | ||
} | ||
for (const item of data.otherName || []) { | ||
value.push(new asn1X509.GeneralName({ | ||
otherName: new asn1X509.OtherName({ | ||
typeId: item.type, | ||
value: pvtsutils.Convert.FromHex(item.value), | ||
}), | ||
})); | ||
} | ||
super(asn1X509.id_ce_subjectAltName, args[1], asn1Schema.AsnConvert.serialize(value)); | ||
} | ||
} | ||
onInit(asn) { | ||
super.onInit(asn); | ||
const value = asn1Schema.AsnConvert.parse(asn.extnValue, asn1X509.SubjectAlternativeName); | ||
this.dns = value.filter(o => o.dNSName).map(o => o.dNSName || ""); | ||
this.email = value.filter(o => o.rfc822Name).map(o => o.rfc822Name || ""); | ||
this.ip = value.filter(o => o.iPAddress).map(o => o.iPAddress || ""); | ||
this.url = value.filter(o => o.uniformResourceIdentifier).map(o => o.uniformResourceIdentifier || ""); | ||
this.upn = value | ||
.filter(o => { var _a; return ((_a = o.otherName) === null || _a === void 0 ? void 0 : _a.typeId) === SubjectAlternativeNameExtension.UPN; }) | ||
.map(o => o.otherName ? asn1Schema.AsnConvert.parse(o.otherName.value, asn1X509.DirectoryString).toString() : ""); | ||
this.guid = value | ||
.filter(o => { var _a; return ((_a = o.otherName) === null || _a === void 0 ? void 0 : _a.typeId) === SubjectAlternativeNameExtension.GUID; }) | ||
.map(o => o.otherName ? asn1Schema.AsnConvert.parse(o.otherName.value, asn1Schema.OctetString) : new asn1Schema.OctetString()) | ||
.map(o => { | ||
const matches = /([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})/i.exec(pvtsutils.Convert.ToHex(o)); | ||
if (!matches) { | ||
throw new Error("Cannot parse GUID value. Value doesn't match to regular expression"); | ||
} | ||
const guid = matches | ||
.slice(1) | ||
.map((o, i) => { | ||
if (i < 3) { | ||
return pvtsutils.Convert.ToHex(new Uint8Array(pvtsutils.Convert.FromHex(o)).reverse()); | ||
} | ||
return o; | ||
}) | ||
.join("-"); | ||
return `{${guid}}`; | ||
}); | ||
this.registeredId = value.filter(o => o.registeredID).map(o => o.registeredID || ""); | ||
this.otherNames = value | ||
.filter(o => o.otherName && ![SubjectAlternativeNameExtension.GUID, SubjectAlternativeNameExtension.UPN].includes(o.otherName.typeId)) | ||
.map(o => new OtherName(o.otherName.typeId, o.otherName.value)); | ||
} | ||
toJSON() { | ||
const json = {}; | ||
if (this.dns.length) { | ||
json.dns = [...this.dns]; | ||
} | ||
if (this.email.length) { | ||
json.email = [...this.email]; | ||
} | ||
if (this.ip.length) { | ||
json.ip = [...this.ip]; | ||
} | ||
if (this.guid.length) { | ||
json.guid = [...this.guid]; | ||
} | ||
if (this.upn.length) { | ||
json.upn = [...this.upn]; | ||
} | ||
if (this.url.length) { | ||
json.url = [...this.url]; | ||
} | ||
if (this.registeredId.length) { | ||
json.registeredId = [...this.registeredId]; | ||
} | ||
if (this.otherNames.length) { | ||
json.otherName = this.otherNames.map(o => o.toJSON()); | ||
} | ||
return json; | ||
} | ||
} | ||
SubjectAlternativeNameExtension.GUID = "1.3.6.1.4.1.311.25.1"; | ||
SubjectAlternativeNameExtension.UPN = "1.3.6.1.4.1.311.20.2.3"; | ||
class Attribute extends AsnData { | ||
@@ -1207,2 +1341,3 @@ constructor(...args) { | ||
ExtensionFactory.register(asn1X509.id_ce_authorityKeyIdentifier, AuthorityKeyIdentifierExtension); | ||
ExtensionFactory.register(asn1X509.id_ce_subjectAltName, SubjectAlternativeNameExtension); | ||
AttributeFactory.register(asnPkcs9.id_pkcs9_at_challengePassword, ChallengePasswordAttribute); | ||
@@ -1225,2 +1360,3 @@ AttributeFactory.register(asnPkcs9.id_pkcs9_at_extensionRequest, ExtensionsAttribute); | ||
exports.Name = Name; | ||
exports.OtherName = OtherName; | ||
exports.PemConverter = PemConverter; | ||
@@ -1230,2 +1366,3 @@ exports.Pkcs10CertificateRequest = Pkcs10CertificateRequest; | ||
exports.PublicKey = PublicKey; | ||
exports.SubjectAlternativeNameExtension = SubjectAlternativeNameExtension; | ||
exports.SubjectKeyIdentifierExtension = SubjectKeyIdentifierExtension; | ||
@@ -1232,0 +1369,0 @@ exports.X509Certificate = X509Certificate; |
@@ -26,4 +26,4 @@ /*! | ||
import 'reflect-metadata'; | ||
import { AsnConvert, OctetString } from '@peculiar/asn1-schema'; | ||
import { Extension as Extension$1, Name as Name$1, AttributeTypeAndValue, RelativeDistinguishedName, SubjectPublicKeyInfo, Certificate, AuthorityKeyIdentifier, id_ce_authorityKeyIdentifier, BasicConstraints, id_ce_basicConstraints, ExtendedKeyUsage, id_ce_extKeyUsage, KeyUsage, id_ce_keyUsage, SubjectKeyIdentifier, id_ce_subjectKeyIdentifier, Attribute as Attribute$1, Extensions, AlgorithmIdentifier, id_ce_subjectAltName, TBSCertificate, Version, Validity } from '@peculiar/asn1-x509'; | ||
import { AsnConvert, OctetString, AsnUtf8StringConverter } from '@peculiar/asn1-schema'; | ||
import { Extension as Extension$1, Name as Name$1, AttributeTypeAndValue, RelativeDistinguishedName, SubjectPublicKeyInfo, Certificate, AuthorityKeyIdentifier, id_ce_authorityKeyIdentifier, BasicConstraints, id_ce_basicConstraints, ExtendedKeyUsage, id_ce_extKeyUsage, KeyUsage, id_ce_keyUsage, SubjectKeyIdentifier, id_ce_subjectKeyIdentifier, OtherName as OtherName$1, SubjectAlternativeName, GeneralName, id_ce_subjectAltName, DirectoryString, Attribute as Attribute$1, Extensions, AlgorithmIdentifier, TBSCertificate, Version, Validity } from '@peculiar/asn1-x509'; | ||
import { BufferSourceConverter, isEqual, Convert } from 'pvtsutils'; | ||
@@ -142,3 +142,2 @@ import { container, injectable } from 'tsyringe'; | ||
names.register("T", "2.5.4.12"); | ||
const special = [",", "+", "\"", "\\", "<", ">", ";", "#", " "]; | ||
function replaceUnknownCharacter(text, char) { | ||
@@ -203,17 +202,8 @@ return `\\${Convert.ToHex(Convert.FromUtf8String(char)).toUpperCase()}`; | ||
const asn = new Name$1(); | ||
let subAttribute = false; | ||
for (let i = 0; i < data.length; i++) { | ||
let char = data[i]; | ||
let type = ""; | ||
for (i; i < data.length; i++) { | ||
char = data[i]; | ||
if (char === "=") { | ||
i++; | ||
break; | ||
} | ||
if (char === " ") { | ||
continue; | ||
} | ||
type += char; | ||
} | ||
const regex = /(\d\.[\d.]*\d|[A-Z]+)=(((?:").*?(?<!\\)(?:"))|([^"].*?))((?<!\\)[,+])/g; | ||
let matches = null; | ||
let level = ","; | ||
while (matches = regex.exec(`${data},`)) { | ||
let [, type, value] = matches; | ||
const next = matches[5]; | ||
if (!/[\d.]+/.test(type)) { | ||
@@ -225,49 +215,16 @@ type = names.get(type) || ""; | ||
} | ||
let value = ""; | ||
let valueType = ValueType.simple; | ||
for (i; i < data.length; i++) { | ||
char = data[i]; | ||
if (value === "") { | ||
if (char === "#") { | ||
valueType = ValueType.hexadecimal; | ||
continue; | ||
} | ||
else if (char === "\"") { | ||
valueType = ValueType.quoted; | ||
continue; | ||
} | ||
} | ||
if (valueType === ValueType.quoted && char === "\"") { | ||
while (i++ < data.length) { | ||
char = data[i]; | ||
if (data === "," || char === "+") { | ||
break; | ||
} | ||
if (data === " ") { | ||
continue; | ||
} | ||
throw new Error("Cannot parse name from string. Incorrect character after quoted attribute value"); | ||
} | ||
break; | ||
} | ||
else if ((valueType === ValueType.simple || valueType === ValueType.hexadecimal) && (char === "," || char === "+")) { | ||
break; | ||
} | ||
if (char === "\\") { | ||
char = data[++i]; | ||
if (!special.includes(char)) { | ||
const hex = `${data[i++]}${data[i]}`; | ||
if (!/[0-9a-f]{2}/i.test(hex)) { | ||
throw new Error("Cannot parse name from string. Escaped hexadecimal value doesn't match to regular pattern"); | ||
} | ||
char = String.fromCharCode(parseInt(hex, 16)); | ||
} | ||
} | ||
value += char; | ||
} | ||
const attr = new AttributeTypeAndValue({ type }); | ||
if (valueType === ValueType.hexadecimal) { | ||
attr.value.anyValue = Convert.FromHex(value); | ||
if (value.charAt(0) === "#") { | ||
attr.value.anyValue = Convert.FromHex(value.slice(1)); | ||
} | ||
else { | ||
const quotedMatches = /(?:")(.*?)(?<!\\)(?:")/.exec(value); | ||
if (quotedMatches) { | ||
value = quotedMatches[1]; | ||
} | ||
value = value | ||
.replace(/\\0a/ig, "\n") | ||
.replace(/\\0d/ig, "\r") | ||
.replace(/\\0g/ig, "\t") | ||
.replace(/\\(.)/g, "$1"); | ||
if (type === names.get("E") || type === names.get("DC")) { | ||
@@ -280,3 +237,3 @@ attr.value.ia5String = value; | ||
} | ||
if (subAttribute) { | ||
if (level === "+") { | ||
asn[asn.length - 1].push(attr); | ||
@@ -287,3 +244,3 @@ } | ||
} | ||
subAttribute = char === "+"; | ||
level = next; | ||
} | ||
@@ -527,3 +484,3 @@ return asn; | ||
let algorithm = "SHA-1"; | ||
if (args.length === 1 && !((_a = args[0]) === null || _a === void 0 ? void 0 : _a.subtle)) { | ||
if (args.length >= 1 && !((_a = args[0]) === null || _a === void 0 ? void 0 : _a.subtle)) { | ||
algorithm = args[0] || algorithm; | ||
@@ -576,5 +533,12 @@ crypto = args[1] || cryptoProvider.get(); | ||
for (const ext of this.extensions) { | ||
if (ext.type === type) { | ||
return ext; | ||
if (typeof type === "string") { | ||
if (ext.type === type) { | ||
return ext; | ||
} | ||
} | ||
else { | ||
if (ext instanceof type) { | ||
return ext; | ||
} | ||
} | ||
} | ||
@@ -584,3 +548,10 @@ return null; | ||
getExtensions(type) { | ||
return this.extensions.filter(o => o.type === type); | ||
return this.extensions.filter(o => { | ||
if (typeof type === "string") { | ||
return o.type === type; | ||
} | ||
else { | ||
return o instanceof type; | ||
} | ||
}); | ||
} | ||
@@ -604,3 +575,3 @@ async verify(params, crypto = cryptoProvider.get()) { | ||
let algorithm = "SHA-1"; | ||
if (args.length === 1 && !((_a = args[0]) === null || _a === void 0 ? void 0 : _a.subtle)) { | ||
if (args.length >= 1 && !((_a = args[0]) === null || _a === void 0 ? void 0 : _a.subtle)) { | ||
algorithm = args[0] || algorithm; | ||
@@ -748,2 +719,165 @@ crypto = args[1] || crypto; | ||
class OtherName extends AsnData { | ||
constructor(...args) { | ||
let raw; | ||
if (BufferSourceConverter.isBufferSource(args[0])) { | ||
raw = BufferSourceConverter.toArrayBuffer(args[0]); | ||
} | ||
else { | ||
const type = args[0]; | ||
const value = BufferSourceConverter.toArrayBuffer(args[1]); | ||
raw = AsnConvert.serialize(new OtherName$1({ typeId: type, value })); | ||
} | ||
super(raw, OtherName$1); | ||
} | ||
onInit(asn) { | ||
this.type = asn.typeId; | ||
this.value = asn.value; | ||
} | ||
toJSON() { | ||
return { | ||
type: this.type, | ||
value: Convert.ToHex(this.value), | ||
}; | ||
} | ||
} | ||
class SubjectAlternativeNameExtension extends Extension { | ||
constructor(...args) { | ||
if (BufferSourceConverter.isBufferSource(args[0])) { | ||
super(args[0]); | ||
} | ||
else { | ||
const data = args[0] || {}; | ||
const value = new SubjectAlternativeName(); | ||
for (const item of data.dns || []) { | ||
value.push(new GeneralName({ | ||
dNSName: item, | ||
})); | ||
} | ||
for (const item of data.email || []) { | ||
value.push(new GeneralName({ | ||
rfc822Name: item, | ||
})); | ||
} | ||
for (const item of data.guid || []) { | ||
const matches = /([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})/i.exec(item); | ||
if (!matches) { | ||
throw new Error("Cannot parse GUID value. Value doesn't match to regular expression"); | ||
} | ||
const hex = matches | ||
.slice(1) | ||
.map((o, i) => { | ||
if (i < 3) { | ||
return Convert.ToHex(new Uint8Array(Convert.FromHex(o)).reverse()); | ||
} | ||
return o; | ||
}) | ||
.join(""); | ||
value.push(new GeneralName({ | ||
otherName: new OtherName$1({ | ||
typeId: SubjectAlternativeNameExtension.GUID, | ||
value: AsnConvert.serialize(new OctetString(Convert.FromHex(hex))), | ||
}), | ||
})); | ||
} | ||
for (const item of data.ip || []) { | ||
value.push(new GeneralName({ | ||
iPAddress: item, | ||
})); | ||
} | ||
for (const item of data.url || []) { | ||
value.push(new GeneralName({ | ||
uniformResourceIdentifier: item, | ||
})); | ||
} | ||
for (const item of data.upn || []) { | ||
value.push(new GeneralName({ | ||
otherName: new OtherName$1({ | ||
typeId: SubjectAlternativeNameExtension.UPN, | ||
value: AsnConvert.serialize(AsnUtf8StringConverter.toASN(item)) | ||
}), | ||
})); | ||
} | ||
for (const item of data.registeredId || []) { | ||
value.push(new GeneralName({ | ||
registeredID: item, | ||
})); | ||
} | ||
for (const item of data.otherName || []) { | ||
value.push(new GeneralName({ | ||
otherName: new OtherName$1({ | ||
typeId: item.type, | ||
value: Convert.FromHex(item.value), | ||
}), | ||
})); | ||
} | ||
super(id_ce_subjectAltName, args[1], AsnConvert.serialize(value)); | ||
} | ||
} | ||
onInit(asn) { | ||
super.onInit(asn); | ||
const value = AsnConvert.parse(asn.extnValue, SubjectAlternativeName); | ||
this.dns = value.filter(o => o.dNSName).map(o => o.dNSName || ""); | ||
this.email = value.filter(o => o.rfc822Name).map(o => o.rfc822Name || ""); | ||
this.ip = value.filter(o => o.iPAddress).map(o => o.iPAddress || ""); | ||
this.url = value.filter(o => o.uniformResourceIdentifier).map(o => o.uniformResourceIdentifier || ""); | ||
this.upn = value | ||
.filter(o => { var _a; return ((_a = o.otherName) === null || _a === void 0 ? void 0 : _a.typeId) === SubjectAlternativeNameExtension.UPN; }) | ||
.map(o => o.otherName ? AsnConvert.parse(o.otherName.value, DirectoryString).toString() : ""); | ||
this.guid = value | ||
.filter(o => { var _a; return ((_a = o.otherName) === null || _a === void 0 ? void 0 : _a.typeId) === SubjectAlternativeNameExtension.GUID; }) | ||
.map(o => o.otherName ? AsnConvert.parse(o.otherName.value, OctetString) : new OctetString()) | ||
.map(o => { | ||
const matches = /([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})/i.exec(Convert.ToHex(o)); | ||
if (!matches) { | ||
throw new Error("Cannot parse GUID value. Value doesn't match to regular expression"); | ||
} | ||
const guid = matches | ||
.slice(1) | ||
.map((o, i) => { | ||
if (i < 3) { | ||
return Convert.ToHex(new Uint8Array(Convert.FromHex(o)).reverse()); | ||
} | ||
return o; | ||
}) | ||
.join("-"); | ||
return `{${guid}}`; | ||
}); | ||
this.registeredId = value.filter(o => o.registeredID).map(o => o.registeredID || ""); | ||
this.otherNames = value | ||
.filter(o => o.otherName && ![SubjectAlternativeNameExtension.GUID, SubjectAlternativeNameExtension.UPN].includes(o.otherName.typeId)) | ||
.map(o => new OtherName(o.otherName.typeId, o.otherName.value)); | ||
} | ||
toJSON() { | ||
const json = {}; | ||
if (this.dns.length) { | ||
json.dns = [...this.dns]; | ||
} | ||
if (this.email.length) { | ||
json.email = [...this.email]; | ||
} | ||
if (this.ip.length) { | ||
json.ip = [...this.ip]; | ||
} | ||
if (this.guid.length) { | ||
json.guid = [...this.guid]; | ||
} | ||
if (this.upn.length) { | ||
json.upn = [...this.upn]; | ||
} | ||
if (this.url.length) { | ||
json.url = [...this.url]; | ||
} | ||
if (this.registeredId.length) { | ||
json.registeredId = [...this.registeredId]; | ||
} | ||
if (this.otherNames.length) { | ||
json.otherName = this.otherNames.map(o => o.toJSON()); | ||
} | ||
return json; | ||
} | ||
} | ||
SubjectAlternativeNameExtension.GUID = "1.3.6.1.4.1.311.25.1"; | ||
SubjectAlternativeNameExtension.UPN = "1.3.6.1.4.1.311.20.2.3"; | ||
class Attribute extends AsnData { | ||
@@ -1205,5 +1339,6 @@ constructor(...args) { | ||
ExtensionFactory.register(id_ce_authorityKeyIdentifier, AuthorityKeyIdentifierExtension); | ||
ExtensionFactory.register(id_ce_subjectAltName, SubjectAlternativeNameExtension); | ||
AttributeFactory.register(id_pkcs9_at_challengePassword, ChallengePasswordAttribute); | ||
AttributeFactory.register(id_pkcs9_at_extensionRequest, ExtensionsAttribute); | ||
export { AlgorithmProvider, AsnData, Attribute, AttributeFactory, AuthorityKeyIdentifierExtension, BasicConstraintsExtension, ChallengePasswordAttribute, CryptoProvider, EcAlgorithm, ExtendedKeyUsageExtension, Extension, ExtensionFactory, ExtensionsAttribute, KeyUsageFlags, KeyUsagesExtension, Name, PemConverter, Pkcs10CertificateRequest, Pkcs10CertificateRequestGenerator, PublicKey, RsaAlgorithm, SubjectKeyIdentifierExtension, X509Certificate, X509CertificateGenerator, X509Certificates, X509ChainBuilder, cryptoProvider, diAlgorithm, diAlgorithmProvider }; | ||
export { AlgorithmProvider, AsnData, Attribute, AttributeFactory, AuthorityKeyIdentifierExtension, BasicConstraintsExtension, ChallengePasswordAttribute, CryptoProvider, EcAlgorithm, ExtendedKeyUsageExtension, Extension, ExtensionFactory, ExtensionsAttribute, KeyUsageFlags, KeyUsagesExtension, Name, OtherName, PemConverter, Pkcs10CertificateRequest, Pkcs10CertificateRequestGenerator, PublicKey, RsaAlgorithm, SubjectAlternativeNameExtension, SubjectKeyIdentifierExtension, X509Certificate, X509CertificateGenerator, X509Certificates, X509ChainBuilder, cryptoProvider, diAlgorithm, diAlgorithmProvider }; |
{ | ||
"name": "@peculiar/x509", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "@peculiar/x509 is an easy to use TypeScript/Javascript library based on @peculiar/asn1-schema that makes generating X.509 Certificates and Certificate Requests as well as validating certificate chains easy", | ||
@@ -5,0 +5,0 @@ "main": "build/x509.cjs.js", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
304081
37
3723