import * as asn1js from "asn1js"; import * as pvtsutils from "pvtsutils"; import * as pvutils from "pvutils"; import * as common from "./common"; import { AlgorithmIdentifier, AlgorithmIdentifierJson, AlgorithmIdentifierSchema } from "./AlgorithmIdentifier"; import { Certificate } from "./Certificate"; import * as Schema from "./Schema"; import { AsnError, ParameterError } from "./errors"; import { PkiObject, PkiObjectParameters } from "./PkiObject"; import { EMPTY_STRING } from "./constants";
export interface ICertID { /** * Hash algorithm used to generate the `issuerNameHash` and `issuerKeyHash` values
*/
hashAlgorithm: AlgorithmIdentifier; /** * Hash of the issuer's distinguished name (DN). The hash shall be calculated over the DER encoding * of the issuer's name field in the certificate being checked.
*/
issuerNameHash: asn1js.OctetString; /** * Hash of the issuer's public key. The hash shall be calculated over the value (excluding tag and length) * of the subject public key field in the issuer's certificate.
*/
issuerKeyHash: asn1js.OctetString; /** * Serial number of the certificate for which status is being requested
*/
serialNumber: asn1js.Integer;
}
export type CertIDParameters = PkiObjectParameters & Partial<ICertID>;
/** * Making OCSP certificate identifier for specific certificate * @param certificate Certificate making OCSP Request for * @param parameters Additional parameters * @param crypto Crypto engine * @returns Returns created CertID object
*/ publicstatic async create(certificate: Certificate, parameters: CertIDCreateParams, crypto = common.getCrypto(true)): Promise<CertID> { const certID = new CertID();
await certID.createForCertificate(certificate, parameters, crypto);
return certID;
}
public hashAlgorithm!: AlgorithmIdentifier; public issuerNameHash!: asn1js.OctetString; public issuerKeyHash!: asn1js.OctetString; public serialNumber!: asn1js.Integer;
/** * Initializes a new instance of the {@link CertID} class * @param parameters Initialization parameters
*/
constructor(parameters: CertIDParameters = {}) { super();
if (parameters.schema) { this.fromSchema(parameters.schema);
}
}
/** * Returns default values for all class members * @param memberName String name for a class member * @returns Default value
*/ publicstatic override defaultValues(memberName: typeof HASH_ALGORITHM): AlgorithmIdentifier; publicstatic override defaultValues(memberName: typeof ISSUER_NAME_HASH): asn1js.OctetString; publicstatic override defaultValues(memberName: typeof ISSUER_KEY_HASH): asn1js.OctetString; publicstatic override defaultValues(memberName: typeof SERIAL_NUMBER): asn1js.Integer; publicstatic override defaultValues(memberName: string): any { switch (memberName) { case HASH_ALGORITHM: returnnew AlgorithmIdentifier(); case ISSUER_NAME_HASH: case ISSUER_KEY_HASH: returnnew asn1js.OctetString(); case SERIAL_NUMBER: returnnew asn1js.Integer(); default: returnsuper.defaultValues(memberName);
}
}
/** * Compare values with default values for all class members * @param memberName String name for a class member * @param memberValue Value to compare with default value
*/ publicstatic compareWithDefault(memberName: string, memberValue: any): boolean { switch (memberName) { case HASH_ALGORITHM: return ((memberValue.algorithmId === EMPTY_STRING) && (("algorithmParams" in memberValue) === false)); case ISSUER_NAME_HASH: case ISSUER_KEY_HASH: case SERIAL_NUMBER: return (memberValue.isEqual(CertID.defaultValues(SERIAL_NUMBER))); default: returnsuper.defaultValues(memberName);
}
}
/** * Checks that two "CertIDs" are equal * @param certificateID Identifier of the certificate to be checked
*/ public isEqual(certificateID: CertID): boolean { // Check HASH_ALGORITHM if (this.hashAlgorithm.algorithmId !== certificateID.hashAlgorithm.algorithmId) { returnfalse;
}
// Check ISSUER_NAME_HASH if (!pvtsutils.BufferSourceConverter.isEqual(this.issuerNameHash.valueBlock.valueHexView, certificateID.issuerNameHash.valueBlock.valueHexView)) { returnfalse;
}
// Check ISSUER_KEY_HASH if (!pvtsutils.BufferSourceConverter.isEqual(this.issuerKeyHash.valueBlock.valueHexView, certificateID.issuerKeyHash.valueBlock.valueHexView)) { returnfalse;
}
// Check SERIAL_NUMBER if (!this.serialNumber.isEqual(certificateID.serialNumber)) { returnfalse;
}
returntrue;
}
/** * Making OCSP certificate identifier for specific certificate * @param certificate Certificate making OCSP Request for * @param parameters Additional parameters * @param crypto Crypto engine
*/ public async createForCertificate(certificate: Certificate, parameters: CertIDCreateParams, crypto = common.getCrypto(true)): Promise<void> { //#region Check input parameters
ParameterError.assert(parameters, HASH_ALGORITHM, "issuerCertificate");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.