Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 1 | /* BEGIN_HEADER */ |
Rich Evans | ce2f237 | 2015-02-06 13:57:42 +0000 | [diff] [blame] | 2 | #include "polarssl/x509_crt.h" |
| 3 | #include "polarssl/x509_crl.h" |
| 4 | #include "polarssl/x509_csr.h" |
| 5 | #include "polarssl/pem.h" |
| 6 | #include "polarssl/oid.h" |
| 7 | #include "polarssl/base64.h" |
Paul Bakker | b63b0af | 2011-01-13 17:54:59 +0000 | [diff] [blame] | 8 | |
Paul Bakker | c559c7a | 2013-09-18 14:13:26 +0200 | [diff] [blame] | 9 | int verify_none( void *data, x509_crt *crt, int certificate_depth, int *flags ) |
Paul Bakker | b63b0af | 2011-01-13 17:54:59 +0000 | [diff] [blame] | 10 | { |
Paul Bakker | 5a62408 | 2011-01-18 16:31:52 +0000 | [diff] [blame] | 11 | ((void) data); |
| 12 | ((void) crt); |
| 13 | ((void) certificate_depth); |
Paul Bakker | 915275b | 2012-09-28 07:10:55 +0000 | [diff] [blame] | 14 | *flags |= BADCERT_OTHER; |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 15 | |
Paul Bakker | 915275b | 2012-09-28 07:10:55 +0000 | [diff] [blame] | 16 | return 0; |
Paul Bakker | b63b0af | 2011-01-13 17:54:59 +0000 | [diff] [blame] | 17 | } |
| 18 | |
Paul Bakker | c559c7a | 2013-09-18 14:13:26 +0200 | [diff] [blame] | 19 | int verify_all( void *data, x509_crt *crt, int certificate_depth, int *flags ) |
Paul Bakker | b63b0af | 2011-01-13 17:54:59 +0000 | [diff] [blame] | 20 | { |
Paul Bakker | 5a62408 | 2011-01-18 16:31:52 +0000 | [diff] [blame] | 21 | ((void) data); |
| 22 | ((void) crt); |
| 23 | ((void) certificate_depth); |
Paul Bakker | 915275b | 2012-09-28 07:10:55 +0000 | [diff] [blame] | 24 | *flags = 0; |
Paul Bakker | 5a62408 | 2011-01-18 16:31:52 +0000 | [diff] [blame] | 25 | |
Paul Bakker | b63b0af | 2011-01-13 17:54:59 +0000 | [diff] [blame] | 26 | return 0; |
| 27 | } |
| 28 | |
Manuel Pégourié-Gonnard | 15f1088 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 29 | #if defined(POLARSSL_X509_CRT_PARSE_C) |
| 30 | typedef struct { |
| 31 | char buf[512]; |
| 32 | char *p; |
| 33 | } verify_print_context; |
| 34 | |
| 35 | void verify_print_init( verify_print_context *ctx ) |
| 36 | { |
| 37 | memset( ctx, 0, sizeof( verify_print_context ) ); |
| 38 | ctx->p = ctx->buf; |
| 39 | } |
| 40 | |
| 41 | #if defined(_MSC_VER) && !defined snprintf |
| 42 | #define snprintf _snprintf |
| 43 | #endif |
| 44 | |
| 45 | #define SAFE_SNPRINTF \ |
| 46 | do \ |
| 47 | { \ |
| 48 | if( ret < 0 || (size_t) ret > n ) \ |
| 49 | { \ |
| 50 | p[n - 1] = '\0'; \ |
| 51 | return( -1 ); \ |
| 52 | } \ |
| 53 | \ |
| 54 | n -= (unsigned int) ret; \ |
| 55 | p += (unsigned int) ret; \ |
| 56 | } while( 0 ) |
| 57 | |
| 58 | int verify_print( void *data, x509_crt *crt, int certificate_depth, int *flags ) |
| 59 | { |
| 60 | int ret; |
| 61 | verify_print_context *ctx = (verify_print_context *) data; |
| 62 | char *p = ctx->p; |
| 63 | size_t n = ctx->buf + sizeof( ctx->buf ) - ctx->p; |
| 64 | ((void) flags); |
| 65 | |
| 66 | ret = polarssl_snprintf( p, n, "depth %d - serial ", certificate_depth ); |
| 67 | SAFE_SNPRINTF; |
| 68 | |
| 69 | ret = x509_serial_gets( p, n, &crt->serial ); |
| 70 | SAFE_SNPRINTF; |
| 71 | |
| 72 | ret = polarssl_snprintf( p, n, " - subject " ); |
| 73 | SAFE_SNPRINTF; |
| 74 | |
| 75 | ret = x509_dn_gets( p, n, &crt->subject ); |
| 76 | SAFE_SNPRINTF; |
| 77 | |
| 78 | ret = polarssl_snprintf( p, n, "\n" ); |
| 79 | SAFE_SNPRINTF; |
| 80 | |
| 81 | ctx->p = p; |
| 82 | |
| 83 | return( 0 ); |
| 84 | } |
| 85 | #endif /* POLARSSL_X509_CRT_PARSE_C */ |
Manuel Pégourié-Gonnard | 28e1ac5 | 2015-11-02 06:34:46 +0900 | [diff] [blame] | 86 | |
| 87 | /* strsep() not available on Windows */ |
| 88 | char *mystrsep(char **stringp, const char *delim) |
| 89 | { |
| 90 | const char *p; |
| 91 | char *ret = *stringp; |
| 92 | |
| 93 | if( *stringp == NULL ) |
| 94 | return( NULL ); |
| 95 | |
| 96 | for( ; ; (*stringp)++ ) |
| 97 | { |
| 98 | if( **stringp == '\0' ) |
| 99 | { |
| 100 | *stringp = NULL; |
| 101 | goto done; |
| 102 | } |
| 103 | |
| 104 | for( p = delim; *p != '\0'; p++ ) |
| 105 | if( **stringp == *p ) |
| 106 | { |
| 107 | **stringp = '\0'; |
| 108 | (*stringp)++; |
| 109 | goto done; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | done: |
| 114 | return( ret ); |
| 115 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 116 | /* END_HEADER */ |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 117 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 118 | /* BEGIN_DEPENDENCIES |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 119 | * depends_on:POLARSSL_BIGNUM_C |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 120 | * END_DEPENDENCIES |
| 121 | */ |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 122 | |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 123 | /* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CRT_PARSE_C */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 124 | void x509_cert_info( char *crt_file, char *result_str ) |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 125 | { |
Paul Bakker | c559c7a | 2013-09-18 14:13:26 +0200 | [diff] [blame] | 126 | x509_crt crt; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 127 | char buf[2000]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 128 | int res; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 129 | |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 130 | x509_crt_init( &crt ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 131 | memset( buf, 0, 2000 ); |
| 132 | |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 133 | TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 ); |
| 134 | res = x509_crt_info( buf, 2000, "", &crt ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 135 | |
| 136 | TEST_ASSERT( res != -1 ); |
| 137 | TEST_ASSERT( res != -2 ); |
| 138 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 139 | TEST_ASSERT( strcmp( buf, result_str ) == 0 ); |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 140 | |
| 141 | exit: |
| 142 | x509_crt_free( &crt ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 143 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 144 | /* END_CASE */ |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 145 | |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 146 | /* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CRL_PARSE_C */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 147 | void x509_crl_info( char *crl_file, char *result_str ) |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 148 | { |
| 149 | x509_crl crl; |
| 150 | char buf[2000]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 151 | int res; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 152 | |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 153 | x509_crl_init( &crl ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 154 | memset( buf, 0, 2000 ); |
| 155 | |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 156 | TEST_ASSERT( x509_crl_parse_file( &crl, crl_file ) == 0 ); |
| 157 | res = x509_crl_info( buf, 2000, "", &crl ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 158 | |
| 159 | TEST_ASSERT( res != -1 ); |
| 160 | TEST_ASSERT( res != -2 ); |
| 161 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 162 | TEST_ASSERT( strcmp( buf, result_str ) == 0 ); |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 163 | |
| 164 | exit: |
| 165 | x509_crl_free( &crl ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 166 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 167 | /* END_CASE */ |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 168 | |
Manuel Pégourié-Gonnard | 2a8d7fd | 2014-01-24 17:34:26 +0100 | [diff] [blame] | 169 | /* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CSR_PARSE_C */ |
| 170 | void x509_csr_info( char *csr_file, char *result_str ) |
| 171 | { |
| 172 | x509_csr csr; |
| 173 | char buf[2000]; |
| 174 | int res; |
| 175 | |
| 176 | x509_csr_init( &csr ); |
| 177 | memset( buf, 0, 2000 ); |
| 178 | |
| 179 | TEST_ASSERT( x509_csr_parse_file( &csr, csr_file ) == 0 ); |
| 180 | res = x509_csr_info( buf, 2000, "", &csr ); |
| 181 | |
Manuel Pégourié-Gonnard | 2a8d7fd | 2014-01-24 17:34:26 +0100 | [diff] [blame] | 182 | TEST_ASSERT( res != -1 ); |
| 183 | TEST_ASSERT( res != -2 ); |
| 184 | |
| 185 | TEST_ASSERT( strcmp( buf, result_str ) == 0 ); |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 186 | |
| 187 | exit: |
| 188 | x509_csr_free( &csr ); |
Manuel Pégourié-Gonnard | 2a8d7fd | 2014-01-24 17:34:26 +0100 | [diff] [blame] | 189 | } |
| 190 | /* END_CASE */ |
| 191 | |
Manuel Pégourié-Gonnard | 39a183a | 2015-04-17 16:14:32 +0200 | [diff] [blame] | 192 | /* BEGIN_CASE depends_on:POLARSSL_X509_CRT_PARSE_C */ |
| 193 | void x509_verify_info( int flags, char *prefix, char *result_str ) |
| 194 | { |
| 195 | char buf[2000]; |
| 196 | int res; |
| 197 | |
| 198 | memset( buf, 0, sizeof( buf ) ); |
| 199 | |
| 200 | res = x509_crt_verify_info( buf, sizeof( buf ), prefix, flags ); |
| 201 | |
| 202 | TEST_ASSERT( res >= 0 ); |
| 203 | |
| 204 | TEST_ASSERT( strcmp( buf, result_str ) == 0 ); |
| 205 | } |
| 206 | /* END_CASE */ |
| 207 | |
Manuel Pégourié-Gonnard | cbf3ef3 | 2013-09-23 12:20:02 +0200 | [diff] [blame] | 208 | /* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CRT_PARSE_C:POLARSSL_X509_CRL_PARSE_C */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 209 | void x509_verify( char *crt_file, char *ca_file, char *crl_file, |
| 210 | char *cn_name_str, int result, int flags_result, |
| 211 | char *verify_callback ) |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 212 | { |
Paul Bakker | c559c7a | 2013-09-18 14:13:26 +0200 | [diff] [blame] | 213 | x509_crt crt; |
| 214 | x509_crt ca; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 215 | x509_crl crl; |
| 216 | int flags = 0; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 217 | int res; |
Paul Bakker | c559c7a | 2013-09-18 14:13:26 +0200 | [diff] [blame] | 218 | int (*f_vrfy)(void *, x509_crt *, int, int *) = NULL; |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 219 | char * cn_name = NULL; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 220 | |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 221 | x509_crt_init( &crt ); |
| 222 | x509_crt_init( &ca ); |
| 223 | x509_crl_init( &crl ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 224 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 225 | if( strcmp( cn_name_str, "NULL" ) != 0 ) |
| 226 | cn_name = cn_name_str; |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 227 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 228 | if( strcmp( verify_callback, "NULL" ) == 0 ) |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 229 | f_vrfy = NULL; |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 230 | else if( strcmp( verify_callback, "verify_none" ) == 0 ) |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 231 | f_vrfy = verify_none; |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 232 | else if( strcmp( verify_callback, "verify_all" ) == 0 ) |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 233 | f_vrfy = verify_all; |
| 234 | else |
| 235 | TEST_ASSERT( "No known verify callback selected" == 0 ); |
| 236 | |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 237 | TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 ); |
| 238 | TEST_ASSERT( x509_crt_parse_file( &ca, ca_file ) == 0 ); |
| 239 | TEST_ASSERT( x509_crl_parse_file( &crl, crl_file ) == 0 ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 240 | |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 241 | res = x509_crt_verify( &crt, &ca, &crl, cn_name, &flags, f_vrfy, NULL ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 242 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 243 | TEST_ASSERT( res == ( result ) ); |
| 244 | TEST_ASSERT( flags == ( flags_result ) ); |
| 245 | |
| 246 | exit: |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 247 | x509_crt_free( &crt ); |
| 248 | x509_crt_free( &ca ); |
Paul Bakker | b08e684 | 2012-02-11 18:43:20 +0000 | [diff] [blame] | 249 | x509_crl_free( &crl ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 250 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 251 | /* END_CASE */ |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 252 | |
Manuel Pégourié-Gonnard | 15f1088 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 253 | /* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CRT_PARSE_C */ |
| 254 | void x509_verify_callback( char *crt_file, char *ca_file, |
| 255 | int exp_ret, char *exp_vrfy_out ) |
| 256 | { |
| 257 | int ret; |
| 258 | x509_crt crt; |
| 259 | x509_crt ca; |
| 260 | int flags = 0; |
| 261 | verify_print_context vrfy_ctx; |
| 262 | |
| 263 | x509_crt_init( &crt ); |
| 264 | x509_crt_init( &ca ); |
| 265 | verify_print_init( &vrfy_ctx ); |
| 266 | |
| 267 | TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 ); |
| 268 | TEST_ASSERT( x509_crt_parse_file( &ca, ca_file ) == 0 ); |
| 269 | |
| 270 | ret = x509_crt_verify( &crt, &ca, NULL, NULL, &flags, |
| 271 | verify_print, &vrfy_ctx ); |
| 272 | |
| 273 | TEST_ASSERT( ret == exp_ret ); |
| 274 | TEST_ASSERT( strcmp( vrfy_ctx.buf, exp_vrfy_out ) == 0 ); |
| 275 | |
| 276 | exit: |
| 277 | x509_crt_free( &crt ); |
| 278 | x509_crt_free( &ca ); |
| 279 | } |
| 280 | /* END_CASE */ |
| 281 | |
Manuel Pégourié-Gonnard | 8f63e95 | 2015-09-01 18:44:47 +0200 | [diff] [blame] | 282 | /* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CRT_PARSE_C */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 283 | void x509_dn_gets( char *crt_file, char *entity, char *result_str ) |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 284 | { |
Paul Bakker | c559c7a | 2013-09-18 14:13:26 +0200 | [diff] [blame] | 285 | x509_crt crt; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 286 | char buf[2000]; |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 287 | int res = 0; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 288 | |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 289 | x509_crt_init( &crt ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 290 | memset( buf, 0, 2000 ); |
| 291 | |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 292 | TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 293 | if( strcmp( entity, "subject" ) == 0 ) |
Paul Bakker | 86d0c19 | 2013-09-18 11:11:02 +0200 | [diff] [blame] | 294 | res = x509_dn_gets( buf, 2000, &crt.subject ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 295 | else if( strcmp( entity, "issuer" ) == 0 ) |
Paul Bakker | 86d0c19 | 2013-09-18 11:11:02 +0200 | [diff] [blame] | 296 | res = x509_dn_gets( buf, 2000, &crt.issuer ); |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 297 | else |
| 298 | TEST_ASSERT( "Unknown entity" == 0 ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 299 | |
| 300 | TEST_ASSERT( res != -1 ); |
| 301 | TEST_ASSERT( res != -2 ); |
| 302 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 303 | TEST_ASSERT( strcmp( buf, result_str ) == 0 ); |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 304 | |
| 305 | exit: |
| 306 | x509_crt_free( &crt ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 307 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 308 | /* END_CASE */ |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 309 | |
Manuel Pégourié-Gonnard | 8f63e95 | 2015-09-01 18:44:47 +0200 | [diff] [blame] | 310 | /* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CRT_PARSE_C */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 311 | void x509_time_expired( char *crt_file, char *entity, int result ) |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 312 | { |
Paul Bakker | c559c7a | 2013-09-18 14:13:26 +0200 | [diff] [blame] | 313 | x509_crt crt; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 314 | |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 315 | x509_crt_init( &crt ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 316 | |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 317 | TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 ); |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 318 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 319 | if( strcmp( entity, "valid_from" ) == 0 ) |
Paul Bakker | 86d0c19 | 2013-09-18 11:11:02 +0200 | [diff] [blame] | 320 | TEST_ASSERT( x509_time_expired( &crt.valid_from ) == result ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 321 | else if( strcmp( entity, "valid_to" ) == 0 ) |
Paul Bakker | 86d0c19 | 2013-09-18 11:11:02 +0200 | [diff] [blame] | 322 | TEST_ASSERT( x509_time_expired( &crt.valid_to ) == result ); |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 323 | else |
| 324 | TEST_ASSERT( "Unknown entity" == 0 ); |
Paul Bakker | b08e684 | 2012-02-11 18:43:20 +0000 | [diff] [blame] | 325 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 326 | exit: |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 327 | x509_crt_free( &crt ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 328 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 329 | /* END_CASE */ |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 330 | |
Manuel Pégourié-Gonnard | 8f63e95 | 2015-09-01 18:44:47 +0200 | [diff] [blame] | 331 | /* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CRT_PARSE_C */ |
Manuel Pégourié-Gonnard | 6304f78 | 2014-03-10 12:26:11 +0100 | [diff] [blame] | 332 | void x509_time_future( char *crt_file, char *entity, int result ) |
| 333 | { |
| 334 | x509_crt crt; |
| 335 | |
| 336 | x509_crt_init( &crt ); |
| 337 | |
| 338 | TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 ); |
| 339 | |
| 340 | if( strcmp( entity, "valid_from" ) == 0 ) |
| 341 | TEST_ASSERT( x509_time_future( &crt.valid_from ) == result ); |
| 342 | else if( strcmp( entity, "valid_to" ) == 0 ) |
| 343 | TEST_ASSERT( x509_time_future( &crt.valid_to ) == result ); |
| 344 | else |
| 345 | TEST_ASSERT( "Unknown entity" == 0 ); |
| 346 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 347 | exit: |
Manuel Pégourié-Gonnard | 6304f78 | 2014-03-10 12:26:11 +0100 | [diff] [blame] | 348 | x509_crt_free( &crt ); |
| 349 | } |
| 350 | /* END_CASE */ |
| 351 | |
Paul Bakker | 5a5fa92 | 2014-09-26 14:53:04 +0200 | [diff] [blame] | 352 | /* BEGIN_CASE depends_on:POLARSSL_X509_CRT_PARSE_C:POLARSSL_FS_IO */ |
| 353 | void x509parse_crt_file( char *crt_file, int result ) |
| 354 | { |
| 355 | x509_crt crt; |
| 356 | |
| 357 | x509_crt_init( &crt ); |
| 358 | |
| 359 | TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == result ); |
| 360 | |
| 361 | exit: |
| 362 | x509_crt_free( &crt ); |
| 363 | } |
| 364 | /* END_CASE */ |
| 365 | |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 366 | /* BEGIN_CASE depends_on:POLARSSL_X509_CRT_PARSE_C */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 367 | void x509parse_crt( char *crt_data, char *result_str, int result ) |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 368 | { |
Paul Bakker | c559c7a | 2013-09-18 14:13:26 +0200 | [diff] [blame] | 369 | x509_crt crt; |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 370 | unsigned char buf[2000]; |
| 371 | unsigned char output[2000]; |
| 372 | int data_len, res; |
| 373 | |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 374 | x509_crt_init( &crt ); |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 375 | memset( buf, 0, 2000 ); |
| 376 | memset( output, 0, 2000 ); |
| 377 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 378 | data_len = unhexify( buf, crt_data ); |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 379 | |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 380 | TEST_ASSERT( x509_crt_parse( &crt, buf, data_len ) == ( result ) ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 381 | if( ( result ) == 0 ) |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 382 | { |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 383 | res = x509_crt_info( (char *) output, 2000, "", &crt ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 384 | |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 385 | TEST_ASSERT( res != -1 ); |
| 386 | TEST_ASSERT( res != -2 ); |
| 387 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 388 | TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 ); |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 389 | } |
Paul Bakker | b08e684 | 2012-02-11 18:43:20 +0000 | [diff] [blame] | 390 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 391 | exit: |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 392 | x509_crt_free( &crt ); |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 393 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 394 | /* END_CASE */ |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 395 | |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 396 | /* BEGIN_CASE depends_on:POLARSSL_X509_CRL_PARSE_C */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 397 | void x509parse_crl( char *crl_data, char *result_str, int result ) |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 398 | { |
| 399 | x509_crl crl; |
| 400 | unsigned char buf[2000]; |
| 401 | unsigned char output[2000]; |
| 402 | int data_len, res; |
| 403 | |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 404 | x509_crl_init( &crl ); |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 405 | memset( buf, 0, 2000 ); |
| 406 | memset( output, 0, 2000 ); |
| 407 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 408 | data_len = unhexify( buf, crl_data ); |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 409 | |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 410 | TEST_ASSERT( x509_crl_parse( &crl, buf, data_len ) == ( result ) ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 411 | if( ( result ) == 0 ) |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 412 | { |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 413 | res = x509_crl_info( (char *) output, 2000, "", &crl ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 414 | |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 415 | TEST_ASSERT( res != -1 ); |
| 416 | TEST_ASSERT( res != -2 ); |
| 417 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 418 | TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 ); |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 419 | } |
Paul Bakker | b08e684 | 2012-02-11 18:43:20 +0000 | [diff] [blame] | 420 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 421 | exit: |
Paul Bakker | b08e684 | 2012-02-11 18:43:20 +0000 | [diff] [blame] | 422 | x509_crl_free( &crl ); |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 423 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 424 | /* END_CASE */ |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 425 | |
Manuel Pégourié-Gonnard | d77cd5d | 2014-06-13 11:13:15 +0200 | [diff] [blame] | 426 | /* BEGIN_CASE depends_on:POLARSSL_X509_CSR_PARSE_C */ |
| 427 | void x509_csr_parse( char *csr_der_hex, char *ref_out, int ref_ret ) |
| 428 | { |
| 429 | x509_csr csr; |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 430 | unsigned char *csr_der = NULL; |
Manuel Pégourié-Gonnard | d77cd5d | 2014-06-13 11:13:15 +0200 | [diff] [blame] | 431 | char my_out[1000]; |
| 432 | size_t csr_der_len; |
| 433 | int my_ret; |
| 434 | |
| 435 | x509_csr_init( &csr ); |
| 436 | memset( my_out, 0, sizeof( my_out ) ); |
| 437 | csr_der = unhexify_alloc( csr_der_hex, &csr_der_len ); |
| 438 | |
Manuel Pégourié-Gonnard | f3b4724 | 2014-06-16 18:06:48 +0200 | [diff] [blame] | 439 | my_ret = x509_csr_parse_der( &csr, csr_der, csr_der_len ); |
Manuel Pégourié-Gonnard | d77cd5d | 2014-06-13 11:13:15 +0200 | [diff] [blame] | 440 | TEST_ASSERT( my_ret == ref_ret ); |
| 441 | |
| 442 | if( ref_ret == 0 ) |
| 443 | { |
| 444 | size_t my_out_len = x509_csr_info( my_out, sizeof( my_out ), "", &csr ); |
| 445 | TEST_ASSERT( my_out_len == strlen( ref_out ) ); |
| 446 | TEST_ASSERT( strcmp( my_out, ref_out ) == 0 ); |
| 447 | } |
| 448 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 449 | exit: |
Manuel Pégourié-Gonnard | d77cd5d | 2014-06-13 11:13:15 +0200 | [diff] [blame] | 450 | x509_csr_free( &csr ); |
| 451 | polarssl_free( csr_der ); |
| 452 | } |
| 453 | /* END_CASE */ |
| 454 | |
Manuel Pégourié-Gonnard | fbae2a1 | 2013-11-26 16:43:39 +0100 | [diff] [blame] | 455 | /* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CRT_PARSE_C */ |
| 456 | void x509_crt_parse_path( char *crt_path, int ret, int nb_crt ) |
| 457 | { |
| 458 | x509_crt chain, *cur; |
| 459 | int i; |
| 460 | |
| 461 | x509_crt_init( &chain ); |
| 462 | |
| 463 | TEST_ASSERT( x509_crt_parse_path( &chain, crt_path ) == ret ); |
| 464 | |
| 465 | /* Check how many certs we got */ |
| 466 | for( i = 0, cur = &chain; cur != NULL; cur = cur->next ) |
| 467 | if( cur->raw.p != NULL ) |
| 468 | i++; |
| 469 | |
| 470 | TEST_ASSERT( i == nb_crt ); |
| 471 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 472 | exit: |
Paul Bakker | a2ffccd | 2013-12-02 21:56:37 +0100 | [diff] [blame] | 473 | x509_crt_free( &chain ); |
Manuel Pégourié-Gonnard | fbae2a1 | 2013-11-26 16:43:39 +0100 | [diff] [blame] | 474 | } |
| 475 | /* END_CASE */ |
| 476 | |
Janos Follath | 189c743 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 477 | /* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CRT_PARSE_C */ |
Janos Follath | 3d98a7e | 2015-10-11 16:17:27 +0200 | [diff] [blame] | 478 | void x509_crt_verify_chain( char *chain_paths, char *trusted_ca, int flags_result ) |
Janos Follath | 189c743 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 479 | { |
| 480 | char* act; |
| 481 | int flags; |
Janos Follath | 3d98a7e | 2015-10-11 16:17:27 +0200 | [diff] [blame] | 482 | int result, res; |
Janos Follath | 189c743 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 483 | x509_crt trusted, chain; |
| 484 | |
Janos Follath | 3d98a7e | 2015-10-11 16:17:27 +0200 | [diff] [blame] | 485 | result = flags_result ? POLARSSL_ERR_X509_CERT_VERIFY_FAILED : 0; |
| 486 | |
Janos Follath | 189c743 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 487 | x509_crt_init( &chain ); |
| 488 | x509_crt_init( &trusted ); |
| 489 | |
Manuel Pégourié-Gonnard | 28e1ac5 | 2015-11-02 06:34:46 +0900 | [diff] [blame] | 490 | while( ( act = mystrsep( &chain_paths, " " ) ) != NULL ) |
Janos Follath | 189c743 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 491 | TEST_ASSERT( x509_crt_parse_file( &chain, act ) == 0 ); |
| 492 | TEST_ASSERT( x509_crt_parse_file( &trusted, trusted_ca ) == 0 ); |
| 493 | |
| 494 | res = x509_crt_verify( &chain, &trusted, NULL, NULL, &flags, NULL, NULL ); |
| 495 | |
Janos Follath | 3d98a7e | 2015-10-11 16:17:27 +0200 | [diff] [blame] | 496 | TEST_ASSERT( res == result ); |
| 497 | TEST_ASSERT( flags == flags_result ); |
Janos Follath | 189c743 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 498 | |
| 499 | exit: |
| 500 | x509_crt_free( &trusted ); |
| 501 | x509_crt_free( &chain ); |
| 502 | } |
| 503 | /* END_CASE */ |
| 504 | |
Manuel Pégourié-Gonnard | 0f7b619 | 2014-06-24 11:37:54 +0200 | [diff] [blame] | 505 | /* BEGIN_CASE depends_on:POLARSSL_X509_USE_C */ |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 506 | void x509_oid_desc( char *oid_str, char *ref_desc ) |
| 507 | { |
| 508 | x509_buf oid; |
Manuel Pégourié-Gonnard | 079333b | 2015-03-20 18:14:26 +0000 | [diff] [blame] | 509 | const char *desc = NULL; |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 510 | unsigned char buf[20]; |
Manuel Pégourié-Gonnard | 079333b | 2015-03-20 18:14:26 +0000 | [diff] [blame] | 511 | int ret; |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 512 | |
| 513 | memset( buf, 0, sizeof buf ); |
| 514 | |
| 515 | oid.tag = ASN1_OID; |
| 516 | oid.len = unhexify( buf, oid_str ); |
| 517 | oid.p = buf; |
| 518 | |
Manuel Pégourié-Gonnard | 079333b | 2015-03-20 18:14:26 +0000 | [diff] [blame] | 519 | ret = oid_get_extended_key_usage( &oid, &desc ); |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 520 | |
| 521 | if( strcmp( ref_desc, "notfound" ) == 0 ) |
Manuel Pégourié-Gonnard | 079333b | 2015-03-20 18:14:26 +0000 | [diff] [blame] | 522 | { |
| 523 | TEST_ASSERT( ret != 0 ); |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 524 | TEST_ASSERT( desc == NULL ); |
Manuel Pégourié-Gonnard | 079333b | 2015-03-20 18:14:26 +0000 | [diff] [blame] | 525 | } |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 526 | else |
| 527 | { |
Manuel Pégourié-Gonnard | 079333b | 2015-03-20 18:14:26 +0000 | [diff] [blame] | 528 | TEST_ASSERT( ret == 0 ); |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 529 | TEST_ASSERT( desc != NULL ); |
| 530 | TEST_ASSERT( strcmp( desc, ref_desc ) == 0 ); |
| 531 | } |
| 532 | } |
| 533 | /* END_CASE */ |
| 534 | |
Manuel Pégourié-Gonnard | 0f7b619 | 2014-06-24 11:37:54 +0200 | [diff] [blame] | 535 | /* BEGIN_CASE depends_on:POLARSSL_X509_USE_C */ |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 536 | void x509_oid_numstr( char *oid_str, char *numstr, int blen, int ret ) |
| 537 | { |
| 538 | x509_buf oid; |
| 539 | unsigned char oid_buf[20]; |
| 540 | char num_buf[100]; |
| 541 | |
| 542 | memset( oid_buf, 0x00, sizeof oid_buf ); |
| 543 | memset( num_buf, 0x2a, sizeof num_buf ); |
| 544 | |
| 545 | oid.tag = ASN1_OID; |
| 546 | oid.len = unhexify( oid_buf, oid_str ); |
| 547 | oid.p = oid_buf; |
| 548 | |
| 549 | TEST_ASSERT( (size_t) blen <= sizeof num_buf ); |
| 550 | |
Manuel Pégourié-Gonnard | 079333b | 2015-03-20 18:14:26 +0000 | [diff] [blame] | 551 | TEST_ASSERT( oid_get_numeric_string( num_buf, blen, &oid ) == ret ); |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 552 | |
| 553 | if( ret >= 0 ) |
| 554 | { |
| 555 | TEST_ASSERT( num_buf[ret] == 0 ); |
| 556 | TEST_ASSERT( strcmp( num_buf, numstr ) == 0 ); |
| 557 | } |
| 558 | } |
| 559 | /* END_CASE */ |
| 560 | |
Paul Bakker | 5b11d02 | 2014-07-10 13:54:38 +0200 | [diff] [blame] | 561 | /* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CRT_PARSE_C:POLARSSL_X509_CHECK_KEY_USAGE */ |
Manuel Pégourié-Gonnard | 603116c | 2014-04-09 09:50:03 +0200 | [diff] [blame] | 562 | void x509_check_key_usage( char *crt_file, int usage, int ret ) |
| 563 | { |
| 564 | x509_crt crt; |
| 565 | |
| 566 | x509_crt_init( &crt ); |
| 567 | |
| 568 | TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 ); |
| 569 | |
| 570 | TEST_ASSERT( x509_crt_check_key_usage( &crt, usage ) == ret ); |
| 571 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 572 | exit: |
Manuel Pégourié-Gonnard | 603116c | 2014-04-09 09:50:03 +0200 | [diff] [blame] | 573 | x509_crt_free( &crt ); |
| 574 | } |
| 575 | /* END_CASE */ |
| 576 | |
Paul Bakker | 5b11d02 | 2014-07-10 13:54:38 +0200 | [diff] [blame] | 577 | /* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CRT_PARSE_C:POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE */ |
Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 578 | void x509_check_extended_key_usage( char *crt_file, char *usage_hex, int ret ) |
| 579 | { |
| 580 | x509_crt crt; |
| 581 | char oid[50]; |
| 582 | size_t len; |
| 583 | |
| 584 | x509_crt_init( &crt ); |
| 585 | |
| 586 | len = unhexify( (unsigned char *) oid, usage_hex ); |
| 587 | |
| 588 | TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 ); |
| 589 | |
| 590 | TEST_ASSERT( x509_crt_check_extended_key_usage( &crt, oid, len ) == ret ); |
| 591 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 592 | exit: |
Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 593 | x509_crt_free( &crt ); |
| 594 | } |
| 595 | /* END_CASE */ |
| 596 | |
Manuel Pégourié-Gonnard | d1539b1 | 2014-06-06 16:42:37 +0200 | [diff] [blame] | 597 | /* BEGIN_CASE depends_on:POLARSSL_X509_CRT_PARSE_C:POLARSSL_X509_RSASSA_PSS_SUPPORT */ |
Manuel Pégourié-Gonnard | 8540369 | 2014-06-06 14:48:38 +0200 | [diff] [blame] | 598 | void x509_parse_rsassa_pss_params( char *hex_params, int params_tag, |
| 599 | int ref_msg_md, int ref_mgf_md, |
| 600 | int ref_salt_len, int ref_ret ) |
| 601 | { |
| 602 | int my_ret; |
| 603 | x509_buf params; |
| 604 | md_type_t my_msg_md, my_mgf_md; |
| 605 | int my_salt_len; |
| 606 | |
| 607 | params.p = unhexify_alloc( hex_params, ¶ms.len ); |
| 608 | params.tag = params_tag; |
| 609 | |
| 610 | my_ret = x509_get_rsassa_pss_params( ¶ms, &my_msg_md, &my_mgf_md, |
| 611 | &my_salt_len ); |
| 612 | |
Manuel Pégourié-Gonnard | 8540369 | 2014-06-06 14:48:38 +0200 | [diff] [blame] | 613 | TEST_ASSERT( my_ret == ref_ret ); |
| 614 | |
| 615 | if( ref_ret == 0 ) |
| 616 | { |
| 617 | TEST_ASSERT( my_msg_md == (md_type_t) ref_msg_md ); |
| 618 | TEST_ASSERT( my_mgf_md == (md_type_t) ref_mgf_md ); |
| 619 | TEST_ASSERT( my_salt_len == ref_salt_len ); |
| 620 | } |
| 621 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 622 | exit: |
Manuel Pégourié-Gonnard | 8540369 | 2014-06-06 14:48:38 +0200 | [diff] [blame] | 623 | polarssl_free( params.p ); |
| 624 | } |
| 625 | /* END_CASE */ |
| 626 | |
Manuel Pégourié-Gonnard | 2014016 | 2013-10-10 12:48:03 +0200 | [diff] [blame] | 627 | /* BEGIN_CASE depends_on:POLARSSL_X509_CRT_PARSE_C:POLARSSL_SELF_TEST */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 628 | void x509_selftest() |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 629 | { |
| 630 | TEST_ASSERT( x509_self_test( 0 ) == 0 ); |
| 631 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 632 | /* END_CASE */ |