-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OID Checkup (eu-digital-green-certificates#42)
* OID Services, Test Classes and Helper added. * Testcases modified, Unknown Certificatetype added to validation, overload added for validation. * Updated tests * Updated formatting * Updated tests * Update Co-authored-by: Oleksandr Sarapulov <[email protected]>
- Loading branch information
1 parent
0aeb3a5
commit e3e8644
Showing
9 changed files
with
302 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
decoder/src/main/java/dgca/verifier/app/decoder/model/CertificateType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package dgca.verifier.app.decoder.model | ||
|
||
enum class CertificateType { | ||
UNKNOWN,VACCINATION,RECOVERY,TEST | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
decoder/src/main/java/dgca/verifier/app/decoder/services/X509.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package dgca.verifier.app.decoder.services | ||
|
||
import dgca.verifier.app.decoder.model.CertificateType | ||
import java.io.ByteArrayInputStream | ||
import java.security.cert.* | ||
|
||
|
||
class X509 { | ||
private val OID_TEST = "1.3.6.1.4.1.1847.2021.1.1" | ||
private val OID_ALT_TEST = "1.3.6.1.4.1.0.1847.2021.1.1" | ||
private val OID_VACCINATION = "1.3.6.1.4.1.1847.2021.1.2" | ||
private val OID_ALT_VACCINATION = "1.3.6.1.4.1.0.1847.2021.1.2" | ||
private val OID_RECOVERY = "1.3.6.1.4.1.1847.2021.1.3" | ||
private val OID_ALT_RECOVERY = "1.3.6.1.4.1.0.1847.2021.1.3" | ||
|
||
fun checkIsSuitable(cert: String?, certType: CertificateType?): Boolean { | ||
val b64: ByteArray = org.bouncycastle.util.encoders.Base64.decode(cert) | ||
return isSuitable(b64, certType) | ||
} | ||
|
||
fun isSuitable(data: ByteArray?, certificateType: CertificateType?): Boolean { | ||
try { | ||
val cf: CertificateFactory = CertificateFactory.getInstance("X.509") | ||
val cert: Certificate = cf.generateCertificate(ByteArrayInputStream(data)) | ||
if (isType(cert as X509Certificate)) { | ||
val extendedKeys = cert.extendedKeyUsage | ||
return when (certificateType) { | ||
CertificateType.TEST -> extendedKeys.contains(OID_TEST) || extendedKeys.contains( | ||
OID_ALT_TEST | ||
) | ||
CertificateType.VACCINATION -> extendedKeys.contains(OID_VACCINATION) || extendedKeys.contains( | ||
OID_ALT_VACCINATION | ||
) | ||
CertificateType.RECOVERY -> extendedKeys.contains(OID_RECOVERY) || extendedKeys.contains( | ||
OID_ALT_RECOVERY | ||
) | ||
CertificateType.UNKNOWN -> false | ||
else -> false | ||
} | ||
} | ||
} catch (e: CertificateException) { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
private fun isType(certificate: X509Certificate): Boolean { | ||
return try { | ||
val extendedKeyUsage: List<String> = certificate.extendedKeyUsage ?: return false | ||
|
||
extendedKeyUsage.contains(OID_TEST) | ||
|| extendedKeyUsage.contains(OID_ALT_TEST) | ||
|| extendedKeyUsage.contains(OID_RECOVERY) | ||
|| extendedKeyUsage.contains(OID_ALT_RECOVERY) | ||
|| extendedKeyUsage.contains(OID_VACCINATION) | ||
|| extendedKeyUsage.contains(OID_ALT_VACCINATION) | ||
} catch (e: CertificateParsingException) { | ||
false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 0 additions & 139 deletions
139
decoder/src/test/java/dgca/verifier/app/decoder/QrCodeTests.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.