return pk;
}
-std::shared_ptr<X509Req> X509Req::parse( std::string content ) {
+std::shared_ptr<X509Req> X509Req::parseCSR( std::string content ) {
std::shared_ptr<BIO> in = std::shared_ptr<BIO>( BIO_new_mem_buf( const_cast<char*>( content.c_str() ), -1 ), BIO_free );
X509_REQ* req = PEM_read_bio_X509_REQ( in.get(), NULL, NULL, NULL );
X509Req( X509_REQ* csr );
X509Req( std::string spkac );
public:
- static std::shared_ptr<X509Req> parse( std::string content );
+ static std::shared_ptr<X509Req> parseCSR( std::string content );
static std::shared_ptr<X509Req> parseSPKAC( std::string content );
int verify();
std::shared_ptr<EVP_PKEY> getPkey();
throw "Big number math failed while calcing serials.";
}
- char* serStr = BN_bn2hex( serial.get() );
- writeFile( serStr, "serial" );
- OPENSSL_free( serStr );
+ std::shared_ptr<char> serStr = std::shared_ptr<char>(
+ BN_bn2hex( serial.get() ),
+ []( char* ref ) {
+ OPENSSL_free( ref );
+ } );
+ writeFile( "serial", serStr.get() );
return std::shared_ptr<BIGNUM>( BN_bin2bn( data.get(), len + 4 + 16 , 0 ), BN_free );
}
if( cert->csr_type == "SPKAC" ) {
req = X509Req::parseSPKAC( cert->csr_content );
} else if( cert->csr_type == "CSR" ) {
- req = X509Req::parse( cert->csr_content );
+ req = X509Req::parseCSR( cert->csr_content );
} else {
throw "Error, unknown REQ rype " + ( cert->csr_type );
}
#include <fstream>
-void writeFile( const std::string& content, const std::string& name ) {
+void writeFile( const std::string& name, const std::string& content ) {
std::ofstream file;
file.open( name );
#include <string>
-void writeFile( const std::string& content, const std::string& name );
+void writeFile( const std::string& name, const std::string& content );
std::string readFile( const std::string& name );
BOOST_AUTO_TEST_CASE( CSR ) {
// Testing a valid CSR
- std::shared_ptr<X509Req> req( X509Req::parse( readFile( "testdata/test.csr" ) ) );
+ std::shared_ptr<X509Req> req( X509Req::parseCSR( readFile( "testdata/test.csr" ) ) );
BOOST_REQUIRE( req );
BOOST_CHECK( req->verify() == 1 );
// Testing a CSR, where the signature content has been tampered with
- req = std::shared_ptr<X509Req>( X509Req::parse( readFile( "testdata/test_false_sig.csr" ) ) );
+ req = std::shared_ptr<X509Req>( X509Req::parseCSR( readFile( "testdata/test_false_sig.csr" ) ) );
BOOST_REQUIRE( req );
BOOST_CHECK( req->verify() == 0 );
// Testing a CSR, where the signature OID is something strange
- req = std::shared_ptr<X509Req>( X509Req::parse( readFile( "testdata/test_invalid_sig.csr" ) ) );
+ req = std::shared_ptr<X509Req>( X509Req::parseCSR( readFile( "testdata/test_invalid_sig.csr" ) ) );
BOOST_REQUIRE( req );
BOOST_CHECK( req->verify() < 0 );
}