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