Close #24: Add LibreSSL support. Tested with LibreSSL 2.7.2

This commit is contained in:
Christian Hohnstaedt 2018-04-22 16:12:04 +02:00
parent 331b79bd9d
commit bfe6fbbc43
4 changed files with 12 additions and 17 deletions

View File

@ -14,6 +14,8 @@
#ifndef __OPENSS_COMPAT_XCA_H
#define __OPENSS_COMPAT_XCA_H
#include <openssl/opensslv.h>
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#include <openssl/rsa.h>
#include <openssl/dsa.h>
@ -75,7 +77,7 @@ RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q)
}
static inline void
RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1, const BIGNUM **dmq1,
const BIGNUM **iqmp)
const BIGNUM **iqmp)
{
if (dmp1) *dmp1=r->dmp1;
if (dmq1) *dmq1=r->dmq1;

View File

@ -660,8 +660,8 @@ int pkcs11::encrypt(int flen, const unsigned char *from,
return size;
}
#if OPENSSL_VERSION_NUMBER < 0x10000000L || \
OPENSSL_VERSION_NUMBER >= 0x10100000L
#if OPENSSL_VERSION_NUMBER < 0x10000000L || \
OPENSSL_VERSION_NUMBER >= 0x10100000L && ! defined LIBRESSL_VERSION_NUMBER
static int rsa_privdata_free(RSA *rsa)
{
pkcs11 *priv = (pkcs11*)RSA_get_app_data(rsa);

View File

@ -510,7 +510,8 @@ EVP_PKEY *pki_evp::legacyDecryptKey(QByteArray &myencKey,
(const unsigned char*)myencKey.constData() +8,
myencKey.count() -8);
decsize = outl;
EVP_DecryptFinal(ctx, p + decsize , &outl);
EVP_DecryptFinal_ex(ctx, p + decsize , &outl);
EVP_CIPHER_CTX_cleanup(ctx);
decsize += outl;
pki_openssl_error();
tmpkey = d2i_PrivateKey(getKeyType(), NULL, &p1, decsize);
@ -721,27 +722,24 @@ void pki_evp::writeDefault(const QString fname)
mycb, true);
}
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined LIBRESSL_VERSION_NUMBER
int PEM_write_bio_PrivateKey_traditional(BIO *bp, EVP_PKEY *x,
const EVP_CIPHER *enc,
unsigned char *kstr, int klen,
pem_password_cb *cb, void *u)
{
const char *t = "";
char pem_str[80];
int keytype = EVP_PKEY_id(x);
switch (keytype) {
case EVP_PKEY_RSA: t = "RSA"; break;
case EVP_PKEY_DSA: t = "DSA"; break;
case EVP_PKEY_RSA: t = "RSA PRIVATE KEY"; break;
case EVP_PKEY_DSA: t = "DSA PRIVATE KEY"; break;
#ifndef OPENSSL_NO_EC
case EVP_PKEY_EC: t = "EC"; break;
case EVP_PKEY_EC: t = "EC PRIVATE KEY"; break;
#endif
}
BIO_snprintf(pem_str, 80, "%s PRIVATE KEY", t);
return PEM_ASN1_write_bio((i2d_of_void *)i2d_PrivateKey,
pem_str, bp, (char*)x, enc, kstr, klen, cb, u);
t, bp, (char*)x, enc, kstr, klen, cb, u);
}
#endif

View File

@ -399,13 +399,8 @@ BIO *pki_temp::pem(BIO *b, int format)
QByteArray ba = toExportData();
if (!b)
b = BIO_new(BIO_s_mem());
#if OPENSSL_VERSION_NUMBER < 0x10002000L
PEM_write_bio(b, PEM_STRING_XCA_TEMPLATE, (char*)"",
(unsigned char*)(ba.data()), ba.size());
#else
PEM_write_bio(b, PEM_STRING_XCA_TEMPLATE, "",
(const unsigned char*)(ba.constData()), ba.size());
#endif
pki_openssl_error();
return b;
}