blob: 938d3d0c849c6e5cc63b65de774f2be4fae542cb [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 Bakkerb2c38f52009-07-19 19:36:15 +0000147x509parse_crt:crt_data:result_str:result
148{
149 x509_cert crt;
150 unsigned char buf[2000];
151 unsigned char output[2000];
152 int data_len, res;
153
154 memset( &crt, 0, sizeof( x509_cert ) );
155 memset( buf, 0, 2000 );
156 memset( output, 0, 2000 );
157
158 data_len = unhexify( buf, {crt_data} );
159
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000160 TEST_ASSERT( x509parse_crt( &crt, buf, data_len ) == ( {result} ) );
161 if( ( {result} ) == 0 )
162 {
163 res = x509parse_cert_info( (char *) output, 2000, "", &crt );
164
165 TEST_ASSERT( res != -1 );
166 TEST_ASSERT( res != -2 );
167
168 TEST_ASSERT( strcmp( (char *) output, {result_str} ) == 0 );
169 }
170}
171END_CASE
172
173BEGIN_CASE
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000174x509parse_crl:crl_data:result_str:result
175{
176 x509_crl crl;
177 unsigned char buf[2000];
178 unsigned char output[2000];
179 int data_len, res;
180
181 memset( &crl, 0, sizeof( x509_crl ) );
182 memset( buf, 0, 2000 );
183 memset( output, 0, 2000 );
184
185 data_len = unhexify( buf, {crl_data} );
186
187 TEST_ASSERT( x509parse_crl( &crl, buf, data_len ) == ( {result} ) );
188 if( ( {result} ) == 0 )
189 {
190 res = x509parse_crl_info( (char *) output, 2000, "", &crl );
191
192 TEST_ASSERT( res != -1 );
193 TEST_ASSERT( res != -2 );
194
195 TEST_ASSERT( strcmp( (char *) output, {result_str} ) == 0 );
196 }
197}
198END_CASE
199
200BEGIN_CASE
201x509parse_key:key_data:result_str:result
202{
203 rsa_context rsa;
204 unsigned char buf[2000];
205 unsigned char output[2000];
206 int data_len, res;
207
208 memset( &rsa, 0, sizeof( rsa_context ) );
209 memset( buf, 0, 2000 );
210 memset( output, 0, 2000 );
211
212 data_len = unhexify( buf, {key_data} );
213
214 res = x509parse_key( &rsa, buf, data_len, NULL, 0 );
215
216 TEST_ASSERT( x509parse_key( &rsa, buf, data_len, NULL, 0 ) == ( {result} ) );
217 if( ( {result} ) == 0 )
218 {
219 TEST_ASSERT( 1 );
220 }
221}
222END_CASE
223
224BEGIN_CASE
Paul Bakker37940d9f2009-07-10 22:38:58 +0000225x509_selftest:
226{
227 TEST_ASSERT( x509_self_test( 0 ) == 0 );
228}
229END_CASE