Example usage for javax.net.ssl SSLProtocolException SSLProtocolException

List of usage examples for javax.net.ssl SSLProtocolException SSLProtocolException

Introduction

In this page you can find the example usage for javax.net.ssl SSLProtocolException SSLProtocolException.

Prototype

public SSLProtocolException(String reason) 

Source Link

Document

Constructs an exception reporting an SSL protocol error detected by an SSL subsystem.

Usage

From source file:org.lizardirc.beancounter.security.FingerprintingSslSocketFactory.java

private void verify(SSLSocket socket) throws SSLException {
    SSLSession session = socket.getSession();
    Certificate cert = session.getPeerCertificates()[0];
    byte[] encoded;
    try {//from   w  ww . j ava 2 s  . c om
        encoded = cert.getEncoded();
    } catch (CertificateEncodingException e) {
        throw new SSLProtocolException("Invalid certificate encoding");
    }
    boolean match = Stream.<Function<byte[], String>>of(DigestUtils::md5Hex, DigestUtils::sha1Hex,
            DigestUtils::sha256Hex, DigestUtils::sha512Hex).map(f -> f.apply(encoded))
            .anyMatch(fingerprints::contains);

    if (!match) {
        System.err.println("Rejecting; fingerprint not matched");
        throw new SSLPeerUnverifiedException("Failed to verify: certificate fingerprint mismatch");
    }
}