use of com.github.zhenwei.provider.x509.X509CertPairStoreSelector 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.X509CertPairStoreSelector in project LinLong-Java by zhenwei1108.
the class X509StoreLDAPCertPairs method engineGetMatches.
/**
* Returns a collection of matching cross certificate pairs from the LDAP location.
* <p>
* The selector must be a of type <code>X509CertPairStoreSelector</code>. If it is not an empty
* collection is returned.
* </p>
* <p>
* The subject should be a reasonable criteria for a selector.
* </p>
*
* @param selector The selector to use for finding.
* @return A collection with the matches.
* @throws StoreException if an exception occurs while searching.
*/
public Collection engineGetMatches(Selector selector) throws StoreException {
if (!(selector instanceof X509CertPairStoreSelector)) {
return Collections.EMPTY_SET;
}
X509CertPairStoreSelector xselector = (X509CertPairStoreSelector) selector;
Set set = new HashSet();
set.addAll(helper.getCrossCertificatePairs(xselector));
return set;
}
use of com.github.zhenwei.provider.x509.X509CertPairStoreSelector 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.X509CertPairStoreSelector 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