-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move certificate verification to handshake and allow disabling.
- Loading branch information
1 parent
4bfbc10
commit d38e165
Showing
21 changed files
with
538 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
#include <openssl/ssl.h> | ||
|
||
#include <vector> | ||
#include <string> | ||
|
||
namespace dote { | ||
namespace openssl { | ||
|
||
class CertificateUtilities | ||
{ | ||
public: | ||
/// \brief Create a utilty instance for the given certificate | ||
/// | ||
/// \param certificate A certificate to work on, must last the lifetime of the instance | ||
explicit CertificateUtilities(X509* certificate); | ||
|
||
/// \brief Get the SHA-256 hash of the public key of the given certificate | ||
/// | ||
/// \return The SHA-256 hash of the certificate's public key or empty vector on error | ||
std::vector<unsigned char> getPublicKeyHash(); | ||
|
||
/// \brief Get the common name of the certificate | ||
/// | ||
/// \return The common name of the certificate or empty string on error | ||
std::string getCommonName(); | ||
|
||
private: | ||
/// The hash function for getPeerCertificateHash | ||
using HashFunction = int(*)( | ||
const X509*, const EVP_MD*, unsigned char*, unsigned int* | ||
); | ||
|
||
/// \brief Get the SHA-256 hash of the certificate | ||
/// | ||
/// \param function The hash function to use for the certificate | ||
/// | ||
/// \return The SHA-256 hash | ||
std::vector<unsigned char> getCertificateHash(HashFunction function); | ||
|
||
/// The certificate to perform operations on | ||
X509* m_certificate; | ||
}; | ||
|
||
} // namespace openssl | ||
} // namespace dote |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
#include "config_parser.h" | ||
|
||
#include <vector> | ||
#include <string> | ||
|
||
#include <openssl/ssl.h> | ||
|
||
namespace dote { | ||
namespace openssl { | ||
|
||
class SpkiVerifier | ||
{ | ||
public: | ||
/// \brief Create a verifier for a given forwarder | ||
/// | ||
/// \param config The forwarder to create the verifier for, lifetime must outlive this instance | ||
explicit SpkiVerifier(ConfigParser::Forwarder& config); | ||
|
||
/// \brief Verify a certificate matches the SPKI requirements | ||
/// | ||
/// \param store The store to get the certificates to check | ||
/// | ||
/// \return 2 if pin and hostname pass, 1 if hostname only, 0 if not valid | ||
int verify(X509_STORE_CTX* store) const; | ||
|
||
private: | ||
/// \brief Check the given peer certificate is valid for the | ||
/// configured hostname | ||
/// | ||
/// \param certificate The certificate to verify against the hostname | ||
/// | ||
/// \return True if the hostname is valid for the connected peer | ||
bool verifyHostname(X509* certificate) const; | ||
|
||
/// \brief Check the given peer certificate is valid for the | ||
/// configured public key hash | ||
/// | ||
/// \param certificate The certificate to verify against the hash | ||
/// | ||
/// \return True if the SHA-256 hash of the public key matches the configured hash | ||
bool verifyHash(X509* certificate) const; | ||
|
||
/// The forwarder configuration to validate against | ||
ConfigParser::Forwarder& m_config; | ||
}; | ||
|
||
} // namespace openssl | ||
} // namespace dote |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.