interim commit for supporting multiple HMAC digest types (# 45)
This commit is contained in:
+8
-2
@@ -46,14 +46,17 @@ enum {
|
||||
RC_FILE_PATH,
|
||||
RESOLVE_URL,
|
||||
USE_HMAC,
|
||||
SPA_ICMP_TYPE,
|
||||
SPA_ICMP_CODE,
|
||||
KEY_LEN,
|
||||
HMAC_DIGEST_TYPE,
|
||||
HMAC_KEY_LEN,
|
||||
/* Put GPG-related items below the following line */
|
||||
GPG_ENCRYPTION = 0x200,
|
||||
GPG_RECIP_KEY,
|
||||
GPG_SIGNER_KEY,
|
||||
GPG_HOME_DIR,
|
||||
GPG_AGENT,
|
||||
SPA_ICMP_TYPE,
|
||||
SPA_ICMP_CODE,
|
||||
NOOP /* Just to be a marker for the end */
|
||||
};
|
||||
|
||||
@@ -87,6 +90,9 @@ static struct option cmd_opts[] =
|
||||
{"http-proxy", 1, NULL, 'H'},
|
||||
{"key-gen", 0, NULL, 'k'},
|
||||
{"key-gen-file", 1, NULL, 'K'},
|
||||
{"key-len", 1, NULL, KEY_LEN},
|
||||
{"hmac-key-len", 1, NULL, HMAC_KEY_LEN},
|
||||
{"hmac-digest-type", 1, NULL, HMAC_DIGEST_TYPE},
|
||||
{"icmp-type", 1, NULL, SPA_ICMP_TYPE },
|
||||
{"icmp-code", 1, NULL, SPA_ICMP_CODE },
|
||||
{"last-cmd", 0, NULL, 'l'},
|
||||
|
||||
+55
-20
@@ -36,25 +36,6 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
/* Convert a digest_type string to its integer value.
|
||||
*/
|
||||
static short
|
||||
digest_strtoint(const char *dt_str)
|
||||
{
|
||||
if(strcasecmp(dt_str, "md5") == 0)
|
||||
return(FKO_DIGEST_MD5);
|
||||
else if(strcasecmp(dt_str, "sha1") == 0)
|
||||
return(FKO_DIGEST_SHA1);
|
||||
else if(strcasecmp(dt_str, "sha256") == 0)
|
||||
return(FKO_DIGEST_SHA256);
|
||||
else if(strcasecmp(dt_str, "sha384") == 0)
|
||||
return(FKO_DIGEST_SHA384);
|
||||
else if(strcasecmp(dt_str, "sha512") == 0)
|
||||
return(FKO_DIGEST_SHA512);
|
||||
else
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* Convert a protocol string to its integer value.
|
||||
*/
|
||||
static int
|
||||
@@ -394,6 +375,22 @@ parse_rc_param(fko_cli_options_t *options, const char *var, char * val)
|
||||
strlcpy(options->key_base64, val, MAX_KEY_LEN);
|
||||
options->have_base64_key = 1;
|
||||
}
|
||||
/* HMAC digest type */
|
||||
else if(CONF_VAR_IS(var, "HMAC_DIGEST_TYPE"))
|
||||
{
|
||||
tmpint = hmac_digest_strtoint(val);
|
||||
if(tmpint < 0)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"HMAC_DIGEST_TYPE argument '%s' must be one of {md5,sha1,sha256,sha384,sha512}\n",
|
||||
val);
|
||||
return(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
options->hmac_type = tmpint;
|
||||
}
|
||||
}
|
||||
/* HMAC key */
|
||||
else if(CONF_VAR_IS(var, "HMAC_KEY_BASE64"))
|
||||
{
|
||||
@@ -730,8 +727,13 @@ set_defaults(fko_cli_options_t *options)
|
||||
options->spa_dst_port = FKO_DEFAULT_PORT;
|
||||
options->fw_timeout = -1;
|
||||
|
||||
options->key_len = FKO_DEFAULT_KEY_LEN;
|
||||
options->hmac_key_len = FKO_DEFAULT_HMAC_KEY_LEN;
|
||||
options->hmac_type = FKO_DEFAULT_HMAC_MODE;
|
||||
|
||||
options->spa_icmp_type = ICMP_ECHOREPLY; /* only used in '-P icmp' mode */
|
||||
options->spa_icmp_code = 0; /* only used in '-P icmp' mode */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -840,6 +842,35 @@ config_init(fko_cli_options_t *options, int argc, char **argv)
|
||||
options->key_gen = 1;
|
||||
strlcpy(options->key_gen_file, optarg, MAX_PATH_LEN);
|
||||
break;
|
||||
case KEY_LEN:
|
||||
options->key_len = strtol_wrapper(optarg, 1,
|
||||
MAX_KEY_LEN, NO_EXIT_UPON_ERR, &is_err);
|
||||
if(is_err != FKO_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "Invalid key length '%s', must be in [%d-%d]\n",
|
||||
optarg, 1, MAX_KEY_LEN);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case HMAC_DIGEST_TYPE:
|
||||
if((options->hmac_type = hmac_digest_strtoint(optarg)) < 0)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"* Invalid hmac digest type: %s, use {md5,sha1,sha256,sha384,sha512}\n",
|
||||
optarg);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case HMAC_KEY_LEN:
|
||||
options->hmac_key_len = strtol_wrapper(optarg, 1,
|
||||
MAX_KEY_LEN, NO_EXIT_UPON_ERR, &is_err);
|
||||
if(is_err != FKO_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "Invalid hmac key length '%s', must be in [%d-%d]\n",
|
||||
optarg, 1, MAX_KEY_LEN);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case SPA_ICMP_TYPE:
|
||||
options->spa_icmp_type = strtol_wrapper(optarg, 0,
|
||||
MAX_ICMP_TYPE, NO_EXIT_UPON_ERR, &is_err);
|
||||
@@ -1066,9 +1097,13 @@ usage(void)
|
||||
" -v, --verbose Set verbose mode.\n"
|
||||
" -V, --version Print version number.\n"
|
||||
" -m, --digest-type Specify the message digest algorithm to use.\n"
|
||||
" (md5, sha1, or sha256 (default)).\n"
|
||||
" (md5, sha1, sha256, sha384, or sha512). The\n"
|
||||
" default is sha256.\n"
|
||||
" -f, --fw-timeout Specify SPA server firewall timeout from the\n"
|
||||
" client side.\n"
|
||||
" --hmac-digest-type Set the HMAC digest algorithm (default is\n"
|
||||
" sha256). Options are md5, sha1, sha256,\n"
|
||||
" sha384, or sha512.\n"
|
||||
" --icmp-type Set the ICMP type (used with '-P icmp')\n"
|
||||
" --icmp-code Set the ICMP code (used with '-P icmp')\n"
|
||||
" --gpg-encryption Use GPG encryption (default is Rijndael).\n"
|
||||
|
||||
+13
-5
@@ -66,7 +66,7 @@ main(int argc, char **argv)
|
||||
fko_ctx_t ctx = NULL;
|
||||
fko_ctx_t ctx2 = NULL;
|
||||
int res;
|
||||
char *spa_data, *version;
|
||||
char *spa_data=NULL, *version=NULL;
|
||||
char access_buf[MAX_LINE_LEN] = {0};
|
||||
char key[MAX_KEY_LEN+1] = {0};
|
||||
char hmac_key[MAX_KEY_LEN+1] = {0};
|
||||
@@ -75,6 +75,9 @@ main(int argc, char **argv)
|
||||
|
||||
fko_cli_options_t options;
|
||||
|
||||
memset(key, 0x00, MAX_KEY_LEN+1);
|
||||
memset(hmac_key, 0x00, MAX_KEY_LEN+1);
|
||||
memset(access_buf, 0x00, MAX_LINE_LEN);
|
||||
memset(hmac_key, 0x00, MAX_KEY_LEN);
|
||||
|
||||
/* Handle command line
|
||||
@@ -90,7 +93,9 @@ main(int argc, char **argv)
|
||||
*/
|
||||
if(options.key_gen)
|
||||
{
|
||||
fko_key_gen(options.key_base64, options.hmac_key_base64);
|
||||
fko_key_gen(options.key_base64, options.key_len,
|
||||
options.hmac_key_base64, options.hmac_key_len,
|
||||
options.hmac_type);
|
||||
|
||||
if(options.key_gen_file != NULL && options.key_gen_file[0] != '\0')
|
||||
{
|
||||
@@ -965,10 +970,10 @@ get_keys(fko_ctx_t ctx, fko_cli_options_t *options,
|
||||
|
||||
if (use_hmac)
|
||||
{
|
||||
res = fko_set_hmac_mode(ctx, FKO_HMAC_SHA256);
|
||||
res = fko_set_hmac_type(ctx, FKO_HMAC_SHA256);
|
||||
if(res != FKO_SUCCESS)
|
||||
{
|
||||
errmsg("fko_set_hmac_mode", res);
|
||||
errmsg("fko_set_hmac_type", res);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@@ -1013,6 +1018,7 @@ display_ctx(fko_ctx_t ctx)
|
||||
time_t timestamp = 0;
|
||||
short msg_type = -1;
|
||||
short digest_type = -1;
|
||||
short hmac_type = -1;
|
||||
int encryption_mode = -1;
|
||||
int client_timeout = -1;
|
||||
|
||||
@@ -1028,6 +1034,7 @@ display_ctx(fko_ctx_t ctx)
|
||||
fko_get_spa_server_auth(ctx, &server_auth);
|
||||
fko_get_spa_client_timeout(ctx, &client_timeout);
|
||||
fko_get_spa_digest_type(ctx, &digest_type);
|
||||
fko_get_spa_hmac_type(ctx, &hmac_type);
|
||||
fko_get_spa_encryption_mode(ctx, &encryption_mode);
|
||||
fko_get_encoded_data(ctx, &enc_data);
|
||||
fko_get_hmac_data(ctx, &hmac_data);
|
||||
@@ -1045,10 +1052,11 @@ display_ctx(fko_ctx_t ctx)
|
||||
printf(" Server Auth: %s\n", server_auth == NULL ? "<NULL>" : server_auth);
|
||||
printf(" Client Timeout: %u\n", client_timeout);
|
||||
printf(" Digest Type: %d\n", digest_type);
|
||||
printf(" HMAC Type: %d\n", hmac_type);
|
||||
printf("Encryption Mode: %d\n", encryption_mode);
|
||||
printf("\n Encoded Data: %s\n", enc_data == NULL ? "<NULL>" : enc_data);
|
||||
printf("SPA Data Digest: %s\n", spa_digest == NULL ? "<NULL>" : spa_digest);
|
||||
printf(" HMAC-SHA256: %s\n", hmac_data == NULL ? "<NULL>" : hmac_data);
|
||||
printf(" HMAC: %s\n", hmac_data == NULL ? "<NULL>" : hmac_data);
|
||||
|
||||
if (enc_data != NULL && spa_digest != NULL)
|
||||
printf(" Plaintext: %s:%s\n", enc_data, spa_digest);
|
||||
|
||||
@@ -102,13 +102,16 @@ typedef struct fko_cli_options
|
||||
/* Encryption keys read from a .fwknoprc stanza
|
||||
*/
|
||||
char key[MAX_KEY_LEN+1];
|
||||
char key_base64[MAX_KEY_LEN+1];
|
||||
char key_base64[2*MAX_KEY_LEN+1];
|
||||
int key_len;
|
||||
char hmac_key[MAX_KEY_LEN+1];
|
||||
char hmac_key_base64[MAX_KEY_LEN+1];
|
||||
char hmac_key_base64[2*MAX_KEY_LEN+1];
|
||||
int hmac_key_len;
|
||||
int have_key;
|
||||
int have_base64_key;
|
||||
int have_hmac_key;
|
||||
int have_hmac_base64_key;
|
||||
int hmac_type;
|
||||
|
||||
/* NAT access
|
||||
*/
|
||||
|
||||
@@ -27,7 +27,7 @@ my $min_len = 0;
|
||||
my $lib_dir = '../../lib/.libs';
|
||||
my $fwknop_client_path = '../../client/.libs/fwknop';
|
||||
my $enc_mode = 'cbc';
|
||||
my $hmac_mode = 0;
|
||||
my $hmac_type = 0;
|
||||
my $hmac_key_file = '../../test/conf/fwknoprc_default_hmac_base64_key';
|
||||
my $enable_fwknop_client_gpg = 0;
|
||||
my $gpg_recipient = '361BBAD4';
|
||||
@@ -67,7 +67,7 @@ die "[*] See '$0 -h' for usage information" unless (GetOptions(
|
||||
'gpg-recip=s' => \$gpg_recipient,
|
||||
'gpg-signer=s' => \$gpg_signer,
|
||||
'gpg-home=s' => \$gpg_home_dir,
|
||||
'hmac-mode' => \$hmac_mode,
|
||||
'hmac-mode' => \$hmac_type,
|
||||
'lib-dir=s' => \$lib_dir,
|
||||
'Client-path=s' => \$fwknop_client_path,
|
||||
'use-openssl' => \$use_openssl,
|
||||
@@ -245,7 +245,7 @@ sub run_fwknop_client() {
|
||||
my $cmd = "LD_LIBRARY_PATH=$lib_dir $fwknop_client_path -A tcp/22 " .
|
||||
"-a 127.0.0.2 -D 127.0.0.1 -B $file_to_measure -b -v --test";
|
||||
|
||||
if ($hmac_mode) {
|
||||
if ($hmac_type) {
|
||||
$cmd .= " --rc-file $hmac_key_file";
|
||||
} else {
|
||||
$cmd .= " --get-key $spa_key_file";
|
||||
|
||||
@@ -92,7 +92,7 @@ typedef enum {
|
||||
FKO_HMAC_SHA384,
|
||||
FKO_HMAC_SHA512,
|
||||
FKO_LAST_HMAC_MODE /* Always leave this as the last one */
|
||||
} fko_hmac_mode_t;
|
||||
} fko_hmac_type_t;
|
||||
|
||||
/* Supported encryption types...
|
||||
*/
|
||||
@@ -186,10 +186,13 @@ typedef enum {
|
||||
|
||||
/* General Defaults
|
||||
*/
|
||||
#define FKO_DEFAULT_MSG_TYPE FKO_ACCESS_MSG
|
||||
#define FKO_DEFAULT_DIGEST FKO_DIGEST_SHA256
|
||||
#define FKO_DEFAULT_ENCRYPTION FKO_ENCRYPTION_RIJNDAEL
|
||||
#define FKO_DEFAULT_ENC_MODE FKO_ENC_MODE_CBC
|
||||
#define FKO_DEFAULT_MSG_TYPE FKO_ACCESS_MSG
|
||||
#define FKO_DEFAULT_DIGEST FKO_DIGEST_SHA256
|
||||
#define FKO_DEFAULT_ENCRYPTION FKO_ENCRYPTION_RIJNDAEL
|
||||
#define FKO_DEFAULT_ENC_MODE FKO_ENC_MODE_CBC
|
||||
#define FKO_DEFAULT_KEY_LEN 0
|
||||
#define FKO_DEFAULT_HMAC_KEY_LEN 0
|
||||
#define FKO_DEFAULT_HMAC_MODE FKO_HMAC_SHA256
|
||||
|
||||
/* Define the consistent prefixes or salt on some encryption schemes.
|
||||
*/
|
||||
@@ -257,13 +260,15 @@ DLL_API int fko_set_raw_spa_digest(fko_ctx_t ctx);
|
||||
DLL_API int fko_set_spa_encryption_type(fko_ctx_t ctx, const short encrypt_type);
|
||||
DLL_API int fko_set_spa_encryption_mode(fko_ctx_t ctx, const int encrypt_mode);
|
||||
DLL_API int fko_set_spa_data(fko_ctx_t ctx, const char * const enc_msg);
|
||||
DLL_API int fko_set_hmac_mode(fko_ctx_t ctx, const short hmac_mode);
|
||||
DLL_API int fko_set_hmac_type(fko_ctx_t ctx, const short hmac_type);
|
||||
|
||||
/* Data processing and misc utility functions
|
||||
*/
|
||||
DLL_API const char* fko_errstr(const int err_code);
|
||||
DLL_API int fko_encryption_type(const char * const enc_data);
|
||||
DLL_API int fko_key_gen(char * const key_base64, char * const hmac_key_base64);
|
||||
DLL_API int fko_key_gen(char * const key_base64, const int key_len,
|
||||
char * const hmac_key_base64, const int hmac_ken_len,
|
||||
const int hmac_type);
|
||||
DLL_API int fko_base64_encode(unsigned char * const in, char * const out, int in_len);
|
||||
DLL_API int fko_base64_decode(const char * const in, unsigned char *out);
|
||||
|
||||
@@ -294,6 +299,7 @@ DLL_API int fko_get_spa_server_auth(fko_ctx_t ctx, char **server_auth);
|
||||
DLL_API int fko_get_spa_client_timeout(fko_ctx_t ctx, int *client_timeout);
|
||||
DLL_API int fko_get_spa_digest_type(fko_ctx_t ctx, short *spa_digest_type);
|
||||
DLL_API int fko_get_raw_spa_digest_type(fko_ctx_t ctx, short *raw_spa_digest_type);
|
||||
DLL_API int fko_get_spa_hmac_type(fko_ctx_t ctx, short *spa_hmac_type);
|
||||
DLL_API int fko_get_spa_digest(fko_ctx_t ctx, char **spa_digest);
|
||||
DLL_API int fko_get_raw_spa_digest(fko_ctx_t ctx, char **raw_spa_digest);
|
||||
DLL_API int fko_get_spa_encryption_type(fko_ctx_t ctx, short *spa_enc_type);
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ struct fko_context {
|
||||
short digest_type;
|
||||
short encryption_type;
|
||||
int encryption_mode;
|
||||
short hmac_mode;
|
||||
short hmac_type;
|
||||
|
||||
/* Computed or predefined data */
|
||||
char *version;
|
||||
|
||||
+34
-6
@@ -352,16 +352,44 @@ fko_destroy(fko_ctx_t ctx)
|
||||
* encode them
|
||||
*/
|
||||
int
|
||||
fko_key_gen(char * const key_base64, char * const hmac_key_base64)
|
||||
fko_key_gen(char * const key_base64, const int key_len,
|
||||
char * const hmac_key_base64, const int hmac_key_len,
|
||||
const int hmac_type)
|
||||
{
|
||||
unsigned char key[RIJNDAEL_MAX_KEYSIZE];
|
||||
unsigned char hmac_key[SHA256_BLOCK_LEN];
|
||||
int klen = 0;
|
||||
int hmac_klen = 0;
|
||||
|
||||
get_random_data(key, RIJNDAEL_MAX_KEYSIZE);
|
||||
get_random_data(hmac_key, SHA256_BLOCK_LEN);
|
||||
if(key_len == FKO_DEFAULT_KEY_LEN)
|
||||
klen = RIJNDAEL_MAX_KEYSIZE;
|
||||
|
||||
b64_encode(key, key_base64, RIJNDAEL_MAX_KEYSIZE);
|
||||
b64_encode(hmac_key, hmac_key_base64, SHA256_BLOCK_LEN);
|
||||
if(hmac_key_len == FKO_DEFAULT_KEY_LEN)
|
||||
{
|
||||
if(hmac_type == FKO_DEFAULT_HMAC_MODE
|
||||
|| hmac_type == FKO_HMAC_SHA256)
|
||||
hmac_klen = SHA256_BLOCK_LEN;
|
||||
else if(hmac_type == FKO_HMAC_MD5)
|
||||
hmac_klen = MD5_DIGEST_LEN;
|
||||
else if(hmac_type == FKO_HMAC_SHA1)
|
||||
hmac_klen = SHA1_DIGEST_LEN;
|
||||
else if(hmac_type == FKO_HMAC_SHA384)
|
||||
hmac_klen = SHA384_BLOCK_LEN;
|
||||
else if(hmac_type == FKO_HMAC_SHA512)
|
||||
hmac_klen = SHA512_BLOCK_LEN;
|
||||
}
|
||||
|
||||
if((klen < 1) || (klen > RIJNDAEL_MAX_KEYSIZE))
|
||||
return(FKO_ERROR_INVALID_DATA);
|
||||
|
||||
if((hmac_klen < 1) || (hmac_klen > SHA512_BLOCK_LEN))
|
||||
return(FKO_ERROR_INVALID_DATA);
|
||||
|
||||
get_random_data(key, klen);
|
||||
get_random_data(hmac_key, hmac_klen);
|
||||
|
||||
b64_encode(key, key_base64, klen);
|
||||
b64_encode(hmac_key, hmac_key_base64, hmac_klen);
|
||||
|
||||
return(FKO_SUCCESS);
|
||||
}
|
||||
@@ -417,7 +445,7 @@ fko_spa_data_final(fko_ctx_t ctx,
|
||||
/* Now calculate hmac if so configured
|
||||
*/
|
||||
if (res == FKO_SUCCESS &&
|
||||
ctx->hmac_mode != FKO_HMAC_UNKNOWN && hmac_key != NULL)
|
||||
ctx->hmac_type != FKO_HMAC_UNKNOWN && hmac_key != NULL)
|
||||
{
|
||||
res = fko_calculate_hmac(ctx, hmac_key, hmac_key_len);
|
||||
|
||||
|
||||
+20
-5
@@ -86,7 +86,7 @@ int fko_verify_hmac(fko_ctx_t ctx,
|
||||
/* Calculate the HMAC from the encrypted data and then
|
||||
* compare
|
||||
*/
|
||||
res = fko_set_hmac_mode(ctx, FKO_HMAC_SHA256);
|
||||
res = fko_set_hmac_type(ctx, FKO_HMAC_SHA256);
|
||||
if(res == FKO_SUCCESS)
|
||||
{
|
||||
res = fko_calculate_hmac(ctx, hmac_key, hmac_key_len);
|
||||
@@ -123,23 +123,38 @@ fko_get_hmac_data(fko_ctx_t ctx, char **hmac_data)
|
||||
/* Set the HMAC type
|
||||
*/
|
||||
int
|
||||
fko_set_hmac_mode(fko_ctx_t ctx, const short hmac_mode)
|
||||
fko_set_hmac_type(fko_ctx_t ctx, const short hmac_type)
|
||||
{
|
||||
/* Must be initialized
|
||||
*/
|
||||
if(!CTX_INITIALIZED(ctx))
|
||||
return(FKO_ERROR_CTX_NOT_INITIALIZED);
|
||||
|
||||
if(hmac_mode < 0 || hmac_mode >= FKO_LAST_HMAC_MODE)
|
||||
if(hmac_type < 0 || hmac_type >= FKO_LAST_HMAC_MODE)
|
||||
return(FKO_ERROR_INVALID_DATA);
|
||||
|
||||
ctx->hmac_mode = hmac_mode;
|
||||
ctx->hmac_type = hmac_type;
|
||||
|
||||
ctx->state |= FKO_HMAC_MODE_MODIFIED;
|
||||
|
||||
return(FKO_SUCCESS);
|
||||
}
|
||||
|
||||
/* Return the fko HMAC type
|
||||
*/
|
||||
int
|
||||
fko_get_spa_hmac_type(fko_ctx_t ctx, short *hmac_type)
|
||||
{
|
||||
/* Must be initialized
|
||||
*/
|
||||
if(!CTX_INITIALIZED(ctx))
|
||||
return(FKO_ERROR_CTX_NOT_INITIALIZED);
|
||||
|
||||
*hmac_type = ctx->hmac_type;
|
||||
|
||||
return(FKO_SUCCESS);
|
||||
}
|
||||
|
||||
int fko_calculate_hmac(fko_ctx_t ctx,
|
||||
const char * const hmac_key, const int hmac_key_len)
|
||||
{
|
||||
@@ -155,7 +170,7 @@ int fko_calculate_hmac(fko_ctx_t ctx,
|
||||
|
||||
/* Only HMAC-SHA256 is supported for now
|
||||
*/
|
||||
if(ctx->hmac_mode != FKO_HMAC_SHA256)
|
||||
if(ctx->hmac_type != FKO_HMAC_SHA256)
|
||||
return(FKO_ERROR_UNSUPPORTED_HMAC_MODE);
|
||||
|
||||
hmac_base64 = calloc(1, MD_HEX_SIZE(SHA256_DIGEST_LEN)+1);
|
||||
|
||||
@@ -44,6 +44,42 @@ is_valid_encoded_msg_len(const int len)
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* Convert a digest_type string to its integer value.
|
||||
*/
|
||||
short
|
||||
digest_strtoint(const char *dt_str)
|
||||
{
|
||||
if(strcasecmp(dt_str, "md5") == 0)
|
||||
return(FKO_DIGEST_MD5);
|
||||
else if(strcasecmp(dt_str, "sha1") == 0)
|
||||
return(FKO_DIGEST_SHA1);
|
||||
else if(strcasecmp(dt_str, "sha256") == 0)
|
||||
return(FKO_DIGEST_SHA256);
|
||||
else if(strcasecmp(dt_str, "sha384") == 0)
|
||||
return(FKO_DIGEST_SHA384);
|
||||
else if(strcasecmp(dt_str, "sha512") == 0)
|
||||
return(FKO_DIGEST_SHA512);
|
||||
else
|
||||
return(-1);
|
||||
}
|
||||
|
||||
short
|
||||
hmac_digest_strtoint(const char *dt_str)
|
||||
{
|
||||
if(strcasecmp(dt_str, "md5") == 0)
|
||||
return(FKO_HMAC_MD5);
|
||||
else if(strcasecmp(dt_str, "sha1") == 0)
|
||||
return(FKO_HMAC_SHA1);
|
||||
else if(strcasecmp(dt_str, "sha256") == 0)
|
||||
return(FKO_HMAC_SHA256);
|
||||
else if(strcasecmp(dt_str, "sha384") == 0)
|
||||
return(FKO_HMAC_SHA384);
|
||||
else if(strcasecmp(dt_str, "sha512") == 0)
|
||||
return(FKO_HMAC_SHA512);
|
||||
else
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* Validate plaintext input size
|
||||
*/
|
||||
int
|
||||
|
||||
@@ -39,6 +39,8 @@ int is_valid_digest_len(const int len);
|
||||
int enc_mode_strtoint(const char *enc_mode_str);
|
||||
int strtol_wrapper(const char * const str, const int min,
|
||||
const int max, const int exit_upon_err, int *is_err);
|
||||
short digest_strtoint(const char *dt_str);
|
||||
short hmac_digest_strtoint(const char *dt_str);
|
||||
|
||||
size_t strlcat(char *dst, const char *src, size_t siz);
|
||||
size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||
|
||||
@@ -71,10 +71,12 @@ extern "C" {
|
||||
#define SHA256_DIGEST_LEN 32
|
||||
#define SHA256_DIGEST_STR_LEN (SHA256_DIGEST_LEN * 2 + 1)
|
||||
#define SHA256_B64_LEN 43
|
||||
|
||||
#define SHA384_BLOCK_LEN 128
|
||||
#define SHA384_DIGEST_LEN 48
|
||||
#define SHA384_DIGEST_STR_LEN (SHA384_DIGEST_LEN * 2 + 1)
|
||||
#define SHA384_B64_LEN 64
|
||||
|
||||
#define SHA512_BLOCK_LEN 128
|
||||
#define SHA512_DIGEST_LEN 64
|
||||
#define SHA512_DIGEST_STR_LEN (SHA512_DIGEST_LEN * 2 + 1)
|
||||
|
||||
+3
-3
@@ -179,12 +179,12 @@ _get_encryption_mode(ctx, val)
|
||||
RETVAL
|
||||
|
||||
int
|
||||
_set_hmac_mode(ctx, hmac_mode)
|
||||
_set_hmac_type(ctx, hmac_type)
|
||||
INPUT:
|
||||
fko_ctx_t ctx;
|
||||
short hmac_mode;
|
||||
short hmac_type;
|
||||
CODE:
|
||||
RETVAL = fko_set_hmac_mode(ctx, hmac_mode);
|
||||
RETVAL = fko_set_hmac_type(ctx, hmac_type);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
|
||||
@@ -1029,6 +1029,18 @@ parse_access_file(fko_srv_options_t *opts)
|
||||
&(curr_acc->key_len), curr_acc->key_base64);
|
||||
add_acc_bool(&(curr_acc->use_rijndael), "Y");
|
||||
}
|
||||
/* HMAC digest type */
|
||||
else if(CONF_VAR_IS(var, "HMAC_DIGEST_TYPE"))
|
||||
{
|
||||
curr_acc->hmac_type = hmac_digest_strtoint(val);
|
||||
if(curr_acc->hmac_type < 0)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"HMAC_DIGEST_TYPE argument '%s' must be one of {md5,sha1,sha256,sha384,sha512}\n",
|
||||
val);
|
||||
clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else if(CONF_VAR_IS(var, "HMAC_KEY_BASE64"))
|
||||
{
|
||||
if(strcasecmp(val, "__CHANGEME__") == 0)
|
||||
|
||||
@@ -297,6 +297,7 @@ typedef struct acc_stanza
|
||||
char *hmac_key;
|
||||
int hmac_key_len;
|
||||
char *hmac_key_base64;
|
||||
int hmac_type;
|
||||
unsigned char use_rijndael;
|
||||
int fw_access_timeout;
|
||||
unsigned char enable_cmd_exec;
|
||||
|
||||
@@ -46,8 +46,9 @@
|
||||
#GPG_HOMEDIR /path/to/.gnupg
|
||||
#GPG_SIGNER <signer ID>
|
||||
#GPG_RECIPIENT <recipient ID>
|
||||
KEY_BASE64: wzNP62oPPgEc+kXDPQLHPOayQBuNbYUTPP+QrErNDmg=
|
||||
HMAC_KEY_BASE64: Yh+xizBnl6FotC5ec7FanVGClRMlsOAPh2u6eovnerfBVKwaVKzjGoblFMHMc593TNyi0dWn4opLoTIV9q/ttg==
|
||||
HMAC_DIGEST_TYPE sha256
|
||||
KEY_BASE64 wzNP62oPPgEc+kXDPQLHPOayQBuNbYUTPP+QrErNDmg=
|
||||
HMAC_KEY_BASE64 Yh+xizBnl6FotC5ec7FanVGClRMlsOAPh2u6eovnerfBVKwaVKzjGoblFMHMc593TNyi0dWn4opLoTIV9q/ttg==
|
||||
|
||||
# User-provided named stanzas:
|
||||
|
||||
|
||||
@@ -93,8 +93,8 @@ int main(void) {
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_set_hmac_mode(FKO_HMAC_SHA256): %d\n",
|
||||
fko_set_hmac_mode(ctx, FKO_HMAC_SHA256));
|
||||
printf("fko_set_hmac_type(FKO_HMAC_SHA256): %d\n",
|
||||
fko_set_hmac_type(ctx, FKO_HMAC_SHA256));
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
|
||||
+108
-272
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user