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.mjs CHANGED
@@ -782,10 +782,20 @@ async function construct_CertificateAuthority(certificateAuthority) {
782
782
  }
783
783
  }
784
784
  await construct_default_files();
785
- if (fs6.existsSync(path5.join(caRootDir, "private/cakey.pem")) && !config2.forceCA) {
786
- debugLog("CA private key already exists ... skipping");
785
+ const caKeyExists = fs6.existsSync(path5.join(caRootDir, "private/cakey.pem"));
786
+ const caCertExists = fs6.existsSync(path5.join(caRootDir, "public/cacert.pem"));
787
+ if (caKeyExists && caCertExists && !config2.forceCA) {
788
+ debugLog("CA private key and certificate already exist ... skipping");
787
789
  return;
788
790
  }
791
+ if (caKeyExists && !caCertExists) {
792
+ debugLog("CA private key exists but cacert.pem is missing \u2014 rebuilding CA");
793
+ fs6.unlinkSync(path5.join(caRootDir, "private/cakey.pem"));
794
+ const staleCsr = path5.join(caRootDir, "private/cakey.csr");
795
+ if (fs6.existsSync(staleCsr)) {
796
+ fs6.unlinkSync(staleCsr);
797
+ }
798
+ }
789
799
  displayTitle("Create Certificate Authority (CA)");
790
800
  const indexFileAttr = path5.join(caRootDir, "index.txt.attr");
791
801
  if (!fs6.existsSync(indexFileAttr)) {