TR03112Utils { public static boolean isInCommCertificates(TlsServerCertificate serverCertificate, List<byte[]> commCertificates, @Nullable String serverDesc) { LOG.info("Checking certificate hash of {} against list of communication certificates.", serverDesc); try { MessageDigest md = MessageDigest.getInstance(SHA256); md.update(serverCertificate.getCertificate().getCertificateAt(0).getEncoded()); byte[] hash = md.digest(); if (LOG.isDebugEnabled()) { LOG.debug("Hash of the retrieved server certificate: {}", ByteUtils.toHexString(hash)); } for (byte[] commCertificate : commCertificates) { LOG.debug("CommCertificate: {}", ByteUtils.toHexString(commCertificate)); if (ByteUtils.compare(commCertificate, hash)) { return true; } } } catch (NoSuchAlgorithmException e) { LOG.error("SHA-256 digest algorithm is not available."); return false; } catch (IOException e) { LOG.error("Server certificate couldn't be encoded."); return false; } return false; }  static boolean checkSameOriginPolicy(URL url1, URL url2); static boolean isInCommCertificates(TlsServerCertificate serverCertificate, List<byte[]> commCertificates,
	    @Nullable String serverDesc); static boolean isRedirectStatusCode(int statusCode); static boolean DEVELOPER_MODE; }
@Test public void testInCommCertificates() throws IOException { new Expectations() {{ tlsCert.getCertificate().getCertificateAt(0).getEncoded(); result = x509Certificate; tlsCert.getCertificate().getCertificateAt(0).getEncoded(); result = x509Certificate; }}; ArrayList<byte[]> listOfHashes = new ArrayList<>(); listOfHashes.add(correctHash); boolean result = TR03112Utils.isInCommCertificates(tlsCert, listOfHashes, null); Assert.assertTrue(result); listOfHashes.clear(); listOfHashes.add(incorrectHash); result = TR03112Utils.isInCommCertificates(tlsCert, listOfHashes, null); Assert.assertFalse(result); }