Skip to content

Commit

Permalink
fix: correct the type of SharedKeyHexDigest (#56)
Browse files Browse the repository at this point in the history
Signed-off-by: Van Hau TRAN <vanonox@gmail.com>

Signed-off-by: Van Hau TRAN <vanonox@gmail.com>
  • Loading branch information
vanonox authored Jan 4, 2023
1 parent b4af590 commit c2b759c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
12 changes: 6 additions & 6 deletions fluent/protocol/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func makePing(hostname string, sharedKey, salt, nonce []byte, creds ...string) (
MessageType: MsgTypePing,
ClientHostname: hostname,
SharedKeySalt: salt,
SharedKeyHexDigest: bytes,
SharedKeyHexDigest: string(bytes),
}

if len(creds) >= 2 {
Expand All @@ -119,7 +119,7 @@ type Ping struct {
MessageType string
ClientHostname string
SharedKeySalt []byte
SharedKeyHexDigest []byte
SharedKeyHexDigest string
Username string
Password string
}
Expand Down Expand Up @@ -149,7 +149,7 @@ func NewPong(authResult bool, reason string, hostname string, sharedKey []byte,
AuthResult: authResult,
Reason: reason,
ServerHostname: hostname,
SharedKeyHexDigest: bytes,
SharedKeyHexDigest: string(bytes),
}

return &p, err
Expand All @@ -164,21 +164,21 @@ type Pong struct {
AuthResult bool
Reason string
ServerHostname string
SharedKeyHexDigest []byte
SharedKeyHexDigest string
}

// ValidatePingDigest validates that the digest contained in the PING message
// is valid for the client hostname (as contained in the PING).
// Returns a non-nil error if validation fails, nil otherwise.
func ValidatePingDigest(p *Ping, key, nonce []byte) error {
return validateDigest(p.SharedKeyHexDigest, key, nonce, p.SharedKeySalt, p.ClientHostname)
return validateDigest([]byte(p.SharedKeyHexDigest), key, nonce, p.SharedKeySalt, p.ClientHostname)
}

// ValidatePongDigest validates that the digest contained in the PONG message
// is valid for the server hostname (as contained in the PONG).
// Returns a non-nil error if validation fails, nil otherwise.
func ValidatePongDigest(p *Pong, key, nonce, salt []byte) error {
return validateDigest(p.SharedKeyHexDigest, key, nonce, salt, p.ServerHostname)
return validateDigest([]byte(p.SharedKeyHexDigest), key, nonce, salt, p.ServerHostname)
}

func validateDigest(received, key, nonce, salt []byte, hostname string) error {
Expand Down
20 changes: 10 additions & 10 deletions fluent/protocol/handshake_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions fluent/protocol/transport_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c2b759c

Please sign in to comment.