|
| 1 | +import cpp |
| 2 | +private import experimental.quantum.Language |
| 3 | +private import KnownAlgorithmConstants |
| 4 | +private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumers |
| 5 | +private import experimental.quantum.OpenSSL.AlgorithmInstances.OpenSSLAlgorithmInstanceBase |
| 6 | +private import AlgToAVCFlow |
| 7 | + |
| 8 | +predicate knownOpenSSLConstantToKeyAgreementFamilyType( |
| 9 | + KnownOpenSSLKeyAgreementAlgorithmConstant e, Crypto::TKeyAgreementType type |
| 10 | +) { |
| 11 | + exists(string name | |
| 12 | + name = e.getNormalizedName() and |
| 13 | + ( |
| 14 | + name = "ECDH" and type = Crypto::ECDH() |
| 15 | + or |
| 16 | + name = "DH" and type = Crypto::DH() |
| 17 | + or |
| 18 | + name = "EDH" and type = Crypto::EDH() |
| 19 | + or |
| 20 | + name = "ESDH" and type = Crypto::EDH() |
| 21 | + ) |
| 22 | + ) |
| 23 | +} |
| 24 | + |
| 25 | +class KnownOpenSSLHashConstantAlgorithmInstance extends OpenSSLAlgorithmInstance, |
| 26 | + Crypto::KeyAgreementAlgorithmInstance instanceof KnownOpenSSLKeyAgreementAlgorithmConstant |
| 27 | +{ |
| 28 | + OpenSSLAlgorithmValueConsumer getterCall; |
| 29 | + |
| 30 | + KnownOpenSSLHashConstantAlgorithmInstance() { |
| 31 | + // Two possibilities: |
| 32 | + // 1) The source is a literal and flows to a getter, then we know we have an instance |
| 33 | + // 2) The source is a KnownOpenSSLAlgorithm is call, and we know we have an instance immediately from that |
| 34 | + // Possibility 1: |
| 35 | + this instanceof Literal and |
| 36 | + exists(DataFlow::Node src, DataFlow::Node sink | |
| 37 | + // Sink is an argument to a CipherGetterCall |
| 38 | + sink = getterCall.getInputNode() and |
| 39 | + // Source is `this` |
| 40 | + src.asExpr() = this and |
| 41 | + // This traces to a getter |
| 42 | + KnownOpenSSLAlgorithmToAlgorithmValueConsumerFlow::flow(src, sink) |
| 43 | + ) |
| 44 | + or |
| 45 | + // Possibility 2: |
| 46 | + this instanceof DirectAlgorithmValueConsumer and getterCall = this |
| 47 | + } |
| 48 | + |
| 49 | + override OpenSSLAlgorithmValueConsumer getAVC() { result = getterCall } |
| 50 | + |
| 51 | + override Crypto::TKeyAgreementType getKeyAgreementType() { |
| 52 | + knownOpenSSLConstantToKeyAgreementFamilyType(this, result) |
| 53 | + or |
| 54 | + not knownOpenSSLConstantToKeyAgreementFamilyType(this, _) and |
| 55 | + result = Crypto::OtherKeyAgreementType() |
| 56 | + } |
| 57 | + |
| 58 | + override string getRawKeyAgreementAlgorithmName() { |
| 59 | + result = this.(Literal).getValue().toString() |
| 60 | + or |
| 61 | + result = this.(Call).getTarget().getName() |
| 62 | + } |
| 63 | +} |
0 commit comments