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/bin/pki.mjs CHANGED
@@ -2470,10 +2470,20 @@ async function construct_CertificateAuthority(certificateAuthority) {
2470
2470
  }
2471
2471
  }
2472
2472
  await construct_default_files();
2473
- if (fs9.existsSync(path6.join(caRootDir, "private/cakey.pem")) && !config3.forceCA) {
2474
- debugLog("CA private key already exists ... skipping");
2473
+ const caKeyExists = fs9.existsSync(path6.join(caRootDir, "private/cakey.pem"));
2474
+ const caCertExists = fs9.existsSync(path6.join(caRootDir, "public/cacert.pem"));
2475
+ if (caKeyExists && caCertExists && !config3.forceCA) {
2476
+ debugLog("CA private key and certificate already exist ... skipping");
2475
2477
  return;
2476
2478
  }
2479
+ if (caKeyExists && !caCertExists) {
2480
+ debugLog("CA private key exists but cacert.pem is missing \u2014 rebuilding CA");
2481
+ fs9.unlinkSync(path6.join(caRootDir, "private/cakey.pem"));
2482
+ const staleCsr = path6.join(caRootDir, "private/cakey.csr");
2483
+ if (fs9.existsSync(staleCsr)) {
2484
+ fs9.unlinkSync(staleCsr);
2485
+ }
2486
+ }
2477
2487
  displayTitle("Create Certificate Authority (CA)");
2478
2488
  const indexFileAttr = path6.join(caRootDir, "index.txt.attr");
2479
2489
  if (!fs9.existsSync(indexFileAttr)) {