use of com.github.zhenwei.core.asn1.x509.CertificatePair in project LinLong-Java by zhenwei1108.
the class X509CertPairParser method readDERCrossCertificatePair.
private X509CertificatePair readDERCrossCertificatePair(InputStream in) throws IOException, CertificateParsingException {
ASN1InputStream dIn = new ASN1InputStream(in);
ASN1Sequence seq = (ASN1Sequence) dIn.readObject();
CertificatePair pair = CertificatePair.getInstance(seq);
return new X509CertificatePair(pair);
}
use of com.github.zhenwei.core.asn1.x509.CertificatePair in project LinLong-Java by zhenwei1108.
the class X509LDAPCertStoreSpi method engineGetCertificates.
public Collection engineGetCertificates(CertSelector selector) throws CertStoreException {
if (!(selector instanceof X509CertSelector)) {
throw new CertStoreException("selector is not a X509CertSelector");
}
X509CertSelector xselector = (X509CertSelector) selector;
Set certSet = new HashSet();
Set set = getEndCertificates(xselector);
set.addAll(getCACertificates(xselector));
set.addAll(getCrossCertificates(xselector));
Iterator it = set.iterator();
try {
CertificateFactory cf = CertificateFactory.getInstance("X.509", WeGooProvider.PROVIDER_NAME);
while (it.hasNext()) {
byte[] bytes = (byte[]) it.next();
if (bytes == null || bytes.length == 0) {
continue;
}
List bytesList = new ArrayList();
bytesList.add(bytes);
try {
CertificatePair pair = CertificatePair.getInstance(new ASN1InputStream(bytes).readObject());
bytesList.clear();
if (pair.getForward() != null) {
bytesList.add(pair.getForward().getEncoded());
}
if (pair.getReverse() != null) {
bytesList.add(pair.getReverse().getEncoded());
}
} catch (IOException e) {
} catch (IllegalArgumentException e) {
}
for (Iterator it2 = bytesList.iterator(); it2.hasNext(); ) {
ByteArrayInputStream bIn = new ByteArrayInputStream((byte[]) it2.next());
try {
Certificate cert = cf.generateCertificate(bIn);
// cert).getSubjectX500Principal());
if (xselector.match(cert)) {
certSet.add(cert);
}
} catch (Exception e) {
}
}
}
} catch (Exception e) {
throw new CertStoreException("certificate cannot be constructed from LDAP result: " + e);
}
return certSet;
}
use of com.github.zhenwei.core.asn1.x509.CertificatePair in project LinLong-Java by zhenwei1108.
the class X509CertificatePair method getEncoded.
public byte[] getEncoded() throws CertificateEncodingException {
Certificate f = null;
Certificate r = null;
try {
if (forward != null) {
f = Certificate.getInstance(new ASN1InputStream(forward.getEncoded()).readObject());
if (f == null) {
throw new CertificateEncodingException("unable to get encoding for forward");
}
}
if (reverse != null) {
r = Certificate.getInstance(new ASN1InputStream(reverse.getEncoded()).readObject());
if (r == null) {
throw new CertificateEncodingException("unable to get encoding for reverse");
}
}
return new CertificatePair(f, r).getEncoded(ASN1Encoding.DER);
} catch (IllegalArgumentException e) {
throw new ExtCertificateEncodingException(e.toString(), e);
} catch (IOException e) {
throw new ExtCertificateEncodingException(e.toString(), e);
}
}
use of com.github.zhenwei.core.asn1.x509.CertificatePair in project LinLong-Java by zhenwei1108.
the class LDAPStoreHelper method createCrossCertificatePairs.
private Set createCrossCertificatePairs(List list, X509CertPairStoreSelector xselector) throws StoreException {
Set certPairSet = new HashSet();
int i = 0;
while (i < list.size()) {
X509CertificatePair pair;
try {
// first try to decode it as certificate pair
try {
X509CertPairParser parser = new X509CertPairParser();
parser.engineInit(new ByteArrayInputStream((byte[]) list.get(i)));
pair = (X509CertificatePair) parser.engineRead();
} catch (StreamParsingException e) {
// now try it to construct it the forward and reverse
// certificate
byte[] forward = (byte[]) list.get(i);
byte[] reverse = (byte[]) list.get(i + 1);
pair = new X509CertificatePair(new CertificatePair(Certificate.getInstance(new ASN1InputStream(forward).readObject()), Certificate.getInstance(new ASN1InputStream(reverse).readObject())));
i++;
}
if (xselector.match((Object) pair)) {
certPairSet.add(pair);
}
} catch (CertificateParsingException e) {
// try next
} catch (IOException e) {
// try next
}
i++;
}
return certPairSet;
}
Aggregations