Cuberite
A lightweight, fast and extensible game server for Minecraft
SslConfig.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "mbedtls/ssl.h"
5 
6 // fwd:
7 class cCryptoKey;
8 class cCtrDrbgContext;
9 class cX509Cert;
10 
11 using cCryptoKeyPtr = std::shared_ptr<cCryptoKey>;
12 using cCtrDrbgContextPtr = std::shared_ptr<cCtrDrbgContext>;
13 using cX509CertPtr = std::shared_ptr<cX509Cert>;
14 
15 enum class eSslAuthMode
16 {
17  None = 0, // MBEDTLS_SSL_VERIFY_NONE
18  Optional = 1, // MBEDTLS_SSL_VERIFY_OPTIONAL
19  Required = 2, // MBEDTLS_SSL_VERIFY_REQUIRED
20  Unset = 3, // MBEDTLS_SSL_VERIFY_UNSET
21 };
22 
23 
24 
26 {
27  friend class cSslContext;
28 public:
36  using cDebugCallback = void(*)(void *, int, const char *, int, const char *);
37 
44  using cVerifyCallback = int(*)(void *, mbedtls_x509_crt *, int, uint32_t *);
45 
46  cSslConfig();
47  ~cSslConfig();
48 
50  int InitDefaults(bool a_IsClient);
51 
53  void SetAuthMode(eSslAuthMode a_AuthMode);
54 
56  void SetRng(cCtrDrbgContextPtr a_CtrDrbg);
57 
59  void SetDebugCallback(cDebugCallback a_CallbackFun, void * a_CallbackData);
60 
62  void SetVerifyCallback(cVerifyCallback a_CallbackFun, void * a_CallbackData);
63 
65  void SetCipherSuites(std::vector<int> a_CipherSuites);
66 
68  void SetOwnCert(cX509CertPtr a_OwnCert, cCryptoKeyPtr a_OwnCertPrivKey);
69 
71  void SetCACerts(cX509CertPtr a_CACert);
72 
74  static std::shared_ptr<cSslConfig> MakeDefaultConfig(bool a_IsClient);
75 
77  static std::shared_ptr<const cSslConfig> GetDefaultClientConfig();
78 
80  static std::shared_ptr<const cSslConfig> GetDefaultServerConfig();
81 
82 private:
83 
85  const mbedtls_ssl_config * GetInternal() const { return &m_Config; }
86 
87  mbedtls_ssl_config m_Config;
92  std::vector<int> m_CipherSuites;
93 };
cCtrDrbgContextPtr m_CtrDrbg
Definition: SslConfig.h:88
std::shared_ptr< cX509Cert > cX509CertPtr
Definition: SslConfig.h:13
void(*)(void *, int, const char *, int, const char *) cDebugCallback
Type of the SSL debug callback.
Definition: SslConfig.h:36
eSslAuthMode
Definition: SslConfig.h:15
std::shared_ptr< cCryptoKey > cCryptoKeyPtr
Definition: CryptoKey.h:72
const mbedtls_ssl_config * GetInternal() const
Returns a pointer to the wrapped mbedtls representation.
Definition: SslConfig.h:85
cX509CertPtr m_CACerts
Definition: SslConfig.h:91
cX509CertPtr m_OwnCert
Definition: SslConfig.h:89
int(*)(void *, mbedtls_x509_crt *, int, uint32_t *) cVerifyCallback
Type of the SSL certificate verify callback.
Definition: SslConfig.h:44
cCryptoKeyPtr m_OwnCertPrivKey
Definition: SslConfig.h:90
std::shared_ptr< cCtrDrbgContext > cCtrDrbgContextPtr
Definition: SslConfig.h:12
mbedtls_ssl_config m_Config
Definition: SslConfig.h:87
std::vector< int > m_CipherSuites
Definition: SslConfig.h:92