Skip to content
Snippets Groups Projects
Commit 1fb1af9d authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Add --import-pkcs12 and --export-pkcs12 options

To import, the private key and cert must be encrypted using the system
password.  On export, the cert/key are encrypted with the system password.
parent f1094791
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
......@@ -100,3 +100,40 @@ if (argv.indexOf('--import') > -1) {
print("Certificate imported, delete "+csr_fname+" after verifying.");
file_touch(recycle_sem);
}
if (argv.indexOf('--import-pkcs12') > -1) {
i = argv.indexOf('--import-pkcs12') + 1;
if (i>=argc)
throw("No cert filename specified");
ks = new CryptKeyset(argv[i], CryptKeyset.KEYOPT.READONLY);
rsa = ks.get_private_key("[none]", syspass);
ks.close();
for (i=0; i < 10; i++) {
if (file_remove(sks_fname))
break;
mswait(100);
}
if (i == 10)
throw("Unable to delete file "+sks_fname);
ks = new CryptKeyset(sks_fname, CryptKeyset.KEYOPT.CREATE);
ks.add_private_key(rsa, syspass);
ks.close();
print("Certificate imported.");
file_touch(recycle_sem);
}
if (argv.indexOf('--export-pkcs12') > -1) {
i = argv.indexOf('--export-pkcs12') + 1;
if (i>=argc)
throw("No cert filename specified");
if (argv[i].search(/\.p12$/) === -1)
throw("Filename must end in .p12");
ks = new CryptKeyset(sks_fname, CryptKeyset.KEYOPT.READONLY);
rsa = ks.get_private_key("ssl_cert", syspass);
ks.close();
ks = new CryptKeyset(argv[i], CryptKeyset.KEYOPT.CREATE);
ks.add_private_key(rsa, syspass);
ks.close();
print("Certificate exported.");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment