-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7a5d73
commit af42b53
Showing
37 changed files
with
128 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,4 @@ _backup/ | |
*.#* | ||
*.bin | ||
*.log | ||
tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* SSL symbols dynamic loader | ||
* | ||
* (c) Philippe, [email protected] | ||
* | ||
* 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 3 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, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#ifndef SSLSHIM_H | ||
#define SSLSHIM_H | ||
|
||
// this must be include after various openssl includes | ||
|
||
#if OPENSSL_VERSION_NUMBER < 0x10100000 | ||
int RSA_set0_key(RSA* r, BIGNUM* n, BIGNUM* e, BIGNUM* d); | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* SSL symboles dynamic loader | ||
* SSL symbols dynamic loader | ||
* | ||
* (c) Philippe, [email protected] | ||
* | ||
|
@@ -25,17 +25,84 @@ | |
#include <dlfcn.h> | ||
#endif | ||
|
||
#ifdef __BORLANDC__ | ||
#pragma warn -8081 | ||
#endif | ||
|
||
#include "openssl/ssl.h" | ||
#include "openssl/err.h" | ||
#include <openssl/rand.h> | ||
#include <openssl/rsa.h> | ||
#include <openssl/engine.h> | ||
#include <openssl/aes.h> | ||
#include <openssl/bio.h> | ||
#include "sslshim.h" | ||
|
||
static void *SSLhandle = NULL; | ||
static void *CRYPThandle = NULL; | ||
|
||
#define P0() void | ||
#define P1(t1, p1) t1 p1 | ||
#define P2(t1, p1, t2, p2) t1 p1, t2 p2 | ||
#define P3(t1, p1, t2, p2, t3, p3) t1 p1, t2 p2, t3 p3 | ||
#define P4(t1, p1, t2, p2, t3, p3, t4, p4) t1 p1, t2 p2, t3 p3, t4 p4 | ||
#define P5(t1, p1, t2, p2, t3, p3, t4, p4, t5, p5) t1 p1, t2 p2, t3 p3, t4 p4, t5 p5 | ||
#define P6(t1, p1, t2, p2, t3, p3, t4, p4, t5, p5, t6, p6) t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6 | ||
#define V0() | ||
#define V1(t1, p1) p1 | ||
#define V2(t1, p1, t2, p2) p1, p2 | ||
#define V3(t1, p1, t2, p2, t3, p3) p1, p2, p3 | ||
#define V4(t1, p1, t2, p2, t3, p3, t4, p4) p1, p2, p3, p4 | ||
#define V5(t1, p1, t2, p2, t3, p3, t4, p4, t5, p5) p1, p2, p3, p4, p5 | ||
#define V6(t1, p1, t2, p2, t3, p3, t4, p4, t5, p5, t6, p6) p1, p2, p3, p4, p5, p6 | ||
|
||
#define P(n, ...) P##n(__VA_ARGS__) | ||
#define V(n, ...) V##n(__VA_ARGS__) | ||
|
||
#ifndef LINKALL | ||
|
||
#define SYMDECL(fn, ret, n, ...) \ | ||
static ret (*dlsym_##fn)(P(n,__VA_ARGS__)); \ | ||
ret fn(P(n,__VA_ARGS__)) { \ | ||
return (*dlsym_##fn)(V(n,__VA_ARGS__)); \ | ||
} | ||
|
||
#define SYMSHIMDECL(fn, ret, n, ...) \ | ||
static ret (*dlsym_##fn)(P(n,__VA_ARGS__)); \ | ||
ret fn(P(n,__VA_ARGS__)) { \ | ||
if (dlsym_##fn) \ | ||
return (*dlsym_##fn)(V(n,__VA_ARGS__)); \ | ||
else \ | ||
return (shim_##fn)(V(n,__VA_ARGS__)); \ | ||
} | ||
|
||
#else | ||
|
||
#define SYMDECL(fn, ret, n, ...) | ||
|
||
#define SYMSHIMDECL(fn, ret, n, ...) \ | ||
ret fn(P(n,__VA_ARGS__)) { \ | ||
return (shim_##fn)(V(n,__VA_ARGS__)); \ | ||
} | ||
|
||
#endif | ||
|
||
/* | ||
MNNFFPPS: major minor fix patch status | ||
0x101ffpps = 1.1. fix->ff patch->pp status->s | ||
*/ | ||
|
||
// create shim functions | ||
#if OPENSSL_VERSION_NUMBER < 0x10100000 | ||
static int shim_RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d) { | ||
r->n = n; r->e = e; r->d = d; | ||
return 1; | ||
} | ||
SYMSHIMDECL(RSA_set0_key, int, 4, RSA*, r, BIGNUM*, n, BIGNUM*, e, BIGNUM*, d); | ||
#else | ||
SYMDECL(RSA_set0_key, int, 4, RSA*, r, BIGNUM*, n, BIGNUM*, e, BIGNUM*, d); | ||
#endif | ||
|
||
#ifndef LINKALL | ||
|
||
#if WIN | ||
|
@@ -65,46 +132,19 @@ static char *LIBCRYPTO[] = { | |
"libcrypto.so.1.0.0", NULL }; | ||
#endif | ||
|
||
#define P0() void | ||
#define P1(t1, p1) t1 p1 | ||
#define P2(t1, p1, t2, p2) t1 p1, t2 p2 | ||
#define P3(t1, p1, t2, p2, t3, p3) t1 p1, t2 p2, t3 p3 | ||
#define P4(t1, p1, t2, p2, t3, p3, t4, p4) t1 p1, t2 p2, t3 p3, t4 p4 | ||
#define P5(t1, p1, t2, p2, t3, p3, t4, p4, t5, p5) t1 p1, t2 p2, t3 p3, t4 p4, t5 p5 | ||
#define P6(t1, p1, t2, p2, t3, p3, t4, p4, t5, p5, t6, p6) t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6 | ||
#define V0() | ||
#define V1(t1, p1) p1 | ||
#define V2(t1, p1, t2, p2) p1, p2 | ||
#define V3(t1, p1, t2, p2, t3, p3) p1, p2, p3 | ||
#define V4(t1, p1, t2, p2, t3, p3, t4, p4) p1, p2, p3, p4 | ||
#define V5(t1, p1, t2, p2, t3, p3, t4, p4, t5, p5) p1, p2, p3, p4, p5 | ||
#define V6(t1, p1, t2, p2, t3, p3, t4, p4, t5, p5, t6, p6) p1, p2, p3, p4, p5, p6 | ||
|
||
#define P(n, ...) P##n(__VA_ARGS__) | ||
#define V(n, ...) V##n(__VA_ARGS__) | ||
|
||
#define SYM(fn) dlsym_##fn | ||
#define SYMDECL(fn, ret, n, ...) \ | ||
static ret (*dlsym_##fn)(P(n,__VA_ARGS__)); \ | ||
ret fn(P(n,__VA_ARGS__)) { \ | ||
return (*dlsym_##fn)(V(n,__VA_ARGS__)); \ | ||
} | ||
|
||
#define SYMDECLVOID(fn, n, ...) \ | ||
static void (*dlsym_##fn)(P(n,__VA_ARGS__)); \ | ||
void fn(P(n,__VA_ARGS__)) { \ | ||
(*dlsym_##fn)(V(n,__VA_ARGS__)); \ | ||
} | ||
|
||
#if 0 | ||
#define SYMLOAD(h, fn) { \ | ||
dlsym_##fn = dlsym(h, #fn); \ | ||
printf("%s %p\n", #fn, dlsym_##fn); \ | ||
#define SYMLOAD(h, fn) { \ | ||
dlsym_##fn = dlsym(h, #fn); \ | ||
printf("%s %p\n", #fn, dlsym_##fn); \ | ||
} | ||
#else | ||
#define SYMLOAD(h, fn) dlsym_##fn = dlsym(h, #fn) | ||
#endif | ||
|
||
#define SHIMSET(fn) if (!SYM(fn)) SYM(fn) = &(shim_##fn) | ||
|
||
SYMDECL(SSL_read, int, 3, SSL*, s, void*, buf, int, len); | ||
SYMDECL(SSL_write, int, 3, SSL*, s, const void*, buf, int, len); | ||
SYMDECL(SSLv23_client_method, const SSL_METHOD*, 0); | ||
|
@@ -124,8 +164,8 @@ SYMDECL(SSL_get_error, int, 2, const SSL*, s, int, ret_code); | |
SYMDECL(SSL_ctrl, long, 4, SSL*, ssl, int, cmd, long, larg, void*, parg); | ||
SYMDECL(SSL_pending, int, 1, const SSL*, s); | ||
|
||
SYMDECLVOID(SSL_free, 1, SSL*, s); | ||
SYMDECLVOID(SSL_CTX_free, 1, SSL_CTX *, ctx); | ||
SYMDECL(SSL_free, void, 1, SSL*, s); | ||
SYMDECL(SSL_CTX_free, void, 1, SSL_CTX *, ctx); | ||
|
||
SYMDECL(ERR_get_error, unsigned long, 0); | ||
SYMDECL(SHA512_Init, int, 1, SHA512_CTX*, c); | ||
|
@@ -144,11 +184,11 @@ SYMDECL(BIO_new_mem_buf, BIO*, 2, const void*, buf, int, len); | |
SYMDECL(BIO_free, int, 1, BIO*, a); | ||
SYMDECL(PEM_read_bio_RSAPrivateKey, RSA *, 4, BIO*, bp, RSA**, x, pem_password_cb*, cb, void*, u); | ||
|
||
SYMDECLVOID(AES_cbc_encrypt, 6, const unsigned char*, in, unsigned char*, out, size_t, length, const AES_KEY*, key, unsigned char*, ivec, const int, enc); | ||
SYMDECLVOID(RAND_seed, 2, const void*, buf, int, num); | ||
SYMDECLVOID(RSA_free, 1, RSA*, r); | ||
SYMDECLVOID(ERR_clear_error, 0); | ||
SYMDECLVOID(ERR_remove_state, 1, unsigned long, pid); | ||
SYMDECL(AES_cbc_encrypt, void, 6, const unsigned char*, in, unsigned char*, out, size_t, length, const AES_KEY*, key, unsigned char*, ivec, const int, enc); | ||
SYMDECL(RAND_seed, void, 2, const void*, buf, int, num); | ||
SYMDECL(RSA_free, void, 1, RSA*, r); | ||
SYMDECL(ERR_clear_error, void, 0); | ||
SYMDECL(ERR_remove_state, void, 1, unsigned long, pid); | ||
|
||
#if WIN | ||
static void *dlopen(const char *filename, int flag) { | ||
|
@@ -222,6 +262,7 @@ bool load_ssl_symbols(void) { | |
SYMLOAD(CRYPThandle, RSA_public_decrypt); | ||
SYMLOAD(CRYPThandle, RSA_private_decrypt); | ||
SYMLOAD(CRYPThandle, RSA_free); | ||
SYMLOAD(CRYPThandle, RSA_set0_key); | ||
SYMLOAD(CRYPThandle, BN_bin2bn); | ||
SYMLOAD(CRYPThandle, AES_set_decrypt_key); | ||
SYMLOAD(CRYPThandle, AES_cbc_encrypt); | ||
|
@@ -233,6 +274,9 @@ bool load_ssl_symbols(void) { | |
if (!SYM(SSLv23_client_method)) SYM(SSLv23_client_method) = SYM(TLS_client_method); | ||
if (!SYM(SSL_library_init)) SYM(SSL_library_init) = λ | ||
|
||
// manage mandatory new functions | ||
SHIMSET(RSA_set0_key); | ||
|
||
return true; | ||
} | ||
|
||
|