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