import * as asn1js from "asn1js"; import * as pvutils from "pvutils"; import * as common from "./common"; import { TBSRequest, TBSRequestJson, TBSRequestSchema } from "./TBSRequest"; import { Signature, SignatureJson, SignatureSchema } from "./Signature"; import { Request } from "./Request"; import { CertID, CertIDCreateParams } from "./CertID"; import * as Schema from "./Schema"; import { Certificate } from "./Certificate"; import { AsnError, ParameterError } from "./errors"; import { PkiObject, PkiObjectParameters } from "./PkiObject";
public fromSchema(schema: Schema.SchemaType): void { // Clear input data first
pvutils.clearProps(schema, CLEAR_PROPS);
// Check the schema is valid const asn1 = asn1js.compareSchema(schema,
schema,
OCSPRequest.schema()
);
AsnError.assertSchema(asn1, this.className);
// Get internal properties from parsed schema this.tbsRequest = new TBSRequest({ schema: asn1.result.tbsRequest }); if (OPTIONAL_SIGNATURE in asn1.result) this.optionalSignature = new Signature({ schema: asn1.result.optionalSignature });
}
public toSchema(encodeFlag = false) { //#region Create array for output sequence const outputArray = [];
// Check that OPTIONAL_SIGNATURE exists in the current request if (!this.optionalSignature) { thrownew Error("Need to create \"optionalSignature\" field before signing");
}
//#region Get a "default parameters" for current algorithm and set correct signature algorithm const signatureParams = await crypto.getSignatureParameters(privateKey, hashAlgorithm); const parameters = signatureParams.parameters; this.optionalSignature.signatureAlgorithm = signatureParams.signatureAlgorithm; //#endregion
//#region Create TBS data for signing const tbs = this.tbsRequest.toSchema(true).toBER(false); //#endregion
// Signing TBS data on provided private key const signature = await crypto.signWithPrivateKey(tbs, privateKey, parameters as any); this.optionalSignature.signature = new asn1js.BitString({ valueHex: signature });
}
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.