Add PKCS12 enc algo setting and use it when exporting PKCS12

This commit is contained in:
Tobias Wich 2022-10-06 15:03:36 +02:00
parent d177f8cd08
commit 097cbfb815
6 changed files with 32 additions and 6 deletions

View File

@ -662,7 +662,8 @@ void db_x509::writePKCS12(pki_x509 *cert, XFile &file, bool chain) const
cert = signer;
signer = signer->getSigner();
}
p12->writePKCS12(file);
encAlgo encAlgo((QString) Settings["pkcs12_enc_algo"]);
p12->writePKCS12(file, encAlgo);
}
catch (errorEx &err) {
XCA_ERROR(err);

View File

@ -118,7 +118,7 @@ pki_pkcs12::pki_pkcs12(const QString &fname)
pki_openssl_error();
}
void pki_pkcs12::writePKCS12(XFile &file) const
void pki_pkcs12::writePKCS12(XFile &file, encAlgo &encAlgo) const
{
Passwd pass;
PKCS12 *pkcs12;
@ -137,9 +137,10 @@ void pki_pkcs12::writePKCS12(XFile &file) const
if (x && x != cert)
sk_X509_push(certstack, x->getCert());
}
int encAlgoNid = encAlgo.getEncAlgoNid();
pkcs12 = PKCS12_create(pass.data(), getIntName().toUtf8().data(),
key->decryptKey(), cert->getCert(), certstack,
NID_pbe_WithSHA1And3_Key_TripleDES_CBC, NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
encAlgoNid, encAlgoNid,
0, 0, 0);
BioByteArray b;
i2d_PKCS12_bio(b, pkcs12);

View File

@ -57,6 +57,6 @@ class pki_pkcs12: public pki_multi
{
return cert;
}
void writePKCS12(XFile &file) const;
void writePKCS12(XFile &file, encAlgo &encAlgo) const;
};
#endif

View File

@ -3,6 +3,7 @@
#include "sql.h"
#include "pki_key.h"
#include "digest.h"
#include "pki_pkcs12.h"
#include "pki_export.h"
#include <QDir>
@ -34,6 +35,7 @@ settings::settings()
defaul["string_opt"] = "MASK:0x2002";
defaul["workingdir"] = "";
defaul["default_hash"] = digest::getDefault().name();
defaul["pkcs12_enc_algo"] = encAlgo::getDefault().name();
defaul["ical_expiry"] = "1W";
defaul["cert_expiry"] = "80%";
defaul["serial_len"] = "64";
@ -59,6 +61,8 @@ void settings::setAction(const QString &key, const QString &value)
ASN1_STRING_set_default_mask_asc((char*)CCHAR(value));
else if (key == "default_hash")
digest::setDefault(value);
else if (key == "pkcs12_enc_algo")
encAlgo::setDefault(value);
else if (key == "defaultkey")
keyjob::defaultjob = keyjob(value);
else if (key == "optionflags") {

View File

@ -56,6 +56,20 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>PKCS12 encryption algorithm</string>
</property>
</widget>
</item>
<item>
<widget class="pkcs12EncBox" name="pkcs12EncAlgo"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<item>
@ -423,15 +437,20 @@ Especially EC and DSA are only defined with SHA1 in the PKCS#11 specification.</
</layout>
</widget>
<customwidgets>
<customwidget>
<class>focusCombo</class>
<extends>QComboBox</extends>
<header>widgets/FocusCombo.h</header>
</customwidget>
<customwidget>
<class>hashBox</class>
<extends>QComboBox</extends>
<header>widgets/hashBox.h</header>
</customwidget>
<customwidget>
<class>focusCombo</class>
<class>pkcs12EncBox</class>
<extends>QComboBox</extends>
<header>widgets/FocusCombo.h</header>
<header>widgets/pkcs12EncBox.h</header>
</customwidget>
</customwidgets>
<tabstops>

View File

@ -147,6 +147,7 @@ int Options::exec()
Settings["disable_netscape"] = disableNetscape->checkState();
Settings["default_hash"] = hashAlgo->current().name();
Settings["pkcs12_enc_algo"] = pkcs12EncAlgo->current().name();
Settings["mandatory_dn"] = getDnString(extDNlist);
Settings["explicit_dn"] = getDnString(expDNlist);
Settings["string_opt"] = string_opts[mbstring->currentIndex()];