]> WPIA git - cassiopeia.git/blob - src/simpleOpensslSigner.cpp
add: Makeing initialization of OpenSSL crypto work
[cassiopeia.git] / src / simpleOpensslSigner.cpp
1 #include "simpleOpensslSigner.h"
2
3 #include <iostream>
4
5 #include <openssl/ssl.h>
6 #include <openssl/err.h>
7 #include <openssl/bio.h>
8 #include <openssl/bn.h>
9 #include <openssl/engine.h>
10
11 void SimpleOpensslSigner::sign( std::shared_ptr<TBSCertificate> cert ) {
12     std::cout << cert->CN << std::endl;
13     BIO* in;
14     in = BIO_new_mem_buf( const_cast<char*>( cert->csr_content.c_str() ), -1 );
15     X509_REQ* req = PEM_read_bio_X509_REQ( in, NULL, NULL, NULL );
16
17     if( req == NULL ) {
18         std::cerr << "Error parsing CSR" << std::endl;
19         return;
20     }
21
22     EVP_PKEY* pktmp = X509_REQ_get_pubkey( req );
23
24     if( pktmp == NULL ) {
25         std::cerr << "Error extracting pubkey" << std::endl;
26         return;
27     }
28
29     std::cout << req << ";" << pktmp << std::endl;
30     SSL_library_init();
31     int i = X509_REQ_verify( req, pktmp );
32     ERR_load_crypto_strings();
33     ERR_print_errors_fp( stderr );
34     std::cout << ERR_get_error() << std::endl;
35
36     if( i < 0 ) {
37         std::cerr << "Signature problems ... " << i << std::endl;
38         return;
39     } else if( i == 0 ) {
40         std::cerr << "Signature did not match" << std::endl;
41         return;
42     } else {
43         std::cerr << "Signature ok" << std::endl;
44     }
45
46 }