Skip to content
Snippets Groups Projects
Commit 4cd3745f authored by Zdravko Iliev's avatar Zdravko Iliev
Browse files

debug info public key

parent 0b9643d4
No related branches found
No related tags found
1 merge request!83Exchange 2016 support
......@@ -314,9 +314,9 @@ function fixPkijsRDN() {
//region Decode stored TBS value
if (this.valueBeforeDecode.byteLength === 0) // No stored encoded array, create "from scratch"
{
return (new asn1js.Sequence({
return new asn1js.Sequence({
value: Array.from(this.typesAndValues, element => new asn1js.Set({value: [element.toSchema()]}))
}));
});
}
const asn1 = asn1js.fromBER(this.valueBeforeDecode);
......@@ -330,7 +330,6 @@ function fixPkijsRDN() {
//*********************************************************************************
function createCertificate(certData, issuerData = null) {
if (typeof certData === "undefined" || certData === null) {
return Promise.reject("No Certificate data provided");
}
......@@ -596,9 +595,9 @@ function createCertificate(certData, issuerData = null) {
const keyUsageBuffer = new ArrayBuffer(1);
const keyUsageBitView = new Uint8Array(keyUsageBuffer);
keyUsageBitView[0] = !!certData.isCA
? KEY_USAGE_CertificateAuthority
: KEY_USAGE_LeafCertificate;
keyUsageBitView[0] = certData.isCA ?
KEY_USAGE_CertificateAuthority :
KEY_USAGE_LeafCertificate;
// noinspection JSUnresolvedFunction
const keyUsage = new asn1js.BitString({ valueHex: keyUsageBuffer });
......@@ -625,7 +624,7 @@ function createCertificate(certData, issuerData = null) {
keyPurposes.push(OID_ID_PKIX_TimeStamping);
const extKeyUsage = new pkijs.ExtKeyUsage({
keyPurposes: keyPurposes
keyPurposes
});
certificate.extensions.push(
......@@ -662,7 +661,7 @@ function createCertificate(certData, issuerData = null) {
}
const subjAltNames = new pkijs.GeneralNames({
names: names
names
});
certificate.extensions.push(
......@@ -739,15 +738,20 @@ function createCertificate(certData, issuerData = null) {
//region Signing final certificate
sequence = sequence.then(
() => {
let signerKey =
issuerData && issuerData.privateKey
? issuerData.privateKey
: privateKey;
const signerKey =
issuerData && issuerData.privateKey ?
issuerData.privateKey :
privateKey;
console.log({signerKey});
console.log({certData});
console.log({defaultAlgorithms});
return certificate.sign(
signerKey,
certData.algorithms && certData.algorithms.hashAlg
? certData.algorithms.hashAlg
: defaultAlgorithms.hashAlg
certData.algorithms && certData.algorithms.hashAlg ?
certData.algorithms.hashAlg :
defaultAlgorithms.hashAlg
);
},
error => Promise.reject(`Error during exporting public key: ${error}`)
......@@ -791,11 +795,11 @@ function createCertificate(certData, issuerData = null) {
return sequence.then(() => {
const result = {
certificate: certificate,
certificate,
certificatePEM: encodePEM(certificateBuffer, "CERTIFICATE"),
publicKey: publicKey,
publicKey,
publicKeyPEM: encodePEM(publicKeyBuffer, "PUBLIC KEY"),
privateKey: privateKey,
privateKey,
privateKeyPEM: encodePEM(privateKeyBuffer, "PRIVATE KEY")
};
return result;
......@@ -1042,7 +1046,7 @@ Vereign - Authentic Communication
const hashAlg = "SHA-256";
let cmsSignedSimpl;
let mimeHeadersTitles = [
const mimeHeadersTitles = [
"Content-Type",
"Content-Transfer-Encoding",
"Content-ID",
......@@ -1055,26 +1059,26 @@ Vereign - Authentic Communication
mime = mime.replace(newline, "\r\n");
let newHeaderLines = "";
let headersEnd = mime.indexOf("\r\n\r\n"); //the first empty line
const headersEnd = mime.indexOf("\r\n\r\n"); //the first empty line
if (headersEnd < 0 && mime.startsWith("\r\n")) {
mime = mime.substring(2); //should not happen
} else if (headersEnd >= 0) {
let mimeHeaders = {};
let mimeBody = mime.substring(headersEnd + 4);
const mimeHeaders = {};
const mimeBody = mime.substring(headersEnd + 4);
let mimeHeadersStr = mime.substring(0, headersEnd);
const mimeHeadersStr = mime.substring(0, headersEnd);
let headers = libmime.decodeHeaders(mimeHeadersStr);
const headers = libmime.decodeHeaders(mimeHeadersStr);
for (let i = 0; i < mimeHeadersTitles.length; i++) {
let key = mimeHeadersTitles[i].toLowerCase();
const key = mimeHeadersTitles[i].toLowerCase();
if (key in headers) {
mimeHeaders[key] = headers[key];
delete headers[key];
}
}
for (let key in headers) {
for (const key in headers) {
if (!(key === "" || key === "MIME-Version".toLowerCase())) {
//we have MIME-Version in the template
newHeaderLines += capitalizeHeader(key) + ": " + headers[key] + "\r\n";
......@@ -1082,7 +1086,7 @@ Vereign - Authentic Communication
}
let newMimeHeaderLines = "";
for (let key in mimeHeaders) {
for (const key in mimeHeaders) {
if (!(key === "")) {
newMimeHeaderLines +=
capitalizeHeader(key) + ": " + mimeHeaders[key] + "\r\n";
......@@ -1096,7 +1100,7 @@ Vereign - Authentic Communication
mime = newMimeHeaderLines + "\r\n" + mimeBody;
}
let dataBuffer = Buffer.from(mime, "utf-8");
const dataBuffer = Buffer.from(mime, "utf-8");
let sequence = Promise.resolve();
......@@ -1235,8 +1239,8 @@ Vereign - Authentic Communication
//endregion
sequence = sequence.then(cmsSignedBuffer => {
let signature = arrayBufferToBase64Formatted(cmsSignedBuffer);
let boundary = makeBoundary();
const signature = arrayBufferToBase64Formatted(cmsSignedBuffer);
const boundary = makeBoundary();
template = template.replace(/{{boundary}}/g, boundary);
template = template.replace("{{signature}}", signature);
......@@ -1278,7 +1282,7 @@ function capitalizeHeader(string) {
}
function makeBoundary() {
let len = 20 + Math.random() * 20;
const len = 20 + Math.random() * 20;
return "W0RyLiBEYW15YW4gTWl0ZXZd--" + makeid(len);
}
......@@ -1472,7 +1476,6 @@ export const verifySMIME = (smimeString, rootCaPem) => {
};
export class ImageData {
/**
* Constructor for ImageData class
* @param {Object} [parameters] Object in format
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment