You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

239 lines
6.2 KiB

  1. --- a/src/Mayaqua/Encrypt.c
  2. +++ b/src/Mayaqua/Encrypt.c
  3. @@ -120,6 +120,7 @@
  4. #include <openssl/rand.h>
  5. #include <openssl/engine.h>
  6. #include <openssl/bio.h>
  7. +#include <openssl/bn.h>
  8. #include <openssl/x509.h>
  9. #include <openssl/pkcs7.h>
  10. #include <openssl/pkcs12.h>
  11. @@ -128,6 +129,7 @@
  12. #include <openssl/md4.h>
  13. #include <openssl/hmac.h>
  14. #include <openssl/sha.h>
  15. +#include <openssl/rsa.h>
  16. #include <openssl/des.h>
  17. #include <openssl/aes.h>
  18. #include <openssl/dh.h>
  19. @@ -627,7 +629,7 @@ UINT CipherProcess(CIPHER *c, void *iv,
  20. return 0;
  21. }
  22. - if (EVP_CipherFinal(c->Ctx, ((UCHAR *)dest) + (UINT)r, &r2) == 0)
  23. + if (EVP_CipherFinal_ex(c->Ctx, ((UCHAR *)dest) + (UINT)r, &r2) == 0)
  24. {
  25. return 0;
  26. }
  27. @@ -926,6 +928,7 @@ BUF *BigNumToBuf(const BIGNUM *bn)
  28. // Initialization of the lock of OpenSSL
  29. void OpenSSL_InitLock()
  30. {
  31. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  32. UINT i;
  33. // Initialization of the lock object
  34. @@ -939,11 +942,13 @@ void OpenSSL_InitLock()
  35. // Setting the lock function
  36. CRYPTO_set_locking_callback(OpenSSL_Lock);
  37. CRYPTO_set_id_callback(OpenSSL_Id);
  38. +#endif
  39. }
  40. // Release of the lock of OpenSSL
  41. void OpenSSL_FreeLock()
  42. {
  43. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  44. UINT i;
  45. for (i = 0;i < ssl_lock_num;i++)
  46. @@ -955,11 +960,13 @@ void OpenSSL_FreeLock()
  47. CRYPTO_set_locking_callback(NULL);
  48. CRYPTO_set_id_callback(NULL);
  49. +#endif
  50. }
  51. // Lock function for OpenSSL
  52. void OpenSSL_Lock(int mode, int n, const char *file, int line)
  53. {
  54. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  55. LOCK *lock = ssl_lock_obj[n];
  56. if (mode & CRYPTO_LOCK)
  57. @@ -972,12 +979,15 @@ void OpenSSL_Lock(int mode, int n, const
  58. // Unlock
  59. Unlock(lock);
  60. }
  61. +#endif
  62. }
  63. // Return the thread ID
  64. unsigned long OpenSSL_Id(void)
  65. {
  66. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  67. return (unsigned long)ThreadId();
  68. +#endif
  69. }
  70. // Get the display name of the certificate
  71. @@ -1901,8 +1911,8 @@ X509 *NewX509(K *pub, K *priv, X *ca, NA
  72. X509_set_version(x509, 2L);
  73. // Set the Expiration
  74. - t1 = X509_get_notBefore(x509);
  75. - t2 = X509_get_notAfter(x509);
  76. + t1 = X509_getm_notBefore(x509);
  77. + t2 = X509_getm_notAfter(x509);
  78. if (!UINT64ToAsn1Time(t1, notBefore))
  79. {
  80. FreeX509(x509);
  81. @@ -2043,8 +2053,8 @@ X509 *NewRootX509(K *pub, K *priv, NAME
  82. X509_set_version(x509, 2L);
  83. // Set the Expiration
  84. - t1 = X509_get_notBefore(x509);
  85. - t2 = X509_get_notAfter(x509);
  86. + t1 = X509_getm_notBefore(x509);
  87. + t2 = X509_getm_notAfter(x509);
  88. if (!UINT64ToAsn1Time(t1, notBefore))
  89. {
  90. FreeX509(x509);
  91. @@ -2698,6 +2708,43 @@ bool RsaCheckEx()
  92. return false;
  93. }
  94. +
  95. +// RSA key generation
  96. +static RSA *RsaGenKey(UINT bit, BN_ULONG e)
  97. +{
  98. + RSA *rsa = NULL;
  99. + char errbuf[MAX_SIZE];
  100. + BIGNUM *bne = NULL;
  101. +
  102. + if ((bne = BN_new()) == NULL)
  103. + {
  104. + Debug("BN_new: err=%s\n", ERR_error_string(ERR_get_error(), errbuf));
  105. + return NULL;
  106. + }
  107. + if (BN_set_word(bne, e) == 0)
  108. + {
  109. + Debug("BN_set_word: err=%s\n", ERR_error_string(ERR_get_error(), errbuf));
  110. + goto fail;
  111. + }
  112. + if ((rsa = RSA_new()) == NULL)
  113. + {
  114. + Debug("RSA_new: err=%s\n", ERR_error_string(ERR_get_error(), errbuf));
  115. + goto fail;
  116. + }
  117. + if (RSA_generate_key_ex(rsa, bit, bne, NULL) == 0)
  118. + {
  119. + Debug("RSA_generate_key_ex: err=%s\n", ERR_error_string(ERR_get_error(), errbuf));
  120. + goto fail;
  121. + }
  122. + BN_free(bne);
  123. + return rsa;
  124. +
  125. +fail:
  126. + RSA_free(rsa);
  127. + BN_free(bne);
  128. + return NULL;
  129. +}
  130. +
  131. bool RsaCheck()
  132. {
  133. RSA *rsa;
  134. @@ -2711,12 +2758,11 @@ bool RsaCheck()
  135. // Key generation
  136. Lock(openssl_lock);
  137. {
  138. - rsa = RSA_generate_key(bit, RSA_F4, NULL, NULL);
  139. + rsa = RsaGenKey(bit, RSA_F4);
  140. }
  141. Unlock(openssl_lock);
  142. if (rsa == NULL)
  143. {
  144. - Debug("RSA_generate_key: err=%s\n", ERR_error_string(ERR_get_error(), errbuf));
  145. return false;
  146. }
  147. @@ -2781,12 +2827,11 @@ bool RsaGen(K **priv, K **pub, UINT bit)
  148. // Key generation
  149. Lock(openssl_lock);
  150. {
  151. - rsa = RSA_generate_key(bit, RSA_F4, NULL, NULL);
  152. + rsa = RsaGenKey(bit, RSA_F4);
  153. }
  154. Unlock(openssl_lock);
  155. if (rsa == NULL)
  156. {
  157. - Debug("RSA_generate_key: err=%s\n", ERR_error_string(ERR_get_error(), errbuf));
  158. return false;
  159. }
  160. @@ -3896,7 +3941,7 @@ X *X509ToX(X509 *x509)
  161. {
  162. if (OBJ_obj2nid(ad->method) == NID_ad_ca_issuers && ad->location->type == GEN_URI)
  163. {
  164. - char *uri = (char *)ASN1_STRING_data(ad->location->d.uniformResourceIdentifier);
  165. + char *uri = (char *)ASN1_STRING_get0_data(ad->location->d.uniformResourceIdentifier);
  166. if (IsEmptyStr(uri) == false)
  167. {
  168. @@ -4109,7 +4154,9 @@ void Rand(void *buf, UINT size)
  169. // Delete a thread-specific information that OpenSSL has holded
  170. void FreeOpenSSLThreadState()
  171. {
  172. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  173. ERR_remove_state(0);
  174. +#endif
  175. }
  176. // Release the Crypt library
  177. @@ -4131,12 +4178,14 @@ void InitCryptLibrary()
  178. CheckIfIntelAesNiSupportedInit();
  179. // RAND_Init_For_SoftEther()
  180. openssl_lock = NewLock();
  181. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  182. SSL_library_init();
  183. //OpenSSL_add_all_algorithms();
  184. OpenSSL_add_all_ciphers();
  185. OpenSSL_add_all_digests();
  186. ERR_load_crypto_strings();
  187. SSL_load_error_strings();
  188. +#endif
  189. ssl_clientcert_index = SSL_get_ex_new_index(0, "struct SslClientCertInfo *", NULL, NULL, NULL);
  190. --- a/src/Mayaqua/Encrypt.h
  191. +++ b/src/Mayaqua/Encrypt.h
  192. @@ -105,7 +105,7 @@
  193. #ifndef ENCRYPT_H
  194. #define ENCRYPT_H
  195. -#if OPENSSL_VERSION_NUMBER >= 0x10100000L
  196. +#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(OPENSSL_NO_CHACHA) && !defined(LIBRESSL_VERSION_NUMBER)
  197. #define USE_OPENSSL_AEAD_CHACHA20POLY1305
  198. #endif
  199. --- a/src/Mayaqua/Network.c
  200. +++ b/src/Mayaqua/Network.c
  201. @@ -18172,7 +18172,7 @@ struct ssl_ctx_st *NewSSLCtx(bool server
  202. SSL_CTX_set_ecdh_auto(ctx, 1);
  203. #endif // SSL_CTX_set_ecdh_auto
  204. -#if OPENSSL_VERSION_NUMBER >= 0x1010100fL
  205. +#if OPENSSL_VERSION_NUMBER >= 0x1010100fL && !defined(LIBRESSL_VERSION_NUMBER)
  206. // For compatibility with VPN 3.0 or older
  207. SSL_CTX_set_security_level(ctx, 0);
  208. #endif
  209. --- a/src/Mayaqua/Secure.c
  210. +++ b/src/Mayaqua/Secure.c
  211. @@ -127,6 +127,7 @@
  212. #include <openssl/pkcs7.h>
  213. #include <openssl/pkcs12.h>
  214. #include <openssl/rc4.h>
  215. +#include <openssl/rsa.h>
  216. #include <openssl/md5.h>
  217. #include <openssl/sha.h>
  218. #include <Mayaqua/Mayaqua.h>