20#include <dhtnet/certstore.h>
65 :
std::runtime_error(
str) {};
185 TlsValidator(
const dhtnet::tls::CertificateStore& certStore,
186 const std::string& certificate,
189 const std::string&
caList =
"");
195 TlsValidator(
const dhtnet::tls::CertificateStore& certStore,
const std::shared_ptr<dht::crypto::Certificate>&);
258 std::shared_ptr<dht::crypto::Certificate>
getCertificate()
const {
return x509crt_; }
287 const dhtnet::tls::CertificateStore& certStore_;
288 std::string certificatePath_;
289 std::string privateKeyPath_;
290 std::string caListPath_ {};
292 std::vector<uint8_t> certificateContent_;
294 std::shared_ptr<dht::crypto::Certificate> x509crt_;
296 bool certificateFileFound_ {
false};
297 bool certificateFound_ {
false};
298 bool privateKeyFound_ {
false};
299 bool privateKeyPassword_ {
false};
300 bool privateKeyMatch_ {
false};
302 bool caChecked_ {
false};
303 unsigned int caValidationOutput_ {
306 mutable char copy_buffer[4096];
314 unsigned int compareToCa();
325 static int verifyHostnameCertificate(const std::string& host,
TlsValidatorException(const std::string &str)
CheckResult getSignatureAlgorithm()
Return the algorithm used to sign the Key.
CheckResult privateKeyStoragePermissions()
CheckResult requirePrivateKeyPassword()
If the key need decryption.
CheckResult getIssuerUID()
If the certificate is not self signed, return the issuer UID.
CheckResult privateKeyDirectoryPermissions()
CheckResult getSerialNumber()
Return the certificate serial number.
CheckResult validAuthority()
The provided authority is invalid.
CheckResult activated()
If the activation value is in the past.
CheckResult keyMatch()
The provided key can be used along with the certificate.
CertificateCheck
All validation fields.
@ NOT_SELF_SIGNED
This certificate has been signed with a brute-force-able method
@ PUBLIC_KEY_STORAGE_PERMISSION
The file hosting the private key isn't correctly secured.
@ EXIST
Some operating systems require keys to have extra attributes
@ AUTHORITY_MISMATCH
The certificate has been revoked by the authority
@ PUBLIC_KEY_DIRECTORY_PERMISSIONS
The folder storing the private key isn't correctly secured
@ NOT_REVOKED
Some operating systems provide a list of trusted authorities, use it.
@ EXPIRED
This certificate has a build in private key
@ PRIVATE_KEY_DIRECTORY_PERMISSIONS
The file hosting the public key isn't correctly secured.
@ PUBLIC_KEY_STORAGE_LOCATION
Some operating systems have extra policies for certificate storage
@ COUNT__
The certificate has not been activated yet
@ STRONG_SIGNING
This certificate is past its expiration date
@ PUBLIC_KEY_SELINUX_ATTRIBUTES
Some operating systems require keys to have extra attributes
@ UNEXPECTED_OWNER
The certificate and authority mismatch.
@ PRIVATE_KEY_STORAGE_PERMISSION
The public and private keys provided don't match
@ VALID_AUTHORITY
The file is not a certificate
@ KNOWN_AUTHORITY
The claimed authority did not sign the certificate
@ VALID
The certificate file doesn't exist or is not accessible
@ NOT_ACTIVATED
The certificate has an expected owner
@ PRIVATE_KEY_STORAGE_LOCATION
The folder storing the public key isn't correctly secured
@ PRIVATE_KEY_SELINUX_ATTRIBUTES
Some operating systems have extra policies for certificate storage
@ KEY_MATCH
This certificate has been self signed
CheckResult getN()
The 'N' section of a DN (RFC4514)
CheckResult getO()
The 'O' section of a DN (RFC4514)
CheckResult notRevoked()
Check if the certificate has been revoked.
CheckResult getActivationDate()
Get the activation date.
CheckResult notSelfSigned()
The certificate is not self signed.
CheckResult getVersionNumber()
Return the certificate version.
CheckResult strongSigning()
If the algorithm used to sign the certificate is considered weak by modern standard.
CheckResult getPublicKeyId()
Return an hexadecimal identifier.
CheckResult authorityMatch()
Check if the authority match the certificate.
std::shared_ptr< dht::crypto::Certificate > getCertificate() const
CheckResult getIssuer()
If the certificate is not self signed, return the issuer.
bool hasCa() const
A certificate authority has been provided.
CheckResult isCA()
If the certificate is not self signed, return the issuer.
CheckResult notExpired()
Check if the certificate is not expired.
CheckResult getUID()
The 'UID' section of a DN (RFC4514)
CheckResult getIssuerO()
If the certificate is not self signed, return the issuer O.
CheckResult getSubjectKeyAlgorithm()
The algorithm used to sign the certificate details (rather than the certificate itself)
bool isValid(bool verbose=false)
Check if all boolean check passed return true if there was no FAILED checks.
CheckResult getIssuerDN()
If the certificate is not self signed, return the issuer DN (RFC4514)
CheckResult outgoingServer()
The expected outgoing server domain.
CheckResult knownAuthority()
When an account require an authority known by the system (like /usr/share/ssl/certs) then the whole c...
CheckResult privateKeySelinuxAttributes()
SELinux provide additional key protection mechanism.
std::pair< CheckValues, std::string > CheckResult
CheckResult getPublicSignature()
An hexadecimal representation of the signature.
CheckResult getExpirationDate()
Get the expiration date.
CheckResult exist()
The file has been found.
CheckResult valid()
The certificate is invalid compared to the authority.
@ UNSUPPORTED
Equivalent of a boolean "false"
@ FAILED
Equivalent of a boolean "true"
CheckResult getMd5Fingerprint()
Compute the key fingerprint.
CheckResult hasPrivateKey()
Check if the Validator have access to a private key.
void setCaTlsValidator(const TlsValidator &validator)
std::map< std::string, std::string > getSerializedChecks()
Convert all checks results into a string map.
CheckResult getSubjectKey()
The subject public key.
CheckResult publicKeyStoragePermissions()
CheckValuesType
Categories of possible values for each CertificateCheck.
CertificateDetails
Informative fields about a certificate.
@ REQUIRE_PRIVATE_KEY_PASSWORD
The certificate activation date
@ IS_CA
The hostname/outgoing server used for this certificate
@ PUBLIC_SIGNATURE
Does the private key require a password.
@ ACTIVATION_DATE
The certificate expiration date
@ NEXT_EXPECTED_UPDATE_DATE
CheckResult getIssuerN()
If the certificate is not self signed, return the issuer N.
CheckResult privateKeyStorageLocation()
Certificate should be located in specific path on some operating systems.
CheckResult publicKeyStorageLocation()
Certificate should be located in specific path on some operating systems.
CheckResult getIssuerCN()
If the certificate is not self signed, return the issuer CN.
CheckResult getSha1Fingerprint()
Compute the key fingerprint.
std::map< std::string, std::string > getSerializedDetails()
Get a map with all common certificate details.
CheckResult publicKeySelinuxAttributes()
SELinux provide additional key protection mechanism.
CheckResult expectedOwner()
The CA and certificate provide conflicting ownership information.
CheckResult publicKeyDirectoryPermissions()
CheckResult getCN()
The 'CN' section of a DN (RFC4514)
void emitSignal(Args... args)
This generic class represents a multidimensional enum class array.