Skip to content
PKIjsPKIjsPKIjsv4.0.1

CertificationRequest

Represents the CertificationRequest structure described in RFC2986

The following example demonstrates how to parse PKCS#11 certification request

and verify its challenge password extension and signature value

const pkcs10 = pkijs.CertificationRequest.fromBER(pkcs10Raw);
// Get and validate challenge password extension
if (pkcs10.attributes) {
const attrExtensions = pkcs10.attributes.find(o => o.type === "1.2.840.113549.1.9.14"); // pkcs-9-at-extensionRequest
if (attrExtensions) {
const extensions = new pkijs.Extensions({ schema: attrExtensions.values[0] });
for (const extension of extensions.extensions) {
if (extension.extnID === "1.2.840.113549.1.9.7") { // pkcs-9-at-challengePassword
const asn = asn1js.fromBER(extension.extnValue.valueBlock.valueHex);
if (asn.result.valueBlock.value !== "passwordChallenge") {
throw new Error("PKCS#11 certification request is invalid. Challenge password is incorrect");
}
}
}
}
}
// Verify signature value
const ok = await pkcs10.verify();
if (!ok) {
throw Error("PKCS#11 certification request is invalid. Signature is wrong")
}

The following example demonstrates how to create PKCS#11 certification request

// Get a "crypto" extension
const crypto = pkijs.getCrypto(true);
const pkcs10 = new pkijs.CertificationRequest();
pkcs10.subject.typesAndValues.push(new pkijs.AttributeTypeAndValue({
type: "2.5.4.3",
value: new asn1js.Utf8String({ value: "Test" })
}));
await pkcs10.subjectPublicKeyInfo.importKey(keys.publicKey);
pkcs10.attributes = [];
// Subject Alternative Name
const altNames = new pkijs.GeneralNames({
names: [
new pkijs.GeneralName({ // email
type: 1,
}),
new pkijs.GeneralName({ // domain
type: 2,
value: "www.domain.com"
}),
]
});
// SubjectKeyIdentifier
const subjectKeyIdentifier = await crypto.digest({ name: "SHA-1" }, pkcs10.subjectPublicKeyInfo.subjectPublicKey.valueBlock.valueHex);
pkcs10.attributes.push(new pkijs.Attribute({
type: "1.2.840.113549.1.9.14", // pkcs-9-at-extensionRequest
values: [(new pkijs.Extensions({
extensions: [
new pkijs.Extension({
extnID: "2.5.29.14", // id-ce-subjectKeyIdentifier
critical: false,
extnValue: (new asn1js.OctetString({ valueHex: subjectKeyIdentifier })).toBER(false)
}),
new pkijs.Extension({
extnID: "2.5.29.17", // id-ce-subjectAltName
critical: false,
extnValue: altNames.toSchema().toBER(false)
}),
new pkijs.Extension({
extnID: "1.2.840.113549.1.9.7", // pkcs-9-at-challengePassword
critical: false,
extnValue: (new asn1js.PrintableString({ value: "passwordChallenge" })).toBER(false)
})
]
})).toSchema()]
}));
// Signing final PKCS#10 request
await pkcs10.sign(keys.privateKey, "SHA-256");
const pkcs10Raw = pkcs10.toSchema(true).toBER();

new CertificationRequest(parameters?): CertificationRequest

Initializes a new instance of the CertificationRequest class

CertificationRequestParameters = {}

Initialization parameters

CertificationRequest

PkiObject.constructor

optional attributes?: Attribute[]

Collection of attributes providing additional information about the subject of the certificate

ICertificationRequest.attributes


signatureAlgorithm: AlgorithmIdentifier

signature algorithm (and any associated parameters) under which the certification-request information is signed

ICertificationRequest.signatureAlgorithm


signatureValue: BitString

result of signing the certification request information with the certification request subject’s private key

ICertificationRequest.signatureValue


subject: RelativeDistinguishedNames

Distinguished name of the certificate subject

ICertificationRequest.subject


subjectPublicKeyInfo: PublicKeyInfo

Information about the public key being certified

ICertificationRequest.subjectPublicKeyInfo


tbsView: Uint8Array


version: number

Version number. It should be 0

ICertificationRequest.version


static CLASS_NAME: string = "CertificationRequest"

Name of the class

PkiObject.CLASS_NAME

get className(): string

string

PkiObject.className


get tbs(): ArrayBuffer

ArrayBuffer

set tbs(value): void

ArrayBuffer

void

Value being signed

ICertificationRequest.tbs

fromSchema(schema): void

Converts parsed ASN.1 object into current class

any

ASN.1 schema

void

PkiObject.fromSchema


getPublicKey(parameters?, crypto?): Promise<CryptoKey>

Importing public key for current certificate request

CryptoEnginePublicKeyParams

ICryptoEngine = ...

Crypto engine

Promise<CryptoKey>

WebCrypt public key


sign(privateKey, hashAlgorithm?, crypto?): Promise<void>

Makes signature for current certification request

CryptoKey

WebCrypto private key

string = "SHA-1"

String representing current hashing algorithm

ICryptoEngine = ...

Crypto engine

Promise<void>


toJSON(): CertificationRequestJson

Converts the class to JSON object

CertificationRequestJson

JSON object

PkiObject.toJSON


toSchema(encodeFlag?): Sequence

Converts current object to ASN.1 object and sets correct values

boolean = false

If param equal to false then creates schema via decoding stored value. In other case creates schema via assembling from cached parts

Sequence

ASN.1 object

PkiObject.toSchema


toString(encoding?): string

"hex" | "base64" | "base64url" = "hex"

string

PkiObject.toString


verify(crypto?): Promise<boolean>

Verify existing certification request signature

ICryptoEngine = ...

Crypto engine

Promise<boolean>

Returns true if signature value is valid, otherwise false


static blockName(): string

Returns block name

string

Returns string block name

PkiObject.blockName


static defaultValues(memberName): ArrayBuffer

Returns default values for all class members

"tbs"

String name for a class member

ArrayBuffer

Default value

PkiObject.defaultValues

static defaultValues(memberName): number

Returns default values for all class members

"version"

String name for a class member

number

Default value

PkiObject.defaultValues

static defaultValues(memberName): RelativeDistinguishedNames

Returns default values for all class members

"subject"

String name for a class member

RelativeDistinguishedNames

Default value

PkiObject.defaultValues

static defaultValues(memberName): PublicKeyInfo

Returns default values for all class members

"subjectPublicKeyInfo"

String name for a class member

PublicKeyInfo

Default value

PkiObject.defaultValues

static defaultValues(memberName): Attribute[]

Returns default values for all class members

"attributes"

String name for a class member

Attribute[]

Default value

PkiObject.defaultValues

static defaultValues(memberName): AlgorithmIdentifier

Returns default values for all class members

"signatureAlgorithm"

String name for a class member

AlgorithmIdentifier

Default value

PkiObject.defaultValues

static defaultValues(memberName): BitString

Returns default values for all class members

"signatureValue"

String name for a class member

BitString

Default value

PkiObject.defaultValues


static fromBER<T>(this, raw): T

Creates PKI object from the raw data

T extends PkiObject

PkiObjectConstructor<T>

BufferSource

ASN.1 encoded raw data

T

Initialized and filled current class object

PkiObject.fromBER


static schema(parameters?): any

Returns value of pre-defined ASN.1 schema for current class

SchemaParameters<{ certificationRequestInfo?: CertificationRequestInfoParameters; signatureAlgorithm?: string; signatureValue?: string; }> = {}

Input parameters for the schema

any

ASN.1 schema object

PkiObject.schema