CertificationRequest
Represents the CertificationRequest structure described in RFC2986
Examples
Section titled “Examples”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 extensionif (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 valueconst 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" extensionconst 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 Nameconst altNames = new pkijs.GeneralNames({ names: [ new pkijs.GeneralName({ // email type: 1, }), new pkijs.GeneralName({ // domain type: 2, value: "www.domain.com" }), ]});
// SubjectKeyIdentifierconst 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 requestawait pkcs10.sign(keys.privateKey, "SHA-256");
const pkcs10Raw = pkcs10.toSchema(true).toBER();Extends
Section titled “Extends”Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new CertificationRequest(
parameters?):CertificationRequest
Initializes a new instance of the CertificationRequest class
Parameters
Section titled “Parameters”parameters?
Section titled “parameters?”CertificationRequestParameters = {}
Initialization parameters
Returns
Section titled “Returns”CertificationRequest
Overrides
Section titled “Overrides”Properties
Section titled “Properties”attributes?
Section titled “attributes?”
optionalattributes?:Attribute[]
Collection of attributes providing additional information about the subject of the certificate
Implementation of
Section titled “Implementation of”ICertificationRequest.attributes
signatureAlgorithm
Section titled “signatureAlgorithm”signatureAlgorithm:
AlgorithmIdentifier
signature algorithm (and any associated parameters) under which the certification-request information is signed
Implementation of
Section titled “Implementation of”ICertificationRequest.signatureAlgorithm
signatureValue
Section titled “signatureValue”signatureValue:
BitString
result of signing the certification request information with the certification request subject’s private key
Implementation of
Section titled “Implementation of”ICertificationRequest.signatureValue
subject
Section titled “subject”subject:
RelativeDistinguishedNames
Distinguished name of the certificate subject
Implementation of
Section titled “Implementation of”subjectPublicKeyInfo
Section titled “subjectPublicKeyInfo”subjectPublicKeyInfo:
PublicKeyInfo
Information about the public key being certified
Implementation of
Section titled “Implementation of”ICertificationRequest.subjectPublicKeyInfo
tbsView
Section titled “tbsView”tbsView:
Uint8Array
version
Section titled “version”version:
number
Version number. It should be 0
Implementation of
Section titled “Implementation of”CLASS_NAME
Section titled “CLASS_NAME”
staticCLASS_NAME:string="CertificationRequest"
Name of the class
Overrides
Section titled “Overrides”Accessors
Section titled “Accessors”className
Section titled “className”Get Signature
Section titled “Get Signature”get className():
string
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get tbs():
ArrayBuffer
Returns
Section titled “Returns”ArrayBuffer
Set Signature
Section titled “Set Signature”set tbs(
value):void
Parameters
Section titled “Parameters”ArrayBuffer
Returns
Section titled “Returns”void
Value being signed
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”fromSchema()
Section titled “fromSchema()”fromSchema(
schema):void
Converts parsed ASN.1 object into current class
Parameters
Section titled “Parameters”schema
Section titled “schema”any
ASN.1 schema
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”getPublicKey()
Section titled “getPublicKey()”getPublicKey(
parameters?,crypto?):Promise<CryptoKey>
Importing public key for current certificate request
Parameters
Section titled “Parameters”parameters?
Section titled “parameters?”crypto?
Section titled “crypto?”ICryptoEngine = ...
Crypto engine
Returns
Section titled “Returns”Promise<CryptoKey>
WebCrypt public key
sign()
Section titled “sign()”sign(
privateKey,hashAlgorithm?,crypto?):Promise<void>
Makes signature for current certification request
Parameters
Section titled “Parameters”privateKey
Section titled “privateKey”CryptoKey
WebCrypto private key
hashAlgorithm?
Section titled “hashAlgorithm?”string = "SHA-1"
String representing current hashing algorithm
crypto?
Section titled “crypto?”ICryptoEngine = ...
Crypto engine
Returns
Section titled “Returns”Promise<void>
toJSON()
Section titled “toJSON()”toJSON():
CertificationRequestJson
Converts the class to JSON object
Returns
Section titled “Returns”JSON object
Overrides
Section titled “Overrides”toSchema()
Section titled “toSchema()”toSchema(
encodeFlag?):Sequence
Converts current object to ASN.1 object and sets correct values
Parameters
Section titled “Parameters”encodeFlag?
Section titled “encodeFlag?”boolean = false
If param equal to false then creates schema via decoding stored value. In other case creates schema via assembling from cached parts
Returns
Section titled “Returns”Sequence
ASN.1 object
Overrides
Section titled “Overrides”toString()
Section titled “toString()”toString(
encoding?):string
Parameters
Section titled “Parameters”encoding?
Section titled “encoding?”"hex" | "base64" | "base64url" = "hex"
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”verify()
Section titled “verify()”verify(
crypto?):Promise<boolean>
Verify existing certification request signature
Parameters
Section titled “Parameters”crypto?
Section titled “crypto?”ICryptoEngine = ...
Crypto engine
Returns
Section titled “Returns”Promise<boolean>
Returns true if signature value is valid, otherwise false
blockName()
Section titled “blockName()”
staticblockName():string
Returns block name
Returns
Section titled “Returns”string
Returns string block name
Inherited from
Section titled “Inherited from”defaultValues()
Section titled “defaultValues()”Call Signature
Section titled “Call Signature”
staticdefaultValues(memberName):ArrayBuffer
Returns default values for all class members
Parameters
Section titled “Parameters”memberName
Section titled “memberName”"tbs"
String name for a class member
Returns
Section titled “Returns”ArrayBuffer
Default value
Overrides
Section titled “Overrides”Call Signature
Section titled “Call Signature”
staticdefaultValues(memberName):number
Returns default values for all class members
Parameters
Section titled “Parameters”memberName
Section titled “memberName”"version"
String name for a class member
Returns
Section titled “Returns”number
Default value
Overrides
Section titled “Overrides”PkiObject.defaultValues
Call Signature
Section titled “Call Signature”
staticdefaultValues(memberName):RelativeDistinguishedNames
Returns default values for all class members
Parameters
Section titled “Parameters”memberName
Section titled “memberName”"subject"
String name for a class member
Returns
Section titled “Returns”Default value
Overrides
Section titled “Overrides”PkiObject.defaultValues
Call Signature
Section titled “Call Signature”
staticdefaultValues(memberName):PublicKeyInfo
Returns default values for all class members
Parameters
Section titled “Parameters”memberName
Section titled “memberName”"subjectPublicKeyInfo"
String name for a class member
Returns
Section titled “Returns”Default value
Overrides
Section titled “Overrides”PkiObject.defaultValues
Call Signature
Section titled “Call Signature”
staticdefaultValues(memberName):Attribute[]
Returns default values for all class members
Parameters
Section titled “Parameters”memberName
Section titled “memberName”"attributes"
String name for a class member
Returns
Section titled “Returns”Default value
Overrides
Section titled “Overrides”PkiObject.defaultValues
Call Signature
Section titled “Call Signature”
staticdefaultValues(memberName):AlgorithmIdentifier
Returns default values for all class members
Parameters
Section titled “Parameters”memberName
Section titled “memberName”"signatureAlgorithm"
String name for a class member
Returns
Section titled “Returns”Default value
Overrides
Section titled “Overrides”PkiObject.defaultValues
Call Signature
Section titled “Call Signature”
staticdefaultValues(memberName):BitString
Returns default values for all class members
Parameters
Section titled “Parameters”memberName
Section titled “memberName”"signatureValue"
String name for a class member
Returns
Section titled “Returns”BitString
Default value
Overrides
Section titled “Overrides”PkiObject.defaultValues
fromBER()
Section titled “fromBER()”
staticfromBER<T>(this,raw):T
Creates PKI object from the raw data
Type Parameters
Section titled “Type Parameters”T extends PkiObject
Parameters
Section titled “Parameters”PkiObjectConstructor<T>
BufferSource
ASN.1 encoded raw data
Returns
Section titled “Returns”T
Initialized and filled current class object
Inherited from
Section titled “Inherited from”schema()
Section titled “schema()”
staticschema(parameters?):any
Returns value of pre-defined ASN.1 schema for current class
Parameters
Section titled “Parameters”parameters?
Section titled “parameters?”SchemaParameters<{ certificationRequestInfo?: CertificationRequestInfoParameters; signatureAlgorithm?: string; signatureValue?: string; }> = {}
Input parameters for the schema
Returns
Section titled “Returns”any
ASN.1 schema object