use of com.github.zhenwei.provider.x509.X509CertificatePair in project LinLong-Java by zhenwei1108.
the class X509CertPairParser method engineReadAll.
public Collection engineReadAll() throws StreamParsingException {
X509CertificatePair pair;
List certs = new ArrayList();
while ((pair = (X509CertificatePair) engineRead()) != null) {
certs.add(pair);
}
return certs;
}
use of com.github.zhenwei.provider.x509.X509CertificatePair 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.provider.x509.X509CertificatePair in project LinLong-Java by zhenwei1108.
the class LDAPStoreHelper method getCrossCertificatePairs.
/**
* Returns cross certificate pairs.
*
* @param selector The selector to use to find the cross certificates.
* @return A possible empty collection with {@link X509CertificatePair}s
* @throws StoreException
*/
public Collection getCrossCertificatePairs(X509CertPairStoreSelector selector) throws StoreException {
String[] attrs = splitString(params.getCrossCertificateAttribute());
String[] attrNames = splitString(params.getLdapCrossCertificateAttributeName());
String[] subjectAttributeNames = splitString(params.getCrossCertificateSubjectAttributeName());
List list = crossCertificatePairSubjectSearch(selector, attrs, attrNames, subjectAttributeNames);
Set resultSet = createCrossCertificatePairs(list, selector);
if (resultSet.size() == 0) {
X509CertStoreSelector emptyCertselector = new X509CertStoreSelector();
X509CertPairStoreSelector emptySelector = new X509CertPairStoreSelector();
emptySelector.setForwardSelector(emptyCertselector);
emptySelector.setReverseSelector(emptyCertselector);
list = crossCertificatePairSubjectSearch(emptySelector, attrs, attrNames, subjectAttributeNames);
resultSet.addAll(createCrossCertificatePairs(list, selector));
}
return resultSet;
}
use of com.github.zhenwei.provider.x509.X509CertificatePair 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;
}
use of com.github.zhenwei.provider.x509.X509CertificatePair in project LinLong-Java by zhenwei1108.
the class X509StoreLDAPCerts method getCertificatesFromCrossCertificatePairs.
private Collection getCertificatesFromCrossCertificatePairs(X509CertStoreSelector xselector) throws StoreException {
Set set = new HashSet();
X509CertPairStoreSelector ps = new X509CertPairStoreSelector();
ps.setForwardSelector(xselector);
ps.setReverseSelector(new X509CertStoreSelector());
Set crossCerts = new HashSet(helper.getCrossCertificatePairs(ps));
Set forward = new HashSet();
Set reverse = new HashSet();
Iterator it = crossCerts.iterator();
while (it.hasNext()) {
X509CertificatePair pair = (X509CertificatePair) it.next();
if (pair.getForward() != null) {
forward.add(pair.getForward());
}
if (pair.getReverse() != null) {
reverse.add(pair.getReverse());
}
}
set.addAll(forward);
set.addAll(reverse);
return set;
}
Aggregations