More FIPS algorithm blocking.
Catch attempted use of non FIPS algorithms with HMAC. Give an assertion error for applications that ignore FIPS digest errors. Make -non-fips-allow work with dgst and HMAC.
This commit is contained in:
14
apps/dgst.c
14
apps/dgst.c
@@ -78,7 +78,7 @@ static HMAC_CTX hmac_ctx;
|
|||||||
|
|
||||||
int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
|
int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
|
||||||
EVP_PKEY *key, unsigned char *sigin, int siglen, const char *title,
|
EVP_PKEY *key, unsigned char *sigin, int siglen, const char *title,
|
||||||
const char *file,BIO *bmd,const char *hmac_key);
|
const char *file,BIO *bmd,const char *hmac_key, int non_fips_allow);
|
||||||
|
|
||||||
int MAIN(int, char **);
|
int MAIN(int, char **);
|
||||||
|
|
||||||
@@ -366,7 +366,7 @@ int MAIN(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
BIO_set_fp(in,stdin,BIO_NOCLOSE);
|
BIO_set_fp(in,stdin,BIO_NOCLOSE);
|
||||||
err=do_fp(out, buf,inp,separator, out_bin, sigkey, sigbuf,
|
err=do_fp(out, buf,inp,separator, out_bin, sigkey, sigbuf,
|
||||||
siglen,"","(stdin)",bmd,hmac_key);
|
siglen,"","(stdin)",bmd,hmac_key, non_fips_allow);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -392,7 +392,7 @@ int MAIN(int argc, char **argv)
|
|||||||
else
|
else
|
||||||
tmp="";
|
tmp="";
|
||||||
r=do_fp(out,buf,inp,separator,out_bin,sigkey,sigbuf,
|
r=do_fp(out,buf,inp,separator,out_bin,sigkey,sigbuf,
|
||||||
siglen,tmp,argv[i],bmd,hmac_key);
|
siglen,tmp,argv[i],bmd,hmac_key,non_fips_allow);
|
||||||
if(r)
|
if(r)
|
||||||
err=r;
|
err=r;
|
||||||
if(tofree)
|
if(tofree)
|
||||||
@@ -419,7 +419,7 @@ end:
|
|||||||
|
|
||||||
int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
|
int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
|
||||||
EVP_PKEY *key, unsigned char *sigin, int siglen, const char *title,
|
EVP_PKEY *key, unsigned char *sigin, int siglen, const char *title,
|
||||||
const char *file,BIO *bmd,const char *hmac_key)
|
const char *file,BIO *bmd,const char *hmac_key, int non_fips_allow)
|
||||||
{
|
{
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
int i;
|
int i;
|
||||||
@@ -430,7 +430,11 @@ int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
|
|||||||
EVP_MD *md;
|
EVP_MD *md;
|
||||||
|
|
||||||
BIO_get_md(bmd,&md);
|
BIO_get_md(bmd,&md);
|
||||||
HMAC_Init(&hmac_ctx,hmac_key,strlen(hmac_key),md);
|
HMAC_CTX_init(&hmac_ctx);
|
||||||
|
if (non_fips_allow)
|
||||||
|
HMAC_CTX_set_flags(&hmac_ctx,
|
||||||
|
EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
|
||||||
|
HMAC_Init_ex(&hmac_ctx,hmac_key,strlen(hmac_key),md, NULL);
|
||||||
BIO_get_md_ctx(bmd,&md_ctx);
|
BIO_get_md_ctx(bmd,&md_ctx);
|
||||||
BIO_set_md_ctx(bmd,&hmac_ctx.md_ctx);
|
BIO_set_md_ctx(bmd,&hmac_ctx.md_ctx);
|
||||||
}
|
}
|
||||||
|
@@ -440,6 +440,9 @@ void OpenSSLDie(const char *file,int line,const char *assertion);
|
|||||||
int FIPS_mode(void);
|
int FIPS_mode(void);
|
||||||
void *FIPS_rand_check(void);
|
void *FIPS_rand_check(void);
|
||||||
|
|
||||||
|
#define FIPS_ERROR_IGNORED(alg) OpenSSLDie(__FILE__, __LINE__, \
|
||||||
|
alg " previous FIPS forbidden algorithm error ignored");
|
||||||
|
|
||||||
#define FIPS_BAD_ABORT(alg) OpenSSLDie(__FILE__, __LINE__, \
|
#define FIPS_BAD_ABORT(alg) OpenSSLDie(__FILE__, __LINE__, \
|
||||||
#alg " Algorithm forbidden in FIPS mode");
|
#alg " Algorithm forbidden in FIPS mode");
|
||||||
|
|
||||||
|
@@ -137,6 +137,39 @@ int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
|
|||||||
return EVP_DigestInit_ex(ctx, type, NULL);
|
return EVP_DigestInit_ex(ctx, type, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef OPENSSL_FIPS
|
||||||
|
|
||||||
|
/* The purpose of these is to trap programs that attempt to use non FIPS
|
||||||
|
* algorithms in FIPS mode and ignore the errors.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int bad_init(EVP_MD_CTX *ctx)
|
||||||
|
{ FIPS_ERROR_IGNORED("Digest init"); return 0;}
|
||||||
|
|
||||||
|
static int bad_update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
|
||||||
|
{ FIPS_ERROR_IGNORED("Digest update"); return 0;}
|
||||||
|
|
||||||
|
static int bad_final(EVP_MD_CTX *ctx,unsigned char *md)
|
||||||
|
{ FIPS_ERROR_IGNORED("Digest Final"); return 0;}
|
||||||
|
|
||||||
|
static const EVP_MD bad_md =
|
||||||
|
{
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
bad_init,
|
||||||
|
bad_update,
|
||||||
|
bad_final,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
{0,0,0,0},
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||||
{
|
{
|
||||||
EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
|
EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
|
||||||
@@ -202,6 +235,7 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
|||||||
&& !(ctx->flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW))
|
&& !(ctx->flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW))
|
||||||
{
|
{
|
||||||
EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_DISABLED_FOR_FIPS);
|
EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_DISABLED_FOR_FIPS);
|
||||||
|
ctx->digest = &bad_md;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -77,6 +77,15 @@ void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
|
|||||||
|
|
||||||
if (key != NULL)
|
if (key != NULL)
|
||||||
{
|
{
|
||||||
|
#ifdef OPENSSL_FIPS
|
||||||
|
if (FIPS_mode() && !(md->flags & EVP_MD_FLAG_FIPS)
|
||||||
|
&& (!(ctx->md_ctx.flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW)
|
||||||
|
|| !(ctx->i_ctx.flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW)
|
||||||
|
|| !(ctx->o_ctx.flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW)))
|
||||||
|
OpenSSLDie(__FILE__,__LINE__,
|
||||||
|
"HMAC: digest not allowed in FIPS mode");
|
||||||
|
#endif
|
||||||
|
|
||||||
reset=1;
|
reset=1;
|
||||||
j=EVP_MD_block_size(md);
|
j=EVP_MD_block_size(md);
|
||||||
OPENSSL_assert(j <= sizeof ctx->key);
|
OPENSSL_assert(j <= sizeof ctx->key);
|
||||||
|
Reference in New Issue
Block a user