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