Blame ecryptfs-utils-openssl11.patch

Raphael Groner 37c148
=== modified file 'src/key_mod/ecryptfs_key_mod_openssl.c'
Raphael Groner 37c148
--- src/key_mod/ecryptfs_key_mod_openssl.c	2013-10-25 19:45:09 +0000
Raphael Groner 37c148
+++ src/key_mod/ecryptfs_key_mod_openssl.c	2017-06-02 18:27:28 +0000
Raphael Groner 37c148
@@ -41,6 +41,7 @@
Raphael Groner 37c148
 #include <stdlib.h>
Raphael Groner 37c148
 #include <unistd.h>
Raphael Groner 37c148
 #include <libgen.h>
Raphael Groner 37c148
+#include <openssl/bn.h>
Raphael Groner 37c148
 #include <openssl/pem.h>
Raphael Groner 37c148
 #include <openssl/rsa.h>
Raphael Groner 37c148
 #include <openssl/err.h>
Raphael Groner 37c148
@@ -55,6 +56,19 @@
Raphael Groner 37c148
 	char *passphrase;
Raphael Groner 37c148
 };
Raphael Groner 37c148
 
Raphael Groner 37c148
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
Raphael Groner 37c148
+static void RSA_get0_key(const RSA *r,
Raphael Groner 37c148
+                 const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
Raphael Groner 37c148
+{
Raphael Groner 37c148
+   if (n != NULL)
Raphael Groner 37c148
+       *n = r->n;
Raphael Groner 37c148
+   if (e != NULL)
Raphael Groner 37c148
+       *e = r->e;
Raphael Groner 37c148
+   if (d != NULL)
Raphael Groner 37c148
+       *d = r->d;
Raphael Groner 37c148
+}
Raphael Groner 37c148
+#endif
Raphael Groner 37c148
+
Raphael Groner 37c148
 static void
Raphael Groner 37c148
 ecryptfs_openssl_destroy_openssl_data(struct openssl_data *openssl_data)
Raphael Groner 37c148
 {
Raphael Groner 37c148
@@ -142,6 +156,7 @@
Raphael Groner 37c148
 {
Raphael Groner 37c148
 	int len, nbits, ebits, i;
Raphael Groner 37c148
 	int nbytes, ebytes;
Raphael Groner 37c148
+	const BIGNUM *key_n, *key_e;
Raphael Groner 37c148
 	unsigned char *hash;
Raphael Groner 37c148
 	unsigned char *data = NULL;
Raphael Groner 37c148
 	int rc = 0;
Raphael Groner 37c148
@@ -152,11 +167,13 @@
Raphael Groner 37c148
 		rc = -ENOMEM;
Raphael Groner 37c148
 		goto out;
Raphael Groner 37c148
 	}
Raphael Groner 37c148
-	nbits = BN_num_bits(key->n);
Raphael Groner 37c148
+	RSA_get0_key(key, &key_n, NULL, NULL);
Raphael Groner 37c148
+	nbits = BN_num_bits(key_n);
Raphael Groner 37c148
 	nbytes = nbits / 8;
Raphael Groner 37c148
 	if (nbits % 8)
Raphael Groner 37c148
 		nbytes++;
Raphael Groner 37c148
-	ebits = BN_num_bits(key->e);
Raphael Groner 37c148
+	RSA_get0_key(key, NULL, &key_e, NULL);
Raphael Groner 37c148
+	ebits = BN_num_bits(key_e);
Raphael Groner 37c148
 	ebytes = ebits / 8;
Raphael Groner 37c148
 	if (ebits % 8)
Raphael Groner 37c148
 		ebytes++;
Raphael Groner 37c148
@@ -179,11 +196,13 @@
Raphael Groner 37c148
 	data[i++] = '\02';
Raphael Groner 37c148
 	data[i++] = (nbits >> 8);
Raphael Groner 37c148
 	data[i++] = nbits;
Raphael Groner 37c148
-	BN_bn2bin(key->n, &(data[i]));
Raphael Groner 37c148
+	RSA_get0_key(key, &key_n, NULL, NULL);
Raphael Groner 37c148
+	BN_bn2bin(key_n, &(data[i]));
Raphael Groner 37c148
 	i += nbytes;
Raphael Groner 37c148
 	data[i++] = (ebits >> 8);
Raphael Groner 37c148
 	data[i++] = ebits;
Raphael Groner 37c148
-	BN_bn2bin(key->e, &(data[i]));
Raphael Groner 37c148
+	RSA_get0_key(key, NULL, &key_e, NULL);
Raphael Groner 37c148
+	BN_bn2bin(key_e, &(data[i]));
Raphael Groner 37c148
 	i += ebytes;
Raphael Groner 37c148
 	SHA1(data, len + 3, hash);
Raphael Groner 37c148
 	to_hex(sig, (char *)hash, ECRYPTFS_SIG_SIZE);
Raphael Groner 37c148
@@ -278,7 +297,9 @@
Raphael Groner 37c148
 	BIO *in = NULL;
Raphael Groner 37c148
 	int rc;
Raphael Groner 37c148
 
Raphael Groner 37c148
+	#if OPENSSL_VERSION_NUMBER < 0x10100000L
Raphael Groner 37c148
 	CRYPTO_malloc_init();
Raphael Groner 37c148
+	#endif
Raphael Groner 37c148
 	ERR_load_crypto_strings();
Raphael Groner 37c148
 	OpenSSL_add_all_algorithms();
Raphael Groner 37c148
 	ENGINE_load_builtin_engines();
Raphael Groner 37c148
Raphael Groner 37c148
=== modified file 'src/key_mod/ecryptfs_key_mod_pkcs11_helper.c'
Raphael Groner 37c148
--- src/key_mod/ecryptfs_key_mod_pkcs11_helper.c	2013-10-25 19:45:09 +0000
Raphael Groner 37c148
+++ src/key_mod/ecryptfs_key_mod_pkcs11_helper.c	2017-06-02 18:27:28 +0000
Raphael Groner 37c148
@@ -41,6 +41,7 @@
Raphael Groner 37c148
 #include <errno.h>
Raphael Groner 37c148
 #include <stdlib.h>
Raphael Groner 37c148
 #include <unistd.h>
Raphael Groner 37c148
+#include <openssl/bn.h>
Raphael Groner 37c148
 #include <openssl/err.h>
Raphael Groner 37c148
 #include <openssl/pem.h>
Raphael Groner 37c148
 #include <openssl/x509.h>
Raphael Groner 37c148
@@ -77,6 +78,19 @@
Raphael Groner 37c148
 typedef const unsigned char *__pkcs11_openssl_d2i_t;
Raphael Groner 37c148
 #endif
Raphael Groner 37c148
 
Raphael Groner 37c148
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
Raphael Groner 37c148
+static void RSA_get0_key(const RSA *r,
Raphael Groner 37c148
+                 const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
Raphael Groner 37c148
+{
Raphael Groner 37c148
+   if (n != NULL)
Raphael Groner 37c148
+       *n = r->n;
Raphael Groner 37c148
+   if (e != NULL)
Raphael Groner 37c148
+       *e = r->e;
Raphael Groner 37c148
+   if (d != NULL)
Raphael Groner 37c148
+       *d = r->d;
Raphael Groner 37c148
+}
Raphael Groner 37c148
+#endif
Raphael Groner 37c148
+
Raphael Groner 37c148
 /**
Raphael Groner 37c148
  * ecryptfs_pkcs11h_deserialize
Raphael Groner 37c148
  * @pkcs11h_data: The deserialized version of the key module data;
Raphael Groner 37c148
@@ -282,7 +296,11 @@
Raphael Groner 37c148
 		goto out;
Raphael Groner 37c148
 	}
Raphael Groner 37c148
 	
Raphael Groner 37c148
+	#if OPENSSL_VERSION_NUMBER < 0x10100000L
Raphael Groner 37c148
 	if (pubkey->type != EVP_PKEY_RSA) {
Raphael Groner 37c148
+	#else
Raphael Groner 37c148
+	if (EVP_PKEY_base_id(pubkey) != EVP_PKEY_RSA) {
Raphael Groner 37c148
+	#endif
Raphael Groner 37c148
 		syslog(LOG_ERR, "PKCS#11: Invalid public key algorithm");
Raphael Groner 37c148
 		rc = -EIO;
Raphael Groner 37c148
 		goto out;
Raphael Groner 37c148
@@ -318,6 +336,7 @@
Raphael Groner 37c148
 	int nbytes, ebytes;
Raphael Groner 37c148
 	char *hash = NULL;
Raphael Groner 37c148
 	char *data = NULL;
Raphael Groner 37c148
+	const BIGNUM *rsa_n, *rsa_e;
Raphael Groner 37c148
 	int rc;
Raphael Groner 37c148
 
Raphael Groner 37c148
 	if ((rc = ecryptfs_pkcs11h_get_public_key(&rsa, blob))) {
Raphael Groner 37c148
@@ -331,11 +350,13 @@
Raphael Groner 37c148
 		rc = -ENOMEM;
Raphael Groner 37c148
 		goto out;
Raphael Groner 37c148
 	}
Raphael Groner 37c148
-	nbits = BN_num_bits(rsa->n);
Raphael Groner 37c148
+	RSA_get0_key(rsa, &rsa_n, NULL, NULL);
Raphael Groner 37c148
+	nbits = BN_num_bits(rsa_n);
Raphael Groner 37c148
 	nbytes = nbits / 8;
Raphael Groner 37c148
 	if (nbits % 8)
Raphael Groner 37c148
 		nbytes++;
Raphael Groner 37c148
-	ebits = BN_num_bits(rsa->e);
Raphael Groner 37c148
+	RSA_get0_key(rsa, NULL, &rsa_e, NULL);
Raphael Groner 37c148
+	ebits = BN_num_bits(rsa_e);
Raphael Groner 37c148
 	ebytes = ebits / 8;
Raphael Groner 37c148
 	if (ebits % 8)
Raphael Groner 37c148
 		ebytes++;
Raphael Groner 37c148
@@ -358,11 +379,13 @@
Raphael Groner 37c148
 	data[i++] = '\02';
Raphael Groner 37c148
 	data[i++] = (char)(nbits >> 8);
Raphael Groner 37c148
 	data[i++] = (char)nbits;
Raphael Groner 37c148
-	BN_bn2bin(rsa->n, &(data[i]));
Raphael Groner 37c148
+	RSA_get0_key(rsa, &rsa_n, NULL, NULL);
Raphael Groner 37c148
+	BN_bn2bin(rsa_n, &(data[i]));
Raphael Groner 37c148
 	i += nbytes;
Raphael Groner 37c148
 	data[i++] = (char)(ebits >> 8);
Raphael Groner 37c148
 	data[i++] = (char)ebits;
Raphael Groner 37c148
-	BN_bn2bin(rsa->e, &(data[i]));
Raphael Groner 37c148
+	RSA_get0_key(rsa, NULL, &rsa_e, NULL);
Raphael Groner 37c148
+	BN_bn2bin(rsa_e, &(data[i]));
Raphael Groner 37c148
 	i += ebytes;
Raphael Groner 37c148
 	SHA1(data, len + 3, hash);
Raphael Groner 37c148
 	to_hex(sig, hash, ECRYPTFS_SIG_SIZE);
Raphael Groner 37c148