Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/opensslv3 compat #132

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/client-brski/estclient-brski.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ int main (int argc, char **argv)
break;
case 'f':
/* Turn FIPS on if requested and exit if failure */
set_fips_return = FIPS_mode_set(1);
set_fips_return = est_enable_fips(1);
if (!set_fips_return) {
printf("\nERROR setting FIPS MODE ON ...\n");
ERR_load_crypto_strings();
Expand Down
2 changes: 1 addition & 1 deletion example/client/estclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ int main (int argc, char **argv)
break;
case 'f':
/* Turn FIPS on if requested and exit if failure */
set_fips_return = FIPS_mode_set(1);
set_fips_return = est_enable_fips(1);
if (!set_fips_return) {
printf("\nERROR setting FIPS MODE ON ...\n");
ERR_load_crypto_strings();
Expand Down
2 changes: 1 addition & 1 deletion example/proxy/estproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ int main (int argc, char **argv)
/*
* Turn FIPS on if user requested it and exit if failure
*/
set_fips_return = FIPS_mode_set(1);
set_fips_return = est_enable_fips(1);
if (set_fips_return != 1) {
set_fips_error = ERR_get_error();
printf("\nERROR WHILE SETTING FIPS MODE ON exiting ....\n");
Expand Down
2 changes: 1 addition & 1 deletion example/server/estserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -2285,7 +2285,7 @@ int main (int argc, char **argv)
/* turn FIPS on if user requested it
* and exit if failure.
*/
set_fips_return = FIPS_mode_set(1);
set_fips_return = est_enable_fips(1);
if (set_fips_return != 1) {
set_fips_error = ERR_get_error();
printf("\nERROR WHILE SETTING FIPS MODE ON exiting ....\n");
Expand Down
2 changes: 1 addition & 1 deletion java/jni/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static int jni_est_client_X509_REQ_sign (X509_REQ *x, EVP_PKEY *pkey, const EVP_
*/
JNIEXPORT jint JNICALL Java_com_cisco_c3m_est_ESTClient_enable_1fips(
JNIEnv *env, jclass obj) {
if (!FIPS_mode() && !FIPS_mode_set(1)) {
if (!est_is_fips_enabled() && !est_enable_fips(1)) {
ERR_print_errors_fp(stderr);
return -1;
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/est/est.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
#include <DbgHelp.h>
#endif /* DISABLE_BACKTRACE*/
#endif /* WIN32*/

#include <openssl/err.h>
#include <openssl/ssl.h>
#include <openssl/rand.h>
#ifndef ENABLE_CLIENT_ONLY
static char hex_chpw[] = {0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
0xF7, 0x0D, 0x01, 0x09, 0x07};
Expand Down
13 changes: 7 additions & 6 deletions src/est/est_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <openssl/ssl.h>
#include <openssl/cms.h>
#include <openssl/rand.h>
#include <openssl/crypto.h>
#include "est.h"
#include "est_locl.h"
#include "est_ossl_util.h"
Expand Down Expand Up @@ -3182,7 +3183,7 @@ EST_ERROR est_client_enroll_internal (EST_CTX *ctx, char *cn, int *pkcs7_len, in
* HTTPS digest mode requires the use of MD5. Make sure we're not
* in FIPS mode and can use MD5
*/
if (ctx->auth_mode == AUTH_DIGEST && (FIPS_mode())){
if (ctx->auth_mode == AUTH_DIGEST && (est_is_fips_enabled())){
EST_LOG_ERR("HTTP digest auth not allowed while in FIPS mode");
rv = EST_ERR_BAD_MODE;
goto err;
Expand Down Expand Up @@ -3593,7 +3594,7 @@ EST_ERROR est_client_reenroll (EST_CTX *ctx, X509 *cert, int *pkcs7_len, EVP_PKE
* HTTPS digest mode requires the use of MD5. Make sure we're not
* in FIPS mode and can use MD5
*/
if (ctx->auth_mode == AUTH_DIGEST && (FIPS_mode())){
if (ctx->auth_mode == AUTH_DIGEST && (est_is_fips_enabled())){
EST_LOG_ERR("HTTP digest auth not allowed while in FIPS mode");
rv = EST_ERR_BAD_MODE;
goto err;
Expand Down Expand Up @@ -3679,7 +3680,7 @@ static EST_ERROR est_client_enroll_csr_internal (EST_CTX *ctx, X509_REQ *csr, in
* HTTPS digest mode requires the use of MD5. Make sure we're not
* in FIPS mode and can use MD5
*/
if (ctx->auth_mode == AUTH_DIGEST && (FIPS_mode())){
if (ctx->auth_mode == AUTH_DIGEST && (est_is_fips_enabled())){
EST_LOG_ERR("HTTP digest auth not allowed while in FIPS mode");
rv = EST_ERR_BAD_MODE;
goto err;
Expand Down Expand Up @@ -5871,7 +5872,7 @@ static EST_ERROR est_client_brski_send_get_voucher (EST_CTX *ctx, int *cacert_le
* HTTPS digest mode requires the use of MD5. Make sure we're not
* in FIPS mode and can use MD5
*/
if (ctx->auth_mode == AUTH_DIGEST && (FIPS_mode())){
if (ctx->auth_mode == AUTH_DIGEST && (est_is_fips_enabled())){
EST_LOG_ERR("HTTP digest auth not allowed while in FIPS mode");
rv = EST_ERR_BAD_MODE;
goto err;
Expand Down Expand Up @@ -6365,7 +6366,7 @@ EST_ERROR est_client_brski_send_voucher_status (EST_CTX *ctx, EST_BRSKI_STATUS_V
* HTTPS digest mode requires the use of MD5. Make sure we're not
* in FIPS mode and can use MD5
*/
if (ctx->auth_mode == AUTH_DIGEST && (FIPS_mode())){
if (ctx->auth_mode == AUTH_DIGEST && (est_is_fips_enabled())){
EST_LOG_ERR("HTTP digest auth not allowed while in FIPS mode");
rv = EST_ERR_BAD_MODE;
goto err;
Expand Down Expand Up @@ -6534,7 +6535,7 @@ EST_ERROR est_client_brski_send_enroll_status (EST_CTX *ctx, EST_BRSKI_STATUS_VA
* HTTPS digest mode requires the use of MD5. Make sure we're not
* in FIPS mode and can use MD5
*/
if (ctx->auth_mode == AUTH_DIGEST && (FIPS_mode())){
if (ctx->auth_mode == AUTH_DIGEST && (est_is_fips_enabled())){
EST_LOG_ERR("HTTP digest auth not allowed while in FIPS mode");
rv = EST_ERR_BAD_MODE;
goto err;
Expand Down
18 changes: 18 additions & 0 deletions src/est/est_ossl_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,21 @@ char *est_find_ser_num_in_subj(X509 *cert)
return(ser_num_str);
}
#endif

int est_is_fips_enabled()
{
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
return EVP_default_properties_is_fips_enabled(NULL);
#else
return FIPS_mode();
#endif
}

int est_enable_fips(int enable)
{
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
return EVP_default_properties_enable_fips(NULL, enable);
#else
return FIPS_mode_set(enable);
#endif
}
2 changes: 2 additions & 0 deletions src/est/est_ossl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ LIBEST_TEST_API void ossl_dump_ssl_errors(void);
EST_ERROR ossl_init_cert_store(X509_STORE *store,
unsigned char *raw1, int size1);

int est_is_fips_enabled();
int est_enable_fips(int);
#endif
2 changes: 1 addition & 1 deletion src/est/est_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -3355,7 +3355,7 @@ EST_ERROR est_server_set_auth_mode (EST_CTX *ctx, EST_HTTP_AUTH_MODE amode)
/*
* Since HTTP digest auth uses MD5, make sure we're not in FIPS mode.
*/
if (FIPS_mode()) {
if (est_is_fips_enabled()) {
EST_LOG_ERR("HTTP digest auth not allowed while in FIPS mode");
return (EST_ERR_BAD_MODE);
}
Expand Down
2 changes: 2 additions & 0 deletions src/est/est_server_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <openssl/x509v3.h>
#include <openssl/crypto.h>
#include <openssl/rand.h>
#if defined(_WIN32)
#define _CRT_SECURE_NO_WARNINGS // Disable deprecation warning in VS2005
#else
Expand Down
4 changes: 2 additions & 2 deletions test/UT/US1864/us1864.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ static void us1864_test1 (void)
/*
* Make sure we don't allow DIGEST mode when in FIPS mode
*/
if (!FIPS_mode_set(1)) {
if (!est_enable_fips(1)) {
printf("FIPS mode not supported, skipping test to prevent digest auth when in FIPS mode");
} else {
est_rv = est_server_set_auth_mode(ctx, AUTH_DIGEST);
CU_ASSERT(est_rv == EST_ERR_BAD_MODE);
FIPS_mode_set(0);
est_enable_fips(0);
}

X509_free(x);
Expand Down