0002-package-libest-Add-OpenSSL-3.0-compatibility.patch 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. From ad5ce7ff1cae92c151dc6f350ef943106ddd852f Mon Sep 17 00:00:00 2001
  2. From: Aleksandr Makarov <aleksandr.o.makarov@gmail.com>
  3. Date: Fri, 12 Jul 2024 21:07:36 +0300
  4. Subject: [PATCH] package/libest: Add OpenSSL 3.0 compatibility
  5. The functions `FIPS_mode` and `FIPS_mode_set` are deprecated in OpenSSL 3.0, replaced by
  6. `EVP_default_properties_is_fips_enabled` and `EVP_default_properties_enable_fips` respectively.
  7. This commit introduces wrappers for these new EVP APIs to maintain compatibility with OpenSSL 3.0,
  8. while ensuring continued support for older versions of OpenSSL.
  9. - Implemented `is_fips_enabled` wrapper around `EVP_default_properties_is_fips_enabled`
  10. - Implemented `enable_fips` wrapper around `EVP_default_properties_enable_fips`
  11. - Added conditional compilation to support both new and legacy OpenSSL versions
  12. Upstream: https://github.com/cisco/libest/pull/132
  13. Signed-off-by: Aleksandr Makarov <aleksandr.o.makarov@gmail.com>
  14. ---
  15. example/client-brski/estclient-brski.c | 2 +-
  16. example/client/estclient.c | 2 +-
  17. example/proxy/estproxy.c | 2 +-
  18. example/server/estserver.c | 2 +-
  19. java/jni/client.c | 2 +-
  20. src/est/est_client.c | 12 ++++++------
  21. src/est/est_ossl_util.c | 18 ++++++++++++++++++
  22. src/est/est_ossl_util.h | 2 ++
  23. src/est/est_server.c | 2 +-
  24. test/UT/US1864/us1864.c | 4 ++--
  25. 10 files changed, 34 insertions(+), 14 deletions(-)
  26. diff --git a/example/client-brski/estclient-brski.c b/example/client-brski/estclient-brski.c
  27. index 9e63af5..6e03052 100644
  28. --- a/example/client-brski/estclient-brski.c
  29. +++ b/example/client-brski/estclient-brski.c
  30. @@ -388,7 +388,7 @@ int main (int argc, char **argv)
  31. break;
  32. case 'f':
  33. /* Turn FIPS on if requested and exit if failure */
  34. - set_fips_return = FIPS_mode_set(1);
  35. + set_fips_return = est_enable_fips(1);
  36. if (!set_fips_return) {
  37. printf("\nERROR setting FIPS MODE ON ...\n");
  38. ERR_load_crypto_strings();
  39. diff --git a/example/client/estclient.c b/example/client/estclient.c
  40. index a8a2d6f..75b1272 100644
  41. --- a/example/client/estclient.c
  42. +++ b/example/client/estclient.c
  43. @@ -1280,7 +1280,7 @@ int main (int argc, char **argv)
  44. break;
  45. case 'f':
  46. /* Turn FIPS on if requested and exit if failure */
  47. - set_fips_return = FIPS_mode_set(1);
  48. + set_fips_return = est_enable_fips(1);
  49. if (!set_fips_return) {
  50. printf("\nERROR setting FIPS MODE ON ...\n");
  51. ERR_load_crypto_strings();
  52. diff --git a/example/proxy/estproxy.c b/example/proxy/estproxy.c
  53. index 114bd65..6dbdbda 100644
  54. --- a/example/proxy/estproxy.c
  55. +++ b/example/proxy/estproxy.c
  56. @@ -593,7 +593,7 @@ int main (int argc, char **argv)
  57. /*
  58. * Turn FIPS on if user requested it and exit if failure
  59. */
  60. - set_fips_return = FIPS_mode_set(1);
  61. + set_fips_return = est_enable_fips(1);
  62. if (set_fips_return != 1) {
  63. set_fips_error = ERR_get_error();
  64. printf("\nERROR WHILE SETTING FIPS MODE ON exiting ....\n");
  65. diff --git a/example/server/estserver.c b/example/server/estserver.c
  66. index 3539dc4..90886cf 100644
  67. --- a/example/server/estserver.c
  68. +++ b/example/server/estserver.c
  69. @@ -2285,7 +2285,7 @@ int main (int argc, char **argv)
  70. /* turn FIPS on if user requested it
  71. * and exit if failure.
  72. */
  73. - set_fips_return = FIPS_mode_set(1);
  74. + set_fips_return = est_enable_fips(1);
  75. if (set_fips_return != 1) {
  76. set_fips_error = ERR_get_error();
  77. printf("\nERROR WHILE SETTING FIPS MODE ON exiting ....\n");
  78. diff --git a/java/jni/client.c b/java/jni/client.c
  79. index c5bc28e..f58d5c0 100644
  80. --- a/java/jni/client.c
  81. +++ b/java/jni/client.c
  82. @@ -179,7 +179,7 @@ static int jni_est_client_X509_REQ_sign (X509_REQ *x, EVP_PKEY *pkey, const EVP_
  83. */
  84. JNIEXPORT jint JNICALL Java_com_cisco_c3m_est_ESTClient_enable_1fips(
  85. JNIEnv *env, jclass obj) {
  86. - if (!FIPS_mode() && !FIPS_mode_set(1)) {
  87. + if (!est_is_fips_enabled() && !est_enable_fips(1)) {
  88. ERR_print_errors_fp(stderr);
  89. return -1;
  90. } else {
  91. diff --git a/src/est/est_client.c b/src/est/est_client.c
  92. index 5c25d4f..63069af 100644
  93. --- a/src/est/est_client.c
  94. +++ b/src/est/est_client.c
  95. @@ -3183,7 +3183,7 @@ EST_ERROR est_client_enroll_internal (EST_CTX *ctx, char *cn, int *pkcs7_len, in
  96. * HTTPS digest mode requires the use of MD5. Make sure we're not
  97. * in FIPS mode and can use MD5
  98. */
  99. - if (ctx->auth_mode == AUTH_DIGEST && (FIPS_mode())){
  100. + if (ctx->auth_mode == AUTH_DIGEST && (est_is_fips_enabled())){
  101. EST_LOG_ERR("HTTP digest auth not allowed while in FIPS mode");
  102. rv = EST_ERR_BAD_MODE;
  103. goto err;
  104. @@ -3594,7 +3594,7 @@ EST_ERROR est_client_reenroll (EST_CTX *ctx, X509 *cert, int *pkcs7_len, EVP_PKE
  105. * HTTPS digest mode requires the use of MD5. Make sure we're not
  106. * in FIPS mode and can use MD5
  107. */
  108. - if (ctx->auth_mode == AUTH_DIGEST && (FIPS_mode())){
  109. + if (ctx->auth_mode == AUTH_DIGEST && (est_is_fips_enabled())){
  110. EST_LOG_ERR("HTTP digest auth not allowed while in FIPS mode");
  111. rv = EST_ERR_BAD_MODE;
  112. goto err;
  113. @@ -3680,7 +3680,7 @@ static EST_ERROR est_client_enroll_csr_internal (EST_CTX *ctx, X509_REQ *csr, in
  114. * HTTPS digest mode requires the use of MD5. Make sure we're not
  115. * in FIPS mode and can use MD5
  116. */
  117. - if (ctx->auth_mode == AUTH_DIGEST && (FIPS_mode())){
  118. + if (ctx->auth_mode == AUTH_DIGEST && (est_is_fips_enabled())){
  119. EST_LOG_ERR("HTTP digest auth not allowed while in FIPS mode");
  120. rv = EST_ERR_BAD_MODE;
  121. goto err;
  122. @@ -5872,7 +5872,7 @@ static EST_ERROR est_client_brski_send_get_voucher (EST_CTX *ctx, int *cacert_le
  123. * HTTPS digest mode requires the use of MD5. Make sure we're not
  124. * in FIPS mode and can use MD5
  125. */
  126. - if (ctx->auth_mode == AUTH_DIGEST && (FIPS_mode())){
  127. + if (ctx->auth_mode == AUTH_DIGEST && (est_is_fips_enabled())){
  128. EST_LOG_ERR("HTTP digest auth not allowed while in FIPS mode");
  129. rv = EST_ERR_BAD_MODE;
  130. goto err;
  131. @@ -6366,7 +6366,7 @@ EST_ERROR est_client_brski_send_voucher_status (EST_CTX *ctx, EST_BRSKI_STATUS_V
  132. * HTTPS digest mode requires the use of MD5. Make sure we're not
  133. * in FIPS mode and can use MD5
  134. */
  135. - if (ctx->auth_mode == AUTH_DIGEST && (FIPS_mode())){
  136. + if (ctx->auth_mode == AUTH_DIGEST && (est_is_fips_enabled())){
  137. EST_LOG_ERR("HTTP digest auth not allowed while in FIPS mode");
  138. rv = EST_ERR_BAD_MODE;
  139. goto err;
  140. @@ -6535,7 +6535,7 @@ EST_ERROR est_client_brski_send_enroll_status (EST_CTX *ctx, EST_BRSKI_STATUS_VA
  141. * HTTPS digest mode requires the use of MD5. Make sure we're not
  142. * in FIPS mode and can use MD5
  143. */
  144. - if (ctx->auth_mode == AUTH_DIGEST && (FIPS_mode())){
  145. + if (ctx->auth_mode == AUTH_DIGEST && (est_is_fips_enabled())){
  146. EST_LOG_ERR("HTTP digest auth not allowed while in FIPS mode");
  147. rv = EST_ERR_BAD_MODE;
  148. goto err;
  149. diff --git a/src/est/est_ossl_util.c b/src/est/est_ossl_util.c
  150. index daa54f2..0887daa 100644
  151. --- a/src/est/est_ossl_util.c
  152. +++ b/src/est/est_ossl_util.c
  153. @@ -500,3 +500,21 @@ char *est_find_ser_num_in_subj(X509 *cert)
  154. return(ser_num_str);
  155. }
  156. #endif
  157. +
  158. +int est_is_fips_enabled()
  159. +{
  160. +#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  161. + return EVP_default_properties_is_fips_enabled(NULL);
  162. +#else
  163. + return FIPS_mode();
  164. +#endif
  165. +}
  166. +
  167. +int est_enable_fips(int enable)
  168. +{
  169. +#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  170. + return EVP_default_properties_enable_fips(NULL, enable);
  171. +#else
  172. + return FIPS_mode_set(enable);
  173. +#endif
  174. +}
  175. diff --git a/src/est/est_ossl_util.h b/src/est/est_ossl_util.h
  176. index 68ad290..2389e45 100644
  177. --- a/src/est/est_ossl_util.h
  178. +++ b/src/est/est_ossl_util.h
  179. @@ -44,4 +44,6 @@ LIBEST_TEST_API void ossl_dump_ssl_errors(void);
  180. EST_ERROR ossl_init_cert_store(X509_STORE *store,
  181. unsigned char *raw1, int size1);
  182. +int est_is_fips_enabled();
  183. +int est_enable_fips(int);
  184. #endif
  185. diff --git a/src/est/est_server.c b/src/est/est_server.c
  186. index d047b48..979ae53 100644
  187. --- a/src/est/est_server.c
  188. +++ b/src/est/est_server.c
  189. @@ -3355,7 +3355,7 @@ EST_ERROR est_server_set_auth_mode (EST_CTX *ctx, EST_HTTP_AUTH_MODE amode)
  190. /*
  191. * Since HTTP digest auth uses MD5, make sure we're not in FIPS mode.
  192. */
  193. - if (FIPS_mode()) {
  194. + if (est_is_fips_enabled()) {
  195. EST_LOG_ERR("HTTP digest auth not allowed while in FIPS mode");
  196. return (EST_ERR_BAD_MODE);
  197. }
  198. diff --git a/test/UT/US1864/us1864.c b/test/UT/US1864/us1864.c
  199. index 3e41cd7..1f57494 100644
  200. --- a/test/UT/US1864/us1864.c
  201. +++ b/test/UT/US1864/us1864.c
  202. @@ -218,12 +218,12 @@ static void us1864_test1 (void)
  203. /*
  204. * Make sure we don't allow DIGEST mode when in FIPS mode
  205. */
  206. - if (!FIPS_mode_set(1)) {
  207. + if (!est_enable_fips(1)) {
  208. printf("FIPS mode not supported, skipping test to prevent digest auth when in FIPS mode");
  209. } else {
  210. est_rv = est_server_set_auth_mode(ctx, AUTH_DIGEST);
  211. CU_ASSERT(est_rv == EST_ERR_BAD_MODE);
  212. - FIPS_mode_set(0);
  213. + est_enable_fips(0);
  214. }
  215. X509_free(x);
  216. --
  217. 2.40.1