{"version":3,"sources":["webpack:///webpack/universalModuleDefinition?5ca6","webpack:///ca-cert-utils.min.js","webpack:///webpack/bootstrap 5ff1a27eb6654cc8b4be?39d6","webpack:///./src/CertificateUtils.ts?fecd","webpack:///external {\"commonjs\":\"forge\",\"commonjs2\":\"forge\",\"amd\":\"forge\",\"root\":\"forge\"}?5b2d","webpack:///./src/LocalForageStorage.ts?bd4d","webpack:///external {\"commonjs\":\"localforage\",\"commonjs2\":\"localforage\",\"amd\":\"localforage\",\"root\":\"localforage\"}?9467"],"names":["root","factory","exports","module","require","define","amd","this","__WEBPACK_EXTERNAL_MODULE_1__","__WEBPACK_EXTERNAL_MODULE_3__","modules","__webpack_require__","moduleId","installedModules","i","l","call","m","c","d","name","getter","o","Object","defineProperty","configurable","enumerable","get","n","__esModule","object","property","prototype","hasOwnProperty","p","s","__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","value","step","next","e","rejected","result","done","then","apply","__generator","body","verb","v","op","f","TypeError","_","y","t","label","ops","pop","trys","length","push","g","sent","throw","return","Symbol","iterator","forge","LocalForageStorage_1","Storage","default","Algorithm","pki","util","asn1","pkcs12","CertificateUtils","storageOrName","certStoreKey","Error","storage","storePkcs12File","file","userId","_this","p12FileReader","FileReader","onload","event","p12File","Uint8Array","target","set","getStoreKey","readAsArrayBuffer","isPkcs12FileStored","_a","getPkcs12FileFromStore","downloadPkcs12File","fileName","extension","certFileBlob","url","pfxFileName","a","Blob","URL","createObjectURL","document","createElement","appendChild","style","display","href","setAttribute","click","revokeObjectURL","signDocument","doc","privateKeyPassword","timeStamp","algorithm","SHA512","key","cert","_b","getPrivateKeyAndCert","getCAdESSignedPackage","signPdf","data","privateKey","createCmsSignedPackage","privateKeyPem","privateKeyToPem","certPem","certificateToPem","signedAttr","SigningCertificateV2","array","SigningTime","str","toDateString","cms","KJUR","CMSUtil","newSignedData","content","hex","binary","encode","certs","signerInfos","hashAlg","sAttr","signerCert","sigAlg","toUpperCase","signerPrvKey","cmsHex","getContentInfoEncodedHex","base64","decode","certPassword","buffer","ByteBuffer","p12Asn1","fromDer","p12Cert","pkcs12FromAsn1","keyBags","getBags","bagType","oids","pkcs8ShroudedKeyBag","keyBag","keyAsn1","privateKeyFromAsn1","certBags","certBag","date","year","getUTCFullYear","toString","substr","month","getUTCMonth","day","getUTCDate","toPrecision","hour","getUTCHours","min","getUTCMinutes","sec","getUTCSeconds","localforage","LocalForageStorage","config","remove","removeItem","item","setItem","getItem"],"mappings":"CAAA,SAAAA,EAAAC,GACA,gBAAAC,UAAA,gBAAAC,QACAA,OAAAD,QAAAD,EAAAG,QAAA,SAAAA,QAAA,gBACA,kBAAAC,gBAAAC,IACAD,QAAA,uBAAAJ,GACA,gBAAAC,SACAA,QAAA,GAAAD,EAAAG,QAAA,SAAAA,QAAA,gBAEAJ,EAAA,GAAAC,EAAAD,EAAA,MAAAA,EAAA,cACCO,KAAA,SAAAC,EAAAC,GACD,MCAgB,UAAUC,GCN1B,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAV,OAGA,IAAAC,GAAAU,EAAAD,IACAE,EAAAF,EACAG,GAAA,EACAb,WAUA,OANAQ,GAAAE,GAAAI,KAAAb,EAAAD,QAAAC,IAAAD,QAAAS,GAGAR,EAAAY,GAAA,EAGAZ,EAAAD,QAvBA,GAAAW,KA4DA,OAhCAF,GAAAM,EAAAP,EAGAC,EAAAO,EAAAL,EAGAF,EAAAQ,EAAA,SAAAjB,EAAAkB,EAAAC,GACAV,EAAAW,EAAApB,EAAAkB,IACAG,OAAAC,eAAAtB,EAAAkB,GACAK,cAAA,EACAC,YAAA,EACAC,IAAAN,KAMAV,EAAAiB,EAAA,SAAAzB,GACA,GAAAkB,GAAAlB,KAAA0B,WACA,WAA2B,MAAA1B,GAAA,SAC3B,WAAiC,MAAAA,GAEjC,OADAQ,GAAAQ,EAAAE,EAAA,IAAAA,GACAA,GAIAV,EAAAW,EAAA,SAAAQ,EAAAC,GAAsD,MA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AAAa,OAChBwL,EAAYE,QACR1L,KAAIA,IA0ChB,MA9BIyL,GAAA7K,UAAA+K,OAAA,SAAO3E,GACH,MAAOwE,GAAYI,WAAW,GAAG5E,IAarCyE,EAAA7K,UAAAqE,IAAA,SAAY+B,EAAa6E,GACrB,MAAOL,GAAYM,QAAQ,GAAG9E,EAAO6E,IAYzCJ,EAAA7K,UAAAL,IAAA,SAAYyG,GACR,MAAOwE,GAAYO,QAAQ,GAAG/E,IAEtCyE,IJwbA3M,GAAQ6E,QAAU8H,GAKZ,SAAU1M,EAAQD,GK1fxBC,EAAAD,QAAAO","file":"ca-cert-utils.min.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"forge\"), require(\"localforage\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"forge\", \"localforage\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"ca\"] = factory(require(\"forge\"), require(\"localforage\"));\n\telse\n\t\troot[\"ca\"] = factory(root[\"forge\"], root[\"localforage\"]);\n})(this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_3__) {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition","(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"forge\"), require(\"localforage\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"forge\", \"localforage\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"ca\"] = factory(require(\"forge\"), require(\"localforage\"));\n\telse\n\t\troot[\"ca\"] = factory(root[\"forge\"], root[\"localforage\"]);\n})(this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_3__) {\nreturn /******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId]) {\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\ti: moduleId,\n/******/ \t\t\tl: false,\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.l = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// define getter function for harmony exports\n/******/ \t__webpack_require__.d = function(exports, name, getter) {\n/******/ \t\tif(!__webpack_require__.o(exports, name)) {\n/******/ \t\t\tObject.defineProperty(exports, name, {\n/******/ \t\t\t\tconfigurable: false,\n/******/ \t\t\t\tenumerable: true,\n/******/ \t\t\t\tget: getter\n/******/ \t\t\t});\n/******/ \t\t}\n/******/ \t};\n/******/\n/******/ \t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t__webpack_require__.n = function(module) {\n/******/ \t\tvar getter = module && module.__esModule ?\n/******/ \t\t\tfunction getDefault() { return module['default']; } :\n/******/ \t\t\tfunction getModuleExports() { return module; };\n/******/ \t\t__webpack_require__.d(getter, 'a', getter);\n/******/ \t\treturn getter;\n/******/ \t};\n/******/\n/******/ \t// Object.prototype.hasOwnProperty.call\n/******/ \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(__webpack_require__.s = 0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\r\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n};\r\nvar __generator = (this && this.__generator) || function (thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [0, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n};\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar forge = __webpack_require__(1);\r\nvar LocalForageStorage_1 = __webpack_require__(2);\r\nexports.Storage = LocalForageStorage_1.default;\r\nvar pki = forge.pki, util = forge.util, asn1 = forge.asn1, pkcs12 = forge.pkcs12;\r\nvar Algorithm;\r\n(function (Algorithm) {\r\n Algorithm[\"SHA256\"] = \"sha256\";\r\n Algorithm[\"SHA384\"] = \"sha384\";\r\n Algorithm[\"SHA512\"] = \"sha512\";\r\n})(Algorithm = exports.Algorithm || (exports.Algorithm = {}));\r\n/**\r\n * Class has functions to upload and download a certificate to and from\r\n * browser storage as well as perform document signing\r\n *\r\n * @export\r\n * @class CertificateUtils\r\n */\r\nvar CertificateUtils = (function () {\r\n /**\r\n * Creates an instance of CertificateUtils.\r\n *\r\n * @param {(IStorage | string)} storageOrName - the name of the underlying browser storage\r\n * to create or a object that implements the IStorage interface\r\n * @param {string} certStoreKey - the key to use when adding a certificate to storage.\r\n * Id of user to which to certificate belongs, will be appended to this value to create\r\n * the final key\r\n *\r\n * @memberOf CertificateUtils\r\n */\r\n function CertificateUtils(storageOrName, certStoreKey) {\r\n if (!storageOrName) {\r\n throw new Error('Either the storage name or an an object that implements IStorage instance must be specified');\r\n }\r\n if (!certStoreKey) {\r\n throw new Error('The store key must be specified');\r\n }\r\n if (typeof storageOrName === 'string') {\r\n this.storage = new LocalForageStorage_1.default(storageOrName);\r\n }\r\n else {\r\n this.storage = storageOrName;\r\n }\r\n this.certStoreKey = certStoreKey;\r\n }\r\n /**\r\n * Stores a certificate file in the browser storage\r\n *\r\n * @param {File} file - The PKCS12 file uploaded via a file input element\r\n * @param {string} userId - the id of the user to which the certificate belongs\r\n * @returns {Promise} - A promise of the certificate file as an Uint8Array\r\n *\r\n * @memberOf CertificateUtils\r\n */\r\n CertificateUtils.prototype.storePkcs12File = function (file, userId) {\r\n var _this = this;\r\n if (!file) {\r\n return Promise.reject('The certificate file must be specified');\r\n }\r\n if (!userId) {\r\n return Promise.reject('The user ID must be specified');\r\n }\r\n return new Promise(function (resolve, reject) {\r\n var p12FileReader = new FileReader();\r\n /**\r\n * Handler that saved the uploaded file to the browser's storage\r\n *\r\n * @param {any} event\r\n */\r\n p12FileReader.onload = function (event) {\r\n var p12File = new Uint8Array(event.target.result);\r\n _this.storage\r\n .set(_this.getStoreKey(userId), p12File)\r\n .then(function (_) { return resolve(p12File); });\r\n };\r\n p12FileReader.readAsArrayBuffer(file);\r\n });\r\n };\r\n /**\r\n * Determines if a PKCS12 file belonging to a user is stored in browser storage\r\n *\r\n * @param {string} userId - the id of the user to which the certificate belongs\r\n * @returns {Promise} - A promise of the boolean value. True if stored, otherwise false.\r\n *\r\n * @memberOf CertificateUtils\r\n */\r\n CertificateUtils.prototype.isPkcs12FileStored = function (userId) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var p12File;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n if (!userId) {\r\n return [2 /*return*/, Promise.reject('The user ID must be specified')];\r\n }\r\n return [4 /*yield*/, this.getPkcs12FileFromStore(userId)];\r\n case 1:\r\n p12File = _a.sent();\r\n return [2 /*return*/, !!p12File];\r\n }\r\n });\r\n });\r\n };\r\n /**\r\n * Downloads a PKCS12 file from browser storage\r\n *\r\n * @param {string} userId - the id of the user to which the certificate belongs\r\n * @param {string} fileName - the name to give the downloaded certificate file.\r\n * Defaults to the userId\r\n * @param {string} extension - The file extension. Defaults to 'pfx'\r\n *\r\n * @memberOf CertificateUtils\r\n */\r\n CertificateUtils.prototype.downloadPkcs12File = function (userId, fileName, extension) {\r\n if (extension === void 0) { extension = 'pfx'; }\r\n return __awaiter(this, void 0, void 0, function () {\r\n var p12File, certFileBlob, url, pfxFileName, a;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n if (!userId) {\r\n throw new Error('The user ID must be specified');\r\n }\r\n fileName = fileName || userId;\r\n return [4 /*yield*/, this.getPkcs12FileFromStore(userId)];\r\n case 1:\r\n p12File = _a.sent();\r\n certFileBlob = new Blob([p12File]);\r\n url = URL.createObjectURL(certFileBlob);\r\n pfxFileName = fileName + \".\" + extension;\r\n a = document.createElement('a');\r\n document.body.appendChild(a);\r\n a.style.display = 'none';\r\n a.href = url;\r\n a.setAttribute('download', pfxFileName);\r\n a.click();\r\n URL.revokeObjectURL(url);\r\n return [2 /*return*/];\r\n }\r\n });\r\n });\r\n };\r\n /**\r\n * Signs the given document\r\n *\r\n * @param {(Uint8Array | string)} doc - The file byte array or string\r\n * @param {string} userId - The id of the user to which the certificate belongs\r\n * @param {string} privateKeyPassword - The password for the private key associated with the certificate\r\n * @param {SignatureType} [signatureType=SignatureType.CAdES] - Whether or not to wrap the signature in a PKCS#7\r\n * message format\r\n * @param {Date} timeStamp - The date that will be embedded in the PKCS#7/CMS message or a timestamp token\r\n * from a TimeStamp server to be added to the CAdES message\r\n * @param {Algorithm} [algorithm=Algorithm.SHA512] - The message digest algorithm. Default is sha512\r\n * @returns {Promise} - A promise of the signed document value.\r\n * @memberOf CertificateUtils\r\n */\r\n CertificateUtils.prototype.signDocument = function (doc, userId, privateKeyPassword, timeStamp, algorithm) {\r\n if (algorithm === void 0) { algorithm = Algorithm.SHA512; }\r\n return __awaiter(this, void 0, void 0, function () {\r\n var p12File, _a, key, cert;\r\n return __generator(this, function (_b) {\r\n switch (_b.label) {\r\n case 0:\r\n if (!doc) {\r\n Promise.reject('The document to sign must be specified');\r\n }\r\n if (!userId) {\r\n Promise.reject('The user ID must be specified');\r\n }\r\n if (!privateKeyPassword) {\r\n Promise.reject('Certificate password must be specified');\r\n }\r\n return [4 /*yield*/, this.getPkcs12FileFromStore(userId)];\r\n case 1:\r\n p12File = _b.sent();\r\n if (!p12File) {\r\n throw new Error(\"No certificate found for user ID: \" + userId);\r\n }\r\n _a = this.getPrivateKeyAndCert(p12File, privateKeyPassword), key = _a.key, cert = _a.cert;\r\n if (!(doc instanceof Uint8Array || typeof doc === 'string')) {\r\n throw new Error('The document to sign must be a string or a Uint8Array');\r\n }\r\n return [2 /*return*/, this.getCAdESSignedPackage(doc, cert, key, algorithm, timeStamp)];\r\n }\r\n });\r\n });\r\n };\r\n /**\r\n * Signs a PDF document and embeds the signature\r\n *\r\n *\r\n * @memberOf CertificateUtils\r\n */\r\n CertificateUtils.prototype.signPdf = function () {\r\n throw new Error('signPdf is not yet implemented');\r\n // TODO: Call PDFSign to sign the document\r\n // TODO:\r\n // 1. Patch pdfsign.js (pdfsign-patched-dci.js) to call a custom signDetached function\r\n // instead of the patched function from forge-patched.js file\r\n // 2. Create signedDetachedFunction to take a 'msg' parameter that has the same functionality\r\n // as https://github.com/digitalbazaar/forge/blob/master/lib/pkcs7.js#L330 but patched as in\r\n // https://github.com/Communication-Systems-Group/pdfsign.js/blob/master/src/lib/pkcs7-detached.js#L350\r\n // 3. Call PDFSign to sign document. See sample in samples/pdf-sign.html\r\n };\r\n /**\r\n * Gets the certificate from the store\r\n *\r\n * @param {string} userId - The id of the user to which the certificate belongs\r\n * @returns - The certificate file bytes\r\n *\r\n * @memberOf CertificateUtils\r\n */\r\n CertificateUtils.prototype.getPkcs12FileFromStore = function (userId) {\r\n return this.storage.get(this.getStoreKey(userId));\r\n };\r\n CertificateUtils.prototype.getCAdESSignedPackage = function (data, cert, privateKey, algorithm, timeStamp) {\r\n return this.createCmsSignedPackage(data, cert, privateKey, algorithm, timeStamp);\r\n };\r\n CertificateUtils.prototype.createCmsSignedPackage = function (data, cert, privateKey, algorithm, timeStamp) {\r\n var privateKeyPem = pki.privateKeyToPem(privateKey);\r\n var certPem = pki.certificateToPem(cert);\r\n var signedAttr = { SigningCertificateV2: { array: [certPem] } };\r\n signedAttr.SigningTime = timeStamp\r\n ? { str: this.toDateString(timeStamp) }\r\n : {};\r\n var cms = KJUR.asn1.cms.CMSUtil.newSignedData({\r\n content: data instanceof Uint8Array\r\n ? { hex: util.binary.hex.encode(data) }\r\n : { str: data },\r\n certs: [certPem],\r\n signerInfos: [\r\n {\r\n hashAlg: algorithm,\r\n sAttr: signedAttr,\r\n signerCert: certPem,\r\n sigAlg: algorithm.toUpperCase() + \"withRSA\",\r\n signerPrvKey: privateKeyPem\r\n }\r\n ]\r\n });\r\n var cmsHex = cms.getContentInfoEncodedHex();\r\n return util.binary.base64.encode(util.binary.hex.decode(cmsHex));\r\n };\r\n CertificateUtils.prototype.getPrivateKeyAndCert = function (p12File, certPassword) {\r\n // create forge byte bugger\r\n var buffer = new util.ByteBuffer(p12File.buffer);\r\n // get forge cert from byte buffer\r\n var p12Asn1 = asn1.fromDer(buffer);\r\n // decrypt p12 using non-strict parsing mode (resolves some ASN.1 parse errors)\r\n var p12Cert = pkcs12.pkcs12FromAsn1(p12Asn1, false, certPassword);\r\n // get key bags\r\n var keyBags = p12Cert.getBags({ bagType: pki.oids.pkcs8ShroudedKeyBag });\r\n // get key\r\n var keyBag = keyBags[pki.oids.pkcs8ShroudedKeyBag][0];\r\n if (!keyBag) {\r\n throw new Error('PKCS12 file does not contain a private key');\r\n }\r\n var key = keyBag.key;\r\n // if the key is in a format unrecognized by forge then\r\n // bag.key will be `null`, use bag.asn1 to get the ASN.1\r\n // representation of the key\r\n if (key === null) {\r\n var keyAsn1 = keyBag.asn1;\r\n key = pki.privateKeyFromAsn1(keyAsn1);\r\n if (!key) {\r\n throw new Error('Unable to read key stored in PKCS12 file');\r\n }\r\n }\r\n // get cert bags\r\n var certBags = p12Cert.getBags({ bagType: pki.oids.certBag });\r\n // get cert\r\n var certBag = certBags[pki.oids.certBag][0];\r\n if (!certBag) {\r\n throw new Error('PKCS12 file does not contain a certificate');\r\n }\r\n if (!certBag.cert) {\r\n throw new Error('Unable to read certificate stored in PKCS12 file');\r\n }\r\n var cert = certBag.cert;\r\n return { key: key, cert: cert };\r\n };\r\n CertificateUtils.prototype.getStoreKey = function (userId) {\r\n return this.certStoreKey + \"_\" + userId;\r\n };\r\n CertificateUtils.prototype.toDateString = function (date) {\r\n var year = date.getUTCFullYear().toString().substr(2);\r\n var month = (date.getUTCMonth() + 1).toString();\r\n if (month.length === 1) {\r\n month = '0' + month;\r\n }\r\n var day = date.getUTCDate().toPrecision();\r\n if (day.length === 1) {\r\n day = '0' + day;\r\n }\r\n var hour = date.getUTCHours().toString();\r\n if (hour.length === 1) {\r\n hour = '0' + hour;\r\n }\r\n var min = date.getUTCMinutes().toString();\r\n if (min.length === 1) {\r\n min = '0' + min;\r\n }\r\n var sec = date.getUTCSeconds().toString();\r\n if (sec.length === 1) {\r\n sec = '0' + sec;\r\n }\r\n return year + month + day + hour + min + sec + 'Z';\r\n };\r\n return CertificateUtils;\r\n}());\r\nexports.CertificateUtils = CertificateUtils;\r\n\n\n/***/ }),\n/* 1 */\n/***/ (function(module, exports) {\n\nmodule.exports = __WEBPACK_EXTERNAL_MODULE_1__;\n\n/***/ }),\n/* 2 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar localforage = __webpack_require__(3);\r\n/**\r\n * The browser storage class\r\n *\r\n * @export\r\n * @class Storage\r\n */\r\nvar LocalForageStorage = (function () {\r\n /**\r\n * Creates an instance of Storage.\r\n *\r\n * @param {string} name\r\n *\r\n * @memberOf Storage\r\n */\r\n function LocalForageStorage(name) {\r\n this.name = name;\r\n localforage.config({\r\n name: name\r\n });\r\n }\r\n /**\r\n * Removes an item with the given key from storage\r\n *\r\n * @param {string} key\r\n * @returns {Promise}\r\n *\r\n * @memberOf Storage\r\n */\r\n LocalForageStorage.prototype.remove = function (key) {\r\n return localforage.removeItem(\"\" + key);\r\n };\r\n /**\r\n * Sets the value of an item in storage based on the given key\r\n *\r\n * @template TValue\r\n * @param {string} key\r\n * @param {TValue} item\r\n * @returns {Promise}\r\n *\r\n * @memberOf Storage\r\n */\r\n LocalForageStorage.prototype.set = function (key, item) {\r\n return localforage.setItem(\"\" + key, item);\r\n };\r\n /**\r\n * Gets the item with the given key from storage\r\n *\r\n * @template TValue\r\n * @param {string} key\r\n * @returns {Promise}\r\n *\r\n * @memberOf Storage\r\n */\r\n LocalForageStorage.prototype.get = function (key) {\r\n return localforage.getItem(\"\" + key);\r\n };\r\n return LocalForageStorage;\r\n}());\r\nexports.default = LocalForageStorage;\r\n\n\n/***/ }),\n/* 3 */\n/***/ (function(module, exports) {\n\nmodule.exports = __WEBPACK_EXTERNAL_MODULE_3__;\n\n/***/ })\n/******/ ]);\n});\n\n\n// WEBPACK FOOTER //\n// ca-cert-utils.min.js"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 5ff1a27eb6654cc8b4be","import * as forge from 'node-forge'\r\nimport Storage from './LocalForageStorage'\r\nimport { IStorage } from './IStorage'\r\n\r\ndeclare var KJUR: any\r\n\r\nconst { pki, util, asn1, pkcs12 } = forge\r\n\r\nexport enum Algorithm {\r\n SHA256 = 'sha256',\r\n SHA384 = 'sha384',\r\n SHA512 = 'sha512'\r\n}\r\n\r\nexport { Storage, IStorage }\r\n\r\n/**\r\n * Class has functions to upload and download a certificate to and from \r\n * browser storage as well as perform document signing\r\n * \r\n * @export\r\n * @class CertificateUtils\r\n */\r\nexport class CertificateUtils {\r\n private storage: IStorage\r\n private certStoreKey: string\r\n\r\n /**\r\n * Creates an instance of CertificateUtils.\r\n * \r\n * @param {(IStorage | string)} storageOrName - the name of the underlying browser storage \r\n * to create or a object that implements the IStorage interface\r\n * @param {string} certStoreKey - the key to use when adding a certificate to storage.\r\n * Id of user to which to certificate belongs, will be appended to this value to create \r\n * the final key\r\n * \r\n * @memberOf CertificateUtils\r\n */\r\n constructor(storageOrName: IStorage | string, certStoreKey: string) {\r\n if (!storageOrName) {\r\n throw new Error(\r\n 'Either the storage name or an an object that implements IStorage instance must be specified'\r\n )\r\n }\r\n if (!certStoreKey) {\r\n throw new Error('The store key must be specified')\r\n }\r\n\r\n if (typeof storageOrName === 'string') {\r\n this.storage = new Storage(storageOrName)\r\n } else {\r\n this.storage = storageOrName\r\n }\r\n\r\n this.certStoreKey = certStoreKey\r\n }\r\n\r\n /**\r\n * Stores a certificate file in the browser storage\r\n * \r\n * @param {File} file - The PKCS12 file uploaded via a file input element\r\n * @param {string} userId - the id of the user to which the certificate belongs\r\n * @returns {Promise} - A promise of the certificate file as an Uint8Array\r\n * \r\n * @memberOf CertificateUtils\r\n */\r\n public storePkcs12File(file: File, userId: string): Promise {\r\n if (!file) {\r\n return Promise.reject(\r\n 'The certificate file must be specified'\r\n )\r\n }\r\n if (!userId) {\r\n return Promise.reject('The user ID must be specified')\r\n }\r\n\r\n return new Promise((resolve, reject) => {\r\n let p12FileReader = new FileReader()\r\n\r\n /**\r\n * Handler that saved the uploaded file to the browser's storage\r\n * \r\n * @param {any} event\r\n */\r\n p12FileReader.onload = event => {\r\n let p12File = new Uint8Array((event.target).result)\r\n\r\n this.storage\r\n .set(this.getStoreKey(userId), p12File)\r\n .then(_ => resolve(p12File))\r\n }\r\n\r\n p12FileReader.readAsArrayBuffer(file)\r\n })\r\n }\r\n\r\n /**\r\n * Determines if a PKCS12 file belonging to a user is stored in browser storage\r\n * \r\n * @param {string} userId - the id of the user to which the certificate belongs\r\n * @returns {Promise} - A promise of the boolean value. True if stored, otherwise false. \r\n * \r\n * @memberOf CertificateUtils\r\n */\r\n public async isPkcs12FileStored(userId: string): Promise {\r\n if (!userId) {\r\n return Promise.reject('The user ID must be specified')\r\n }\r\n\r\n const p12File = await this.getPkcs12FileFromStore(userId)\r\n\r\n return !!p12File\r\n }\r\n\r\n /**\r\n * Downloads a PKCS12 file from browser storage\r\n * \r\n * @param {string} userId - the id of the user to which the certificate belongs\r\n * @param {string} fileName - the name to give the downloaded certificate file. \r\n * Defaults to the userId\r\n * @param {string} extension - The file extension. Defaults to 'pfx'\r\n * \r\n * @memberOf CertificateUtils\r\n */\r\n public async downloadPkcs12File(\r\n userId: string,\r\n fileName?: string,\r\n extension: string = 'pfx'\r\n ) {\r\n if (!userId) {\r\n throw new Error('The user ID must be specified')\r\n }\r\n\r\n fileName = fileName || userId\r\n\r\n const p12File = await this.getPkcs12FileFromStore(userId)\r\n\r\n const certFileBlob = new Blob([p12File])\r\n let url = URL.createObjectURL(certFileBlob)\r\n const pfxFileName = `${fileName}.${extension}`\r\n\r\n let a = document.createElement('a')\r\n document.body.appendChild(a)\r\n a.style.display = 'none'\r\n a.href = url\r\n a.setAttribute('download', pfxFileName)\r\n a.click()\r\n URL.revokeObjectURL(url)\r\n }\r\n\r\n /**\r\n * Signs the given document\r\n * \r\n * @param {(Uint8Array | string)} doc - The file byte array or string \r\n * @param {string} userId - The id of the user to which the certificate belongs\r\n * @param {string} privateKeyPassword - The password for the private key associated with the certificate \r\n * @param {SignatureType} [signatureType=SignatureType.CAdES] - Whether or not to wrap the signature in a PKCS#7 \r\n * message format\r\n * @param {Date} timeStamp - The date that will be embedded in the PKCS#7/CMS message or a timestamp token\r\n * from a TimeStamp server to be added to the CAdES message\r\n * @param {Algorithm} [algorithm=Algorithm.SHA512] - The message digest algorithm. Default is sha512\r\n * @returns {Promise} - A promise of the signed document value. \r\n * @memberOf CertificateUtils\r\n */\r\n public async signDocument(\r\n doc: Uint8Array | string,\r\n userId: string,\r\n privateKeyPassword: string,\r\n timeStamp?: Date,\r\n algorithm: Algorithm = Algorithm.SHA512\r\n ): Promise {\r\n if (!doc) {\r\n Promise.reject('The document to sign must be specified')\r\n }\r\n if (!userId) {\r\n Promise.reject('The user ID must be specified')\r\n }\r\n if (!privateKeyPassword) {\r\n Promise.reject('Certificate password must be specified')\r\n }\r\n\r\n const p12File = await this.getPkcs12FileFromStore(userId)\r\n\r\n if (!p12File) {\r\n throw new Error(`No certificate found for user ID: ${userId}`)\r\n }\r\n\r\n let { key, cert } = this.getPrivateKeyAndCert(p12File, privateKeyPassword)\r\n\r\n if (!(doc instanceof Uint8Array || typeof doc === 'string')) {\r\n throw new Error('The document to sign must be a string or a Uint8Array')\r\n }\r\n\r\n return this.getCAdESSignedPackage(doc, cert, key, algorithm, timeStamp)\r\n }\r\n\r\n /**\r\n * Signs a PDF document and embeds the signature\r\n * \r\n * \r\n * @memberOf CertificateUtils\r\n */\r\n public signPdf() {\r\n throw new Error('signPdf is not yet implemented')\r\n // TODO: Call PDFSign to sign the document\r\n // TODO:\r\n // 1. Patch pdfsign.js (pdfsign-patched-dci.js) to call a custom signDetached function\r\n // instead of the patched function from forge-patched.js file\r\n // 2. Create signedDetachedFunction to take a 'msg' parameter that has the same functionality\r\n // as https://github.com/digitalbazaar/forge/blob/master/lib/pkcs7.js#L330 but patched as in\r\n // https://github.com/Communication-Systems-Group/pdfsign.js/blob/master/src/lib/pkcs7-detached.js#L350\r\n // 3. Call PDFSign to sign document. See sample in samples/pdf-sign.html\r\n }\r\n\r\n /**\r\n * Gets the certificate from the store\r\n * \r\n * @param {string} userId - The id of the user to which the certificate belongs\r\n * @returns - The certificate file bytes\r\n * \r\n * @memberOf CertificateUtils\r\n */\r\n public getPkcs12FileFromStore(userId: string) {\r\n return this.storage.get(this.getStoreKey(userId))\r\n }\r\n\r\n private getCAdESSignedPackage(\r\n data: Uint8Array | string,\r\n cert: any,\r\n privateKey: any,\r\n algorithm: Algorithm,\r\n timeStamp?: Date\r\n ) {\r\n return this.createCmsSignedPackage(\r\n data,\r\n cert,\r\n privateKey,\r\n algorithm,\r\n timeStamp\r\n )\r\n }\r\n\r\n private createCmsSignedPackage(\r\n data: Uint8Array | string,\r\n cert: any,\r\n privateKey: any,\r\n algorithm: Algorithm,\r\n timeStamp?: Date\r\n ) {\r\n const privateKeyPem = pki.privateKeyToPem(privateKey)\r\n const certPem = pki.certificateToPem(cert)\r\n\r\n const signedAttr: any = { SigningCertificateV2: { array: [certPem] } }\r\n\r\n signedAttr.SigningTime = timeStamp\r\n ? { str: this.toDateString(timeStamp) }\r\n : {}\r\n\r\n let cms = KJUR.asn1.cms.CMSUtil.newSignedData({\r\n content:\r\n data instanceof Uint8Array\r\n ? { hex: util.binary.hex.encode(data) }\r\n : { str: data },\r\n certs: [certPem],\r\n signerInfos: [\r\n {\r\n hashAlg: algorithm,\r\n sAttr: signedAttr,\r\n signerCert: certPem,\r\n sigAlg: `${algorithm.toUpperCase()}withRSA`,\r\n signerPrvKey: privateKeyPem\r\n }\r\n ]\r\n })\r\n\r\n const cmsHex = cms.getContentInfoEncodedHex()\r\n\r\n return util.binary.base64.encode(util.binary.hex.decode(cmsHex))\r\n }\r\n\r\n private getPrivateKeyAndCert(p12File: Uint8Array, certPassword: string) {\r\n // create forge byte bugger\r\n let buffer = new util.ByteBuffer(p12File.buffer)\r\n // get forge cert from byte buffer\r\n let p12Asn1 = asn1.fromDer(buffer)\r\n // decrypt p12 using non-strict parsing mode (resolves some ASN.1 parse errors)\r\n let p12Cert = pkcs12.pkcs12FromAsn1(p12Asn1, false, certPassword)\r\n\r\n // get key bags\r\n let keyBags = p12Cert.getBags({ bagType: pki.oids.pkcs8ShroudedKeyBag })\r\n // get key\r\n let keyBag = keyBags[pki.oids.pkcs8ShroudedKeyBag][0]\r\n\r\n if (!keyBag) {\r\n throw new Error('PKCS12 file does not contain a private key')\r\n }\r\n\r\n let key = keyBag.key\r\n // if the key is in a format unrecognized by forge then\r\n // bag.key will be `null`, use bag.asn1 to get the ASN.1\r\n // representation of the key\r\n if (key === null) {\r\n let keyAsn1 = keyBag.asn1\r\n key = pki.privateKeyFromAsn1(keyAsn1)\r\n\r\n if (!key) {\r\n throw new Error('Unable to read key stored in PKCS12 file')\r\n }\r\n }\r\n\r\n // get cert bags\r\n let certBags = p12Cert.getBags({ bagType: pki.oids.certBag })\r\n // get cert\r\n let certBag = certBags[pki.oids.certBag][0]\r\n\r\n if (!certBag) {\r\n throw new Error('PKCS12 file does not contain a certificate')\r\n }\r\n\r\n if (!certBag.cert) {\r\n throw new Error('Unable to read certificate stored in PKCS12 file')\r\n }\r\n\r\n let cert = certBag.cert\r\n\r\n return { key, cert }\r\n }\r\n\r\n private getStoreKey(userId: string) {\r\n return `${this.certStoreKey}_${userId}`\r\n }\r\n\r\n private toDateString(date: Date) {\r\n const year = date.getUTCFullYear().toString().substr(2)\r\n\r\n let month = (date.getUTCMonth() + 1).toString()\r\n if (month.length === 1) {\r\n month = '0' + month\r\n }\r\n\r\n let day = date.getUTCDate().toPrecision()\r\n if (day.length === 1) {\r\n day = '0' + day\r\n }\r\n\r\n let hour = date.getUTCHours().toString()\r\n if (hour.length === 1) {\r\n hour = '0' + hour\r\n }\r\n\r\n let min = date.getUTCMinutes().toString()\r\n if (min.length === 1) {\r\n min = '0' + min\r\n }\r\n\r\n let sec = date.getUTCSeconds().toString()\r\n if (sec.length === 1) {\r\n sec = '0' + sec\r\n }\r\n\r\n return year + month + day + hour + min + sec + 'Z'\r\n }\r\n}\r\n\n\n\n// WEBPACK FOOTER //\n// ./src/CertificateUtils.ts","module.exports = __WEBPACK_EXTERNAL_MODULE_1__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external {\"commonjs\":\"forge\",\"commonjs2\":\"forge\",\"amd\":\"forge\",\"root\":\"forge\"}\n// module id = 1\n// module chunks = 0 1","import * as localforage from 'localforage';\r\nimport { IStorage } from './IStorage';\r\n\r\n/**\r\n * The browser storage class\r\n * \r\n * @export\r\n * @class Storage\r\n */\r\nexport default class LocalForageStorage implements IStorage {\r\n /**\r\n * Creates an instance of Storage.\r\n * \r\n * @param {string} name\r\n * \r\n * @memberOf Storage\r\n */\r\n constructor(private name: string) {\r\n localforage.config({\r\n name\r\n });\r\n }\r\n\r\n /**\r\n * Removes an item with the given key from storage\r\n * \r\n * @param {string} key\r\n * @returns {Promise}\r\n * \r\n * @memberOf Storage\r\n */\r\n remove(key: string): Promise {\r\n return localforage.removeItem(`${key}`);\r\n }\r\n\r\n /**\r\n * Sets the value of an item in storage based on the given key\r\n * \r\n * @template TValue\r\n * @param {string} key\r\n * @param {TValue} item\r\n * @returns {Promise}\r\n * \r\n * @memberOf Storage\r\n */\r\n set(key: string, item: TValue): Promise {\r\n return localforage.setItem(`${key}`, item);\r\n }\r\n\r\n /**\r\n * Gets the item with the given key from storage\r\n * \r\n * @template TValue\r\n * @param {string} key\r\n * @returns {Promise}\r\n * \r\n * @memberOf Storage\r\n */\r\n get(key: string): Promise {\r\n return localforage.getItem(`${key}`);\r\n }\r\n}\n\n\n// WEBPACK FOOTER //\n// ./src/LocalForageStorage.ts","module.exports = __WEBPACK_EXTERNAL_MODULE_3__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external {\"commonjs\":\"localforage\",\"commonjs2\":\"localforage\",\"amd\":\"localforage\",\"root\":\"localforage\"}\n// module id = 3\n// module chunks = 0 1"],"sourceRoot":""}