Skip to content

Commit 2f41a8c

Browse files
authored
Merge pull request #293 from open-eid/MOPPAND-1697
Fix for LDAP search from multiple URLs.
2 parents 2bbe986 + e726ede commit 2f41a8c

File tree

4 files changed

+41
-35
lines changed

4 files changed

+41
-35
lines changed

crypto-lib/src/androidTest/kotlin/ee/ria/DigiDoc/cryptolib/CryptoContainerTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ class CryptoContainerTest {
908908
val cdoc2Settings = CDOC2Settings(context)
909909
val recipient = Addressee(Base64.getDecoder().decode(authCert))
910910

911-
val testFiles:List<File> = listOf()
911+
val testFiles: List<File> = listOf()
912912
val container = openOrCreate(context, testFile, testFiles, cdoc2Settings)
913913

914914
encrypt(context, container.file, testFiles, listOf(recipient), cdoc2Settings, configurationRepository)

crypto-lib/src/main/kotlin/ee/ria/DigiDoc/cryptolib/Addressee.kt

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -188,24 +188,8 @@ class Addressee(
188188
val policyInfo = PolicyInformation.getInstance(element)
189189
val oid = policyInfo.policyIdentifier.id
190190

191-
when {
192-
oid.startsWith(OID.ID_CARD_POLICY_PREFIX) ||
193-
oid.startsWith(OID.ALTERNATE_ID_CARD_POLICY) ->
194-
return CertType.IDCardType
195-
196-
oid.startsWith(OID.DIGI_ID_POLICY_PREFIX) ||
197-
oid.startsWith(OID.ALTERNATE_DIGI_ID_POLICY1) ||
198-
oid.startsWith(OID.ALTERNATE_DIGI_ID_POLICY2) ->
199-
return CertType.DigiIDType
200-
201-
oid.startsWith(OID.MOBILE_ID_POLICY_PREFIX) ||
202-
oid.startsWith(OID.ALTERNATE_MOBILE_ID_POLICY) ->
203-
return CertType.MobileIDType
204-
205-
oid.startsWith(OID.ESEAL_POLICY_PREFIX1) ||
206-
oid.startsWith(OID.ESEAL_POLICY_PREFIX2) ||
207-
oid.startsWith(OID.ESEAL_POLICY_PREFIX3) ->
208-
return CertType.ESealType
191+
if (policyInfo.policyQualifiers != null) {
192+
return certType(listOf(oid))
209193
}
210194
}
211195
}

crypto-lib/src/main/kotlin/ee/ria/DigiDoc/cryptolib/CertType.kt

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,39 @@ enum class CertType {
3131
ESealType,
3232
}
3333

34-
object OID {
35-
const val ID_CARD_POLICY_PREFIX = "1.3.6.1.4.1.10015.1.1"
36-
const val ALTERNATE_ID_CARD_POLICY = "1.3.6.1.4.1.51361.1.1.1"
34+
fun certType(policies: List<String>): CertType {
35+
for (oid in policies) {
36+
when {
37+
// DigiIDType
38+
oid.startsWith("1.3.6.1.4.1.51361.1.1.3") ||
39+
oid.startsWith("1.3.6.1.4.1.51361.1.1.4") ||
40+
oid.startsWith("1.3.6.1.4.1.51361.2.1.6") ||
41+
oid.contains("1.3.6.1.4.1.51361.2.1.6") ->
42+
return CertType.DigiIDType
3743

38-
const val DIGI_ID_POLICY_PREFIX = "1.3.6.1.4.1.10015.1.2"
39-
const val ALTERNATE_DIGI_ID_POLICY1 = "1.3.6.1.4.1.51361.1.1"
40-
const val ALTERNATE_DIGI_ID_POLICY2 = "1.3.6.1.4.1.51455.1.1"
44+
// IDCardType
45+
oid.startsWith("1.3.6.1.4.1.51361.1.1") ||
46+
oid.startsWith("1.3.6.1.4.1.51361.1.2") ||
47+
oid.startsWith("1.3.6.1.4.1.51361.2.1") ||
48+
oid.contains("1.3.6.1.4.1.51361.2.1") ||
49+
oid.startsWith("1.3.6.1.4.1.51455.1.1") ||
50+
oid.startsWith("1.3.6.1.4.1.51455.1.2") ||
51+
oid.startsWith("1.3.6.1.4.1.51455.2.1") ||
52+
oid.contains("1.3.6.1.4.1.51455.2.1") ->
53+
return CertType.IDCardType
4154

42-
const val MOBILE_ID_POLICY_PREFIX = "1.3.6.1.4.1.10015.1.3"
43-
const val ALTERNATE_MOBILE_ID_POLICY = "1.3.6.1.4.1.10015.11.1"
55+
// MobileIDType
56+
oid.startsWith("1.3.6.1.4.1.10015.1.3") ||
57+
oid.startsWith("1.3.6.1.4.1.10015.11.1") ->
58+
return CertType.MobileIDType
4459

45-
const val ESEAL_POLICY_PREFIX1 = "1.3.6.1.4.1.10015.7.3"
46-
const val ESEAL_POLICY_PREFIX2 = "1.3.6.1.4.1.10015.7.1"
47-
const val ESEAL_POLICY_PREFIX3 = "1.3.6.1.4.1.10015.2.1"
60+
// ESealType
61+
oid.startsWith("1.3.6.1.4.1.10015.7.3") ||
62+
oid.startsWith("1.3.6.1.4.1.10015.7.1") ||
63+
oid.startsWith("1.3.6.1.4.1.10015.2.1") ->
64+
return CertType.ESealType
65+
}
66+
}
67+
68+
return CertType.UnknownType
4869
}

crypto-lib/src/main/kotlin/ee/ria/DigiDoc/cryptolib/repository/RecipientRepositoryImpl.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,18 @@ class RecipientRepositoryImpl
102102
val ldapFilter = LdapFilter(query)
103103
if (ldapFilter.isPersonalCode(query)) {
104104
val ldapPersonUrls = configurationProvider?.ldapPersonUrls
105+
val addressees = ArrayList<Addressee>()
106+
var count = 0
105107
for (url in ldapPersonUrls.orEmpty()) {
106108
val ldapUrl = url.split("://")[1]
107109
val ldapUrlComponents = ldapUrl.split("/")
108110
val ldapPersonUrl = ldapUrlComponents[0]
109111
val dn = if (ldapUrlComponents.size > 1) ldapUrlComponents[1] else null
110112

111113
try {
112-
val (addressees, count) = search(context, ldapPersonUrl, dn, LdapFilter(query))
113-
if (addressees.isNotEmpty()) {
114-
return Pair(addressees, count)
115-
}
114+
val (addresseesSearch, countSearch) = search(context, ldapPersonUrl, dn, LdapFilter(query))
115+
addressees.addAll(addresseesSearch)
116+
count += countSearch
116117
} catch (e: NoInternetConnectionException) {
117118
errorLog(logTag, "Unable to connect to LDAP url: $ldapPersonUrl", e)
118119
throw e
@@ -121,7 +122,7 @@ class RecipientRepositoryImpl
121122
throw CryptoException("Unable to get certificates from LDAP url: $ldapPersonUrl", ce)
122123
}
123124
}
124-
return Pair(listOf(), 0)
125+
return Pair(addressees, count)
125126
} else {
126127
val ldapCorpUrl = configurationProvider?.ldapCorpUrl?.split("://")[1]
127128
return search(context, ldapCorpUrl, null, LdapFilter(query))

0 commit comments

Comments
 (0)