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

build

parent 8db290ee
No related branches found
No related tags found
1 merge request!39Resolve "QR Code Data Signing & Verification flow"
......@@ -30,7 +30,7 @@ const convertPemToBinary = (pem) => {
}
return common_1.base64ToArrayBuffer(encoded);
};
exports.verifyRSASignature = (publicKeyPEM, data, signature) => __awaiter(void 0, void 0, void 0, function* () {
const verifyRSASignature = (publicKeyPEM, data, signature) => __awaiter(void 0, void 0, void 0, function* () {
const publicKey = yield crypto.subtle.importKey("spki", convertPemToBinary(publicKeyPEM), {
name: "RSASSA-PKCS1-v1_5",
hash: "SHA-256",
......@@ -40,6 +40,7 @@ exports.verifyRSASignature = (publicKeyPEM, data, signature) => __awaiter(void 0
hash: "SHA-256",
}, publicKey, signature, data);
});
exports.verifyRSASignature = verifyRSASignature;
const encryptAESGCM = (data) => __awaiter(void 0, void 0, void 0, function* () {
const key = yield crypto.subtle.generateKey({
name: "AES-GCM",
......
......@@ -330,7 +330,7 @@ exports.getAttachment = getAttachment;
* @param headers
* @returns {string} ('file.txt')
*/
exports.getFilenameFromHeaders = (headers) => {
const getFilenameFromHeaders = (headers) => {
const headersToSearch = ["content-type", "content-disposition"];
const filename = headers &&
Object.keys(headers)
......@@ -341,6 +341,7 @@ exports.getFilenameFromHeaders = (headers) => {
}, "");
return filename || DEFAULT_ATTACHMENT_NAME;
};
exports.getFilenameFromHeaders = getFilenameFromHeaders;
// export const splitParticipants = participantsList => {
// if (!participantsList) {
// return [];
......@@ -357,7 +358,7 @@ exports.getFilenameFromHeaders = (headers) => {
* @param string
* @returns {*}
*/
exports.extractHtmlBodyFromString = (string) => {
const extractHtmlBodyFromString = (string) => {
const extractBodyRegex = /<body.*?>([\s\S]+)<\/body>/gm;
const bodyMatch = extractBodyRegex.exec(string);
let body = string;
......@@ -369,6 +370,7 @@ exports.extractHtmlBodyFromString = (string) => {
.replace(/<!--[\s\S]*?-->/gm, "")
.trim();
};
exports.extractHtmlBodyFromString = extractHtmlBodyFromString;
exports.default = {
parseMIME,
getHTML,
......
......@@ -23,20 +23,22 @@ const pruneElement = (element) => {
}
return !!elementsToRemove[element.nodeName.toLowerCase()];
};
exports.pruneGmailElement = (element) => {
const pruneGmailElement = (element) => {
return pruneElement(element);
};
exports.pruneGmailElement = pruneGmailElement;
/**
* Returns true if element should be completely removed
* @param element
*/
exports.pruneOutlookElement = (element) => {
const pruneOutlookElement = (element) => {
if (pruneElement(element)) {
return true;
}
// Remove Outlook generic <o:*> tags
return !!element.nodeName.toLowerCase().startsWith("o:");
};
exports.pruneOutlookElement = pruneOutlookElement;
const cloneAnchorFromPane = (a, pane) => {
try {
const url = new URL(a.href);
......@@ -49,7 +51,7 @@ const cloneAnchorFromPane = (a, pane) => {
return;
}
};
exports.amendOutlookNodes = (document) => {
const amendOutlookNodes = (document) => {
/**
* Get rid of attachments panes
*/
......@@ -100,7 +102,8 @@ exports.amendOutlookNodes = (document) => {
});
});
};
exports.amendGmailNodes = (document) => {
exports.amendOutlookNodes = amendOutlookNodes;
const amendGmailNodes = (document) => {
/**
* Look for attachments panes and remove everything but liks
*/
......@@ -115,7 +118,8 @@ exports.amendGmailNodes = (document) => {
pane.parentNode.removeChild(pane);
});
};
exports.cleanupGMailElementAttributes = (element) => {
exports.amendGmailNodes = amendGmailNodes;
const cleanupGMailElementAttributes = (element) => {
if (element.attributes.length > 0) {
for (const attribute of element.attributes) {
if (attribute.name === "data-surl") {
......@@ -131,7 +135,8 @@ exports.cleanupGMailElementAttributes = (element) => {
}
}
};
exports.cleanupOutlookElementAttributes = (element) => {
exports.cleanupGMailElementAttributes = cleanupGMailElementAttributes;
const cleanupOutlookElementAttributes = (element) => {
if (element.attributes.length > 0) {
for (const attribute of element.attributes) {
let valueSplit = attribute.value.split(" ");
......@@ -147,3 +152,4 @@ exports.cleanupOutlookElementAttributes = (element) => {
}
}
};
exports.cleanupOutlookElementAttributes = cleanupOutlookElementAttributes;
......@@ -4,7 +4,7 @@ exports.printOutlookElement = exports.pruneHtmlNode = exports.cleanupHtmlNodeAtt
const stringUtils_1 = require("../../utils/stringUtils");
const __1 = require("../..");
const constants_1 = require("./constants");
exports.printHtmlChildren = (node, printFunction, depth) => {
const printHtmlChildren = (node, printFunction, depth) => {
let child = node.firstChild;
if (!child) {
return "";
......@@ -21,7 +21,8 @@ exports.printHtmlChildren = (node, printFunction, depth) => {
return result;
}
};
exports.printHtmlNode = (node, printFunction, depth) => {
exports.printHtmlChildren = printHtmlChildren;
const printHtmlNode = (node, printFunction, depth) => {
let result = "";
if (printFunction) {
const customPrintout = printFunction(node);
......@@ -67,7 +68,8 @@ exports.printHtmlNode = (node, printFunction, depth) => {
}
return result;
};
exports.cleanupHtmlNodeAttributes = (node, cleanupElementAttributes) => {
exports.printHtmlNode = printHtmlNode;
const cleanupHtmlNodeAttributes = (node, cleanupElementAttributes) => {
if (node.nodeType === node.ELEMENT_NODE) {
cleanupElementAttributes(node);
}
......@@ -77,7 +79,8 @@ exports.cleanupHtmlNodeAttributes = (node, cleanupElementAttributes) => {
child = child.nextSibling;
}
};
exports.pruneHtmlNode = (node, pruneElement) => {
exports.cleanupHtmlNodeAttributes = cleanupHtmlNodeAttributes;
const pruneHtmlNode = (node, pruneElement) => {
let toBeRemoved = false;
switch (node.nodeType) {
case node.COMMENT_NODE:
......@@ -109,11 +112,13 @@ exports.pruneHtmlNode = (node, pruneElement) => {
childrenToRemove.forEach((child) => node.removeChild(child));
return false;
};
exports.pruneHtmlNode = pruneHtmlNode;
// TODO: Move this logic to amendOutlookNodes
exports.printOutlookElement = (node) => {
const printOutlookElement = (node) => {
if (node.nodeType === constants_1.ELEMENT_NODE) {
if (node.classList.contains("WordSection1")) {
return exports.printHtmlChildren(node, null, 0);
}
}
};
exports.printOutlookElement = printOutlookElement;
......@@ -108,7 +108,7 @@ const computeQrCodeHash = (emailData) => __awaiter(void 0, void 0, void 0, funct
return index_1.CryptoService.SHA256(string);
});
const hashArray = yield Promise.all(promises);
return hashArray.sort().join("\n");
return hashArray.map(common_1.arrayBufferToBase64).sort().join("\n");
});
const calculateQRCodeSignature = (accountPrivateKey, qrCodeHash) => __awaiter(void 0, void 0, void 0, function* () {
const signature = yield index_1.CryptoService.signRSA(accountPrivateKey, Buffer.from(qrCodeHash));
......
......@@ -2,19 +2,23 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.escapeHtmlString = exports.arrayBufferToHex = exports.decompressData = exports.compressData = exports.ensureUint8Array = exports.ensureArrayBuffer = exports.ensureBase64 = exports.base64ToArrayBuffer = exports.arrayBufferToBase64 = void 0;
const zlib_min_1 = require("zlibjs/bin/zlib.min");
exports.arrayBufferToBase64 = (buffer) => {
const arrayBufferToBase64 = (buffer) => {
return Buffer.from(buffer).toString("base64");
};
exports.base64ToArrayBuffer = (base64) => {
exports.arrayBufferToBase64 = arrayBufferToBase64;
const base64ToArrayBuffer = (base64) => {
return Buffer.from(base64, "base64");
};
exports.ensureBase64 = (data) => {
exports.base64ToArrayBuffer = base64ToArrayBuffer;
const ensureBase64 = (data) => {
return typeof data === "string" ? data : exports.arrayBufferToBase64(data);
};
exports.ensureArrayBuffer = (data) => {
exports.ensureBase64 = ensureBase64;
const ensureArrayBuffer = (data) => {
return typeof data === "string" ? exports.base64ToArrayBuffer(data) : data;
};
exports.ensureUint8Array = (data) => {
exports.ensureArrayBuffer = ensureArrayBuffer;
const ensureUint8Array = (data) => {
return data instanceof Uint8Array
? data
: typeof data === "string"
......@@ -23,20 +27,24 @@ exports.ensureUint8Array = (data) => {
? new Uint8Array(data)
: data;
};
exports.compressData = (binary) => {
exports.ensureUint8Array = ensureUint8Array;
const compressData = (binary) => {
const deflate = new zlib_min_1.Zlib.Deflate(exports.ensureUint8Array(binary));
return deflate.compress();
};
exports.decompressData = (binary) => {
exports.compressData = compressData;
const decompressData = (binary) => {
const inflate = new zlib_min_1.Zlib.Inflate(exports.ensureUint8Array(binary));
return inflate.decompress();
};
exports.arrayBufferToHex = (buffer) => {
exports.decompressData = decompressData;
const arrayBufferToHex = (buffer) => {
return [...new Uint8Array(buffer)]
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
};
exports.escapeHtmlString = (string) => {
exports.arrayBufferToHex = arrayBufferToHex;
const escapeHtmlString = (string) => {
const matchHtmlRegExp = /["'&<>]/;
const str = "" + string;
const match = matchHtmlRegExp.exec(str);
......@@ -75,6 +83,7 @@ exports.escapeHtmlString = (string) => {
}
return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
};
exports.escapeHtmlString = escapeHtmlString;
exports.default = {
compressData: exports.compressData,
decompressData: exports.decompressData,
......
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeQRCodes = exports.removeSpacesAndLinebreaks = void 0;
exports.removeSpacesAndLinebreaks = (s) => {
const removeSpacesAndLinebreaks = (s) => {
const regexNewlines = new RegExp(/[\r\n\v]+/g);
const regexSpaces = new RegExp(/\s+|\u200B/g);
return s.replace(regexNewlines, "").replace(regexSpaces, "");
};
exports.removeQRCodes = (s) => {
exports.removeSpacesAndLinebreaks = removeSpacesAndLinebreaks;
const removeQRCodes = (s) => {
return s
.replace(/\[qrcode.png\]\s*<https:\/\/[\w./?=\-&]+>/g, "")
.replace(/<https:\/\/[\w./?=\-&]+>\s*\[qrcode.png\]/g, "");
};
exports.removeQRCodes = removeQRCodes;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment