Skip to content

Commit

Permalink
Refactor security logger
Browse files Browse the repository at this point in the history
Customize security logger to avoid logging secret values.
* Add a new safe string printer.
* Only log the safe params in send().
* Bump codeql[0].

[0]: https://github.blog/changelog/2022-04-27-code-scanning-deprecation-of-codeql-action-v1/

Signed-off-by: SuperQ <superq@gmail.com>
  • Loading branch information
SuperQ committed Dec 15, 2022
1 parent 9a70609 commit f2ab7d6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
# Override language selection by uncommenting this and choosing your languages
# with:
# languages: go, javascript, csharp, python, cpp, java

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -51,4 +51,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
2 changes: 1 addition & 1 deletion marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func (x *GoSNMP) send(packetOut *SnmpPacket, wait bool) (result *SnmpPacket, err
}

if result.Version == Version3 {
x.Logger.Printf("SEND STORE SECURITY PARAMS from result: %+v", result)
x.Logger.Printf("SEND STORE SECURITY PARAMS from result: %s", result.SecurityParameters.String())
err = x.storeSecurityParameters(result)

if result.PDUType == Report && len(result.Variables) == 1 {
Expand Down
1 change: 1 addition & 0 deletions v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type SnmpV3SecurityParameters interface {
Log()
Copy() SnmpV3SecurityParameters
Description() string
String() string
validate(flags SnmpV3MsgFlags) error
init(log Logger) error
initPacket(packet *SnmpPacket) error
Expand Down
18 changes: 17 additions & 1 deletion v3_usm.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,27 @@ func (sp *UsmSecurityParameters) Description() string {
return sb.String()
}

// String returns a logging safe (no secrets) string of the UsmSecurityParameters
func (sp *UsmSecurityParameters) String() string {
sp.mu.Lock()
defer sp.mu.Unlock()
return fmt.Sprintf("AuthoritativeEngineID:%s, AuthoritativeEngineBoots:%d, AuthoritativeEngineTimes:%d, UserName:%s, AuthenticationParameters:%s, PrivacyParameters:%v, AuthenticationProtocol:%s, PrivacyProtocol:%s",
sp.AuthoritativeEngineID,
sp.AuthoritativeEngineBoots,
sp.AuthoritativeEngineTime,
sp.UserName,
sp.AuthenticationParameters,
sp.PrivacyParameters,
sp.AuthenticationProtocol,
sp.PrivacyProtocol,
)
}

// Log logs security paramater information to the provided GoSNMP Logger
func (sp *UsmSecurityParameters) Log() {
sp.mu.Lock()
defer sp.mu.Unlock()
sp.Logger.Printf("SECURITY PARAMETERS:%+v", sp)
sp.Logger.Printf("SECURITY PARAMS: %s", sp.String())
}

// Copy method for UsmSecurityParameters used to copy a SnmpV3SecurityParameters without knowing it's implementation
Expand Down

0 comments on commit f2ab7d6

Please sign in to comment.