java - Correct way to instantiate class so I'm able to validate path chains in certificate -


i have 3d party library(sdk kalkan provider). part of library checks certificate paths believe. problem should pass 2 parameters instantiate class correctly use 1 of method need.

here's code:

final pkixcertpathreviewer checker = new pkixcertpathreviewer(cp, params); boolean test = checker.isvalidcertpath(); 

here's part of constructor:

public pkixcertpathreviewer(certpath certpath, pkixparameters params) 

about task bit. have signed document client certificate. want validate path in client's certificate. have client's x509certificate instance of certificate, 1 middle certificate , 1 root certificate. last 2 files in cer format on disk. understand should combine 3 certificates together. if showed me how create cp , params helpfull. in advance.

so i've managed solve problem. here's code if have same problems me.

certificatefactory cf = certificatefactory.getinstance("x.509", kalkanprovider.provider_name); java.security.cert.certificate rootcertificate = /*root certificate*/; java.security.cert.certificate clientcertificate = /*client certificate*/; list mylist = new arraylist(); mylist.add(clientcertificate); certpath cp = cf.generatecertpath(mylist); trustanchor rootanchor = new trustanchor((x509certificate) rootcertificate, null); set<trustanchor> truststore = new hashset<>(); truststore.add(rootanchor); if (null != /*chain contains middle cert besides root*/) {     java.security.cert.certificate middlecertificate = /*middle certificate*/;     trustanchor middleanchor = new trustanchor((x509certificate) middlecertificate, null);     truststore.add(middleanchor); } pkixparameters params = new pkixparameters(truststore); params.setrevocationenabled(false);//true - if need ocsp validation final pkixcertpathreviewer checker = new pkixcertpathreviewer(cp, params); errors = checker.geterrors(); boolean result = checker.isvalidcertpath(); 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo