test_suite_x509parse.function 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. BEGIN_HEADER
  2. #include <polarssl/x509.h>
  3. #include <polarssl/pem.h>
  4. int verify_none( void *data, x509_cert *crt, int certificate_depth, int preverify_ok )
  5. {
  6. ((void) data);
  7. ((void) crt);
  8. ((void) certificate_depth);
  9. ((void) preverify_ok);
  10. return 1;
  11. }
  12. int verify_all( void *data, x509_cert *crt, int certificate_depth, int preverify_ok )
  13. {
  14. ((void) data);
  15. ((void) crt);
  16. ((void) certificate_depth);
  17. ((void) preverify_ok);
  18. return 0;
  19. }
  20. END_HEADER
  21. BEGIN_DEPENDENCIES
  22. depends_on:POLARSSL_X509_PARSE_C:POLARSSL_BIGNUM_C
  23. END_DEPENDENCIES
  24. BEGIN_CASE
  25. x509_cert_info:crt_file:result_str
  26. {
  27. x509_cert crt;
  28. char buf[2000];
  29. int res;
  30. memset( &crt, 0, sizeof( x509_cert ) );
  31. memset( buf, 0, 2000 );
  32. TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
  33. res = x509parse_cert_info( buf, 2000, "", &crt );
  34. TEST_ASSERT( res != -1 );
  35. TEST_ASSERT( res != -2 );
  36. TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
  37. }
  38. END_CASE
  39. BEGIN_CASE
  40. x509_crl_info:crl_file:result_str
  41. {
  42. x509_crl crl;
  43. char buf[2000];
  44. int res;
  45. memset( &crl, 0, sizeof( x509_crl ) );
  46. memset( buf, 0, 2000 );
  47. TEST_ASSERT( x509parse_crlfile( &crl, {crl_file} ) == 0 );
  48. res = x509parse_crl_info( buf, 2000, "", &crl );
  49. TEST_ASSERT( res != -1 );
  50. TEST_ASSERT( res != -2 );
  51. TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
  52. }
  53. END_CASE
  54. BEGIN_CASE
  55. x509_verify:crt_file:ca_file:crl_file:cn_name:result:flags:verify_callback
  56. {
  57. x509_cert crt;
  58. x509_cert ca;
  59. x509_crl crl;
  60. int flags = 0;
  61. int res;
  62. memset( &crt, 0, sizeof( x509_cert ) );
  63. memset( &ca, 0, sizeof( x509_cert ) );
  64. memset( &crl, 0, sizeof( x509_crl ) );
  65. TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
  66. TEST_ASSERT( x509parse_crtfile( &ca, {ca_file} ) == 0 );
  67. TEST_ASSERT( x509parse_crlfile( &crl, {crl_file} ) == 0 );
  68. res = x509parse_verify( &crt, &ca, &crl, {cn_name}, &flags, {verify_callback}, NULL );
  69. TEST_ASSERT( res == ( {result} ) );
  70. TEST_ASSERT( flags == ( {flags} ) );
  71. }
  72. END_CASE
  73. BEGIN_CASE
  74. x509_dn_gets:crt_file:entity:result_str
  75. {
  76. x509_cert crt;
  77. char buf[2000];
  78. int res;
  79. memset( &crt, 0, sizeof( x509_cert ) );
  80. memset( buf, 0, 2000 );
  81. TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
  82. res = x509parse_dn_gets( buf, 2000, &crt.{entity} );
  83. TEST_ASSERT( res != -1 );
  84. TEST_ASSERT( res != -2 );
  85. TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
  86. }
  87. END_CASE
  88. BEGIN_CASE
  89. x509_time_expired:crt_file:entity:result
  90. {
  91. x509_cert crt;
  92. memset( &crt, 0, sizeof( x509_cert ) );
  93. TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
  94. TEST_ASSERT( x509parse_time_expired( &crt.{entity} ) == {result} );
  95. }
  96. END_CASE
  97. BEGIN_CASE
  98. x509parse_keyfile:key_file:password:result
  99. {
  100. rsa_context rsa;
  101. int res;
  102. memset( &rsa, 0, sizeof( rsa_context ) );
  103. res = x509parse_keyfile( &rsa, {key_file}, {password} );
  104. TEST_ASSERT( res == {result} );
  105. if( res == 0 )
  106. {
  107. TEST_ASSERT( rsa_check_privkey( &rsa ) == 0 );
  108. }
  109. }
  110. END_CASE
  111. BEGIN_CASE
  112. x509parse_public_keyfile:key_file:result
  113. {
  114. rsa_context rsa;
  115. int res;
  116. memset( &rsa, 0, sizeof( rsa_context ) );
  117. res = x509parse_public_keyfile( &rsa, {key_file} );
  118. TEST_ASSERT( res == {result} );
  119. if( res == 0 )
  120. {
  121. TEST_ASSERT( rsa_check_pubkey( &rsa ) == 0 );
  122. }
  123. }
  124. END_CASE
  125. BEGIN_CASE
  126. x509parse_crt:crt_data:result_str:result
  127. {
  128. x509_cert crt;
  129. unsigned char buf[2000];
  130. unsigned char output[2000];
  131. int data_len, res;
  132. memset( &crt, 0, sizeof( x509_cert ) );
  133. memset( buf, 0, 2000 );
  134. memset( output, 0, 2000 );
  135. data_len = unhexify( buf, {crt_data} );
  136. TEST_ASSERT( x509parse_crt( &crt, buf, data_len ) == ( {result} ) );
  137. if( ( {result} ) == 0 )
  138. {
  139. res = x509parse_cert_info( (char *) output, 2000, "", &crt );
  140. TEST_ASSERT( res != -1 );
  141. TEST_ASSERT( res != -2 );
  142. TEST_ASSERT( strcmp( (char *) output, {result_str} ) == 0 );
  143. }
  144. }
  145. END_CASE
  146. BEGIN_CASE
  147. x509parse_crl:crl_data:result_str:result
  148. {
  149. x509_crl crl;
  150. unsigned char buf[2000];
  151. unsigned char output[2000];
  152. int data_len, res;
  153. memset( &crl, 0, sizeof( x509_crl ) );
  154. memset( buf, 0, 2000 );
  155. memset( output, 0, 2000 );
  156. data_len = unhexify( buf, {crl_data} );
  157. TEST_ASSERT( x509parse_crl( &crl, buf, data_len ) == ( {result} ) );
  158. if( ( {result} ) == 0 )
  159. {
  160. res = x509parse_crl_info( (char *) output, 2000, "", &crl );
  161. TEST_ASSERT( res != -1 );
  162. TEST_ASSERT( res != -2 );
  163. TEST_ASSERT( strcmp( (char *) output, {result_str} ) == 0 );
  164. }
  165. }
  166. END_CASE
  167. BEGIN_CASE
  168. x509parse_key:key_data:result_str:result
  169. {
  170. rsa_context rsa;
  171. unsigned char buf[2000];
  172. unsigned char output[2000];
  173. int data_len;
  174. memset( &rsa, 0, sizeof( rsa_context ) );
  175. memset( buf, 0, 2000 );
  176. memset( output, 0, 2000 );
  177. data_len = unhexify( buf, {key_data} );
  178. x509parse_key( &rsa, buf, data_len, NULL, 0 );
  179. TEST_ASSERT( x509parse_key( &rsa, buf, data_len, NULL, 0 ) == ( {result} ) );
  180. if( ( {result} ) == 0 )
  181. {
  182. TEST_ASSERT( 1 );
  183. }
  184. }
  185. END_CASE
  186. BEGIN_CASE
  187. x509_selftest:
  188. {
  189. TEST_ASSERT( x509_self_test( 0 ) == 0 );
  190. }
  191. END_CASE