blob: 18e1c41f3dc7cc360b2b8d4632202c58c34e0703 [file] [log] [blame]
Paul Bakker37940d9f2009-07-10 22:38:58 +00001BEGIN_HEADER
2#include <polarssl/x509.h>
Paul Bakker96743fc2011-02-12 14:30:57 +00003#include <polarssl/pem.h>
Paul Bakkerb63b0af2011-01-13 17:54:59 +00004
5int verify_none( void *data, x509_cert *crt, int certificate_depth, int preverify_ok )
6{
Paul Bakker5a624082011-01-18 16:31:52 +00007 ((void) data);
8 ((void) crt);
9 ((void) certificate_depth);
10 ((void) preverify_ok);
11
Paul Bakkerb63b0af2011-01-13 17:54:59 +000012 return 1;
13}
14
15int verify_all( void *data, x509_cert *crt, int certificate_depth, int preverify_ok )
16{
Paul Bakker5a624082011-01-18 16:31:52 +000017 ((void) data);
18 ((void) crt);
19 ((void) certificate_depth);
20 ((void) preverify_ok);
21
Paul Bakkerb63b0af2011-01-13 17:54:59 +000022 return 0;
23}
24
Paul Bakker37940d9f2009-07-10 22:38:58 +000025END_HEADER
26
Paul Bakker5690efc2011-05-26 13:16:06 +000027BEGIN_DEPENDENCIES
28depends_on:POLARSSL_X509_PARSE_C:POLARSSL_BIGNUM_C
29END_DEPENDENCIES
30
Paul Bakker37940d9f2009-07-10 22:38:58 +000031BEGIN_CASE
32x509_cert_info:crt_file:result_str
33{
34 x509_cert crt;
35 char buf[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +000036 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +000037
38 memset( &crt, 0, sizeof( x509_cert ) );
39 memset( buf, 0, 2000 );
40
41 TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
Paul Bakker69998dd2009-07-11 19:15:20 +000042 res = x509parse_cert_info( buf, 2000, "", &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +000043
44 TEST_ASSERT( res != -1 );
45 TEST_ASSERT( res != -2 );
46
47 TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
48}
49END_CASE
50
51BEGIN_CASE
52x509_crl_info:crl_file:result_str
53{
54 x509_crl crl;
55 char buf[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +000056 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +000057
58 memset( &crl, 0, sizeof( x509_crl ) );
59 memset( buf, 0, 2000 );
60
61 TEST_ASSERT( x509parse_crlfile( &crl, {crl_file} ) == 0 );
Paul Bakker69998dd2009-07-11 19:15:20 +000062 res = x509parse_crl_info( buf, 2000, "", &crl );
Paul Bakker37940d9f2009-07-10 22:38:58 +000063
64 TEST_ASSERT( res != -1 );
65 TEST_ASSERT( res != -2 );
66
67 TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
68}
69END_CASE
70
71BEGIN_CASE
Paul Bakkerb63b0af2011-01-13 17:54:59 +000072x509_verify:crt_file:ca_file:crl_file:cn_name:result:flags:verify_callback
Paul Bakker37940d9f2009-07-10 22:38:58 +000073{
74 x509_cert crt;
75 x509_cert ca;
76 x509_crl crl;
77 int flags = 0;
Paul Bakker69998dd2009-07-11 19:15:20 +000078 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +000079
80 memset( &crt, 0, sizeof( x509_cert ) );
81 memset( &ca, 0, sizeof( x509_cert ) );
82 memset( &crl, 0, sizeof( x509_crl ) );
83
84 TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
85 TEST_ASSERT( x509parse_crtfile( &ca, {ca_file} ) == 0 );
86 TEST_ASSERT( x509parse_crlfile( &crl, {crl_file} ) == 0 );
87
Paul Bakkerb63b0af2011-01-13 17:54:59 +000088 res = x509parse_verify( &crt, &ca, &crl, {cn_name}, &flags, {verify_callback}, NULL );
Paul Bakker37940d9f2009-07-10 22:38:58 +000089
Paul Bakkerb63b0af2011-01-13 17:54:59 +000090 TEST_ASSERT( res == ( {result} ) );
91 TEST_ASSERT( flags == ( {flags} ) );
Paul Bakker37940d9f2009-07-10 22:38:58 +000092}
93END_CASE
94
95BEGIN_CASE
96x509_dn_gets:crt_file:entity:result_str
97{
98 x509_cert crt;
99 char buf[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +0000100 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000101
102 memset( &crt, 0, sizeof( x509_cert ) );
103 memset( buf, 0, 2000 );
104
105 TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
Paul Bakker69998dd2009-07-11 19:15:20 +0000106 res = x509parse_dn_gets( buf, 2000, &crt.{entity} );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000107
108 TEST_ASSERT( res != -1 );
109 TEST_ASSERT( res != -2 );
110
111 TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
112}
113END_CASE
114
115BEGIN_CASE
116x509_time_expired:crt_file:entity:result
117{
118 x509_cert crt;
119
120 memset( &crt, 0, sizeof( x509_cert ) );
121
122 TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
123 TEST_ASSERT( x509parse_time_expired( &crt.{entity} ) == {result} );
124}
125END_CASE
126
127BEGIN_CASE
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000128x509parse_keyfile:key_file:password:result
Paul Bakker37940d9f2009-07-10 22:38:58 +0000129{
130 rsa_context rsa;
Paul Bakker69998dd2009-07-11 19:15:20 +0000131 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000132
133 memset( &rsa, 0, sizeof( rsa_context ) );
134
Paul Bakker69998dd2009-07-11 19:15:20 +0000135 res = x509parse_keyfile( &rsa, {key_file}, {password} );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000136
137 TEST_ASSERT( res == {result} );
138
139 if( res == 0 )
140 {
141 TEST_ASSERT( rsa_check_privkey( &rsa ) == 0 );
142 }
143}
144END_CASE
145
146BEGIN_CASE
Paul Bakker36f1b192011-07-13 11:32:29 +0000147x509parse_public_keyfile:key_file:result
148{
149 rsa_context rsa;
150 int res;
151
152 memset( &rsa, 0, sizeof( rsa_context ) );
153
154 res = x509parse_public_keyfile( &rsa, {key_file} );
155
156 TEST_ASSERT( res == {result} );
157
158 if( res == 0 )
159 {
160 TEST_ASSERT( rsa_check_pubkey( &rsa ) == 0 );
161 }
162}
163END_CASE
164
165BEGIN_CASE
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000166x509parse_crt:crt_data:result_str:result
167{
168 x509_cert crt;
169 unsigned char buf[2000];
170 unsigned char output[2000];
171 int data_len, res;
172
173 memset( &crt, 0, sizeof( x509_cert ) );
174 memset( buf, 0, 2000 );
175 memset( output, 0, 2000 );
176
177 data_len = unhexify( buf, {crt_data} );
178
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000179 TEST_ASSERT( x509parse_crt( &crt, buf, data_len ) == ( {result} ) );
180 if( ( {result} ) == 0 )
181 {
182 res = x509parse_cert_info( (char *) output, 2000, "", &crt );
183
184 TEST_ASSERT( res != -1 );
185 TEST_ASSERT( res != -2 );
186
187 TEST_ASSERT( strcmp( (char *) output, {result_str} ) == 0 );
188 }
189}
190END_CASE
191
192BEGIN_CASE
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000193x509parse_crl:crl_data:result_str:result
194{
195 x509_crl crl;
196 unsigned char buf[2000];
197 unsigned char output[2000];
198 int data_len, res;
199
200 memset( &crl, 0, sizeof( x509_crl ) );
201 memset( buf, 0, 2000 );
202 memset( output, 0, 2000 );
203
204 data_len = unhexify( buf, {crl_data} );
205
206 TEST_ASSERT( x509parse_crl( &crl, buf, data_len ) == ( {result} ) );
207 if( ( {result} ) == 0 )
208 {
209 res = x509parse_crl_info( (char *) output, 2000, "", &crl );
210
211 TEST_ASSERT( res != -1 );
212 TEST_ASSERT( res != -2 );
213
214 TEST_ASSERT( strcmp( (char *) output, {result_str} ) == 0 );
215 }
216}
217END_CASE
218
219BEGIN_CASE
220x509parse_key:key_data:result_str:result
221{
222 rsa_context rsa;
223 unsigned char buf[2000];
224 unsigned char output[2000];
Paul Bakkereaf90d92011-07-13 14:21:52 +0000225 int data_len;
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000226
227 memset( &rsa, 0, sizeof( rsa_context ) );
228 memset( buf, 0, 2000 );
229 memset( output, 0, 2000 );
230
231 data_len = unhexify( buf, {key_data} );
232
Paul Bakkereaf90d92011-07-13 14:21:52 +0000233 x509parse_key( &rsa, buf, data_len, NULL, 0 );
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000234
235 TEST_ASSERT( x509parse_key( &rsa, buf, data_len, NULL, 0 ) == ( {result} ) );
236 if( ( {result} ) == 0 )
237 {
238 TEST_ASSERT( 1 );
239 }
240}
241END_CASE
242
243BEGIN_CASE
Paul Bakker37940d9f2009-07-10 22:38:58 +0000244x509_selftest:
245{
246 TEST_ASSERT( x509_self_test( 0 ) == 0 );
247}
248END_CASE