New Makefile structure; added compatibility with Windows + Visual C + nmake.
This commit is contained in:
parent
2f454aad57
commit
3f00688b9d
29 changed files with 2240 additions and 1069 deletions
|
|
@ -58,7 +58,7 @@ t0_parse7E_signed(const unsigned char **p)
|
|||
#define T0_INT4(x) T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0)
|
||||
#define T0_INT5(x) T0_SBYTE(x), T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0)
|
||||
|
||||
static const uint8_t t0_datablock[];
|
||||
/* static const unsigned char t0_datablock[]; */
|
||||
|
||||
|
||||
void br_pem_decoder_init_main(void *t0ctx);
|
||||
|
|
@ -109,12 +109,12 @@ br_pem_decoder_event(br_pem_decoder_context *ctx)
|
|||
|
||||
|
||||
|
||||
static const uint8_t t0_datablock[] = {
|
||||
static const unsigned char t0_datablock[] = {
|
||||
0x00, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20,
|
||||
0x00, 0x2D, 0x2D, 0x2D, 0x2D, 0x45, 0x4E, 0x44, 0x20, 0x00
|
||||
};
|
||||
|
||||
static const uint8_t t0_codeblock[] = {
|
||||
static const unsigned char t0_codeblock[] = {
|
||||
0x00, 0x01, 0x00, 0x09, 0x00, 0x00, 0x01, 0x01, 0x07, 0x00, 0x00, 0x01,
|
||||
0x01, 0x08, 0x00, 0x00, 0x13, 0x13, 0x00, 0x00, 0x01,
|
||||
T0_INT2(offsetof(br_pem_decoder_context, event)), 0x00, 0x00, 0x01,
|
||||
|
|
|
|||
11
src/inner.h
11
src/inner.h
|
|
@ -31,6 +31,15 @@
|
|||
#include "config.h"
|
||||
#include "bearssl.h"
|
||||
|
||||
/*
|
||||
* On MSVC, disable the warning about applying unary minus on an
|
||||
* unsigned type: it is standard, we do it all the time, and for
|
||||
* good reasons.
|
||||
*/
|
||||
#if _MSC_VER
|
||||
#pragma warning( disable : 4146 )
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Maximum size for a RSA modulus (in bits). Allocated stack buffers
|
||||
* depend on that size, so this value should be kept small. Currently,
|
||||
|
|
@ -300,7 +309,7 @@ static inline void
|
|||
br_multihash_copyimpl(br_multihash_context *dst,
|
||||
const br_multihash_context *src)
|
||||
{
|
||||
memcpy(dst->impl, src->impl, sizeof src->impl);
|
||||
memcpy((void *)dst->impl, src->impl, sizeof src->impl);
|
||||
}
|
||||
|
||||
/* ==================================================================== */
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ t0_parse7E_signed(const unsigned char **p)
|
|||
#define T0_INT4(x) T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0)
|
||||
#define T0_INT5(x) T0_SBYTE(x), T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0)
|
||||
|
||||
static const uint8_t t0_datablock[];
|
||||
/* static const unsigned char t0_datablock[]; */
|
||||
|
||||
|
||||
void br_ssl_hs_client_init_main(void *t0ctx);
|
||||
|
|
@ -416,7 +416,7 @@ make_client_sign(br_ssl_client_context *ctx)
|
|||
|
||||
|
||||
|
||||
static const uint8_t t0_datablock[] = {
|
||||
static const unsigned char t0_datablock[] = {
|
||||
0x00, 0x00, 0x0A, 0x00, 0x24, 0x00, 0x2F, 0x01, 0x24, 0x00, 0x35, 0x02,
|
||||
0x24, 0x00, 0x3C, 0x01, 0x44, 0x00, 0x3D, 0x02, 0x44, 0x00, 0x9C, 0x03,
|
||||
0x04, 0x00, 0x9D, 0x04, 0x05, 0xC0, 0x03, 0x40, 0x24, 0xC0, 0x04, 0x41,
|
||||
|
|
@ -432,7 +432,7 @@ static const uint8_t t0_datablock[] = {
|
|||
0x04, 0xCC, 0xA9, 0x25, 0x04, 0x00, 0x00
|
||||
};
|
||||
|
||||
static const uint8_t t0_codeblock[] = {
|
||||
static const unsigned char t0_codeblock[] = {
|
||||
0x00, 0x01, 0x00, 0x0A, 0x00, 0x00, 0x01, 0x00, 0x0D, 0x00, 0x00, 0x01,
|
||||
0x00, 0x0E, 0x00, 0x00, 0x01, 0x00, 0x0F, 0x00, 0x00, 0x01, 0x01, 0x08,
|
||||
0x00, 0x00, 0x01, 0x01, 0x09, 0x00, 0x00, 0x01, 0x02, 0x08, 0x00, 0x00,
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ t0_parse7E_signed(const unsigned char **p)
|
|||
#define T0_INT4(x) T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0)
|
||||
#define T0_INT5(x) T0_SBYTE(x), T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0)
|
||||
|
||||
static const uint8_t t0_datablock[];
|
||||
/* static const unsigned char t0_datablock[]; */
|
||||
|
||||
|
||||
void br_ssl_hs_server_init_main(void *t0ctx);
|
||||
|
|
@ -445,7 +445,7 @@ verify_CV_sig(br_ssl_server_context *ctx, size_t sig_len)
|
|||
|
||||
|
||||
|
||||
static const uint8_t t0_datablock[] = {
|
||||
static const unsigned char t0_datablock[] = {
|
||||
0x00, 0x00, 0x0A, 0x00, 0x24, 0x00, 0x2F, 0x01, 0x24, 0x00, 0x35, 0x02,
|
||||
0x24, 0x00, 0x3C, 0x01, 0x44, 0x00, 0x3D, 0x02, 0x44, 0x00, 0x9C, 0x03,
|
||||
0x04, 0x00, 0x9D, 0x04, 0x05, 0xC0, 0x03, 0x40, 0x24, 0xC0, 0x04, 0x41,
|
||||
|
|
@ -461,7 +461,7 @@ static const uint8_t t0_datablock[] = {
|
|||
0x04, 0xCC, 0xA9, 0x25, 0x04, 0x00, 0x00
|
||||
};
|
||||
|
||||
static const uint8_t t0_codeblock[] = {
|
||||
static const unsigned char t0_codeblock[] = {
|
||||
0x00, 0x01, 0x00, 0x0B, 0x00, 0x00, 0x01, 0x00, 0x0E, 0x00, 0x00, 0x01,
|
||||
0x00, 0x0F, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x01, 0x01, 0x08,
|
||||
0x00, 0x00, 0x01, 0x01, 0x09, 0x00, 0x00, 0x01, 0x02, 0x08, 0x00, 0x00,
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ t0_parse7E_signed(const unsigned char **p)
|
|||
#define T0_INT4(x) T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0)
|
||||
#define T0_INT5(x) T0_SBYTE(x), T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0)
|
||||
|
||||
static const uint8_t t0_datablock[];
|
||||
/* static const unsigned char t0_datablock[]; */
|
||||
|
||||
|
||||
void br_skey_decoder_init_main(void *t0ctx);
|
||||
|
|
@ -101,14 +101,14 @@ br_skey_decoder_push(br_skey_decoder_context *ctx,
|
|||
|
||||
|
||||
|
||||
static const uint8_t t0_datablock[] = {
|
||||
static const unsigned char t0_datablock[] = {
|
||||
0x00, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x07,
|
||||
0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x08, 0x2A, 0x86, 0x48, 0xCE,
|
||||
0x3D, 0x03, 0x01, 0x07, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x22, 0x05, 0x2B,
|
||||
0x81, 0x04, 0x00, 0x23
|
||||
};
|
||||
|
||||
static const uint8_t t0_codeblock[] = {
|
||||
static const unsigned char t0_codeblock[] = {
|
||||
0x00, 0x01, 0x01, 0x07, 0x00, 0x00, 0x01, 0x01, 0x08, 0x00, 0x00, 0x13,
|
||||
0x13, 0x00, 0x00, 0x01, T0_INT1(BR_ERR_X509_BAD_TAG_CLASS), 0x00, 0x00,
|
||||
0x01, T0_INT1(BR_ERR_X509_BAD_TAG_VALUE), 0x00, 0x00, 0x01,
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ t0_parse7E_signed(const unsigned char **p)
|
|||
#define T0_INT4(x) T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0)
|
||||
#define T0_INT5(x) T0_SBYTE(x), T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0)
|
||||
|
||||
static const uint8_t t0_datablock[];
|
||||
/* static const unsigned char t0_datablock[]; */
|
||||
|
||||
|
||||
void br_x509_decoder_init_main(void *t0ctx);
|
||||
|
|
@ -110,7 +110,7 @@ br_x509_decoder_push(br_x509_decoder_context *ctx,
|
|||
|
||||
|
||||
|
||||
static const uint8_t t0_datablock[] = {
|
||||
static const unsigned char t0_datablock[] = {
|
||||
0x00, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x09,
|
||||
0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05, 0x09, 0x2A, 0x86,
|
||||
0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0E, 0x09, 0x2A, 0x86, 0x48, 0x86,
|
||||
|
|
@ -129,7 +129,7 @@ static const uint8_t t0_datablock[] = {
|
|||
0x29, 0xFF, 0x03, 0x55, 0x1D, 0x13
|
||||
};
|
||||
|
||||
static const uint8_t t0_codeblock[] = {
|
||||
static const unsigned char t0_codeblock[] = {
|
||||
0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x01, 0x00, 0x11, 0x00, 0x00, 0x01,
|
||||
0x01, 0x09, 0x00, 0x00, 0x01, 0x01, 0x0A, 0x00, 0x00, 0x1A, 0x1A, 0x00,
|
||||
0x00, 0x01, T0_INT1(BR_ERR_X509_BAD_BOOLEAN), 0x00, 0x00, 0x01,
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ t0_parse7E_signed(const unsigned char **p)
|
|||
#define T0_INT4(x) T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0)
|
||||
#define T0_INT5(x) T0_SBYTE(x), T0_VBYTE(x, 21), T0_VBYTE(x, 14), T0_VBYTE(x, 7), T0_FBYTE(x, 0)
|
||||
|
||||
static const uint8_t t0_datablock[];
|
||||
/* static const unsigned char t0_datablock[]; */
|
||||
|
||||
|
||||
void br_x509_minimal_init_main(void *t0ctx);
|
||||
|
|
@ -392,55 +392,6 @@ eqbigint(const unsigned char *b1, size_t len1,
|
|||
return memcmp(b1, b2, len1) == 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify the signature on the certificate with the provided public key.
|
||||
* This function checks the public key type with regards to the expected
|
||||
* type. Returned value is either 0 on success, or a non-zero error code.
|
||||
*/
|
||||
static int
|
||||
verify_signature(br_x509_minimal_context *ctx, const br_x509_pkey *pk)
|
||||
{
|
||||
int kt;
|
||||
|
||||
kt = ctx->cert_signer_key_type;
|
||||
if ((pk->key_type & 0x0F) != kt) {
|
||||
return BR_ERR_X509_WRONG_KEY_TYPE;
|
||||
}
|
||||
switch (kt) {
|
||||
unsigned char tmp[64];
|
||||
|
||||
case BR_KEYTYPE_RSA:
|
||||
if (ctx->irsa == 0) {
|
||||
return BR_ERR_X509_UNSUPPORTED;
|
||||
}
|
||||
if (!ctx->irsa(ctx->cert_sig, ctx->cert_sig_len,
|
||||
&t0_datablock[ctx->cert_sig_hash_oid],
|
||||
ctx->cert_sig_hash_len, &pk->key.rsa, tmp))
|
||||
{
|
||||
return BR_ERR_X509_BAD_SIGNATURE;
|
||||
}
|
||||
if (memcmp(ctx->tbs_hash, tmp, ctx->cert_sig_hash_len) != 0) {
|
||||
return BR_ERR_X509_BAD_SIGNATURE;
|
||||
}
|
||||
return 0;
|
||||
|
||||
case BR_KEYTYPE_EC:
|
||||
if (ctx->iecdsa == 0) {
|
||||
return BR_ERR_X509_UNSUPPORTED;
|
||||
}
|
||||
if (!ctx->iecdsa(ctx->iec, ctx->tbs_hash,
|
||||
ctx->cert_sig_hash_len, &pk->key.ec,
|
||||
ctx->cert_sig, ctx->cert_sig_len))
|
||||
{
|
||||
return BR_ERR_X509_BAD_SIGNATURE;
|
||||
}
|
||||
return 0;
|
||||
|
||||
default:
|
||||
return BR_ERR_X509_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare two strings for equality, in a case-insensitive way. This
|
||||
* function handles casing only for ASCII letters.
|
||||
|
|
@ -470,9 +421,12 @@ eqnocase(const void *s1, const void *s2, size_t len)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int verify_signature(br_x509_minimal_context *ctx,
|
||||
const br_x509_pkey *pk);
|
||||
|
||||
|
||||
static const uint8_t t0_datablock[] = {
|
||||
|
||||
static const unsigned char t0_datablock[] = {
|
||||
0x00, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x09,
|
||||
0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05, 0x09, 0x2A, 0x86,
|
||||
0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0E, 0x09, 0x2A, 0x86, 0x48, 0x86,
|
||||
|
|
@ -499,7 +453,7 @@ static const uint8_t t0_datablock[] = {
|
|||
0x01, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x01, 0x0B
|
||||
};
|
||||
|
||||
static const uint8_t t0_codeblock[] = {
|
||||
static const unsigned char t0_codeblock[] = {
|
||||
0x00, 0x01, 0x00, 0x0D, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x01,
|
||||
0x00, 0x11, 0x00, 0x00, 0x01, 0x01, 0x09, 0x00, 0x00, 0x01, 0x01, 0x0A,
|
||||
0x00, 0x00, 0x24, 0x24, 0x00, 0x00, 0x01,
|
||||
|
|
@ -1704,3 +1658,56 @@ t0_exit:
|
|||
((t0_context *)t0ctx)->rp = rp;
|
||||
((t0_context *)t0ctx)->ip = ip;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Verify the signature on the certificate with the provided public key.
|
||||
* This function checks the public key type with regards to the expected
|
||||
* type. Returned value is either 0 on success, or a non-zero error code.
|
||||
*/
|
||||
static int
|
||||
verify_signature(br_x509_minimal_context *ctx, const br_x509_pkey *pk)
|
||||
{
|
||||
int kt;
|
||||
|
||||
kt = ctx->cert_signer_key_type;
|
||||
if ((pk->key_type & 0x0F) != kt) {
|
||||
return BR_ERR_X509_WRONG_KEY_TYPE;
|
||||
}
|
||||
switch (kt) {
|
||||
unsigned char tmp[64];
|
||||
|
||||
case BR_KEYTYPE_RSA:
|
||||
if (ctx->irsa == 0) {
|
||||
return BR_ERR_X509_UNSUPPORTED;
|
||||
}
|
||||
if (!ctx->irsa(ctx->cert_sig, ctx->cert_sig_len,
|
||||
&t0_datablock[ctx->cert_sig_hash_oid],
|
||||
ctx->cert_sig_hash_len, &pk->key.rsa, tmp))
|
||||
{
|
||||
return BR_ERR_X509_BAD_SIGNATURE;
|
||||
}
|
||||
if (memcmp(ctx->tbs_hash, tmp, ctx->cert_sig_hash_len) != 0) {
|
||||
return BR_ERR_X509_BAD_SIGNATURE;
|
||||
}
|
||||
return 0;
|
||||
|
||||
case BR_KEYTYPE_EC:
|
||||
if (ctx->iecdsa == 0) {
|
||||
return BR_ERR_X509_UNSUPPORTED;
|
||||
}
|
||||
if (!ctx->iecdsa(ctx->iec, ctx->tbs_hash,
|
||||
ctx->cert_sig_hash_len, &pk->key.ec,
|
||||
ctx->cert_sig, ctx->cert_sig_len))
|
||||
{
|
||||
return BR_ERR_X509_BAD_SIGNATURE;
|
||||
}
|
||||
return 0;
|
||||
|
||||
default:
|
||||
return BR_ERR_X509_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -341,6 +341,42 @@ eqbigint(const unsigned char *b1, size_t len1,
|
|||
return memcmp(b1, b2, len1) == 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare two strings for equality, in a case-insensitive way. This
|
||||
* function handles casing only for ASCII letters.
|
||||
*/
|
||||
static int
|
||||
eqnocase(const void *s1, const void *s2, size_t len)
|
||||
{
|
||||
const unsigned char *buf1, *buf2;
|
||||
|
||||
buf1 = s1;
|
||||
buf2 = s2;
|
||||
while (len -- > 0) {
|
||||
int x1, x2;
|
||||
|
||||
x1 = *buf1 ++;
|
||||
x2 = *buf2 ++;
|
||||
if (x1 >= 'A' && x1 <= 'Z') {
|
||||
x1 += 'a' - 'A';
|
||||
}
|
||||
if (x2 >= 'A' && x2 <= 'Z') {
|
||||
x2 += 'a' - 'A';
|
||||
}
|
||||
if (x1 != x2) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int verify_signature(br_x509_minimal_context *ctx,
|
||||
const br_x509_pkey *pk);
|
||||
|
||||
}
|
||||
|
||||
postamble {
|
||||
|
||||
/*
|
||||
* Verify the signature on the certificate with the provided public key.
|
||||
* This function checks the public key type with regards to the expected
|
||||
|
|
@ -390,35 +426,6 @@ verify_signature(br_x509_minimal_context *ctx, const br_x509_pkey *pk)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare two strings for equality, in a case-insensitive way. This
|
||||
* function handles casing only for ASCII letters.
|
||||
*/
|
||||
static int
|
||||
eqnocase(const void *s1, const void *s2, size_t len)
|
||||
{
|
||||
const unsigned char *buf1, *buf2;
|
||||
|
||||
buf1 = s1;
|
||||
buf2 = s2;
|
||||
while (len -- > 0) {
|
||||
int x1, x2;
|
||||
|
||||
x1 = *buf1 ++;
|
||||
x2 = *buf2 ++;
|
||||
if (x1 >= 'A' && x1 <= 'Z') {
|
||||
x1 += 'a' - 'A';
|
||||
}
|
||||
if (x2 >= 'A' && x2 <= 'Z') {
|
||||
x2 += 'a' - 'A';
|
||||
}
|
||||
if (x1 != x2) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cc: read8-low ( -- x ) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue