]> WPIA git - cassiopeia.git/blob - test/src/X509Req.cpp
change to postgres with libpqxx
[cassiopeia.git] / test / src / X509Req.cpp
1 #include <boost/test/unit_test.hpp>
2
3 #include <openssl/err.h>
4
5 #include "util.h"
6
7 #include "crypto/X509.h"
8
9 #include <iostream>
10 #include <openssl/ssl.h>
11
12 BOOST_AUTO_TEST_SUITE( TestX509Req )
13
14 BOOST_AUTO_TEST_CASE( CSR ) {
15     ERR_load_crypto_strings();
16     ERR_free_strings();
17     SSL_load_error_strings();
18     ERR_print_errors_fp(stdout);
19     BOOST_REQUIRE( ERR_peek_error() == 0 );
20
21     // Testing a valid CSR
22     std::shared_ptr<X509Req> req( X509Req::parseCSR( readFile( "testdata/test.csr" ) ) );
23     BOOST_REQUIRE( req );
24     BOOST_CHECK( req->verify() == 1 );
25     BOOST_REQUIRE( ERR_peek_error() == 0 );
26
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" ) ) );
29     BOOST_REQUIRE( req );
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 );
35
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" ) ) );
38     BOOST_REQUIRE( req );
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 );
42 }
43
44 BOOST_AUTO_TEST_CASE( SPKAC ) {
45     // Testing a valid SPKAC
46     std::shared_ptr<X509Req> req( X509Req::parseSPKAC( readFile( "testdata/test.spkac" ) ) );
47     BOOST_REQUIRE( req );
48     BOOST_CHECK( req->verify() == 1 );
49
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" ) ) );
52     BOOST_REQUIRE( req );
53     BOOST_CHECK( req->verify() == 0 );
54
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" ) ) );
57     BOOST_REQUIRE( req );
58     BOOST_CHECK( req->verify() < 0 );
59 }
60
61 BOOST_AUTO_TEST_SUITE_END()