103 lines
5.2 KiB
JavaScript
103 lines
5.2 KiB
JavaScript
"use strict";
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT license.
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
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());
|
|
});
|
|
};
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.uninstallCaCertificate = exports.deleteCertificateFiles = void 0;
|
|
const child_process_1 = require("child_process");
|
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
const path_1 = __importDefault(require("path"));
|
|
const defaults = __importStar(require("./defaults"));
|
|
const verify_1 = require("./verify");
|
|
const defaults_1 = require("./defaults");
|
|
const office_addin_usage_data_1 = require("office-addin-usage-data");
|
|
/* global console process __dirname */
|
|
function getUninstallCommand(machine = false) {
|
|
switch (process.platform) {
|
|
case "win32": {
|
|
const script = path_1.default.resolve(__dirname, "..\\scripts\\uninstall.ps1");
|
|
return `powershell -ExecutionPolicy Bypass -File "${script}" ${machine ? "LocalMachine" : "CurrentUser"} "${defaults.certificateName}"`;
|
|
}
|
|
case "darwin": {
|
|
// macOS
|
|
const script = path_1.default.resolve(__dirname, "../scripts/uninstall.sh");
|
|
return `sudo sh '${script}' '${defaults.certificateName}'`;
|
|
}
|
|
case "linux": {
|
|
const script = path_1.default.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 (fs_extra_1.default.existsSync(certificateDirectory)) {
|
|
fs_extra_1.default.removeSync(path_1.default.join(certificateDirectory, defaults.localhostCertificateFileName));
|
|
fs_extra_1.default.removeSync(path_1.default.join(certificateDirectory, defaults.localhostKeyFileName));
|
|
fs_extra_1.default.removeSync(path_1.default.join(certificateDirectory, defaults.caCertificateFileName));
|
|
if (fs_extra_1.default.readdirSync(certificateDirectory).length === 0) {
|
|
fs_extra_1.default.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
|