crypto-inventory 0.4.0: Swift and Kotlin detectors (CryptoKit, CommonCrypto, Security.framework, Android Keystore, Tink, OkHttp, the libsignal Swift and Android APIs), Apple and Android manifests; remediation recipes for Apache and HAProxy measured on real servers, HAProxy precondition fixed
This commit is contained in:
1 parent
e453c0c42d
commit
b6ed4d2b71
37 files changed
+1623
-82
No files matched your search
@@ -0,0 +1,102 @@
|
||||
// Fixtura: JCA/JSSE din Kotlin (fara `new`, cu `val`), verificatorul PKIX al lui rustls-platform-verifier asa cum sta in clona libsignal
|
||||
// (java/android/src/main/java/org/rustls/platformverifier/CertificateVerifier.kt, randurile in dreptul formelor), Android Keystore
|
||||
// (developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.Builder), Tink (developers.google.com/tink, sabloanele
|
||||
// de chei) si OkHttp (square.github.io/okhttp/features/https: ConnectionSpec, TlsVersion, CipherSuite, CertificatePinner). Nu se compileaza.
|
||||
package fixturi
|
||||
|
||||
import java.security.KeyPairGenerator
|
||||
import java.security.KeyStore
|
||||
import java.security.MessageDigest
|
||||
import java.security.cert.CertPathValidator
|
||||
import java.security.cert.CertificateFactory
|
||||
import java.security.spec.ECGenParameterSpec
|
||||
import javax.crypto.Cipher
|
||||
import javax.crypto.KeyGenerator
|
||||
import javax.crypto.Mac
|
||||
import javax.net.ssl.SSLContext
|
||||
import javax.net.ssl.TrustManagerFactory
|
||||
import javax.net.ssl.X509TrustManager
|
||||
import android.security.keystore.KeyGenParameterSpec
|
||||
import android.security.keystore.KeyProperties
|
||||
import com.google.crypto.tink.KeyTemplates
|
||||
import com.google.crypto.tink.KeysetHandle
|
||||
import com.google.crypto.tink.aead.AeadConfig
|
||||
import okhttp3.CertificatePinner
|
||||
import okhttp3.CipherSuite
|
||||
import okhttp3.ConnectionSpec
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.TlsVersion
|
||||
import org.bouncycastle.crypto.engines.RC4Engine // EXPECT: RC4 | weak-now
|
||||
|
||||
class Android {
|
||||
private val DIGEST = "SHA-256"
|
||||
|
||||
fun jca(algDinParametru: String, keystore: KeyStore) {
|
||||
val alias = "root_${keystore.size()}" // CertificateVerifier.kt:149: un sablon ${ } inaintea apelurilor (lexerul trebuie sa il inchida)
|
||||
val kpg = KeyPairGenerator.getInstance("RSA") // EXPECT: RSA-3072 | quantum-vulnerable
|
||||
kpg.initialize(3072)
|
||||
val ec = KeyPairGenerator.getInstance("EC") // EXPECT: EC-secp256r1 | quantum-vulnerable
|
||||
ec.initialize(ECGenParameterSpec("secp256r1"))
|
||||
val c1 = Cipher.getInstance("AES/GCM/NoPadding") // EXPECT: AES-GCM | quantum-safe
|
||||
val mac = Mac.getInstance("HmacSHA256") // EXPECT: HMAC-SHA-256 | quantum-safe
|
||||
val md = MessageDigest.getInstance(DIGEST) // EXPECT: SHA-256 | quantum-safe
|
||||
val md2 = MessageDigest.getInstance(algDinParametru) // EXPECT: MessageDigest.getInstance | unknown
|
||||
val tls = SSLContext.getInstance("TLSv1.2") // EXPECT: TLSv1.2 | quantum-vulnerable
|
||||
println(listOf(alias, c1, mac, md, md2, tls))
|
||||
}
|
||||
|
||||
// rustls-platform-verifier, CertificateVerifier.kt: lantul de incredere TLS al clientului (verificare de certificate, nu schimb de cheie)
|
||||
fun pkix(keystore: KeyStore?, principal: ByteArray) {
|
||||
val factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()) // :101; EXPECT: X.509 chain validation (PKIX) | quantum-vulnerable
|
||||
factory.init(keystore)
|
||||
for (manager in factory.trustManagers) {
|
||||
if (manager is X509TrustManager) { // :113; EXPECT: X.509 chain validation (PKIX) | quantum-vulnerable
|
||||
manager.checkServerTrusted(arrayOf(), "RSA") // :291; EXPECT: X.509 chain validation (PKIX) | quantum-vulnerable
|
||||
}
|
||||
}
|
||||
val certFactory: CertificateFactory = CertificateFactory.getInstance("X.509") // :198: parsare de certificate, nu verificare: nimic
|
||||
val systemKeystore = KeyStore.getInstance("AndroidCAStore") // :209; EXPECT: X.509 chain validation (PKIX) | quantum-vulnerable
|
||||
val validator = CertPathValidator.getInstance("PKIX") // :367; EXPECT: X.509 chain validation (PKIX) | quantum-vulnerable
|
||||
val digest = MessageDigest.getInstance("MD5").digest(principal) // :435: aliasul de sistem al unei radacini, nu securitate; unealta nu judeca intentia; EXPECT: MD5 | weak-now
|
||||
println(listOf(certFactory, systemKeystore, validator, digest))
|
||||
}
|
||||
|
||||
fun keystore() {
|
||||
val kpg = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_EC, "AndroidKeyStore") // curba din Builder-ul de mai jos; EXPECT: EC-secp256r1 | quantum-vulnerable
|
||||
kpg.initialize(
|
||||
KeyGenParameterSpec.Builder("alias", KeyProperties.PURPOSE_SIGN or KeyProperties.PURPOSE_VERIFY)
|
||||
.setAlgorithmParameterSpec(ECGenParameterSpec("secp256r1"))
|
||||
.setDigests(KeyProperties.DIGEST_SHA256)
|
||||
.build()
|
||||
)
|
||||
val rsa = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA, "AndroidKeyStore") // marimea din variabila spec; EXPECT: RSA-2048 | quantum-vulnerable
|
||||
val spec = KeyGenParameterSpec.Builder("rsa", KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT)
|
||||
.setKeySize(2048)
|
||||
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_OAEP)
|
||||
.build()
|
||||
rsa.initialize(spec)
|
||||
val kg = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore") // EXPECT: AES-256-GCM | quantum-safe
|
||||
kg.init(KeyGenParameterSpec.Builder("aes", KeyProperties.PURPOSE_ENCRYPT).setBlockModes(KeyProperties.BLOCK_MODE_GCM).setKeySize(256).build())
|
||||
val singur = KeyGenParameterSpec.Builder("hmac", KeyProperties.PURPOSE_SIGN).setKeySize(521).build() // fara generator in fisier: din marime; EXPECT: EC-secp521r1 | quantum-vulnerable
|
||||
println(singur)
|
||||
}
|
||||
|
||||
fun tink() {
|
||||
AeadConfig.register() // dovada slaba, suprimata de sabloanele de mai jos: nimic
|
||||
val aead = KeysetHandle.generateNew(KeyTemplates.get("AES256_GCM")) // EXPECT: AES-256-GCM | quantum-safe
|
||||
val sig = KeysetHandle.generateNew(KeyTemplates.get("ECDSA_P256")) // EXPECT: ECDSA-secp256r1 | quantum-vulnerable
|
||||
val hybrid = KeysetHandle.generateNew(KeyTemplates.get("DHKEM_X25519_HKDF_SHA256_HKDF_SHA256_AES_256_GCM")) // HPKE; EXPECT: X25519 | quantum-vulnerable
|
||||
val mac = KeysetHandle.generateNew(KeyTemplates.get("HMAC_SHA256_256BITTAG")) // EXPECT: HMAC-SHA-256 | quantum-safe
|
||||
val rsa = KeysetHandle.generateNew(KeyTemplates.get("RSA_SSA_PSS_3072_SHA256_F4")) // EXPECT: RSA-3072 | quantum-vulnerable
|
||||
println(listOf(aead, sig, hybrid, mac, rsa))
|
||||
}
|
||||
|
||||
fun okhttp(): OkHttpClient {
|
||||
val spec = ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS) // EXPECT: TLS (negotiated, OkHttp MODERN_TLS) | unknown
|
||||
.tlsVersions(TlsVersion.TLS_1_2, TlsVersion.TLS_1_3) // EXPECT: TLSv1.2 | quantum-vulnerable ; TLSv1.3 | unknown
|
||||
.cipherSuites(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, CipherSuite.TLS_AES_256_GCM_SHA384) // EXPECT: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 | quantum-vulnerable ; AES-256-GCM | quantum-safe
|
||||
.build()
|
||||
val pinner = CertificatePinner.Builder().add("example.com", "sha256/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=").build() // EXPECT: certificate pinning (SPKI) | quantum-vulnerable
|
||||
return OkHttpClient.Builder().connectionSpecs(listOf(spec)).certificatePinner(pinner).build()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user