fko_decode.c fko_encryption.c fko_error.c fko_funcs.c fko_message.c \
fko_message.h fko_nat_access.c fko_rand_value.c fko_server_auth.c \
fko.h fko_limits.h fko_timestamp.c fko_hmac.c hmac.c hmac.h \
- fko_user.c fko_util.h md5.c md5.h rijndael.c rijndael.h sha1.c sha1.h \
- sha2.c sha2.h strlcat.c strlcpy.c fko_state.h fko_context.h \
- gpgme_funcs.c gpgme_funcs.h
+ fko_user.c fko_util.c fko_util.h md5.c md5.h rijndael.c rijndael.h \
+ sha1.c sha1.h sha2.c sha2.h strlcat.c strlcpy.c fko_state.h \
+ fko_context.h gpgme_funcs.c gpgme_funcs.h
libfko_la_SOURCES = $(libfko_source_files)
char *tbuf, *ndx, *tmp;
int t_size, i;
- if (ctx->encoded_msg_len < MIN_SPA_ENCODED_MSG_SIZE
- || ctx->encoded_msg_len > MAX_SPA_ENCODED_MSG_SIZE)
+ if (! is_valid_encoded_msg_len(ctx->encoded_msg_len))
return(FKO_ERROR_INVALID_DATA);
/* Make sure there are enough fields in the SPA packet
ctx->encoded_msg_len = strnlen(ctx->encoded_msg, MAX_SPA_ENCODED_MSG_SIZE);
- if(ctx->encoded_msg_len == MAX_SPA_ENCODED_MSG_SIZE)
+ if(! is_valid_encoded_msg_len(ctx->encoded_msg_len));
return(FKO_ERROR_INVALID_DATA);
/* At this point we can compute the digest for this SPA data.
unsigned char *ciphertext;
int cipher_len;
+ if (! is_valid_encoded_msg_len(ctx->encoded_msg_len))
+ return(FKO_ERROR_INVALID_DATA);
+
+ if (! is_valid_digest_len(ctx->digest_len))
+ return(FKO_ERROR_INVALID_DATA);
+
/* Make a bucket big enough to hold the enc msg + digest (plaintext)
* and populate it appropriately.
*/
if(pt_len < (cipher_len - 32))
return(FKO_ERROR_DECRYPTION_SIZE);
- if(ctx->encoded_msg == NULL || pt_len < MIN_SPA_ENCODED_MSG_SIZE)
+ if(ctx->encoded_msg == NULL)
return(FKO_ERROR_INVALID_DATA);
- if(pt_len == MAX_SPA_ENCODED_MSG_SIZE)
+ if(! is_valid_encoded_msg_len(pt_len))
return(FKO_ERROR_INVALID_DATA);
ctx->encoded_msg_len = pt_len;
size_t cipher_len;
char *empty_key = "";
+ if (! is_valid_encoded_msg_len(ctx->encoded_msg_len))
+ return(FKO_ERROR_INVALID_DATA);
+
+ if (! is_valid_digest_len(ctx->digest_len))
+ return(FKO_ERROR_INVALID_DATA);
+
/* First make sure we have a recipient key set.
*/
if(ctx->gpg_recipient == NULL)
pt_len = strnlen(ctx->encoded_msg, MAX_SPA_ENCODED_MSG_SIZE);
- if(ctx->encoded_msg == NULL || pt_len < MIN_SPA_ENCODED_MSG_SIZE)
+ if(ctx->encoded_msg == NULL)
return(FKO_ERROR_INVALID_DATA);
- if(pt_len == MAX_SPA_ENCODED_MSG_SIZE)
+ if(! is_valid_encoded_msg_len(pt_len))
return(FKO_ERROR_INVALID_DATA);
ctx->encoded_msg_len = pt_len;
* check for a somewhat arbitrary minimum length for the encoded
* data.
*/
- if(ctx->encoded_msg_len < MIN_SPA_ENCODED_MSG_SIZE)
+ if (! is_valid_encoded_msg_len(ctx->encoded_msg_len))
return(FKO_ERROR_MISSING_ENCODED_DATA);
/* Encrypt according to type and return...
--- /dev/null
+/*
+ *****************************************************************************
+ *
+ * File: fko_util.c
+ *
+ * Author: Michael Rash
+ *
+ * Purpose: Set/Get the current username.
+ *
+ * Copyright 2012 Michael Rash (mbr@cipherdyne.org)
+ *
+ * License (GNU Public License):
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * 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
+ *
+ *****************************************************************************
+*/
+#include "fko_common.h"
+#include "fko.h"
+
+/* Validate encoded message length
+*/
+int
+is_valid_encoded_msg_len(const int len)
+{
+ if(len < MIN_SPA_ENCODED_MSG_SIZE || len >= MAX_SPA_ENCODED_MSG_SIZE)
+ return(0);
+
+ return(1);
+}
+
+/* Validate digest length
+*/
+int
+is_valid_digest_len(const int len)
+{
+ switch(len)
+ {
+ case MD5_B64_LENGTH:
+ break;
+ case SHA1_B64_LENGTH:
+ break;
+ case SHA256_B64_LENGTH:
+ break;
+ case SHA384_B64_LENGTH:
+ break;
+ case SHA512_B64_LENGTH:
+ break;
+ default:
+ return(0);
+ }
+
+ return(1);
+}
/* Function prototypes
*/
+int is_valid_encoded_msg_len(const int len);
+int is_valid_digest_len(const int len);
+
size_t strlcat(char *dst, const char *src, size_t siz);
size_t strlcpy(char *dst, const char *src, size_t siz);