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

Commit a714863

Browse files
committed
Merge branch 'standard-lib-pt-6' into stdlib-339-340-342-346-347
2 parents 61a0cfa + 3a7406b commit a714863

File tree

11 files changed

+410
-12
lines changed

11 files changed

+410
-12
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import semmle.go.frameworks.stdlib.Fmt
1616
import semmle.go.frameworks.stdlib.ContainerHeap
1717
import semmle.go.frameworks.stdlib.ContainerList
1818
import semmle.go.frameworks.stdlib.ContainerRing
19+
import semmle.go.frameworks.stdlib.Crypto
20+
import semmle.go.frameworks.stdlib.CryptoCipher
21+
import semmle.go.frameworks.stdlib.CryptoRsa
22+
import semmle.go.frameworks.stdlib.CryptoTls
23+
import semmle.go.frameworks.stdlib.CryptoX509
1924
import semmle.go.frameworks.stdlib.Mime
2025
import semmle.go.frameworks.stdlib.MimeMultipart
2126
import semmle.go.frameworks.stdlib.MimeQuotedprintable
@@ -239,15 +244,3 @@ module URL {
239244
}
240245
}
241246
}
242-
243-
/** Provides models of some functions in the `crypto/cipher` package. */
244-
module CryptoCipher {
245-
private class AeadOpenFunction extends TaintTracking::FunctionModel, Method {
246-
AeadOpenFunction() { this.hasQualifiedName("crypto/cipher", "AEAD", "Open") }
247-
248-
override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) {
249-
inp.isParameter(2) and
250-
outp.isResult(0)
251-
}
252-
}
253-
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `crypto` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `crypto` package. */
8+
module Crypto {
9+
private class MethodModels extends TaintTracking::FunctionModel, Method {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
MethodModels() {
14+
// signature: func (Decrypter).Decrypt(rand io.Reader, msg []byte, opts DecrypterOpts) (plaintext []byte, err error)
15+
this.implements("crypto", "Decrypter", "Decrypt") and
16+
(inp.isParameter(1) and outp.isResult(0))
17+
}
18+
19+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
20+
input = inp and output = outp
21+
}
22+
}
23+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `crypto/cipher` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `crypto/cipher` package. */
8+
module CryptoCipher {
9+
private class MethodModels extends TaintTracking::FunctionModel, Method {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
MethodModels() {
14+
// signature: func (Block).Decrypt(dst []byte, src []byte)
15+
this.implements("crypto/cipher", "Block", "Decrypt") and
16+
(inp.isParameter(1) and outp.isParameter(0))
17+
or
18+
// signature: func (AEAD).Open(dst []byte, nonce []byte, ciphertext []byte, additionalData []byte) ([]byte, error)
19+
this.implements("crypto/cipher", "AEAD", "Open") and
20+
(
21+
inp.isParameter(2) and
22+
(outp.isParameter(0) or outp.isResult(0))
23+
)
24+
}
25+
26+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
27+
input = inp and output = outp
28+
}
29+
}
30+
}
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+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `crypto/tls` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `crypto/tls` package. */
8+
module CryptoTls {
9+
private class FunctionModels extends TaintTracking::FunctionModel {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
FunctionModels() {
14+
// signature: func Client(conn net.Conn, config *Config) *Conn
15+
hasQualifiedName("crypto/tls", "Client") and
16+
(
17+
inp.isParameter(0) and outp.isResult()
18+
or
19+
inp.isResult() and outp.isParameter(0)
20+
)
21+
or
22+
// signature: func NewListener(inner net.Listener, config *Config) net.Listener
23+
hasQualifiedName("crypto/tls", "NewListener") and
24+
(inp.isParameter(0) and outp.isResult())
25+
or
26+
// signature: func Server(conn net.Conn, config *Config) *Conn
27+
hasQualifiedName("crypto/tls", "Server") and
28+
(
29+
inp.isParameter(0) and outp.isResult()
30+
or
31+
inp.isResult() and outp.isParameter(0)
32+
)
33+
}
34+
35+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
36+
input = inp and output = outp
37+
}
38+
}
39+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `crypto/x509` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `crypto/x509` package. */
8+
module CryptoX509 {
9+
private class FunctionModels extends TaintTracking::FunctionModel {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
FunctionModels() {
14+
// signature: func DecryptPEMBlock(b *encoding/pem.Block, password []byte) ([]byte, error)
15+
hasQualifiedName("crypto/x509", "DecryptPEMBlock") and
16+
(inp.isParameter(0) and outp.isResult(0))
17+
}
18+
19+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
20+
input = inp and output = outp
21+
}
22+
}
23+
}

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

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

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

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

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)