From 81890bfdb2c3b4db5be8a1744925581476c77a34 Mon Sep 17 00:00:00 2001 From: BakasuraRCE Date: Sat, 1 Jun 2019 18:00:57 -0500 Subject: [PATCH] fishlim: Use Glib base64 functions fix string consts wasn't end in NULL --- plugins/fishlim/base64.c | 103 ------------------------ plugins/fishlim/base64.h | 36 --------- plugins/fishlim/fish.c | 9 ++- plugins/fishlim/fishlim.vcxproj | 2 - plugins/fishlim/fishlim.vcxproj.filters | 6 -- plugins/fishlim/meson.build | 1 - 6 files changed, 5 insertions(+), 152 deletions(-) delete mode 100644 plugins/fishlim/base64.c delete mode 100644 plugins/fishlim/base64.h diff --git a/plugins/fishlim/base64.c b/plugins/fishlim/base64.c deleted file mode 100644 index 0988ecc3..00000000 --- a/plugins/fishlim/base64.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - - MIT License - - Copyright (c) 2013 Barry Steyn - Copyright (c) 2019 - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - -*/ - -#include "base64.h" - -#include -#include -#include -#include -#include -#include - -static const char base64_chars[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; - -size_t calcDecodeLength(const char *b64input) { //Calculates the length of a decoded string - size_t len = strlen(b64input), - padding = 0; - - if (b64input[len - 1] == '=' && b64input[len - 2] == '=') //last two chars are = - padding = 2; - else if (b64input[len - 1] == '=') //last char is = - padding = 1; - - return (len * 3) / 4 - padding; -} - -int openssl_base64_encode(const unsigned char *buffer, size_t length, char **b64text) { //Encodes a binary safe base 64 string - BIO *bio, *b64; - BUF_MEM *bufferPtr; - - b64 = BIO_new(BIO_f_base64()); - bio = BIO_new(BIO_s_mem()); - bio = BIO_push(b64, bio); - - BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); //Ignore newlines - write everything in one line - BIO_set_close(bio, BIO_CLOSE); - BIO_write(bio, buffer, length); - BIO_flush(bio); - BIO_get_mem_ptr(bio, &bufferPtr); - - *b64text = (char *) g_malloc0((*bufferPtr).length + 1); - memcpy(*b64text, (*bufferPtr).data, (*bufferPtr).length); - - BIO_free_all(bio); - - return (0); //success -} - -int openssl_base64_decode(const char *b64message, unsigned char **buffer, size_t *length) { //Decodes a base64 encoded string - BIO *bio = NULL, *b64 = NULL; - int decodeLen = 0; - - if (strspn(b64message, base64_chars) != strlen(b64message)) - return -1; - - decodeLen = calcDecodeLength(b64message); - - if (decodeLen == 0) - return -1; - - *buffer = (unsigned char *) malloc(decodeLen + 1); - (*buffer)[decodeLen] = '\0'; - - bio = BIO_new_mem_buf(b64message, -1); - b64 = BIO_new(BIO_f_base64()); - bio = BIO_push(b64, bio); - - BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); //Do not use newlines to flush buffer - *length = BIO_read(bio, *buffer, strlen(b64message)); - BIO_free_all(bio); - - if (*length == decodeLen) { - return 0; - } else { - *length = 0; - free(*buffer); - return -1; - } -} diff --git a/plugins/fishlim/base64.h b/plugins/fishlim/base64.h deleted file mode 100644 index e0d83844..00000000 --- a/plugins/fishlim/base64.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - - MIT License - - Copyright (c) 2013 Barry Steyn - Copyright (c) 2019 - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - -*/ - -#ifndef BASE64_H -#define BASE64_H - -#include - -int openssl_base64_encode(const unsigned char *buffer, size_t length, char **b64text); -int openssl_base64_decode(const char *b64message, unsigned char **buffer, size_t *length); - -#endif //BASE64_H diff --git a/plugins/fishlim/fish.c b/plugins/fishlim/fish.c index a552b67f..9301d5d5 100644 --- a/plugins/fishlim/fish.c +++ b/plugins/fishlim/fish.c @@ -36,11 +36,11 @@ #include #include "keystore.h" -#include "base64.h" #include "fish.h" #define IB 64 -static const char fish_base64[64] = "./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; +static const char fish_base64[] = "./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; +static const char base64_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; static const signed char fish_unbase64[256] = { IB,IB,IB,IB,IB,IB,IB,IB, IB,IB,IB,IB,IB,IB,IB,IB, IB,IB,IB,IB,IB,IB,IB,IB, IB,IB,IB,IB,IB,IB,IB,IB, @@ -316,7 +316,7 @@ char *fish_encrypt(const char *key, size_t keylen, const char *message, size_t m switch (mode) { case FISH_CBC_MODE: - openssl_base64_encode((const unsigned char *) ciphertext, ciphertext_len, &b64); + b64 = g_base64_encode((const unsigned char *) ciphertext, ciphertext_len); break; case FISH_ECB_MODE: @@ -354,8 +354,9 @@ char *fish_decrypt(const char *key, size_t keylen, const char *data, enum fish_m switch (mode) { case FISH_CBC_MODE: - if (openssl_base64_decode(data, (unsigned char **) &ciphertext, &ciphertext_len) != 0) + if (strspn(data, base64_chars) != strlen(data)) return NULL; + ciphertext = (char *) g_base64_decode(data, &ciphertext_len); break; case FISH_ECB_MODE: diff --git a/plugins/fishlim/fishlim.vcxproj b/plugins/fishlim/fishlim.vcxproj index 9fc2e928..43ae1df9 100644 --- a/plugins/fishlim/fishlim.vcxproj +++ b/plugins/fishlim/fishlim.vcxproj @@ -54,7 +54,6 @@ - @@ -62,7 +61,6 @@ - diff --git a/plugins/fishlim/fishlim.vcxproj.filters b/plugins/fishlim/fishlim.vcxproj.filters index 65053087..09649ec9 100644 --- a/plugins/fishlim/fishlim.vcxproj.filters +++ b/plugins/fishlim/fishlim.vcxproj.filters @@ -26,9 +26,6 @@ Header Files - - Header Files - Header Files @@ -46,9 +43,6 @@ Source Files - - Source Files - Source Files diff --git a/plugins/fishlim/meson.build b/plugins/fishlim/meson.build index 179dc90e..894923aa 100644 --- a/plugins/fishlim/meson.build +++ b/plugins/fishlim/meson.build @@ -4,7 +4,6 @@ endif fishlim_sources = [ 'dh1080.c', - 'base64.c', 'fish.c', 'irc.c', 'keystore.c',