mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2007, Cameron Rich
|
* Copyright (c) 2007-2016, Cameron Rich
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@ -38,9 +38,6 @@
|
|||||||
#include "os_port.h"
|
#include "os_port.h"
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
|
||||||
/* all commented out in skeleton mode */
|
|
||||||
#ifndef CONFIG_SSL_SKELETON_MODE
|
|
||||||
|
|
||||||
#define rot1(x) (((x) << 24) | ((x) >> 8))
|
#define rot1(x) (((x) << 24) | ((x) >> 8))
|
||||||
#define rot2(x) (((x) << 16) | ((x) >> 16))
|
#define rot2(x) (((x) << 16) | ((x) >> 16))
|
||||||
#define rot3(x) (((x) << 8) | ((x) >> 24))
|
#define rot3(x) (((x) << 8) | ((x) >> 24))
|
||||||
@ -453,5 +450,3 @@ static void AES_decrypt(const AES_CTX *ctx, uint32_t *data)
|
|||||||
data[row-1] = tmp[row-1] ^ *(--k);
|
data[row-1] = tmp[row-1] ^ *(--k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2007-2015, Cameron Rich
|
* Copyright (c) 2007-2016, Cameron Rich
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@ -200,6 +200,8 @@ void hmac_md5(const uint8_t *msg, int length, const uint8_t *key,
|
|||||||
int key_len, uint8_t *digest);
|
int key_len, uint8_t *digest);
|
||||||
void hmac_sha1(const uint8_t *msg, int length, const uint8_t *key,
|
void hmac_sha1(const uint8_t *msg, int length, const uint8_t *key,
|
||||||
int key_len, uint8_t *digest);
|
int key_len, uint8_t *digest);
|
||||||
|
void hmac_sha256(const uint8_t *msg, int length, const uint8_t *key,
|
||||||
|
int key_len, uint8_t *digest);
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* RSA declarations
|
* RSA declarations
|
||||||
|
@ -53,7 +53,7 @@ static int rng_fd = -1;
|
|||||||
static HCRYPTPROV gCryptProv;
|
static HCRYPTPROV gCryptProv;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (!defined(CONFIG_USE_DEV_URANDOM) && !defined(CONFIG_WIN32_USE_CRYPTO_LIB))
|
#if (!defined(ESP8266) && !defined(CONFIG_USE_DEV_URANDOM) && !defined(CONFIG_WIN32_USE_CRYPTO_LIB))
|
||||||
/* change to processor registers as appropriate */
|
/* change to processor registers as appropriate */
|
||||||
#define ENTROPY_POOL_SIZE 32
|
#define ENTROPY_POOL_SIZE 32
|
||||||
#define ENTROPY_COUNTER1 ((((uint64_t)tv.tv_sec)<<32) | tv.tv_usec)
|
#define ENTROPY_COUNTER1 ((((uint64_t)tv.tv_sec)<<32) | tv.tv_usec)
|
||||||
@ -109,7 +109,7 @@ int get_file(const char *filename, uint8_t **buf)
|
|||||||
EXP_FUNC void STDCALL RNG_initialize()
|
EXP_FUNC void STDCALL RNG_initialize()
|
||||||
{
|
{
|
||||||
#if !defined(WIN32) && defined(CONFIG_USE_DEV_URANDOM)
|
#if !defined(WIN32) && defined(CONFIG_USE_DEV_URANDOM)
|
||||||
rng_fd = ax_open("/dev/urandom", O_RDONLY);
|
rng_fd = open("/dev/urandom", O_RDONLY);
|
||||||
#elif defined(WIN32) && defined(CONFIG_WIN32_USE_CRYPTO_LIB)
|
#elif defined(WIN32) && defined(CONFIG_WIN32_USE_CRYPTO_LIB)
|
||||||
if (!CryptAcquireContext(&gCryptProv,
|
if (!CryptAcquireContext(&gCryptProv,
|
||||||
NULL, NULL, PROV_RSA_FULL, 0))
|
NULL, NULL, PROV_RSA_FULL, 0))
|
||||||
@ -130,7 +130,7 @@ EXP_FUNC void STDCALL RNG_initialize()
|
|||||||
/* start of with a stack to copy across */
|
/* start of with a stack to copy across */
|
||||||
int i;
|
int i;
|
||||||
memcpy(entropy_pool, &i, ENTROPY_POOL_SIZE);
|
memcpy(entropy_pool, &i, ENTROPY_POOL_SIZE);
|
||||||
srand((unsigned int)&i);
|
rand_r((unsigned int *)entropy_pool);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ EXP_FUNC int STDCALL get_random(int num_rand_bytes, uint8_t *rand_data)
|
|||||||
#else /* nothing else to use, so use a custom RNG */
|
#else /* nothing else to use, so use a custom RNG */
|
||||||
/* The method we use when we've got nothing better. Use RC4, time
|
/* The method we use when we've got nothing better. Use RC4, time
|
||||||
and a couple of random seeds to generate a random sequence */
|
and a couple of random seeds to generate a random sequence */
|
||||||
RC4_CTX rng_ctx;
|
AES_CTX rng_ctx;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
MD5_CTX rng_digest_ctx;
|
MD5_CTX rng_digest_ctx;
|
||||||
uint8_t digest[MD5_SIZE];
|
uint8_t digest[MD5_SIZE];
|
||||||
@ -200,10 +200,10 @@ EXP_FUNC int STDCALL get_random(int num_rand_bytes, uint8_t *rand_data)
|
|||||||
MD5_Final(digest, &rng_digest_ctx);
|
MD5_Final(digest, &rng_digest_ctx);
|
||||||
|
|
||||||
/* come up with the random sequence */
|
/* come up with the random sequence */
|
||||||
RC4_setup(&rng_ctx, digest, MD5_SIZE); /* use as a key */
|
AES_set_key(&rng_ctx, digest, (const uint8_t *)ep, AES_MODE_128); /* use as a key */
|
||||||
memcpy(rand_data, entropy_pool, num_rand_bytes < ENTROPY_POOL_SIZE ?
|
memcpy(rand_data, entropy_pool, num_rand_bytes < ENTROPY_POOL_SIZE ?
|
||||||
num_rand_bytes : ENTROPY_POOL_SIZE);
|
num_rand_bytes : ENTROPY_POOL_SIZE);
|
||||||
RC4_crypt(&rng_ctx, rand_data, rand_data, num_rand_bytes);
|
AES_cbc_encrypt(&rng_ctx, rand_data, rand_data, num_rand_bytes);
|
||||||
|
|
||||||
/* move things along */
|
/* move things along */
|
||||||
for (i = ENTROPY_POOL_SIZE-1; i >= MD5_SIZE ; i--)
|
for (i = ENTROPY_POOL_SIZE-1; i >= MD5_SIZE ; i--)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2007, Cameron Rich
|
* Copyright (c) 2007-2016, Cameron Rich
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@ -103,3 +103,37 @@ void hmac_sha1(const uint8_t *msg, int length, const uint8_t *key,
|
|||||||
SHA1_Update(&context, digest, SHA1_SIZE);
|
SHA1_Update(&context, digest, SHA1_SIZE);
|
||||||
SHA1_Final(digest, &context);
|
SHA1_Final(digest, &context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform HMAC-SHA256
|
||||||
|
* NOTE: does not handle keys larger than the block size.
|
||||||
|
*/
|
||||||
|
void hmac_sha256(const uint8_t *msg, int length, const uint8_t *key,
|
||||||
|
int key_len, uint8_t *digest)
|
||||||
|
{
|
||||||
|
SHA256_CTX context;
|
||||||
|
uint8_t k_ipad[64];
|
||||||
|
uint8_t k_opad[64];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
memset(k_ipad, 0, sizeof k_ipad);
|
||||||
|
memset(k_opad, 0, sizeof k_opad);
|
||||||
|
memcpy(k_ipad, key, key_len);
|
||||||
|
memcpy(k_opad, key, key_len);
|
||||||
|
|
||||||
|
for (i = 0; i < 64; i++)
|
||||||
|
{
|
||||||
|
k_ipad[i] ^= 0x36;
|
||||||
|
k_opad[i] ^= 0x5c;
|
||||||
|
}
|
||||||
|
|
||||||
|
SHA256_Init(&context);
|
||||||
|
SHA256_Update(&context, k_ipad, 64);
|
||||||
|
SHA256_Update(&context, msg, length);
|
||||||
|
SHA256_Final(digest, &context);
|
||||||
|
SHA256_Init(&context);
|
||||||
|
SHA256_Update(&context, k_opad, 64);
|
||||||
|
SHA256_Update(&context, digest, SHA256_SIZE);
|
||||||
|
SHA256_Final(digest, &context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, Cameron Rich
|
* Copyright (c) 2012-2016, Cameron Rich
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@ -56,7 +56,6 @@ typedef INT64 int64_t;
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#else
|
#else
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <endian.h>
|
|
||||||
#endif /* Not Solaris */
|
#endif /* Not Solaris */
|
||||||
|
|
||||||
#endif /* Not Win32 */
|
#endif /* Not Win32 */
|
||||||
|
@ -125,7 +125,6 @@ const char * x509_display_error(int error);
|
|||||||
#define ASN1_EXPLICIT_TAG 0xa0
|
#define ASN1_EXPLICIT_TAG 0xa0
|
||||||
#define ASN1_V3_DATA 0xa3
|
#define ASN1_V3_DATA 0xa3
|
||||||
|
|
||||||
#define SIG_TYPE_MD2 0x02
|
|
||||||
#define SIG_TYPE_MD5 0x04
|
#define SIG_TYPE_MD5 0x04
|
||||||
#define SIG_TYPE_SHA1 0x05
|
#define SIG_TYPE_SHA1 0x05
|
||||||
#define SIG_TYPE_SHA256 0x0b
|
#define SIG_TYPE_SHA256 0x0b
|
||||||
|
12
ssl/loader.c
12
ssl/loader.c
@ -82,7 +82,9 @@ EXP_FUNC int STDCALL ssl_obj_load(SSL_CTX *ssl_ctx, int obj_type,
|
|||||||
#ifdef CONFIG_SSL_HAS_PEM
|
#ifdef CONFIG_SSL_HAS_PEM
|
||||||
ret = ssl_obj_PEM_load(ssl_ctx, obj_type, ssl_obj, password);
|
ret = ssl_obj_PEM_load(ssl_ctx, obj_type, ssl_obj, password);
|
||||||
#else
|
#else
|
||||||
|
#ifdef CONFIG_SSL_FULL_MODE
|
||||||
printf("%s", unsupported_str);
|
printf("%s", unsupported_str);
|
||||||
|
#endif
|
||||||
ret = SSL_ERROR_NOT_SUPPORTED;
|
ret = SSL_ERROR_NOT_SUPPORTED;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -93,7 +95,9 @@ error:
|
|||||||
ssl_obj_free(ssl_obj);
|
ssl_obj_free(ssl_obj);
|
||||||
return ret;
|
return ret;
|
||||||
#else
|
#else
|
||||||
|
#ifdef CONFIG_SSL_FULL_MODE
|
||||||
printf("%s", unsupported_str);
|
printf("%s", unsupported_str);
|
||||||
|
#endif
|
||||||
return SSL_ERROR_NOT_SUPPORTED;
|
return SSL_ERROR_NOT_SUPPORTED;
|
||||||
#endif /* CONFIG_SSL_SKELETON_MODE */
|
#endif /* CONFIG_SSL_SKELETON_MODE */
|
||||||
}
|
}
|
||||||
@ -150,7 +154,9 @@ static int do_obj(SSL_CTX *ssl_ctx, int obj_type,
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
|
#ifdef CONFIG_SSL_FULL_MODE
|
||||||
printf("%s", unsupported_str);
|
printf("%s", unsupported_str);
|
||||||
|
#endif
|
||||||
ret = SSL_ERROR_NOT_SUPPORTED;
|
ret = SSL_ERROR_NOT_SUPPORTED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -223,7 +229,7 @@ static int pem_decrypt(const char *where, const char *end,
|
|||||||
if (password == NULL || strlen(password) == 0)
|
if (password == NULL || strlen(password) == 0)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_SSL_FULL_MODE
|
#ifdef CONFIG_SSL_FULL_MODE
|
||||||
printf("Error: Need a password for this PEM file\n"); TTY_FLUSH();
|
printf("Error: Need a password for this PEM file\n");
|
||||||
#endif
|
#endif
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -240,7 +246,7 @@ static int pem_decrypt(const char *where, const char *end,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_SSL_FULL_MODE
|
#ifdef CONFIG_SSL_FULL_MODE
|
||||||
printf("Error: Unsupported password cipher\n"); TTY_FLUSH();
|
printf("Error: Unsupported password cipher\n");
|
||||||
#endif
|
#endif
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -475,7 +481,7 @@ error:
|
|||||||
#ifdef CONFIG_SSL_FULL_MODE
|
#ifdef CONFIG_SSL_FULL_MODE
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
printf("Error: Certificate or key not loaded\n"); TTY_FLUSH();
|
printf("Error: Certificate or key not loaded\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2007, Cameron Rich
|
* Copyright (c) 2007-2016, Cameron Rich
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@ -49,10 +49,8 @@
|
|||||||
|
|
||||||
static char *key_password = NULL;
|
static char *key_password = NULL;
|
||||||
|
|
||||||
void *SSLv23_server_method(void) { return NULL; }
|
|
||||||
void *SSLv3_server_method(void) { return NULL; }
|
void *SSLv3_server_method(void) { return NULL; }
|
||||||
void *TLSv1_server_method(void) { return NULL; }
|
void *TLSv1_server_method(void) { return NULL; }
|
||||||
void *SSLv23_client_method(void) { return NULL; }
|
|
||||||
void *SSLv3_client_method(void) { return NULL; }
|
void *SSLv3_client_method(void) { return NULL; }
|
||||||
void *TLSv1_client_method(void) { return NULL; }
|
void *TLSv1_client_method(void) { return NULL; }
|
||||||
|
|
||||||
@ -81,14 +79,13 @@ void SSL_CTX_free(SSL_CTX * ssl_ctx)
|
|||||||
SSL * SSL_new(SSL_CTX *ssl_ctx)
|
SSL * SSL_new(SSL_CTX *ssl_ctx)
|
||||||
{
|
{
|
||||||
SSL *ssl;
|
SSL *ssl;
|
||||||
ssl_func_type_t ssl_func_type;
|
#ifdef CONFIG_SSL_ENABLE_CLIENT
|
||||||
|
ssl_func_type_t ssl_func_type = OPENSSL_CTX_ATTR->ssl_func_type;
|
||||||
|
#endif
|
||||||
|
|
||||||
ssl = ssl_new(ssl_ctx, -1); /* fd is set later */
|
ssl = ssl_new(ssl_ctx, -1); /* fd is set later */
|
||||||
ssl_func_type = OPENSSL_CTX_ATTR->ssl_func_type;
|
|
||||||
|
|
||||||
#ifdef CONFIG_SSL_ENABLE_CLIENT
|
#ifdef CONFIG_SSL_ENABLE_CLIENT
|
||||||
if (ssl_func_type == SSLv23_client_method ||
|
if (ssl_func_type == SSLv3_client_method ||
|
||||||
ssl_func_type == SSLv3_client_method ||
|
|
||||||
ssl_func_type == TLSv1_client_method)
|
ssl_func_type == TLSv1_client_method)
|
||||||
{
|
{
|
||||||
SET_SSL_FLAG(SSL_IS_CLIENT);
|
SET_SSL_FLAG(SSL_IS_CLIENT);
|
||||||
@ -231,8 +228,6 @@ void SSL_CTX_set_client_CA_list(SSL_CTX *ssl_ctx, void *file)
|
|||||||
ssl_obj_load(ssl_ctx, SSL_OBJ_X509_CERT, (const char *)file, NULL);
|
ssl_obj_load(ssl_ctx, SSL_OBJ_X509_CERT, (const char *)file, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSLv23_method(void) { }
|
|
||||||
|
|
||||||
void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, void *cb) { }
|
void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, void *cb) { }
|
||||||
|
|
||||||
void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u)
|
void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2007, Cameron Rich
|
* Copyright (c) 2007-2016, Cameron Rich
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@ -91,9 +91,3 @@ EXP_FUNC int STDCALL getdomainname(char *buf, int buf_size)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#undef malloc
|
|
||||||
#undef realloc
|
|
||||||
#undef calloc
|
|
||||||
|
|
||||||
static const char * out_of_mem_str = "out of memory";
|
|
||||||
static const char * file_open_str = "Could not open file \"%s\"";
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2007-2015, Cameron Rich
|
* Copyright (c) 2007-2016, Cameron Rich
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@ -62,7 +62,7 @@ extern "C" {
|
|||||||
|
|
||||||
#include "util/time.h"
|
#include "util/time.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
// #define alloca(size) __builtin_alloca(size)
|
#define alloca(size) __builtin_alloca(size)
|
||||||
#define TTY_FLUSH()
|
#define TTY_FLUSH()
|
||||||
#ifdef putc
|
#ifdef putc
|
||||||
#undef putc
|
#undef putc
|
||||||
@ -80,6 +80,7 @@ extern "C" {
|
|||||||
#define EWOULDBLOCK EAGAIN
|
#define EWOULDBLOCK EAGAIN
|
||||||
|
|
||||||
#define hmac_sha1 ax_hmac_sha1
|
#define hmac_sha1 ax_hmac_sha1
|
||||||
|
#define hmac_sha256 ax_hmac_sha256
|
||||||
#define hmac_md5 ax_hmac_md5
|
#define hmac_md5 ax_hmac_md5
|
||||||
|
|
||||||
#ifndef be64toh
|
#ifndef be64toh
|
||||||
@ -189,19 +190,6 @@ EXP_FUNC int STDCALL getdomainname(char *buf, int buf_size);
|
|||||||
#endif /* Not Win32 */
|
#endif /* Not Win32 */
|
||||||
|
|
||||||
/* some functions to mutate the way these work */
|
/* some functions to mutate the way these work */
|
||||||
#define malloc(A) ax_port_malloc(A, __FILE__, __LINE__)
|
|
||||||
#ifndef realloc
|
|
||||||
#define realloc(A,B) ax_port_realloc(A,B, __FILE__, __LINE__)
|
|
||||||
#endif
|
|
||||||
#define calloc(A,B) ax_port_calloc(A,B, __FILE__, __LINE__)
|
|
||||||
#define free(x) ax_port_free(x)
|
|
||||||
|
|
||||||
EXP_FUNC void * STDCALL ax_port_malloc(size_t s, const char*, int);
|
|
||||||
EXP_FUNC void * STDCALL ax_port_realloc(void *y, size_t s, const char*, int);
|
|
||||||
EXP_FUNC void * STDCALL ax_port_calloc(size_t n, size_t s, const char*, int);
|
|
||||||
EXP_FUNC void * STDCALL ax_port_free(void*);
|
|
||||||
EXP_FUNC int STDCALL ax_open(const char *pathname, int flags);
|
|
||||||
|
|
||||||
inline uint32_t htonl(uint32_t n){
|
inline uint32_t htonl(uint32_t n){
|
||||||
return ((n & 0xff) << 24) |
|
return ((n & 0xff) << 24) |
|
||||||
((n & 0xff00) << 8) |
|
((n & 0xff00) << 8) |
|
||||||
@ -211,6 +199,8 @@ inline uint32_t htonl(uint32_t n){
|
|||||||
|
|
||||||
#define ntohl htonl
|
#define ntohl htonl
|
||||||
|
|
||||||
|
EXP_FUNC int STDCALL ax_open(const char *pathname, int flags);
|
||||||
|
|
||||||
#ifdef CONFIG_PLATFORM_LINUX
|
#ifdef CONFIG_PLATFORM_LINUX
|
||||||
void exit_now(const char *format, ...) __attribute((noreturn));
|
void exit_now(const char *format, ...) __attribute((noreturn));
|
||||||
#else
|
#else
|
||||||
|
15
ssl/ssl.h
15
ssl/ssl.h
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2007, Cameron Rich
|
* Copyright (c) 2007-2016, Cameron Rich
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@ -91,13 +91,16 @@ extern "C" {
|
|||||||
#define SSL_ERROR_DEAD -2
|
#define SSL_ERROR_DEAD -2
|
||||||
#define SSL_CLOSE_NOTIFY -3
|
#define SSL_CLOSE_NOTIFY -3
|
||||||
#define SSL_ERROR_CONN_LOST -256
|
#define SSL_ERROR_CONN_LOST -256
|
||||||
|
#define SSL_ERROR_RECORD_OVERFLOW -257
|
||||||
#define SSL_ERROR_SOCK_SETUP_FAILURE -258
|
#define SSL_ERROR_SOCK_SETUP_FAILURE -258
|
||||||
#define SSL_ERROR_INVALID_HANDSHAKE -260
|
#define SSL_ERROR_INVALID_HANDSHAKE -260
|
||||||
#define SSL_ERROR_INVALID_PROT_MSG -261
|
#define SSL_ERROR_INVALID_PROT_MSG -261
|
||||||
#define SSL_ERROR_INVALID_HMAC -262
|
#define SSL_ERROR_INVALID_HMAC -262
|
||||||
#define SSL_ERROR_INVALID_VERSION -263
|
#define SSL_ERROR_INVALID_VERSION -263
|
||||||
|
#define SSL_ERROR_UNSUPPORTED_EXTENSION -264
|
||||||
#define SSL_ERROR_INVALID_SESSION -265
|
#define SSL_ERROR_INVALID_SESSION -265
|
||||||
#define SSL_ERROR_NO_CIPHER -266
|
#define SSL_ERROR_NO_CIPHER -266
|
||||||
|
#define SSL_ERROR_INVALID_CERT_HASH_ALG -267
|
||||||
#define SSL_ERROR_BAD_CERTIFICATE -268
|
#define SSL_ERROR_BAD_CERTIFICATE -268
|
||||||
#define SSL_ERROR_INVALID_KEY -269
|
#define SSL_ERROR_INVALID_KEY -269
|
||||||
#define SSL_ERROR_FINISHED_INVALID -271
|
#define SSL_ERROR_FINISHED_INVALID -271
|
||||||
@ -115,19 +118,25 @@ extern "C" {
|
|||||||
#define SSL_ALERT_CLOSE_NOTIFY 0
|
#define SSL_ALERT_CLOSE_NOTIFY 0
|
||||||
#define SSL_ALERT_UNEXPECTED_MESSAGE 10
|
#define SSL_ALERT_UNEXPECTED_MESSAGE 10
|
||||||
#define SSL_ALERT_BAD_RECORD_MAC 20
|
#define SSL_ALERT_BAD_RECORD_MAC 20
|
||||||
|
#define SSL_ALERT_RECORD_OVERFLOW 22
|
||||||
#define SSL_ALERT_HANDSHAKE_FAILURE 40
|
#define SSL_ALERT_HANDSHAKE_FAILURE 40
|
||||||
#define SSL_ALERT_BAD_CERTIFICATE 42
|
#define SSL_ALERT_BAD_CERTIFICATE 42
|
||||||
|
#define SSL_ALERT_UNSUPPORTED_CERTIFICATE 43
|
||||||
|
#define SSL_ALERT_CERTIFICATE_EXPIRED 45
|
||||||
|
#define SSL_ALERT_CERTIFICATE_UNKNOWN 46
|
||||||
#define SSL_ALERT_ILLEGAL_PARAMETER 47
|
#define SSL_ALERT_ILLEGAL_PARAMETER 47
|
||||||
|
#define SSL_ALERT_UNKNOWN_CA 48
|
||||||
#define SSL_ALERT_DECODE_ERROR 50
|
#define SSL_ALERT_DECODE_ERROR 50
|
||||||
#define SSL_ALERT_DECRYPT_ERROR 51
|
#define SSL_ALERT_DECRYPT_ERROR 51
|
||||||
#define SSL_ALERT_INVALID_VERSION 70
|
#define SSL_ALERT_INVALID_VERSION 70
|
||||||
#define SSL_ALERT_NO_RENEGOTIATION 100
|
#define SSL_ALERT_NO_RENEGOTIATION 100
|
||||||
|
#define SSL_ALERT_UNSUPPORTED_EXTENSION 110
|
||||||
|
|
||||||
/* The ciphers that are supported */
|
/* The ciphers that are supported */
|
||||||
#define SSL_AES128_SHA 0x2f
|
#define SSL_AES128_SHA 0x2f
|
||||||
#define SSL_AES256_SHA 0x35
|
#define SSL_AES256_SHA 0x35
|
||||||
#define SSL_RC4_128_SHA 0x05
|
#define SSL_AES128_SHA256 0x3c
|
||||||
#define SSL_RC4_128_MD5 0x04
|
#define SSL_AES256_SHA256 0x3d
|
||||||
|
|
||||||
/* build mode ids' */
|
/* build mode ids' */
|
||||||
#define SSL_BUILD_SKELETON_MODE 0x01
|
#define SSL_BUILD_SKELETON_MODE 0x01
|
||||||
|
18
ssl/test/axTLS.ca_x509_sha256.pem
Normal file
18
ssl/test/axTLS.ca_x509_sha256.pem
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIC5DCCAcwCCQDGL4Ul/VVK0TANBgkqhkiG9w0BAQsFADA0MTIwMAYDVQQKEylh
|
||||||
|
eFRMUyBQcm9qZWN0IERvZGd5IENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNjA4
|
||||||
|
MTUxMDIwNTZaFw0zMDA0MjQxMDIwNTZaMDQxMjAwBgNVBAoTKWF4VExTIFByb2pl
|
||||||
|
Y3QgRG9kZ3kgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MIIBIjANBgkqhkiG9w0BAQEF
|
||||||
|
AAOCAQ8AMIIBCgKCAQEA6d9BDlOJo6fdmSkUdAkMYFnlAK4Q5qwE/vYX8umY0Gz1
|
||||||
|
CEIwEyKJq+rCpl2vmlwEETGcphlRsiybOMwVfdRDQv51ZfTJnz1WQZBKdsYb55xy
|
||||||
|
JWOZFHSpuZa+THW1TOImpvxXoK3OMh/dcuaQG5G7QoWMWRK5aZvpl27rRx033dik
|
||||||
|
U8lO12oaUtCD3AgNttU7zTLiIQjeIZ9JbES74mx1s4lT22nmXoL5/AdJa3yGjDjG
|
||||||
|
J1RX8hQ7/pbcC2s4+0XIjGthB2ClJWyvv8bY96POZ+Kc5XLFFjxYoGHtRzQbw2gx
|
||||||
|
rx7r5/a+d7XgWedMnwf1M1/v9vNA14kgjg2pwuFD4QIDAQABMA0GCSqGSIb3DQEB
|
||||||
|
CwUAA4IBAQBW9MtGYroXnu8id8rDvjki8Vk8lDBD0AkOq5QYbXB322Wbg2C+cmHP
|
||||||
|
zQAJ9YZU/NjnRZiEX1QVoZAXdSXXScbUbSlBQweEvGZmailTGPhJ/wtmNtK6P7ZP
|
||||||
|
YIJ6XaQdALvteULFMhEQKM9UUkrsbqh41wtoTjOsMlWcRvq9FHLujXxyzjvFPdEI
|
||||||
|
kz26d7F2yqtgzxW4YLAlclZu6vex/MzNmbjhHenMWp6LNWVWofdIv9jRS1tOSyK+
|
||||||
|
hg2sV7CL75nzQ/A22ql8X3SZLAZNR/V7DF+MSBrIcHBzgFZ8QEGlNam29WseuC2C
|
||||||
|
51+ZXtv0DZ1bPmX+Pz1E06wMGlBTpC4z
|
||||||
|
-----END CERTIFICATE-----
|
15
ssl/test/axTLS.x509_1024_sha256.pem
Normal file
15
ssl/test/axTLS.x509_1024_sha256.pem
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIICWDCCAUACCQCMs+C6AhuzaTANBgkqhkiG9w0BAQsFADA0MTIwMAYDVQQKEylh
|
||||||
|
eFRMUyBQcm9qZWN0IERvZGd5IENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNjA4
|
||||||
|
MTUxMDIwNTZaFw0zMDA0MjQxMDIwNTZaMCwxFjAUBgNVBAoTDWF4VExTIFByb2pl
|
||||||
|
Y3QxEjAQBgNVBAMTCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkC
|
||||||
|
gYEAq9P2gjL8e0OgMrA81JoZeqaZMRmSaTH8xIHf7MkbGYW1ZyBWW+n+017itYgH
|
||||||
|
pu61CiYcyAfuUACTL2VBhrakCb+j53OF0V+9uEH/BkftUUcu+6ppBB4XI5KbYmTH
|
||||||
|
JjhBW8N1OHadHLCG4dkQLjnaFgekpM8xZzvd4kkbM4mZqtECAwEAATANBgkqhkiG
|
||||||
|
9w0BAQsFAAOCAQEAG/SBHWYNVf5drxN1aLx9UqTpryjmzDP9/gckKpuNEiDCmp38
|
||||||
|
MIKBJYamL9hTwmtf1k4vHB2sxXfv9AVULwMa7+RcgUc3fhTWWoqf1LvYvzMrx9W9
|
||||||
|
yU6bfXQh5zb6TOrq/j4fliA2NeDvAzq8tzhBVhiyvy0GhhU1C9eBRVFr4D9l/B2z
|
||||||
|
odWvCZ4ljLjtmoOhrSSf0OHFuk/eqFJ/SS1jo3ugl7wEmMzphOjmwgK7CLyACBSn
|
||||||
|
6Bzlh/A16AgqznniMHZ9p99zopMSqPUkCCHPEUiqs8hoy6Pc7O6FrTKfkeiAnY1u
|
||||||
|
SfKiOf4ODmDcLb5gVtDx+zp59Q/khBX+6IT+BA==
|
||||||
|
-----END CERTIFICATE-----
|
15
ssl/test/axTLS.x509_1024_sha384.pem
Normal file
15
ssl/test/axTLS.x509_1024_sha384.pem
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIICWDCCAUACCQCMs+C6AhuzajANBgkqhkiG9w0BAQwFADA0MTIwMAYDVQQKEylh
|
||||||
|
eFRMUyBQcm9qZWN0IERvZGd5IENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNjA4
|
||||||
|
MTUxMDIwNTZaFw0zMDA0MjQxMDIwNTZaMCwxFjAUBgNVBAoTDWF4VExTIFByb2pl
|
||||||
|
Y3QxEjAQBgNVBAMTCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkC
|
||||||
|
gYEAq9P2gjL8e0OgMrA81JoZeqaZMRmSaTH8xIHf7MkbGYW1ZyBWW+n+017itYgH
|
||||||
|
pu61CiYcyAfuUACTL2VBhrakCb+j53OF0V+9uEH/BkftUUcu+6ppBB4XI5KbYmTH
|
||||||
|
JjhBW8N1OHadHLCG4dkQLjnaFgekpM8xZzvd4kkbM4mZqtECAwEAATANBgkqhkiG
|
||||||
|
9w0BAQwFAAOCAQEA151mqDTC1YPiFq4t7J2UK84jYlGriW0z6KhfmtecLm18Uu07
|
||||||
|
vDh+cvWoFRf/fgSlO7c6td0Jb4NGjPBwpV4UmoYND65d1+EkrP+Bl+2DndUi/xka
|
||||||
|
h4bwfmPrKAjDbUZaNnRi1zQdyPU9tta9b0MamHQVHFOIAyLQXDf1/Tz+wRaFPCIH
|
||||||
|
PfJEqjD4Nr15O41aMJOaM170rOtbQ9uH4Vlotpt+xJsHufmHFMf1fJtgBXayCzmS
|
||||||
|
1927ajoKNyDA/QQ+e+60uba6UN6CQnoMzmkMypMxD4JBUt6TEgB46uQ7nkkf3raS
|
||||||
|
tMAyMnytSc+O7EbhZSWWBSTUkeI+YWjLAtI42Q==
|
||||||
|
-----END CERTIFICATE-----
|
15
ssl/test/axTLS.x509_1024_sha512.pem
Normal file
15
ssl/test/axTLS.x509_1024_sha512.pem
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIICWDCCAUACCQCMs+C6AhuzazANBgkqhkiG9w0BAQ0FADA0MTIwMAYDVQQKEylh
|
||||||
|
eFRMUyBQcm9qZWN0IERvZGd5IENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNjA4
|
||||||
|
MTUxMDIwNTZaFw0zMDA0MjQxMDIwNTZaMCwxFjAUBgNVBAoTDWF4VExTIFByb2pl
|
||||||
|
Y3QxEjAQBgNVBAMTCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkC
|
||||||
|
gYEAq9P2gjL8e0OgMrA81JoZeqaZMRmSaTH8xIHf7MkbGYW1ZyBWW+n+017itYgH
|
||||||
|
pu61CiYcyAfuUACTL2VBhrakCb+j53OF0V+9uEH/BkftUUcu+6ppBB4XI5KbYmTH
|
||||||
|
JjhBW8N1OHadHLCG4dkQLjnaFgekpM8xZzvd4kkbM4mZqtECAwEAATANBgkqhkiG
|
||||||
|
9w0BAQ0FAAOCAQEA51hsTX6DlE9WnI0XaNfx0hfWG74maMZK+GG1LQKi6JlaA6U4
|
||||||
|
7aLpoluw4G7oZz39ROuNbOvTMrhN4kOXG16Zk2HGufzAQgqoegIsgI2BiaOtmBnn
|
||||||
|
vOchhiZ16JLmKB6ZMlESFubV1Ynyr6QacTLOipLGICGn3N65BrbwfaXD/nbJQd+a
|
||||||
|
YOwkJ9OHxbK9zqLMBG3kK/QKXqID3dI21+MDCGSSBAh/tVPhwTMcTzViF5vT4Mpq
|
||||||
|
81+Z9eg3vI++rOiBppdjRKH4CFcO74rEA6j9fNFHI0PiS142TtT4vXLf+D4PQLkI
|
||||||
|
tBuSq99ensRy5IvjYXpcx7/jixVd3MmwWrolbg==
|
||||||
|
-----END CERTIFICATE-----
|
625
ssl/tls1.c
625
ssl/tls1.c
File diff suppressed because it is too large
Load Diff
46
ssl/tls1.h
46
ssl/tls1.h
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2007-2014, Cameron Rich
|
* Copyright (c) 2007-2016, Cameron Rich
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@ -43,13 +43,14 @@ extern "C" {
|
|||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "os_int.h"
|
#include "os_int.h"
|
||||||
|
#include "os_port.h"
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
#include "crypto_misc.h"
|
#include "crypto_misc.h"
|
||||||
|
|
||||||
#define SSL_PROTOCOL_MIN_VERSION 0x31 /* TLS v1.0 */
|
#define SSL_PROTOCOL_MIN_VERSION 0x31 /* TLS v1.0 */
|
||||||
#define SSL_PROTOCOL_MINOR_VERSION 0x02 /* TLS v1.1 */
|
#define SSL_PROTOCOL_VERSION_MAX 0x33 /* TLS v1.3 */
|
||||||
#define SSL_PROTOCOL_VERSION_MAX 0x32 /* TLS v1.1 */
|
#define SSL_PROTOCOL_VERSION_TLS1_1 0x32 /* TLS v1.1 */
|
||||||
#define SSL_PROTOCOL_VERSION1_1 0x32 /* TLS v1.1 */
|
#define SSL_PROTOCOL_VERSION_TLS1_2 0x33 /* TLS v1.2 */
|
||||||
#define SSL_RANDOM_SIZE 32
|
#define SSL_RANDOM_SIZE 32
|
||||||
#define SSL_SECRET_SIZE 48
|
#define SSL_SECRET_SIZE 48
|
||||||
#define SSL_FINISHED_HASH_SIZE 12
|
#define SSL_FINISHED_HASH_SIZE 12
|
||||||
@ -79,11 +80,15 @@ extern "C" {
|
|||||||
#define RT_EXTRA 1024
|
#define RT_EXTRA 1024
|
||||||
#define BM_RECORD_OFFSET 5
|
#define BM_RECORD_OFFSET 5
|
||||||
|
|
||||||
#ifdef CONFIG_SSL_SKELETON_MODE
|
#define NUM_PROTOCOLS 4
|
||||||
#define NUM_PROTOCOLS 1
|
|
||||||
#else
|
#define MAX_SIG_ALGORITHMS 4
|
||||||
#define NUM_PROTOCOLS 2
|
#define SIG_ALG_EXTENSION 0x0d
|
||||||
#endif
|
#define SIG_ALG_SHA1 2
|
||||||
|
#define SIG_ALG_SHA256 4
|
||||||
|
#define SIG_ALG_SHA384 5
|
||||||
|
#define SIG_ALG_SHA512 6
|
||||||
|
#define SIG_ALG_RSA 1
|
||||||
|
|
||||||
#define PARANOIA_CHECK(A, B) if (A < B) { \
|
#define PARANOIA_CHECK(A, B) if (A < B) { \
|
||||||
ret = SSL_ERROR_INVALID_HANDSHAKE; goto error; }
|
ret = SSL_ERROR_INVALID_HANDSHAKE; goto error; }
|
||||||
@ -117,9 +122,9 @@ typedef struct
|
|||||||
uint8_t cipher;
|
uint8_t cipher;
|
||||||
uint8_t key_size;
|
uint8_t key_size;
|
||||||
uint8_t iv_size;
|
uint8_t iv_size;
|
||||||
uint8_t key_block_size;
|
|
||||||
uint8_t padding_size;
|
uint8_t padding_size;
|
||||||
uint8_t digest_size;
|
uint8_t digest_size;
|
||||||
|
uint8_t key_block_size;
|
||||||
hmac_func hmac;
|
hmac_func hmac;
|
||||||
crypt_func encrypt;
|
crypt_func encrypt;
|
||||||
crypt_func decrypt;
|
crypt_func decrypt;
|
||||||
@ -144,18 +149,21 @@ typedef struct
|
|||||||
{
|
{
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
int size;
|
int size;
|
||||||
|
uint8_t hash_alg;
|
||||||
} SSL_CERT;
|
} SSL_CERT;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
MD5_CTX md5_ctx;
|
MD5_CTX md5_ctx;
|
||||||
SHA1_CTX sha1_ctx;
|
SHA1_CTX sha1_ctx;
|
||||||
uint8_t final_finish_mac[SSL_FINISHED_HASH_SIZE];
|
SHA256_CTX sha256_ctx;
|
||||||
uint8_t *key_block;
|
|
||||||
uint8_t master_secret[SSL_SECRET_SIZE];
|
|
||||||
uint8_t client_random[SSL_RANDOM_SIZE]; /* client's random sequence */
|
uint8_t client_random[SSL_RANDOM_SIZE]; /* client's random sequence */
|
||||||
uint8_t server_random[SSL_RANDOM_SIZE]; /* server's random sequence */
|
uint8_t server_random[SSL_RANDOM_SIZE]; /* server's random sequence */
|
||||||
|
uint8_t final_finish_mac[128];
|
||||||
|
uint8_t master_secret[SSL_SECRET_SIZE];
|
||||||
|
uint8_t key_block[256];
|
||||||
uint16_t bm_proc_index;
|
uint16_t bm_proc_index;
|
||||||
|
uint8_t key_block_generated;
|
||||||
} DISPOSABLE_CTX;
|
} DISPOSABLE_CTX;
|
||||||
|
|
||||||
struct _SSL
|
struct _SSL
|
||||||
@ -180,6 +188,8 @@ struct _SSL
|
|||||||
uint16_t bm_index;
|
uint16_t bm_index;
|
||||||
uint16_t bm_read_index;
|
uint16_t bm_read_index;
|
||||||
size_t max_plain_length;
|
size_t max_plain_length;
|
||||||
|
uint8_t sig_algs[MAX_SIG_ALGORITHMS];
|
||||||
|
uint8_t num_sig_algs;
|
||||||
struct _SSL *next; /* doubly linked list */
|
struct _SSL *next; /* doubly linked list */
|
||||||
struct _SSL *prev;
|
struct _SSL *prev;
|
||||||
struct _SSL_CTX *ssl_ctx; /* back reference to a clnt/svr ctx */
|
struct _SSL_CTX *ssl_ctx; /* back reference to a clnt/svr ctx */
|
||||||
@ -192,10 +202,10 @@ struct _SSL
|
|||||||
bool can_free_certificates;
|
bool can_free_certificates;
|
||||||
#endif
|
#endif
|
||||||
uint8_t session_id[SSL_SESSION_ID_SIZE];
|
uint8_t session_id[SSL_SESSION_ID_SIZE];
|
||||||
uint8_t client_mac[SHA1_SIZE]; /* for HMAC verification */
|
uint8_t client_mac[SHA256_SIZE]; /* for HMAC verification */
|
||||||
uint8_t server_mac[SHA1_SIZE]; /* for HMAC verification */
|
uint8_t server_mac[SHA256_SIZE]; /* for HMAC verification */
|
||||||
uint8_t read_sequence[8]; /* 64 bit sequence number */
|
uint8_t read_sequence[8]; /* 64 bit sequence number */
|
||||||
uint8_t write_sequence[8]; /* 64 bit sequence number */
|
uint8_t write_sequence[8]; /* 64 bit sequence number */
|
||||||
uint8_t hmac_header[SSL_RECORD_SIZE]; /* rx hmac */
|
uint8_t hmac_header[SSL_RECORD_SIZE]; /* rx hmac */
|
||||||
char *host_name; /* Needed for the SNI support */
|
char *host_name; /* Needed for the SNI support */
|
||||||
};
|
};
|
||||||
@ -246,7 +256,7 @@ int send_finished(SSL *ssl);
|
|||||||
int send_certificate(SSL *ssl);
|
int send_certificate(SSL *ssl);
|
||||||
int basic_read(SSL *ssl, uint8_t **in_data);
|
int basic_read(SSL *ssl, uint8_t **in_data);
|
||||||
int send_change_cipher_spec(SSL *ssl);
|
int send_change_cipher_spec(SSL *ssl);
|
||||||
void finished_digest(SSL *ssl, const char *label, uint8_t *digest);
|
int finished_digest(SSL *ssl, const char *label, uint8_t *digest);
|
||||||
void generate_master_secret(SSL *ssl, const uint8_t *premaster_secret);
|
void generate_master_secret(SSL *ssl, const uint8_t *premaster_secret);
|
||||||
void add_packet(SSL *ssl, const uint8_t *pkt, int len);
|
void add_packet(SSL *ssl, const uint8_t *pkt, int len);
|
||||||
int add_cert(SSL_CTX *ssl_ctx, const uint8_t *buf, int len);
|
int add_cert(SSL_CTX *ssl_ctx, const uint8_t *buf, int len);
|
||||||
|
130
ssl/tls1_clnt.c
130
ssl/tls1_clnt.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2007, Cameron Rich
|
* Copyright (c) 2007-2016, Cameron Rich
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@ -37,6 +37,23 @@
|
|||||||
|
|
||||||
#ifdef CONFIG_SSL_ENABLE_CLIENT /* all commented out if no client */
|
#ifdef CONFIG_SSL_ENABLE_CLIENT /* all commented out if no client */
|
||||||
|
|
||||||
|
/* support sha512/384/256/1 RSA */
|
||||||
|
static const uint8_t g_sig_alg[] = {
|
||||||
|
0x00, 0x0e,
|
||||||
|
0x00, SIG_ALG_EXTENSION,
|
||||||
|
0x00, 0x0a, 0x00, 0x08,
|
||||||
|
SIG_ALG_SHA512, SIG_ALG_RSA,
|
||||||
|
SIG_ALG_SHA384, SIG_ALG_RSA,
|
||||||
|
SIG_ALG_SHA256, SIG_ALG_RSA,
|
||||||
|
SIG_ALG_SHA1, SIG_ALG_RSA
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t g_asn1_sha256[] =
|
||||||
|
{
|
||||||
|
0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
|
||||||
|
0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20
|
||||||
|
};
|
||||||
|
|
||||||
static int send_client_hello(SSL *ssl);
|
static int send_client_hello(SSL *ssl);
|
||||||
static int process_server_hello(SSL *ssl);
|
static int process_server_hello(SSL *ssl);
|
||||||
static int process_server_hello_done(SSL *ssl);
|
static int process_server_hello_done(SSL *ssl);
|
||||||
@ -227,27 +244,14 @@ static int send_client_hello(SSL *ssl)
|
|||||||
buf[offset++] = 1; /* no compression */
|
buf[offset++] = 1; /* no compression */
|
||||||
buf[offset++] = 0;
|
buf[offset++] = 0;
|
||||||
|
|
||||||
if (ssl->host_name != NULL) {
|
/* send the signature algorithm extension for TLS 1.2+ */
|
||||||
unsigned int host_len = strlen(ssl->host_name);
|
if (ssl->version >= SSL_PROTOCOL_VERSION_TLS1_2)
|
||||||
|
{
|
||||||
buf[offset++] = 0;
|
memcpy(&buf[offset], g_sig_alg, sizeof(g_sig_alg));
|
||||||
buf[offset++] = host_len+9; /* extensions length */
|
offset += sizeof(g_sig_alg);
|
||||||
|
|
||||||
buf[offset++] = 0;
|
|
||||||
buf[offset++] = 0; /* server_name(0) (65535) */
|
|
||||||
buf[offset++] = 0;
|
|
||||||
buf[offset++] = host_len+5; /* server_name length */
|
|
||||||
buf[offset++] = 0;
|
|
||||||
buf[offset++] = host_len+3; /* server_list length */
|
|
||||||
buf[offset++] = 0; /* host_name(0) (255) */
|
|
||||||
buf[offset++] = 0;
|
|
||||||
buf[offset++] = host_len; /* host_name length */
|
|
||||||
strncpy((char*) &buf[offset], ssl->host_name, host_len);
|
|
||||||
offset += host_len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buf[3] = offset - 4; /* handshake size */
|
buf[3] = offset - 4; /* handshake size */
|
||||||
|
|
||||||
return send_packet(ssl, PT_HANDSHAKE_PROTOCOL, NULL, offset);
|
return send_packet(ssl, PT_HANDSHAKE_PROTOCOL, NULL, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,15 +310,18 @@ static int process_server_hello(SSL *ssl)
|
|||||||
ssl->sess_id_size = sess_id_size;
|
ssl->sess_id_size = sess_id_size;
|
||||||
offset += sess_id_size;
|
offset += sess_id_size;
|
||||||
|
|
||||||
/* get the real cipher we are using */
|
/* get the real cipher we are using - ignore MSB */
|
||||||
ssl->cipher = buf[++offset];
|
ssl->cipher = buf[++offset];
|
||||||
ssl->next_state = IS_SET_SSL_FLAG(SSL_SESSION_RESUME) ?
|
ssl->next_state = IS_SET_SSL_FLAG(SSL_SESSION_RESUME) ?
|
||||||
HS_FINISHED : HS_CERTIFICATE;
|
HS_FINISHED : HS_CERTIFICATE;
|
||||||
|
|
||||||
offset++; // skip the compr
|
offset += 2; // ignore compression
|
||||||
PARANOIA_CHECK(pkt_size, offset);
|
PARANOIA_CHECK(pkt_size, offset);
|
||||||
ssl->dc->bm_proc_index = offset+1;
|
|
||||||
|
|
||||||
|
ssl->dc->bm_proc_index = offset+1;
|
||||||
|
PARANOIA_CHECK(pkt_size, offset);
|
||||||
|
|
||||||
|
// no extensions
|
||||||
error:
|
error:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -340,8 +347,10 @@ static int send_client_key_xchg(SSL *ssl)
|
|||||||
buf[0] = HS_CLIENT_KEY_XCHG;
|
buf[0] = HS_CLIENT_KEY_XCHG;
|
||||||
buf[1] = 0;
|
buf[1] = 0;
|
||||||
|
|
||||||
premaster_secret[0] = 0x03; /* encode the version number */
|
// spec says client must use the what is initially negotiated -
|
||||||
premaster_secret[1] = SSL_PROTOCOL_MINOR_VERSION; /* must be TLS 1.1 */
|
// and this is our current version
|
||||||
|
premaster_secret[0] = 0x03;
|
||||||
|
premaster_secret[1] = SSL_PROTOCOL_VERSION_MAX & 0x0f;
|
||||||
if (get_random(SSL_SECRET_SIZE-2, &premaster_secret[2]) < 0)
|
if (get_random(SSL_SECRET_SIZE-2, &premaster_secret[2]) < 0)
|
||||||
return SSL_NOT_OK;
|
return SSL_NOT_OK;
|
||||||
|
|
||||||
@ -369,14 +378,47 @@ static int process_cert_req(SSL *ssl)
|
|||||||
{
|
{
|
||||||
uint8_t *buf = &ssl->bm_data[ssl->dc->bm_proc_index];
|
uint8_t *buf = &ssl->bm_data[ssl->dc->bm_proc_index];
|
||||||
int ret = SSL_OK;
|
int ret = SSL_OK;
|
||||||
int offset = (buf[2] << 4) + buf[3];
|
int cert_req_size = (buf[2]<<8) + buf[3];
|
||||||
|
int offset = 4;
|
||||||
int pkt_size = ssl->bm_index;
|
int pkt_size = ssl->bm_index;
|
||||||
|
uint8_t cert_type_len, sig_alg_len;
|
||||||
|
|
||||||
|
PARANOIA_CHECK(pkt_size, offset + cert_req_size);
|
||||||
|
ssl->dc->bm_proc_index = cert_req_size;
|
||||||
|
|
||||||
/* don't do any processing - we will send back an RSA certificate anyway */
|
/* don't do any processing - we will send back an RSA certificate anyway */
|
||||||
ssl->next_state = HS_SERVER_HELLO_DONE;
|
ssl->next_state = HS_SERVER_HELLO_DONE;
|
||||||
SET_SSL_FLAG(SSL_HAS_CERT_REQ);
|
SET_SSL_FLAG(SSL_HAS_CERT_REQ);
|
||||||
ssl->dc->bm_proc_index += offset;
|
|
||||||
PARANOIA_CHECK(pkt_size, offset);
|
if (ssl->version >= SSL_PROTOCOL_VERSION_TLS1_2) // TLS1.2+
|
||||||
|
{
|
||||||
|
// supported certificate types
|
||||||
|
cert_type_len = buf[offset++];
|
||||||
|
PARANOIA_CHECK(pkt_size, offset + cert_type_len);
|
||||||
|
offset += cert_type_len;
|
||||||
|
|
||||||
|
// supported signature algorithms
|
||||||
|
sig_alg_len = buf[offset++] << 8;
|
||||||
|
sig_alg_len += buf[offset++];
|
||||||
|
PARANOIA_CHECK(pkt_size, offset + sig_alg_len);
|
||||||
|
|
||||||
|
while (sig_alg_len > 0)
|
||||||
|
{
|
||||||
|
uint8_t hash_alg = buf[offset++];
|
||||||
|
uint8_t sig_alg = buf[offset++];
|
||||||
|
sig_alg_len -= 2;
|
||||||
|
|
||||||
|
if (sig_alg == SIG_ALG_RSA &&
|
||||||
|
(hash_alg == SIG_ALG_SHA1 ||
|
||||||
|
hash_alg == SIG_ALG_SHA256 ||
|
||||||
|
hash_alg == SIG_ALG_SHA384 ||
|
||||||
|
hash_alg == SIG_ALG_SHA512))
|
||||||
|
{
|
||||||
|
ssl->sig_algs[ssl->num_sig_algs++] = hash_alg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -387,9 +429,11 @@ error:
|
|||||||
static int send_cert_verify(SSL *ssl)
|
static int send_cert_verify(SSL *ssl)
|
||||||
{
|
{
|
||||||
uint8_t *buf = ssl->bm_data;
|
uint8_t *buf = ssl->bm_data;
|
||||||
uint8_t dgst[MD5_SIZE+SHA1_SIZE];
|
uint8_t dgst[SHA1_SIZE+MD5_SIZE+15];
|
||||||
RSA_CTX *rsa_ctx = ssl->ssl_ctx->rsa_ctx;
|
RSA_CTX *rsa_ctx = ssl->ssl_ctx->rsa_ctx;
|
||||||
int n = 0, ret;
|
int n = 0, ret;
|
||||||
|
int offset = 0;
|
||||||
|
int dgst_len;
|
||||||
|
|
||||||
if (rsa_ctx == NULL)
|
if (rsa_ctx == NULL)
|
||||||
return SSL_OK;
|
return SSL_OK;
|
||||||
@ -399,13 +443,26 @@ static int send_cert_verify(SSL *ssl)
|
|||||||
buf[0] = HS_CERT_VERIFY;
|
buf[0] = HS_CERT_VERIFY;
|
||||||
buf[1] = 0;
|
buf[1] = 0;
|
||||||
|
|
||||||
finished_digest(ssl, NULL, dgst); /* calculate the digest */
|
if (ssl->version >= SSL_PROTOCOL_VERSION_TLS1_2) // TLS1.2+
|
||||||
|
{
|
||||||
|
buf[4] = SIG_ALG_SHA256;
|
||||||
|
buf[5] = SIG_ALG_RSA;
|
||||||
|
offset = 6;
|
||||||
|
memcpy(dgst, g_asn1_sha256, sizeof(g_asn1_sha256));
|
||||||
|
dgst_len = finished_digest(ssl, NULL, &dgst[sizeof(g_asn1_sha256)]) +
|
||||||
|
sizeof(g_asn1_sha256);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
offset = 4;
|
||||||
|
dgst_len = finished_digest(ssl, NULL, dgst);
|
||||||
|
}
|
||||||
|
|
||||||
/* rsa_ctx->bi_ctx is not thread-safe */
|
/* rsa_ctx->bi_ctx is not thread-safe */
|
||||||
if (rsa_ctx)
|
if (rsa_ctx)
|
||||||
{
|
{
|
||||||
SSL_CTX_LOCK(ssl->ssl_ctx->mutex);
|
SSL_CTX_LOCK(ssl->ssl_ctx->mutex);
|
||||||
n = RSA_encrypt(rsa_ctx, dgst, sizeof(dgst), &buf[6], 1);
|
n = RSA_encrypt(rsa_ctx, dgst, dgst_len, &buf[offset + 2], 1);
|
||||||
SSL_CTX_UNLOCK(ssl->ssl_ctx->mutex);
|
SSL_CTX_UNLOCK(ssl->ssl_ctx->mutex);
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
@ -415,12 +472,19 @@ static int send_cert_verify(SSL *ssl)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buf[4] = n >> 8; /* add the RSA size (not officially documented) */
|
buf[offset] = n >> 8; /* add the RSA size */
|
||||||
buf[5] = n & 0xff;
|
buf[offset+1] = n & 0xff;
|
||||||
n += 2;
|
n += 2;
|
||||||
|
|
||||||
|
if (ssl->version >= SSL_PROTOCOL_VERSION_TLS1_2) // TLS1.2+
|
||||||
|
{
|
||||||
|
n += 2; // sig/alg
|
||||||
|
offset -= 2;
|
||||||
|
}
|
||||||
|
|
||||||
buf[2] = n >> 8;
|
buf[2] = n >> 8;
|
||||||
buf[3] = n & 0xff;
|
buf[3] = n & 0xff;
|
||||||
ret = send_packet(ssl, PT_HANDSHAKE_PROTOCOL, NULL, n+4);
|
ret = send_packet(ssl, PT_HANDSHAKE_PROTOCOL, NULL, n + offset);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
return ret;
|
return ret;
|
||||||
|
216
ssl/tls1_svr.c
216
ssl/tls1_svr.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2007, Cameron Rich
|
* Copyright (c) 2007-2016, Cameron Rich
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@ -35,6 +35,11 @@
|
|||||||
#include "ssl.h"
|
#include "ssl.h"
|
||||||
|
|
||||||
static const uint8_t g_hello_done[] = { HS_SERVER_HELLO_DONE, 0, 0, 0 };
|
static const uint8_t g_hello_done[] = { HS_SERVER_HELLO_DONE, 0, 0, 0 };
|
||||||
|
static const uint8_t g_asn1_sha256[] =
|
||||||
|
{
|
||||||
|
0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
|
||||||
|
0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20
|
||||||
|
};
|
||||||
|
|
||||||
static int process_client_hello(SSL *ssl);
|
static int process_client_hello(SSL *ssl);
|
||||||
static int send_server_hello_sequence(SSL *ssl);
|
static int send_server_hello_sequence(SSL *ssl);
|
||||||
@ -154,7 +159,7 @@ static int process_client_hello(SSL *ssl)
|
|||||||
cs_len = (buf[offset]<<8) + buf[offset+1];
|
cs_len = (buf[offset]<<8) + buf[offset+1];
|
||||||
offset += 3; /* add 1 due to all cipher suites being 8 bit */
|
offset += 3; /* add 1 due to all cipher suites being 8 bit */
|
||||||
|
|
||||||
PARANOIA_CHECK(pkt_size, offset);
|
PARANOIA_CHECK(pkt_size, offset + cs_len);
|
||||||
|
|
||||||
/* work out what cipher suite we are going to use - client defines
|
/* work out what cipher suite we are going to use - client defines
|
||||||
the preference */
|
the preference */
|
||||||
@ -165,89 +170,75 @@ static int process_client_hello(SSL *ssl)
|
|||||||
if (ssl_prot_prefs[j] == buf[offset+i]) /* got a match? */
|
if (ssl_prot_prefs[j] == buf[offset+i]) /* got a match? */
|
||||||
{
|
{
|
||||||
ssl->cipher = ssl_prot_prefs[j];
|
ssl->cipher = ssl_prot_prefs[j];
|
||||||
goto do_state;
|
goto do_compression;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ouch! protocol is not supported */
|
/* ouch! protocol is not supported */
|
||||||
ret = SSL_ERROR_NO_CIPHER;
|
return SSL_ERROR_NO_CIPHER;
|
||||||
|
|
||||||
do_state:
|
/* completely ignore compression */
|
||||||
error:
|
do_compression:
|
||||||
return ret;
|
offset += cs_len;
|
||||||
}
|
id_len = buf[offset++];
|
||||||
|
|
||||||
#ifdef CONFIG_SSL_ENABLE_V23_HANDSHAKE
|
|
||||||
/*
|
|
||||||
* Some browsers use a hybrid SSLv2 "client hello"
|
|
||||||
*/
|
|
||||||
int process_sslv23_client_hello(SSL *ssl)
|
|
||||||
{
|
|
||||||
uint8_t *buf = ssl->bm_data;
|
|
||||||
int bytes_needed = ((buf[0] & 0x7f) << 8) + buf[1];
|
|
||||||
int ret = SSL_OK;
|
|
||||||
|
|
||||||
/* we have already read 3 extra bytes so far */
|
|
||||||
int read_len = SOCKET_READ(ssl->client_fd, buf, bytes_needed-3);
|
|
||||||
int cs_len = buf[1];
|
|
||||||
int id_len = buf[3];
|
|
||||||
int ch_len = buf[5];
|
|
||||||
int i, j, offset = 8; /* start at first cipher */
|
|
||||||
int random_offset = 0;
|
|
||||||
|
|
||||||
DISPLAY_BYTES(ssl, "received %d bytes", buf, read_len, read_len);
|
|
||||||
|
|
||||||
/* connection has gone, so die */
|
|
||||||
if (read_len < 0)
|
|
||||||
{
|
|
||||||
return SSL_ERROR_CONN_LOST;
|
|
||||||
}
|
|
||||||
|
|
||||||
add_packet(ssl, buf, read_len);
|
|
||||||
|
|
||||||
/* now work out what cipher suite we are going to use */
|
|
||||||
for (j = 0; j < NUM_PROTOCOLS; j++)
|
|
||||||
{
|
|
||||||
for (i = 0; i < cs_len; i += 3)
|
|
||||||
{
|
|
||||||
if (ssl_prot_prefs[j] == buf[offset+i])
|
|
||||||
{
|
|
||||||
ssl->cipher = ssl_prot_prefs[j];
|
|
||||||
goto server_hello;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ouch! protocol is not supported */
|
|
||||||
ret = SSL_ERROR_NO_CIPHER;
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
server_hello:
|
|
||||||
/* get the session id */
|
|
||||||
offset += cs_len - 2; /* we've gone 2 bytes past the end */
|
|
||||||
#ifndef CONFIG_SSL_SKELETON_MODE
|
|
||||||
ssl->session = ssl_session_update(ssl->ssl_ctx->num_sessions,
|
|
||||||
ssl->ssl_ctx->ssl_sessions, ssl, id_len ? &buf[offset] : NULL);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* get the client random data */
|
|
||||||
offset += id_len;
|
offset += id_len;
|
||||||
|
PARANOIA_CHECK(pkt_size, offset + id_len);
|
||||||
|
|
||||||
/* random can be anywhere between 16 and 32 bytes long - so it is padded
|
if (offset == pkt_size)
|
||||||
* with 0's to the left */
|
|
||||||
if (ch_len == 0x10)
|
|
||||||
{
|
{
|
||||||
random_offset += 0x10;
|
/* no extensions */
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&ssl->dc->client_random[random_offset], &buf[offset], ch_len);
|
/* extension size */
|
||||||
ret = send_server_hello_sequence(ssl);
|
id_len = buf[offset++] << 8;
|
||||||
|
id_len += buf[offset++];
|
||||||
|
PARANOIA_CHECK(pkt_size, offset + id_len);
|
||||||
|
|
||||||
|
// Check for extensions from the client - only the signature algorithm
|
||||||
|
// is supported
|
||||||
|
while (offset < pkt_size)
|
||||||
|
{
|
||||||
|
int ext = buf[offset++] << 8;
|
||||||
|
ext += buf[offset++];
|
||||||
|
int ext_len = buf[offset++] << 8;
|
||||||
|
ext_len += buf[offset++];
|
||||||
|
PARANOIA_CHECK(pkt_size, offset + ext_len);
|
||||||
|
|
||||||
|
if (ext == SIG_ALG_EXTENSION)
|
||||||
|
{
|
||||||
|
while (ext_len > 0)
|
||||||
|
{
|
||||||
|
uint8_t hash_alg = buf[offset++];
|
||||||
|
uint8_t sig_alg = buf[offset++];
|
||||||
|
ext_len -= 2;
|
||||||
|
|
||||||
|
if (sig_alg == SIG_ALG_RSA &&
|
||||||
|
(hash_alg == SIG_ALG_SHA1 ||
|
||||||
|
hash_alg == SIG_ALG_SHA256 ||
|
||||||
|
hash_alg == SIG_ALG_SHA384 ||
|
||||||
|
hash_alg == SIG_ALG_SHA512))
|
||||||
|
{
|
||||||
|
ssl->sig_algs[ssl->num_sig_algs++] = hash_alg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
offset += ext_len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* default is RSA/SHA1 */
|
||||||
|
if (ssl->num_sig_algs == 0)
|
||||||
|
{
|
||||||
|
ssl->sig_algs[ssl->num_sig_algs++] = SIG_ALG_SHA1;
|
||||||
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send the entire server hello sequence
|
* Send the entire server hello sequence
|
||||||
@ -350,7 +341,7 @@ static int send_server_hello(SSL *ssl)
|
|||||||
|
|
||||||
buf[offset++] = 0; /* cipher we are using */
|
buf[offset++] = 0; /* cipher we are using */
|
||||||
buf[offset++] = ssl->cipher;
|
buf[offset++] = ssl->cipher;
|
||||||
buf[offset++] = 0; /* no compression */
|
buf[offset++] = 0; /* no compression and no extensions supported */
|
||||||
buf[3] = offset - 4; /* handshake size */
|
buf[3] = offset - 4; /* handshake size */
|
||||||
return send_packet(ssl, PT_HANDSHAKE_PROTOCOL, NULL, offset);
|
return send_packet(ssl, PT_HANDSHAKE_PROTOCOL, NULL, offset);
|
||||||
}
|
}
|
||||||
@ -409,10 +400,6 @@ static int process_client_key_xchg(SSL *ssl)
|
|||||||
/* and continue - will die eventually when checking the mac */
|
/* and continue - will die eventually when checking the mac */
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
print_blob("pre-master", premaster_secret, SSL_SECRET_SIZE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
generate_master_secret(ssl, premaster_secret);
|
generate_master_secret(ssl, premaster_secret);
|
||||||
|
|
||||||
#ifdef CONFIG_SSL_CERT_VERIFICATION
|
#ifdef CONFIG_SSL_CERT_VERIFICATION
|
||||||
@ -428,15 +415,34 @@ error:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_SSL_CERT_VERIFICATION
|
#ifdef CONFIG_SSL_CERT_VERIFICATION
|
||||||
static const uint8_t g_cert_request[] = { HS_CERT_REQ, 0, 0, 4, 1, 0, 0, 0 };
|
static const uint8_t g_cert_request[] = { HS_CERT_REQ, 0,
|
||||||
|
0, 0x0e,
|
||||||
|
1, 1, // rsa sign
|
||||||
|
0x00, 0x08,
|
||||||
|
SIG_ALG_SHA256, SIG_ALG_RSA,
|
||||||
|
SIG_ALG_SHA512, SIG_ALG_RSA,
|
||||||
|
SIG_ALG_SHA384, SIG_ALG_RSA,
|
||||||
|
SIG_ALG_SHA1, SIG_ALG_RSA,
|
||||||
|
0, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t g_cert_request_v1[] = { HS_CERT_REQ, 0, 0, 4, 1, 0, 0, 0 };
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send the certificate request message.
|
* Send the certificate request message.
|
||||||
*/
|
*/
|
||||||
static int send_certificate_request(SSL *ssl)
|
static int send_certificate_request(SSL *ssl)
|
||||||
{
|
{
|
||||||
return send_packet(ssl, PT_HANDSHAKE_PROTOCOL,
|
if (ssl->version >= SSL_PROTOCOL_VERSION_TLS1_2) // TLS1.2+
|
||||||
|
{
|
||||||
|
return send_packet(ssl, PT_HANDSHAKE_PROTOCOL,
|
||||||
g_cert_request, sizeof(g_cert_request));
|
g_cert_request, sizeof(g_cert_request));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return send_packet(ssl, PT_HANDSHAKE_PROTOCOL,
|
||||||
|
g_cert_request_v1, sizeof(g_cert_request_v1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -448,29 +454,65 @@ static int process_cert_verify(SSL *ssl)
|
|||||||
uint8_t *buf = &ssl->bm_data[ssl->dc->bm_proc_index];
|
uint8_t *buf = &ssl->bm_data[ssl->dc->bm_proc_index];
|
||||||
int pkt_size = ssl->bm_index;
|
int pkt_size = ssl->bm_index;
|
||||||
uint8_t dgst_buf[MAX_KEY_BYTE_SIZE];
|
uint8_t dgst_buf[MAX_KEY_BYTE_SIZE];
|
||||||
uint8_t dgst[MD5_SIZE+SHA1_SIZE];
|
uint8_t dgst[MD5_SIZE + SHA1_SIZE];
|
||||||
X509_CTX *x509_ctx = ssl->x509_ctx;
|
X509_CTX *x509_ctx = ssl->x509_ctx;
|
||||||
int ret = SSL_OK;
|
int ret = SSL_OK;
|
||||||
|
int offset = 6;
|
||||||
|
int rsa_len;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
PARANOIA_CHECK(pkt_size, x509_ctx->rsa_ctx->num_octets+6);
|
|
||||||
DISPLAY_RSA(ssl, x509_ctx->rsa_ctx);
|
DISPLAY_RSA(ssl, x509_ctx->rsa_ctx);
|
||||||
|
|
||||||
|
if (ssl->version >= SSL_PROTOCOL_VERSION_TLS1_2) // TLS1.2+
|
||||||
|
{
|
||||||
|
// TODO: should really need to be able to handle other algorihms. An
|
||||||
|
// assumption is made on RSA/SHA256 and appears to be OK.
|
||||||
|
//uint8_t hash_alg = buf[4];
|
||||||
|
//uint8_t sig_alg = buf[5];
|
||||||
|
offset = 8;
|
||||||
|
rsa_len = (buf[6] << 8) + buf[7];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rsa_len = (buf[4] << 8) + buf[5];
|
||||||
|
}
|
||||||
|
|
||||||
|
PARANOIA_CHECK(pkt_size, offset + rsa_len);
|
||||||
|
|
||||||
/* rsa_ctx->bi_ctx is not thread-safe */
|
/* rsa_ctx->bi_ctx is not thread-safe */
|
||||||
SSL_CTX_LOCK(ssl->ssl_ctx->mutex);
|
SSL_CTX_LOCK(ssl->ssl_ctx->mutex);
|
||||||
n = RSA_decrypt(x509_ctx->rsa_ctx, &buf[6], dgst_buf, sizeof(dgst_buf), 0);
|
n = RSA_decrypt(x509_ctx->rsa_ctx, &buf[offset], dgst_buf,
|
||||||
|
sizeof(dgst_buf), 0);
|
||||||
SSL_CTX_UNLOCK(ssl->ssl_ctx->mutex);
|
SSL_CTX_UNLOCK(ssl->ssl_ctx->mutex);
|
||||||
|
|
||||||
if (n != SHA1_SIZE + MD5_SIZE)
|
if (ssl->version >= SSL_PROTOCOL_VERSION_TLS1_2) // TLS1.2+
|
||||||
{
|
{
|
||||||
ret = SSL_ERROR_INVALID_KEY;
|
if (memcmp(dgst_buf, g_asn1_sha256, sizeof(g_asn1_sha256)))
|
||||||
goto end_cert_vfy;
|
{
|
||||||
}
|
ret = SSL_ERROR_INVALID_KEY;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
finished_digest(ssl, NULL, dgst); /* calculate the digest */
|
finished_digest(ssl, NULL, dgst); /* calculate the digest */
|
||||||
if (memcmp(dgst_buf, dgst, MD5_SIZE + SHA1_SIZE))
|
if (memcmp(&dgst_buf[sizeof(g_asn1_sha256)], dgst, SHA256_SIZE))
|
||||||
|
{
|
||||||
|
ret = SSL_ERROR_INVALID_KEY;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // TLS1.0/1.1
|
||||||
{
|
{
|
||||||
ret = SSL_ERROR_INVALID_KEY;
|
if (n != SHA1_SIZE + MD5_SIZE)
|
||||||
|
{
|
||||||
|
ret = SSL_ERROR_INVALID_KEY;
|
||||||
|
goto end_cert_vfy;
|
||||||
|
}
|
||||||
|
|
||||||
|
finished_digest(ssl, NULL, dgst); /* calculate the digest */
|
||||||
|
if (memcmp(dgst_buf, dgst, MD5_SIZE + SHA1_SIZE))
|
||||||
|
{
|
||||||
|
ret = SSL_ERROR_INVALID_KEY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
end_cert_vfy:
|
end_cert_vfy:
|
||||||
|
@ -74,7 +74,9 @@ int x509_new(const uint8_t *cert, int *len, X509_CTX **ctx)
|
|||||||
int begin_tbs, end_tbs;
|
int begin_tbs, end_tbs;
|
||||||
int ret = X509_NOT_OK, offset = 0, cert_size = 0;
|
int ret = X509_NOT_OK, offset = 0, cert_size = 0;
|
||||||
X509_CTX *x509_ctx;
|
X509_CTX *x509_ctx;
|
||||||
|
#ifdef CONFIG_SSL_CERT_VERIFICATION /* only care if doing verification */
|
||||||
BI_CTX *bi_ctx;
|
BI_CTX *bi_ctx;
|
||||||
|
#endif
|
||||||
|
|
||||||
*ctx = (X509_CTX *)calloc(1, sizeof(X509_CTX));
|
*ctx = (X509_CTX *)calloc(1, sizeof(X509_CTX));
|
||||||
x509_ctx = *ctx;
|
x509_ctx = *ctx;
|
||||||
@ -117,7 +119,6 @@ int x509_new(const uint8_t *cert, int *len, X509_CTX **ctx)
|
|||||||
goto end_cert;
|
goto end_cert;
|
||||||
}
|
}
|
||||||
|
|
||||||
bi_ctx = x509_ctx->rsa_ctx->bi_ctx;
|
|
||||||
|
|
||||||
x509_ctx->fingerprint = malloc(SHA1_SIZE);
|
x509_ctx->fingerprint = malloc(SHA1_SIZE);
|
||||||
SHA1_CTX sha_fp_ctx;
|
SHA1_CTX sha_fp_ctx;
|
||||||
@ -126,6 +127,8 @@ int x509_new(const uint8_t *cert, int *len, X509_CTX **ctx)
|
|||||||
SHA1_Final(x509_ctx->fingerprint, &sha_fp_ctx);
|
SHA1_Final(x509_ctx->fingerprint, &sha_fp_ctx);
|
||||||
|
|
||||||
#ifdef CONFIG_SSL_CERT_VERIFICATION /* only care if doing verification */
|
#ifdef CONFIG_SSL_CERT_VERIFICATION /* only care if doing verification */
|
||||||
|
bi_ctx = x509_ctx->rsa_ctx->bi_ctx;
|
||||||
|
|
||||||
/* use the appropriate signature algorithm */
|
/* use the appropriate signature algorithm */
|
||||||
switch (x509_ctx->sig_type)
|
switch (x509_ctx->sig_type)
|
||||||
{
|
{
|
||||||
@ -524,9 +527,6 @@ void x509_print(const X509_CTX *cert, CA_CERT_CTX *ca_cert_ctx)
|
|||||||
printf("Sig Type:\t\t\t");
|
printf("Sig Type:\t\t\t");
|
||||||
switch (cert->sig_type)
|
switch (cert->sig_type)
|
||||||
{
|
{
|
||||||
case SIG_TYPE_MD2:
|
|
||||||
printf("MD2\n");
|
|
||||||
break;
|
|
||||||
case SIG_TYPE_MD5:
|
case SIG_TYPE_MD5:
|
||||||
printf("MD5\n");
|
printf("MD5\n");
|
||||||
break;
|
break;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# Copyright (c) 2007, Cameron Rich
|
# Copyright (c) 2007-2016, Cameron Rich
|
||||||
#
|
#
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
@ -56,7 +56,7 @@ prompt = no
|
|||||||
|
|
||||||
[ req_distinguished_name ]
|
[ req_distinguished_name ]
|
||||||
O = $PROJECT_NAME
|
O = $PROJECT_NAME
|
||||||
CN = 127.0.0.1
|
CN = localhost
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
cat > device_cert.conf << EOF
|
cat > device_cert.conf << EOF
|
||||||
@ -69,21 +69,16 @@ prompt = no
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
# private key generation
|
# private key generation
|
||||||
openssl genrsa -out axTLS.ca_key.pem 1024
|
openssl genrsa -out axTLS.ca_key.pem 2048
|
||||||
openssl genrsa -out axTLS.key_512.pem 512
|
|
||||||
openssl genrsa -out axTLS.key_1024.pem 1024
|
openssl genrsa -out axTLS.key_1024.pem 1024
|
||||||
openssl genrsa -out axTLS.key_1042.pem 1042
|
|
||||||
openssl genrsa -out axTLS.key_2048.pem 2048
|
openssl genrsa -out axTLS.key_2048.pem 2048
|
||||||
openssl genrsa -out axTLS.key_4096.pem 4096
|
openssl genrsa -out axTLS.key_4096.pem 4096
|
||||||
openssl genrsa -out axTLS.device_key.pem 1024
|
openssl genrsa -out axTLS.device_key.pem 1024
|
||||||
openssl genrsa -aes128 -passout pass:abcd -out axTLS.key_aes128.pem 512
|
openssl genrsa -aes128 -passout pass:abcd -out axTLS.key_aes128.pem 1024
|
||||||
openssl genrsa -aes256 -passout pass:abcd -out axTLS.key_aes256.pem 512
|
openssl genrsa -aes256 -passout pass:abcd -out axTLS.key_aes256.pem 1024
|
||||||
|
|
||||||
|
|
||||||
# convert private keys into DER format
|
# convert private keys into DER format
|
||||||
openssl rsa -in axTLS.key_512.pem -out axTLS.key_512 -outform DER
|
|
||||||
openssl rsa -in axTLS.key_1024.pem -out axTLS.key_1024 -outform DER
|
openssl rsa -in axTLS.key_1024.pem -out axTLS.key_1024 -outform DER
|
||||||
openssl rsa -in axTLS.key_1042.pem -out axTLS.key_1042 -outform DER
|
|
||||||
openssl rsa -in axTLS.key_2048.pem -out axTLS.key_2048 -outform DER
|
openssl rsa -in axTLS.key_2048.pem -out axTLS.key_2048 -outform DER
|
||||||
openssl rsa -in axTLS.key_4096.pem -out axTLS.key_4096 -outform DER
|
openssl rsa -in axTLS.key_4096.pem -out axTLS.key_4096 -outform DER
|
||||||
openssl rsa -in axTLS.device_key.pem -out axTLS.device_key -outform DER
|
openssl rsa -in axTLS.device_key.pem -out axTLS.device_key -outform DER
|
||||||
@ -91,12 +86,8 @@ openssl rsa -in axTLS.device_key.pem -out axTLS.device_key -outform DER
|
|||||||
# cert requests
|
# cert requests
|
||||||
openssl req -out axTLS.ca_x509.req -key axTLS.ca_key.pem -new \
|
openssl req -out axTLS.ca_x509.req -key axTLS.ca_key.pem -new \
|
||||||
-config ./ca_cert.conf
|
-config ./ca_cert.conf
|
||||||
openssl req -out axTLS.x509_512.req -key axTLS.key_512.pem -new \
|
|
||||||
-config ./certs.conf
|
|
||||||
openssl req -out axTLS.x509_1024.req -key axTLS.key_1024.pem -new \
|
openssl req -out axTLS.x509_1024.req -key axTLS.key_1024.pem -new \
|
||||||
-config ./certs.conf
|
-config ./certs.conf
|
||||||
openssl req -out axTLS.x509_1042.req -key axTLS.key_1042.pem -new \
|
|
||||||
-config ./certs.conf
|
|
||||||
openssl req -out axTLS.x509_2048.req -key axTLS.key_2048.pem -new \
|
openssl req -out axTLS.x509_2048.req -key axTLS.key_2048.pem -new \
|
||||||
-config ./certs.conf
|
-config ./certs.conf
|
||||||
openssl req -out axTLS.x509_4096.req -key axTLS.key_4096.pem -new \
|
openssl req -out axTLS.x509_4096.req -key axTLS.key_4096.pem -new \
|
||||||
@ -110,25 +101,32 @@ openssl req -out axTLS.x509_aes256.req -key axTLS.key_aes256.pem \
|
|||||||
|
|
||||||
# generate the actual certs.
|
# generate the actual certs.
|
||||||
openssl x509 -req -in axTLS.ca_x509.req -out axTLS.ca_x509.pem \
|
openssl x509 -req -in axTLS.ca_x509.req -out axTLS.ca_x509.pem \
|
||||||
-sha1 -days 5000 -signkey axTLS.ca_key.pem
|
-sha1 -days 5000 -signkey axTLS.ca_key.pem \
|
||||||
openssl x509 -req -in axTLS.x509_512.req -out axTLS.x509_512.pem \
|
-CAkey axTLS.ca_key.pem
|
||||||
-sha1 -CAcreateserial -days 5000 \
|
openssl x509 -req -in axTLS.ca_x509.req -out axTLS.ca_x509_sha256.pem \
|
||||||
-CA axTLS.ca_x509.pem -CAkey axTLS.ca_key.pem
|
-sha256 -days 5000 -signkey axTLS.ca_key.pem \
|
||||||
|
-CAkey axTLS.ca_key.pem
|
||||||
openssl x509 -req -in axTLS.x509_1024.req -out axTLS.x509_1024.pem \
|
openssl x509 -req -in axTLS.x509_1024.req -out axTLS.x509_1024.pem \
|
||||||
-sha1 -CAcreateserial -days 5000 \
|
-sha1 -CAcreateserial -days 5000 \
|
||||||
-CA axTLS.ca_x509.pem -CAkey axTLS.ca_key.pem
|
-CA axTLS.ca_x509.pem -CAkey axTLS.ca_key.pem
|
||||||
openssl x509 -req -in axTLS.x509_1042.req -out axTLS.x509_1042.pem \
|
openssl x509 -req -in axTLS.x509_1024.req -out axTLS.x509_1024_sha256.pem \
|
||||||
|
-sha256 -CAcreateserial -days 5000 \
|
||||||
|
-CA axTLS.ca_x509_sha256.pem -CAkey axTLS.ca_key.pem
|
||||||
|
openssl x509 -req -in axTLS.x509_1024.req -out axTLS.x509_1024_sha384.pem \
|
||||||
|
-sha384 -CAcreateserial -days 5000 \
|
||||||
|
-CA axTLS.ca_x509_sha256.pem -CAkey axTLS.ca_key.pem
|
||||||
|
openssl x509 -req -in axTLS.x509_1024.req -out axTLS.x509_1024_sha512.pem \
|
||||||
|
-sha512 -CAcreateserial -days 5000 \
|
||||||
|
-CA axTLS.ca_x509_sha256.pem -CAkey axTLS.ca_key.pem
|
||||||
|
openssl x509 -req -in axTLS.x509_2048.req -out axTLS.x509_2048.pem \
|
||||||
-sha1 -CAcreateserial -days 5000 \
|
-sha1 -CAcreateserial -days 5000 \
|
||||||
-CA axTLS.ca_x509.pem -CAkey axTLS.ca_key.pem
|
-CA axTLS.ca_x509.pem -CAkey axTLS.ca_key.pem
|
||||||
openssl x509 -req -in axTLS.x509_2048.req -out axTLS.x509_2048.pem \
|
|
||||||
-md5 -CAcreateserial -days 5000 \
|
|
||||||
-CA axTLS.ca_x509.pem -CAkey axTLS.ca_key.pem
|
|
||||||
openssl x509 -req -in axTLS.x509_4096.req -out axTLS.x509_4096.pem \
|
openssl x509 -req -in axTLS.x509_4096.req -out axTLS.x509_4096.pem \
|
||||||
-md5 -CAcreateserial -days 5000 \
|
-sha1 -CAcreateserial -days 5000 \
|
||||||
-CA axTLS.ca_x509.pem -CAkey axTLS.ca_key.pem
|
-CA axTLS.ca_x509.pem -CAkey axTLS.ca_key.pem
|
||||||
openssl x509 -req -in axTLS.x509_device.req -out axTLS.x509_device.pem \
|
openssl x509 -req -in axTLS.x509_device.req -out axTLS.x509_device.pem \
|
||||||
-sha1 -CAcreateserial -days 5000 \
|
-sha1 -CAcreateserial -days 5000 \
|
||||||
-CA axTLS.x509_512.pem -CAkey axTLS.key_512.pem
|
-CA axTLS.x509_1024.pem -CAkey axTLS.key_1024.pem
|
||||||
openssl x509 -req -in axTLS.x509_aes128.req \
|
openssl x509 -req -in axTLS.x509_aes128.req \
|
||||||
-out axTLS.x509_aes128.pem \
|
-out axTLS.x509_aes128.pem \
|
||||||
-sha1 -CAcreateserial -days 5000 \
|
-sha1 -CAcreateserial -days 5000 \
|
||||||
@ -141,35 +139,33 @@ openssl x509 -req -in axTLS.x509_aes256.req \
|
|||||||
# note: must be root to do this
|
# note: must be root to do this
|
||||||
DATE_NOW=`date`
|
DATE_NOW=`date`
|
||||||
if date -s "Jan 1 2025"; then
|
if date -s "Jan 1 2025"; then
|
||||||
openssl x509 -req -in axTLS.x509_512.req -out axTLS.x509_bad_before.pem \
|
openssl x509 -req -in axTLS.x509_1024.req -out axTLS.x509_bad_before.pem \
|
||||||
-sha1 -CAcreateserial -days 365 \
|
-sha1 -CAcreateserial -days 365 \
|
||||||
-CA axTLS.ca_x509.pem -CAkey axTLS.ca_key.pem
|
-CA axTLS.ca_x509.pem -CAkey axTLS.ca_key.pem
|
||||||
date -s "$DATE_NOW"
|
date -s "$DATE_NOW"
|
||||||
touch axTLS.x509_bad_before.pem
|
touch axTLS.x509_bad_before.pem
|
||||||
fi
|
fi
|
||||||
openssl x509 -req -in axTLS.x509_512.req -out axTLS.x509_bad_after.pem \
|
openssl x509 -req -in axTLS.x509_1024.req -out axTLS.x509_bad_after.pem \
|
||||||
-sha1 -CAcreateserial -days -365 \
|
-sha1 -CAcreateserial -days -365 \
|
||||||
-CA axTLS.ca_x509.pem -CAkey axTLS.ca_key.pem
|
-CA axTLS.ca_x509.pem -CAkey axTLS.ca_key.pem
|
||||||
|
|
||||||
# some cleanup
|
# some cleanup
|
||||||
rm axTLS*.req
|
rm axTLS*.req
|
||||||
rm axTLS.srl
|
rm *.srl
|
||||||
rm *.conf
|
rm *.conf
|
||||||
|
|
||||||
# need this for the client tests
|
# need this for the client tests
|
||||||
openssl x509 -in axTLS.ca_x509.pem -outform DER -out axTLS.ca_x509.cer
|
openssl x509 -in axTLS.ca_x509.pem -outform DER -out axTLS.ca_x509.cer
|
||||||
openssl x509 -in axTLS.x509_512.pem -outform DER -out axTLS.x509_512.cer
|
|
||||||
openssl x509 -in axTLS.x509_1024.pem -outform DER -out axTLS.x509_1024.cer
|
openssl x509 -in axTLS.x509_1024.pem -outform DER -out axTLS.x509_1024.cer
|
||||||
openssl x509 -in axTLS.x509_1042.pem -outform DER -out axTLS.x509_1042.cer
|
|
||||||
openssl x509 -in axTLS.x509_2048.pem -outform DER -out axTLS.x509_2048.cer
|
openssl x509 -in axTLS.x509_2048.pem -outform DER -out axTLS.x509_2048.cer
|
||||||
openssl x509 -in axTLS.x509_4096.pem -outform DER -out axTLS.x509_4096.cer
|
openssl x509 -in axTLS.x509_4096.pem -outform DER -out axTLS.x509_4096.cer
|
||||||
openssl x509 -in axTLS.x509_device.pem -outform DER -out axTLS.x509_device.cer
|
openssl x509 -in axTLS.x509_device.pem -outform DER -out axTLS.x509_device.cer
|
||||||
|
|
||||||
# generate pkcs8 files (use RC4-128 for encryption)
|
# generate pkcs8 files (use RC4-128 for encryption)
|
||||||
openssl pkcs8 -in axTLS.key_512.pem -passout pass:abcd -topk8 -v1 PBE-SHA1-RC4-128 -out axTLS.encrypted_pem.p8
|
openssl pkcs8 -in axTLS.key_1024.pem -passout pass:abcd -topk8 -v1 PBE-SHA1-RC4-128 -out axTLS.encrypted_pem.p8
|
||||||
openssl pkcs8 -in axTLS.key_512.pem -passout pass:abcd -topk8 -outform DER -v1 PBE-SHA1-RC4-128 -out axTLS.encrypted.p8
|
openssl pkcs8 -in axTLS.key_1024.pem -passout pass:abcd -topk8 -outform DER -v1 PBE-SHA1-RC4-128 -out axTLS.encrypted.p8
|
||||||
openssl pkcs8 -in axTLS.key_512.pem -nocrypt -topk8 -out axTLS.unencrypted_pem.p8
|
openssl pkcs8 -in axTLS.key_1024.pem -nocrypt -topk8 -out axTLS.unencrypted_pem.p8
|
||||||
openssl pkcs8 -in axTLS.key_512.pem -nocrypt -topk8 -outform DER -out axTLS.unencrypted.p8
|
openssl pkcs8 -in axTLS.key_1024.pem -nocrypt -topk8 -outform DER -out axTLS.unencrypted.p8
|
||||||
|
|
||||||
# generate pkcs12 files (use RC4-128 for encryption)
|
# generate pkcs12 files (use RC4-128 for encryption)
|
||||||
openssl pkcs12 -export -in axTLS.x509_1024.pem -inkey axTLS.key_1024.pem -certfile axTLS.ca_x509.pem -keypbe PBE-SHA1-RC4-128 -certpbe PBE-SHA1-RC4-128 -name "p12_with_CA" -out axTLS.withCA.p12 -password pass:abcd
|
openssl pkcs12 -export -in axTLS.x509_1024.pem -inkey axTLS.key_1024.pem -certfile axTLS.ca_x509.pem -keypbe PBE-SHA1-RC4-128 -certpbe PBE-SHA1-RC4-128 -name "p12_with_CA" -out axTLS.withCA.p12 -password pass:abcd
|
||||||
|
Reference in New Issue
Block a user