]> WPIA git - cassiopeia.git/blob - src/crypto/sslUtil.h
6ecb536cd5cac1ca479239da1411d042595d5925
[cassiopeia.git] / src / 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
17     std::shared_ptr<X509> ca;
18     std::shared_ptr<EVP_PKEY> caKey;
19     std::shared_ptr<ASN1_TIME> notBefore;
20
21     CAConfig( const std::string& name );
22
23     bool crlNeedsResign();
24 };
25
26 struct Profile {
27     uint16_t id;
28
29     std::string eku;
30     std::string ku;
31
32     std::vector<std::shared_ptr<CAConfig>> ca;
33     std::time_t maxValidity;
34     std::shared_ptr<CAConfig> getCA() {
35         for( auto it = ca.rbegin(); it != ca.rend(); it++ ) {
36             if( X509_cmp_current_time( ( *it )->notBefore.get() ) < 0 ) {
37                 return *it;
38             }
39         }
40
41         return ca[0];
42     }
43 };
44
45 extern std::shared_ptr<int> ssl_lib_ref;
46
47 std::shared_ptr<X509> loadX509FromFile( const std::string& filename );
48 std::shared_ptr<EVP_PKEY> loadPkeyFromFile( const std::string& filename );
49
50 std::shared_ptr<SSL_CTX> generateSSLContext( bool server );
51 std::shared_ptr<BIO> openSerial( const std::string& name );
52 std::string timeToString( std::shared_ptr<ASN1_TIME> time );
53
54 void extractTimes( std::shared_ptr<X509> source, std::shared_ptr<SignedCertificate> cert );