private int compareStrength(X509Certificate lhs, X509Certificate rhs) { int result; PublicKey lhsPublicKey = lhs.getPublicKey(); PublicKey rhsPublicKey = rhs.getPublicKey(); result = compareKeyAlgorithm(lhsPublicKey, rhsPublicKey); if (result != 0) { return result; } result = compareKeySize(lhsPublicKey, rhsPublicKey); if (result != 0) { return result; } return compareSignatureAlgorithm(lhs, rhs); }
private int compareKeySize(PublicKey lhs, PublicKey rhs) { String lhsAlgorithm = lhs.getAlgorithm(); String rhsAlgorithm = rhs.getAlgorithm(); if (!lhsAlgorithm.equalsIgnoreCase(rhsAlgorithm)) { throw new IllegalArgumentException("Keys are not of the same type"); } int lhsSize = getKeySize(lhs); int rhsSize = getKeySize(rhs); return lhsSize - rhsSize; }
@Override public int compare(TrustAnchor lhs, TrustAnchor rhs) { X509Certificate lhsCert = lhs.getTrustedCert(); X509Certificate rhsCert = rhs.getTrustedCert(); return CERT_COMPARATOR.compare(lhsCert, rhsCert); } }
@Override public int compare(X509Certificate lhs, X509Certificate rhs) { int result; boolean lhsSelfSigned = lhs.getSubjectDN().equals(lhs.getIssuerDN()); boolean rhsSelfSigned = rhs.getSubjectDN().equals(rhs.getIssuerDN()); // Self-issued before not self-issued to avoid trying bridge certs first. if (lhsSelfSigned != rhsSelfSigned) { return rhsSelfSigned ? 1 : -1; } // Strength descending. result = compareStrength(rhs, lhs); if (result != 0) { return result; } // notAfter descending. Date lhsNotAfter = lhs.getNotAfter(); Date rhsNotAfter = rhs.getNotAfter(); result = rhsNotAfter.compareTo(lhsNotAfter); if (result != 0) { return result; } // notBefore descending. Date lhsNotBefore = lhs.getNotBefore(); Date rhsNotBefore = rhs.getNotBefore(); return rhsNotBefore.compareTo(lhsNotBefore); }
@Override public int compare(TrustAnchor lhs, TrustAnchor rhs) { X509Certificate lhsCert = lhs.getTrustedCert(); X509Certificate rhsCert = rhs.getTrustedCert(); return CERT_COMPARATOR.compare(lhsCert, rhsCert); } }
@Override public int compare(X509Certificate lhs, X509Certificate rhs) { int result; boolean lhsSelfSigned = lhs.getSubjectDN().equals(lhs.getIssuerDN()); boolean rhsSelfSigned = rhs.getSubjectDN().equals(rhs.getIssuerDN()); // Self-issued before not self-issued to avoid trying bridge certs first. if (lhsSelfSigned != rhsSelfSigned) { return rhsSelfSigned ? 1 : -1; } // Strength descending. result = compareStrength(rhs, lhs); if (result != 0) { return result; } // notAfter descending. Date lhsNotAfter = lhs.getNotAfter(); Date rhsNotAfter = rhs.getNotAfter(); result = rhsNotAfter.compareTo(lhsNotAfter); if (result != 0) { return result; } // notBefore descending. Date lhsNotBefore = lhs.getNotBefore(); Date rhsNotBefore = rhs.getNotBefore(); return rhsNotBefore.compareTo(lhsNotBefore); }
private int compareStrength(X509Certificate lhs, X509Certificate rhs) { int result; PublicKey lhsPublicKey = lhs.getPublicKey(); PublicKey rhsPublicKey = rhs.getPublicKey(); result = compareKeyAlgorithm(lhsPublicKey, rhsPublicKey); if (result != 0) { return result; } result = compareKeySize(lhsPublicKey, rhsPublicKey); if (result != 0) { return result; } return compareSignatureAlgorithm(lhs, rhs); }
private int compareKeySize(PublicKey lhs, PublicKey rhs) { String lhsAlgorithm = lhs.getAlgorithm(); String rhsAlgorithm = rhs.getAlgorithm(); if (!lhsAlgorithm.equalsIgnoreCase(rhsAlgorithm)) { throw new IllegalArgumentException("Keys are not of the same type"); } int lhsSize = getKeySize(lhs); int rhsSize = getKeySize(rhs); return lhsSize - rhsSize; }