blob: fe9a7337565ea4a9a9b4864c6aa24fab21aee9ce [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{
7 return 1;
8}
9
10int verify_all( void *data, x509_cert *crt, int certificate_depth, int preverify_ok )
11{
12 return 0;
13}
14
Paul Bakker37940d9f2009-07-10 22:38:58 +000015END_HEADER
16
17BEGIN_CASE
18x509_cert_info:crt_file:result_str
19{
20 x509_cert crt;
21 char buf[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +000022 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +000023
24 memset( &crt, 0, sizeof( x509_cert ) );
25 memset( buf, 0, 2000 );
26
27 TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
Paul Bakker69998dd2009-07-11 19:15:20 +000028 res = x509parse_cert_info( buf, 2000, "", &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +000029
30 TEST_ASSERT( res != -1 );
31 TEST_ASSERT( res != -2 );
32
33 TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
34}
35END_CASE
36
37BEGIN_CASE
38x509_crl_info:crl_file:result_str
39{
40 x509_crl crl;
41 char buf[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +000042 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +000043
44 memset( &crl, 0, sizeof( x509_crl ) );
45 memset( buf, 0, 2000 );
46
47 TEST_ASSERT( x509parse_crlfile( &crl, {crl_file} ) == 0 );
Paul Bakker69998dd2009-07-11 19:15:20 +000048 res = x509parse_crl_info( buf, 2000, "", &crl );
Paul Bakker37940d9f2009-07-10 22:38:58 +000049
50 TEST_ASSERT( res != -1 );
51 TEST_ASSERT( res != -2 );
52
53 TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
54}
55END_CASE
56
57BEGIN_CASE
Paul Bakkerb63b0af2011-01-13 17:54:59 +000058x509_verify:crt_file:ca_file:crl_file:cn_name:result:flags:verify_callback
Paul Bakker37940d9f2009-07-10 22:38:58 +000059{
60 x509_cert crt;
61 x509_cert ca;
62 x509_crl crl;
63 int flags = 0;
Paul Bakker69998dd2009-07-11 19:15:20 +000064 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +000065
66 memset( &crt, 0, sizeof( x509_cert ) );
67 memset( &ca, 0, sizeof( x509_cert ) );
68 memset( &crl, 0, sizeof( x509_crl ) );
69
70 TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
71 TEST_ASSERT( x509parse_crtfile( &ca, {ca_file} ) == 0 );
72 TEST_ASSERT( x509parse_crlfile( &crl, {crl_file} ) == 0 );
73
Paul Bakkerb63b0af2011-01-13 17:54:59 +000074 res = x509parse_verify( &crt, &ca, &crl, {cn_name}, &flags, {verify_callback}, NULL );
Paul Bakker37940d9f2009-07-10 22:38:58 +000075
Paul Bakkerb63b0af2011-01-13 17:54:59 +000076 TEST_ASSERT( res == ( {result} ) );
77 TEST_ASSERT( flags == ( {flags} ) );
Paul Bakker37940d9f2009-07-10 22:38:58 +000078}
79END_CASE
80
81BEGIN_CASE
82x509_dn_gets:crt_file:entity:result_str
83{
84 x509_cert crt;
85 char buf[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +000086 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +000087
88 memset( &crt, 0, sizeof( x509_cert ) );
89 memset( buf, 0, 2000 );
90
91 TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
Paul Bakker69998dd2009-07-11 19:15:20 +000092 res = x509parse_dn_gets( buf, 2000, &crt.{entity} );
Paul Bakker37940d9f2009-07-10 22:38:58 +000093
94 TEST_ASSERT( res != -1 );
95 TEST_ASSERT( res != -2 );
96
97 TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
98}
99END_CASE
100
101BEGIN_CASE
102x509_time_expired:crt_file:entity:result
103{
104 x509_cert crt;
105
106 memset( &crt, 0, sizeof( x509_cert ) );
107
108 TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
109 TEST_ASSERT( x509parse_time_expired( &crt.{entity} ) == {result} );
110}
111END_CASE
112
113BEGIN_CASE
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000114x509parse_keyfile:key_file:password:result
Paul Bakker37940d9f2009-07-10 22:38:58 +0000115{
116 rsa_context rsa;
Paul Bakker69998dd2009-07-11 19:15:20 +0000117 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000118
119 memset( &rsa, 0, sizeof( rsa_context ) );
120
Paul Bakker69998dd2009-07-11 19:15:20 +0000121 res = x509parse_keyfile( &rsa, {key_file}, {password} );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000122
123 TEST_ASSERT( res == {result} );
124
125 if( res == 0 )
126 {
127 TEST_ASSERT( rsa_check_privkey( &rsa ) == 0 );
128 }
129}
130END_CASE
131
132BEGIN_CASE
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000133x509parse_crt:crt_data:result_str:result
134{
135 x509_cert crt;
136 unsigned char buf[2000];
137 unsigned char output[2000];
138 int data_len, res;
139
140 memset( &crt, 0, sizeof( x509_cert ) );
141 memset( buf, 0, 2000 );
142 memset( output, 0, 2000 );
143
144 data_len = unhexify( buf, {crt_data} );
145
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000146 TEST_ASSERT( x509parse_crt( &crt, buf, data_len ) == ( {result} ) );
147 if( ( {result} ) == 0 )
148 {
149 res = x509parse_cert_info( (char *) output, 2000, "", &crt );
150
151 TEST_ASSERT( res != -1 );
152 TEST_ASSERT( res != -2 );
153
154 TEST_ASSERT( strcmp( (char *) output, {result_str} ) == 0 );
155 }
156}
157END_CASE
158
159BEGIN_CASE
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000160x509parse_crl:crl_data:result_str:result
161{
162 x509_crl crl;
163 unsigned char buf[2000];
164 unsigned char output[2000];
165 int data_len, res;
166
167 memset( &crl, 0, sizeof( x509_crl ) );
168 memset( buf, 0, 2000 );
169 memset( output, 0, 2000 );
170
171 data_len = unhexify( buf, {crl_data} );
172
173 TEST_ASSERT( x509parse_crl( &crl, buf, data_len ) == ( {result} ) );
174 if( ( {result} ) == 0 )
175 {
176 res = x509parse_crl_info( (char *) output, 2000, "", &crl );
177
178 TEST_ASSERT( res != -1 );
179 TEST_ASSERT( res != -2 );
180
181 TEST_ASSERT( strcmp( (char *) output, {result_str} ) == 0 );
182 }
183}
184END_CASE
185
186BEGIN_CASE
187x509parse_key:key_data:result_str:result
188{
189 rsa_context rsa;
190 unsigned char buf[2000];
191 unsigned char output[2000];
192 int data_len, res;
193
194 memset( &rsa, 0, sizeof( rsa_context ) );
195 memset( buf, 0, 2000 );
196 memset( output, 0, 2000 );
197
198 data_len = unhexify( buf, {key_data} );
199
200 res = x509parse_key( &rsa, buf, data_len, NULL, 0 );
201
202 TEST_ASSERT( x509parse_key( &rsa, buf, data_len, NULL, 0 ) == ( {result} ) );
203 if( ( {result} ) == 0 )
204 {
205 TEST_ASSERT( 1 );
206 }
207}
208END_CASE
209
210BEGIN_CASE
Paul Bakker37940d9f2009-07-10 22:38:58 +0000211x509_selftest:
212{
213 TEST_ASSERT( x509_self_test( 0 ) == 0 );
214}
215END_CASE