Skip to content

Commit

Permalink
Fix parsing of issuer country (eu-digital-green-certificates#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
craftbyte authored Dec 29, 2021
1 parent 4556a26 commit 540abc5
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ import java.time.ZoneId
import java.time.ZoneOffset
import java.time.ZonedDateTime
import java.util.*
import java.util.regex.Matcher
import java.util.regex.Pattern
import javax.inject.Inject

@HiltViewModel
Expand Down Expand Up @@ -347,12 +349,10 @@ class VerificationViewModel @Inject constructor(
const val ISSUING_COUNTRY_X509_CERTIFICATE_KEY = "C"

fun X509Certificate.getIssuerCountry(): String {
val keys = issuerX500Principal.name.split(",")
keys.forEach {
val (key, value) = it.split("=")
if (key.equals(ISSUING_COUNTRY_X509_CERTIFICATE_KEY, ignoreCase = true)) {
return value.toLowerCase(Locale.ROOT)
}
val fieldPattern = Pattern.compile("$ISSUING_COUNTRY_X509_CERTIFICATE_KEY=((?:[^,]|\\\\,)+)");
val matcher = fieldPattern.matcher(issuerX500Principal.name);
if (matcher.find()) {
return matcher.group(1);
}
return ""
}

0 comments on commit 540abc5

Please sign in to comment.