|
12 | 12 | import org.bouncycastle.asn1.ASN1OctetString; |
13 | 13 | import org.bouncycastle.asn1.ASN1Sequence; |
14 | 14 | import org.bouncycastle.asn1.DERIA5String; |
| 15 | +import org.bouncycastle.asn1.x500.RDN; |
15 | 16 | import org.bouncycastle.asn1.x500.X500Name; |
| 17 | +import org.bouncycastle.asn1.x500.style.BCStyle; |
| 18 | +import org.bouncycastle.asn1.x500.style.IETFUtils; |
| 19 | +import org.bouncycastle.asn1.x500.style.RFC4519Style; |
| 20 | +import org.bouncycastle.asn1.x509.GeneralName; |
| 21 | +import org.bouncycastle.asn1.x509.GeneralSubtree; |
16 | 22 | import org.bouncycastle.util.Arrays; |
17 | 23 | import org.bouncycastle.util.Integers; |
18 | 24 | import org.bouncycastle.util.Strings; |
@@ -392,9 +398,33 @@ private static boolean withinDNSubtree( |
392 | 398 |
|
393 | 399 | for (int j = subtree.size() - 1; j >= 0; j--) |
394 | 400 | { |
395 | | - if (!subtree.getObjectAt(j).equals(dns.getObjectAt(j))) |
396 | | - { |
397 | | - return false; |
| 401 | + // both subtree and dns are a ASN.1 Name and the elements are a RDN |
| 402 | + RDN subtreeRdn = RDN.getInstance(subtree.getObjectAt(j)); |
| 403 | + dnsiteration: |
| 404 | + for (int k=0; k<dns.size(); k++) { |
| 405 | + RDN dnsRdn = RDN.getInstance(dns.getObjectAt(k)); |
| 406 | + // check if types and values of all naming attributes are matching, other types which are not restricted are allowed, see https://tools.ietf.org/html/rfc5280#section-7.1 |
| 407 | + if (subtreeRdn.size() > 0 && subtreeRdn.size() == dnsRdn.size()) { |
| 408 | + // Two relative distinguished names |
| 409 | + // RDN1 and RDN2 match if they have the same number of naming attributes |
| 410 | + // and for each naming attribute in RDN1 there is a matching naming attribute in RDN2. |
| 411 | + // NOTE: this is checking the attributes in the same order, which might be not necessary, if this is a problem also IETFUtils.rDNAreEqual mus tbe changed. |
| 412 | + for (int l=0; l<subtreeRdn.size(); l++) { |
| 413 | + if (!subtreeRdn.getTypesAndValues()[l].getType().equals(dnsRdn.getTypesAndValues()[l].getType())) { |
| 414 | + continue dnsiteration; |
| 415 | + } |
| 416 | + } |
| 417 | + // use new RFC 5280 comparison, NOTE: this is now different from with RFC 3280, where only binary comparison is used |
| 418 | + // obey RFC 5280 7.1 |
| 419 | + // special treatment of serialNumber for GSMA SGP.22 RSP specification |
| 420 | + if (subtreeRdn.size() == 1 && subtreeRdn.getFirst().getType().equals(RFC4519Style.serialNumber)) { |
| 421 | + if (!dnsRdn.getFirst().getValue().toString().startsWith(subtreeRdn.getFirst().getValue().toString())) { |
| 422 | + return false; |
| 423 | + } |
| 424 | + } else if (!IETFUtils.rDNAreEqual(subtreeRdn, dnsRdn)) { |
| 425 | + return false; |
| 426 | + } |
| 427 | + } |
398 | 428 | } |
399 | 429 | } |
400 | 430 |
|
|
0 commit comments