]> WPIA git - cassiopeia.git/blob - src/crypto/sslUtil.h
fix: Fix memory-leak in CRL.cpp, revocation from DB, multiple CAs
[cassiopeia.git] / src / crypto / sslUtil.h
1 #pragma once
2 #include <openssl/ssl.h>
3 #include <memory>
4 #include <string>
5 #include <vector>
6 #include <cinttypes>
7
8 class CAConfig {
9 public:
10     std::string path;
11     std::string name;
12
13     std::shared_ptr<X509> ca;
14     std::shared_ptr<EVP_PKEY> caKey;
15     std::shared_ptr<ASN1_TIME> notBefore;
16     CAConfig( std::string name );
17
18 };
19
20 struct Profile {
21     uint16_t id;
22
23     std::string eku;
24     std::string ku;
25
26     std::vector<std::shared_ptr<CAConfig>> ca;
27     std::shared_ptr<CAConfig> getCA() {
28         for( auto it = ca.rbegin(); it != ca.rend(); it++ ) {
29             if( X509_cmp_current_time( ( *it )->notBefore.get() ) < 0 ) {
30                 return *it;
31             }
32         }
33
34         return ca[0];
35     }
36 };
37
38 extern std::shared_ptr<int> ssl_lib_ref;
39
40 std::shared_ptr<X509> loadX509FromFile( std::string filename );
41 std::shared_ptr<EVP_PKEY> loadPkeyFromFile( std::string filename );
42
43 std::shared_ptr<SSL_CTX> generateSSLContext( bool server );
44 std::shared_ptr<BIO> openSerial( const std::string name );