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