blob: b56b893108ecaaf2089dc1d09e009dec5765d040 [file] [log] [blame]
Paul Bakker37940d9f2009-07-10 22:38:58 +00001BEGIN_HEADER
2#include <polarssl/x509.h>
3END_HEADER
4
5BEGIN_CASE
6x509_cert_info:crt_file:result_str
7{
8 x509_cert crt;
9 char buf[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +000010 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +000011
12 memset( &crt, 0, sizeof( x509_cert ) );
13 memset( buf, 0, 2000 );
14
15 TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
Paul Bakker69998dd2009-07-11 19:15:20 +000016 res = x509parse_cert_info( buf, 2000, "", &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +000017
18 TEST_ASSERT( res != -1 );
19 TEST_ASSERT( res != -2 );
20
21 TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
22}
23END_CASE
24
25BEGIN_CASE
26x509_crl_info:crl_file:result_str
27{
28 x509_crl crl;
29 char buf[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +000030 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +000031
32 memset( &crl, 0, sizeof( x509_crl ) );
33 memset( buf, 0, 2000 );
34
35 TEST_ASSERT( x509parse_crlfile( &crl, {crl_file} ) == 0 );
Paul Bakker69998dd2009-07-11 19:15:20 +000036 res = x509parse_crl_info( buf, 2000, "", &crl );
Paul Bakker37940d9f2009-07-10 22:38:58 +000037
38 TEST_ASSERT( res != -1 );
39 TEST_ASSERT( res != -2 );
40
41 TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
42}
43END_CASE
44
45BEGIN_CASE
46x509_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 Bakker69998dd2009-07-11 19:15:20 +000052 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +000053
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 Bakker69998dd2009-07-11 19:15:20 +000062 res = x509parse_verify( &crt, &ca, &crl, {cn_name}, &flags );
Paul Bakker37940d9f2009-07-10 22:38:58 +000063
64 if( res == 0 )
65 {
66 TEST_ASSERT( res == ( {result} ) );
67 }
68 else
69 {
70 TEST_ASSERT( flags == ( {result} ) );
71 }
72}
73END_CASE
74
75BEGIN_CASE
76x509_dn_gets:crt_file:entity:result_str
77{
78 x509_cert crt;
79 char buf[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +000080 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +000081
82 memset( &crt, 0, sizeof( x509_cert ) );
83 memset( buf, 0, 2000 );
84
85 TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
Paul Bakker69998dd2009-07-11 19:15:20 +000086 res = x509parse_dn_gets( buf, 2000, &crt.{entity} );
Paul Bakker37940d9f2009-07-10 22:38:58 +000087
88 TEST_ASSERT( res != -1 );
89 TEST_ASSERT( res != -2 );
90
91 TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
92}
93END_CASE
94
95BEGIN_CASE
96x509_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}
105END_CASE
106
107BEGIN_CASE
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000108x509parse_keyfile:key_file:password:result
Paul Bakker37940d9f2009-07-10 22:38:58 +0000109{
110 rsa_context rsa;
Paul Bakker69998dd2009-07-11 19:15:20 +0000111 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000112
113 memset( &rsa, 0, sizeof( rsa_context ) );
114
Paul Bakker69998dd2009-07-11 19:15:20 +0000115 res = x509parse_keyfile( &rsa, {key_file}, {password} );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000116
117 TEST_ASSERT( res == {result} );
118
119 if( res == 0 )
120 {
121 TEST_ASSERT( rsa_check_privkey( &rsa ) == 0 );
122 }
123}
124END_CASE
125
126BEGIN_CASE
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000127x509parse_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 Bakkerb2c38f52009-07-19 19:36:15 +0000140 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}
151END_CASE
152
153BEGIN_CASE
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000154x509parse_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}
178END_CASE
179
180BEGIN_CASE
181x509parse_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}
202END_CASE
203
204BEGIN_CASE
Paul Bakker37940d9f2009-07-10 22:38:58 +0000205x509_selftest:
206{
207 TEST_ASSERT( x509_self_test( 0 ) == 0 );
208}
209END_CASE