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