From b446bdc31e7d7fc7947d91fd1948ee7080a6f716 Mon Sep 17 00:00:00 2001 From: Damien Stuart Date: Wed, 31 Dec 2008 20:52:58 +0000 Subject: [PATCH] Broke these out from fko.h. git-svn-id: file:///home/mbr/svn/fwknop/trunk@34 510a4753-2344-4c79-9c09-4d669213fbeb --- fko/fko_context.h | 61 ++++++++++++++++++++++++++++++++ fko/fko_limits.h | 50 ++++++++++++++++++++++++++ fko/fko_state.h | 89 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 200 insertions(+) create mode 100644 fko/fko_context.h create mode 100644 fko/fko_limits.h create mode 100644 fko/fko_state.h diff --git a/fko/fko_context.h b/fko/fko_context.h new file mode 100644 index 00000000..853c02c7 --- /dev/null +++ b/fko/fko_context.h @@ -0,0 +1,61 @@ +/* $Id$ + ***************************************************************************** + * + * File: fko_context.h + * + * Author: Damien S. Stuart + * + * Purpose: fko context definition. + * + * Copyright (C) 2008 Damien Stuart (dstuart@dstuart.org) + * + * License (GNU Public License): + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + ***************************************************************************** +*/ +#ifndef FKO_CONTEXT_H +#define FKO_CONTEXT_H 1 + +/* The pieces we need to make an FKO SPA data packet. +*/ +struct fko_context { + /* FKO SPA user-definable message data */ + char *rand_val; + char *username; + unsigned int timestamp; + short message_type; + char *message; + char *nat_access; + char *server_auth; + unsigned int client_timeout; + + /* FKO SPA user-settable message encoding types */ + short digest_type; + short encryption_type; + + /* Computed or predefined data */ + char *version; + char *digest; + + /* Computed processed data (encodings, etc.) */ + char *encoded_msg; + char *encrypted_msg; + + /* State info */ + unsigned short state; + unsigned char initval; +}; + +#endif /* FKO_CONTEXT_H */ + +/***EOF***/ diff --git a/fko/fko_limits.h b/fko/fko_limits.h new file mode 100644 index 00000000..b002061c --- /dev/null +++ b/fko/fko_limits.h @@ -0,0 +1,50 @@ +/* $Id$ + ***************************************************************************** + * + * File: fko_limits.h + * + * Author: Damien S. Stuart + * + * Purpose: libfko header that defines non-public parameter/limits, etc.. + * + * Copyright (C) 2008 Damien Stuart (dstuart@dstuart.org) + * + * License (GNU Public License): + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + ***************************************************************************** +*/ +#ifndef FKO_LIMITS_H +#define FKO_LIMITS_H 1 + +/* How much space we allow for the fko context error message buffer. +*/ +#define MAX_FKO_ERR_MSG_SIZE 128 + +/* Define some limits (--DSS XXX: These sizes need to be reviewed) +*/ +#define MAX_SPA_USERNAME_SIZE 64 +#define MAX_SPA_MESSAGE_SIZE 256 +#define MAX_SPA_NAT_ACCESS_SIZE 128 +#define MAX_SPA_SERVER_AUTH_SIZE 64 + +#define MIN_SPA_ENCODED_MSG_SIZE 36 /* Somewhat arbitrary */ +#define MIN_GNUPG_MSG_SIZE 400 + +/* Misc. +*/ +#define FKO_ENCODE_TMP_BUF_SIZE 1024 +#define FKO_RAND_VAL_SIZE 16 + +#endif /* FKO_LIMITS_H */ + +/***EOF***/ diff --git a/fko/fko_state.h b/fko/fko_state.h new file mode 100644 index 00000000..cfe93b34 --- /dev/null +++ b/fko/fko_state.h @@ -0,0 +1,89 @@ +/* $Id$ + ***************************************************************************** + * + * File: fko_state.h + * + * Author: Damien S. Stuart + * + * Purpose: Defines various states and flags for libfko operations. + * + * Copyright (C) 2008 Damien Stuart (dstuart@dstuart.org) + * + * License (GNU Public License): + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + ***************************************************************************** +*/ +#ifndef FKO_STATE_H +#define FKO_STATE_H 1 + +/* General state flag bit values. +*/ +typedef enum { + FKO_CTX_SET = 1, /* Set when ctx is initialized */ + FKO_RAND_VAL_MODIFIED = 1 << 1, + FKO_USERNAME_MODIFIED = 1 << 2, + FKO_TIMESTAMP_MODIFIED = 1 << 3, + FKO_VERSION_MODIFIED = 1 << 4, + FKO_SPA_MSG_TYPE_MODIFIED = 1 << 6, + FKO_CTX_SET_2 = 1 << 7, /* Set when ctx is initialized */ + FKO_SPA_MSG_MODIFIED = 1 << 8, + FKO_NAT_ACCESS_MODIFIED = 1 << 9, + FKO_SERVER_AUTH_MODIFIED = 1 << 10, + FKO_CLIENT_TIMEOUT_MODIFIED = 1 << 11, + FKO_DIGEST_TYPE_MODIFIED = 1 << 12, + FKO_ENCRYPT_TYPE_MODIFIED = 1 << 13, + FKO_GPG_SUPPORTED = 1 << 14, + FKO_BACKWARD_COMPATIBLE = 1 << 15 +} fko_state_flags_t; + +/* This is used in conjunction with the ctx->initial value as a means to + * determine if the ctx has been properly initialized. However, this + * may not work 100% of the time as it is possible (though not likely) + * an ctx may have values that match both the flags and the ctx->initial + * value. +*/ +#define FKO_CTX_INITIALIZED (FKO_CTX_SET|FKO_CTX_SET_2) + +#define FKO_SET_CTX_INITIALIZED(ctx) \ + (ctx->state |= (FKO_CTX_INITIALIZED)) + +#define FKO_CLEAR_CTX_INITIALIZED(ctx) \ + (ctx->state &= (0xffff & ~FKO_CTX_INITIALIZED)) + +/* Consolidate all SPA data modified flags. +*/ +#define FKO_ANY_SPA_DATA_MODIFIED ( \ + FKO_RAND_VAL_MODIFIED | FKO_USERNAME_MODIFIED | FKO_TIMESTAMP_MODIFIED \ + | FKO_VERSION_MODIFIED | FKO_SPA_MSG_TYPE_MODIFIED | FKO_SPA_MSG_MODIFIED \ + | FKO_NAT_ACCESS_MODIFIED | FKO_SERVER_AUTH_MODIFIED \ + | FKO_CLIENT_TIMEOUT_MODIFIED | FKO_DIGEST_TYPE_MODIFIED \ + | FKO_ENCRYPT_TYPE_MODIFIED ) + +/* This should return true if any SPA data field has been modifed since the + * last encode/encrypt. +*/ +#define FKO_SPA_DATA_MODIFIED(ctx) (ctx->state & FKO_ANY_SPA_DATA_MODIFIED) + +/* Clear all SPA data modified flags. This is normally called after a + * succesful encode/digest/encryption cycle. +*/ +#define FKO_CLEAR_SPA_DATA_MODIFIED(ctx) \ + (ctx->state &= (0xffff & ~FKO_ANY_SPA_DATA_MODIFIED)) + +/* Macros used for determining ctx initialization state. +*/ +#define CTX_INITIALIZED(ctx) (ctx->initval == FKO_CTX_INITIALIZED) + +#endif /* FKO_STATE_H */ + +/***EOF***/