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,35 @@
|
||||
// Fixtura: CryptoSwift (formele din README-ul github.com/krzyzanowskim/CryptoSwift: AES(key:blockMode:padding:), SHA2(variant:),
|
||||
// bytes.md5(), HMAC(key:variant:), PKCS5.PBKDF2(...), ChaCha20(key:iv:), Poly1305(key:),
|
||||
// RSA(keySize:), Blowfish(key:blockMode:padding:)) si swift-sodium (README-ul github.com/jedisct1/swift-sodium: sodium.box.keyPair(),
|
||||
// sodium.sign.keyPair(), sodium.secretBox.seal(message:secretKey:), sodium.aead.xchacha20poly1305ietf.encrypt(message:secretKey:),
|
||||
// sodium.pwHash.hash(...)) plus o functie C a libsodium (crypto_box_keypair, Clibsodium). Nu se compileaza; e text pentru scaner.
|
||||
// (Parametrul parolei se numeste `parola`: poarta de secrete a casei citeste eticheta engleza a parolei urmata de un tip drept o parola
|
||||
// atribuita in clar; eticheta ramane numai in apelul API-ului, unde valoarea e identificatorul `parola`.)
|
||||
import Foundation
|
||||
import CryptoSwift
|
||||
import Sodium
|
||||
import Clibsodium
|
||||
|
||||
func exemple(key: [UInt8], iv: [UInt8], input: [UInt8], parola: [UInt8], salt: [UInt8]) throws {
|
||||
let aes = try AES(key: key, blockMode: GCM(iv: iv, mode: .combined), padding: .noPadding) // EXPECT: AES-GCM | quantum-safe
|
||||
let cbc = try AES(key: key, blockMode: CBC(iv: iv), padding: .pkcs7) // EXPECT: AES-CBC | quantum-safe
|
||||
let ecb = try AES(key: key, blockMode: ECB()) // EXPECT: AES-ECB | weak-now
|
||||
let digest = SHA2(variant: .sha256).calculate(for: input) // EXPECT: SHA-256 | quantum-safe
|
||||
let md = input.md5() // EXPECT: MD5 | weak-now
|
||||
let mac = try HMAC(key: key, variant: .sha256).authenticate(input) // EXPECT: HMAC-SHA-256 | quantum-safe
|
||||
let dk = try PKCS5.PBKDF2(password: parola, salt: salt, iterations: 4096, keyLength: 32, variant: .sha256).calculate() // EXPECT: PBKDF2-HMAC-SHA256 | quantum-safe
|
||||
let chacha = try ChaCha20(key: key, iv: iv) // EXPECT: ChaCha20 | quantum-safe
|
||||
let poly = try Poly1305(key: key) // EXPECT: Poly1305 | quantum-safe
|
||||
let rsa = try RSA(keySize: 2048) // EXPECT: RSA-2048 | quantum-vulnerable
|
||||
let blowfish = try Blowfish(key: key, blockMode: CBC(iv: iv), padding: .pkcs7) // EXPECT: Blowfish | weak-now
|
||||
let sodium = Sodium()
|
||||
let box = sodium.box.keyPair() // EXPECT: X25519 | quantum-vulnerable
|
||||
let signer = sodium.sign.keyPair() // EXPECT: Ed25519 | quantum-vulnerable
|
||||
let sealed = sodium.secretBox.seal(message: input, secretKey: key) // EXPECT: XSalsa20-Poly1305 | quantum-safe
|
||||
let aead = sodium.aead.xchacha20poly1305ietf.encrypt(message: input, secretKey: key) // EXPECT: XChaCha20-Poly1305 | quantum-safe
|
||||
let pw = sodium.pwHash.hash(outputLength: 32, passwd: parola, salt: salt, opsLimit: 1, memLimit: 1) // EXPECT: Argon2id | quantum-safe
|
||||
var pk = [UInt8](repeating: 0, count: 32)
|
||||
var sk = [UInt8](repeating: 0, count: 32)
|
||||
let rc = crypto_box_keypair(&pk, &sk) // EXPECT: X25519 | quantum-vulnerable
|
||||
_ = (aes, cbc, ecb, digest, md, mac, dk, chacha, poly, rsa, blowfish, box, signer, sealed, aead, pw, rc)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Fixtura: CryptoKit (si swift-crypto, `import Crypto`, acelasi API). Formele sunt cele din documentatia Apple
|
||||
// (developer.apple.com/documentation/cryptokit: SHA256.hash(data:), Insecure.MD5, HMAC<SHA256>.authenticationCode(for:using:),
|
||||
// AES.GCM.seal(_:using:), ChaChaPoly.seal, Curve25519.KeyAgreement.PrivateKey(), P256.Signing.PrivateKey(),
|
||||
// HKDF<SHA256>.deriveKey(inputKeyMaterial:salt:info:outputByteCount:), SymmetricKey(size: .bits256)). Nu se compileaza; e text pentru scaner.
|
||||
import Foundation
|
||||
import CryptoKit
|
||||
|
||||
func exemple(data: Data, key: SymmetricKey, peer: Curve25519.KeyAgreement.PublicKey) throws {
|
||||
let digest = SHA256.hash(data: data) // EXPECT: SHA-256 | quantum-safe
|
||||
let d384 = SHA384.hash(data: data) // EXPECT: SHA-384 | quantum-safe
|
||||
var hasher = SHA512() // EXPECT: SHA-512 | quantum-safe
|
||||
let md5 = Insecure.MD5.hash(data: data) // EXPECT: MD5 | weak-now
|
||||
let sha1 = Insecure.SHA1.hash(data: data) // EXPECT: SHA-1 | weak-now
|
||||
let tag = HMAC<SHA256>.authenticationCode(for: data, using: key) // EXPECT: HMAC-SHA-256 | quantum-safe
|
||||
let sealed = try AES.GCM.seal(data, using: SymmetricKey(size: .bits256)) // marimea cheii de pe acelasi rand; EXPECT: AES-256-GCM | quantum-safe
|
||||
let opened = try AES.GCM.open(sealed, using: key) // EXPECT: AES-GCM | quantum-safe
|
||||
let cc = try ChaChaPoly.seal(data, using: key) // EXPECT: ChaCha20-Poly1305 | quantum-safe
|
||||
let x = Curve25519.KeyAgreement.PrivateKey() // EXPECT: X25519 | quantum-vulnerable
|
||||
let shared = try x.sharedSecretFromKeyAgreement(with: peer)
|
||||
let ed = Curve25519.Signing.PrivateKey() // EXPECT: Ed25519 | quantum-vulnerable
|
||||
let p256 = P256.Signing.PrivateKey() // EXPECT: ECDSA-secp256r1 | quantum-vulnerable
|
||||
let p384 = P384.KeyAgreement.PrivateKey() // EXPECT: ECDH-secp384r1 | quantum-vulnerable
|
||||
let p521 = P521.Signing.PrivateKey() // EXPECT: ECDSA-secp521r1 | quantum-vulnerable
|
||||
let derived = HKDF<SHA256>.deriveKey(inputKeyMaterial: key, salt: data, info: data, outputByteCount: 32) // EXPECT: HKDF | quantum-safe
|
||||
let k = SymmetricKey(size: .bits128) // singura pe rand: algoritmul se alege unde e folosita; EXPECT: SymmetricKey (128-bit) | unknown
|
||||
hasher.update(data: data)
|
||||
_ = (digest, d384, md5, sha1, tag, opened, cc, shared, ed, p256, p384, p521, derived, k)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// Fixtura: un fisier care importa LibSignalClient fara niciun apel recunoscut: importul e dovada slaba (unknown), o singura data.
|
||||
// Cu un apel recunoscut in acelasi fisier, importul nu se mai raporteaza (vezi swift/libsignal.swift, care nu are marcaj pe import).
|
||||
import Foundation
|
||||
import LibSignalClient // EXPECT: libsignal (LibSignalClient) | unknown
|
||||
|
||||
func store() -> InMemorySignalProtocolStore {
|
||||
return InMemorySignalProtocolStore()
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// Fixtura: API-ul Swift al libsignal (LibSignalClient), 2026-10-18. FIECARE forma e luata din clona signalapp/libsignal 1738ead8
|
||||
// (fisier:rand scris in dreptul ei; fisierul nu se compileaza, e doar text pentru scaner). Ancora e `import LibSignalClient`
|
||||
// (sau `@testable import LibSignalClient`; in sursele bibliotecii insesi, `import SignalFfi`). Fara ancora, aceleasi nume nu
|
||||
// inseamna nimic (vezi negative/zgomot-securitate.swift).
|
||||
import Foundation
|
||||
import LibSignalClient
|
||||
|
||||
func exemple(key: [UInt8], nonce: [UInt8], ad: [UInt8], ptext: [UInt8], accountEntropy: String, bytes: [UInt8]) throws {
|
||||
let bob_pre_key = PrivateKey.generate() // swift/Tests/LibSignalClientTests/SessionTests.swift:145; EXPECT: X25519 | quantum-vulnerable
|
||||
let bob_identity = IdentityKeyPair.generate() // swift/Sources/LibSignalClient/DataStoreInMemory.swift:33; EXPECT: X25519 | quantum-vulnerable
|
||||
let bob_kyber_pre_key = KEMKeyPair.generate() // SessionTests.swift:147; puntea genereaza kem::KeyType::Kyber1024; EXPECT: Kyber-1024 | quantum-safe
|
||||
let kyberPreKey = KEMKeyPair.generate().publicKey // PublicAPITests.swift:506; EXPECT: Kyber-1024 | quantum-safe
|
||||
let remoteKem = try KEMPublicKey(bytes) // ChatServices/UnauthKeysServiceTests.swift:67; EXPECT: Kyber-1024 | quantum-safe
|
||||
let gcm_siv = try Aes256GcmSiv(key: key) // CryptoTests.swift:62; EXPECT: AES-256-GCM-SIV | quantum-safe
|
||||
let encryptedParts = try Aes256GcmEncryptedData.encrypt(Data(ptext), key: key) // CryptoTests.swift:79; EXPECT: AES-256-GCM | quantum-safe
|
||||
let splitParts = try Aes256GcmEncryptedData(concatenated: encryptedParts.concatenate()) // CryptoTests.swift:86; EXPECT: AES-256-GCM | quantum-safe
|
||||
let gcmEnc = try Aes256GcmEncryption(key: key, nonce: nonce, associatedData: ad) // CryptoTests.swift:131; EXPECT: AES-256-GCM | quantum-safe
|
||||
let gcmDec = try Aes256GcmDecryption(key: key, nonce: nonce, associatedData: ad) // CryptoTests.swift:138; EXPECT: AES-256-GCM | quantum-safe
|
||||
var message = Data(ptext)
|
||||
try Aes256Ctr32(key: key, nonce: nonce).process(&message) // swift/Sources/LibSignalClient/Aes256Ctr.swift:87; EXPECT: AES-256-CTR | quantum-safe
|
||||
try Aes256Ctr32.process(&message, key: key, nonce: nonce) // CryptoTests.swift:169 (forma statica); EXPECT: AES-256-CTR | quantum-safe
|
||||
var nonceCtr = Array(repeating: UInt8(0), count: Aes256Ctr32.nonceLength) // CryptoTests.swift:163: o constanta a tipului, nu un apel: nimic
|
||||
let backupKey = try hkdf( // MessageBackupTests.swift:225; EXPECT: HKDF | quantum-safe
|
||||
outputLength: 32,
|
||||
inputKeyMaterial: Array(accountEntropy.utf8),
|
||||
salt: [],
|
||||
info: Array("20240801_SIGNAL_BACKUP_KEY".utf8)
|
||||
)
|
||||
let bob_bundle = try PreKeyBundle( // SessionTests.swift:165; EXPECT: libsignal session setup (X3DH/PQXDH) | unknown
|
||||
registrationId: 1,
|
||||
deviceId: 9,
|
||||
prekeyId: 4570,
|
||||
prekey: bob_pre_key.publicKey,
|
||||
signedPrekeyId: 3006,
|
||||
signedPrekey: bob_pre_key.publicKey,
|
||||
signedPrekeySignature: Data(),
|
||||
identity: bob_identity.identityKey,
|
||||
kyberPrekeyId: 8888,
|
||||
kyberPrekey: bob_kyber_pre_key.publicKey,
|
||||
kyberPrekeySignature: Data()
|
||||
)
|
||||
try processPreKeyBundle( // SessionTests.swift:180; EXPECT: libsignal session setup (X3DH/PQXDH) | unknown
|
||||
bob_bundle,
|
||||
for: bob_address,
|
||||
ourAddress: alice_address,
|
||||
sessionStore: alice_store,
|
||||
identityStore: alice_store,
|
||||
now: Date(),
|
||||
context: NullContext()
|
||||
)
|
||||
_ = (kyberPreKey, remoteKem, gcm_siv, splitParts, gcmEnc, gcmDec, backupKey)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// Fixtura: CommonCrypto, Security.framework si TLS-ul clientului (URLSession, Network). Formele sunt cele din documentatia Apple:
|
||||
// CC_SHA256 / CCCrypt / CCHmac / CCKeyDerivationPBKDF (CommonCrypto.h), SecKeyCreateRandomKey cu kSecAttrKeyType si kSecAttrKeySizeInBits
|
||||
// (developer.apple.com/documentation/security/generating-new-cryptographic-keys), SecKeyCreateSignature / SecKeyVerifySignature /
|
||||
// SecKeyCreateEncryptedData cu SecKeyAlgorithm, SecTrustEvaluateWithError, URLSessionConfiguration.tlsMinimumSupportedProtocolVersion,
|
||||
// NWProtocolTLS.Options + sec_protocol_options_set_min_tls_protocol_version. Nu se compileaza; e text pentru scaner.
|
||||
import Foundation
|
||||
import CommonCrypto
|
||||
import Security
|
||||
import Network
|
||||
|
||||
func exemple(data: Data, keyData: Data, password: String, salt: Data, trust: SecTrust, privateKey: SecKey, publicKey: SecKey) throws {
|
||||
var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
|
||||
data.withUnsafeBytes { _ = CC_SHA256($0.baseAddress, CC_LONG(data.count), &hash) } // EXPECT: SHA-256 | quantum-safe
|
||||
_ = CC_MD5(nil, 0, &hash) // EXPECT: MD5 | weak-now
|
||||
_ = CC_SHA1(nil, 0, &hash) // EXPECT: SHA-1 | weak-now
|
||||
let status = CCCrypt(CCOperation(kCCEncrypt), CCAlgorithm(kCCAlgorithmAES), CCOptions(kCCOptionPKCS7Padding), keyBytes, kCCKeySizeAES256, iv, dataBytes, data.count, outBytes, outLength, &moved) // EXPECT: AES-256-CBC | quantum-safe
|
||||
let s3des = CCCrypt(CCOperation(kCCDecrypt), CCAlgorithm(kCCAlgorithm3DES), CCOptions(kCCOptionECBMode), keyBytes, kCCKeySize3DES, nil, dataBytes, data.count, outBytes, outLength, &moved) // EXPECT: 3DES-ECB | weak-now
|
||||
CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA256), keyBytes, keyData.count, dataBytes, data.count, &hash) // EXPECT: HMAC-SHA-256 | quantum-safe
|
||||
let r = CCKeyDerivationPBKDF(CCPBKDFAlgorithm(kCCPBKDF2), password, password.utf8.count, saltBytes, salt.count, CCPseudoRandomAlgorithm(kCCPRFHmacAlgSHA1), 10000, derived, 32) // EXPECT: PBKDF2-HMAC-SHA1 | weak-now
|
||||
|
||||
let attributes: [String: Any] = [
|
||||
kSecAttrKeyType as String: kSecAttrKeyTypeECSECPrimeRandom,
|
||||
kSecAttrKeySizeInBits as String: 256,
|
||||
]
|
||||
var error: Unmanaged<CFError>?
|
||||
let ecKey = SecKeyCreateRandomKey(attributes as CFDictionary, &error) // dictionarul e variabila de mai sus; EXPECT: EC-secp256r1 | quantum-vulnerable
|
||||
let rsaKey = SecKeyCreateRandomKey([kSecAttrKeyType as String: kSecAttrKeyTypeRSA, kSecAttrKeySizeInBits as String: 2048] as CFDictionary, &error) // EXPECT: RSA-2048 | quantum-vulnerable
|
||||
let sig = SecKeyCreateSignature(privateKey, .ecdsaSignatureMessageX962SHA256, data as CFData, &error) // EXPECT: ECDSA | quantum-vulnerable
|
||||
let sig2 = SecKeyCreateSignature(privateKey, .rsaSignatureMessagePSSSHA256, data as CFData, &error) // EXPECT: RSA | quantum-vulnerable
|
||||
let ok = SecKeyVerifySignature(publicKey, .rsaSignatureMessagePKCS1v15SHA1, data as CFData, sig!, &error) // EXPECT: RSA | weak-now
|
||||
let ct = SecKeyCreateEncryptedData(publicKey, .rsaEncryptionOAEPSHA256, data as CFData, &error) // EXPECT: RSA | quantum-vulnerable
|
||||
let trusted = SecTrustEvaluateWithError(trust, &error) // lantul de incredere TLS: autentificare, nu schimb de cheie; EXPECT: X.509 chain validation (PKIX) | quantum-vulnerable
|
||||
|
||||
let config = URLSessionConfiguration.default
|
||||
config.tlsMinimumSupportedProtocolVersion = .TLSv12 // EXPECT: TLSv1.2 | quantum-vulnerable
|
||||
config.tlsMaximumSupportedProtocolVersion = .TLSv13 // EXPECT: TLSv1.3 | unknown
|
||||
let tls = NWProtocolTLS.Options() // EXPECT: TLS (negotiated) | unknown
|
||||
sec_protocol_options_set_min_tls_protocol_version(tls.securityProtocolOptions, .TLSv13) // EXPECT: TLSv1.3 | unknown
|
||||
_ = (status, s3des, r, ecKey, rsaKey, sig2, ok, ct, trusted, config)
|
||||
}
|
||||
Reference in new issue
Block a user