Initial import.

This commit is contained in:
Thomas Pornin 2016-11-02 19:01:13 -04:00
commit 3210f38e04
292 changed files with 58526 additions and 0 deletions

5155
test/test_crypto.c Normal file

File diff suppressed because it is too large Load diff

482
test/test_math.c Normal file
View file

@ -0,0 +1,482 @@
/*
* Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
#include <gmp.h>
#include "bearssl.h"
#include "inner.h"
/*
* Pointers to implementations.
*/
typedef struct {
uint32_t word_size;
void (*zero)(uint32_t *x, uint32_t bit_len);
void (*decode)(uint32_t *x, const void *src, size_t len);
uint32_t (*decode_mod)(uint32_t *x,
const void *src, size_t len, const uint32_t *m);
void (*reduce)(uint32_t *x, const uint32_t *a, const uint32_t *m);
void (*decode_reduce)(uint32_t *x,
const void *src, size_t len, const uint32_t *m);
void (*encode)(void *dst, size_t len, const uint32_t *x);
uint32_t (*add)(uint32_t *a, const uint32_t *b, uint32_t ctl);
uint32_t (*sub)(uint32_t *a, const uint32_t *b, uint32_t ctl);
uint32_t (*ninv)(uint32_t x);
void (*montymul)(uint32_t *d, const uint32_t *x, const uint32_t *y,
const uint32_t *m, uint32_t m0i);
void (*to_monty)(uint32_t *x, const uint32_t *m);
void (*from_monty)(uint32_t *x, const uint32_t *m, uint32_t m0i);
void (*modpow)(uint32_t *x, const unsigned char *e, size_t elen,
const uint32_t *m, uint32_t m0i, uint32_t *t1, uint32_t *t2);
} int_impl;
static const int_impl i31_impl = {
31,
&br_i31_zero,
&br_i31_decode,
&br_i31_decode_mod,
&br_i31_reduce,
&br_i31_decode_reduce,
&br_i31_encode,
&br_i31_add,
&br_i31_sub,
&br_i31_ninv31,
&br_i31_montymul,
&br_i31_to_monty,
&br_i31_from_monty,
&br_i31_modpow
};
static const int_impl i32_impl = {
32,
&br_i32_zero,
&br_i32_decode,
&br_i32_decode_mod,
&br_i32_reduce,
&br_i32_decode_reduce,
&br_i32_encode,
&br_i32_add,
&br_i32_sub,
&br_i32_ninv32,
&br_i32_montymul,
&br_i32_to_monty,
&br_i32_from_monty,
&br_i32_modpow
};
static const int_impl *impl;
static gmp_randstate_t RNG;
/*
* Get a random prime of length 'size' bits. This function also guarantees
* that x-1 is not a multiple of 65537.
*/
static void
rand_prime(mpz_t x, int size)
{
for (;;) {
mpz_urandomb(x, RNG, size - 1);
mpz_setbit(x, 0);
mpz_setbit(x, size - 1);
if (mpz_probab_prime_p(x, 50)) {
mpz_sub_ui(x, x, 1);
if (mpz_divisible_ui_p(x, 65537)) {
continue;
}
mpz_add_ui(x, x, 1);
return;
}
}
}
/*
* Print out a GMP integer (for debug).
*/
static void
print_z(mpz_t z)
{
unsigned char zb[1000];
size_t zlen, k;
mpz_export(zb, &zlen, 1, 1, 0, 0, z);
if (zlen == 0) {
printf(" 00");
return;
}
if ((zlen & 3) != 0) {
k = 4 - (zlen & 3);
memmove(zb + k, zb, zlen);
memset(zb, 0, k);
zlen += k;
}
for (k = 0; k < zlen; k += 4) {
printf(" %02X%02X%02X%02X",
zb[k], zb[k + 1], zb[k + 2], zb[k + 3]);
}
}
/*
* Print out an i31 or i32 integer (for debug).
*/
static void
print_u(uint32_t *x)
{
size_t k;
if (x[0] == 0) {
printf(" 00000000 (0, 0)");
return;
}
for (k = (x[0] + 31) >> 5; k > 0; k --) {
printf(" %08lX", (unsigned long)x[k]);
}
printf(" (%u, %u)", (unsigned)(x[0] >> 5), (unsigned)(x[0] & 31));
}
/*
* Check that an i31/i32 number and a GMP number are equal.
*/
static void
check_eqz(uint32_t *x, mpz_t z)
{
unsigned char xb[1000];
unsigned char zb[1000];
size_t xlen, zlen;
int good;
xlen = ((x[0] + 31) & ~(uint32_t)31) >> 3;
impl->encode(xb, xlen, x);
mpz_export(zb, &zlen, 1, 1, 0, 0, z);
good = 1;
if (xlen < zlen) {
good = 0;
} else if (xlen > zlen) {
size_t u;
for (u = xlen; u > zlen; u --) {
if (xb[xlen - u] != 0) {
good = 0;
break;
}
}
}
good = good && memcmp(xb + xlen - zlen, zb, zlen) == 0;
if (!good) {
size_t u;
printf("Mismatch:\n");
printf(" x = ");
print_u(x);
printf("\n");
printf(" ex = ");
for (u = 0; u < xlen; u ++) {
printf("%02X", xb[u]);
}
printf("\n");
printf(" z = ");
print_z(z);
printf("\n");
exit(EXIT_FAILURE);
}
}
/* obsolete
static void
mp_to_br(uint32_t *mx, uint32_t x_bitlen, mpz_t x)
{
uint32_t x_ebitlen;
size_t xlen;
if (mpz_sizeinbase(x, 2) > x_bitlen) {
abort();
}
x_ebitlen = ((x_bitlen / 31) << 5) + (x_bitlen % 31);
br_i31_zero(mx, x_ebitlen);
mpz_export(mx + 1, &xlen, -1, sizeof *mx, 0, 1, x);
}
*/
static void
test_modint(void)
{
int i, j, k;
mpz_t p, a, b, v, t1;
printf("Test modular integers: ");
fflush(stdout);
gmp_randinit_mt(RNG);
mpz_init(p);
mpz_init(a);
mpz_init(b);
mpz_init(v);
mpz_init(t1);
mpz_set_ui(t1, (unsigned long)time(NULL));
gmp_randseed(RNG, t1);
for (k = 2; k <= 128; k ++) {
for (i = 0; i < 10; i ++) {
unsigned char ep[100], ea[100], eb[100], ev[100];
size_t plen, alen, blen, vlen;
uint32_t mp[40], ma[40], mb[40], mv[60], mx[100];
uint32_t mt1[40], mt2[40], mt3[40];
uint32_t ctl;
uint32_t mp0i;
rand_prime(p, k);
mpz_urandomm(a, RNG, p);
mpz_urandomm(b, RNG, p);
mpz_urandomb(v, RNG, k + 60);
if (mpz_sgn(b) == 0) {
mpz_set_ui(b, 1);
}
mpz_export(ep, &plen, 1, 1, 0, 0, p);
mpz_export(ea, &alen, 1, 1, 0, 0, a);
mpz_export(eb, &blen, 1, 1, 0, 0, b);
mpz_export(ev, &vlen, 1, 1, 0, 0, v);
impl->decode(mp, ep, plen);
if (impl->decode_mod(ma, ea, alen, mp) != 1) {
printf("Decode error\n");
printf(" ea = ");
print_z(a);
printf("\n");
printf(" p = ");
print_u(mp);
printf("\n");
exit(EXIT_FAILURE);
}
mp0i = impl->ninv(mp[1]);
if (impl->decode_mod(mb, eb, blen, mp) != 1) {
printf("Decode error\n");
printf(" eb = ");
print_z(b);
printf("\n");
printf(" p = ");
print_u(mp);
printf("\n");
exit(EXIT_FAILURE);
}
impl->decode(mv, ev, vlen);
check_eqz(mp, p);
check_eqz(ma, a);
check_eqz(mb, b);
check_eqz(mv, v);
impl->decode_mod(ma, ea, alen, mp);
impl->decode_mod(mb, eb, blen, mp);
ctl = impl->add(ma, mb, 1);
ctl |= impl->sub(ma, mp, 0) ^ (uint32_t)1;
impl->sub(ma, mp, ctl);
mpz_add(t1, a, b);
mpz_mod(t1, t1, p);
check_eqz(ma, t1);
impl->decode_mod(ma, ea, alen, mp);
impl->decode_mod(mb, eb, blen, mp);
impl->add(ma, mp, impl->sub(ma, mb, 1));
mpz_sub(t1, a, b);
mpz_mod(t1, t1, p);
check_eqz(ma, t1);
impl->decode_reduce(ma, ev, vlen, mp);
mpz_mod(t1, v, p);
check_eqz(ma, t1);
impl->decode(mv, ev, vlen);
impl->reduce(ma, mv, mp);
mpz_mod(t1, v, p);
check_eqz(ma, t1);
impl->decode_mod(ma, ea, alen, mp);
impl->to_monty(ma, mp);
mpz_mul_2exp(t1, a, ((k + impl->word_size - 1)
/ impl->word_size) * impl->word_size);
mpz_mod(t1, t1, p);
check_eqz(ma, t1);
impl->from_monty(ma, mp, mp0i);
check_eqz(ma, a);
impl->decode_mod(ma, ea, alen, mp);
impl->decode_mod(mb, eb, blen, mp);
impl->to_monty(ma, mp);
impl->montymul(mt1, ma, mb, mp, mp0i);
mpz_mul(t1, a, b);
mpz_mod(t1, t1, p);
check_eqz(mt1, t1);
impl->decode_mod(ma, ea, alen, mp);
impl->modpow(ma, ev, vlen, mp, mp0i, mt1, mt2);
mpz_powm(t1, a, v, p);
check_eqz(ma, t1);
/*
br_modint_decode(ma, mp, ea, alen);
br_modint_decode(mb, mp, eb, blen);
if (!br_modint_div(ma, mb, mp, mt1, mt2, mt3)) {
fprintf(stderr, "division failed\n");
exit(EXIT_FAILURE);
}
mpz_sub_ui(t1, p, 2);
mpz_powm(t1, b, t1, p);
mpz_mul(t1, a, t1);
mpz_mod(t1, t1, p);
check_eqz(ma, t1);
br_modint_decode(ma, mp, ea, alen);
br_modint_decode(mb, mp, eb, blen);
for (j = 0; j <= (2 * k + 5); j ++) {
br_int_add(mx, j, ma, mb);
mpz_add(t1, a, b);
mpz_tdiv_r_2exp(t1, t1, j);
check_eqz(mx, t1);
br_int_mul(mx, j, ma, mb);
mpz_mul(t1, a, b);
mpz_tdiv_r_2exp(t1, t1, j);
check_eqz(mx, t1);
}
*/
}
printf(".");
fflush(stdout);
}
mpz_clear(p);
mpz_clear(a);
mpz_clear(b);
mpz_clear(v);
mpz_clear(t1);
printf(" done.\n");
fflush(stdout);
}
#if 0
static void
test_RSA_core(void)
{
int i, j, k;
mpz_t n, e, d, p, q, dp, dq, iq, t1, t2, phi;
printf("Test RSA core: ");
fflush(stdout);
gmp_randinit_mt(RNG);
mpz_init(n);
mpz_init(e);
mpz_init(d);
mpz_init(p);
mpz_init(q);
mpz_init(dp);
mpz_init(dq);
mpz_init(iq);
mpz_init(t1);
mpz_init(t2);
mpz_init(phi);
mpz_set_ui(t1, (unsigned long)time(NULL));
gmp_randseed(RNG, t1);
/*
* To test corner cases, we want to try RSA keys such that the
* lengths of both factors can be arbitrary modulo 2^32. Factors
* p and q need not be of the same length; p can be greater than
* q and q can be greater than p.
*
* To keep computation time reasonable, we use p and q factors of
* less than 128 bits; this is way too small for secure RSA,
* but enough to exercise all code paths (since we work only with
* 32-bit words).
*/
for (i = 64; i <= 96; i ++) {
rand_prime(p, i);
for (j = i - 33; j <= i + 33; j ++) {
uint32_t mp[40], mq[40], mdp[40], mdq[40], miq[40];
/*
* Generate a RSA key pair, with p of length i bits,
* and q of length j bits.
*/
do {
rand_prime(q, j);
} while (mpz_cmp(p, q) == 0);
mpz_mul(n, p, q);
mpz_set_ui(e, 65537);
mpz_sub_ui(t1, p, 1);
mpz_sub_ui(t2, q, 1);
mpz_mul(phi, t1, t2);
mpz_invert(d, e, phi);
mpz_mod(dp, d, t1);
mpz_mod(dq, d, t2);
mpz_invert(iq, q, p);
/*
* Convert the key pair elements to BearSSL arrays.
*/
mp_to_br(mp, mpz_sizeinbase(p, 2), p);
mp_to_br(mq, mpz_sizeinbase(q, 2), q);
mp_to_br(mdp, mpz_sizeinbase(dp, 2), dp);
mp_to_br(mdq, mpz_sizeinbase(dq, 2), dq);
mp_to_br(miq, mp[0], iq);
/*
* Compute and check ten public/private operations.
*/
for (k = 0; k < 10; k ++) {
uint32_t mx[40];
mpz_urandomm(t1, RNG, n);
mpz_powm(t2, t1, e, n);
mp_to_br(mx, mpz_sizeinbase(n, 2), t2);
br_rsa_private_core(mx, mp, mq, mdp, mdq, miq);
check_eqz(mx, t1);
}
}
printf(".");
fflush(stdout);
}
printf(" done.\n");
fflush(stdout);
}
#endif
int
main(void)
{
printf("===== i32 ======\n");
impl = &i32_impl;
test_modint();
printf("===== i31 ======\n");
impl = &i31_impl;
test_modint();
/*
test_RSA_core();
*/
return 0;
}

1098
test/test_speed.c Normal file

File diff suppressed because it is too large Load diff

1634
test/test_x509.c Normal file

File diff suppressed because it is too large Load diff

660
test/x509/alltests.txt Normal file
View file

@ -0,0 +1,660 @@
; Most/all of these test chains use the same structure:
; root -> ica1 -> ica2 -> ee
; "ica1" is "Intermediate CA 1"
; "ee" is "end-entity", i.e. the client or server certificate itself
;
; In SSL/TLS order, the EE comes first. The root may or may not be included
; as a self-signed certificate.
[key]
name = root-rsa2048
type = RSA
n = B6D934D450FDB3AF7A73F1CE38BF5D6F45E1FD4EB198C6608326D217D1C5B79AA3C1DE6339979CF05E5CC81C17B988196DF0B62E3050A1546E93C0DBCF30CB9F1E2779F1C3995235AA3DB6DFB0AD7CCB49CDC0EDE766102AE9CE281F2150FA774C2DDAEF3C58EB4EBFCEE9FB1ADAA383A3CDA3CA9380DCDAF317CC7AAB33809CB2D47F463FC53CDC6194B727296E2ABC5B0936D4C63B0DEBBECEDB1D1CBC106A7171B3F2CA289A77F28AEC42EFB14A8EE2F21A322ACDC0A6462C9AC28537917F46A19381A17466DFBAB339209193FA1DA1A885E7E4F907F610F6A82701B67F12C340C3C9E2B0AB49183A64B659B795B59636DF2269AA726A544E2729A30E9715
e = 010001
[key]
name = root-p256
type = EC
curve = P-256
q = 047174BAABB9302E81D5E557F9F320680C9CF964DBB4200D6DEA40D04A6E42FDB69A682544F6DF7BC4FCDEDD7BBBC5DB7C763F4166406EDBA787C2E5D8C5F37F8D
[key]
name = root-p384
type = EC
curve = P-384
q = 040ED28B3F7F0A38A6DB72CB4DAC8198C3D595BFABEE2E4A3CC6797F1A272C57AD715F96B5FDA29C4DD87B75B1438B6A92C4FD0282A3080A857F28AB31FF8B49F805470A01EE551F7F27C914E7E780AE474558D6F5539BAE806626514FE560478B
[key]
name = root-p521
type = EC
curve = P-521
q = 040168E669615D1B20F2E753D2C86312F51094D3E5C6CF49E8D73418278CD769FE40A84AD4F34865D59D94D5685B389E0CFD0450754CAE81ED1D4A91D0773F7A002ED701DEF2DBDEFC7554E74CD600693DBDE1A7E09CD9044774C744C7CE575BF8B645FF79FCCE06116F61D44FDAE62D3046F4EB41DECB8219B279A5B8CE2A47F3DF0D463B
[key]
name = ica1-rsa2048
type = RSA
n = B3E86BAF9C1652E3810C50AB25CECC0DC7F21F7F50DF2C5C35D6622E632741A7E453A84B27FA1391A3FA094A2F3B5ECF77B38AC1CD49959C750D6474EFE4D74BB9A19B68D2307148EAF74B14DF3F47A9D8BBEC8F28CCFADFB41F947C96FC080528F9E8F42F2FEE629C8A3AE0855860B60F2D30B4C04154914C1F5FADF119F0C022A67DD83F793459427B5BB541C4647F52CF3C3722A12F7925942441C23FFAC775FB48B50D18A7F454F32E6ED84358C4AB50E805AD91B61E0175B3549CDEA09915FBACF15C974951CCEF58126F736BB33414010F5A9DFAAAD693D3E2EAC3ABBC4EEDCC51A1B8F894B6B42CA8862B1FF6514329525E1389B36A78604E4EC01BA5
e = 010001
[key]
name = ica2-rsa2048
type = RSA
n = AE15F7CBEEE3961BCA63D22681B2D8163423735684FCFDB2E98E9DD0D9D0D706A191EF8D4F604E16BDE6529EE557867B7A7FFCBC34AD86EC9150ADD5C7D18D83E95ABA2FDB0DB92131FAA2FD91EC37836261809C6A82253309DF8F7893EACFDB93B0A2687CEA873E369C4B379A71E52084C3789A2BA42C7E76D561A9131272F14B411BC6A555BA9D8965C06699C0F17C9B61B24E6601B0A9C4FDC8C1D0C789BE2746DE6271BA27F52A850F436026BC2A9D07AAD608DC26D86956A1D308DED858936B0EC2AF783E2574D49F001820BFD7158DB9D13D8900A01264E186C0D580F124B2D2FB4C677CAE3DC9BF47026DE47C0D4490518CCD026237F86FB96701C695
e = 010001
[key]
name = ee-rsa2048
type = RSA
n = D47A1D27BA2B3A67B2916AFBE78344CAED1C75ADDD4D8362D6AA6895B224217B15AE2A996815ED66F0B858E7D3F52EC6D92A5EE70E2EE7FC6759C0C8617D4BA46FDD9FD9C8858764C7BA1A0F29D496A8789A6B6220A932D0EEA98C286147A2502A63F621DEDAD8D5F07FC5008270E6A3BF5C89274F51927703C3B0CC2E3BEC23F22F5341AF8993FFD280B14397DED619A092127A3D6679E1C1BCE17770A28B3D4684533FE44E424137921E1FFD38B3F7EF873980D356CFF4E013DE64B072A40384C441ED6FFA3EE2CA0420D2D7DC2C822B7AE26DA11C48DBCF894F34973D28A853DAE7C1E17315A330767F8F2342143D5134D25AAD3C9BCBC8FE7F6E8E40F3BD
e = 010001
[key]
name = ee-p256
type = EC
curve = P-256
q = 045F389DA7FF4D8AAFF63439461AFC3ADFF423AAA9EAFBC508DE008EBE79A537584C6DDD01CAAB47DF89B6C7171F38FC1D2014DD45C0E08F934E380BFCE999A149
[key]
name = ee-p384
type = EC
curve = P-384
q = 0415A488877F3D14830E29A1C2F2C0745CE8CF5E684304D1668972389BA615B34E9648D5A7861E49DFFFBFFFEAD7FC6AF11BC4516C3557332DD86DDFDE2A236CCEA844EBD594CCD3ED5B7AE0061BD6595737B59FE754BCDAB6FE38D34D93DBBF30
[key]
name = ee-p521
type = EC
curve = P-521
q = 040060547ACA9D520FB3272833236CBF8E71AC286A3001FBB1E2C3FD8BAB0817DDE4E4FA53550F120D678F4D55AE4FF36C7C8EAE9E32A08A44FC66F45331E08946077A0139B87FE54B986012A94838C8006034941CD0512E596436D2E8E61CA93585D5C06EAD5094585B5B2A3E013803B3E6AAA1D4156EF09E8352029BB70AC6BF338F918B
; Trust anchor: the root.
[anchor]
name = root
DN_file = dn-root.der
key = root-rsa2048
type = CA
; Trust anchor: root with an ECDSA key (in P-256 curve)
[anchor]
name = root-p256
DN_file = dn-root.der
key = root-p256
type = CA
; Trust anchor: root with an ECDSA key (in P-384 curve)
[anchor]
name = root-p384
DN_file = dn-root.der
key = root-p384
type = CA
; Trust anchor: root with an ECDSA key (in P-521 curve)
[anchor]
name = root-p521
DN_file = dn-root.der
key = root-p521
type = CA
; Intermediate CA 1 as trust anchor.
[anchor]
name = ica1
DN_file = dn-ica1.der
key = ica1-rsa2048
type = CA
; Intermediate CA 2 as trust anchor.
[anchor]
name = ica2
DN_file = dn-ica2.der
key = ica2-rsa2048
type = CA
; EE certificate as trust anchor (direct trust only).
[anchor]
name = ee
DN_file = dn-ee.der
key = ee-rsa2048
type = EE
; Base valid chain.
[chain]
name = base
anchors = root
chain = ee.crt ica2.crt ica1.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Valid chain except that no trust anchor is provided; this should fail
; with BR_ERR_X509_NOT_TRUSTED.
[chain]
name = noTA
anchors =
chain = ee.crt ica2.crt ica1.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
status = 62
; Use of intermediate CA 1 as anchor (extra certificates are ignored).
[chain]
name = anchorICA1
anchors = ica1
chain = ee.crt ica2.crt junk.crt junk.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Use of intermediate CA 2 as anchor (extra certificates are ignored).
[chain]
name = anchorICA2
anchors = ica2
chain = ee.crt junk.crt junk.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Direct trust of EE.
[chain]
name = directTrust
anchors = ee
chain = ee.crt junk.crt junk.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Server name check: name does not match the SAN nor the CN.
[chain]
name = wrongName1
anchors = root
chain = ee.crt ica2.crt ica1.crt
servername = foo.example.com
keytype = RSA
keyusage = KEYX
status = 56
; Server name check: name matches the CN but not the SAN, and there is
; a SAN so the CN is ignored.
[chain]
name = wrongName2
anchors = root
chain = ee-names.crt ica2.crt ica1.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
status = 56
; Server name check: name does not match CN, but matches the first SAN
; name.
[chain]
name = goodName1
anchors = root
chain = ee-names.crt ica2.crt ica1.crt
servername = foo.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Server name check: name does not match CN, but matches the second SAN
; name.
[chain]
name = goodName2
anchors = root
chain = ee-names.crt ica2.crt ica1.crt
servername = barqux.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Server name check: no SAN, but the CN matches the server name.
[chain]
name = goodName3
anchors = root
chain = ee-names2.crt ica2.crt ica1.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Server name check: no SAN, and the CN does not match the server name.
[chain]
name = wrongName3
anchors = root
chain = ee-names2.crt ica2.crt ica1.crt
servername = foo.example.com
keytype = RSA
keyusage = KEYX
status = 56
; Server name check: no SAN, and the CN does not match the server name,
; although its byte contents seem to match (but with BMPString encoding).
[chain]
name = wrongName4
anchors = root
chain = ee-names3.crt ica2.crt ica1.crt
servername = www1.example.com
keytype = RSA
keyusage = KEYX
status = 56
; Server name check: no SAN, and the CN uses BMPString encoding, but we
; do not actually request a server name check, so this should pass.
[chain]
name = ignoreName1
anchors = root
chain = ee-names3.crt ica2.crt ica1.crt
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Wildcard processing: the name 'localhost' should not match because
; the engine recognises the wildcard only in a '*.' starting sequence,
; so the lone '*' in a SAN will not be accepted.
[chain]
name = wildcard1
anchors = root
chain = ee-names4.crt ica2.crt ica1.crt
servername = localhost
keytype = RSA
keyusage = KEYX
status = 56
; Wildcard processing: the name 'example.com' will be matched by '*.com'.
[chain]
name = wildcard2
anchors = root
chain = ee-names4.crt ica2.crt ica1.crt
servername = example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Wildcard processing: the name 'www.example.com' will be matched by
; '*.example.com'.
[chain]
name = wildcard3
anchors = root
chain = ee-names4.crt ica2.crt ica1.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Wildcard processing: the name 'foo.foo.example.com' will not be matched by
; 'foo.*.example.com' because we accept the wildcard only in the first name
; component.
[chain]
name = wildcard4
anchors = root
chain = ee-names4.crt ica2.crt ica1.crt
servername = foo.foo.example.com
keytype = RSA
keyusage = KEYX
status = 56
; Wildcard processing: the name 'foo.bar.example.com' will not be matched by
; 'foo.*.example.com', but '*.bar.example.com' will fit.
[chain]
name = wildcard5
anchors = root
chain = ee-names4.crt ica2.crt ica1.crt
servername = foo.bar.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Wildcard processing: the name 'foo.bar.example.foobar' will not be matched by
; '*.*.example.foobar' because we support only a single level of wildcard.
[chain]
name = wildcard6
anchors = root
chain = ee-names4.crt ica2.crt ica1.crt
servername = foo.bar.example.foobar
keytype = RSA
keyusage = KEYX
status = 56
; Wildcard processing: the name 'foo.*.example.foobar' will be matched
; by '*.*.example.foobar' because the '*' in the provided server name matches
; the second '*' in '*.*.example.foobar'. This is a corner case with no
; practical impact because expected server names are usually extracted from
; URL and cannot have embedded '*' in them.
[chain]
name = wildcard7
anchors = root
chain = ee-names4.crt ica2.crt ica1.crt
servername = foo.*.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Hash function support: the chain uses only SHA-256.
[chain]
name = hashSHA256Only
anchors = root
chain = ee.crt ica2.crt ica1.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
hashes = sha256
eekey = ee-rsa2048
status = 0
; Hash function support: the chain uses only SHA-256.
[chain]
name = hashSHA256Unsupported
anchors = root
chain = ee.crt ica2.crt ica1.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
hashes = md5 sha1 sha224 sha384 sha512
status = 49
; Hash function support: signature on EE uses SHA-1.
[chain]
name = hashSHA1
anchors = root
chain = ee-sha1.crt ica2.crt ica1.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Hash function support: signature on EE uses SHA-224.
[chain]
name = hashSHA224
anchors = root
chain = ee-sha224.crt ica2.crt ica1.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Hash function support: signature on EE uses SHA-384.
[chain]
name = hashSHA384
anchors = root
chain = ee-sha384.crt ica2.crt ica1.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Hash function support: signature on EE uses SHA-512.
[chain]
name = hashSHA512
anchors = root
chain = ee-sha512.crt ica2.crt ica1.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Hash function support: signature on EE uses MD5. This is rejected by
; the engine (even though MD5 is supported as a hash function).
[chain]
name = hashMD5
anchors = root
chain = ee-md5.crt ica2.crt ica1.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
status = 49
; EE certificate has trailing garbage (an extra byte), which should be
; rejected.
[chain]
name = trailingGarbage
anchors = root
chain = ee-trailing.crt ica2.crt ica1.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
status = 40
; Signature on EE certificate is incorrect (one byte modified in signature).
[chain]
name = badSignature1
anchors = root
chain = ee-badsig1.crt ica2.crt ica1.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
status = 52
; Signature on EE certificate is incorrect (one byte modified in serial
; number).
[chain]
name = badSignature2
anchors = root
chain = ee-badsig2.crt ica2.crt ica1.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
status = 52
; Signature on EE certificate is incorrect but this is ignored because we
; use a direct trust model here.
[chain]
name = ignoredSignature1
anchors = ee
chain = ee-badsig1.crt ica2.crt ica1.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Signature on EE certificate is incorrect but this is ignored because we
; use a direct trust model here.
[chain]
name = ignoredSignature2
anchors = ee
chain = ee-badsig2.crt ica2.crt ica1.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Intermediate CA 1 has a 1016-bit RSA key, which should be rejected
; with BR_ERR_X509_WEAK_PUBLIC_KEY.
[chain]
name = rsa1016
anchors = root
chain = ee.crt ica2-1016.crt ica1-1016.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
status = 60
; Intermediate CA 1 has a 1017-bit RSA key, which should be accepted
; (because that's 128 bytes, which is the lower limit).
[chain]
name = rsa1017
anchors = root
chain = ee.crt ica2-1017.crt ica1-1017.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; Intermediate CA 1 has a 4096-bit RSA key, which should be supported.
[chain]
name = rsa4096
anchors = root
chain = ee.crt ica2-4096.crt ica1-4096.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; EE is valid from 2010/02/17 11:40:35 to 2098/07/20 15:11:08. The
; start date is in UTCTime, the end date is in GeneralizedTime.
[chain]
name = date1
anchors = ica2
chain = ee-dates.crt ica2.crt ica1.crt
time = 2010-02-17 11:40:34Z
servername = www.example.com
keytype = RSA
keyusage = KEYX
status = 54
; EE is valid from 2010/02/17 11:40:35 to 2098/07/20 15:11:08. The
; start date is in UTCTime, the end date is in GeneralizedTime.
[chain]
name = date2
anchors = ica2
chain = ee-dates.crt ica2.crt ica1.crt
time = 2010-02-17 11:40:36Z
servername = www.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; EE is valid from 2010/02/17 11:40:35 to 2098/07/20 15:11:08. The
; start date is in UTCTime, the end date is in GeneralizedTime.
[chain]
name = date3
anchors = ica2
chain = ee-dates.crt ica2.crt ica1.crt
time = 2098-07-20 15:11:07Z
servername = www.example.com
keytype = RSA
keyusage = KEYX
eekey = ee-rsa2048
status = 0
; EE is valid from 2010/02/17 11:40:35 to 2098/07/20 15:11:08. The
; start date is in UTCTime, the end date is in GeneralizedTime.
[chain]
name = date4
anchors = ica2
chain = ee-dates.crt ica2.crt ica1.crt
time = 2098-07-20 15:11:09Z
servername = www.example.com
keytype = RSA
keyusage = KEYX
status = 54
; Intermediate CA 2 certificate is not a CA.
[chain]
name = notCA
anchors = root
chain = ee-dates.crt ica2-notCA.crt ica1.crt
servername = www.example.com
keytype = RSA
keyusage = KEYX
status = 58
; A chain using ECDSA with P-256.
[chain]
name = secp256r1
anchors = root-p256
chain = ee-p256.crt ica2-p256.crt ica1-p256.crt
servername = www.example.com
keytype = EC
keyusage = SIGN
eekey = ee-p256
status = 0
; A chain using ECDSA with P-384.
[chain]
name = secp384r1
anchors = root-p384
chain = ee-p384.crt ica2-p384.crt ica1-p384.crt
servername = www.example.com
keytype = EC
keyusage = SIGN
eekey = ee-p384
status = 0
; A chain using ECDSA with P-521.
[chain]
name = secp521r1
anchors = root-p521
chain = ee-p521.crt ica2-p521.crt ica1-p521.crt
servername = www.example.com
keytype = EC
keyusage = SIGN
eekey = ee-p521
status = 0
; A chain using ECDSA with P-256, signature on EE uses SHA-1.
[chain]
name = secp256r1-sha1
anchors = root-p256
chain = ee-p256-sha1.crt ica2-p256.crt ica1-p256.crt
servername = www.example.com
keytype = EC
keyusage = SIGN
eekey = ee-p256
status = 0
; A chain using ECDSA with P-256, signature on EE uses SHA-224.
[chain]
name = secp256r1-sha224
anchors = root-p256
chain = ee-p256-sha224.crt ica2-p256.crt ica1-p256.crt
servername = www.example.com
keytype = EC
keyusage = SIGN
eekey = ee-p256
status = 0
; A chain using ECDSA with P-256, signature on EE uses SHA-256.
[chain]
name = secp256r1-sha256
anchors = root-p256
chain = ee-p256-sha256.crt ica2-p256.crt ica1-p256.crt
servername = www.example.com
keytype = EC
keyusage = SIGN
eekey = ee-p256
status = 0
; A chain using ECDSA with P-256, signature on EE uses SHA-384.
[chain]
name = secp256r1-sha384
anchors = root-p256
chain = ee-p256-sha384.crt ica2-p256.crt ica1-p256.crt
servername = www.example.com
keytype = EC
keyusage = SIGN
eekey = ee-p256
status = 0
; A chain using ECDSA with P-256, signature on EE uses SHA-512.
[chain]
name = secp256r1-sha512
anchors = root-p256
chain = ee-p256-sha512.crt ica2-p256.crt ica1-p256.crt
servername = www.example.com
keytype = EC
keyusage = SIGN
eekey = ee-p256
status = 0

1
test/x509/dn-ee.der Normal file
View file

@ -0,0 +1 @@
0'1 0 UCA10Uwww.example.com

1
test/x509/dn-ica1.der Normal file
View file

@ -0,0 +1 @@
011 0 UCA1"0 UExample Intermediate CA 1

1
test/x509/dn-ica2.der Normal file
View file

@ -0,0 +1 @@
011 0 UCA1"0 UExample Intermediate CA 2

1
test/x509/dn-root.der Normal file
View file

@ -0,0 +1 @@
0$1 0 UCA10U Example Root

BIN
test/x509/ee-badsig1.crt Normal file

Binary file not shown.

BIN
test/x509/ee-badsig2.crt Normal file

Binary file not shown.

BIN
test/x509/ee-dates.crt Normal file

Binary file not shown.

BIN
test/x509/ee-md5.crt Normal file

Binary file not shown.

BIN
test/x509/ee-names.crt Normal file

Binary file not shown.

BIN
test/x509/ee-names2.crt Normal file

Binary file not shown.

BIN
test/x509/ee-names3.crt Normal file

Binary file not shown.

BIN
test/x509/ee-names4.crt Normal file

Binary file not shown.

BIN
test/x509/ee-p256-sha1.crt Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
test/x509/ee-p256.crt Normal file

Binary file not shown.

BIN
test/x509/ee-p384.crt Normal file

Binary file not shown.

BIN
test/x509/ee-p521.crt Normal file

Binary file not shown.

BIN
test/x509/ee-sha1.crt Normal file

Binary file not shown.

BIN
test/x509/ee-sha224.crt Normal file

Binary file not shown.

BIN
test/x509/ee-sha384.crt Normal file

Binary file not shown.

BIN
test/x509/ee-sha512.crt Normal file

Binary file not shown.

BIN
test/x509/ee-trailing.crt Normal file

Binary file not shown.

BIN
test/x509/ee.crt Normal file

Binary file not shown.

BIN
test/x509/ica1-1016.crt Normal file

Binary file not shown.

BIN
test/x509/ica1-1017.crt Normal file

Binary file not shown.

BIN
test/x509/ica1-4096.crt Normal file

Binary file not shown.

BIN
test/x509/ica1-p256.crt Normal file

Binary file not shown.

BIN
test/x509/ica1-p384.crt Normal file

Binary file not shown.

BIN
test/x509/ica1-p521.crt Normal file

Binary file not shown.

BIN
test/x509/ica1.crt Normal file

Binary file not shown.

BIN
test/x509/ica2-1016.crt Normal file

Binary file not shown.

BIN
test/x509/ica2-1017.crt Normal file

Binary file not shown.

BIN
test/x509/ica2-4096.crt Normal file

Binary file not shown.

BIN
test/x509/ica2-notCA.crt Normal file

Binary file not shown.

BIN
test/x509/ica2-p256.crt Normal file

Binary file not shown.

BIN
test/x509/ica2-p384.crt Normal file

Binary file not shown.

BIN
test/x509/ica2-p521.crt Normal file

Binary file not shown.

BIN
test/x509/ica2.crt Normal file

Binary file not shown.

BIN
test/x509/junk.crt Normal file

Binary file not shown.

BIN
test/x509/root-p256.crt Normal file

Binary file not shown.

BIN
test/x509/root-p384.crt Normal file

Binary file not shown.

BIN
test/x509/root-p521.crt Normal file

Binary file not shown.

BIN
test/x509/root.crt Normal file

Binary file not shown.