import * as asn1js from "asn1js"; import * as pvutils from "pvutils"; import { ResponseBytes, ResponseBytesJson, ResponseBytesSchema } from "./ResponseBytes"; import { BasicOCSPResponse } from "./BasicOCSPResponse"; import * as Schema from "./Schema"; import { Certificate } from "./Certificate"; import { id_PKIX_OCSP_Basic } from "./ObjectIdentifiers"; import { AsnError } from "./errors"; import { PkiObject, PkiObjectParameters } from "./PkiObject"; import * as common from "./common";
public responseStatus!: asn1js.Enumerated; public responseBytes?: ResponseBytes;
/** * Initializes a new instance of the {@link OCSPResponse} class * @param parameters Initialization parameters
*/
constructor(parameters: OCSPResponseParameters = {}) { super();
this.responseStatus = pvutils.getParametersValue(parameters, RESPONSE_STATUS, OCSPResponse.defaultValues(RESPONSE_STATUS)); if (RESPONSE_BYTES in parameters) { this.responseBytes = pvutils.getParametersValue(parameters, RESPONSE_BYTES, OCSPResponse.defaultValues(RESPONSE_BYTES));
}
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 RESPONSE_STATUS): asn1js.Enumerated; publicstatic override defaultValues(memberName: typeof RESPONSE_BYTES): ResponseBytes; publicstatic override defaultValues(memberName: string): any { switch (memberName) { case RESPONSE_STATUS: returnnew asn1js.Enumerated(); case RESPONSE_BYTES: returnnew ResponseBytes(); 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 RESPONSE_STATUS: return (memberValue.isEqual(OCSPResponse.defaultValues(memberName))); case RESPONSE_BYTES: return ((ResponseBytes.compareWithDefault("responseType", memberValue.responseType)) &&
(ResponseBytes.compareWithDefault("response", memberValue.response))); default: returnsuper.defaultValues(memberName);
}
}
public fromSchema(schema: Schema.SchemaType): void { // Clear input data first
pvutils.clearProps(schema, [
RESPONSE_STATUS,
RESPONSE_BYTES
]);
// Check the schema is valid const asn1 = asn1js.compareSchema(schema,
schema,
OCSPResponse.schema()
);
AsnError.assertSchema(asn1, this.className);
// Get internal properties from parsed schema this.responseStatus = asn1.result.responseStatus; if (RESPONSE_BYTES in asn1.result) this.responseBytes = new ResponseBytes({ schema: asn1.result.responseBytes });
}
public toSchema(): asn1js.Sequence { //#region Create array for output sequence const outputArray = [];
/** * Make a signature for current OCSP Response * @param privateKey Private key for "subjectPublicKeyInfo" structure * @param hashAlgorithm Hashing algorithm. Default SHA-1
*/ public async sign(privateKey: CryptoKey, hashAlgorithm?: string, crypto = common.getCrypto(true)) { //#region Check that ResponseData has type BasicOCSPResponse and sign it if (this.responseBytes && this.responseBytes.responseType === id_PKIX_OCSP_Basic) { const basicResponse = BasicOCSPResponse.fromBER(this.responseBytes.response.valueBlock.valueHexView);
/** * Verify current OCSP Response * @param issuerCertificate In order to decrease size of resp issuer cert could be omitted. In such case you need manually provide it. * @param crypto Crypto engine
*/ public async verify(issuerCertificate: Certificate | null = null, crypto = common.getCrypto(true)): Promise<boolean> { //#region Check that ResponseBytes exists in the object if ((RESPONSE_BYTES in this) === false) thrownew Error("Empty ResponseBytes field"); //#endregion
//#region Check that ResponseData has type BasicOCSPResponse and verify it if (this.responseBytes && this.responseBytes.responseType === id_PKIX_OCSP_Basic) { const basicResponse = BasicOCSPResponse.fromBER(this.responseBytes.response.valueBlock.valueHexView);
if (issuerCertificate !== null) { if (!basicResponse.certs) {
basicResponse.certs = [];
}
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.