75 lines
3.9 KiB
JavaScript
75 lines
3.9 KiB
JavaScript
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||
|
// Licensed under the MIT license.
|
||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||
|
});
|
||
|
};
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.uninstallCaCertificate = exports.deleteCertificateFiles = void 0;
|
||
|
const child_process_1 = require("child_process");
|
||
|
const fsExtra = require("fs-extra");
|
||
|
const path = require("path");
|
||
|
const defaults = require("./defaults");
|
||
|
const verify_1 = require("./verify");
|
||
|
const defaults_1 = require("./defaults");
|
||
|
const office_addin_usage_data_1 = require("office-addin-usage-data");
|
||
|
/* global process, console, __dirname */
|
||
|
function getUninstallCommand(machine = false) {
|
||
|
switch (process.platform) {
|
||
|
case "win32": {
|
||
|
const script = path.resolve(__dirname, "..\\scripts\\uninstall.ps1");
|
||
|
return `powershell -ExecutionPolicy Bypass -File "${script}" ${machine ? "LocalMachine" : "CurrentUser"} "${defaults.certificateName}"`;
|
||
|
}
|
||
|
case "darwin": {
|
||
|
// macOS
|
||
|
const script = path.resolve(__dirname, "../scripts/uninstall.sh");
|
||
|
return `sudo sh '${script}' '${defaults.certificateName}'`;
|
||
|
}
|
||
|
case "linux":
|
||
|
const script = path.resolve(__dirname, "../scripts/uninstall_linux.sh");
|
||
|
return `sudo sh '${script}' '${defaults.caCertificateFileName}'`;
|
||
|
default:
|
||
|
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}`);
|
||
|
}
|
||
|
}
|
||
|
// Deletes the generated certificate files and delete the certificate directory if its empty
|
||
|
function deleteCertificateFiles(certificateDirectory = defaults.certificateDirectory) {
|
||
|
if (fsExtra.existsSync(certificateDirectory)) {
|
||
|
fsExtra.removeSync(path.join(certificateDirectory, defaults.localhostCertificateFileName));
|
||
|
fsExtra.removeSync(path.join(certificateDirectory, defaults.localhostKeyFileName));
|
||
|
fsExtra.removeSync(path.join(certificateDirectory, defaults.caCertificateFileName));
|
||
|
if (fsExtra.readdirSync(certificateDirectory).length === 0) {
|
||
|
fsExtra.removeSync(certificateDirectory);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
exports.deleteCertificateFiles = deleteCertificateFiles;
|
||
|
function uninstallCaCertificate(machine = false, verbose = true) {
|
||
|
return __awaiter(this, void 0, void 0, function* () {
|
||
|
if ((0, verify_1.isCaCertificateInstalled)(/* returnInvalidCertificate */ true)) {
|
||
|
const command = getUninstallCommand(machine);
|
||
|
try {
|
||
|
console.log(`Uninstalling CA certificate "Developer CA for Microsoft Office Add-ins"...`);
|
||
|
(0, child_process_1.execSync)(command, { stdio: "pipe" });
|
||
|
console.log(`You no longer have trusted access to https://localhost.`);
|
||
|
defaults_1.usageDataObject.reportSuccess("uninstallCaCertificate()");
|
||
|
}
|
||
|
catch (error) {
|
||
|
defaults_1.usageDataObject.reportException("uninstallCaCertificate()", error);
|
||
|
throw new Error(`Unable to uninstall the CA certificate.\n${error.stderr.toString()}`);
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
if (verbose) {
|
||
|
console.log(`The CA certificate is not installed.`);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
exports.uninstallCaCertificate = uninstallCaCertificate;
|
||
|
//# sourceMappingURL=uninstall.js.map
|