Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 5e0e3cc

Browse files
committed
Add taint-tracking for crypto/rsa package
1 parent 742319c commit 5e0e3cc

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

ql/src/semmle/go/frameworks/Stdlib.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import semmle.go.frameworks.stdlib.CompressZlib
1515
import semmle.go.frameworks.stdlib.Fmt
1616
import semmle.go.frameworks.stdlib.Crypto
1717
import semmle.go.frameworks.stdlib.CryptoCipher
18+
import semmle.go.frameworks.stdlib.CryptoRsa
1819
import semmle.go.frameworks.stdlib.Mime
1920
import semmle.go.frameworks.stdlib.MimeMultipart
2021
import semmle.go.frameworks.stdlib.MimeQuotedprintable
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `crypto/rsa` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `crypto/rsa` package. */
8+
module CryptoRsa {
9+
private class FunctionModels extends TaintTracking::FunctionModel {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
FunctionModels() {
14+
// signature: func DecryptOAEP(hash hash.Hash, random io.Reader, priv *PrivateKey, ciphertext []byte, label []byte) ([]byte, error)
15+
hasQualifiedName("crypto/rsa", "DecryptOAEP") and
16+
(inp.isParameter(3) and outp.isResult(0))
17+
or
18+
// signature: func DecryptPKCS1v15(rand io.Reader, priv *PrivateKey, ciphertext []byte) ([]byte, error)
19+
hasQualifiedName("crypto/rsa", "DecryptPKCS1v15") and
20+
(inp.isParameter(2) and outp.isResult(0))
21+
}
22+
23+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
24+
input = inp and output = outp
25+
}
26+
}
27+
28+
private class MethodModels extends TaintTracking::FunctionModel, Method {
29+
FunctionInput inp;
30+
FunctionOutput outp;
31+
32+
MethodModels() {
33+
// signature: func (*PrivateKey).Decrypt(rand io.Reader, ciphertext []byte, opts crypto.DecrypterOpts) (plaintext []byte, err error)
34+
this.hasQualifiedName("crypto/rsa", "PrivateKey", "Decrypt") and
35+
(inp.isParameter(1) and outp.isResult(0))
36+
}
37+
38+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
39+
input = inp and output = outp
40+
}
41+
}
42+
}

ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/CryptoRsa.go

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)