CRYPTO_cleanup_all_ex_data();
} );
+std::shared_ptr<X509> loadX509FromFile( std::string filename ) {
+ FILE* f = fopen( filename.c_str(), "r" );
+
+ if( !f ) {
+ return std::shared_ptr<X509>();
+ }
+
+ X509* key = PEM_read_X509( f, NULL, NULL, 0 );
+ fclose( f );
+
+ if( !key ) {
+ return std::shared_ptr<X509>();
+ }
+
+ return std::shared_ptr<X509>(
+ key,
+ []( X509 * ref ) {
+ X509_free( ref );
+ } );
+}
+
+std::shared_ptr<EVP_PKEY> loadPkeyFromFile( std::string filename ) {
+ FILE* f = fopen( filename.c_str(), "r" );
+
+ if( !f ) {
+ return std::shared_ptr<EVP_PKEY>();
+ }
+
+ EVP_PKEY* key = PEM_read_PrivateKey( f, NULL, NULL, 0 );
+ fclose( f );
+
+ if( !key ) {
+ return std::shared_ptr<EVP_PKEY>();
+ }
+
+ return std::shared_ptr<EVP_PKEY>(
+ key,
+ []( EVP_PKEY * ref ) {
+ EVP_PKEY_free( ref );
+ } );
+}
+
int gencb( int a, int b, BN_GENCB* g ) {
( void ) a;
( void ) b;
throw "failed to get attrs";
}
- attr.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP
- | INLCR | IGNCR | ICRNL | IXON );
+ attr.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON );
attr.c_oflag &= ~OPOST;
attr.c_lflag &= ~( ECHO | ECHONL | ICANON | ISIG | IEXTEN );
attr.c_cflag &= ~( CSIZE | PARENB );
}
}
-std::shared_ptr<BIO> openSerial( const char* name ) {
- FILE* f = fopen( name, "r+" );
+std::shared_ptr<BIO> openSerial( const std::string name ) {
+ FILE* f = fopen( name.c_str(), "r+" );
if( !f ) {
std::cout << "Opening serial device failed" << std::endl;
std::shared_ptr<BIO> b( BIO_new_fd( fileno( f ), 0 ), BIO_free );
return b;
}
+
+CAConfig::CAConfig( std::string name ) {
+ this->name = name;
+ this->path = "ca/" + name;
+ ca = loadX509FromFile( path + "/ca.crt" );
+ caKey = loadPkeyFromFile( path + "/ca.key" );
+}