blob: 9a7a46019858e7d7ecb21859e68e5c4fb7c14a31 [file] [log] [blame]
Paul Bakker37940d9f2009-07-10 22:38:58 +00001BEGIN_HEADER
Paul Bakkerb63b0af2011-01-13 17:54:59 +00002#include <polarssl/config.h>
Paul Bakker37940d9f2009-07-10 22:38:58 +00003#include <polarssl/x509.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
27BEGIN_CASE
28x509_cert_info:crt_file:result_str
29{
30 x509_cert crt;
31 char buf[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +000032 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +000033
34 memset( &crt, 0, sizeof( x509_cert ) );
35 memset( buf, 0, 2000 );
36
37 TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
Paul Bakker69998dd2009-07-11 19:15:20 +000038 res = x509parse_cert_info( buf, 2000, "", &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +000039
40 TEST_ASSERT( res != -1 );
41 TEST_ASSERT( res != -2 );
42
43 TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
44}
45END_CASE
46
47BEGIN_CASE
48x509_crl_info:crl_file:result_str
49{
50 x509_crl crl;
51 char buf[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +000052 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +000053
54 memset( &crl, 0, sizeof( x509_crl ) );
55 memset( buf, 0, 2000 );
56
57 TEST_ASSERT( x509parse_crlfile( &crl, {crl_file} ) == 0 );
Paul Bakker69998dd2009-07-11 19:15:20 +000058 res = x509parse_crl_info( buf, 2000, "", &crl );
Paul Bakker37940d9f2009-07-10 22:38:58 +000059
60 TEST_ASSERT( res != -1 );
61 TEST_ASSERT( res != -2 );
62
63 TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
64}
65END_CASE
66
67BEGIN_CASE
Paul Bakkerb63b0af2011-01-13 17:54:59 +000068x509_verify:crt_file:ca_file:crl_file:cn_name:result:flags:verify_callback
Paul Bakker37940d9f2009-07-10 22:38:58 +000069{
70 x509_cert crt;
71 x509_cert ca;
72 x509_crl crl;
73 int flags = 0;
Paul Bakker69998dd2009-07-11 19:15:20 +000074 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +000075
76 memset( &crt, 0, sizeof( x509_cert ) );
77 memset( &ca, 0, sizeof( x509_cert ) );
78 memset( &crl, 0, sizeof( x509_crl ) );
79
80 TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
81 TEST_ASSERT( x509parse_crtfile( &ca, {ca_file} ) == 0 );
82 TEST_ASSERT( x509parse_crlfile( &crl, {crl_file} ) == 0 );
83
Paul Bakkerb63b0af2011-01-13 17:54:59 +000084 res = x509parse_verify( &crt, &ca, &crl, {cn_name}, &flags, {verify_callback}, NULL );
Paul Bakker37940d9f2009-07-10 22:38:58 +000085
Paul Bakkerb63b0af2011-01-13 17:54:59 +000086 TEST_ASSERT( res == ( {result} ) );
87 TEST_ASSERT( flags == ( {flags} ) );
Paul Bakker37940d9f2009-07-10 22:38:58 +000088}
89END_CASE
90
91BEGIN_CASE
92x509_dn_gets:crt_file:entity:result_str
93{
94 x509_cert crt;
95 char buf[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +000096 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +000097
98 memset( &crt, 0, sizeof( x509_cert ) );
99 memset( buf, 0, 2000 );
100
101 TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
Paul Bakker69998dd2009-07-11 19:15:20 +0000102 res = x509parse_dn_gets( buf, 2000, &crt.{entity} );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000103
104 TEST_ASSERT( res != -1 );
105 TEST_ASSERT( res != -2 );
106
107 TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
108}
109END_CASE
110
111BEGIN_CASE
112x509_time_expired:crt_file:entity:result
113{
114 x509_cert crt;
115
116 memset( &crt, 0, sizeof( x509_cert ) );
117
118 TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
119 TEST_ASSERT( x509parse_time_expired( &crt.{entity} ) == {result} );
120}
121END_CASE
122
123BEGIN_CASE
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000124x509parse_keyfile:key_file:password:result
Paul Bakker37940d9f2009-07-10 22:38:58 +0000125{
126 rsa_context rsa;
Paul Bakker69998dd2009-07-11 19:15:20 +0000127 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000128
129 memset( &rsa, 0, sizeof( rsa_context ) );
130
Paul Bakker69998dd2009-07-11 19:15:20 +0000131 res = x509parse_keyfile( &rsa, {key_file}, {password} );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000132
133 TEST_ASSERT( res == {result} );
134
135 if( res == 0 )
136 {
137 TEST_ASSERT( rsa_check_privkey( &rsa ) == 0 );
138 }
139}
140END_CASE
141
142BEGIN_CASE
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000143x509parse_crt:crt_data:result_str:result
144{
145 x509_cert crt;
146 unsigned char buf[2000];
147 unsigned char output[2000];
148 int data_len, res;
149
150 memset( &crt, 0, sizeof( x509_cert ) );
151 memset( buf, 0, 2000 );
152 memset( output, 0, 2000 );
153
154 data_len = unhexify( buf, {crt_data} );
155
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000156 TEST_ASSERT( x509parse_crt( &crt, buf, data_len ) == ( {result} ) );
157 if( ( {result} ) == 0 )
158 {
159 res = x509parse_cert_info( (char *) output, 2000, "", &crt );
160
161 TEST_ASSERT( res != -1 );
162 TEST_ASSERT( res != -2 );
163
164 TEST_ASSERT( strcmp( (char *) output, {result_str} ) == 0 );
165 }
166}
167END_CASE
168
169BEGIN_CASE
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000170x509parse_crl:crl_data:result_str:result
171{
172 x509_crl crl;
173 unsigned char buf[2000];
174 unsigned char output[2000];
175 int data_len, res;
176
177 memset( &crl, 0, sizeof( x509_crl ) );
178 memset( buf, 0, 2000 );
179 memset( output, 0, 2000 );
180
181 data_len = unhexify( buf, {crl_data} );
182
183 TEST_ASSERT( x509parse_crl( &crl, buf, data_len ) == ( {result} ) );
184 if( ( {result} ) == 0 )
185 {
186 res = x509parse_crl_info( (char *) output, 2000, "", &crl );
187
188 TEST_ASSERT( res != -1 );
189 TEST_ASSERT( res != -2 );
190
191 TEST_ASSERT( strcmp( (char *) output, {result_str} ) == 0 );
192 }
193}
194END_CASE
195
196BEGIN_CASE
197x509parse_key:key_data:result_str:result
198{
199 rsa_context rsa;
200 unsigned char buf[2000];
201 unsigned char output[2000];
202 int data_len, res;
203
204 memset( &rsa, 0, sizeof( rsa_context ) );
205 memset( buf, 0, 2000 );
206 memset( output, 0, 2000 );
207
208 data_len = unhexify( buf, {key_data} );
209
210 res = x509parse_key( &rsa, buf, data_len, NULL, 0 );
211
212 TEST_ASSERT( x509parse_key( &rsa, buf, data_len, NULL, 0 ) == ( {result} ) );
213 if( ( {result} ) == 0 )
214 {
215 TEST_ASSERT( 1 );
216 }
217}
218END_CASE
219
220BEGIN_CASE
Paul Bakker37940d9f2009-07-10 22:38:58 +0000221x509_selftest:
222{
223 TEST_ASSERT( x509_self_test( 0 ) == 0 );
224}
225END_CASE