From 31ef94024cea1edb3024c9f78efa30794aa81264 Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Thu, 16 Jul 2009 00:28:04 +0000 Subject: [PATCH] added B64_GPG_PREFIX 'hQ' string for GnuPG prefix handling (similar to the 'Salted__' handling for Rijndael SPA packet encryption git-svn-id: file:///home/mbr/svn/fwknop/trunk@111 510a4753-2344-4c79-9c09-4d669213fbeb --- fko/fko_encryption.c | 4 ++-- fko/fko_funcs.c | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/fko/fko_encryption.c b/fko/fko_encryption.c index e5a9cdce..2c0f1e5b 100644 --- a/fko/fko_encryption.c +++ b/fko/fko_encryption.c @@ -119,14 +119,14 @@ _rijndael_decrypt(fko_ctx_t ctx, char *dec_key, int b64_len) if(tbuf == NULL) return(FKO_ERROR_MEMORY_ALLOCATION); - memmove(tbuf+10, tbuf, b64_len); + memmove(tbuf+strlen(B64_RIJNDAEL_SALT), tbuf, b64_len); ctx->encrypted_msg = memcpy(tbuf, B64_RIJNDAEL_SALT, strlen(B64_RIJNDAEL_SALT)); /* Adjust b64_len for added SALT value and Make sure we are still * a properly NULL-terminated string (Ubuntu was one system for * which this was an issue). */ - b64_len += 10; + b64_len += strlen(B64_RIJNDAEL_SALT); tbuf[b64_len] = '\0'; } diff --git a/fko/fko_funcs.c b/fko/fko_funcs.c index 6c8cb137..c71f3d81 100644 --- a/fko/fko_funcs.c +++ b/fko/fko_funcs.c @@ -30,6 +30,7 @@ * of Rijndael encrypted data. */ #define B64_RIJNDAEL_SALT "U2FsdGVkX1" +#define B64_GPG_PREFIX "hQ" /* Initialize an fko context. */ @@ -303,10 +304,14 @@ fko_get_spa_data(fko_ctx_t ctx, char **spa_data) *spa_data = ctx->encrypted_msg; /* Notice we omit the first 10 bytes if Rijndael encryption is - * used (to eliminate the consistent 'Salted__' string). + * used (to eliminate the consistent 'Salted__' string), and + * in GnuPG mode we eliminate the consistent 'hQ' base64 encoded + * prefix */ if(ctx->encryption_type == FKO_ENCRYPTION_RIJNDAEL) - *spa_data += 10; + *spa_data += strlen(B64_RIJNDAEL_SALT); + else if(ctx->encryption_type == FKO_ENCRYPTION_GPG) + *spa_data += strlen(B64_GPG_PREFIX); return(FKO_SUCCESS); }