0002-openssl110.patch 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. Fix build with OpenSSL 1.1.x
  2. Downloaded from upstream commit
  3. https://code.launchpad.net/~jelle-vdwaa/ecryptfs/ecryptfs/+merge/319746
  4. Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
  5. === modified file 'src/key_mod/ecryptfs_key_mod_openssl.c'
  6. --- a/src/key_mod/ecryptfs_key_mod_openssl.c 2013-10-25 19:45:09 +0000
  7. +++ b/src/key_mod/ecryptfs_key_mod_openssl.c 2017-06-02 18:27:28 +0000
  8. @@ -41,6 +41,7 @@
  9. #include <stdlib.h>
  10. #include <unistd.h>
  11. #include <libgen.h>
  12. +#include <openssl/bn.h>
  13. #include <openssl/pem.h>
  14. #include <openssl/rsa.h>
  15. #include <openssl/err.h>
  16. @@ -55,6 +56,19 @@
  17. char *passphrase;
  18. };
  19. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  20. +static void RSA_get0_key(const RSA *r,
  21. + const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
  22. +{
  23. + if (n != NULL)
  24. + *n = r->n;
  25. + if (e != NULL)
  26. + *e = r->e;
  27. + if (d != NULL)
  28. + *d = r->d;
  29. +}
  30. +#endif
  31. +
  32. static void
  33. ecryptfs_openssl_destroy_openssl_data(struct openssl_data *openssl_data)
  34. {
  35. @@ -142,6 +156,7 @@
  36. {
  37. int len, nbits, ebits, i;
  38. int nbytes, ebytes;
  39. + const BIGNUM *key_n, *key_e;
  40. unsigned char *hash;
  41. unsigned char *data = NULL;
  42. int rc = 0;
  43. @@ -152,11 +167,13 @@
  44. rc = -ENOMEM;
  45. goto out;
  46. }
  47. - nbits = BN_num_bits(key->n);
  48. + RSA_get0_key(key, &key_n, NULL, NULL);
  49. + nbits = BN_num_bits(key_n);
  50. nbytes = nbits / 8;
  51. if (nbits % 8)
  52. nbytes++;
  53. - ebits = BN_num_bits(key->e);
  54. + RSA_get0_key(key, NULL, &key_e, NULL);
  55. + ebits = BN_num_bits(key_e);
  56. ebytes = ebits / 8;
  57. if (ebits % 8)
  58. ebytes++;
  59. @@ -179,11 +196,13 @@
  60. data[i++] = '\02';
  61. data[i++] = (nbits >> 8);
  62. data[i++] = nbits;
  63. - BN_bn2bin(key->n, &(data[i]));
  64. + RSA_get0_key(key, &key_n, NULL, NULL);
  65. + BN_bn2bin(key_n, &(data[i]));
  66. i += nbytes;
  67. data[i++] = (ebits >> 8);
  68. data[i++] = ebits;
  69. - BN_bn2bin(key->e, &(data[i]));
  70. + RSA_get0_key(key, NULL, &key_e, NULL);
  71. + BN_bn2bin(key_e, &(data[i]));
  72. i += ebytes;
  73. SHA1(data, len + 3, hash);
  74. to_hex(sig, (char *)hash, ECRYPTFS_SIG_SIZE);
  75. @@ -278,7 +297,9 @@
  76. BIO *in = NULL;
  77. int rc;
  78. + #if OPENSSL_VERSION_NUMBER < 0x10100000L
  79. CRYPTO_malloc_init();
  80. + #endif
  81. ERR_load_crypto_strings();
  82. OpenSSL_add_all_algorithms();
  83. ENGINE_load_builtin_engines();
  84. === modified file 'src/key_mod/ecryptfs_key_mod_pkcs11_helper.c'
  85. --- a/src/key_mod/ecryptfs_key_mod_pkcs11_helper.c 2013-10-25 19:45:09 +0000
  86. +++ b/src/key_mod/ecryptfs_key_mod_pkcs11_helper.c 2017-06-02 18:27:28 +0000
  87. @@ -41,6 +41,7 @@
  88. #include <errno.h>
  89. #include <stdlib.h>
  90. #include <unistd.h>
  91. +#include <openssl/bn.h>
  92. #include <openssl/err.h>
  93. #include <openssl/pem.h>
  94. #include <openssl/x509.h>
  95. @@ -77,6 +78,19 @@
  96. typedef const unsigned char *__pkcs11_openssl_d2i_t;
  97. #endif
  98. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  99. +static void RSA_get0_key(const RSA *r,
  100. + const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
  101. +{
  102. + if (n != NULL)
  103. + *n = r->n;
  104. + if (e != NULL)
  105. + *e = r->e;
  106. + if (d != NULL)
  107. + *d = r->d;
  108. +}
  109. +#endif
  110. +
  111. /**
  112. * ecryptfs_pkcs11h_deserialize
  113. * @pkcs11h_data: The deserialized version of the key module data;
  114. @@ -282,7 +296,11 @@
  115. goto out;
  116. }
  117. + #if OPENSSL_VERSION_NUMBER < 0x10100000L
  118. if (pubkey->type != EVP_PKEY_RSA) {
  119. + #else
  120. + if (EVP_PKEY_base_id(pubkey) != EVP_PKEY_RSA) {
  121. + #endif
  122. syslog(LOG_ERR, "PKCS#11: Invalid public key algorithm");
  123. rc = -EIO;
  124. goto out;
  125. @@ -318,6 +336,7 @@
  126. int nbytes, ebytes;
  127. char *hash = NULL;
  128. char *data = NULL;
  129. + const BIGNUM *rsa_n, *rsa_e;
  130. int rc;
  131. if ((rc = ecryptfs_pkcs11h_get_public_key(&rsa, blob))) {
  132. @@ -331,11 +350,13 @@
  133. rc = -ENOMEM;
  134. goto out;
  135. }
  136. - nbits = BN_num_bits(rsa->n);
  137. + RSA_get0_key(rsa, &rsa_n, NULL, NULL);
  138. + nbits = BN_num_bits(rsa_n);
  139. nbytes = nbits / 8;
  140. if (nbits % 8)
  141. nbytes++;
  142. - ebits = BN_num_bits(rsa->e);
  143. + RSA_get0_key(rsa, NULL, &rsa_e, NULL);
  144. + ebits = BN_num_bits(rsa_e);
  145. ebytes = ebits / 8;
  146. if (ebits % 8)
  147. ebytes++;
  148. @@ -358,11 +379,13 @@
  149. data[i++] = '\02';
  150. data[i++] = (char)(nbits >> 8);
  151. data[i++] = (char)nbits;
  152. - BN_bn2bin(rsa->n, &(data[i]));
  153. + RSA_get0_key(rsa, &rsa_n, NULL, NULL);
  154. + BN_bn2bin(rsa_n, &(data[i]));
  155. i += nbytes;
  156. data[i++] = (char)(ebits >> 8);
  157. data[i++] = (char)ebits;
  158. - BN_bn2bin(rsa->e, &(data[i]));
  159. + RSA_get0_key(rsa, NULL, &rsa_e, NULL);
  160. + BN_bn2bin(rsa_e, &(data[i]));
  161. i += ebytes;
  162. SHA1(data, len + 3, hash);
  163. to_hex(sig, hash, ECRYPTFS_SIG_SIZE);