foundCertificateInChain

abstract fun foundCertificateInChain(chain: List<String>, commonName: String): ValidationEvent

Checks if a certificate is found and trusted within the provided chain for a given common name.

Return

A ValidationEvent indicating the result of the validation.

    // Obtain an instance of SSLPinning, typically from the ShieldCert SDK
val sslPinning = ShieldCert.sslPinning()
// sha256
val certificateChain = listOf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB=")
val hostCommonName = "example.com"
val validationResult = sslPinning.foundCertificateInChain(certificateChain, hostCommonName)
when (validationResult) {
is ValidationEvent.Trusted -> println("Certificate for $hostCommonName is trusted.")
is ValidationEvent.Untrusted -> println("Certificate for $hostCommonName is NOT trusted.")
is ValidationEvent.NotFound -> println("No matching certificate found for $hostCommonName.")
else -> println("Validation returned an unexpected event: $validationResult")
}

Parameters

chain

A list of certificate fingerprints in the chain.

commonName

The common name of the host to validate against.