Skip to content

Commit 0178bf3

Browse files
committed
more tests
1 parent 54a3e5c commit 0178bf3

File tree

8 files changed

+51
-26
lines changed

8 files changed

+51
-26
lines changed

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/OpenSSLAlgorithmInstances.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ import PaddingAlgorithmInstance
44
import BlockAlgorithmInstance
55
import HashAlgorithmInstance
66
import EllipticCurveAlgorithmInstance
7+
import SignatureAlgorithmInstance

cpp/ql/lib/experimental/quantum/OpenSSL/Operations/EVPKeyGenOperation.qll

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@ private import OpenSSLOperationBase
44
private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumers
55
private import semmle.code.cpp.dataflow.new.DataFlow
66

7-
87
class EVPKeyGenInitialize extends EVPInitialize {
9-
EVPKeyGenInitialize() { this.(Call).getTarget().getName() in [
10-
"EVP_PKEY_keygen_init", "EVP_PKEY_paramgen_init"
11-
]
12-
}
13-
14-
override Expr getAlgorithmArg() {
15-
result = getAlgorithmFromCtx(this.getContextArg())
16-
}
8+
EVPKeyGenInitialize() {
9+
this.(Call).getTarget().getName() in [
10+
"EVP_PKEY_keygen_init",
11+
"EVP_PKEY_paramgen_init"
12+
]
13+
}
14+
15+
override Expr getAlgorithmArg() { result = getAlgorithmFromCtx(this.getContextArg()) }
1716
}
1817

1918
class EVPKeyGenOperation extends EVPOperation, Crypto::KeyGenerationOperationInstance {
20-
EVPKeyGenOperation() { this.(Call).getTarget().getName() in [
21-
"EVP_PKEY_generate", "EVP_PKEY_paramgen", "EVP_PKEY_keygen", "EVP_PKEY_Q_keygen"
22-
]
23-
}
19+
EVPKeyGenOperation() {
20+
this.(Call).getTarget().getName() in [
21+
"EVP_PKEY_generate", "EVP_PKEY_keygen", "EVP_PKEY_Q_keygen", "EVP_PKEY_paramgen"
22+
// TODO: "EVP_PKEY_paramgen"
23+
]
24+
}
2425

2526
override Expr getAlgorithmArg() {
26-
if this.(Call).getTarget().getName() = "EVP_PKEY_Q_keygen" then
27-
result = this.(Call).getArgument(0)
28-
else
29-
result = EVPOperation.super.getAlgorithmArg()
30-
}
27+
if this.(Call).getTarget().getName() = "EVP_PKEY_Q_keygen"
28+
then result = this.(Call).getArgument(0)
29+
else result = EVPOperation.super.getAlgorithmArg()
30+
}
3131

3232
override Crypto::KeyArtifactType getOutputKeyType() { result = Crypto::TAsymmetricKeyType() }
3333

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import cpp
2+
import experimental.quantum.Language
3+
import experimental.quantum.OpenSSL.Operations.EVPKeyGenOperation
4+
5+
from EVPKeyGenOperation keyGen, Crypto::KeyArtifactNode key
6+
where keyGen = key.asElement().(Crypto::KeyArtifactOutputInstance).getCreator()
7+
select keyGen, key, key.getAKnownAlgorithm()
8+
// TODO: add key.getSourceNode() when the test has any explicit key source (now we always generate new keys)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import cpp
2+
import experimental.quantum.Language
3+
4+
from Crypto::KeyGenerationOperationNode n
5+
select n, n.getOutputKeyArtifact(), n.getAnAlgorithmOrGenericSource()

cpp/ql/test/experimental/library-tests/quantum/openssl/signature/openssl_signature.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ static EVP_PKEY* generate_dsa_key(void) {
571571
EVP_PKEY *params = NULL, *key = NULL;
572572

573573
/* Generate parameters first */
574-
param_ctx = EVP_PKEY_CTX_new_from_name(NULL, "DSA", NULL);
574+
param_ctx = EVP_PKEY_CTX_new_from_name(NULL, "dsa", NULL);
575575
if (!param_ctx) return NULL;
576576

577577
if (EVP_PKEY_paramgen_init(param_ctx) <= 0 ||
@@ -764,7 +764,7 @@ int test_signature_apis_dsa(void) {
764764
}
765765

766766
/* Test generic APIs */
767-
if (!test_signature_apis(key, md, no_parameter_setter, "DSA")) {
767+
if (!test_signature_apis(key, md, no_parameter_setter, "dsa")) {
768768
success = 0;
769769
}
770770

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import cpp
2+
import experimental.quantum.Language
3+
4+
from Crypto::SignatureOperationNode op, Crypto::KeyArtifactNode key
5+
where op.getAKey() = key
6+
select op, key
7+
// TODO: should key.getAKnownAlgorithm() return a value?
8+
// TODO: add key.getSourceNode() when the test has any explicit key source (now we always generate new keys)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import cpp
2+
import experimental.quantum.Language
3+
4+
from Crypto::SignatureOperationNode n, Crypto::MessageArtifactNode m
5+
where n.getAnInputArtifact() = m
6+
select n, m, m.getSourceNode()
7+
// TODO: we miss call to EVP_PKEY_sign, because getSourceNode does not find the `digest` we sign
8+
// TODO: we miss message generated with `EVP_SignUpdate(md_ctx, message+1, message_len-1)`, because getSourceNode does not find it
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import cpp
22
import experimental.quantum.Language
3-
import experimental.quantum.OpenSSL.AlgorithmValueConsumers.PKeyAlgorithmValueConsumer
4-
import experimental.quantum.OpenSSL.CtxFlow
5-
import experimental.quantum.OpenSSL.Operations.EVPSignatureOperation
6-
import experimental.quantum.OpenSSL.Operations.OpenSSLOperationBase
73

84
from Crypto::SignatureOperationNode n
95
select n, n.getAnInputArtifact(), n.getAnOutputArtifact(), n.getAKey(),
106
n.getAnAlgorithmOrGenericSource(), n.getKeyOperationSubtype()
11-
// , n.getASignatureArtifact()
12-
7+
// TODO: add n.getASignatureArtifact() for verification operations

0 commit comments

Comments
 (0)