diff --git a/changelog b/changelog index ce088e74..9e4bf415 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,5 @@ + * Support building with EC disabled * Close bug [3091576] Private key export is always PKCS#8 encoded * Feature Request [3058196] Autoload database * Feature Request [3058195] Export directly to the clipboard diff --git a/configure b/configure index 291812aa..c40b54cb 100755 --- a/configure +++ b/configure @@ -140,14 +140,12 @@ export LD_LIBRARY_PATH cat >conftest.c < #include -//#include +#include #include int main(){ printf("\nThe Versions of the used libraries are:\n\t%s 0x%lxL\n\tQT: %s\n", -// "\tOpenSC: %s\n", OPENSSL_VERSION_TEXT, OPENSSL_VERSION_NUMBER, QT_VERSION_STR -// , sc_get_version() ); if (QT_VERSION < 0x040300) { @@ -158,6 +156,10 @@ int main(){ printf("You need OpenSSL >= 0.9.8 or higher\n"); return 1; } +#ifdef OPENSSL_NO_EC + printf("\n### This OpenSSL installation has no EC cryptography support\n"); +#endif + puts("\n"); return 0; } EOF diff --git a/lib/pki_evp.cpp b/lib/pki_evp.cpp index a588c3f3..b18c36c7 100644 --- a/lib/pki_evp.cpp +++ b/lib/pki_evp.cpp @@ -27,9 +27,11 @@ QString pki_evp::passHash = QString(); QPixmap *pki_evp::icon[2]= { NULL, NULL }; +#ifndef OPENSSL_NO_EC EC_builtin_curve *pki_evp::curves = NULL; size_t pki_evp::num_curves = 0; unsigned char *pki_evp::curve_flags = NULL; +#endif void pki_evp::erasePasswd() { @@ -99,22 +101,20 @@ void pki_evp::setOwnPass(enum passType x) void pki_evp::generate(int bits, int type, QProgressBar *progress, int curve_nid) { - RSA *rsakey; - DSA *dsakey; - EC_KEY *eckey; - progress->setMinimum(0); progress->setMaximum(100); progress->setValue(50); switch (type) { case EVP_PKEY_RSA: + RSA *rsakey; rsakey = RSA_generate_key(bits, 0x10001, inc_progress_bar, progress); if (rsakey) EVP_PKEY_assign_RSA(key, rsakey); break; case EVP_PKEY_DSA: + DSA *dsakey; progress->setMaximum(500); dsakey = DSA_generate_parameters(bits, NULL, 0, NULL, NULL, inc_progress_bar, progress); @@ -122,7 +122,9 @@ void pki_evp::generate(int bits, int type, QProgressBar *progress, int curve_nid if (dsakey) EVP_PKEY_assign_DSA(key, dsakey); break; +#ifndef OPENSSL_NO_EC case EVP_PKEY_EC: + EC_KEY *eckey; EC_GROUP *group = EC_GROUP_new_by_curve_name(curve_nid); if (!group) break; @@ -142,6 +144,7 @@ void pki_evp::generate(int bits, int type, QProgressBar *progress, int curve_nid EC_KEY_free(eckey); EC_GROUP_free(group); break; +#endif } pki_openssl_error(); encryptKey(); @@ -180,8 +183,10 @@ static bool EVP_PKEY_isPrivKey(EVP_PKEY *key) return key->pkey.rsa->d ? true: false; case EVP_PKEY_DSA: return key->pkey.dsa->priv_key ? true: false; +#ifndef OPENSSL_NO_EC case EVP_PKEY_EC: return EC_KEY_get0_private_key(key->pkey.ec) ? true: false; +#endif } return false; } @@ -226,8 +231,14 @@ void pki_evp::fromPEM_BIO(BIO *bio, QString name) openssl_error(name); } -static void search_ec_oid(EC_KEY *ec) +static void search_ec_oid(EVP_PKEY *pkey) { +#ifndef OPENSSL_NO_EC + if (pkey->type != EVP_PKEY_EC) + return; + + EC_KEY *ec = pkey->pkey.ec; + const EC_GROUP *ec_group = EC_KEY_get0_group(ec); EC_GROUP *builtin; @@ -249,6 +260,7 @@ static void search_ec_oid(EC_KEY *ec) EC_GROUP_free(builtin); } } +#endif } void pki_evp::fload(const QString fname) @@ -311,8 +323,7 @@ void pki_evp::fload(const QString fname) throw errorEx(tr("Unable to load the private key in file %1. Tried PEM and DER private, public and PKCS#8 key types.").arg(fname)); } if (pkey){ - if (pkey->type == EVP_PKEY_EC) - search_ec_oid(pkey->pkey.ec); + search_ec_oid(pkey); if (key) EVP_PKEY_free(key); key = pkey; @@ -629,10 +640,12 @@ void pki_evp::writeKey(const QString fname, const EVP_CIPHER *enc, PEM_write_DSAPrivateKey(fp, pkey->pkey.dsa, enc, NULL, 0, cb, &p); break; +#ifndef OPENSSL_NO_EC case EVP_PKEY_EC: PEM_write_ECPrivateKey(fp, pkey->pkey.ec, enc, NULL, 0, cb, &p); break; +#endif default: PEM_write_PrivateKey(fp, pkey, enc, NULL, 0, cb, &p); @@ -675,7 +688,9 @@ const EVP_MD *pki_evp::getDefaultMD() switch (key->type) { case EVP_PKEY_RSA: md = EVP_sha1(); break; case EVP_PKEY_DSA: md = EVP_dss1(); break; +#ifndef OPENSSL_NO_EC case EVP_PKEY_EC: md = EVP_ecdsa(); break; +#endif default: md = NULL; break; } return md; diff --git a/lib/pki_evp.h b/lib/pki_evp.h index 4a061309..b733d6a8 100644 --- a/lib/pki_evp.h +++ b/lib/pki_evp.h @@ -37,10 +37,11 @@ class pki_evp: public pki_key static void setOldPasswd(const char *pass); static QString md5passwd(const char *pass); static QString sha512passwd(QString pass, QString salt); +#ifndef OPENSSL_NO_EC static EC_builtin_curve *curves; static size_t num_curves; static unsigned char *curve_flags; - +#endif void generate(int bits, int type, QProgressBar *progress); void generate(int bits, int type, QProgressBar *progress, int curve_nid); diff --git a/lib/pki_key.cpp b/lib/pki_key.cpp index 5f626ed5..49fb3b3f 100644 --- a/lib/pki_key.cpp +++ b/lib/pki_key.cpp @@ -209,7 +209,7 @@ QString pki_key::pubkey() return BN2QString(key->pkey.dsa->pub_key); return QString(); } - +#ifndef OPENSSL_NO_EC int pki_key::ecParamNid() { if (key->type != EVP_PKEY_EC) @@ -232,7 +232,7 @@ QString pki_key::ecPubKey() } return pub; } - +#endif bool pki_key::compare(pki_base *ref) { pki_key *kref = (pki_key *)ref; diff --git a/lib/pki_scard.cpp b/lib/pki_scard.cpp index ed3f2ddb..ffa2281e 100644 --- a/lib/pki_scard.cpp +++ b/lib/pki_scard.cpp @@ -66,8 +66,7 @@ QString pki_scard::getMsg(msg_type msg) EVP_PKEY *pki_scard::load_pubkey(pkcs11 &p11, CK_OBJECT_HANDLE object) const { - const unsigned char *p; - unsigned long s, keytype; + unsigned long keytype; EVP_PKEY *pkey = NULL; pk11_attr_ulong type(CKA_KEY_TYPE); @@ -113,7 +112,10 @@ EVP_PKEY *pki_scard::load_pubkey(pkcs11 &p11, CK_OBJECT_HANDLE object) const EVP_PKEY_assign_DSA(pkey, dsa); break; } +#ifndef OPENSSL_NO_EC case CKK_EC: { + unsigned long s; + const unsigned char *p; EC_KEY *ec = EC_KEY_new(); pk11_attr_data grp(CKA_EC_PARAMS); @@ -137,6 +139,7 @@ EVP_PKEY *pki_scard::load_pubkey(pkcs11 &p11, CK_OBJECT_HANDLE object) const EVP_PKEY_assign_EC_KEY(pkey, ec); break; } +#endif default: throw errorEx(QString("Unsupported CKA_KEY_TYPE: %1\n").arg(keytype)); } @@ -368,7 +371,9 @@ QList pki_scard::possibleHashNids() switch (mech_list[i]) { case CKM_MD5_RSA_PKCS: nids << NID_md5; break; case CKM_DSA_SHA1: +#ifndef OPENSSL_NO_EC case CKM_ECDSA_SHA1: +#endif case CKM_SHA1_RSA_PKCS: nids << NID_sha1; break; case CKM_SHA256_RSA_PKCS: nids << NID_sha256; break; case CKM_SHA384_RSA_PKCS: nids << NID_sha384; break; @@ -389,8 +394,10 @@ const EVP_MD *pki_scard::getDefaultMD() return EVP_sha1(); if (mech_list.contains(CKM_DSA_SHA1)) return EVP_dss1(); +#ifndef OPENSSL_NO_EC if (mech_list.contains(CKM_ECDSA_SHA1)) return EVP_ecdsa(); +#endif if (mech_list.contains(CKM_SHA512_RSA_PKCS)) return EVP_sha512(); if (mech_list.contains(CKM_SHA384_RSA_PKCS)) diff --git a/widgets/KeyDetail.cpp b/widgets/KeyDetail.cpp index 253d4c3e..3f4c7b6c 100644 --- a/widgets/KeyDetail.cpp +++ b/widgets/KeyDetail.cpp @@ -25,6 +25,7 @@ KeyDetail::KeyDetail(QWidget *parent) keyDesc->setReadOnly(true); } +#ifndef OPENSSL_NO_EC static QString CurveComment(int nid) { for (size_t i=0; isetText(key->getIntName()); keyLength->setText(key->length()); @@ -74,7 +74,9 @@ void KeyDetail::setKey(pki_key *key) keyPubEx->setText(key->subprime()); keyModulus->setText(key->pubkey()); break; +#ifndef OPENSSL_NO_EC case EVP_PKEY_EC: + int nid; nid = key->ecParamNid(); tlModulus->setText(tr("Public key")); tlPrivEx->setText(tr("Private key")); @@ -83,6 +85,7 @@ void KeyDetail::setKey(pki_key *key) keyPubEx->setToolTip(CurveComment(nid)); keyModulus->setText(key->ecPubKey()); break; +#endif default: tlHeader->setText(tr("Unknown key")); } diff --git a/widgets/MainWindow.cpp b/widgets/MainWindow.cpp index 5eb15d2c..677091f9 100644 --- a/widgets/MainWindow.cpp +++ b/widgets/MainWindow.cpp @@ -101,6 +101,7 @@ static const int other_curve_nids[] = { static void init_curves() { +#ifndef OPENSSL_NO_EC pki_evp::num_curves = EC_get_builtin_curves(NULL, 0); pki_evp::curves = (EC_builtin_curve*)OPENSSL_malloc( (int)(sizeof(EC_builtin_curve) *pki_evp::num_curves)); @@ -129,6 +130,7 @@ static void init_curves() } } } +#endif } void MainWindow::enableTokenMenu(bool enable) diff --git a/widgets/NewKey.cpp b/widgets/NewKey.cpp index b1d15036..d238eed0 100644 --- a/widgets/NewKey.cpp +++ b/widgets/NewKey.cpp @@ -24,7 +24,9 @@ struct typelist { static const struct typelist typeList[] = { { "RSA", EVP_PKEY_RSA }, { "DSA", EVP_PKEY_DSA }, +#ifndef OPENSSL_NO_EC { "EC", EVP_PKEY_EC }, +#endif }; class keyListItem @@ -97,7 +99,7 @@ NewKey::NewKey(QWidget *parent, QString name) keyListItem gk(typeList +i); keytypes << gk; } - +#ifndef OPENSSL_NO_EC for (i = 0; iaddItems(curve_x962); curveBox->addItems(curve_other); +#endif keyLength->setCurrentIndex(0); keyDesc->setFocus(); if (pkcs11::loaded()) try { diff --git a/widgets/hashBox.cpp b/widgets/hashBox.cpp index 78a6b6ed..5dc0051f 100644 --- a/widgets/hashBox.cpp +++ b/widgets/hashBox.cpp @@ -40,8 +40,10 @@ const EVP_MD *hashBox::currentHash() switch(key_type) { case EVP_PKEY_DSA: return EVP_dss1(); +#ifndef OPENSSL_NO_EC case EVP_PKEY_EC: return EVP_ecdsa(); +#endif default: QString hash = currentText(); for (unsigned i=0; i