X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2FsslUtil.cpp;fp=src%2FsslUtil.cpp;h=db50f2d46918600e1a645b09aeb2588ef47ac948;hb=c3f5775ce88f4df732e5e803dab70ce395c5f504;hp=2a9de5999a82f0c49f6681b38221192bc48ddc9d;hpb=d289583508396f1ae84580febc8faa913fd20935;p=cassiopeia.git diff --git a/src/sslUtil.cpp b/src/sslUtil.cpp index 2a9de59..db50f2d 100644 --- a/src/sslUtil.cpp +++ b/src/sslUtil.cpp @@ -14,6 +14,48 @@ std::shared_ptr ssl_lib_ref( CRYPTO_cleanup_all_ex_data(); } ); +std::shared_ptr loadX509FromFile( std::string filename ) { + FILE* f = fopen( filename.c_str(), "r" ); + + if( !f ) { + return std::shared_ptr(); + } + + X509* key = PEM_read_X509( f, NULL, NULL, 0 ); + fclose( f ); + + if( !key ) { + return std::shared_ptr(); + } + + return std::shared_ptr( + key, + []( X509 * ref ) { + X509_free( ref ); + } ); +} + +std::shared_ptr loadPkeyFromFile( std::string filename ) { + FILE* f = fopen( filename.c_str(), "r" ); + + if( !f ) { + return std::shared_ptr(); + } + + EVP_PKEY* key = PEM_read_PrivateKey( f, NULL, NULL, 0 ); + fclose( f ); + + if( !key ) { + return std::shared_ptr(); + } + + return std::shared_ptr( + key, + []( EVP_PKEY * ref ) { + EVP_PKEY_free( ref ); + } ); +} + int gencb( int a, int b, BN_GENCB* g ) { ( void ) a; ( void ) b; @@ -103,8 +145,7 @@ void setupSerial( FILE* f ) { 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 );