@peculiar/x509
Advanced tools
Comparing version 1.0.5 to 1.0.6
import { AlgorithmIdentifier } from "@peculiar/asn1-x509"; | ||
export interface IAlgorithm { | ||
/** | ||
* Converts WebCrypto algorithm to ASN.1 algorithm | ||
* @param alg WebCrypto algorithm | ||
* @returns ASN.1 algorithm or null | ||
*/ | ||
toAsnAlgorithm(alg: Algorithm): AlgorithmIdentifier | null; | ||
/** | ||
* Converts ASN.1 algorithm to WebCrypto algorithm | ||
* @param alg ASN.1 algorithm | ||
* @returns WebCrypto algorithm or null | ||
*/ | ||
toWebAlgorithm(alg: AlgorithmIdentifier): Algorithm | null; | ||
} | ||
/** | ||
* Dependency Injection algorithm identifier | ||
*/ | ||
export declare const diAlgorithm = "crypto.algorithm"; | ||
export declare class AlgorithmProvider { | ||
/** | ||
* Returns all registered algorithm providers | ||
*/ | ||
getAlgorithms(): IAlgorithm[]; | ||
/** | ||
* Converts WebCrypto algorithm to ASN.1 algorithm | ||
* @param alg WebCrypto algorithm | ||
* @returns ASN.1 algorithm or null | ||
* @throws Error whenever cannot convert an algorithm | ||
*/ | ||
toAsnAlgorithm(alg: Algorithm): AlgorithmIdentifier; | ||
/** | ||
* ConvertsASN.1 algorithm to WebCrypto algorithm | ||
* @param alg ASN.1 algorithm | ||
* @returns algorithm or null | ||
* @throws Error whenever cannot convert an algorithm | ||
*/ | ||
toWebAlgorithm(alg: AlgorithmIdentifier): Algorithm; | ||
} | ||
export declare const diAlgorithmProvider = "crypto.algorithmProvider"; |
@@ -1,27 +0,9 @@ | ||
/** | ||
* Represents an ASN.1 data | ||
*/ | ||
export declare abstract class AsnData<T> { | ||
/** | ||
* Gets a DER encoded buffer | ||
*/ | ||
readonly rawData: ArrayBuffer; | ||
/** | ||
* Creates a new instance | ||
* @param raw DER encoded buffer | ||
* @param type ASN.1 convertible class for `@peculiar/asn1-schema` schema | ||
*/ | ||
constructor(raw: BufferSource, type: { | ||
new (): T; | ||
}); | ||
/** | ||
* ASN.1 object | ||
* @param asn | ||
*/ | ||
constructor(asn: T); | ||
/** | ||
* Occurs on instance initialization | ||
* @param asn ASN.1 object | ||
*/ | ||
protected abstract onInit(asn: T): void; | ||
equal(data: any): data is this; | ||
} |
import { Attribute as AsnAttribute } from "@peculiar/asn1-x509"; | ||
import { AsnData } from "./asn_data"; | ||
/** | ||
* Represents the Attribute structure | ||
*/ | ||
export declare class Attribute extends AsnData<AsnAttribute> { | ||
/** | ||
* Gets an attribute identifier | ||
*/ | ||
type: string; | ||
/** | ||
* Gets a list of DER encoded attribute values | ||
*/ | ||
values: ArrayBuffer[]; | ||
/** | ||
* Crates a new instance | ||
* @param type Attribute identifier | ||
* @param values List of DER encoded attribute values | ||
*/ | ||
constructor(type: string, values?: BufferSource[]); | ||
/** | ||
* Crates a new instance from DER encoded buffer | ||
* @param raw DER encoded buffer | ||
*/ | ||
constructor(raw: BufferSource); | ||
protected onInit(asn: AsnAttribute): void; | ||
} |
import { Attribute } from "../attribute"; | ||
/** | ||
* Static class to manage X509 attributes | ||
*/ | ||
export declare class AttributeFactory { | ||
private static items; | ||
/** | ||
* Registers a new X509 Attribute class. If id already exists replaces it | ||
* @param id Attribute identifier | ||
* @param type Attribute class | ||
* | ||
* @example | ||
* ```js | ||
* AttributeFactory.register(asnPkcs9.id_pkcs9_at_challengePassword, ChallengePasswordAttribute); | ||
* ``` | ||
*/ | ||
static register(id: string, type: any): void; | ||
/** | ||
* Returns X509 Attribute based on it's identifier | ||
* @param data DER encoded buffer | ||
* | ||
* @example | ||
* ```js | ||
* const attr = AttributeFactory.create(asnAttrRaw); | ||
* ``` | ||
*/ | ||
static create(data: BufferSource): Attribute; | ||
} |
@@ -5,13 +5,5 @@ import * as asnX509 from "@peculiar/asn1-x509"; | ||
password: string; | ||
/** | ||
* Creates a new instance from DER encoded buffer | ||
* @param raw DER encoded buffer | ||
*/ | ||
constructor(raw: BufferSource); | ||
/** | ||
* Creates a new instance | ||
* @param value | ||
*/ | ||
constructor(value: string); | ||
protected onInit(asn: asnX509.Attribute): void; | ||
} |
@@ -6,13 +6,5 @@ import * as asnX509 from "@peculiar/asn1-x509"; | ||
items: Extension[]; | ||
/** | ||
* Creates a new instance from DER encoded buffer | ||
* @param raw DER encoded buffer | ||
*/ | ||
constructor(raw: BufferSource); | ||
/** | ||
* Creates a new instance | ||
* @param extensions | ||
*/ | ||
constructor(extensions: Extension[]); | ||
protected onInit(asn: asnX509.Attribute): void; | ||
} |
import { AlgorithmIdentifier } from "@peculiar/asn1-x509"; | ||
import { IAlgorithm } from "./algorithm"; | ||
import { HashedAlgorithm } from "./types"; | ||
/** | ||
* EC algorithm provider | ||
*/ | ||
export declare class EcAlgorithm implements IAlgorithm { | ||
@@ -8,0 +5,0 @@ toAsnAlgorithm(alg: HashedAlgorithm | EcKeyGenParams): AlgorithmIdentifier | null; |
import { Extension as AsnExtension } from "@peculiar/asn1-x509"; | ||
import { AsnData } from "./asn_data"; | ||
/** | ||
* Represents the certificate extension | ||
*/ | ||
export declare class Extension extends AsnData<AsnExtension> { | ||
/** | ||
* Gets an extension identifier | ||
*/ | ||
type: string; | ||
/** | ||
* Indicates where extension is critical | ||
*/ | ||
critical: boolean; | ||
/** | ||
* Gets a DER encoded value of extension | ||
*/ | ||
value: ArrayBuffer; | ||
/** | ||
* Creates a new instance from DER encoded Buffer | ||
* @param raw DER encoded buffer | ||
*/ | ||
constructor(raw: BufferSource); | ||
/** | ||
* Creates a new instance | ||
* @param type Extension identifier | ||
* @param critical Indicates where extension is critical | ||
* @param value DER encoded value of extension | ||
*/ | ||
constructor(type: string, critical: boolean, value: BufferSource); | ||
protected onInit(asn: AsnExtension): void; | ||
} |
@@ -5,62 +5,15 @@ import * as asn1X509 from "@peculiar/asn1-x509"; | ||
export interface CertificateIdentifier { | ||
/** | ||
* Name | ||
*/ | ||
name: asn1X509.GeneralName[]; | ||
/** | ||
* Hexadecimal string | ||
*/ | ||
serialNumber: string; | ||
} | ||
/** | ||
* Represents the Authority Key Identifier certificate extension | ||
*/ | ||
export declare class AuthorityKeyIdentifierExtension extends Extension { | ||
/** | ||
* Creates authority key identifier extension from certificate | ||
* @param cert Certificate | ||
* @param critical Indicates where extension is critical. Default is `false` | ||
* @param crypto WebCrypto provider. Default is from CryptoProvider | ||
*/ | ||
static create(cert: X509Certificate, critical?: boolean, crypto?: Crypto): Promise<AuthorityKeyIdentifierExtension>; | ||
/** | ||
* Creates authority key identifier extension from certificate identifier | ||
* @param certId Certificate identifier | ||
* @param critical Indicates where extension is critical. Default is `false` | ||
* @param crypto WebCrypto provider. Default is from CryptoProvider | ||
*/ | ||
static create(certId: CertificateIdentifier, critical?: boolean, crypto?: Crypto): Promise<AuthorityKeyIdentifierExtension>; | ||
/** | ||
* Creates authority key identifier extension from CryptoKey | ||
* @param publicKey Public CryptoKey | ||
* @param critical Indicates where extension is critical. Default is `false` | ||
* @param crypto WebCrypto provider. Default is from CryptoProvider | ||
*/ | ||
static create(publicKey: CryptoKey, critical?: boolean, crypto?: Crypto): Promise<AuthorityKeyIdentifierExtension>; | ||
/** | ||
* Gets a hexadecimal representation of key identifier | ||
*/ | ||
keyId?: string; | ||
/** | ||
* Gets a certificate identifier in the issuer name and serial number | ||
*/ | ||
certId?: CertificateIdentifier; | ||
/** | ||
* Creates a new instance from DER encoded buffer | ||
* @param raw DER encoded buffer | ||
*/ | ||
constructor(raw: BufferSource); | ||
/** | ||
* Creates a new instance | ||
* @param identifier Hexadecimal representation of key identifier | ||
* @param critical Indicates where extension is critical. Default is `false` | ||
*/ | ||
constructor(identifier: string, critical?: boolean); | ||
/** | ||
* Creates a new instance | ||
* @param id Certificate identifier in the issuer name and serial number | ||
* @param critical Indicates where extension is critical. Default is `false` | ||
*/ | ||
constructor(id: CertificateIdentifier, critical?: boolean); | ||
protected onInit(asn: asn1X509.Extension): void; | ||
} |
import { Extension } from "../extension"; | ||
/** | ||
* Represents the Basic Constraints certificate extension | ||
*/ | ||
export declare class BasicConstraintsExtension extends Extension { | ||
/** | ||
* Indicates whether the certified public key may be used | ||
* to verify certificate signatures | ||
*/ | ||
readonly ca: boolean; | ||
/** | ||
* Gets a maximum number of non-self-issued intermediate certificates that may | ||
* follow this certificate in a valid certification path | ||
*/ | ||
readonly pathLength?: number; | ||
/** | ||
* Creates a new instance from DER encoded buffer | ||
* @param raw DER encoded buffer | ||
*/ | ||
constructor(raw: BufferSource); | ||
/** | ||
* Creates a new instance | ||
* @param ca | ||
* @param pathLength | ||
* @param critical | ||
*/ | ||
constructor(ca: boolean, pathLength?: number, critical?: boolean); | ||
} |
import { Extension } from "../extension"; | ||
/** | ||
* Represents the Extended Key Usage certificate extension | ||
*/ | ||
export declare class ExtendedKeyUsageExtension extends Extension { | ||
/** | ||
* Gets a list of purposes for which the certified public key may be used | ||
*/ | ||
readonly usages: string[]; | ||
/** | ||
* Creates a new instance from DER encoded buffer | ||
* @param raw DER encoded buffer | ||
*/ | ||
constructor(raw: BufferSource); | ||
/** | ||
* Creates a new instance | ||
* @param usages | ||
* @param critical | ||
*/ | ||
constructor(usages: string[], critical?: boolean); | ||
} |
import { Extension } from "../extension"; | ||
/** | ||
* Static class to manage X509 extensions | ||
*/ | ||
export declare class ExtensionFactory { | ||
private static items; | ||
/** | ||
* Registers a new X509 Extension class. If id already exists replaces it | ||
* @param id Extension identifier | ||
* @param type Extension class | ||
* | ||
* @example | ||
* ```js | ||
* ExtensionFactory.register(asnX509.id_ce_basicConstraints, extensions.BasicConstraintsExtension); | ||
* ``` | ||
*/ | ||
static register(id: string, type: any): void; | ||
/** | ||
* Returns X509 Extension based on it's identifier | ||
* @param data DER encoded buffer | ||
* | ||
* @example | ||
* ```js | ||
* const ext = ExtensionFactory.create(asnExtRaw); | ||
* ``` | ||
*/ | ||
static create(data: BufferSource): Extension; | ||
} |
import { Extension } from "../extension"; | ||
/** | ||
* X509 key usages flags | ||
*/ | ||
export declare enum KeyUsageFlags { | ||
@@ -16,21 +13,6 @@ digitalSignature = 1, | ||
} | ||
/** | ||
* Represents the Key Usage certificate extension | ||
*/ | ||
export declare class KeyUsagesExtension extends Extension { | ||
/** | ||
* Gets a key usages flag | ||
*/ | ||
readonly usages: KeyUsageFlags; | ||
/** | ||
* Creates a new instance from DER encoded buffer | ||
* @param raw DER encoded buffer | ||
*/ | ||
constructor(raw: BufferSource); | ||
/** | ||
* Creates a new instance | ||
* @param usages | ||
* @param critical | ||
*/ | ||
constructor(usages: KeyUsageFlags, critical?: boolean); | ||
} |
import { Extension } from "../extension"; | ||
/** | ||
* Represents the Subject Key Identifier certificate extension | ||
*/ | ||
export declare class SubjectKeyIdentifierExtension extends Extension { | ||
/** | ||
* Creates subject key identifier extension from CryptoKey | ||
* @param publicKey Public CryptoKey | ||
* @param critical Indicates where extension is critical. Default is `false` | ||
* @param crypto WebCrypto provider. Default is from CryptoProvider | ||
*/ | ||
static create(publicKey: CryptoKey, critical?: boolean, crypto?: Crypto): Promise<SubjectKeyIdentifierExtension>; | ||
/** | ||
* Gets hexadecimal representation of key identifier | ||
*/ | ||
readonly keyId: string; | ||
/** | ||
* Creates a new instance from DER encoded buffer | ||
* @param raw DER encoded buffer | ||
*/ | ||
constructor(raw: BufferSource); | ||
/** | ||
* Creates a new instance | ||
* @param keyId Hexadecimal representation of key identifier | ||
* @param critical Indicates where extension is critical. Default is `false` | ||
*/ | ||
constructor(keyId: string, critical?: boolean); | ||
} |
@@ -11,2 +11,3 @@ import "reflect-metadata"; | ||
export * from "./name"; | ||
export * from "./pem_converter"; | ||
export * from "./pkcs10_cert_req"; | ||
@@ -13,0 +14,0 @@ export * from "./pkcs10_cert_req_generator"; |
import { Name as AsnName } from "@peculiar/asn1-x509"; | ||
/** | ||
* JSON representation of Attribute and Value | ||
*/ | ||
export interface JsonAttributeAndValue { | ||
[type: string]: string[]; | ||
} | ||
/** | ||
* JSON array of Attribute and Value | ||
*/ | ||
export declare type JsonName = Array<JsonAttributeAndValue>; | ||
/** | ||
* UTF-8 String Representation of Distinguished Names | ||
* | ||
* https://tools.ietf.org/html/rfc2253 | ||
*/ | ||
export declare class Name { | ||
/** | ||
* ASN.1 Name | ||
*/ | ||
private asn; | ||
/** | ||
* Creates a new instance | ||
* @param data | ||
*/ | ||
constructor(data: BufferSource | AsnName | string | JsonName); | ||
/** | ||
* Returns string serialized Name | ||
*/ | ||
toString(): string; | ||
/** | ||
* Returns a JSON representation of the Name | ||
*/ | ||
toJSON(): JsonName; | ||
/** | ||
* Creates AsnName object from string | ||
* @param data | ||
*/ | ||
private fromString; | ||
/** | ||
* Creates AsnName from JSON | ||
* @param data | ||
*/ | ||
private fromJSON; | ||
/** | ||
* Returns Name in DER encoded format | ||
*/ | ||
toArrayBuffer(): ArrayBuffer; | ||
} |
@@ -6,37 +6,11 @@ import { Attribute } from "./attribute"; | ||
export declare type Pkcs10CertificateRequestCreateParamsName = string | JsonName; | ||
/** | ||
* Pkcs10CertificateRequest create parameters | ||
*/ | ||
export interface Pkcs10CertificateRequestCreateParams { | ||
/** | ||
* Subject name | ||
*/ | ||
name?: Pkcs10CertificateRequestCreateParamsName; | ||
/** | ||
* Extensions | ||
*/ | ||
extensions?: Extension[]; | ||
/** | ||
* Attributes | ||
*/ | ||
attributes?: Attribute[]; | ||
/** | ||
* Signing algorithm | ||
*/ | ||
signingAlgorithm: Algorithm | EcdsaParams; | ||
/** | ||
* Crypto key pair | ||
*/ | ||
keys: CryptoKeyPair; | ||
} | ||
/** | ||
* Generator of PKCS10 certificate requests | ||
*/ | ||
export declare class Pkcs10CertificateRequestGenerator { | ||
/** | ||
* Creates a new PKCS10 Certificate request | ||
* @param params Create parameters | ||
* @param crypto Crypto provider. Default is from CryptoProvider | ||
*/ | ||
static create(params: Pkcs10CertificateRequestCreateParams, crypto?: Crypto): Promise<Pkcs10CertificateRequest>; | ||
} |
import { CertificationRequest } from "@peculiar/asn1-csr"; | ||
import { HashedAlgorithm } from "./types"; | ||
import { AsnData } from "./asn_data"; | ||
import { Attribute } from "./attribute"; | ||
import { Extension } from "./extension"; | ||
import { PublicKey } from "./public_key"; | ||
/** | ||
* Representation of PKCS10 Certificate Request | ||
*/ | ||
export declare class Pkcs10CertificateRequest extends AsnData<CertificationRequest> { | ||
/** | ||
* ToBeSigned block of CSR | ||
*/ | ||
import { AsnEncodedType, PemData } from "./pem_data"; | ||
export declare class Pkcs10CertificateRequest extends PemData<CertificationRequest> { | ||
protected readonly tag: string; | ||
private tbs; | ||
/** | ||
* Gets a string subject name | ||
*/ | ||
subject: string; | ||
/** | ||
* Gets a signature algorithm | ||
*/ | ||
signatureAlgorithm: HashedAlgorithm; | ||
/** | ||
* Gets a signature | ||
*/ | ||
signature: ArrayBuffer; | ||
/** | ||
* Gets a public key of CSR | ||
*/ | ||
publicKey: PublicKey; | ||
/** | ||
* Gets a list fo CSR attributes | ||
*/ | ||
attributes: Attribute[]; | ||
/** | ||
* Gets a list of CSR extensions | ||
*/ | ||
extensions: Extension[]; | ||
/** | ||
* Creates a new instance fromDER encoded buffer | ||
* @param raw DER encoded buffer | ||
*/ | ||
constructor(raw: BufferSource); | ||
/** | ||
* Creates a new instance from ASN.1 CertificationRequest | ||
* @param asn ASN.1 CertificationRequest | ||
*/ | ||
constructor(raw: AsnEncodedType); | ||
constructor(asn: CertificationRequest); | ||
protected onInit(asn: CertificationRequest): void; | ||
/** | ||
* Returns attribute of the specified type | ||
* @param type Attribute identifier | ||
* @returns Attribute or null | ||
*/ | ||
getAttribute(type: string): Attribute | null; | ||
/** | ||
* Returns a list of attributes of the specified type | ||
* @param type Attribute identifier | ||
*/ | ||
getAttributes(type: string): Attribute[]; | ||
/** | ||
* Returns extension of the specified type | ||
* @param type Extension identifier | ||
* @returns Extension or null | ||
*/ | ||
getExtension(type: string): Extension | null; | ||
/** | ||
* Returns a list of extension of the specified type | ||
* @param type Extension identifier | ||
*/ | ||
getExtensions(type: string): Extension[]; | ||
/** | ||
* Validates CSR signature | ||
* @param crypto Crypto provider. Default is from CryptoProvider | ||
*/ | ||
verify(crypto?: Crypto): Promise<boolean>; | ||
} |
@@ -1,42 +0,11 @@ | ||
/** | ||
* Crypto provider | ||
*/ | ||
export declare class CryptoProvider extends Map<string, Crypto> { | ||
static DEFAULT: string; | ||
/** | ||
* Returns `true` if data is CryptoKeyPair | ||
* @param data | ||
*/ | ||
static isCryptoKeyPair(data: any): data is CryptoKeyPair; | ||
static isCryptoKey(data: any): data is CryptoKey; | ||
/** | ||
* Creates a new instance | ||
*/ | ||
constructor(); | ||
/** | ||
* Returns default crypto | ||
* @throws Error whenever default provider not set | ||
*/ | ||
get(): Crypto; | ||
/** | ||
* Returns crypto by name | ||
* @param key Crypto name | ||
* @throws Error whenever provider with specified identifier does not exist | ||
*/ | ||
get(key: string): Crypto; | ||
/** | ||
* Sets default crypto | ||
* @param value | ||
*/ | ||
set(value: Crypto): this; | ||
/** | ||
* Sets crypto with specified identifier | ||
* @param key Identifier | ||
* @param value crypto provider | ||
*/ | ||
set(key: string, value: Crypto): this; | ||
} | ||
/** | ||
* Singleton crypto provider | ||
*/ | ||
export declare const cryptoProvider: CryptoProvider; |
import { SubjectPublicKeyInfo } from "@peculiar/asn1-x509"; | ||
import { AsnData } from "./asn_data"; | ||
/** | ||
* Representation of Subject Public Key Info | ||
*/ | ||
export declare class PublicKey extends AsnData<SubjectPublicKeyInfo> { | ||
/** | ||
* Gets a key algorithm | ||
*/ | ||
import { AsnEncodedType, PemData } from "./pem_data"; | ||
export declare class PublicKey extends PemData<SubjectPublicKeyInfo> { | ||
protected readonly tag: string; | ||
algorithm: Algorithm; | ||
/** | ||
* Returns a public CryptoKey | ||
* @param crypto Crypto provider. Default is from CryptoProvider | ||
*/ | ||
constructor(asn: SubjectPublicKeyInfo); | ||
constructor(raw: AsnEncodedType); | ||
export(crypto?: Crypto): Promise<CryptoKey>; | ||
/** | ||
* Returns a public CryptoKey with specified parameters | ||
* @param algorithm Algorithm | ||
* @param keyUsages A list of key usages | ||
* @param crypto Crypto provider. Default is from CryptoProvider | ||
*/ | ||
export(algorithm: Algorithm | EcKeyImportParams, keyUsages: KeyUsage[], crypto?: Crypto): Promise<CryptoKey>; | ||
protected onInit(asn: SubjectPublicKeyInfo): void; | ||
/** | ||
* Returns a SHA-1 public key thumbprint | ||
* @param crypto Crypto provider. Default is from CryptoProvider | ||
*/ | ||
getThumbprint(crypto?: Crypto): Promise<ArrayBuffer>; | ||
/** | ||
* Returns a public key thumbprint for specified mechanism | ||
* @param algorithm Hash algorithm | ||
* @param crypto Crypto provider. Default is from CryptoProvider | ||
*/ | ||
getThumbprint(algorithm: globalThis.AlgorithmIdentifier, crypto?: Crypto): Promise<ArrayBuffer>; | ||
} |
import { AlgorithmIdentifier } from "@peculiar/asn1-x509"; | ||
import { IAlgorithm } from "./algorithm"; | ||
import { HashedAlgorithm } from "./types"; | ||
/** | ||
* RSA algorithm provider | ||
*/ | ||
export declare class RsaAlgorithm implements IAlgorithm { | ||
@@ -8,0 +5,0 @@ toAsnAlgorithm(alg: HashedAlgorithm): AlgorithmIdentifier | null; |
@@ -5,30 +5,9 @@ import { Extension } from "./extension"; | ||
export declare type X509CertificateCreateParamsName = string | JsonName; | ||
/** | ||
* Base arguments for certificate creation | ||
*/ | ||
export interface X509CertificateCreateParamsBase { | ||
/** | ||
* Hexadecimal serial number | ||
*/ | ||
serialNumber: string; | ||
/** | ||
* Date before which certificate can't be used | ||
*/ | ||
notBefore: Date; | ||
/** | ||
* Date after which certificate can't be used | ||
*/ | ||
notAfter: Date; | ||
/** | ||
* List of extensions | ||
*/ | ||
extensions?: Extension[]; | ||
/** | ||
* Signing algorithm | ||
*/ | ||
signingAlgorithm: Algorithm | EcdsaParams; | ||
} | ||
/** | ||
* Parameters for X509 Certificate generation | ||
*/ | ||
export interface X509CertificateCreateParams extends X509CertificateCreateParamsBase { | ||
@@ -40,5 +19,2 @@ subject?: X509CertificateCreateParamsName; | ||
} | ||
/** | ||
* Parameters for self-signed X509 Certificate generation | ||
*/ | ||
export interface X509CertificateCreateSelfSignedParams extends X509CertificateCreateParamsBase { | ||
@@ -48,18 +24,5 @@ name?: X509CertificateCreateParamsName; | ||
} | ||
/** | ||
* Generator of X509 certificates | ||
*/ | ||
export declare class X509CertificateGenerator { | ||
/** | ||
* Creates a self-signed certificate | ||
* @param params Parameters | ||
* @param crypto Crypto provider. Default is from CryptoProvider | ||
*/ | ||
static createSelfSigned(params: X509CertificateCreateSelfSignedParams, crypto?: Crypto): Promise<X509Certificate>; | ||
/** | ||
* Creates a certificate signed by private key | ||
* @param params Parameters | ||
* @param crypto Crypto provider. Default is from CryptoProvider | ||
*/ | ||
static create(params: X509CertificateCreateParams, crypto?: Crypto): Promise<X509Certificate>; | ||
} |
import { Certificate } from "@peculiar/asn1-x509"; | ||
import { HashedAlgorithm } from "./types"; | ||
import { Extension } from "./extension"; | ||
import { AsnData } from "./asn_data"; | ||
import { PublicKey } from "./public_key"; | ||
/** | ||
* Verification params of X509 certificate | ||
*/ | ||
import { AsnEncodedType, PemData } from "./pem_data"; | ||
export interface X509CertificateVerifyParams { | ||
@@ -14,90 +11,24 @@ date?: Date; | ||
} | ||
/** | ||
* Representation of X509 certificate | ||
*/ | ||
export declare class X509Certificate extends AsnData<Certificate> { | ||
/** | ||
* ToBeSigned block of certificate | ||
*/ | ||
export declare class X509Certificate extends PemData<Certificate> { | ||
protected readonly tag: string; | ||
private tbs; | ||
/** | ||
* Gets a hexadecimal string of the serial number | ||
*/ | ||
serialNumber: string; | ||
/** | ||
* Gets a string subject name | ||
*/ | ||
subject: string; | ||
/** | ||
* Gets a string issuer name | ||
*/ | ||
issuer: string; | ||
/** | ||
* Gets a date before which certificate can't be used | ||
*/ | ||
notBefore: Date; | ||
/** | ||
* Gets a date after which certificate can't be used | ||
*/ | ||
notAfter: Date; | ||
/** | ||
* Gets a signature algorithm | ||
*/ | ||
signatureAlgorithm: HashedAlgorithm; | ||
/** | ||
* Gets a signature | ||
*/ | ||
signature: ArrayBuffer; | ||
/** | ||
* Gts a list of certificate extensions | ||
*/ | ||
extensions: Extension[]; | ||
/** | ||
* Gets a private key of the certificate | ||
*/ | ||
privateKey?: CryptoKey; | ||
/** | ||
* Gets a public key of the certificate | ||
*/ | ||
publicKey: PublicKey; | ||
/** | ||
* Creates a new instance from ASN.1 Certificate object | ||
* @param asn ASN.1 Certificate object | ||
*/ | ||
constructor(asn: Certificate); | ||
/** | ||
* Creates a new instance from DER encoded buffer | ||
* @param raw DER encoded buffer | ||
*/ | ||
constructor(raw: BufferSource); | ||
constructor(raw: AsnEncodedType); | ||
protected onInit(asn: Certificate): void; | ||
/** | ||
* Returns an extension of specified type | ||
* @param type Extension identifier | ||
* @returns Extension or null | ||
*/ | ||
getExtension<T extends Extension>(type: string): T | null; | ||
/** | ||
* Returns a list of extensions of specified type | ||
* @param type Extension identifier | ||
*/ | ||
getExtensions<T extends Extension>(type: string): T[]; | ||
/** | ||
* Validates a certificate signature | ||
* @param params Verification parameters | ||
* @param crypto Crypto provider. Default is from CryptoProvider | ||
*/ | ||
verify(params: X509CertificateVerifyParams, crypto?: Crypto): Promise<boolean>; | ||
/** | ||
* Returns a SHA-1 certificate thumbprint | ||
* @param crypto Crypto provider. Default is from CryptoProvider | ||
*/ | ||
getThumbprint(crypto?: Crypto): Promise<ArrayBuffer>; | ||
/** | ||
* Returns a certificate thumbprint for specified mechanism | ||
* @param algorithm Hash algorithm | ||
* @param crypto Crypto provider. Default is from CryptoProvider | ||
*/ | ||
getThumbprint(algorithm: globalThis.AlgorithmIdentifier, crypto?: Crypto): Promise<ArrayBuffer>; | ||
isSelfSigned(): Promise<boolean>; | ||
} |
@@ -0,38 +1,14 @@ | ||
import { AsnEncodedType, AsnExportType } from "./pem_data"; | ||
import { X509Certificate } from "./x509_cert"; | ||
/** | ||
* X509 Certificate collection | ||
*/ | ||
export declare class X509Certificates extends Array<X509Certificate> { | ||
/** | ||
* Creates a new instance | ||
*/ | ||
constructor(); | ||
/** | ||
* Creates a new instance from DER encoded PKCS7 buffer | ||
* @param raw DER encoded PKCS7 buffer | ||
*/ | ||
constructor(raw: BufferSource); | ||
/** | ||
* Creates a new instance form X509 certificate | ||
* @param cert X509 certificate | ||
*/ | ||
constructor(raw: AsnEncodedType); | ||
constructor(cert: X509Certificate); | ||
/** | ||
* Creates a new instance from a list of x509 certificates | ||
* @param certs List of x509 certificates | ||
*/ | ||
constructor(certs: X509Certificate[]); | ||
/** | ||
* Returns a DER encoded PKCS7 buffer | ||
*/ | ||
export(): ArrayBuffer; | ||
/** | ||
* Import certificates from DER encoded PKCS7 buffer | ||
* @param data | ||
*/ | ||
import(data: BufferSource): void; | ||
/** | ||
* Removes all items from collection | ||
*/ | ||
export(): string; | ||
export(format: "raw"): ArrayBuffer; | ||
export(format?: AsnExportType): string; | ||
import(data: AsnEncodedType): void; | ||
clear(): void; | ||
toString(format?: AsnEncodedType): string; | ||
} |
import { X509Certificate } from "./x509_cert"; | ||
import { X509Certificates } from "./x509_certs"; | ||
/** | ||
* Represents a chain-building engine for X509Certificate certificates | ||
* @example | ||
* ```js | ||
* const chain = new x509.X509ChainBuilder({ | ||
* certificates: [ | ||
* new x509.X509Certificate(raw1), | ||
* new x509.X509Certificate(raw2), | ||
* // ... | ||
* new x509.X509Certificate(rawN), | ||
* ], | ||
* }); | ||
* | ||
* const cert = x509.X509Certificate(raw); | ||
* const items = await chain.build(cert); | ||
* ``` | ||
*/ | ||
export declare class X509ChainBuilder { | ||
@@ -21,0 +4,0 @@ certificates: X509Certificate[]; |
{ | ||
"name": "@peculiar/x509", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"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", | ||
"main": "build/cjs/index.js", | ||
"module": "build/es2015/index.js", | ||
"main": "build/x509.cjs.js", | ||
"module": "build/x509.es.js", | ||
"browser": "build/x509.js", | ||
"types": "build/types/index.d.ts", | ||
@@ -14,5 +15,3 @@ "scripts": { | ||
"build": "npm run build:module && npm run build:types", | ||
"build:module": "npm run build:cjs && npm run build:es2015", | ||
"build:cjs": "tsc -p tsconfig.json --removeComments --module commonjs --outDir build/cjs", | ||
"build:es2015": "tsc -p tsconfig.json --removeComments --module ES2015 --outDir build/es2015", | ||
"build:module": "rollup -c", | ||
"prebuild:types": "rimraf build/types", | ||
@@ -88,12 +87,20 @@ "build:types": "tsc -p tsconfig.json --outDir build/types --declaration --emitDeclarationOnly", | ||
"devDependencies": { | ||
"@babel/core": "^7.11.6", | ||
"@babel/preset-env": "^7.11.5", | ||
"@peculiar/webcrypto": "^1.1.3", | ||
"@rollup/plugin-babel": "^5.2.1", | ||
"@rollup/plugin-commonjs": "^15.1.0", | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
"@types/mocha": "^8.0.3", | ||
"@types/node": "^14.11.1", | ||
"@typescript-eslint/eslint-plugin": "^4.1.1", | ||
"@typescript-eslint/parser": "^4.1.1", | ||
"@types/node": "^14.11.2", | ||
"@typescript-eslint/eslint-plugin": "^4.3.0", | ||
"@typescript-eslint/parser": "^4.3.0", | ||
"coveralls": "^3.1.0", | ||
"eslint": "^7.9.0", | ||
"eslint": "^7.10.0", | ||
"mocha": "^8.1.3", | ||
"nyc": "^15.1.0", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.28.2", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"rollup-plugin-typescript2": "^0.27.2", | ||
"ts-node": "^9.0.0", | ||
@@ -111,3 +118,3 @@ "typedoc": "^0.19.2", | ||
"@peculiar/asn1-x509": "^2.0.22", | ||
"pvtsutils": "^1.0.12", | ||
"pvtsutils": "^1.0.13", | ||
"reflect-metadata": "^0.1.13", | ||
@@ -114,0 +121,0 @@ "tslib": "^2.0.1", |
@@ -12,2 +12,3 @@ # @peculiar/x509 | ||
- [Usage](#usage) | ||
- [Browser](#browser) | ||
- [Set crypto provider for Node.js](#set-crypto-provider-for-nodejs) | ||
@@ -37,2 +38,16 @@ - [Create a self-signed certificate](#create-a-self-signed-certificate) | ||
### Browser | ||
Every release of `@peculiar/x509` will have new build of `./build/x509.js` for use in the browser. To get access to module classes use `x509` global variable. | ||
> WARN: We recommend hosting and controlling your own copy for security reasons | ||
```html | ||
<script src="https://unpkg.com/@peculiar/x509"></script> | ||
``` | ||
A simple web application examples | ||
- [Generate X509 certificate](https://codesandbox.io/s/generate-cert-fjwfh) | ||
- [Generate PKCS#10 certificate request](https://codesandbox.io/s/generate-csr-0qhed) | ||
### Set crypto provider for Node.js | ||
@@ -54,4 +69,2 @@ | ||
```js | ||
import * as x509 from "@peculiar/x509"; | ||
const alg = { | ||
@@ -78,2 +91,4 @@ name: "RSASSA-PKCS1-v1_5", | ||
}); | ||
console.log(cert.toString("pem")); // Certificate in PEM format | ||
``` | ||
@@ -83,8 +98,5 @@ | ||
```js | ||
import * as x509 from "@peculiar/x509"; | ||
const base64 = "MIIDljCCAn6gAwIBAgIOSETcxtRwD...S+kAFXIwugUGYEnTWp0m5bAn5NlD314IEOg4mnS8Q=="; | ||
const raw = Buffer.from(base64, "base64"); | ||
const cert = new x509.X509Certificate(raw); | ||
const cert = new x509.X509Certificate(base64); | ||
console.log(cert.subject); // CN=Test, O=PeculiarVentures LLC | ||
@@ -95,4 +107,2 @@ ``` | ||
```js | ||
import * as x509 from "@peculiar/x509"; | ||
const alg = { | ||
@@ -115,2 +125,4 @@ name: "ECDSA", | ||
}); | ||
console.log(cert.toString("base64")); // Certificate request in Base64 format | ||
``` | ||
@@ -186,4 +198,2 @@ | ||
```js | ||
import * as x509 from "@peculiar/x509"; | ||
const chain = new x509.X509ChainBuilder({ | ||
@@ -205,11 +215,8 @@ certificates: [ | ||
```js | ||
import * as x509 from "@peculiar/x509"; | ||
const certs = new x509.X509Certificates([ | ||
new x509.X509Certificate(Buffer.from("MIIDljCCAn6gAwIBAgIOSETcxtRwD...S+kAFXIwugUGYEnTWp0m5bAn5NlD314IEOg4mnS8Q==", "base64")), | ||
new x509.X509Certificate(Buffer.from("MIIDljCCAn6gAwIBAgIOSETcxtRwD...w8Y/o+hk3QzNBVa3ZUvzDhVAmamQflvw3lXMm/JG4U=", "base64")), | ||
new x509.X509Certificate("MIIDljCCAn6gAwIBAgIOSETcxtRwD...S+kAFXIwugUGYEnTWp0m5bAn5NlD314IEOg4mnS8Q=="), | ||
new x509.X509Certificate("MIIDljCCAn6gAwIBAgIOSETcxtRwD...w8Y/o+hk3QzNBVa3ZUvzDhVAmamQflvw3lXMm/JG4U="), | ||
]); | ||
const base64 = Buffer.from(await cert.export()).toString("base64"); | ||
console.log(base64); // "MIICTAYJKoZIhvcNAQcCoIICPTCCAjkCAQAxADACBgCgggIq...F7EZPNo3pjbfznpIilRMRrmwf5dkgCdSKDdE94xAA=="); | ||
console.log(certs.export("base64")); // "MIICTAYJKoZIhvcNAQcCoIICPTCCAjkCAQAxADACBgCgggIq...F7EZPNo3pjbfznpIilRMRrmwf5dkgCdSKDdE94xAA=="); | ||
``` |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
284395
3378
214
21
36
1
Updatedpvtsutils@^1.0.13