mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-22 23:59:41 +08:00
wolfSSL support added
This commit is contained in:
1 parent
3a66c0a4c0
commit
f173f8860d
24 files changed
+499
-207
No files matched your search
+12
-10
@@ -5,7 +5,6 @@
|
||||
please read License Agreement
|
||||
|
||||
*/
|
||||
#include "libs/blake2.h"
|
||||
#include "mdhash.h"
|
||||
#include <string.h>
|
||||
|
||||
@@ -52,7 +51,7 @@ unsigned char * ntpwdhash (unsigned char *szHash, const unsigned char *szPasswor
|
||||
}
|
||||
|
||||
/* Encrypt Unicode password to a 16-byte MD4 hash */
|
||||
ctx = mdh_init(MDH_MD4);
|
||||
ctx = mdh_init(MDH_MD4, 16);
|
||||
if(!ctx) return NULL;
|
||||
mdh_update(ctx, szUnicodePass, (nPasswordLen<<1));
|
||||
if(!mdh_final(ctx, szUnicodePass, &len)) {
|
||||
@@ -89,7 +88,7 @@ unsigned char * mycrypt(const unsigned char *pw, const unsigned char *salt, unsi
|
||||
sl = (int)(ep - sp);
|
||||
magic = (unsigned char *)"$1$";
|
||||
|
||||
ctx = mdh_init(MDH_MD5);
|
||||
ctx = mdh_init(MDH_MD5, 16);
|
||||
if(!ctx) {
|
||||
*passwd = 0;
|
||||
return NULL;
|
||||
@@ -105,7 +104,7 @@ unsigned char * mycrypt(const unsigned char *pw, const unsigned char *salt, unsi
|
||||
mdh_update(ctx, sp, (unsigned int)sl);
|
||||
|
||||
/* Then just as many unsigned characters of the MD5(pw,salt,pw) */
|
||||
ctx1 = mdh_init(MDH_MD5);
|
||||
ctx1 = mdh_init(MDH_MD5, 16);
|
||||
if(!ctx1) {
|
||||
mdh_free(ctx);
|
||||
*passwd = 0;
|
||||
@@ -139,7 +138,7 @@ unsigned char * mycrypt(const unsigned char *pw, const unsigned char *salt, unsi
|
||||
*/
|
||||
for(i=0;i<1000;i++) {
|
||||
mdh_free(ctx1);
|
||||
ctx1 = mdh_init(MDH_MD5);
|
||||
ctx1 = mdh_init(MDH_MD5, 16);
|
||||
if(!ctx1) { *passwd = 0; return NULL; }
|
||||
if(i & 1)
|
||||
mdh_update(ctx1, pw, (unsigned int)strlen((char *)pw));
|
||||
@@ -167,14 +166,17 @@ unsigned char * mycrypt(const unsigned char *pw, const unsigned char *salt, unsi
|
||||
sl = (int)(ep - sp);
|
||||
magic = (unsigned char *)"$3$";
|
||||
{
|
||||
blake2b_state S;
|
||||
if(blake2b_init(&S, MD5_SIZE) != 0 ||
|
||||
blake2b_update(&S, pw, strlen((char *)pw) + 1) != 0 ||
|
||||
blake2b_update(&S, sp, sl) != 0 ||
|
||||
blake2b_final(&S, final, MD5_SIZE) != 0) {
|
||||
mdh_ctx *bctx = mdh_init(MDH_BLAKE2, MD5_SIZE);
|
||||
unsigned int blen = MD5_SIZE;
|
||||
if(!bctx ||
|
||||
!mdh_update(bctx, pw, (unsigned int)(strlen((char *)pw) + 1)) ||
|
||||
!mdh_update(bctx, sp, (unsigned int)sl) ||
|
||||
!mdh_final(bctx, final, &blen)) {
|
||||
mdh_free(bctx);
|
||||
*passwd = 0;
|
||||
return NULL;
|
||||
}
|
||||
mdh_free(bctx);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
+4
-4
@@ -164,8 +164,8 @@ md4$(OBJSUFFICS): libs/md4.c libs/md4.h
|
||||
md5$(OBJSUFFICS): libs/md5.c libs/md5.h
|
||||
$(CC) $(COUT)md5$(OBJSUFFICS) $(CFLAGS) libs/md5.c
|
||||
|
||||
$(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS): blake2$(OBJSUFFICS) 3proxy_cryptmain$(OBJSUFFICS) base64$(OBJSUFFICS) mdhash$(OBJSUFFICS) $(BUNDLED_HASH_OBJS)
|
||||
$(LN) $(LNOUT)$(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS) $(LDFLAGS) blake2$(OBJSUFFICS) base64$(OBJSUFFICS) mdhash$(OBJSUFFICS) $(BUNDLED_HASH_OBJS) 3proxy_cryptmain$(OBJSUFFICS) $(LIBS)
|
||||
$(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS): $(BUNDLED_HASH_OBJS) 3proxy_cryptmain$(OBJSUFFICS) base64$(OBJSUFFICS) mdhash$(OBJSUFFICS)
|
||||
$(LN) $(LNOUT)$(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS) $(LDFLAGS) $(BUNDLED_HASH_OBJS) base64$(OBJSUFFICS) mdhash$(OBJSUFFICS) 3proxy_cryptmain$(OBJSUFFICS) $(LIBS)
|
||||
|
||||
stringtable$(OBJSUFFICS): stringtable.c
|
||||
$(CC) $(COUT)stringtable$(OBJSUFFICS) $(CFLAGS) stringtable.c
|
||||
@@ -179,6 +179,6 @@ ssl$(OBJSUFFICS): ssl.c structures.h proxy.h ssl.h
|
||||
pcre$(OBJSUFFICS): pcre.c structures.h
|
||||
$(CC) $(COUT)pcre$(OBJSUFFICS) $(CFLAGS) $(DEFINEOPTION)WITH_PCRE pcre.c
|
||||
|
||||
$(BUILDDIR)3proxy$(EXESUFFICS): 3proxy$(OBJSUFFICS) mainfunc$(OBJSUFFICS) srvproxy$(OBJSUFFICS) srvpop3p$(OBJSUFFICS) srvsmtpp$(OBJSUFFICS) srvftppr$(OBJSUFFICS) srvsocks$(OBJSUFFICS) srvtcppm$(OBJSUFFICS) srvtlspr$(OBJSUFFICS) srvauto$(OBJSUFFICS) srvudppm$(OBJSUFFICS) sockmap$(OBJSUFFICS) udpsockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) auth$(OBJSUFFICS) acl$(OBJSUFFICS) limiter$(OBJSUFFICS) redirect$(OBJSUFFICS) authradius$(OBJSUFFICS) hash$(OBJSUFFICS) hashtables$(OBJSUFFICS) resolve$(OBJSUFFICS) sql$(OBJSUFFICS) conf$(OBJSUFFICS) log$(OBJSUFFICS) datatypes$(OBJSUFFICS) blake2$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) srvwebadmin$(OBJSUFFICS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) mdhash$(OBJSUFFICS) $(BUNDLED_HASH_OBJS) $(SSL_OBJS) $(PCRE_OBJS) $(COMPATLIBS) $(VERSIONDEP)
|
||||
$(LN) $(LNOUT)$(BUILDDIR)3proxy$(EXESUFFICS) $(LDFLAGS) $(VERFILE) 3proxy$(OBJSUFFICS) mainfunc$(OBJSUFFICS) auth$(OBJSUFFICS) acl$(OBJSUFFICS) limiter$(OBJSUFFICS) redirect$(OBJSUFFICS) authradius$(OBJSUFFICS) hash$(OBJSUFFICS) hashtables$(OBJSUFFICS) resolve$(OBJSUFFICS) sql$(OBJSUFFICS) conf$(OBJSUFFICS) datatypes$(OBJSUFFICS) srvauto$(OBJSUFFICS) srvproxy$(OBJSUFFICS) srvpop3p$(OBJSUFFICS) srvsmtpp$(OBJSUFFICS) srvftppr$(OBJSUFFICS) srvsocks$(OBJSUFFICS) srvtcppm$(OBJSUFFICS) srvtlspr$(OBJSUFFICS) srvudppm$(OBJSUFFICS) sockmap$(OBJSUFFICS) udpsockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) blake2$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) srvwebadmin$(OBJSUFFICS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) mdhash$(OBJSUFFICS) $(BUNDLED_HASH_OBJS) $(SSL_OBJS) $(PCRE_OBJS) $(COMPATLIBS) $(LIBS) $(PCRE_LIBS)
|
||||
$(BUILDDIR)3proxy$(EXESUFFICS): 3proxy$(OBJSUFFICS) mainfunc$(OBJSUFFICS) srvproxy$(OBJSUFFICS) srvpop3p$(OBJSUFFICS) srvsmtpp$(OBJSUFFICS) srvftppr$(OBJSUFFICS) srvsocks$(OBJSUFFICS) srvtcppm$(OBJSUFFICS) srvtlspr$(OBJSUFFICS) srvauto$(OBJSUFFICS) srvudppm$(OBJSUFFICS) sockmap$(OBJSUFFICS) udpsockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) auth$(OBJSUFFICS) acl$(OBJSUFFICS) limiter$(OBJSUFFICS) redirect$(OBJSUFFICS) authradius$(OBJSUFFICS) hash$(OBJSUFFICS) hashtables$(OBJSUFFICS) resolve$(OBJSUFFICS) sql$(OBJSUFFICS) conf$(OBJSUFFICS) log$(OBJSUFFICS) datatypes$(OBJSUFFICS) $(BUNDLED_HASH_OBJS) 3proxy_crypt$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) srvwebadmin$(OBJSUFFICS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) mdhash$(OBJSUFFICS) $(SSL_OBJS) $(PCRE_OBJS) $(COMPATLIBS) $(VERSIONDEP)
|
||||
$(LN) $(LNOUT)$(BUILDDIR)3proxy$(EXESUFFICS) $(LDFLAGS) $(VERFILE) 3proxy$(OBJSUFFICS) mainfunc$(OBJSUFFICS) auth$(OBJSUFFICS) acl$(OBJSUFFICS) limiter$(OBJSUFFICS) redirect$(OBJSUFFICS) authradius$(OBJSUFFICS) hash$(OBJSUFFICS) hashtables$(OBJSUFFICS) resolve$(OBJSUFFICS) sql$(OBJSUFFICS) conf$(OBJSUFFICS) datatypes$(OBJSUFFICS) srvauto$(OBJSUFFICS) srvproxy$(OBJSUFFICS) srvpop3p$(OBJSUFFICS) srvsmtpp$(OBJSUFFICS) srvftppr$(OBJSUFFICS) srvsocks$(OBJSUFFICS) srvtcppm$(OBJSUFFICS) srvtlspr$(OBJSUFFICS) srvudppm$(OBJSUFFICS) sockmap$(OBJSUFFICS) udpsockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) $(BUNDLED_HASH_OBJS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) srvwebadmin$(OBJSUFFICS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) mdhash$(OBJSUFFICS) $(SSL_OBJS) $(PCRE_OBJS) $(COMPATLIBS) $(LIBS) $(PCRE_LIBS)
|
||||
|
||||
+9
-5
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
#include "proxy.h"
|
||||
#include "libs/blake2.h"
|
||||
#include "mdhash.h"
|
||||
|
||||
void initbandlims(struct clientparam *param);
|
||||
|
||||
@@ -231,13 +231,17 @@ int strongauth(struct clientparam * param){
|
||||
if((unsigned)pwlen < pwl_table.recsize) {
|
||||
if(!strncmp(pass + 1, (char *)param->password, pwl_table.recsize - 1)) return 0;
|
||||
} else {
|
||||
blake2b_state S;
|
||||
mdh_ctx *bctx;
|
||||
unsigned hashsz;
|
||||
unsigned int blen;
|
||||
hashsz = pwl_table.recsize - 1 < 64 ? pwl_table.recsize - 1 : 64;
|
||||
memset(buf, 0, pwl_table.recsize - 1);
|
||||
blake2b_init(&S, hashsz);
|
||||
blake2b_update(&S, param->password, pwlen + 1);
|
||||
blake2b_final(&S, buf, hashsz);
|
||||
bctx = mdh_init(MDH_BLAKE2, hashsz);
|
||||
if(!bctx) return 6;
|
||||
mdh_update(bctx, param->password, pwlen + 1);
|
||||
blen = hashsz;
|
||||
mdh_final(bctx, buf, &blen);
|
||||
mdh_free(bctx);
|
||||
if(!memcmp(pass + 1, buf, pwl_table.recsize - 1)) return 0;
|
||||
}
|
||||
return 6;
|
||||
|
||||
+1
-1
@@ -188,7 +188,7 @@ char *strNcpy(char *dest, const char *src, int n)
|
||||
void md5_calc(unsigned char *output, unsigned char *input,
|
||||
unsigned int inlen)
|
||||
{
|
||||
mdh_ctx *ctx = mdh_init(MDH_MD5);
|
||||
mdh_ctx *ctx = mdh_init(MDH_MD5, 16);
|
||||
unsigned int len = 16;
|
||||
if(!ctx) return;
|
||||
mdh_update(ctx, input, inlen);
|
||||
|
||||
+9
-5
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
#include "proxy.h"
|
||||
#include "libs/blake2.h"
|
||||
#include "mdhash.h"
|
||||
#ifdef WITH_SSL
|
||||
void ssl_install(void);
|
||||
#endif
|
||||
@@ -543,13 +543,17 @@ static int h_users(int argc, unsigned char **argv){
|
||||
l = strlen(pw[1]);
|
||||
if(l > 255) l = 255;
|
||||
if((unsigned)l >= pwl_table.recsize) {
|
||||
blake2b_state S;
|
||||
mdh_ctx *bctx;
|
||||
unsigned hashsz;
|
||||
unsigned int blen;
|
||||
if(*pass != CL) continue;
|
||||
hashsz = pwl_table.recsize - 1 < 64 ? pwl_table.recsize - 1 : 64;
|
||||
blake2b_init(&S, hashsz);
|
||||
blake2b_update(&S, pw[1], l + 1);
|
||||
blake2b_final(&S, pass+1, hashsz);
|
||||
bctx = mdh_init(MDH_BLAKE2, hashsz);
|
||||
if(!bctx) continue;
|
||||
mdh_update(bctx, pw[1], l + 1);
|
||||
blen = hashsz;
|
||||
mdh_final(bctx, (unsigned char *)pass+1, &blen);
|
||||
mdh_free(bctx);
|
||||
} else {
|
||||
memcpy(pass + 1, pw[1], l);
|
||||
}
|
||||
|
||||
+32
-25
@@ -1,18 +1,21 @@
|
||||
#include "proxy.h"
|
||||
#include "libs/blake2.h"
|
||||
#include "mdhash.h"
|
||||
|
||||
|
||||
static void char_index2hash(const struct hashtable *ht, void *index, uint8_t *hash){
|
||||
blake2b_state S;
|
||||
int len;
|
||||
unsigned int blen;
|
||||
|
||||
len = strlen((const char*)index);
|
||||
memset(hash, 0, ht->hash_size);
|
||||
if(len <= ht->hash_size) memcpy(hash, index, len);
|
||||
else {
|
||||
blake2b_init(&S, ht->hash_size);
|
||||
blake2b_update(&S, index, strlen((const char*)index) + 1);
|
||||
blake2b_final(&S, hash, ht->hash_size);
|
||||
mdh_ctx *bctx = mdh_init(MDH_BLAKE2, ht->hash_size);
|
||||
if(!bctx) return;
|
||||
mdh_update(bctx, index, (unsigned int)(strlen((const char*)index) + 1));
|
||||
blen = ht->hash_size;
|
||||
mdh_final(bctx, hash, &blen);
|
||||
mdh_free(bctx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +26,6 @@ static void param2hash_add(const struct hashtable *ht, void *index, uint8_t *has
|
||||
}
|
||||
|
||||
void param2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
|
||||
blake2b_state S;
|
||||
struct clientparam *param = (struct clientparam *)index;
|
||||
unsigned type = param->srv->authcachetype;
|
||||
int len = 0, oplen = 0, acllen = 0, ulen = 0, plen = 0, hlen = 0, a1len = 0, a2len = 0, a3len = 0, p1len=0, p2len = 0;
|
||||
@@ -55,31 +57,36 @@ void param2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
|
||||
if((type & 2048)){ memcpy(hash + offset, SAPORT(¶m->srv->intsa), p2len); offset += 2; }
|
||||
}
|
||||
else {
|
||||
blake2b_init(&S, ht->hash_size);
|
||||
if((type & 2) && param->username)blake2b_update(&S, param->username, ulen);
|
||||
if((type & 4) && param->password)blake2b_update(&S, param->password, plen);
|
||||
if((type & 1) && !(type & 8))blake2b_update(&S, SAADDR(¶m->sincr), a1len);
|
||||
if((type & 16))blake2b_update(&S, ¶m->srv->acl, acllen);
|
||||
if((type & 64))blake2b_update(&S, SAADDR(¶m->req), a2len);
|
||||
if((type & 128))blake2b_update(&S, SAPORT(¶m->req), 2);
|
||||
if((type & 256) && param->hostname)blake2b_update(&S, param->hostname, hlen);
|
||||
if((type & 512))blake2b_update(&S, ¶m->operation, sizeof(param->operation));
|
||||
if((type & 1024))blake2b_update(&S, SAADDR(¶m->srv->intsa), a3len);
|
||||
if((type & 2048))blake2b_update(&S, SAPORT(¶m->srv->intsa), 2);
|
||||
blake2b_final(&S, hash, ht->hash_size);
|
||||
mdh_ctx *bctx = mdh_init(MDH_BLAKE2, ht->hash_size);
|
||||
unsigned int blen = ht->hash_size;
|
||||
if(!bctx) { memcpy(param->hash, hash, ht->hash_size); return; }
|
||||
if((type & 2) && param->username)mdh_update(bctx, param->username, ulen);
|
||||
if((type & 4) && param->password)mdh_update(bctx, param->password, plen);
|
||||
if((type & 1) && !(type & 8))mdh_update(bctx, SAADDR(¶m->sincr), a1len);
|
||||
if((type & 16))mdh_update(bctx, ¶m->srv->acl, acllen);
|
||||
if((type & 64))mdh_update(bctx, SAADDR(¶m->req), a2len);
|
||||
if((type & 128))mdh_update(bctx, SAPORT(¶m->req), 2);
|
||||
if((type & 256) && param->hostname)mdh_update(bctx, param->hostname, hlen);
|
||||
if((type & 512))mdh_update(bctx, ¶m->operation, sizeof(param->operation));
|
||||
if((type & 1024))mdh_update(bctx, SAADDR(¶m->srv->intsa), a3len);
|
||||
if((type & 2048))mdh_update(bctx, SAPORT(¶m->srv->intsa), 2);
|
||||
mdh_final(bctx, hash, &blen);
|
||||
mdh_free(bctx);
|
||||
}
|
||||
memcpy(param->hash, hash, ht->hash_size);
|
||||
}
|
||||
|
||||
static void udpparam2hash(const struct hashtable *ht, void *index, uint8_t *hash){
|
||||
struct clientparam *param = (struct clientparam *)index;
|
||||
blake2b_state S;
|
||||
blake2b_init(&S, ht->hash_size);
|
||||
blake2b_update(&S, SAADDR(¶m->srv->intsa), SAADDRLEN(¶m->srv->intsa));
|
||||
blake2b_update(&S, SAPORT(¶m->srv->intsa), 2);
|
||||
blake2b_update(&S, SAADDR(¶m->sincr), SAADDRLEN(¶m->sincr));
|
||||
blake2b_update(&S, SAPORT(¶m->sincr), 2);
|
||||
blake2b_final(&S, hash, ht->hash_size);
|
||||
mdh_ctx *bctx = mdh_init(MDH_BLAKE2, ht->hash_size);
|
||||
unsigned int blen = ht->hash_size;
|
||||
if(!bctx) return;
|
||||
mdh_update(bctx, SAADDR(¶m->srv->intsa), SAADDRLEN(¶m->srv->intsa));
|
||||
mdh_update(bctx, SAPORT(¶m->srv->intsa), 2);
|
||||
mdh_update(bctx, SAADDR(¶m->sincr), SAADDRLEN(¶m->sincr));
|
||||
mdh_update(bctx, SAPORT(¶m->sincr), 2);
|
||||
mdh_final(bctx, hash, &blen);
|
||||
mdh_free(bctx);
|
||||
}
|
||||
|
||||
struct hashtable dns_table = {char_index2hash, char_index2hash, 4, 32};
|
||||
|
||||
@@ -26,6 +26,11 @@
|
||||
#ifndef _MD4_H
|
||||
#define _MD4_H
|
||||
|
||||
#ifdef WITH_WOLFSSL
|
||||
#include <wolfssl/options.h>
|
||||
#include <wolfssl/openssl/md4.h>
|
||||
#else
|
||||
|
||||
#include <stddef.h> /* for size_t */
|
||||
|
||||
/* Any 32-bit or wider unsigned integer data type will do */
|
||||
@@ -44,4 +49,6 @@ extern void MD4_Init(MD4_CTX *ctx);
|
||||
extern void MD4_Update(MD4_CTX *ctx, const void *data, size_t size);
|
||||
extern void MD4_Final(unsigned char *result, MD4_CTX *ctx);
|
||||
|
||||
#endif /* !WITH_WOLFSSL */
|
||||
|
||||
#endif
|
||||
@@ -26,6 +26,11 @@
|
||||
#ifndef _MD5_H
|
||||
#define _MD5_H
|
||||
|
||||
#ifdef WITH_WOLFSSL
|
||||
#include <wolfssl/options.h>
|
||||
#include <wolfssl/openssl/md5.h>
|
||||
#else
|
||||
|
||||
/* Any 32-bit or wider unsigned integer data type will do */
|
||||
typedef unsigned int MD5_u32plus;
|
||||
|
||||
@@ -40,4 +45,6 @@ extern void MD5_Init(MD5_CTX *ctx);
|
||||
extern void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size);
|
||||
extern void MD5_Final(unsigned char *result, MD5_CTX *ctx);
|
||||
|
||||
#endif /* !WITH_WOLFSSL */
|
||||
|
||||
#endif
|
||||
+158
-85
@@ -4,129 +4,202 @@
|
||||
|
||||
please read License Agreement
|
||||
|
||||
MD4/MD5 hash implementation.
|
||||
- Windows: CryptoAPI (CAPI). Supports both CALG_MD4 and CALG_MD5.
|
||||
- Other platforms: bundled public-domain MD4/MD5 (Solar Designer, 2001).
|
||||
MD4/MD5/BLAKE2 hash implementation.
|
||||
- Windows (no wolfSSL): CryptoAPI (CAPI) for MD4/MD5; bundled BLAKE2.
|
||||
- wolfSSL: wolfCrypt for MD4/MD5 (OpenSSL compat) and BLAKE2 (native wc_*).
|
||||
- Other: bundled public-domain MD4/MD5 + bundled BLAKE2 reference.
|
||||
*/
|
||||
#include "mdhash.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
/* ----- BLAKE2 backend selection ----- */
|
||||
#ifdef WITH_WOLFSSL
|
||||
#include <wolfssl/options.h>
|
||||
#include <wolfssl/wolfcrypt/blake2.h>
|
||||
#define MDH_BLAKE2_BACKEND_WOLFSSL
|
||||
#else
|
||||
#include "libs/blake2.h"
|
||||
#endif
|
||||
|
||||
/* ----- MD4/MD5 backend selection ----- */
|
||||
#if defined(_WIN32) && !defined(WITH_WOLFSSL)
|
||||
#define MDH_MD_BACKEND_CAPI
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
|
||||
struct mdh_ctx {
|
||||
HCRYPTPROV hProv;
|
||||
HCRYPTHASH hHash;
|
||||
};
|
||||
|
||||
mdh_ctx *mdh_init(mdh_alg alg)
|
||||
{
|
||||
mdh_ctx *c;
|
||||
ALG_ID alg_id;
|
||||
|
||||
c = (mdh_ctx *)malloc(sizeof(mdh_ctx));
|
||||
if(!c) return NULL;
|
||||
c->hProv = 0;
|
||||
c->hHash = 0;
|
||||
|
||||
if(!CryptAcquireContext(&c->hProv, NULL, NULL, PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT)) {
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
alg_id = (alg == MDH_MD4) ? CALG_MD4 : CALG_MD5;
|
||||
if(!CryptCreateHash(c->hProv, alg_id, 0, 0, &c->hHash)) {
|
||||
CryptReleaseContext(c->hProv, 0);
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int mdh_update(mdh_ctx *c, const void *data, unsigned int len)
|
||||
{
|
||||
if(!c || !c->hHash) return 0;
|
||||
if(len == 0) return 1;
|
||||
return CryptHashData(c->hHash, (BYTE *)data, len, 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
int mdh_final(mdh_ctx *c, unsigned char *out, unsigned int *outlen)
|
||||
{
|
||||
DWORD l;
|
||||
BOOL ok;
|
||||
|
||||
if(!c || !c->hHash || !outlen) return 0;
|
||||
l = (DWORD)*outlen;
|
||||
ok = CryptGetHashParam(c->hHash, HP_HASHVAL, out, &l, 0);
|
||||
if(!ok) return 0;
|
||||
*outlen = (unsigned int)l;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void mdh_free(mdh_ctx *c)
|
||||
{
|
||||
if(!c) return;
|
||||
if(c->hHash) CryptDestroyHash(c->hHash);
|
||||
if(c->hProv) CryptReleaseContext(c->hProv, 0);
|
||||
free(c);
|
||||
}
|
||||
|
||||
#else /* !_WIN32 */
|
||||
|
||||
#else
|
||||
#include "libs/md4.h"
|
||||
#include "libs/md5.h"
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
struct mdh_ctx {
|
||||
int alg; /* MDH_MD4 or MDH_MD5 */
|
||||
mdh_alg alg;
|
||||
unsigned int outlen;
|
||||
#ifdef MDH_MD_BACKEND_CAPI
|
||||
HCRYPTPROV hProv;
|
||||
HCRYPTHASH hHash;
|
||||
#else
|
||||
union {
|
||||
MD4_CTX md4;
|
||||
MD5_CTX md5;
|
||||
} u;
|
||||
#endif
|
||||
#ifdef MDH_BLAKE2_BACKEND_WOLFSSL
|
||||
Blake2b blake2;
|
||||
#else
|
||||
blake2b_state blake2;
|
||||
#endif
|
||||
};
|
||||
|
||||
mdh_ctx *mdh_init(mdh_alg alg)
|
||||
mdh_ctx *mdh_init(mdh_alg alg, unsigned int outlen)
|
||||
{
|
||||
mdh_ctx *c = (mdh_ctx *)malloc(sizeof(mdh_ctx));
|
||||
if(!c) return NULL;
|
||||
memset(c, 0, sizeof(*c));
|
||||
c->alg = alg;
|
||||
if(alg == MDH_MD4)
|
||||
MD4_Init(&c->u.md4);
|
||||
else
|
||||
MD5_Init(&c->u.md5);
|
||||
c->outlen = outlen;
|
||||
|
||||
switch(alg) {
|
||||
case MDH_MD4:
|
||||
#ifdef MDH_MD_BACKEND_CAPI
|
||||
if(!CryptAcquireContext(&c->hProv, NULL, NULL, PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT)) {
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
if(!CryptCreateHash(c->hProv, CALG_MD4, 0, 0, &c->hHash)) {
|
||||
CryptReleaseContext(c->hProv, 0);
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
MD4_Init(&c->u.md4);
|
||||
#endif
|
||||
break;
|
||||
case MDH_MD5:
|
||||
#ifdef MDH_MD_BACKEND_CAPI
|
||||
if(!CryptAcquireContext(&c->hProv, NULL, NULL, PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT)) {
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
if(!CryptCreateHash(c->hProv, CALG_MD5, 0, 0, &c->hHash)) {
|
||||
CryptReleaseContext(c->hProv, 0);
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
MD5_Init(&c->u.md5);
|
||||
#endif
|
||||
break;
|
||||
case MDH_BLAKE2:
|
||||
if(!outlen || outlen > 64) {
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
#ifdef MDH_BLAKE2_BACKEND_WOLFSSL
|
||||
if(wc_InitBlake2b(&c->blake2, outlen) != 0) {
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
if(blake2b_init(&c->blake2, outlen) != 0) {
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int mdh_update(mdh_ctx *c, const void *data, unsigned int len)
|
||||
{
|
||||
if(!c) return 0;
|
||||
if(c->alg == MDH_MD4)
|
||||
MD4_Update(&c->u.md4, data, (size_t)len);
|
||||
else
|
||||
MD5_Update(&c->u.md5, data, (unsigned long)len);
|
||||
return 1;
|
||||
if(len == 0) return 1;
|
||||
switch(c->alg) {
|
||||
case MDH_MD4:
|
||||
#ifdef MDH_MD_BACKEND_CAPI
|
||||
return CryptHashData(c->hHash, (BYTE *)data, len, 0) ? 1 : 0;
|
||||
#else
|
||||
MD4_Update(&c->u.md4, data, (size_t)len);
|
||||
return 1;
|
||||
#endif
|
||||
case MDH_MD5:
|
||||
#ifdef MDH_MD_BACKEND_CAPI
|
||||
return CryptHashData(c->hHash, (BYTE *)data, len, 0) ? 1 : 0;
|
||||
#else
|
||||
MD5_Update(&c->u.md5, data, (unsigned long)len);
|
||||
return 1;
|
||||
#endif
|
||||
case MDH_BLAKE2:
|
||||
#ifdef MDH_BLAKE2_BACKEND_WOLFSSL
|
||||
return wc_Blake2bUpdate(&c->blake2, (const byte *)data, len) == 0;
|
||||
#else
|
||||
return blake2b_update(&c->blake2, data, len) == 0;
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mdh_final(mdh_ctx *c, unsigned char *out, unsigned int *outlen)
|
||||
{
|
||||
if(!c || !outlen) return 0;
|
||||
if(c->alg == MDH_MD4)
|
||||
MD4_Final(out, &c->u.md4);
|
||||
else
|
||||
MD5_Final(out, &c->u.md5);
|
||||
*outlen = 16;
|
||||
return 1;
|
||||
switch(c->alg) {
|
||||
case MDH_MD4:
|
||||
#ifdef MDH_MD_BACKEND_CAPI
|
||||
{
|
||||
DWORD l = (DWORD)*outlen;
|
||||
if(!CryptGetHashParam(c->hHash, HP_HASHVAL, out, &l, 0))
|
||||
return 0;
|
||||
*outlen = (unsigned int)l;
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
MD4_Final(out, &c->u.md4);
|
||||
*outlen = 16;
|
||||
return 1;
|
||||
#endif
|
||||
case MDH_MD5:
|
||||
#ifdef MDH_MD_BACKEND_CAPI
|
||||
{
|
||||
DWORD l = (DWORD)*outlen;
|
||||
if(!CryptGetHashParam(c->hHash, HP_HASHVAL, out, &l, 0))
|
||||
return 0;
|
||||
*outlen = (unsigned int)l;
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
MD5_Final(out, &c->u.md5);
|
||||
*outlen = 16;
|
||||
return 1;
|
||||
#endif
|
||||
case MDH_BLAKE2:
|
||||
if(*outlen < c->outlen) return 0;
|
||||
#ifdef MDH_BLAKE2_BACKEND_WOLFSSL
|
||||
if(wc_Blake2bFinal(&c->blake2, out, c->outlen) != 0)
|
||||
return 0;
|
||||
#else
|
||||
if(blake2b_final(&c->blake2, out, c->outlen) != 0)
|
||||
return 0;
|
||||
#endif
|
||||
*outlen = c->outlen;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mdh_free(mdh_ctx *c)
|
||||
{
|
||||
if(!c) return;
|
||||
#ifdef MDH_MD_BACKEND_CAPI
|
||||
if(c->hHash) CryptDestroyHash(c->hHash);
|
||||
if(c->hProv) CryptReleaseContext(c->hProv, 0);
|
||||
#endif
|
||||
memset(c, 0, sizeof(*c));
|
||||
free(c);
|
||||
}
|
||||
|
||||
#endif /* _WIN32 */
|
||||
+10
-6
@@ -4,19 +4,23 @@
|
||||
|
||||
please read License Agreement
|
||||
|
||||
Internal MD4/MD5 hash abstraction.
|
||||
- Windows: CryptoAPI (CAPI) backed, no OpenSSL dependency for these hashes.
|
||||
- Other platforms: OpenSSL EVP backed (requires WITH_SSL).
|
||||
Internal MD4/MD5/BLAKE2 hash abstraction.
|
||||
- Windows (no wolfSSL): CryptoAPI (CAPI) for MD4/MD5; bundled BLAKE2.
|
||||
- wolfSSL: wolfCrypt for MD4/MD5 (OpenSSL compat) and BLAKE2 (native).
|
||||
- Other: bundled public-domain MD4/MD5 + bundled BLAKE2 reference.
|
||||
*/
|
||||
#ifndef _MDHASH_H
|
||||
#define _MDHASH_H
|
||||
|
||||
typedef enum { MDH_MD4, MDH_MD5 } mdh_alg;
|
||||
typedef enum { MDH_MD4, MDH_MD5, MDH_BLAKE2 } mdh_alg;
|
||||
|
||||
typedef struct mdh_ctx mdh_ctx;
|
||||
|
||||
/* Returns NULL on failure. */
|
||||
mdh_ctx *mdh_init(mdh_alg alg);
|
||||
/* alg selects the hash. outlen selects digest size:
|
||||
- MD4/MD5: outlen ignored (fixed 16 bytes).
|
||||
- BLAKE2: outlen is the requested digest length (1..64).
|
||||
Returns NULL on failure. */
|
||||
mdh_ctx *mdh_init(mdh_alg alg, unsigned int outlen);
|
||||
|
||||
/* Returns 1 on success, 0 on failure. */
|
||||
int mdh_update(mdh_ctx *c, const void *data, unsigned int len);
|
||||
|
||||
@@ -6,11 +6,20 @@
|
||||
*/
|
||||
|
||||
#include "structures.h"
|
||||
#ifdef WITH_WOLFSSL
|
||||
#include <wolfssl/options.h>
|
||||
#include <wolfssl/openssl/crypto.h>
|
||||
#include <wolfssl/openssl/x509.h>
|
||||
#include <wolfssl/openssl/pem.h>
|
||||
#include <wolfssl/openssl/ssl.h>
|
||||
#include <wolfssl/openssl/err.h>
|
||||
#else
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
#endif
|
||||
#include "proxy.h"
|
||||
#include "ssl.h"
|
||||
|
||||
@@ -487,7 +496,7 @@ SSL_CTX * ssl_cli_ctx(SSL_CONFIG *config, X509 *server_cert, EVP_PKEY *server_ke
|
||||
int err = 0;
|
||||
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
#if !defined(WITH_WOLFSSL) && OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
ctx = SSL_CTX_new(SSLv23_server_method());
|
||||
#else
|
||||
ctx = SSL_CTX_new(TLS_server_method());
|
||||
@@ -517,14 +526,17 @@ SSL_CTX * ssl_cli_ctx(SSL_CONFIG *config, X509 *server_cert, EVP_PKEY *server_ke
|
||||
if(config->server_min_proto_version)SSL_CTX_set_min_proto_version(ctx, config->server_min_proto_version);
|
||||
if(config->server_max_proto_version)SSL_CTX_set_max_proto_version(ctx, config->server_max_proto_version);
|
||||
if(config->server_cipher_list)SSL_CTX_set_cipher_list(ctx, config->server_cipher_list);
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10101000L
|
||||
#if !defined(WITH_WOLFSSL) && OPENSSL_VERSION_NUMBER >= 0x10101000L
|
||||
if(config->server_ciphersuites)SSL_CTX_set_ciphersuites(ctx, config->server_ciphersuites);
|
||||
#elif defined(WITH_WOLFSSL)
|
||||
/* wolfSSL has no separate TLS1.3 ciphersuites API; route to cipher list. */
|
||||
if(config->server_ciphersuites)wolfSSL_CTX_set_cipher_list(ctx, config->server_ciphersuites);
|
||||
#endif
|
||||
if(config->server_verify){
|
||||
if(config->server_ca_file || config->server_ca_dir){
|
||||
SSL_CTX_load_verify_locations(ctx, config->server_ca_file, config->server_ca_dir);
|
||||
}
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
#if !defined(WITH_WOLFSSL) && OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
else if(config->server_ca_store){
|
||||
SSL_CTX_load_verify_store(ctx, config->server_ca_store);
|
||||
}
|
||||
@@ -655,7 +667,7 @@ static void* ssl_filter_open(void * idata, struct srvparam * srv){
|
||||
srv->so._poll = ssl_poll;
|
||||
}
|
||||
if(sc && (sc->mitm || sc->cli)){
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
#if !defined(WITH_WOLFSSL) && OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
sc->srv_ctx = SSL_CTX_new(SSLv23_client_method());
|
||||
#else
|
||||
sc->srv_ctx = SSL_CTX_new(TLS_client_method());
|
||||
@@ -671,17 +683,20 @@ static void* ssl_filter_open(void * idata, struct srvparam * srv){
|
||||
if(sc->client_min_proto_version)SSL_CTX_set_min_proto_version(sc->srv_ctx, sc->client_min_proto_version);
|
||||
if(sc->client_max_proto_version)SSL_CTX_set_max_proto_version(sc->srv_ctx, sc->client_max_proto_version);
|
||||
if(sc->client_cipher_list)SSL_CTX_set_cipher_list(sc->srv_ctx, sc->client_cipher_list);
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10101000L
|
||||
#if !defined(WITH_WOLFSSL) && OPENSSL_VERSION_NUMBER >= 0x10101000L
|
||||
if(sc->client_ciphersuites)SSL_CTX_set_ciphersuites(sc->srv_ctx, sc->client_ciphersuites);
|
||||
#elif defined(WITH_WOLFSSL)
|
||||
/* wolfSSL has no separate TLS1.3 ciphersuites API; route to cipher list. */
|
||||
if(sc->client_ciphersuites)wolfSSL_CTX_set_cipher_list(sc->srv_ctx, sc->client_ciphersuites);
|
||||
#endif
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10200000L
|
||||
#if (defined(WITH_WOLFSSL) && defined(HAVE_ALPN) && LIBWOLFSSL_VERSION_HEX >= 0x03007000) || (!defined(WITH_WOLFSSL) && OPENSSL_VERSION_NUMBER >= 0x10200000L)
|
||||
if(sc->client_alpn_protos.protos_len)SSL_CTX_set_alpn_protos(sc->srv_ctx, sc->client_alpn_protos.protos, sc->client_alpn_protos.protos_len);
|
||||
#endif
|
||||
if(sc->client_verify){
|
||||
if(sc->client_ca_file || sc->client_ca_dir){
|
||||
SSL_CTX_load_verify_locations(sc->srv_ctx, sc->client_ca_file, sc->client_ca_dir);
|
||||
}
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
#if !defined(WITH_WOLFSSL) && OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
else if(sc->client_ca_store){
|
||||
SSL_CTX_load_verify_store(sc->srv_ctx, sc->client_ca_store);
|
||||
}
|
||||
|
||||
+10
-1
@@ -14,12 +14,22 @@
|
||||
#include <sys/file.h>
|
||||
#endif
|
||||
|
||||
#ifdef WITH_WOLFSSL
|
||||
#include <wolfssl/options.h>
|
||||
#include <wolfssl/openssl/crypto.h>
|
||||
#include <wolfssl/openssl/x509.h>
|
||||
#include <wolfssl/openssl/x509v3.h>
|
||||
#include <wolfssl/openssl/pem.h>
|
||||
#include <wolfssl/openssl/ssl.h>
|
||||
#include <wolfssl/openssl/err.h>
|
||||
#else
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
#endif
|
||||
|
||||
#include "proxy.h"
|
||||
#include "ssl.h"
|
||||
@@ -103,7 +113,6 @@ SSL_CERT ssl_copy_cert(SSL_CERT cert, SSL_CONFIG *config)
|
||||
X509 *dst_cert = NULL;
|
||||
|
||||
EVP_PKEY *pk = NULL;
|
||||
RSA *rsa = NULL;
|
||||
|
||||
unsigned char hash_sha256[32];
|
||||
char hash_name_sha256[(16*2) + 1];
|
||||
|
||||
Reference in new issue
Block a user