|
| 1 | +--- src/ssl.c.orig 2024-02-04 19:32:52 UTC |
| 2 | ++++ src/ssl.c |
| 3 | +@@ -395,30 +395,14 @@ TCN_IMPLEMENT_CALL(void, SSL, randSet)(TCN_STDARGS, js |
| 4 | + |
| 5 | + TCN_IMPLEMENT_CALL(jint, SSL, fipsModeGet)(TCN_STDARGS) |
| 6 | + { |
| 7 | +-#if defined(LIBRESSL_VERSION_NUMBER) |
| 8 | + UNREFERENCED(o); |
| 9 | +- /* LibreSSL doesn't support FIPS */ |
| 10 | +- return 0; |
| 11 | ++#ifdef OPENSSL_FIPS |
| 12 | ++ return FIPS_mode(); |
| 13 | + #else |
| 14 | +- EVP_MD *md; |
| 15 | +- const OSSL_PROVIDER *provider; |
| 16 | +- const char *name; |
| 17 | +- UNREFERENCED(o); |
| 18 | ++ /* FIPS is unavailable */ |
| 19 | ++ tcn_ThrowException(e, "FIPS was not available to tcnative at build time. You will need to re-build tcnative against an OpenSSL with FIPS."); |
| 20 | + |
| 21 | +- // Maps the OpenSSL 3. x onwards behaviour to theOpenSSL 1.x API |
| 22 | +- |
| 23 | +- // Checks that FIPS is the default provider |
| 24 | +- md = EVP_MD_fetch(NULL, "SHA-512", NULL); |
| 25 | +- provider = EVP_MD_get0_provider(md); |
| 26 | +- name = OSSL_PROVIDER_get0_name(provider); |
| 27 | +- // Clean up |
| 28 | +- EVP_MD_free(md); |
| 29 | +- |
| 30 | +- if (strcmp("fips", name)) { |
| 31 | +- return 0; |
| 32 | +- } else { |
| 33 | +- return 1; |
| 34 | +- } |
| 35 | ++ return 0; |
| 36 | + #endif |
| 37 | + } |
| 38 | + |
| 39 | +@@ -427,8 +411,22 @@ TCN_IMPLEMENT_CALL(jint, SSL, fipsModeSet)(TCN_STDARGS |
| 40 | + int r = 0; |
| 41 | + UNREFERENCED(o); |
| 42 | + |
| 43 | +- /* This method should never be called when using Tomcat Native 2.x onwards */ |
| 44 | +- tcn_ThrowException(e, "fipsModeSet is not supported in Tomcat Native 2.x onwards."); |
| 45 | ++#ifdef OPENSSL_FIPS |
| 46 | ++ if(1 != (r = (jint)FIPS_mode_set((int)mode))) { |
| 47 | ++ /* arrange to get a human-readable error message */ |
| 48 | ++ unsigned long err = SSL_ERR_get(); |
| 49 | ++ char msg[256]; |
| 50 | ++ |
| 51 | ++ /* ERR_load_crypto_strings() already called in initialize() */ |
| 52 | ++ |
| 53 | ++ ERR_error_string_n(err, msg, 256); |
| 54 | ++ |
| 55 | ++ tcn_ThrowException(e, msg); |
| 56 | ++ } |
| 57 | ++#else |
| 58 | ++ /* FIPS is unavailable */ |
| 59 | ++ tcn_ThrowException(e, "FIPS was not available to tcnative at build time. You will need to re-build tcnative against an OpenSSL with FIPS."); |
| 60 | ++#endif |
| 61 | + |
| 62 | + return r; |
| 63 | + } |
0 commit comments