in src/Sfx-Standalone/modules/prompt.select-certificate/select-certificate.ts [43:143]
constructor($scope: ISelectCertScope) {
$scope.certInfos = promptContext.promptOptions.data || [];
$scope.certInfos = $scope.certInfos.filter((certInfo) => certInfo.hasPrivateKey);
$scope.isPfx = () => $scope.certFilePath && /\.pfx$/i.test($scope.certFilePath);
$scope.keyFileRequired = () => $scope.certFilePath && !$scope.isPfx();
$scope.certSelected = () =>
($scope.selectedCertInfo !== null
&& $scope.selectedCertInfo !== undefined)
|| ($scope.selectedCertInfo === null
&& typeof $scope.certFilePath === "string"
&& $scope.certFilePath.trim() !== "");
$scope.passwordRequired = () => $scope.keyFileRequired() || $scope.isPfx();
$scope.updateSelectedCert = (certInfo: ICertificateInfo) => {
$scope.selectedCertInfo = certInfo;
};
$scope.selectCert = async () => {
if (!$scope.selectedCertInfo) {
const certLoader = await sfxModuleManager.getComponentAsync("cert.cert-loader");
if ($scope.keyFileRequired()) {
$scope.selectedCertInfo = await certLoader.loadPemAsync($scope.certFilePath, $scope.keyFilePath, $scope.password);
} else {
$scope.selectedCertInfo = await certLoader.loadPfxAsync($scope.certFilePath, $scope.password);
}
}
promptContext.finish($scope.selectedCertInfo);
};
$scope.browseCertFiles = () => {
const selectedFiles = electron.dialog.showOpenDialog({
title: "Open a client certificate ...",
filters: [
{
name: "certificates",
extensions: ["pfx", "PFX", "pem", "PEM", "crt", "CRT", "cer", "CER"]
},
{
name: "PFX",
extensions: ["pfx", "PFX"]
},
{
name: "PEM",
extensions: ["pem", "PEM"]
},
{
name: "CRT",
extensions: ["crt", "CRT"]
},
{
name: "CER",
extensions: ["cer", "CER"]
}
],
message: "Please select a certificate to use.",
properties: ["openFile", "createDirectory"]
});
if (!selectedFiles || selectedFiles.length <= 0) {
return;
}
$scope.certFilePath = selectedFiles[0];
};
$scope.browseKeyFiles = () => {
const selectedFiles = electron.dialog.showOpenDialog({
title: "Open a key file for the client certificate ...",
filters: [
{
name: "key file",
extensions: ["key"]
}
],
message: "Please select the key for the supplied client certificate.",
properties: ["openFile", "createDirectory"]
});
if (!selectedFiles || selectedFiles.length <= 0) {
return;
}
$scope.keyFilePath = selectedFiles[0];
};
$scope.getDateString = (date) => new Date(date).toLocaleDateString("en-US", { year: "numeric", month: "2-digit", day: "2-digit" });
$scope.isCertValid = (startDate, expiryDate) => {
const now = Date.now();
return now >= startDate && now < expiryDate;
};
$scope.cancel = () => promptContext.finish(null);
}