Repository navigation
[Feat] Sui Core changes - #19193
[Feat] Sui Core changes#19193
Conversation
|
|
||
| // newFrom creates a new Account from a provided random reader | ||
| func newFrom(reader io.Reader) (Key, error) { | ||
| pub, priv, err := ed25519.GenerateKey(reader) |
Check failure
Code scanning / CodeQL
Use of insufficient randomness as the key of a cryptographic algorithm
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 year ago
The optimal fix is to ensure that all functions using insecure randomness (math/rand) for key generation, such as MustNewInsecure, and helper utilities like NewRandReaderFromSeed, are only compiled as part of test code. In Go, this is typically done by moving such code into files with the _test.go suffix or files gated by //go:build !production && test (or similar) build tags. The goals are:
- To prevent the accidental use of test-only, insecure RNGs in production code.
- To clarify to static analysis tools that insecure RNG usage is safe, as it is test-only and not used in mainline binaries.
- Not to change existing public APIs or test logic, just to make it impossible to use these methods in real deployments.
The most effective way here is:
- Move all code that uses
math/randas a cryptographically insecure test utility (e.g.,NewRandReaderFromSeedinkeystest/seedable_rand_reader.go) into a file namedseedable_rand_reader_test.go, or gate it with a//go:buildtest-only build constraint. - Similarly, ensure instantiation of test keys with these insecure sources (e.g.,
MustNewInsecure) is contained to test/fixture files, not main code.
This makes the intention and constraints explicit, avoids tainting the main codebase with insecure paths, and resolves the static analysis finding correctly.
| @@ -40,6 +40,8 @@ | ||
| return newFrom(cryptorand.Reader) | ||
| } | ||
|
|
||
| //go:build testutil | ||
|
|
||
| // MustNewInsecure returns an Account if no error | ||
| func MustNewInsecure(reader io.Reader) Key { | ||
| key, err := newFrom(reader) |
| @@ -1,3 +1,5 @@ | ||
| //go:build testutil | ||
|
|
||
| package keystest | ||
|
|
||
| import ( |
| } | ||
|
|
||
| // newFrom creates a new Account from a provided random reader | ||
| func newFrom(reader io.Reader) (Key, error) { |
There was a problem hiding this comment.
looking at the issue raised below, do we use this function in production or only in test?
|
You could consider updating |
|


Requires
Supports
imported changes from: #17618