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
+41
-11
@@ -24,8 +24,10 @@ An API name that appears only inside a comment or inside a string literal is not
|
||||
| Java | `KeyPairGenerator`, `Signature`, `Cipher`, `KeyAgreement`, `MessageDigest`, `Mac`, `KeyGenerator`, `KeyFactory`, `SecretKeyFactory`, `KEM`, `SSLContext` `getInstance("...")`; `ECGenParameterSpec`, `NamedParameterSpec`; `setEnabledProtocols`; JSSE system properties (`jdk.tls.namedGroups`, protocol lists); Bouncy Castle imports and post-quantum parameter sets (`org.bouncycastle.pqc`, `MLKEMParameters`, `MLDSAParameters`, `SLHDSAParameters`, `FalconParameters`, ...); the libsignal Java/Android API (`org.signal.libsignal`, anchored on its import or package: `ECKeyPair.generate`, `IdentityKeyPair.generate`, `KEMKeyPair.generate(KEMKeyType.KYBER_1024)`, `HKDF.deriveSecrets`, `new Aes256GcmSiv` / `Aes256GcmEncryption` / `Aes256Ctr32`, `new PreKeyBundle`) |
|
||||
| Go | imports of `crypto/rsa`, `crypto/ecdsa`, `crypto/elliptic`, `crypto/ecdh`, `crypto/ed25519`, `crypto/md5`, `crypto/sha1`, `crypto/des`, `crypto/rc4`, `crypto/mlkem`, `crypto/tls`, `golang.org/x/crypto/...`, go-ethereum `crypto`, CIRCL ML-KEM/ML-DSA; calls with parameters (`rsa.GenerateKey` size, `ecdsa.GenerateKey` curve, `hmac.New` hash, `mlkem.GenerateKey768`); `tls.Config` `MinVersion`, `MaxVersion`, `CurvePreferences` (including `tls.X25519MLKEM768`) |
|
||||
| Rust | `use`/`extern crate` resolution of names to crates; static calls `Type::method` (`Sha256::new`, `SigningKey::generate`, `Aes256Gcm::new_from_slice`, `RsaPrivateKey::new(rng, 2048)`, `MlDsa65::key_gen`, `MlKem768::generate`); generic parameters (`Hmac::<Sha256>`, `Hkdf::<Sha512>`, `type HmacSha256 = Hmac<Sha256>`, `SigningKey::<Sha2_128s>`); path functions (`blake3::hash`, `pbkdf2::pbkdf2_hmac::<Sha256>`, `pqcrypto_kyber::kyber1024::keypair`, `rustls::crypto::ring::default_provider`); `ring` constants (`aead::AES_256_GCM`, `signature::ED25519`, `agreement::X25519`); `jsonwebtoken::Algorithm::*`, `oqs::Algorithm::*`, libsignal `kem::KeyType::Kyber1024`; RustCrypto modes (`ecb::Encryptor<Aes128>`, `cbc::Decryptor<Aes256>`); `snow` Noise patterns (`Noise_XX_25519_ChaChaPoly_SHA256`); `openssl` and the BoringSSL bindings `boring` / `boring-signal` with the same API (`MessageDigest::*`, `Cipher::*`, `Rsa::generate`, `EcKey::generate` + `Nid`, `PKey::generate_ed25519`, `SslConnector::builder`, `set_min_proto_version`); `secp256k1` `.sign_ecdsa`/`.sign_schnorr`; libcrux (`libcrux_ml_kem::mlkem1024::generate_key_pair`, the pre-standard `kyber768` / `kyber1024` modules, `libcrux_ml_dsa::ml_dsa_65::sign`); `x25519_dalek::x25519(...)`; `HmacReset`; a mode type brought in by name (`use cbc::Decryptor; Decryptor::<Aes256>::new`); the hybrid Noise pattern `Noise_NKhfs_25519+Kyber1024_...` as one hybrid key exchange; a name brought in by a glob import (`use libsignal_protocol::*`) is resolved by trying the glob-imported crates in order |
|
||||
| Swift | names are resolved through `import`: CryptoKit / swift-crypto (`SHA256.hash`, `SHA384`, `SHA512`, `Insecure.MD5`, `Insecure.SHA1`, `HMAC<SHA256>`, `AES.GCM.seal/open` (key size from a `SymmetricKey(size:)` on the same line), `AES.KeyWrap`, `ChaChaPoly.seal`, `Curve25519.KeyAgreement.PrivateKey()`, `Curve25519.Signing.PrivateKey()`, `P256/P384/P521.Signing` and `.KeyAgreement`, `HKDF<SHA256>.deriveKey`, `SymmetricKey(size:)`, `_RSA` from `_CryptoExtras`); CommonCrypto (`CC_SHA256`, `CC_MD5`, `CCCrypt` / `CCCryptorCreate` with `kCCAlgorithm*`, `kCCOptionECBMode`, `kCCKeySizeAES*`, `CCHmac` with `kCCHmacAlg*`, `CCKeyDerivationPBKDF` with `kCCPRFHmacAlg*`); Security.framework (`SecKeyCreateRandomKey` with `kSecAttrKeyTypeRSA` / `kSecAttrKeyTypeECSECPrimeRandom` and `kSecAttrKeySizeInBits`, read from the call or from an attribute dictionary defined in the same file; `SecKeyCreateSignature` / `SecKeyVerifySignature` / `SecKeyCreateEncryptedData` / `SecKeyCreateDecryptedData` with `.rsaSignatureMessagePKCS1v15SHA256`, `.rsaSignatureMessagePSSSHA256`, `.ecdsaSignatureMessageX962SHA256`, `.rsaEncryptionOAEPSHA256`, ...; `SecTrustEvaluateWithError` / `SecPolicyCreateSSL` as certificate-chain validation); the client's TLS (`tlsMinimumSupportedProtocolVersion` / `tlsMaximumSupportedProtocolVersion`, `sec_protocol_options_set_min/max_tls_protocol_version`, `NWProtocolTLS.Options()`); CryptoSwift (`AES(key:blockMode:)`, `SHA2(variant:)`, `.md5()`, `HMAC(key:variant:)`, `PBKDF2`, `ChaCha20`, `Poly1305`, `RSA(keySize:)`, `Blowfish`); swift-sodium / Clibsodium (`sodium.box`, `.sign`, `.keyExchange`, `.secretBox`, `.aead.xchacha20poly1305ietf`, `.pwHash`, `.genericHash`, `crypto_box_*`, `crypto_sign_*`, `crypto_aead_*`, ...); the libsignal Swift API (`import LibSignalClient`, or `import SignalFfi` and the `Sources/LibSignalClient/` target directory for the library's own sources: `IdentityKeyPair.generate()`, `PrivateKey.generate()`, `KEMKeyPair.generate()` (Kyber-1024: the Swift API takes no key type, the bridge generates `kem::KeyType::Kyber1024`), `KEMPublicKey(...)`, `Aes256GcmSiv(key:)`, `Aes256GcmEncryptedData`, `Aes256GcmEncryption` / `Aes256GcmDecryption`, `Aes256Ctr32`, `hkdf(...)`, `PreKeyBundle(...)` / `processPreKeyBundle(...)`) |
|
||||
| Kotlin | the Java rules with Kotlin syntax (no `new`, no `;`, `val`/`var`, `arrayOf(...)`, `ECGenParameterSpec("...")`): JCA `getInstance("...")`, `SSLContext`, `setEnabledProtocols`, Bouncy Castle imports, the libsignal Java/Android API without `new` (`ECPrivateKey.generate()`, `ECKeyPair.generate()`, `KEMKeyPair.generate(KEMKeyType.KYBER_1024)`, `KEMPublicKey(bytes)`, `HKDF.deriveSecrets`, `Aes256GcmSiv(key)`, `PreKeyBundle(...)`, `SealedSessionCipher(...)`) and the library's own native bridge inside `org.signal.libsignal` (`Native.ECPrivateKey_Generate()`, `Native.ECPrivateKey_Agree` / `_Sign` / `_HpkeOpen`, `Native.KyberKeyPair_Generate()`, `Native.HKDF_DeriveSecrets`, `Native.Aes256GcmSiv_New`); plus rules added for the JVM in 0.4.0 that apply to Java too: Android Keystore (`KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_EC, "AndroidKeyStore")` with the size, curve, block mode and padding read from the `KeyGenParameterSpec.Builder` passed to `initialize` / `init`, inline or through a variable), Tink (`KeyTemplates.get("AES256_GCM")`, `AeadKeyTemplates.X`, `PredefinedAeadParameters.X`; `*Config.register()` and the import count as import-level evidence), OkHttp (`ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)`, `.tlsVersions(TlsVersion.TLS_1_2)`, `.cipherSuites(CipherSuite.TLS_...)`, `CertificatePinner.Builder()`), and certificate-chain validation (`CertPathValidator.getInstance("PKIX")`, `TrustManagerFactory.getInstance`, `X509TrustManager`, `checkServerTrusted`, `KeyStore.getInstance("AndroidCAStore")`) |
|
||||
| Any text file | complete PEM blocks: certificates (parsed for subject, validity and key algorithm), public keys, private keys |
|
||||
| Manifests | `package.json`, `requirements*.txt`, `pyproject.toml`, `pom.xml`, `build.gradle(.kts)`, `go.mod`, `Cargo.toml`: cryptographic libraries that are declared |
|
||||
| Manifests | `package.json`, `requirements*.txt`, `pyproject.toml`, `pom.xml`, `build.gradle(.kts)`, `libs.versions.toml`, `go.mod`, `Cargo.toml`, `Package.swift`, `Podfile`, `*.podspec`: cryptographic libraries that are declared (`pkg:swift/github.com/apple/[email protected]`, `pkg:cocoapods/[email protected]`, `pkg:maven/org.signal/[email protected]`) |
|
||||
|
||||
In Go an unused import does not compile, so an import of a crypto package is evidence of use; the
|
||||
import-level finding is dropped when the same file has a call-level finding that covers it. A blank
|
||||
@@ -40,6 +42,24 @@ guessed. An unused import is only a warning in Rust, so an imported crypto crate
|
||||
(`.sign()`, `.encrypt()`) without their constructor in the same file, macros, and a project's own wrapper
|
||||
types (the file that calls the crate directly is the one reported).
|
||||
|
||||
In Swift and Kotlin (added in 0.4.0, 2026-10-18, after the run on libsignal showed 321 files and 20.5% of the
|
||||
source lines not analyzed at all) the `import` lines decide what a name means, as the `use` lines do in Rust:
|
||||
`SHA256.hash` is CryptoKit only in a file that imports CryptoKit or Crypto, `IdentityKeyPair.generate()` is
|
||||
libsignal only with `import LibSignalClient` (or, inside the library, `import SignalFfi` or the
|
||||
`Sources/LibSignalClient/` target directory, because Swift does not declare the module in the file). A
|
||||
third-party library imported without a recognized call (LibSignalClient, CryptoSwift, Sodium) is reported once
|
||||
as import-level evidence; the system frameworks (CryptoKit, CommonCrypto, Security) are not, since Security
|
||||
is imported for the keychain in almost every app. Certificate-chain validation (`SecTrustEvaluate*`, JCA
|
||||
`CertPathValidator("PKIX")`, `X509TrustManager`, OkHttp pinning) is classified as a classical-signature
|
||||
exposure: the chain is signed by the CA with RSA or ECDSA, which a quantum computer could forge; it is an
|
||||
authentication exposure, not a key exchange, and nothing in that code alone can change it. Swift and Kotlin
|
||||
block comments nest; Swift string interpolation `\( )` and Kotlin templates `${ }` may contain strings and
|
||||
brackets, so the lexer scans them with an explicit stack (iteratively: a file made of `"\(` repeated would be
|
||||
tens of thousands of levels deep). The content of a string, interpolation included, is never a use. Not
|
||||
recognized: methods on values without their constructor in the same file (`generateSignature`,
|
||||
`signalEncrypt`), a project's own wrapper types, a module imported through an Objective-C bridging header,
|
||||
`#if DEBUG` as a scope, Kotlin extension functions over JCA.
|
||||
|
||||
When the algorithm is given by a variable, the tool resolves it only when the file assigns that name
|
||||
exactly once, to a plain string literal, and the name is not a function parameter or loop variable
|
||||
(template literals whose `${...}` parts all resolve this way are also resolved). The finding then
|
||||
@@ -186,30 +206,40 @@ console.log(renderSummary(result));
|
||||
configuration files at run time. Those appear as `unknown` at best, or not at all.
|
||||
- It does not prove that a use is exploitable, reachable or security-relevant. MD5 used as a cache key
|
||||
is reported like MD5 used for signatures; the reason text tells you what to check.
|
||||
- It is static pattern analysis. Supported languages: JavaScript/TypeScript, Python, Java, Go and Rust.
|
||||
Kotlin, Scala, C#, C and C++ files are only checked for PEM blocks. Files that are not UTF-8
|
||||
text (including UTF-16) are treated as binary and counted as not read.
|
||||
- It is static pattern analysis. Supported languages: JavaScript/TypeScript, Python, Java, Go, Rust, Swift
|
||||
and Kotlin. Scala, C#, C, C++ and Objective-C files are only checked for PEM blocks. Files that are not
|
||||
UTF-8 text (including UTF-16) are treated as binary and counted as not read.
|
||||
- It does not execute anything from the scanned tree, and it makes no network requests.
|
||||
|
||||
## Tests
|
||||
|
||||
```
|
||||
node test/proba.mjs # 52 probes: fixtures per language with the exact expected findings
|
||||
node test/control-negativ.mjs # breaks the scanner in a copy, one rule at a time (25 mutations), and
|
||||
node test/proba.mjs # 68 probes: fixtures per language with the exact expected findings
|
||||
node test/control-negativ.mjs # breaks the scanner in a copy, one rule at a time (35 mutations), and
|
||||
# requires the matching probe to fail while the rest of the suite still runs
|
||||
node test/proba-timp.mjs # 8 hostile inputs, each at two sizes: the cost must grow linearly
|
||||
node test/control-negativ-timp.mjs # puts each quadratic form back and requires the cost probe to turn red
|
||||
node test/proba-timp.mjs # 13 hostile inputs, each at two sizes: the cost must grow linearly
|
||||
node test/control-negativ-timp.mjs # puts each quadratic form back (and one Swift comment rescan) and requires the cost probe to turn red
|
||||
node test/echivalenta-0.1.0.mjs # same findings as 0.1.0 (needs the git history; skipped without it); detectors
|
||||
# added after 0.1.0 (Rust, the libsignal Java/Node API) are counted apart, and
|
||||
# a finding that 0.1.0 had and the current version lacks is always a difference
|
||||
# added after 0.1.0 (Rust, Swift, Kotlin, the libsignal Java/Node API, the JVM rules of 0.4.0)
|
||||
# are counted apart, and a finding that 0.1.0 had and the current version lacks is always a difference
|
||||
```
|
||||
|
||||
Measured on 2026-10-18 on the libsignal tree (1,788 files; 596 Rust, 343 Java, 173 TypeScript, 210 Swift, 111 Kotlin): before the
|
||||
additions of that day the inventory returned 450 findings, all in Rust and Python, and zero for Java and TypeScript, because
|
||||
libsignal does not call JCA or `node:crypto` but its own API over the native bridge; Swift and Kotlin (20.5% of the source lines)
|
||||
are not analyzed at all. After: 759 findings (Java 262). The Node side of libsignal itself still returns zero, because its own
|
||||
were not analyzed at all. After the 0.3.0 additions: 759 findings (Java 262). The Node side of libsignal itself still returns zero, because its own
|
||||
tree imports by relative path, not by the package name the detector anchors on.
|
||||
|
||||
Measured later on 2026-10-18, same tree, with the Swift and Kotlin detectors of 0.4.0: all 1,440 source files are analyzed (no
|
||||
source line left out by construction); 980 findings; Swift 0 to 134 in 65 files (84 calls, 50 import-level; 128 in test paths,
|
||||
6 in production: X25519 49, Kyber-1024 8, AES-256-GCM 9, AES-256-CTR 4, HKDF 4, AES-256-GCM-SIV 1, session setup 9); Kotlin 0 to 67
|
||||
in 52 files (22 calls, 2 configurations, 43 import-level; 20 in test paths, 47 in production: X.509 chain validation 7, Kyber-1024 6,
|
||||
X25519 5, XEdDSA 2, HKDF 2, MD5 1); Java 262 to 282 through the JVM rules shared with Kotlin. Eleven files were read by hand against
|
||||
the inventory (six Swift, five Kotlin): eight correct at the first run, three with a false negative each (the static form
|
||||
`Aes256Ctr32.process`, a library source without any import, the Curve25519 bridge calls for signing, agreement and HPKE), all three
|
||||
fixed the same hour with their form added to the fixtures. Of 38 Swift/Kotlin files whose code mentions a cryptographic API name, 8
|
||||
have no finding, each for a stated reason (function definitions, handle wrappers, sender keys, randomness).
|
||||
|
||||
Fixtures mark each expected finding on its own line (`EXPECT: <name> | <class>`), and a probe fails on
|
||||
a missing finding, an extra finding, a wrong line or a wrong class. Negative fixtures cover comments,
|
||||
docstrings, strings that mention crypto APIs, a file without cryptography, algorithms from
|
||||
|
||||
Reference in new issue
Block a user