* Interim commit to add a dump function to dump the FKO context shared
by both the server and client. mrash/fwknop#95
This commit is contained in:
parent
fc39de607c
commit
7296d3f3bf
@ -39,7 +39,6 @@
|
||||
*/
|
||||
static int get_keys(fko_ctx_t ctx, fko_cli_options_t *options,
|
||||
char *key, int *key_len, char *hmac_key, int *hmac_key_len);
|
||||
static void display_ctx(fko_ctx_t ctx);
|
||||
static void errmsg(const char *msg, const int err);
|
||||
static int prev_exec(fko_cli_options_t *options, int argc, char **argv);
|
||||
static int get_save_file(char *args_save_file);
|
||||
@ -65,7 +64,7 @@ static int is_hostname_str_with_port(const char *str,
|
||||
#define IPV4_STR_TEMPLATE "%u.%u.%u.%u" /*!< Template for a string as an ipv4 address with sscanf */
|
||||
#define NAT_ACCESS_STR_TEMPLATE "%s,%d" /*!< Template for a nat access string ip,port with sscanf*/
|
||||
#define HOSTNAME_BUFSIZE 64 /*!< Maximum size of a hostname string */
|
||||
|
||||
#define CTX_DUMP_BUFSIZE 4096 /*!< Maximum size allocated to a FKO context dump */
|
||||
|
||||
/**
|
||||
* @brief Check whether a string is an ipv4 address or not
|
||||
@ -183,6 +182,7 @@ main(int argc, char **argv)
|
||||
char hmac_key[MAX_KEY_LEN+1] = {0};
|
||||
int key_len = 0, orig_key_len = 0, hmac_key_len = 0, enc_mode;
|
||||
int tmp_port = 0;
|
||||
char dump_buf[CTX_DUMP_BUFSIZE];
|
||||
|
||||
fko_cli_options_t options;
|
||||
|
||||
@ -468,7 +468,13 @@ main(int argc, char **argv)
|
||||
/* Display the context data.
|
||||
*/
|
||||
if (options.verbose || options.test)
|
||||
display_ctx(ctx);
|
||||
{
|
||||
res = dump_ctx_to_buffer(ctx, dump_buf, sizeof(dump_buf));
|
||||
if (res == FKO_SUCCESS)
|
||||
log_msg(LOG_VERBOSITY_NORMAL, "%s", dump_buf);
|
||||
else
|
||||
log_msg(LOG_VERBOSITY_WARNING, "Unable to dump FKO context: %s", fko_errstr(res));
|
||||
}
|
||||
|
||||
/* Save packet data payload if requested.
|
||||
*/
|
||||
@ -610,8 +616,11 @@ main(int argc, char **argv)
|
||||
hmac_key, &hmac_key_len, EXIT_FAILURE);
|
||||
}
|
||||
|
||||
log_msg(LOG_VERBOSITY_NORMAL,"\nDump of the Decoded Data");
|
||||
display_ctx(ctx2);
|
||||
res = dump_ctx_to_buffer(ctx2, dump_buf, sizeof(dump_buf));
|
||||
if (res == FKO_SUCCESS)
|
||||
log_msg(LOG_VERBOSITY_NORMAL, "\nDump of the Decoded Data\n%s", dump_buf);
|
||||
else
|
||||
log_msg(LOG_VERBOSITY_WARNING, "Unable to dump FKO context: %s", fko_errstr(res));
|
||||
|
||||
if(fko_destroy(ctx2) == FKO_ERROR_ZERO_OUT_DATA)
|
||||
log_msg(LOG_VERBOSITY_ERROR,
|
||||
@ -1306,79 +1315,4 @@ clean_exit(fko_ctx_t ctx, fko_cli_options_t *opts,
|
||||
exit(exit_status);
|
||||
}
|
||||
|
||||
/* Show the fields of the FKO context.
|
||||
*/
|
||||
static void
|
||||
display_ctx(fko_ctx_t ctx)
|
||||
{
|
||||
char *rand_val = NULL;
|
||||
char *username = NULL;
|
||||
char *version = NULL;
|
||||
char *spa_message = NULL;
|
||||
char *nat_access = NULL;
|
||||
char *server_auth = NULL;
|
||||
char *enc_data = NULL;
|
||||
char *hmac_data = NULL;
|
||||
char *spa_digest = NULL;
|
||||
char *spa_data = NULL;
|
||||
char digest_str[MAX_LINE_LEN] = {0};
|
||||
char hmac_str[MAX_LINE_LEN] = {0};
|
||||
char enc_mode_str[MAX_LINE_LEN] = {0};
|
||||
|
||||
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
|
||||
*/
|
||||
fko_get_rand_value(ctx, &rand_val);
|
||||
fko_get_username(ctx, &username);
|
||||
fko_get_timestamp(ctx, ×tamp);
|
||||
fko_get_version(ctx, &version);
|
||||
fko_get_spa_message_type(ctx, &msg_type);
|
||||
fko_get_spa_message(ctx, &spa_message);
|
||||
fko_get_spa_nat_access(ctx, &nat_access);
|
||||
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_spa_hmac(ctx, &hmac_data);
|
||||
fko_get_spa_digest(ctx, &spa_digest);
|
||||
fko_get_spa_data(ctx, &spa_data);
|
||||
|
||||
digest_inttostr(digest_type, digest_str, sizeof(digest_str));
|
||||
hmac_digest_inttostr(hmac_type, hmac_str, sizeof(hmac_str));
|
||||
enc_mode_inttostr(encryption_mode, enc_mode_str, sizeof(enc_mode_str));
|
||||
|
||||
log_msg(LOG_VERBOSITY_NORMAL, "\nFKO Field Values:\n=================\n");
|
||||
log_msg(LOG_VERBOSITY_NORMAL, " Random Value: %s", rand_val == NULL ? "<NULL>" : rand_val);
|
||||
log_msg(LOG_VERBOSITY_NORMAL, " Username: %s", username == NULL ? "<NULL>" : username);
|
||||
log_msg(LOG_VERBOSITY_NORMAL, " Timestamp: %u", (unsigned int) timestamp);
|
||||
log_msg(LOG_VERBOSITY_NORMAL, " FKO Version: %s", version == NULL ? "<NULL>" : version);
|
||||
log_msg(LOG_VERBOSITY_NORMAL, " Message Type: %i (%s)", msg_type, msg_type_inttostr(msg_type));
|
||||
log_msg(LOG_VERBOSITY_NORMAL, " Message String: %s", spa_message == NULL ? "<NULL>" : spa_message);
|
||||
log_msg(LOG_VERBOSITY_NORMAL, " Nat Access: %s", nat_access == NULL ? "<NULL>" : nat_access);
|
||||
log_msg(LOG_VERBOSITY_NORMAL, " Server Auth: %s", server_auth == NULL ? "<NULL>" : server_auth);
|
||||
log_msg(LOG_VERBOSITY_NORMAL, " Client Timeout: %u (seconds)", client_timeout);
|
||||
log_msg(LOG_VERBOSITY_NORMAL, " Digest Type: %d (%s)", digest_type, digest_str);
|
||||
log_msg(LOG_VERBOSITY_NORMAL, " HMAC Type: %d (%s)", hmac_type, hmac_str);
|
||||
log_msg(LOG_VERBOSITY_NORMAL, "Encryption Type: %d (%s)", encryption_type, enc_type_inttostr(encryption_type));
|
||||
log_msg(LOG_VERBOSITY_NORMAL, "Encryption Mode: %d (%s)", encryption_mode, enc_mode_str);
|
||||
log_msg(LOG_VERBOSITY_NORMAL, "\n Encoded Data: %s", enc_data == NULL ? "<NULL>" : enc_data);
|
||||
log_msg(LOG_VERBOSITY_NORMAL, "SPA Data Digest: %s", spa_digest == NULL ? "<NULL>" : spa_digest);
|
||||
log_msg(LOG_VERBOSITY_NORMAL, " HMAC: %s", hmac_data == NULL ? "<NULL>" : hmac_data);
|
||||
|
||||
if (enc_data != NULL && spa_digest != NULL)
|
||||
log_msg(LOG_VERBOSITY_NORMAL, " Plaintext: %s:%s\n", enc_data, spa_digest);
|
||||
|
||||
log_msg(LOG_VERBOSITY_NORMAL, "\nFinal Packed/Encrypted/Encoded Data:\n\n%s\n", spa_data);
|
||||
}
|
||||
|
||||
/***EOF***/
|
||||
|
||||
165
lib/fko_util.c
165
lib/fko_util.c
@ -29,14 +29,22 @@
|
||||
*****************************************************************************
|
||||
*/
|
||||
#include "fko_common.h"
|
||||
#include "fko.h"
|
||||
#include "fko_util.h"
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/* Check for a FKO error returned by a function an go to the error label */
|
||||
#define CHECK_FKO_ERROR(e, f) do { if (((e)=(f)) != FKO_SUCCESS) { goto error; } } while(0);
|
||||
|
||||
/* Check for an error returned by a function an go to the error label. The error is set to a specific value */
|
||||
#define CHECK_ERROR(e, v, f) do { if (((e)=(f)) != 0) { (e)=(v); goto error; } } while(0);
|
||||
|
||||
#define FKO_ENCRYPTION_MODE_BUFSIZE 16 /*!< Maximum size of an encryption mode string */
|
||||
#define FKO_ENC_MODE_SUPPORTED 0 /*!< Defined a supported fko encryption mode */
|
||||
#define FKO_ENC_MODE_NOT_SUPPORTED !FKO_ENC_MODE_SUPPORTED /*!< Defined an unsupported fko encryption mode */
|
||||
|
||||
#define NULL_STRING "<NULL>" /*!< String which represents a NULL buffer */
|
||||
|
||||
/**
|
||||
* Structure to handle an encryption mode string string and its associated integer value
|
||||
*/
|
||||
@ -466,4 +474,159 @@ char
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Add a printf style message to a buffer
|
||||
*
|
||||
* This function allows to append a printf style message to a buffer
|
||||
* and prevents buffer overflow by taking care of the size the buffer.
|
||||
* It returns the number of bytes really written to the buffer.
|
||||
* Thus if an error is encoutered during the process the number of bytes
|
||||
* written is set to 0. This way the user knows exactly how many bytes
|
||||
* can be appended afterwards.
|
||||
*
|
||||
* @param buf Buffer to write the formated message to
|
||||
* @param buf_size Maximum number of bytes to write to the buffer
|
||||
* @param msg Message to format and to append to the buffer
|
||||
*
|
||||
* @return the number of bytes written to the buffer
|
||||
*/
|
||||
static int
|
||||
append_msg_to_buf(char *buf, size_t buf_size, const char* msg, ...)
|
||||
{
|
||||
int bytes_written = 0; /* Number of bytes written to buf */
|
||||
va_list ap;
|
||||
|
||||
/* Check if the buffer is valid */
|
||||
if (buf_size != 0)
|
||||
{
|
||||
va_start(ap, msg);
|
||||
|
||||
/* Format the message like a printf message */
|
||||
bytes_written = vsnprintf(buf, buf_size, msg, ap);
|
||||
|
||||
/* It looks like the message has been truncated or an error occured*/
|
||||
if (bytes_written < 0)
|
||||
bytes_written = 0;
|
||||
|
||||
else if (bytes_written >= buf_size)
|
||||
bytes_written = buf_size;
|
||||
|
||||
/* The messsage has been formatted correctly */
|
||||
else;
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/* No valid buffer has been supplied, thus we do not write anything */
|
||||
else;
|
||||
|
||||
/* Return the number of bytes written to the buffer */
|
||||
return bytes_written;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Dump a FKO context to a buffer
|
||||
*
|
||||
* @param ctx FKO context to dump
|
||||
* @param dump_buf Buffer where to store the dump of the context
|
||||
* @param dump_buf_len Number of bytes available in the dump_buf array
|
||||
*
|
||||
* @return a FKO error code. FKO_SUCCESS if successful.
|
||||
*/
|
||||
int
|
||||
dump_ctx_to_buffer(fko_ctx_t ctx, char *dump_buf, size_t dump_buf_len)
|
||||
{
|
||||
int cp = 0;
|
||||
int err = FKO_LAST_ERROR;
|
||||
|
||||
char *rand_val = NULL;
|
||||
char *username = NULL;
|
||||
char *version = NULL;
|
||||
char *spa_message = NULL;
|
||||
char *nat_access = NULL;
|
||||
char *server_auth = NULL;
|
||||
char *enc_data = NULL;
|
||||
char *hmac_data = NULL;
|
||||
char *spa_digest = NULL;
|
||||
char *spa_data = NULL;
|
||||
char digest_str[24] = {0};
|
||||
char hmac_str[24] = {0};
|
||||
char enc_mode_str[FKO_ENCRYPTION_MODE_BUFSIZE] = {0};
|
||||
|
||||
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;
|
||||
|
||||
/* Zero-ed the buffer */
|
||||
memset(dump_buf, 0, dump_buf_len);
|
||||
|
||||
/* Make sure the FKO context is initialized before printing it */
|
||||
if(!CTX_INITIALIZED(ctx))
|
||||
err = FKO_ERROR_CTX_NOT_INITIALIZED;
|
||||
|
||||
else
|
||||
{
|
||||
/* Parse the FKO context and collect data */
|
||||
CHECK_FKO_ERROR(err, fko_get_rand_value(ctx, &rand_val));
|
||||
CHECK_FKO_ERROR(err, fko_get_username(ctx, &username));
|
||||
CHECK_FKO_ERROR(err, fko_get_timestamp(ctx, ×tamp));
|
||||
CHECK_FKO_ERROR(err, fko_get_version(ctx, &version));
|
||||
CHECK_FKO_ERROR(err, fko_get_spa_message_type(ctx, &msg_type));
|
||||
CHECK_FKO_ERROR(err, fko_get_spa_message(ctx, &spa_message));
|
||||
CHECK_FKO_ERROR(err, fko_get_spa_nat_access(ctx, &nat_access));
|
||||
CHECK_FKO_ERROR(err, fko_get_spa_server_auth(ctx, &server_auth));
|
||||
CHECK_FKO_ERROR(err, fko_get_spa_client_timeout(ctx, &client_timeout));
|
||||
CHECK_FKO_ERROR(err, fko_get_spa_digest_type(ctx, &digest_type));
|
||||
CHECK_FKO_ERROR(err, fko_get_spa_hmac_type(ctx, &hmac_type));
|
||||
CHECK_FKO_ERROR(err, fko_get_spa_encryption_type(ctx, &encryption_type));
|
||||
CHECK_FKO_ERROR(err, fko_get_spa_encryption_mode(ctx, &encryption_mode));
|
||||
CHECK_FKO_ERROR(err, fko_get_encoded_data(ctx, &enc_data));
|
||||
CHECK_FKO_ERROR(err, fko_get_spa_hmac(ctx, &hmac_data));
|
||||
CHECK_FKO_ERROR(err, fko_get_spa_digest(ctx, &spa_digest));
|
||||
CHECK_FKO_ERROR(err, fko_get_spa_data(ctx, &spa_data));
|
||||
|
||||
/* Convert integer to string for somes of the FKO fields */
|
||||
CHECK_ERROR(err, FKO_ERROR_INVALID_DIGEST_TYPE,
|
||||
digest_inttostr(digest_type, digest_str, sizeof(digest_str)));
|
||||
CHECK_ERROR(err, FKO_ERROR_INVALID_ENCRYPTION_TYPE,
|
||||
enc_mode_inttostr(encryption_mode, enc_mode_str, sizeof(enc_mode_str)));
|
||||
if (ctx->msg_hmac_len != 0)
|
||||
{
|
||||
CHECK_ERROR(err, FKO_ERROR_UNSUPPORTED_HMAC_MODE,
|
||||
hmac_digest_inttostr(hmac_type, hmac_str, sizeof(hmac_str)));
|
||||
}
|
||||
|
||||
/* Fill in the buffer to dump */
|
||||
cp = append_msg_to_buf(dump_buf, dump_buf_len, "SPA Field Values:\n=================\n");
|
||||
cp += append_msg_to_buf(dump_buf+cp, dump_buf_len-cp, " Random Value: %s\n", rand_val == NULL ? NULL_STRING : rand_val);
|
||||
cp += append_msg_to_buf(dump_buf+cp, dump_buf_len-cp, " Username: %s\n", username == NULL ? NULL_STRING : username);
|
||||
cp += append_msg_to_buf(dump_buf+cp, dump_buf_len-cp, " Timestamp: %u\n", (unsigned int) timestamp);
|
||||
cp += append_msg_to_buf(dump_buf+cp, dump_buf_len-cp, " FKO Version: %s\n", version == NULL ? NULL_STRING : version);
|
||||
cp += append_msg_to_buf(dump_buf+cp, dump_buf_len-cp, " Message Type: %i (%s)\n", msg_type, msg_type_inttostr(msg_type));
|
||||
cp += append_msg_to_buf(dump_buf+cp, dump_buf_len-cp, " Message String: %s\n", spa_message == NULL ? NULL_STRING : spa_message);
|
||||
cp += append_msg_to_buf(dump_buf+cp, dump_buf_len-cp, " Nat Access: %s\n", nat_access == NULL ? NULL_STRING : nat_access);
|
||||
cp += append_msg_to_buf(dump_buf+cp, dump_buf_len-cp, " Server Auth: %s\n", server_auth == NULL ? NULL_STRING : server_auth);
|
||||
cp += append_msg_to_buf(dump_buf+cp, dump_buf_len-cp, " Client Timeout: %u\n", client_timeout);
|
||||
cp += append_msg_to_buf(dump_buf+cp, dump_buf_len-cp, " Digest Type: %u (%s)\n", digest_type, digest_str);
|
||||
cp += append_msg_to_buf(dump_buf+cp, dump_buf_len-cp, " HMAC Type: %u (%s)\n", hmac_type, hmac_str);
|
||||
cp += append_msg_to_buf(dump_buf+cp, dump_buf_len-cp, "Encryption Type: %d (%s)\n", encryption_type, enc_type_inttostr(encryption_type));
|
||||
cp += append_msg_to_buf(dump_buf+cp, dump_buf_len-cp, "Encryption Mode: %d (%s)\n", encryption_mode, enc_mode_str);
|
||||
cp += append_msg_to_buf(dump_buf+cp, dump_buf_len-cp, " Encoded Data: %s\n", enc_data == NULL ? NULL_STRING : enc_data);
|
||||
cp += append_msg_to_buf(dump_buf+cp, dump_buf_len-cp, "SPA Data Digest: %s\n", spa_digest == NULL ? NULL_STRING : spa_digest);
|
||||
cp += append_msg_to_buf(dump_buf+cp, dump_buf_len-cp, " HMAC: %s\n", hmac_data == NULL ? NULL_STRING : hmac_data);
|
||||
|
||||
if (enc_data != NULL && spa_digest != NULL)
|
||||
cp += append_msg_to_buf(dump_buf+cp, dump_buf_len-cp, " Plaintext: %s:%s\n", enc_data, spa_digest);
|
||||
|
||||
cp += append_msg_to_buf(dump_buf+cp, dump_buf_len-cp, "\nFinal Packed/Encrypted/Encoded Data:\n\n%s\n", spa_data);
|
||||
}
|
||||
|
||||
error:
|
||||
return (err);
|
||||
}
|
||||
|
||||
/***EOF***/
|
||||
|
||||
@ -31,6 +31,8 @@
|
||||
#ifndef FKO_UTIL_H
|
||||
#define FKO_UTIL_H 1
|
||||
|
||||
#include "fko.h"
|
||||
|
||||
/* Function prototypes
|
||||
*/
|
||||
int is_valid_encoded_msg_len(const int len);
|
||||
@ -58,6 +60,8 @@ size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||
char * strndup( const char * s, size_t len );
|
||||
#endif
|
||||
|
||||
int dump_ctx_to_buffer(fko_ctx_t ctx, char *dump_buf, size_t dump_buf_len);
|
||||
|
||||
#endif /* FKO_UTIL_H */
|
||||
|
||||
/***EOF***/
|
||||
|
||||
@ -44,6 +44,8 @@
|
||||
#include "fwknopd_errors.h"
|
||||
#include "replay_cache.h"
|
||||
|
||||
#define CTX_DUMP_BUFSIZE 4096 /*!< Maximum size allocated to a FKO context dump */
|
||||
|
||||
/* Validate and in some cases preprocess/reformat the SPA data. Return an
|
||||
* error code value if there is any indication the data is not valid spa data.
|
||||
*/
|
||||
@ -273,6 +275,7 @@ incoming_spa(fko_srv_options_t *opts)
|
||||
int added_replay_digest = 0, pkt_data_len=0;
|
||||
int is_err, cmd_exec_success = 0, attempted_decrypt = 0;
|
||||
int conf_pkt_age = 0;
|
||||
char dump_buf[CTX_DUMP_BUFSIZE];
|
||||
|
||||
spa_pkt_info_t *spa_pkt = &(opts->spa_pkt);
|
||||
|
||||
@ -544,8 +547,14 @@ incoming_spa(fko_srv_options_t *opts)
|
||||
/* At this point, we assume the SPA data is valid. Now we need to see
|
||||
* if it meets our access criteria.
|
||||
*/
|
||||
log_msg(LOG_DEBUG, "[%s] (stanza #%d) SPA Decode (res=%i):\n%s",
|
||||
spadat.pkt_source_ip, stanza_num, res, dump_ctx(ctx));
|
||||
log_msg(LOG_DEBUG, "[%s] (stanza #%d) SPA Decode (res=%i):",
|
||||
spadat.pkt_source_ip, stanza_num, res);
|
||||
|
||||
res = dump_ctx_to_buffer(ctx, dump_buf, sizeof(dump_buf));
|
||||
if (res == FKO_SUCCESS)
|
||||
log_msg(LOG_DEBUG, "%s", dump_buf);
|
||||
else
|
||||
log_msg(LOG_WARNING, "Unable to dump FKO context: %s", fko_errstr(res));
|
||||
|
||||
/* First, if this is a GPG message, and GPG_REMOTE_ID list is not empty,
|
||||
* then we need to make sure this incoming message is signer ID matches
|
||||
|
||||
120
server/utils.c
120
server/utils.c
@ -30,48 +30,6 @@
|
||||
#include "log_msg.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
/**
|
||||
* @brief Add a printf style message to a buffer
|
||||
*
|
||||
* This function allows to append a printf style message to a buffer
|
||||
* and prevents buffer overflow by taking care of the size the buffer.
|
||||
* It returns the number of bytes really written to the buffer.
|
||||
* Thus if an error is encoutered during the process the number of bytes
|
||||
* written is set to 0. This way the user knows exactly how many bytes
|
||||
* can be appended afterwards.
|
||||
*
|
||||
* @param buf Buffer to write the formated message to
|
||||
* @param buf_size Maximum number of bytes to write to the buffer
|
||||
* @param msg Message to format and to append to the buffer
|
||||
*
|
||||
* @return the number of bytes written to the buffer
|
||||
*/
|
||||
static int
|
||||
append_msg_to_buf(char *buf, size_t buf_size, const char* msg, ...)
|
||||
{
|
||||
int bytes_written = 0; /* Number of bytes written to buf */
|
||||
va_list ap;
|
||||
|
||||
if (buf_size != 0)
|
||||
{
|
||||
va_start(ap, msg);
|
||||
|
||||
bytes_written = vsnprintf(buf, buf_size, msg, ap);
|
||||
if ( (bytes_written < 0) || (bytes_written >= buf_size) )
|
||||
{
|
||||
log_msg(LOG_WARNING, "add_msg_to_buf() : message truncated / snprintf error");
|
||||
bytes_written = 0;
|
||||
}
|
||||
else;
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
else
|
||||
log_msg(LOG_WARNING, "add_msg_to_buf() : nothing to write.");
|
||||
|
||||
return bytes_written;
|
||||
}
|
||||
|
||||
/* Generic hex dump function.
|
||||
*/
|
||||
void
|
||||
@ -109,84 +67,6 @@ hex_dump(const unsigned char *data, const int size)
|
||||
}
|
||||
}
|
||||
|
||||
/* Show the fields of the FKO context.
|
||||
*/
|
||||
char *
|
||||
dump_ctx(fko_ctx_t ctx)
|
||||
{
|
||||
static char buf[CTX_DUMP_BUFSIZE] = {0};
|
||||
int cp = 0;
|
||||
size_t bytes_left;
|
||||
|
||||
char *rand_val = NULL;
|
||||
char *username = NULL;
|
||||
char *version = NULL;
|
||||
char *spa_message = NULL;
|
||||
char *nat_access = NULL;
|
||||
char *server_auth = NULL;
|
||||
char *enc_data = NULL;
|
||||
char *hmac_data = NULL;
|
||||
char *spa_digest = NULL;
|
||||
char *spa_data = NULL;
|
||||
char digest_str[MAX_LINE_LEN] = {0};
|
||||
char hmac_str[MAX_LINE_LEN] = {0};
|
||||
char enc_mode_str[MAX_LINE_LEN] = {0};
|
||||
|
||||
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
|
||||
*/
|
||||
fko_get_rand_value(ctx, &rand_val);
|
||||
fko_get_username(ctx, &username);
|
||||
fko_get_timestamp(ctx, ×tamp);
|
||||
fko_get_version(ctx, &version);
|
||||
fko_get_spa_message_type(ctx, &msg_type);
|
||||
fko_get_spa_message(ctx, &spa_message);
|
||||
fko_get_spa_nat_access(ctx, &nat_access);
|
||||
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_spa_hmac(ctx, &hmac_data);
|
||||
fko_get_spa_digest(ctx, &spa_digest);
|
||||
fko_get_spa_data(ctx, &spa_data);
|
||||
|
||||
digest_inttostr(digest_type, digest_str, sizeof(digest_str));
|
||||
hmac_digest_inttostr(hmac_type, hmac_str, sizeof(hmac_str));
|
||||
enc_mode_inttostr(encryption_mode, enc_mode_str, sizeof(enc_mode_str));
|
||||
|
||||
bytes_left = sizeof(buf) - 1;
|
||||
|
||||
cp = append_msg_to_buf(buf, bytes_left, "SPA Field Values:\n=================\n");
|
||||
cp += append_msg_to_buf(buf+cp, bytes_left-cp, " Random Value: %s\n", rand_val == NULL ? "<NULL>" : rand_val);
|
||||
cp += append_msg_to_buf(buf+cp, bytes_left-cp, " Username: %s\n", username == NULL ? "<NULL>" : username);
|
||||
cp += append_msg_to_buf(buf+cp, bytes_left-cp, " Timestamp: %u\n", (unsigned int) timestamp);
|
||||
cp += append_msg_to_buf(buf+cp, bytes_left-cp, " FKO Version: %s\n", version == NULL ? "<NULL>" : version);
|
||||
cp += append_msg_to_buf(buf+cp, bytes_left-cp, " Message Type: %i (%s)\n", msg_type, msg_type_inttostr(msg_type));
|
||||
cp += append_msg_to_buf(buf+cp, bytes_left-cp, " Message String: %s\n", spa_message == NULL ? "<NULL>" : spa_message);
|
||||
cp += append_msg_to_buf(buf+cp, bytes_left-cp, " Nat Access: %s\n", nat_access == NULL ? "<NULL>" : nat_access);
|
||||
cp += append_msg_to_buf(buf+cp, bytes_left-cp, " Server Auth: %s\n", server_auth == NULL ? "<NULL>" : server_auth);
|
||||
cp += append_msg_to_buf(buf+cp, bytes_left-cp, " Client Timeout: %u\n", client_timeout);
|
||||
cp += append_msg_to_buf(buf+cp, bytes_left-cp, " Digest Type: %u (%s)\n", digest_type, digest_str);
|
||||
cp += append_msg_to_buf(buf+cp, bytes_left-cp, " HMAC Type: %u (%s)\n", hmac_type, hmac_str);
|
||||
cp += append_msg_to_buf(buf+cp, bytes_left-cp, "Encryption Type: %d (%s)\n", encryption_type, enc_type_inttostr(encryption_type));
|
||||
cp += append_msg_to_buf(buf+cp, bytes_left-cp, "Encryption Mode: %d (%s)\n", encryption_mode, enc_mode_str);
|
||||
cp += append_msg_to_buf(buf+cp, bytes_left-cp, " Encoded Data: %s\n", enc_data == NULL ? "<NULL>" : enc_data);
|
||||
cp += append_msg_to_buf(buf+cp, bytes_left-cp, "SPA Data Digest: %s\n", spa_digest == NULL ? "<NULL>" : spa_digest);
|
||||
cp += append_msg_to_buf(buf+cp, bytes_left-cp, " HMAC: %s\n", hmac_data == NULL ? "<NULL>" : hmac_data);
|
||||
|
||||
return(buf);
|
||||
}
|
||||
|
||||
/* Basic directory checks (stat() and whether the path is actually
|
||||
* a directory).
|
||||
*/
|
||||
|
||||
@ -33,8 +33,6 @@
|
||||
|
||||
#include "fko.h"
|
||||
|
||||
#define CTX_DUMP_BUFSIZE 4096
|
||||
|
||||
/* Some convenience macros */
|
||||
|
||||
/* Characters allowed between a config parameter and its value.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user