blob: 984a346a17d48002401f63ffd6000afba834dc11 [file] [log] [blame]
Paul Bakker6d620502012-02-16 14:09:13 +00001BEGIN_HEADER
2#include <polarssl/x509write.h>
3#include <polarssl/x509.h>
4#include <polarssl/pem.h>
5END_HEADER
6
7BEGIN_DEPENDENCIES
8depends_on:POLARSSL_X509_WRITE_C:POLARSSL_BIGNUM_C
9END_DEPENDENCIES
10
11BEGIN_CASE
12x509_cert_req_check:key_file:md_type:cert_req_check_file
13{
14 rsa_context rsa;
15 pem_context pem;
16 x509_req_name req_name, *cur;
17 unsigned char *c;
18 unsigned char buf[4000];
19 unsigned char check_buf[4000];
20 int ret;
21 size_t olen = 2000;
22 FILE *f;
23
24 cur = &req_name;
25
26 memset( cur, 0, sizeof(x509_req_name) );
27 strcpy( cur->oid, OID_CN );
28 strcpy( cur->name, "PolarSSL Server 1" );
29 cur->next = malloc( sizeof(x509_req_name) );
30 cur = cur->next;
31
32 memset( cur, 0, sizeof(x509_req_name) );
33 strcpy( cur->oid, OID_ORGANIZATION );
34 strcpy( cur->name, "PolarSSL" );
35 cur->next = malloc( sizeof(x509_req_name) );
36 cur = cur->next;
37
38 memset( cur, 0, sizeof(x509_req_name) );
39 strcpy( cur->oid, OID_COUNTRY );
40 strcpy( cur->name, "NL" );
41
42 memset( &rsa, 0, sizeof(rsa_context) );
43 ret = x509parse_keyfile( &rsa, {key_file}, NULL );
44 TEST_ASSERT( ret == 0 );
45 if( ret != 0 )
46 return 0;
47
48 ret = x509_write_cert_req( buf, 4000, &rsa, &req_name, {md_type} );
49 TEST_ASSERT( ret >= 0 );
50
51 c = buf + 3999 - ret;
52
53 f = fopen( {cert_req_check_file}, "r" );
54 TEST_ASSERT( f != NULL );
55 fread( check_buf, 1, 4000, f );
56 fclose( f );
57
58 pem_init( &pem );
59 pem_read_buffer( &pem, "-----BEGIN CERTIFICATE REQUEST-----", "-----END CERTIFICATE REQUEST-----", check_buf, NULL, 0, &olen );
60
61 TEST_ASSERT( memcmp( c, pem.buf, pem.buflen ) == 0 );
62 TEST_ASSERT( pem.buflen == (size_t) ret );
63}
64END_CASE