|
8 | 8 | import java.util.Map; |
9 | 9 | import java.util.Set; |
10 | 10 |
|
| 11 | +import org.bouncycastle.asn1.ASN1ObjectIdentifier; |
11 | 12 | import org.bouncycastle.asn1.ASN1OctetString; |
12 | 13 | import org.bouncycastle.asn1.ASN1Sequence; |
13 | 14 | import org.bouncycastle.asn1.DERIA5String; |
14 | 15 | import org.bouncycastle.asn1.x500.RDN; |
| 16 | +import org.bouncycastle.asn1.x500.X500Name; |
| 17 | +import org.bouncycastle.asn1.x500.style.BCStyle; |
15 | 18 | import org.bouncycastle.asn1.x500.style.IETFUtils; |
16 | 19 | import org.bouncycastle.asn1.x500.style.RFC4519Style; |
17 | 20 | import org.bouncycastle.asn1.x509.GeneralName; |
@@ -64,13 +67,28 @@ private static boolean withinDNSubtree( |
64 | 67 | { |
65 | 68 | // both subtree and dns are a ASN.1 Name and the elements are a RDN |
66 | 69 | RDN subtreeRdn = RDN.getInstance(subtree.getObjectAt(j)); |
| 70 | + dnsiteration: |
67 | 71 | for (int k=0; k<dns.size(); k++) { |
68 | 72 | RDN dnsRdn = RDN.getInstance(dns.getObjectAt(k)); |
69 | | - // type must match, other types which are not restricted are allowed, see https://tools.ietf.org/html/rfc5280#section-7.1 |
70 | | - if (subtreeRdn.getFirst().getType().equals(dnsRdn.getFirst().getType())) { |
| 73 | + // 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 |
| 74 | + if (subtreeRdn.size() > 0 && subtreeRdn.size() == dnsRdn.size()) { |
| 75 | + // Two relative distinguished names |
| 76 | + // RDN1 and RDN2 match if they have the same number of naming attributes |
| 77 | + // and for each naming attribute in RDN1 there is a matching naming attribute in RDN2. |
| 78 | + // 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. |
| 79 | + for (int l=0; l<subtreeRdn.size(); l++) { |
| 80 | + if (!subtreeRdn.getTypesAndValues()[l].getType().equals(dnsRdn.getTypesAndValues()[l].getType())) { |
| 81 | + continue dnsiteration; |
| 82 | + } |
| 83 | + } |
71 | 84 | // use new RFC 5280 comparison, NOTE: this is not different from with RFC 3280, where only binary comparison is used |
72 | 85 | // obey RFC 5280 7.1 |
73 | | - if (!IETFUtils.rDNAreEqual(subtreeRdn, dnsRdn)) { |
| 86 | + // special treatment of serialNumber for GSMA SGP.22 RSP specification |
| 87 | + if (subtreeRdn.size() == 1 && subtreeRdn.getFirst().getType().equals(RFC4519Style.serialNumber)) { |
| 88 | + if (!dnsRdn.getFirst().getValue().toString().startsWith(subtreeRdn.getFirst().getValue().toString())) { |
| 89 | + return false; |
| 90 | + } |
| 91 | + } else if (!IETFUtils.rDNAreEqual(subtreeRdn, dnsRdn)) { |
74 | 92 | return false; |
75 | 93 | } |
76 | 94 | } |
|
0 commit comments