Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 1 | BEGIN_HEADER |
| 2 | #include <polarssl/x509.h> |
| 3 | END_HEADER |
| 4 | |
| 5 | BEGIN_CASE |
| 6 | x509_cert_info:crt_file:result_str |
| 7 | { |
| 8 | x509_cert crt; |
| 9 | char buf[2000]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 10 | int res; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 11 | |
| 12 | memset( &crt, 0, sizeof( x509_cert ) ); |
| 13 | memset( buf, 0, 2000 ); |
| 14 | |
| 15 | TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 ); |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 16 | res = x509parse_cert_info( buf, 2000, "", &crt ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 17 | |
| 18 | TEST_ASSERT( res != -1 ); |
| 19 | TEST_ASSERT( res != -2 ); |
| 20 | |
| 21 | TEST_ASSERT( strcmp( buf, {result_str} ) == 0 ); |
| 22 | } |
| 23 | END_CASE |
| 24 | |
| 25 | BEGIN_CASE |
| 26 | x509_crl_info:crl_file:result_str |
| 27 | { |
| 28 | x509_crl crl; |
| 29 | char buf[2000]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 30 | int res; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 31 | |
| 32 | memset( &crl, 0, sizeof( x509_crl ) ); |
| 33 | memset( buf, 0, 2000 ); |
| 34 | |
| 35 | TEST_ASSERT( x509parse_crlfile( &crl, {crl_file} ) == 0 ); |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 36 | res = x509parse_crl_info( buf, 2000, "", &crl ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 37 | |
| 38 | TEST_ASSERT( res != -1 ); |
| 39 | TEST_ASSERT( res != -2 ); |
| 40 | |
| 41 | TEST_ASSERT( strcmp( buf, {result_str} ) == 0 ); |
| 42 | } |
| 43 | END_CASE |
| 44 | |
| 45 | BEGIN_CASE |
| 46 | x509_verify:crt_file:ca_file:crl_file:cn_name:result |
| 47 | { |
| 48 | x509_cert crt; |
| 49 | x509_cert ca; |
| 50 | x509_crl crl; |
| 51 | int flags = 0; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 52 | int res; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 53 | |
| 54 | memset( &crt, 0, sizeof( x509_cert ) ); |
| 55 | memset( &ca, 0, sizeof( x509_cert ) ); |
| 56 | memset( &crl, 0, sizeof( x509_crl ) ); |
| 57 | |
| 58 | TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 ); |
| 59 | TEST_ASSERT( x509parse_crtfile( &ca, {ca_file} ) == 0 ); |
| 60 | TEST_ASSERT( x509parse_crlfile( &crl, {crl_file} ) == 0 ); |
| 61 | |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 62 | res = x509parse_verify( &crt, &ca, &crl, {cn_name}, &flags ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 63 | |
| 64 | if( res == 0 ) |
| 65 | { |
| 66 | TEST_ASSERT( res == ( {result} ) ); |
| 67 | } |
| 68 | else |
| 69 | { |
| 70 | TEST_ASSERT( flags == ( {result} ) ); |
| 71 | } |
| 72 | } |
| 73 | END_CASE |
| 74 | |
| 75 | BEGIN_CASE |
| 76 | x509_dn_gets:crt_file:entity:result_str |
| 77 | { |
| 78 | x509_cert crt; |
| 79 | char buf[2000]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 80 | int res; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 81 | |
| 82 | memset( &crt, 0, sizeof( x509_cert ) ); |
| 83 | memset( buf, 0, 2000 ); |
| 84 | |
| 85 | TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 ); |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 86 | res = x509parse_dn_gets( buf, 2000, &crt.{entity} ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 87 | |
| 88 | TEST_ASSERT( res != -1 ); |
| 89 | TEST_ASSERT( res != -2 ); |
| 90 | |
| 91 | TEST_ASSERT( strcmp( buf, {result_str} ) == 0 ); |
| 92 | } |
| 93 | END_CASE |
| 94 | |
| 95 | BEGIN_CASE |
| 96 | x509_time_expired:crt_file:entity:result |
| 97 | { |
| 98 | x509_cert crt; |
| 99 | |
| 100 | memset( &crt, 0, sizeof( x509_cert ) ); |
| 101 | |
| 102 | TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 ); |
| 103 | TEST_ASSERT( x509parse_time_expired( &crt.{entity} ) == {result} ); |
| 104 | } |
| 105 | END_CASE |
| 106 | |
| 107 | BEGIN_CASE |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame^] | 108 | x509parse_keyfile:key_file:password:result |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 109 | { |
| 110 | rsa_context rsa; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 111 | int res; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 112 | |
| 113 | memset( &rsa, 0, sizeof( rsa_context ) ); |
| 114 | |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 115 | res = x509parse_keyfile( &rsa, {key_file}, {password} ); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 116 | |
| 117 | TEST_ASSERT( res == {result} ); |
| 118 | |
| 119 | if( res == 0 ) |
| 120 | { |
| 121 | TEST_ASSERT( rsa_check_privkey( &rsa ) == 0 ); |
| 122 | } |
| 123 | } |
| 124 | END_CASE |
| 125 | |
| 126 | BEGIN_CASE |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 127 | x509parse_crt:crt_data:result_str:result |
| 128 | { |
| 129 | x509_cert crt; |
| 130 | unsigned char buf[2000]; |
| 131 | unsigned char output[2000]; |
| 132 | int data_len, res; |
| 133 | |
| 134 | memset( &crt, 0, sizeof( x509_cert ) ); |
| 135 | memset( buf, 0, 2000 ); |
| 136 | memset( output, 0, 2000 ); |
| 137 | |
| 138 | data_len = unhexify( buf, {crt_data} ); |
| 139 | |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 140 | TEST_ASSERT( x509parse_crt( &crt, buf, data_len ) == ( {result} ) ); |
| 141 | if( ( {result} ) == 0 ) |
| 142 | { |
| 143 | res = x509parse_cert_info( (char *) output, 2000, "", &crt ); |
| 144 | |
| 145 | TEST_ASSERT( res != -1 ); |
| 146 | TEST_ASSERT( res != -2 ); |
| 147 | |
| 148 | TEST_ASSERT( strcmp( (char *) output, {result_str} ) == 0 ); |
| 149 | } |
| 150 | } |
| 151 | END_CASE |
| 152 | |
| 153 | BEGIN_CASE |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame^] | 154 | x509parse_crl:crl_data:result_str:result |
| 155 | { |
| 156 | x509_crl crl; |
| 157 | unsigned char buf[2000]; |
| 158 | unsigned char output[2000]; |
| 159 | int data_len, res; |
| 160 | |
| 161 | memset( &crl, 0, sizeof( x509_crl ) ); |
| 162 | memset( buf, 0, 2000 ); |
| 163 | memset( output, 0, 2000 ); |
| 164 | |
| 165 | data_len = unhexify( buf, {crl_data} ); |
| 166 | |
| 167 | TEST_ASSERT( x509parse_crl( &crl, buf, data_len ) == ( {result} ) ); |
| 168 | if( ( {result} ) == 0 ) |
| 169 | { |
| 170 | res = x509parse_crl_info( (char *) output, 2000, "", &crl ); |
| 171 | |
| 172 | TEST_ASSERT( res != -1 ); |
| 173 | TEST_ASSERT( res != -2 ); |
| 174 | |
| 175 | TEST_ASSERT( strcmp( (char *) output, {result_str} ) == 0 ); |
| 176 | } |
| 177 | } |
| 178 | END_CASE |
| 179 | |
| 180 | BEGIN_CASE |
| 181 | x509parse_key:key_data:result_str:result |
| 182 | { |
| 183 | rsa_context rsa; |
| 184 | unsigned char buf[2000]; |
| 185 | unsigned char output[2000]; |
| 186 | int data_len, res; |
| 187 | |
| 188 | memset( &rsa, 0, sizeof( rsa_context ) ); |
| 189 | memset( buf, 0, 2000 ); |
| 190 | memset( output, 0, 2000 ); |
| 191 | |
| 192 | data_len = unhexify( buf, {key_data} ); |
| 193 | |
| 194 | res = x509parse_key( &rsa, buf, data_len, NULL, 0 ); |
| 195 | |
| 196 | TEST_ASSERT( x509parse_key( &rsa, buf, data_len, NULL, 0 ) == ( {result} ) ); |
| 197 | if( ( {result} ) == 0 ) |
| 198 | { |
| 199 | TEST_ASSERT( 1 ); |
| 200 | } |
| 201 | } |
| 202 | END_CASE |
| 203 | |
| 204 | BEGIN_CASE |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 205 | x509_selftest: |
| 206 | { |
| 207 | TEST_ASSERT( x509_self_test( 0 ) == 0 ); |
| 208 | } |
| 209 | END_CASE |