mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-10-30 19:20:40 -04:00 
			
		
		
		
	Moved x509_self_test() from x509_crt.c to x509.c and fixed mem-free bug
This commit is contained in:
		
							parent
							
								
									f20ba4b7b6
								
							
						
					
					
						commit
						e9e6ae338b
					
				| @ -688,4 +688,76 @@ int x509parse_time_expired( const x509_time *to ) | |||||||
| } | } | ||||||
| #endif /* POLARSSL_HAVE_TIME */ | #endif /* POLARSSL_HAVE_TIME */ | ||||||
| 
 | 
 | ||||||
|  | #if defined(POLARSSL_SELF_TEST) | ||||||
|  | 
 | ||||||
|  | #include "polarssl/x509_crt.h" | ||||||
|  | #include "polarssl/certs.h" | ||||||
|  | 
 | ||||||
|  | /*
 | ||||||
|  |  * Checkup routine | ||||||
|  |  */ | ||||||
|  | int x509_self_test( int verbose ) | ||||||
|  | { | ||||||
|  | #if defined(POLARSSL_CERTS_C) && defined(POLARSSL_MD5_C) | ||||||
|  |     int ret; | ||||||
|  |     int flags; | ||||||
|  |     x509_cert cacert; | ||||||
|  |     x509_cert clicert; | ||||||
|  | 
 | ||||||
|  |     if( verbose != 0 ) | ||||||
|  |         printf( "  X.509 certificate load: " ); | ||||||
|  | 
 | ||||||
|  |     memset( &clicert, 0, sizeof( x509_cert ) ); | ||||||
|  | 
 | ||||||
|  |     ret = x509parse_crt( &clicert, (const unsigned char *) test_cli_crt, | ||||||
|  |                          strlen( test_cli_crt ) ); | ||||||
|  |     if( ret != 0 ) | ||||||
|  |     { | ||||||
|  |         if( verbose != 0 ) | ||||||
|  |             printf( "failed\n" ); | ||||||
|  | 
 | ||||||
|  |         return( ret ); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     memset( &cacert, 0, sizeof( x509_cert ) ); | ||||||
|  | 
 | ||||||
|  |     ret = x509parse_crt( &cacert, (const unsigned char *) test_ca_crt, | ||||||
|  |                          strlen( test_ca_crt ) ); | ||||||
|  |     if( ret != 0 ) | ||||||
|  |     { | ||||||
|  |         if( verbose != 0 ) | ||||||
|  |             printf( "failed\n" ); | ||||||
|  | 
 | ||||||
|  |         return( ret ); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if( verbose != 0 ) | ||||||
|  |         printf( "passed\n  X.509 signature verify: "); | ||||||
|  | 
 | ||||||
|  |     ret = x509parse_verify( &clicert, &cacert, NULL, NULL, &flags, NULL, NULL ); | ||||||
|  |     if( ret != 0 ) | ||||||
|  |     { | ||||||
|  |         if( verbose != 0 ) | ||||||
|  |             printf( "failed\n" ); | ||||||
|  | 
 | ||||||
|  |         printf("ret = %d, &flags = %04x\n", ret, flags); | ||||||
|  | 
 | ||||||
|  |         return( ret ); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if( verbose != 0 ) | ||||||
|  |         printf( "passed\n\n"); | ||||||
|  | 
 | ||||||
|  |     x509_crt_free( &cacert  ); | ||||||
|  |     x509_crt_free( &clicert ); | ||||||
|  | 
 | ||||||
|  |     return( 0 ); | ||||||
|  | #else | ||||||
|  |     ((void) verbose); | ||||||
|  |     return( POLARSSL_ERR_X509_FEATURE_UNAVAILABLE ); | ||||||
|  | #endif | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
| #endif /* POLARSSL_X509_USE_C */ | #endif /* POLARSSL_X509_USE_C */ | ||||||
|  | |||||||
| @ -1680,77 +1680,4 @@ void x509_crt_free( x509_cert *crt ) | |||||||
|     while( cert_cur != NULL ); |     while( cert_cur != NULL ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #if defined(POLARSSL_SELF_TEST) |  | ||||||
| 
 |  | ||||||
| #include "polarssl/certs.h" |  | ||||||
| 
 |  | ||||||
| /*
 |  | ||||||
|  * Checkup routine |  | ||||||
|  */ |  | ||||||
| int x509_self_test( int verbose ) |  | ||||||
| { |  | ||||||
| #if defined(POLARSSL_CERTS_C) && defined(POLARSSL_MD5_C) |  | ||||||
|     int ret; |  | ||||||
|     int flags; |  | ||||||
|     x509_cert cacert; |  | ||||||
|     x509_cert clicert; |  | ||||||
|     pk_context pkey; |  | ||||||
| 
 |  | ||||||
|     if( verbose != 0 ) |  | ||||||
|         printf( "  X.509 certificate load: " ); |  | ||||||
| 
 |  | ||||||
|     memset( &clicert, 0, sizeof( x509_cert ) ); |  | ||||||
| 
 |  | ||||||
|     ret = x509parse_crt( &clicert, (const unsigned char *) test_cli_crt, |  | ||||||
|                          strlen( test_cli_crt ) ); |  | ||||||
|     if( ret != 0 ) |  | ||||||
|     { |  | ||||||
|         if( verbose != 0 ) |  | ||||||
|             printf( "failed\n" ); |  | ||||||
| 
 |  | ||||||
|         return( ret ); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     memset( &cacert, 0, sizeof( x509_cert ) ); |  | ||||||
| 
 |  | ||||||
|     ret = x509parse_crt( &cacert, (const unsigned char *) test_ca_crt, |  | ||||||
|                          strlen( test_ca_crt ) ); |  | ||||||
|     if( ret != 0 ) |  | ||||||
|     { |  | ||||||
|         if( verbose != 0 ) |  | ||||||
|             printf( "failed\n" ); |  | ||||||
| 
 |  | ||||||
|         return( ret ); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     if( verbose != 0 ) |  | ||||||
|         printf( "passed\n  X.509 signature verify: "); |  | ||||||
| 
 |  | ||||||
|     ret = x509parse_verify( &clicert, &cacert, NULL, NULL, &flags, NULL, NULL ); |  | ||||||
|     if( ret != 0 ) |  | ||||||
|     { |  | ||||||
|         if( verbose != 0 ) |  | ||||||
|             printf( "failed\n" ); |  | ||||||
| 
 |  | ||||||
|         printf("ret = %d, &flags = %04x\n", ret, flags); |  | ||||||
| 
 |  | ||||||
|         return( ret ); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     if( verbose != 0 ) |  | ||||||
|         printf( "passed\n\n"); |  | ||||||
| 
 |  | ||||||
|     x509_crt_free( &cacert  ); |  | ||||||
|     x509_crt_free( &clicert ); |  | ||||||
|     pk_free( &pkey ); |  | ||||||
| 
 |  | ||||||
|     return( 0 ); |  | ||||||
| #else |  | ||||||
|     ((void) verbose); |  | ||||||
|     return( POLARSSL_ERR_X509_FEATURE_UNAVAILABLE ); |  | ||||||
| #endif |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #endif | #endif | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Paul Bakker
						Paul Bakker