Modulecrypton-x509-validation-1.9.1Haskell2010
Data.X509.Validation
X.509 Certificate checks and validations routines
Follows RFC5280 / RFC6818
- 13 types
- 11 values
- Packagecrypton-x509-validation-1.9.1
- Exports24
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceValidation.hs
identification of the connection consisting of the fully qualified host name (e.g. www.example.com) and an optional suffix.
The suffix is not used by the validation process, but is used by the optional cache to identity certificate per service on a specific host. For example, one might have a different certificate on 2 differents ports (443 and 995) for the same host.
for TCP connection, it's recommended to use: :port, or :service for the suffix.
Fingerprint of a certificate
Constructors
Instances3Eq, Show, ByteArrayAccess
Eq FingerprintDefined in crypton-x509-validation-1.9.1 · Data.X509.Validation.FingerprintShow FingerprintDefined in crypton-x509-validation-1.9.1 · Data.X509.Validation.FingerprintByteArrayAccess FingerprintDefined in crypton-x509-validation-1.9.1 · Data.X509.Validation.Fingerprint
Failed validation types
2 declarationsPossible reason of certificate and chain failure.
The values InvalidName and InvalidWildcard are internal-only and are never returned by the validation functions. NameMismatch is returned instead.
Constructors
UnknownCriticalExtension OIDcertificate contains an unknown critical extension
Expiredvalidity ends before checking time
InFuturevalidity starts after checking time
SelfSignedcertificate is self signed
UnknownCAunknown Certificate Authority (CA)
NotAllowedToSigncertificate is not allowed to sign
NotAnAuthoritynot a CA
AuthorityTooDeepViolation of the optional Basic constraint's path length
NoCommonNameCertificate doesn't have any common name (CN)
InvalidName StringInvalid name in certificate
NameMismatch Stringconnection name and certificate do not match
InvalidWildcardinvalid wildcard in certificate
LeafKeyUsageNotAllowedthe requested key usage is not compatible with the leaf certificate's key usage
LeafKeyPurposeNotAllowedthe requested key purpose is not compatible with the leaf certificate's extended key usage
LeafNotV3Only authorized an X509.V3 certificate as leaf certificate.
EmptyChainempty chain of certificate
CacheSaysNo Stringthe cache explicitely denied this certificate
InvalidSignature SignatureFailuresignature failed
Instances2Eq, Show
Eq FailedReasonDefined in crypton-x509-validation-1.9.1 · Data.X509.ValidationShow FailedReasonDefined in crypton-x509-validation-1.9.1 · Data.X509.Validation
Various failure possible during signature checking
Constructors
SignatureInvalidsignature doesn't verify
SignaturePubkeyMismatchalgorithm and public key mismatch, cannot proceed
SignatureUnimplementedunimplemented signature algorithm
Instances2Eq, Show
Eq SignatureFailureDefined in crypton-x509-validation-1.9.1 · Data.X509.Validation.SignatureShow SignatureFailureDefined in crypton-x509-validation-1.9.1 · Data.X509.Validation.Signature
Validation configuration types
4 declarationsA set of checks to activate or parametrize to perform on certificates.
It's recommended to use defaultChecks to create the structure, to better cope with future changes or expansion of the structure.
Constructors
ValidationCheckscheckTimeValidity :: Boolcheck time validity of every certificate in the chain. the make sure that current time is between each validity bounds in the certificate
checkAtTime :: Maybe DateTimeThe time when the validity check happens. When set to Nothing, the current time will be used
checkStrictOrdering :: BoolCheck that no certificate is included that shouldn't be included. unfortunately despite the specification violation, a lots of real world server serves useless and usually old certificates that are not relevant to the certificate sent, in their chain.
checkCAConstraints :: BoolCheck that signing certificate got the CA basic constraint. this is absolutely not recommended to turn it off.
checkExhaustive :: BoolCheck the whole certificate chain without stopping at the first failure. Allow gathering a exhaustive list of failure reasons. if this is turn off, it's absolutely not safe to ignore a failed reason even it doesn't look serious (e.g. Expired) as other more serious checks would not have been performed.
checkLeafV3 :: BoolCheck that the leaf certificate is version 3. If disable, version 2 certificate is authorized in leaf position and key usage cannot be checked.
checkLeafKeyUsage :: [ExtKeyUsageFlag]Check that the leaf certificate is authorized to be used for certain usage. If set to empty list no check are performed, otherwise all the flags is the list need to exists in the key usage extension. If the extension is not present, the check will pass and behave as if the certificate key is not restricted to any specific usage.
checkLeafKeyPurpose :: [ExtKeyUsagePurpose]Check that the leaf certificate is authorized to be used for certain purpose. If set to empty list no check are performed, otherwise all the flags is the list need to exists in the extended key usage extension if present. If the extension is not present, then the check will pass and behave as if the certificate is not restricted to any specific purpose.
checkFQHN :: BoolCheck the top certificate names matching the fully qualified hostname (FQHN). it's not recommended to turn this check off, if no other name checks are performed.
Instances3Eq, Show, Default
Eq ValidationChecksDefined in crypton-x509-validation-1.9.1 · Data.X509.ValidationShow ValidationChecksDefined in crypton-x509-validation-1.9.1 · Data.X509.ValidationDefault ValidationChecksDefined in crypton-x509-validation-1.9.1 · Data.X509.Validation
A set of hooks to manipulate the way the verification works.
BEWARE, it's easy to change behavior leading to compromised security.
Constructors
ValidationHookshookMatchSubjectIssuer :: DistinguishedName -> Certificate -> Boolcheck whether a given issuer DistinguishedName matches the subject DistinguishedName of a candidate issuer certificate.
hookValidateTime :: DateTime -> Certificate -> [FailedReason]check whether the certificate in the second argument is valid at the time provided in the first argument. Return an empty list for success or else one or more failure reasons.
hookValidateName :: HostName -> Certificate -> [FailedReason]validate the certificate leaf name with the DNS named used to connect
hookFilterReason :: [FailedReason] -> [FailedReason]user filter to modify the list of failure reasons
Instances1Default
Default ValidationHooksDefined in crypton-x509-validation-1.9.1 · Data.X509.Validation
Default checks to perform
The default checks are: * Each certificate time is valid * CA constraints is enforced for signing certificate * Leaf certificate is X.509 v3 * Check that the FQHN match
Default hooks in the validation process
Validation
4 declarationsvalidate :: HashALGthe hash algorithm we want to use for hashing the leaf certificate
-> ValidationHooksHooks to use
-> ValidationChecksChecks to do
-> CertificateStoreThe trusted certificate store for CA
-> ValidationCachethe validation cache callbacks
-> ServiceIDidentification of the connection
-> CertificateChainthe certificate chain we want to validate
-> IO [FailedReason]the return failed reasons (empty list is no failure)
X509 validation
the function first interrogate the cache and if the validation fail, proper verification is done. If the verification pass, the add to cache callback is called.
validatePure :: DateTimeThe time for which to check validity for
-> ValidationHooksHooks to use
-> ValidationChecksChecks to do
-> CertificateStoreThe trusted certificate store for CA
-> ServiceIDIdentification of the connection
-> CertificateChainThe certificate chain we want to validate
-> [FailedReason]the return failed reasons (empty list is no failure)
Validate a certificate chain with explicit pure parameters
validateDefault :: CertificateStoreThe trusted certificate store for CA
-> ValidationCachethe validation cache callbacks
-> ServiceIDidentification of the connection
-> CertificateChainthe certificate chain we want to validate
-> IO [FailedReason]the return failed reasons (empty list is no failure)
Validate using the default hooks and checks and the SHA256 mechanism as hashing mechanism
getFingerprint :: (Show a, Eq a, ASN1Object a)=> SignedExact aobject to fingerprint
-> HashALGalgorithm to compute the fingerprint
-> Fingerprintfingerprint in binary form
Get the fingerprint of the whole signed object using the hashing algorithm specified
Cache
7 declarationscreate a simple constant cache that list exceptions to the certification validation. Typically this is use to allow self-signed certificates for specific use, with out-of-bounds user checks.
No fingerprints will be added after the instance is created.
The underlying structure for the check is kept as a list, as usually the exception list will be short, but when the list go above a dozen exceptions it's recommended to use another cache mechanism with a faster lookup mechanism (hashtable, map, etc).
Note that only one fingerprint is allowed per ServiceID, for other use, another cache mechanism need to be use.
Trust on first use (TOFU) cache with an optional list of exceptions
this is similar to the exceptionCache, except that after each succesfull validation it does add the fingerprint to the database. This prevent any further modification of the fingerprint for the remaining
All the callbacks needed for querying and adding to the cache.
Constructors
ValidationCachecacheQuery :: ValidationCacheQueryCallbackcache querying callback
cacheAdd :: ValidationCacheAddCallbackcache adding callback
Instances1Default
Default ValidationCacheDefined in crypton-x509-validation-1.9.1 · Data.X509.Validation.Cache
Validation cache callback type
type ValidationCacheQueryCallback = ServiceID -> Fingerprint -> Certificate -> IO ValidationCacheResultValidation cache query callback type
The result of a cache query
Constructors
ValidationCachePasscache allow this fingerprint to go through
ValidationCacheDenied Stringcache denied this fingerprint for further validation
ValidationCacheUnknownunknown fingerprint in cache
Instances2Eq, Show
Eq ValidationCacheResultDefined in crypton-x509-validation-1.9.1 · Data.X509.Validation.CacheShow ValidationCacheResultDefined in crypton-x509-validation-1.9.1 · Data.X509.Validation.Cache
Signature verification
4 declarationsverifySignature :: SignatureALGSignature algorithm used
-> PubKeyPublic key to use for verify
-> ByteStringCertificate data that need to be verified
-> ByteStringSignature to verify
-> SignatureVerification
verify signature using parameter
Verify a Signed object against a specified public key
Various failure possible during signature checking
Constructors
SignatureInvalidsignature doesn't verify
SignaturePubkeyMismatchalgorithm and public key mismatch, cannot proceed
SignatureUnimplementedunimplemented signature algorithm
Instances2Eq, Show
Eq SignatureFailureDefined in crypton-x509-validation-1.9.1 · Data.X509.Validation.SignatureShow SignatureFailureDefined in crypton-x509-validation-1.9.1 · Data.X509.Validation.Signature
A set of possible return from signature verification.
When SignatureFailed is return, the signature shouldn't be accepted.
Other values are only useful to differentiate the failure reason, but are all equivalent to failure.
Constructors
SignaturePassverification succeeded
SignatureFailed SignatureFailureverification failed
Instances2Eq, Show
Eq SignatureVerificationDefined in crypton-x509-validation-1.9.1 · Data.X509.Validation.SignatureShow SignatureVerificationDefined in crypton-x509-validation-1.9.1 · Data.X509.Validation.Signature