Paul Bakker | 6d62050 | 2012-02-16 14:09:13 +0000 | [diff] [blame] | 1 | BEGIN_HEADER |
| 2 | #include <polarssl/x509write.h> |
| 3 | #include <polarssl/x509.h> |
| 4 | #include <polarssl/pem.h> |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 5 | #include <polarssl/oid.h> |
Paul Bakker | 6d62050 | 2012-02-16 14:09:13 +0000 | [diff] [blame] | 6 | END_HEADER |
| 7 | |
| 8 | BEGIN_DEPENDENCIES |
| 9 | depends_on:POLARSSL_X509_WRITE_C:POLARSSL_BIGNUM_C |
| 10 | END_DEPENDENCIES |
| 11 | |
| 12 | BEGIN_CASE |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame^] | 13 | x509_cert_req_check:key_file:#md_type:cert_req_check_file |
Paul Bakker | 6d62050 | 2012-02-16 14:09:13 +0000 | [diff] [blame] | 14 | { |
| 15 | rsa_context rsa; |
| 16 | pem_context pem; |
| 17 | x509_req_name req_name, *cur; |
| 18 | unsigned char *c; |
| 19 | unsigned char buf[4000]; |
| 20 | unsigned char check_buf[4000]; |
| 21 | int ret; |
| 22 | size_t olen = 2000; |
| 23 | FILE *f; |
| 24 | |
| 25 | cur = &req_name; |
| 26 | |
| 27 | memset( cur, 0, sizeof(x509_req_name) ); |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 28 | strcpy( cur->oid, OID_AT_CN ); |
Paul Bakker | 6d62050 | 2012-02-16 14:09:13 +0000 | [diff] [blame] | 29 | strcpy( cur->name, "PolarSSL Server 1" ); |
| 30 | cur->next = malloc( sizeof(x509_req_name) ); |
| 31 | cur = cur->next; |
| 32 | |
| 33 | memset( cur, 0, sizeof(x509_req_name) ); |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 34 | strcpy( cur->oid, OID_AT_ORGANIZATION ); |
Paul Bakker | 6d62050 | 2012-02-16 14:09:13 +0000 | [diff] [blame] | 35 | strcpy( cur->name, "PolarSSL" ); |
| 36 | cur->next = malloc( sizeof(x509_req_name) ); |
| 37 | cur = cur->next; |
| 38 | |
| 39 | memset( cur, 0, sizeof(x509_req_name) ); |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 40 | strcpy( cur->oid, OID_AT_COUNTRY ); |
Paul Bakker | 6d62050 | 2012-02-16 14:09:13 +0000 | [diff] [blame] | 41 | strcpy( cur->name, "NL" ); |
| 42 | |
| 43 | memset( &rsa, 0, sizeof(rsa_context) ); |
Manuel Pégourié-Gonnard | ba4878a | 2013-06-27 10:51:01 +0200 | [diff] [blame] | 44 | ret = x509parse_keyfile_rsa( &rsa, {key_file}, NULL ); |
Paul Bakker | 6d62050 | 2012-02-16 14:09:13 +0000 | [diff] [blame] | 45 | TEST_ASSERT( ret == 0 ); |
| 46 | if( ret != 0 ) |
| 47 | return 0; |
| 48 | |
| 49 | ret = x509_write_cert_req( buf, 4000, &rsa, &req_name, {md_type} ); |
| 50 | TEST_ASSERT( ret >= 0 ); |
| 51 | |
| 52 | c = buf + 3999 - ret; |
| 53 | |
| 54 | f = fopen( {cert_req_check_file}, "r" ); |
| 55 | TEST_ASSERT( f != NULL ); |
| 56 | fread( check_buf, 1, 4000, f ); |
| 57 | fclose( f ); |
| 58 | |
| 59 | pem_init( &pem ); |
| 60 | pem_read_buffer( &pem, "-----BEGIN CERTIFICATE REQUEST-----", "-----END CERTIFICATE REQUEST-----", check_buf, NULL, 0, &olen ); |
| 61 | |
| 62 | TEST_ASSERT( memcmp( c, pem.buf, pem.buflen ) == 0 ); |
| 63 | TEST_ASSERT( pem.buflen == (size_t) ret ); |
Paul Bakker | 58ef6ec | 2013-01-03 11:33:48 +0100 | [diff] [blame] | 64 | |
| 65 | while( ( cur = req_name.next ) != NULL ) |
| 66 | { |
| 67 | req_name.next = cur->next; |
| 68 | free( cur ); |
| 69 | } |
| 70 | |
| 71 | rsa_free( &rsa ); |
| 72 | pem_free( &pem ); |
Paul Bakker | 6d62050 | 2012-02-16 14:09:13 +0000 | [diff] [blame] | 73 | } |
| 74 | END_CASE |