|
34 | 34 | import org.bouncycastle.asn1.ASN1InputStream; |
35 | 35 | import org.bouncycastle.asn1.x509.CertificatePair; |
36 | 36 | import org.bouncycastle.jce.X509LDAPCertStoreParameters; |
| 37 | +import org.bouncycastle.ldap.LDAPUtils; |
37 | 38 | import org.bouncycastle.util.Strings; |
38 | 39 |
|
39 | 40 | /** |
|
50 | 51 | public class X509LDAPCertStoreSpi |
51 | 52 | extends CertStoreSpi |
52 | 53 | { |
53 | | - private static String[] FILTER_ESCAPE_TABLE = new String['\\' + 1]; |
54 | | - |
55 | | - static |
56 | | - { |
57 | | - // Filter encoding table ------------------------------------- |
58 | | - |
59 | | - // fill with char itself |
60 | | - for (char c = 0; c < FILTER_ESCAPE_TABLE.length; c++) |
61 | | - { |
62 | | - FILTER_ESCAPE_TABLE[c] = String.valueOf(c); |
63 | | - } |
64 | | - |
65 | | - // escapes (RFC2254) |
66 | | - FILTER_ESCAPE_TABLE['*'] = "\\2a"; |
67 | | - FILTER_ESCAPE_TABLE['('] = "\\28"; |
68 | | - FILTER_ESCAPE_TABLE[')'] = "\\29"; |
69 | | - FILTER_ESCAPE_TABLE['\\'] = "\\5c"; |
70 | | - FILTER_ESCAPE_TABLE[0] = "\\00"; |
71 | | - } |
72 | | - |
73 | 54 | /** |
74 | 55 | * Initial Context Factory. |
75 | 56 | */ |
@@ -124,42 +105,6 @@ private DirContext connectLDAP() |
124 | 105 | return ctx; |
125 | 106 | } |
126 | 107 |
|
127 | | - private String parseDN(String subject, String subjectAttributeName) |
128 | | - { |
129 | | - String temp = subject; |
130 | | - int begin = Strings.toLowerCase(temp).indexOf(Strings.toLowerCase(subjectAttributeName)); |
131 | | - temp = temp.substring(begin + subjectAttributeName.length()); |
132 | | - int end = temp.indexOf(','); |
133 | | - if (end == -1) |
134 | | - { |
135 | | - end = temp.length(); |
136 | | - } |
137 | | - while (temp.charAt(end - 1) == '\\') |
138 | | - { |
139 | | - end = temp.indexOf(',', end + 1); |
140 | | - if (end == -1) |
141 | | - { |
142 | | - end = temp.length(); |
143 | | - } |
144 | | - } |
145 | | - temp = temp.substring(0, end); |
146 | | - begin = temp.indexOf('='); |
147 | | - temp = temp.substring(begin + 1); |
148 | | - if (temp.charAt(0) == ' ') |
149 | | - { |
150 | | - temp = temp.substring(1); |
151 | | - } |
152 | | - if (temp.startsWith("\"")) |
153 | | - { |
154 | | - temp = temp.substring(1); |
155 | | - } |
156 | | - if (temp.endsWith("\"")) |
157 | | - { |
158 | | - temp = temp.substring(0, temp.length() - 1); |
159 | | - } |
160 | | - return filterEncode(temp); |
161 | | - } |
162 | | - |
163 | 108 | public Collection engineGetCertificates(CertSelector selector) |
164 | 109 | throws CertStoreException |
165 | 110 | { |
@@ -277,7 +222,7 @@ private Set certSubjectSerialSearch(X509CertSelector xselector, |
277 | 222 | subject = xselector.getSubjectAsString(); |
278 | 223 | } |
279 | 224 | } |
280 | | - String attrValue = parseDN(subject, subjectAttributeName); |
| 225 | + String attrValue = LDAPUtils.parseDN(subject, subjectAttributeName); |
281 | 226 | set.addAll(search(attrName, "*" + attrValue + "*", attrs)); |
282 | 227 | if (serial != null |
283 | 228 | && params.getSearchForSerialNumberIn() != null) |
@@ -374,13 +319,13 @@ public Collection engineGetCRLs(CRLSelector selector) |
374 | 319 | { |
375 | 320 | String issuerAttributeName = params |
376 | 321 | .getCertificateRevocationListIssuerAttributeName(); |
377 | | - attrValue = parseDN((String)o, issuerAttributeName); |
| 322 | + attrValue = LDAPUtils.parseDN((String)o, issuerAttributeName); |
378 | 323 | } |
379 | 324 | else |
380 | 325 | { |
381 | 326 | String issuerAttributeName = params |
382 | 327 | .getCertificateRevocationListIssuerAttributeName(); |
383 | | - attrValue = parseDN(new X500Principal((byte[])o) |
| 328 | + attrValue = LDAPUtils.parseDN(new X500Principal((byte[])o) |
384 | 329 | .getName("RFC1779"), issuerAttributeName); |
385 | 330 | } |
386 | 331 | set.addAll(search(attrName, "*" + attrValue + "*", attrs)); |
@@ -415,43 +360,7 @@ public Collection engineGetCRLs(CRLSelector selector) |
415 | 360 |
|
416 | 361 | return crlSet; |
417 | 362 | } |
418 | | - |
419 | | - /** |
420 | | - * Escape a value for use in a filter. |
421 | | - * |
422 | | - * @param value the value to escape. |
423 | | - * @return a properly escaped representation of the supplied value. |
424 | | - */ |
425 | | - private String filterEncode(String value) |
426 | | - { |
427 | | - if (value == null) |
428 | | - { |
429 | | - return null; |
430 | | - } |
431 | | - |
432 | | - // make buffer roomy |
433 | | - StringBuilder encodedValue = new StringBuilder(value.length() * 2); |
434 | | - |
435 | | - int length = value.length(); |
436 | | - |
437 | | - for (int i = 0; i < length; i++) |
438 | | - { |
439 | | - char c = value.charAt(i); |
440 | | - |
441 | | - if (c < FILTER_ESCAPE_TABLE.length) |
442 | | - { |
443 | | - encodedValue.append(FILTER_ESCAPE_TABLE[c]); |
444 | | - } |
445 | | - else |
446 | | - { |
447 | | - // default: add the char |
448 | | - encodedValue.append(c); |
449 | | - } |
450 | | - } |
451 | | - |
452 | | - return encodedValue.toString(); |
453 | | - } |
454 | | - |
| 363 | + |
455 | 364 | /** |
456 | 365 | * Returns a Set of byte arrays with the certificate or CRL encodings. |
457 | 366 | * |
|
0 commit comments