node-opcua-pki 6.10.1 → 6.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -825,10 +825,20 @@ async function construct_CertificateAuthority(certificateAuthority) {
825
825
  }
826
826
  }
827
827
  await construct_default_files();
828
- if (import_node_fs6.default.existsSync(import_node_path5.default.join(caRootDir, "private/cakey.pem")) && !config2.forceCA) {
829
- debugLog("CA private key already exists ... skipping");
828
+ const caKeyExists = import_node_fs6.default.existsSync(import_node_path5.default.join(caRootDir, "private/cakey.pem"));
829
+ const caCertExists = import_node_fs6.default.existsSync(import_node_path5.default.join(caRootDir, "public/cacert.pem"));
830
+ if (caKeyExists && caCertExists && !config2.forceCA) {
831
+ debugLog("CA private key and certificate already exist ... skipping");
830
832
  return;
831
833
  }
834
+ if (caKeyExists && !caCertExists) {
835
+ debugLog("CA private key exists but cacert.pem is missing \u2014 rebuilding CA");
836
+ import_node_fs6.default.unlinkSync(import_node_path5.default.join(caRootDir, "private/cakey.pem"));
837
+ const staleCsr = import_node_path5.default.join(caRootDir, "private/cakey.csr");
838
+ if (import_node_fs6.default.existsSync(staleCsr)) {
839
+ import_node_fs6.default.unlinkSync(staleCsr);
840
+ }
841
+ }
832
842
  displayTitle("Create Certificate Authority (CA)");
833
843
  const indexFileAttr = import_node_path5.default.join(caRootDir, "index.txt.attr");
834
844
  if (!import_node_fs6.default.existsSync(indexFileAttr)) {