8000 Quantum: OpenSSL signatures by GrosQuildu · Pull Request #19628 · github/codeql · GitHub
[go: up one dir, main page]

Skip to content

Quantum: OpenSSL signatures #19628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 23 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0f874e4
Crypto: Adding initial openssl tests, fixing a bug in hash modeling f…
bdrodes May 22, 2025
10d8504
refactor EVP common classes
GrosQuildu May 23, 2025
8b96ec9
fix openssl outputs
GrosQuildu May 28, 2025
adb9c3b
Update cpp/ql/lib/experimental/quantum/OpenSSL/Operations/OpenSSLOper…
GrosQuildu May 29, 2025
408224a
Apply docs suggestions
GrosQuildu May 29, 2025
0c17cbf
rm one-shot class
GrosQuildu May 29, 2025
c3b384d
init work for openssl signatures
GrosQuildu May 28, 2025
c14fba5
openssl signatures - inputs, outputs and algorithms base
GrosQuildu May 29, 2025
b068833
start on openssl signature tests
GrosQuildu May 29, 2025
310469a
fix super/parent bug, use new SignatureOperationNode
GrosQuildu May 29, 2025
804bd89
flows for key from contexts
GrosQuildu May 29, 2025
02fb52c
make signature tests work for algorithms
GrosQuildu May 29, 2025
16c136e
openssl keygen & tracking of key 8000 s-contexts-algorithms
GrosQuildu May 29, 2025
3672358
signature algorithms are tracked from keys and contexts
GrosQuildu May 30, 2025
54a3e5c
fix cipher tests after adding new stubs
GrosQuildu May 30, 2025
0178bf3
more tests
GrosQuildu May 30, 2025
e618097
signature and keygen tests - expected
GrosQuildu May 30, 2025
c6b2165
change model.qll - KeyArtifactNode getAKnownAlgorithm fix
GrosQuildu May 30, 2025
a70cd60
key sizes basic support
GrosQuildu May 30, 2025
9b87f1f
rm redundant predicate
GrosQuildu May 30, 2025
5dbaf1b
merge main
GrosQuildu Jun 4, 2025
ca67e45
Merge branch 'main' into openssl-signatures
GrosQuildu Jun 4, 2025
30bc605
fix formatting
GrosQuildu Jun 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
openssl signatures - inputs, outputs and algorithms base
  • Loading branch information
GrosQuildu committed May 29, 2025
commit c14fba5edd7f88816c415020c7910957827daf75
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,51 @@ private import experimental.quantum.Language
private import OpenSSLOperationBase
private import experimental.quantum.OpenSSL.CtxFlow as CTXFlow

// TODO: verification
class EVP_Cipher_Initializer extends EVPInitialize {
EVP_Cipher_Initializer() {
// TODO: verification functions


class EVP_Signature_Initializer extends EVPInitialize {
boolean isAlgorithmSpecifiedByKey;
boolean isAlgorithmSpecifiedByCtx;

EVP_Signature_Initializer() {
this.(Call).getTarget().getName() in [
"EVP_DigestSignInit", "EVP_DigestSignInit_ex", "EVP_SignInit", "EVP_SignInit_ex",
"EVP_PKEY_sign_init", "EVP_PKEY_sign_init_ex", "EVP_PKEY_sign_init_ex2",
"EVP_PKEY_sign_message_init"
]
"EVP_DigestSignInit", "EVP_DigestSignInit_ex", "EVP_SignInit", "EVP_SignInit_ex",
"EVP_PKEY_sign_init", "EVP_PKEY_sign_init_ex", "EVP_PKEY_sign_init_ex2",
"EVP_PKEY_sign_message_init"
] and
(
if this.(Call).getTarget().getName().matches("EVP_PKEY_%") then
isAlgorithmSpecifiedByKey = false
else
isAlgorithmSpecifiedByKey = true
)
and
(
if this.(Call).getTarget().getName() in ["EVP_PKEY_sign_init", "EVP_PKEY_sign_init_ex"] then
isAlgorithmSpecifiedByCtx = true
else
isAlgorithmSpecifiedByCtx = false
)
}

/**
* Returns the argument that specifies the algorithm or none if the algorithm is implicit (from context or from key).
* Note that the key may be not provided in the initialization call.
*/
override Expr getAlgorithmArg() {
this.(Call).getTarget().getName() = "EVP_DigestSignInit" and
result = this.(Call).getArgument(1)
or
this.(Call).getTarget().getName() = "EVP_DigestSignInit_ex" and
result = this.(Call).getArgument(1)
or
this.(Call).getTarget().getName() = "EVP_PKEY_sign_init_ex2" and
result = this.(Call).getArgument(1)
or
this.(Call).getTarget().getName() = "EVP_PKEY_sign_message_init" and
result = this.(Call).getArgument(1)
if isAlgorithmSpecifiedByKey = true or isAlgorithmSpecifiedByCtx = true then
none()
else (
this.(Call).getTarget().getName() in ["EVP_PKEY_sign_init_ex2", "EVP_PKEY_sign_message_init"] and
result = this.(Call).getArgument(1)
)
}

/**
* Returns the key argument if there is one.
* They key could be provided in the context or in a later call (final or one-shot).
*/
override Expr getKeyArg() {
this.(Call).getTarget().getName() = "EVP_DigestSignInit" and
result = this.(Call).getArgument(4)
Expand All @@ -38,8 +59,9 @@ class EVP_Cipher_Initializer extends EVPInitialize {
result = this.(Call).getArgument(5)
}

override Expr getIVArg() { none() }

/**
* Signing, verification or unknown.
*/
override Crypto::KeyOperationSubtype getKeyOperationSubtype() {
if this.(Call).getTarget().getName().toLowerCase().matches("%sign%")
then result instanceof Crypto::TSignMode
Expand All @@ -57,13 +79,23 @@ class EVP_Signature_Update_Call extends EVPUpdate {
]
}

/**
* Input is the message to sign.
*/
override Expr getInputArg() { result = this.(Call).getArgument(1) }
}

/**
* Base configuration for all EVP signature operations.
*/
abstract class EVP_Signature_Operation extends EVPOperation, Crypto::KeyOperationInstance {
EVP_Signature_Operation() { this.(Call).getTarget().getName().matches("EVP_%") }

/**
* Signing, verification or unknown.
*/
override Crypto::KeyOperationSubtype getKeyOperationSubtype() {
// TODO: if this KeyOperationSubtype does not match initialization call's KeyOperationSubtype then we found a bug
if this.(Call).getTarget().getName().toLowerCase().matches("%sign%")
then result instanceof Crypto::TSignMode
else
Expand All @@ -72,16 +104,14 @@ abstract class EVP_Signature_Operation extends EVPOperation, Crypto::KeyOperatio
else result instanceof Crypto::TUnknownKeyOperationMode
}

override Expr getOutputArg() { result = this.(Call).getArgument(1) }

override Crypto::ConsumerInputDataFlowNode getNonceConsumer() {
// this.getInitCall().getIVArg() = result.asExpr()
// TODO: some signing operations may have explicit nonce generators
none()
}

override Crypto::ConsumerInputDataFlowNode getKeyConsumer() {
this.getInitCall().getKeyArg() = result.asExpr()
// todo: or track to the EVP_PKEY_CTX_new
result = DataFlow::exprNode(this.getInitCall().getKeyArg())
// TODO: or track to the EVP_PKEY_CTX_new
}

override Crypto::ArtifactOutputDataFlowNode getOutputArtifact() {
Expand All @@ -93,9 +123,17 @@ abstract class EVP_Signature_Operation extends EVPOperation, Crypto::KeyOperatio
}
}

class EVP_Signature_Call extends EVPOneShot, EVP_Signature_Operation {
class EVP_Signature_Call extends EVPOperation, EVP_Signature_Operation {
EVP_Signature_Call() { this.(Call).getTarget().getName() in ["EVP_DigestSign", "EVP_PKEY_sign"] }

/**
* Output is the signature.
*/
override Expr getOutputArg() { result = this.(Call).getArgument(1) }

/**
* Input is the message to sign.
*/
override Expr getInputArg() { result = this.(Call).getArgument(3) }
}

Expand All @@ -105,4 +143,14 @@ class EVP_Signature_Final_Call extends EVPFinal, EVP_Signature_Operation {
"EVP_DigestSignFinal", "EVP_SignFinal_ex", "EVP_SignFinal", "EVP_PKEY_sign_message_final"
]
}

/**
* Output is the signature.
*/
override Expr getOutputArg() {
if this.(Call).getTarget().getName() = "EVP_SignFinal_ex" then
result = this.(Call).getArgument(2)
else
result = this.(Call).getArgument(1)
}
}
0