1 #include "remoteSigner.h"
5 RemoteSigner::RemoteSigner( std::shared_ptr<BIO> target, std::shared_ptr<SSL_CTX> ctx ) {
9 RemoteSigner::~RemoteSigner() {
12 void RemoteSigner::send( std::shared_ptr<OpensslBIOWrapper> bio, RecordHeader& head, RecordHeader::SignerCommand cmd, std::string data ) {
13 head.command = ( uint16_t ) cmd;
15 head.totalLength = data.size();
16 sendCommand( head, data, bio );
20 std::shared_ptr<SignedCertificate> RemoteSigner::sign( std::shared_ptr<TBSCertificate> cert ) {
21 std::shared_ptr<SSL> ssl( SSL_new( ctx.get() ), SSL_free );
22 std::shared_ptr<BIO> bio( BIO_new( BIO_f_ssl() ), BIO_free );
23 SSL_set_connect_state( ssl.get() );
24 SSL_set_bio( ssl.get(), target.get(), target.get() );
25 BIO_set_ssl( bio.get(), ssl.get(), BIO_NOCLOSE );
26 std::shared_ptr<OpensslBIOWrapper> conn( new OpensslBIOWrapper( bio ) );
31 if( cert->csr_type == "csr" ) {
32 send( conn, head, RecordHeader::SignerCommand::SET_CSR, cert->csr_content );
34 std::cout << "Unknown csr_type: " << cert->csr_type;
35 return std::shared_ptr<SignedCertificate>();
38 send( conn, head, RecordHeader::SignerCommand::SET_SIGNATURE_TYPE, cert->md );
39 send( conn, head, RecordHeader::SignerCommand::SET_PROFILE, cert->profile );
40 send( conn, head, RecordHeader::SignerCommand::ADD_AVA, "CN,commonName" );
41 send( conn, head, RecordHeader::SignerCommand::ADD_SAN, "DNS,*.example.com" );
42 send( conn, head, RecordHeader::SignerCommand::SIGN, "" );
43 send( conn, head, RecordHeader::SignerCommand::LOG_SAVED, "" );
44 std::shared_ptr<SignedCertificate> result = std::shared_ptr<SignedCertificate>( new SignedCertificate() );
45 std::vector<char> buffer( 2048 * 4 );
47 for( int i = 0; i < 2; i++ ) {
49 int length = conn->read( buffer.data(), buffer.size() );
51 std::string payload = parseCommand( head, std::string( buffer.data(), length ) );
52 std::cout << "Data: " << std::endl << payload << std::endl;
53 } catch( const char* msg ) {
54 std::cout << msg << std::endl;
55 return std::shared_ptr<SignedCertificate>();