15815213711
2024-08-26 67b8b6731811983447e053d4396b3708c14dfe3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.importCertificate = void 0;
const fs_extra_1 = require("fs-extra");
const os_1 = require("os");
const path = require("path");
const builder_util_1 = require("builder-util");
const fs_1 = require("builder-util/out/fs");
const binDownload_1 = require("../binDownload");
/** @private */
async function importCertificate(cscLink, tmpDir, currentDir) {
    var _a, _b;
    cscLink = cscLink.trim();
    let file = null;
    if ((cscLink.length > 3 && cscLink[1] === ":") || cscLink.startsWith("/") || cscLink.startsWith(".")) {
        file = cscLink;
    }
    else if (cscLink.startsWith("file://")) {
        file = cscLink.substring("file://".length);
    }
    else if (cscLink.startsWith("~/")) {
        file = path.join(os_1.homedir(), cscLink.substring("~/".length));
    }
    else if (cscLink.startsWith("https://")) {
        const tempFile = await tmpDir.getTempFile({ suffix: ".p12" });
        await binDownload_1.download(cscLink, tempFile);
        return tempFile;
    }
    else {
        const mimeType = (_a = /data:.*;base64,/.exec(cscLink)) === null || _a === void 0 ? void 0 : _a[0];
        if (mimeType || cscLink.length > 2048 || cscLink.endsWith("=")) {
            const tempFile = await tmpDir.getTempFile({ suffix: ".p12" });
            await fs_extra_1.outputFile(tempFile, Buffer.from(cscLink.substring((_b = mimeType === null || mimeType === void 0 ? void 0 : mimeType.length) !== null && _b !== void 0 ? _b : 0), "base64"));
            return tempFile;
        }
        file = cscLink;
    }
    file = path.resolve(currentDir, file);
    const stat = await fs_1.statOrNull(file);
    if (stat == null) {
        throw new builder_util_1.InvalidConfigurationError(`${file} doesn't exist`);
    }
    else if (!stat.isFile()) {
        throw new builder_util_1.InvalidConfigurationError(`${file} not a file`);
    }
    else {
        return file;
    }
}
exports.importCertificate = importCertificate;
//# sourceMappingURL=codesign.js.map