Skip to content

Commit 24c6910

Browse files
QA fixes: formatting, debug output, and Go version consistency
- Remove debug print statements from scanner.go that corrupted JSON output - Fix Go version in go.mod (1.23.1 → 1.21) to match documented requirements - Apply gofmt formatting to all Go files - Add security note to README recommending latest Go patch version All tests pass. All CLI features verified working.
1 parent 70b6214 commit 24c6910

12 files changed

Lines changed: 168 additions & 172 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ CryptoScan is purpose-built for quantum readiness assessment:
9292

9393
#### Option 1: Build from Source
9494

95-
Requires **Go 1.21+** ([install Go](https://go.dev/dl/))
95+
Requires **Go 1.21+** ([install Go](https://go.dev/dl/)) — always use the latest patch version for security fixes
9696

9797
Copy and paste this entire block:
9898

crypto-samples/crypto_samples.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ func logCryptoOperation() {
228228
// setCryptoMetadata sets metadata labels - should be filtered (string labels)
229229
func setCryptoMetadata() map[string]string {
230230
return map[string]string{
231-
"auth_method": "ed25519",
232-
"encryption_type": "aes-256-gcm",
231+
"auth_method": "ed25519",
232+
"encryption_type": "aes-256-gcm",
233233
"signing_algorithm": "ecdsa-p256",
234234
}
235235
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/csnp/cryptoscan
22

3-
go 1.23.1
3+
go 1.21
44

55
require github.com/spf13/cobra v1.10.2
66

pkg/analyzer/analyzer.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ const (
5151

5252
// FileContext contains analyzed information about a file
5353
type FileContext struct {
54-
Path string
55-
Name string
56-
Extension string
57-
FileType FileType
58-
Language Language
59-
IsTest bool
60-
IsVendor bool
54+
Path string
55+
Name string
56+
Extension string
57+
FileType FileType
58+
Language Language
59+
IsTest bool
60+
IsVendor bool
6161
IsGenerated bool
6262
}
6363

pkg/analyzer/context.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func IsURLOrPath(line, match string) bool {
158158
}
159159
afterMatch := ""
160160
if pos+len(match) < len(line) {
161-
afterMatch = line[pos+len(match):min(len(line), pos+len(match)+20)]
161+
afterMatch = line[pos+len(match) : min(len(line), pos+len(match)+20)]
162162
}
163163

164164
// Path indicators - must have actual path separator
@@ -374,16 +374,16 @@ func determinePurpose(line string, prevLines []string, lang Language) string {
374374

375375
// ContextPatterns contains patterns that indicate specific crypto contexts
376376
var ContextPatterns = map[string]*regexp.Regexp{
377-
"key_generation": regexp.MustCompile(`(?i)(generate|create|new).*key`),
378-
"encryption": regexp.MustCompile(`(?i)(encrypt|cipher|encode)`),
379-
"decryption": regexp.MustCompile(`(?i)(decrypt|decipher|decode)`),
380-
"signing": regexp.MustCompile(`(?i)(sign|signature)`),
381-
"verification": regexp.MustCompile(`(?i)(verify|validate)`),
382-
"hashing": regexp.MustCompile(`(?i)(hash|digest|checksum)`),
383-
"key_exchange": regexp.MustCompile(`(?i)(exchange|agree|handshake|negotiate)`),
384-
"password": regexp.MustCompile(`(?i)(password|passphrase|secret)`),
385-
"certificate": regexp.MustCompile(`(?i)(cert|x509|pem|der)`),
386-
"random": regexp.MustCompile(`(?i)(random|entropy|seed)`),
377+
"key_generation": regexp.MustCompile(`(?i)(generate|create|new).*key`),
378+
"encryption": regexp.MustCompile(`(?i)(encrypt|cipher|encode)`),
379+
"decryption": regexp.MustCompile(`(?i)(decrypt|decipher|decode)`),
380+
"signing": regexp.MustCompile(`(?i)(sign|signature)`),
381+
"verification": regexp.MustCompile(`(?i)(verify|validate)`),
382+
"hashing": regexp.MustCompile(`(?i)(hash|digest|checksum)`),
383+
"key_exchange": regexp.MustCompile(`(?i)(exchange|agree|handshake|negotiate)`),
384+
"password": regexp.MustCompile(`(?i)(password|passphrase|secret)`),
385+
"certificate": regexp.MustCompile(`(?i)(cert|x509|pem|der)`),
386+
"random": regexp.MustCompile(`(?i)(random|entropy|seed)`),
387387
}
388388

389389
// DetectCryptoContext detects what cryptographic operation is happening

pkg/analyzer/dependencies.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ import (
1414

1515
// CryptoLibrary represents a known cryptographic library
1616
type CryptoLibrary struct {
17-
Name string
18-
Package string // Package identifier (npm, pypi, maven, etc.)
19-
Language Language
20-
Algorithms []string // Known algorithms provided
21-
QuantumSafe bool // Whether it provides PQC algorithms
22-
Description string
23-
Migration string // Migration guidance
24-
Docs string // Documentation URL
17+
Name string
18+
Package string // Package identifier (npm, pypi, maven, etc.)
19+
Language Language
20+
Algorithms []string // Known algorithms provided
21+
QuantumSafe bool // Whether it provides PQC algorithms
22+
Description string
23+
Migration string // Migration guidance
24+
Docs string // Documentation URL
2525
}
2626

2727
// DependencyFinding represents a crypto library found in dependencies
2828
type DependencyFinding struct {
29-
Library CryptoLibrary
30-
Version string
31-
File string
32-
Severity types.Severity
33-
Quantum types.QuantumRisk
34-
Description string
35-
Remediation string
29+
Library CryptoLibrary
30+
Version string
31+
File string
32+
Severity types.Severity
33+
Quantum types.QuantumRisk
34+
Description string
35+
Remediation string
3636
}
3737

3838
// KnownCryptoLibraries contains well-known cryptographic libraries
@@ -41,7 +41,7 @@ var KnownCryptoLibraries = []CryptoLibrary{
4141
{Name: "cryptography", Package: "cryptography", Language: LangPython,
4242
Algorithms: []string{"RSA", "ECC", "AES", "ChaCha20"}, QuantumSafe: false,
4343
Description: "Python cryptographic recipes and primitives",
44-
Migration: "Add liboqs-python for PQC support alongside cryptography"},
44+
Migration: "Add liboqs-python for PQC support alongside cryptography"},
4545
{Name: "PyCryptodome", Package: "pycryptodome", Language: LangPython,
4646
Algorithms: []string{"RSA", "ECC", "AES", "DES", "3DES"}, QuantumSafe: false,
4747
Description: "Self-contained Python crypto library"},
@@ -56,7 +56,7 @@ var KnownCryptoLibraries = []CryptoLibrary{
5656
{Name: "crypto-js", Package: "crypto-js", Language: LangJavaScript,
5757
Algorithms: []string{"AES", "DES", "3DES", "SHA", "MD5"}, QuantumSafe: false,
5858
Description: "JavaScript library of crypto standards",
59-
Migration: "Consider using Web Crypto API or node:crypto for better security"},
59+
Migration: "Consider using Web Crypto API or node:crypto for better security"},
6060
{Name: "node-forge", Package: "node-forge", Language: LangJavaScript,
6161
Algorithms: []string{"RSA", "AES", "DES", "SHA", "MD5"}, QuantumSafe: false,
6262
Description: "JavaScript implementation of TLS and crypto"},
@@ -85,7 +85,7 @@ var KnownCryptoLibraries = []CryptoLibrary{
8585
{Name: "Bouncy Castle", Package: "org.bouncycastle", Language: LangJava,
8686
Algorithms: []string{"RSA", "ECC", "AES", "ML-KEM", "ML-DSA"}, QuantumSafe: true,
8787
Description: "Java crypto provider with PQC support in recent versions",
88-
Migration: "Upgrade to BC 1.78+ for ML-KEM and ML-DSA support"},
88+
Migration: "Upgrade to BC 1.78+ for ML-KEM and ML-DSA support"},
8989
{Name: "Google Tink", Package: "com.google.crypto.tink", Language: LangJava,
9090
Algorithms: []string{"AES-GCM", "ECDSA", "Ed25519"}, QuantumSafe: false,
9191
Description: "Multi-language, cross-platform crypto library"},

pkg/analyzer/scoring.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ func GetSecurityLevel(algorithm string, keySize int) *types.SecurityLevel {
365365
}
366366

367367
case strings.Contains(algo, "SHA-256"), strings.Contains(algo, "SHA256"):
368-
level.ClassicalBits = 128 // Collision resistance
368+
level.ClassicalBits = 128 // Collision resistance
369369
level.QuantumSecurityBits = 85 // Grover for collision
370370

371371
case strings.Contains(algo, "SHA-384"), strings.Contains(algo, "SHA384"):

pkg/patterns/matcher_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ func TestMatchHashFunctions(t *testing.T) {
184184
func TestMatchCryptoImports(t *testing.T) {
185185
m := NewMatcher()
186186
tests := []struct {
187-
name string
188-
content string
189-
file string
187+
name string
188+
content string
189+
file string
190190
}{
191191
{"Go crypto", `import "crypto/tls"`, "test.go"},
192192
{"Python cryptography", "from cryptography.fernet import Fernet", "test.py"},
@@ -314,13 +314,13 @@ func TestMatchWithContext(t *testing.T) {
314314
m := NewMatcher()
315315

316316
tests := []struct {
317-
name string
318-
line string
319-
file string
320-
fileCtx *analyzer.FileContext
321-
lineCtx *analyzer.LineContext
322-
expectMatch bool
323-
expectLowConf bool
317+
name string
318+
line string
319+
file string
320+
fileCtx *analyzer.FileContext
321+
lineCtx *analyzer.LineContext
322+
expectMatch bool
323+
expectLowConf bool
324324
}{
325325
{
326326
name: "RSA in code file",

pkg/reporter/cbom.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ func NewCBOMReporter() *CBOMReporter {
2929

3030
// CBOM structures following CycloneDX CBOM format
3131
type cbomReport struct {
32-
BOMFormat string `json:"bomFormat"`
33-
SpecVersion string `json:"specVersion"`
34-
SerialNumber string `json:"serialNumber"`
35-
Version int `json:"version"`
36-
Metadata cbomMetadata `json:"metadata"`
37-
Components []cbomComponent `json:"components"`
38-
Services []cbomService `json:"services,omitempty"`
39-
Dependencies []cbomDependency `json:"dependencies,omitempty"`
32+
BOMFormat string `json:"bomFormat"`
33+
SpecVersion string `json:"specVersion"`
34+
SerialNumber string `json:"serialNumber"`
35+
Version int `json:"version"`
36+
Metadata cbomMetadata `json:"metadata"`
37+
Components []cbomComponent `json:"components"`
38+
Services []cbomService `json:"services,omitempty"`
39+
Dependencies []cbomDependency `json:"dependencies,omitempty"`
4040
}
4141

4242
type cbomMetadata struct {
43-
Timestamp string `json:"timestamp"`
44-
Tools []cbomTool `json:"tools"`
43+
Timestamp string `json:"timestamp"`
44+
Tools []cbomTool `json:"tools"`
4545
Component *cbomComponent `json:"component,omitempty"`
4646
}
4747

@@ -52,21 +52,21 @@ type cbomTool struct {
5252
}
5353

5454
type cbomComponent struct {
55-
Type string `json:"type"`
56-
BOMRef string `json:"bom-ref,omitempty"`
57-
Name string `json:"name"`
58-
Version string `json:"version,omitempty"`
59-
Description string `json:"description,omitempty"`
60-
CryptoProperties *cbomCryptoProperties `json:"cryptoProperties,omitempty"`
61-
Evidence *cbomEvidence `json:"evidence,omitempty"`
55+
Type string `json:"type"`
56+
BOMRef string `json:"bom-ref,omitempty"`
57+
Name string `json:"name"`
58+
Version string `json:"version,omitempty"`
59+
Description string `json:"description,omitempty"`
60+
CryptoProperties *cbomCryptoProperties `json:"cryptoProperties,omitempty"`
61+
Evidence *cbomEvidence `json:"evidence,omitempty"`
6262
}
6363

6464
type cbomCryptoProperties struct {
65-
AssetType string `json:"assetType"`
66-
AlgorithmProperties *cbomAlgorithm `json:"algorithmProperties,omitempty"`
67-
CertificateProperties *cbomCertificate `json:"certificateProperties,omitempty"`
68-
ProtocolProperties *cbomProtocol `json:"protocolProperties,omitempty"`
69-
OID string `json:"oid,omitempty"`
65+
AssetType string `json:"assetType"`
66+
AlgorithmProperties *cbomAlgorithm `json:"algorithmProperties,omitempty"`
67+
CertificateProperties *cbomCertificate `json:"certificateProperties,omitempty"`
68+
ProtocolProperties *cbomProtocol `json:"protocolProperties,omitempty"`
69+
OID string `json:"oid,omitempty"`
7070
}
7171

7272
type cbomAlgorithm struct {
@@ -83,17 +83,17 @@ type cbomAlgorithm struct {
8383
}
8484

8585
type cbomCertificate struct {
86-
SubjectName string `json:"subjectName,omitempty"`
87-
IssuerName string `json:"issuerName,omitempty"`
88-
NotValidBefore string `json:"notValidBefore,omitempty"`
89-
NotValidAfter string `json:"notValidAfter,omitempty"`
86+
SubjectName string `json:"subjectName,omitempty"`
87+
IssuerName string `json:"issuerName,omitempty"`
88+
NotValidBefore string `json:"notValidBefore,omitempty"`
89+
NotValidAfter string `json:"notValidAfter,omitempty"`
9090
SignatureAlgorithmRef string `json:"signatureAlgorithmRef,omitempty"`
9191
}
9292

9393
type cbomProtocol struct {
94-
Type string `json:"type,omitempty"`
95-
Version string `json:"version,omitempty"`
96-
CipherSuites []cbomCipherSuite `json:"cipherSuites,omitempty"`
94+
Type string `json:"type,omitempty"`
95+
Version string `json:"version,omitempty"`
96+
CipherSuites []cbomCipherSuite `json:"cipherSuites,omitempty"`
9797
}
9898

9999
type cbomCipherSuite struct {
@@ -113,8 +113,8 @@ type cbomOccurrence struct {
113113
}
114114

115115
type cbomService struct {
116-
BOMRef string `json:"bom-ref,omitempty"`
117-
Name string `json:"name,omitempty"`
116+
BOMRef string `json:"bom-ref,omitempty"`
117+
Name string `json:"name,omitempty"`
118118
Endpoints []string `json:"endpoints,omitempty"`
119119
}
120120

pkg/reporter/sarif.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ type sarifRule struct {
5555
}
5656

5757
type sarifRuleProperties struct {
58-
Tags []string `json:"tags,omitempty"`
59-
QuantumRisk string `json:"quantumRisk,omitempty"`
60-
Category string `json:"category,omitempty"`
58+
Tags []string `json:"tags,omitempty"`
59+
QuantumRisk string `json:"quantumRisk,omitempty"`
60+
Category string `json:"category,omitempty"`
6161
}
6262

6363
type sarifDefaultConfig struct {
@@ -69,11 +69,11 @@ type sarifMessage struct {
6969
}
7070

7171
type sarifResult struct {
72-
RuleID string `json:"ruleId"`
73-
Level string `json:"level"`
74-
Message sarifMessage `json:"message"`
75-
Locations []sarifLocation `json:"locations"`
76-
Properties sarifResultProps `json:"properties,omitempty"`
72+
RuleID string `json:"ruleId"`
73+
Level string `json:"level"`
74+
Message sarifMessage `json:"message"`
75+
Locations []sarifLocation `json:"locations"`
76+
Properties sarifResultProps `json:"properties,omitempty"`
7777
}
7878

7979
type sarifResultProps struct {

0 commit comments

Comments
 (0)