1 #include <boost/test/unit_test.hpp>
3 #include <openssl/err.h>
7 #include "crypto/X509.h"
10 #include <openssl/ssl.h>
12 BOOST_AUTO_TEST_SUITE( TestX509Req )
14 BOOST_AUTO_TEST_CASE( CSR ) {
15 ERR_load_crypto_strings();
17 SSL_load_error_strings();
18 ERR_print_errors_fp(stdout);
19 BOOST_REQUIRE( ERR_peek_error() == 0 );
21 // Testing a valid CSR
22 std::shared_ptr<X509Req> req( X509Req::parseCSR( readFile( "testdata/test.csr" ) ) );
24 BOOST_CHECK( req->verify() == 1 );
25 BOOST_REQUIRE( ERR_peek_error() == 0 );
27 // Testing a CSR, where the signature content has been tampered with
28 req = std::shared_ptr<X509Req>( X509Req::parseCSR( readFile( "testdata/test_false_sig.csr" ) ) );
30 BOOST_CHECK( req->verify() == 0 );
31 BOOST_REQUIRE( ERR_get_error() != 0 ); // RSA_padding_check_PKCS1_type_1:block type is not 01
32 BOOST_REQUIRE( ERR_get_error() != 0 ); // RSA_EAY_PUBLIC_DECRYPT:padding check failed
33 BOOST_REQUIRE( ERR_get_error() != 0 ); // ASN1_item_verify:EVP lib
34 BOOST_REQUIRE( ERR_get_error() == 0 );
36 // Testing a CSR, where the signature OID is something strange
37 req = std::shared_ptr<X509Req>( X509Req::parseCSR( readFile( "testdata/test_invalid_sig.csr" ) ) );
39 BOOST_CHECK( req->verify() < 0 );
40 BOOST_REQUIRE( ERR_get_error() != 0 ); // ASN1_item_verify:unknown signature algorithm
41 BOOST_REQUIRE( ERR_get_error() == 0 );
44 BOOST_AUTO_TEST_CASE( SPKAC ) {
45 // Testing a valid SPKAC
46 std::shared_ptr<X509Req> req( X509Req::parseSPKAC( readFile( "testdata/test.spkac" ) ) );
48 BOOST_CHECK( req->verify() == 1 );
50 // Testing a SPKAC, where the signature content has been tampered with
51 req = std::shared_ptr<X509Req>( X509Req::parseSPKAC( readFile( "testdata/test_false_sig.spkac" ) ) );
53 BOOST_CHECK( req->verify() == 0 );
55 // Testing a SPKAC, where the signature OID is something strange
56 req = std::shared_ptr<X509Req>( X509Req::parseSPKAC( readFile( "testdata/test_invalid_sig.spkac" ) ) );
58 BOOST_CHECK( req->verify() < 0 );
61 BOOST_AUTO_TEST_SUITE_END()