Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > validation certificate agains cacert

Reply
Thread Tools

validation certificate agains cacert

 
 
Stone
Guest
Posts: n/a
 
      09-16-2011
Dear programmers,

I would like to ask you if there is any way how to compare certificate
against cacerts file.
I have already loaded certificate in keystore like:

CertificateFactory cf = CertificateFactory.getInstance("X.509");
String filename = System.getProperty("java.home")+"/lib/security/
cacerts".replace('/', File.separatorChar);
System.out.println(filename);
FileInputStream in = new FileInputStream(filename);
BufferedInputStream bis = new BufferedInputStream(in);
KeyStore keystore =
KeyStore.getInstance(KeyStore.getDefaultType());
String pwd = "changeit";
keystore.load(in, pwd.toCharArray());

Is there any way how to validate certificate in TrustManager.
My TrustManager is:
System.out.println("Initialization of Trust Manager");
trustManager = new TrustManager[] {
new X509TrustManager()
{
//X509TrustManager sunJSSEX509TrustManager;
public java.security.cert.X509Certificate[]
getAcceptedIssuers() {
System.out.println("InitializeTrustManager:
getAcceptedIssuers:");
//return
sunJSSEX509TrustManager.getAcceptedIssuers();
return null;
}

public void
checkClientTrusted( java.security.cert.X509Certificate[] certs, String
authType)
{
for(int j=0;j<certs.length;j++)
{
System.out.println("initializeTrustmanager:
checkClientTrusted:" + certs[j] + " authTyp:" + authType);
System.out.println(" Subject DN:
"+certs[j].getSubjectDN());
System.out.println(" Issuer DN:
"+certs[j].getIssuerDN());
System.out.println(" Serial number:
"+certs[j].getSerialNumber());

}
}

public void checkServerTrusted
( java.security.cert.X509Certificate[] certs, String authType) throws
java.security.cert.CertificateException {
for(int i=0;i<certs.length;i++)
{
X509Certificate x509Certificate = certs[i];
System.out.println("InitializeTrustManager:
checkServerTrusted:" +
x509Certificate.getIssuerX500Principal().getName() +"AuthTyp:" +
authType);
System.out.println("InitializeTrustManager:
checkServerTrusted:" + x509Certificate.getIssuerDN());

}

}
public boolean isClientTrusted(X509Certificate[] arg0)
throws CertificateException
{
System.out.println("InitializeTrustManager:
isClientTrusted: ");
return true;
}
public boolean isServerTrusted(X509Certificate[] arg0)
throws CertificateException
{
for(int i=0;i<arg0.length;i++)
{
System.out.println("InitializeTrustManager:
isServerTrusted: "+ arg0[i].getIssuerDN());
}
//TODO
return true;
}
}
};


Thank you in advance
Petr
 
Reply With Quote
 
 
 
 
Daniele Futtorovic
Guest
Posts: n/a
 
      09-16-2011
On 16/09/2011 08:50, Stone allegedly wrote:
> Dear programmers,
>
> I would like to ask you if there is any way how to compare certificate
> against cacerts file.
> I have already loaded certificate in keystore like:
>
> <snip />


Funny you should want to validate against the cacerts file in an
X509TrustManager, for, if I'm not mistaken, that is precisely what the
default TrustManager does. You might want to look for its source code
online (for instance here:
<http://www.docjar.com/docs/api/sun/security/ssl/package-index.html>).

Anyway, the task isn't complicated, although the code is somewhat
convoluted. You'll have to establish a chain (of certificates) from the
certificate you're trying to validate to one of the root certificates in
the trust store.

A quick search turned up this guide:
<http://download.oracle.com/javase/7/docs/technotes/guides/security/certpath/CertPathProgGuide.html>

--
DF.
Determinism trumps correctness.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Win32::OLE and CAPICOM to find a certificate in certificate store will raise exception danielhe99@gmail.com Perl Misc 0 07-20-2006 06:47 AM
Can .NET run agains an Access database? =?Utf-8?B?RWQ=?= ASP .Net 5 04-29-2005 01:29 PM
How to Import Certificate file into windows certificate store under IWAM account Helena Cai ASP General 0 08-29-2004 05:27 AM
Re: certificate validation Andy Foster MCSE 0 08-06-2003 09:14 AM
validation of MCSE certificate mansoor MCSE 0 08-06-2003 08:47 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57