SAMLKeyInfo subjectKeyInfo,
XMLSignature sig,
Certificate[] tlsCerts
) {
X509Certificate[] subjectCerts = subjectKeyInfo.getCerts();
PublicKey subjectPublicKey = subjectKeyInfo.getPublicKey();
//
// Try to match the TLS certs first
//
if (tlsCerts != null && tlsCerts.length > 0 && subjectCerts != null
&& subjectCerts.length > 0 && tlsCerts[0].equals(subjectCerts[0])) {
return true;
} else if (tlsCerts != null && tlsCerts.length > 0 && subjectPublicKey != null
&& tlsCerts[0].getPublicKey().equals(subjectPublicKey)) {
return true;
}
if (sig == null) {
return false;
}
//
// Now try the message-level signatures
//
try {
X509Certificate[] certs =
new X509Certificate[] {sig.getKeyInfo().getX509Certificate()};
PublicKey publicKey = sig.getKeyInfo().getPublicKey();
if (certs != null && certs.length > 0 && subjectCerts != null
&& subjectCerts.length > 0 && certs[0].equals(subjectCerts[0])) {
return true;
}
if (publicKey != null && publicKey.equals(subjectPublicKey)) {
return true;
}
} catch (Exception ex) {
// ignore
}