I am referring Validate X.509 certificate against CA in Java this post.
My implementation of checkServerTrusted
look like:
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException{
InputStream inStream;
try {
inStream = new FileInputStream("E:\\Desktop\\cert\\domain.crt");
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate Mycert = (X509Certificate)cf.generateCertificate(inStream);
inStream.close();
if (certs == null || certs.length == 0 || authType == null
|| authType.length() == 0) {
throw new IllegalArgumentException("null or zero-length parameter");
}
for (X509Certificate cert : certs) {
cert.verify(Mycert.getPublicKey());
}
} catch (Exception e) {
// TODO Auto-generated catch block
throw new CertificateException("error in validating certificate" , e);
}
}
file domain.crt is exported from browser after opening website. certificate path look like .
If i open this file in notepad only one BEGIN CERTIFICATE
and END CERTIFICATE
is their so its not chain of certificate.
If I debug code then, in for
loop @ LOC cert.verify(Mycert.getPublicKey());
at the very first cert[0] certificate I got exception as java.security.SignatureException: Signature does not match.
Where I am doing wrong?