mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
adding authentication, AES alignment issue, MACRO issue
git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@59 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
This commit is contained in:
71
ssl/loader.c
71
ssl/loader.c
@ -169,22 +169,6 @@ void ssl_obj_free(SSLObjLoader *ssl_obj)
|
||||
#define IS_ENCRYPTED_PRIVATE_KEY 1
|
||||
#define IS_CERTIFICATE 2
|
||||
|
||||
/* base64 to binary lookup table */
|
||||
static const uint8_t map[128] =
|
||||
{
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63,
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255,
|
||||
255, 254, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6,
|
||||
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255,
|
||||
255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
|
||||
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
|
||||
49, 50, 51, 255, 255, 255, 255, 255
|
||||
};
|
||||
|
||||
static const char * const begins[NUM_PEM_TYPES] =
|
||||
{
|
||||
"-----BEGIN RSA PRIVATE KEY-----",
|
||||
@ -205,59 +189,6 @@ static const char * const aes_str[2] =
|
||||
"DEK-Info: AES-256-CBC,"
|
||||
};
|
||||
|
||||
static int base64_decode(const uint8_t *in, int len,
|
||||
uint8_t *out, int *outlen)
|
||||
{
|
||||
int g, t, x, y, z;
|
||||
uint8_t c;
|
||||
int ret = -1;
|
||||
|
||||
g = 3;
|
||||
for (x = y = z = t = 0; x < len; x++)
|
||||
{
|
||||
if ((c = map[in[x] & 0x7F]) == 0xff)
|
||||
continue;
|
||||
|
||||
if (c == 254) /* this is the end... */
|
||||
{
|
||||
c = 0;
|
||||
|
||||
if (--g < 0)
|
||||
goto error;
|
||||
}
|
||||
else if (g != 3) /* only allow = at end */
|
||||
goto error;
|
||||
|
||||
t = (t<<6) | c;
|
||||
|
||||
if (++y == 4)
|
||||
{
|
||||
out[z++] = (uint8_t)((t>>16)&255);
|
||||
|
||||
if (g > 1)
|
||||
out[z++] = (uint8_t)((t>>8)&255);
|
||||
|
||||
if (g > 2)
|
||||
out[z++] = (uint8_t)(t&255);
|
||||
|
||||
y = t = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (y != 0)
|
||||
goto error;
|
||||
|
||||
*outlen = z;
|
||||
ret = 0;
|
||||
|
||||
error:
|
||||
#ifdef CONFIG_SSL_FULL_MODE
|
||||
if (ret < 0)
|
||||
printf("Error: Invalid base64 file\n");
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a base64 blob of data and decrypt it (using AES) into its
|
||||
* proper ASN.1 form.
|
||||
@ -372,7 +303,7 @@ static int new_pem_obj(SSLCTX *ssl_ctx, int is_cacert, uint8_t *where,
|
||||
strstr((const char *)start, "4,ENCRYPTED"))
|
||||
{
|
||||
/* check for encrypted PEM file */
|
||||
if ((pem_size = pem_decrypt(start, end, password, ssl_obj)) < 0)
|
||||
if (pem_decrypt(start, end, password, ssl_obj) < 0)
|
||||
goto error;
|
||||
}
|
||||
else if (base64_decode(start, pem_size,
|
||||
|
Reference in New Issue
Block a user