added encryption type/mode and message type string representations for FKO context diplay output

This commit is contained in:
Michael Rash
2013-03-14 22:26:44 -04:00
parent aa36f3ffee
commit 253ccb7cea
4 changed files with 98 additions and 5 deletions

View File

@@ -947,6 +947,12 @@ get_keys(fko_ctx_t ctx, fko_cli_options_t *options,
{
*hmac_key_len = fko_base64_decode(options->hmac_key_base64,
(unsigned char *) options->hmac_key);
if(*hmac_key_len > MAX_KEY_LEN || *hmac_key_len <= 0)
{
fprintf(stderr, "[*] Invalid decoded key length: '%d', must be in [1,%d]",
*hmac_key_len, MAX_KEY_LEN);
clean_exit(ctx, options, EXIT_FAILURE);
}
memcpy(hmac_key, options->hmac_key, *hmac_key_len);
use_hmac = 1;
}
@@ -1018,6 +1024,7 @@ display_ctx(fko_ctx_t ctx)
short msg_type = -1;
short digest_type = -1;
short hmac_type = -1;
short encryption_type = -1;
int encryption_mode = -1;
int client_timeout = -1;
@@ -1034,6 +1041,7 @@ display_ctx(fko_ctx_t ctx)
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_type(ctx, &encryption_type);
fko_get_spa_encryption_mode(ctx, &encryption_mode);
fko_get_encoded_data(ctx, &enc_data);
fko_get_hmac_data(ctx, &hmac_data);
@@ -1045,14 +1053,15 @@ display_ctx(fko_ctx_t ctx)
printf(" Username: %s\n", username == NULL ? "<NULL>" : username);
printf(" Timestamp: %u\n", (unsigned int) timestamp);
printf(" FKO Version: %s\n", version == NULL ? "<NULL>" : version);
printf(" Message Type: %i\n", msg_type);
printf(" Message Type: %i (%s)\n", msg_type, msg_type_inttostr(msg_type));
printf(" Message String: %s\n", spa_message == NULL ? "<NULL>" : spa_message);
printf(" Nat Access: %s\n", nat_access == NULL ? "<NULL>" : nat_access);
printf(" Server Auth: %s\n", server_auth == NULL ? "<NULL>" : server_auth);
printf(" Client Timeout: %u\n", client_timeout);
printf(" Client Timeout: %u (seconds)\n", client_timeout);
printf(" Digest Type: %d (%s)\n", digest_type, digest_inttostr(digest_type));
printf(" HMAC Type: %d (%s)\n", hmac_type, digest_inttostr(hmac_type));
printf("Encryption Mode: %d\n", encryption_mode);
printf("Encryption Type: %d (%s)\n", encryption_type, enc_type_inttostr(encryption_type));
printf("Encryption Mode: %d (%s)\n", encryption_mode, enc_mode_inttostr(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: %s\n", hmac_data == NULL ? "<NULL>" : hmac_data);

View File

@@ -80,6 +80,71 @@ hmac_digest_strtoint(const char *dt_str)
return(-1);
}
/* Return encryption type string representation
*/
const char *
enc_type_inttostr(const int type)
{
if(type == FKO_ENC_MODE_UNKNOWN)
return("Unknown encryption type");
else if(type == FKO_ENCRYPTION_RIJNDAEL)
return("Rijndael");
else if(type == FKO_ENCRYPTION_GPG)
return("GPG");
return("Unknown encryption type");
}
/* Return encryption mode string representation
*/
const char *
enc_mode_inttostr(const int mode)
{
if(mode == FKO_ENC_MODE_UNKNOWN)
return("Unknown encryption mode");
else if(mode == FKO_ENC_MODE_ECB)
return("ECB");
else if(mode == FKO_ENC_MODE_CBC)
return("CBC");
else if(mode == FKO_ENC_MODE_CFB)
return("CFB");
else if(mode == FKO_ENC_MODE_PCBC)
return("PCBC");
else if(mode == FKO_ENC_MODE_OFB)
return("OFB");
else if(mode == FKO_ENC_MODE_CTR)
return("CTR");
else if(mode == FKO_ENC_MODE_ASYMMETRIC)
return("Asymmetric");
else if(mode == FKO_ENC_MODE_CBC_LEGACY_IV)
return("CBC legacy initialization vector");
return("Unknown encryption mode");
}
/* Return message type string representation
*/
const char *
msg_type_inttostr(const int type)
{
if(type == FKO_COMMAND_MSG)
return("Command msg");
else if(type == FKO_ACCESS_MSG)
return("Access msg");
else if(type == FKO_NAT_ACCESS_MSG)
return("NAT access msg");
else if(type == FKO_CLIENT_TIMEOUT_ACCESS_MSG)
return("Client timeout access msg");
else if(type == FKO_CLIENT_TIMEOUT_NAT_ACCESS_MSG)
return("Client timeout NAT access msg");
else if(type == FKO_LOCAL_NAT_ACCESS_MSG)
return("Local NAT access msg");
else if(type == FKO_CLIENT_TIMEOUT_LOCAL_NAT_ACCESS_MSG)
return("Client timeout local NAT access msg");
return("Unknown message type");
}
/* Return digest string representation
*/
const char *

View File

@@ -39,7 +39,10 @@ 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);
const char * msg_type_inttostr(const int type);
short digest_strtoint(const char *dt_str);
const char * enc_type_inttostr(const int type);
const char * enc_mode_inttostr(const int mode);
const char * digest_inttostr(const int type);
short hmac_digest_strtoint(const char *dt_str);

View File

@@ -84,12 +84,16 @@ dump_ctx(fko_ctx_t ctx)
char *nat_access = NULL;
char *server_auth = NULL;
char *enc_data = NULL;
char *hmac_data = NULL;
char *spa_digest = NULL;
char *spa_data = NULL;
time_t timestamp = 0;
short msg_type = -1;
short digest_type = -1;
short hmac_type = -1;
short encryption_type = -1;
int encryption_mode = -1;
int client_timeout = -1;
/* Should be checking return values, but this is temp code. --DSS
@@ -104,7 +108,11 @@ dump_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_type(ctx, &encryption_type);
fko_get_spa_encryption_mode(ctx, &encryption_mode);
fko_get_encoded_data(ctx, &enc_data);
fko_get_hmac_data(ctx, &hmac_data);
fko_get_spa_digest(ctx, &spa_digest);
fko_get_spa_data(ctx, &spa_data);
@@ -122,7 +130,7 @@ dump_ctx(fko_ctx_t ctx)
ndx += cp;
cp = sprintf(ndx, " FKO Version: %s\n", version == NULL ? "<NULL>" : version);
ndx += cp;
cp = sprintf(ndx, " Message Type: %i\n", msg_type);
cp = sprintf(ndx, " Message Type: %i (%s)\n", msg_type, msg_type_inttostr(msg_type));
ndx += cp;
cp = sprintf(ndx, " Message String: %s\n", spa_message == NULL ? "<NULL>" : spa_message);
ndx += cp;
@@ -132,11 +140,19 @@ dump_ctx(fko_ctx_t ctx)
ndx += cp;
cp = sprintf(ndx, " Client Timeout: %u\n", client_timeout);
ndx += cp;
cp = sprintf(ndx, " Digest Type: %u\n", digest_type);
cp = sprintf(ndx, " Digest Type: %u (%s)\n", digest_type, digest_inttostr(digest_type));
ndx += cp;
cp = sprintf(ndx, " HMAC Type: %u (%s)\n", hmac_type, digest_inttostr(hmac_type));
ndx += cp;
cp = sprintf(ndx, "Encryption Type: %d (%s)\n", encryption_type, enc_type_inttostr(encryption_type));
ndx += cp;
cp = sprintf(ndx, "Encryption Mode: %d (%s)\n", encryption_mode, enc_mode_inttostr(encryption_mode));
ndx += cp;
cp = sprintf(ndx, " Encoded Data: %s\n", enc_data == NULL ? "<NULL>" : enc_data);
ndx += cp;
cp = sprintf(ndx, "SPA Data Digest: %s\n", spa_digest == NULL ? "<NULL>" : spa_digest);
ndx += cp;
cp = sprintf(ndx, " HMAC: %s\n", hmac_data == NULL ? "<NULL>" : hmac_data);
return(buf);
}