Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't decode secret to hex and base64 #29

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions cmd/wampproto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,7 @@ func Run(args []string) (string, error) {
return wampprotocli.FormatOutputBytes(*c.output, derivedKey)

case c.signCRAChallenge.FullCommand():
craKey, err := wampprotocli.DecodeHexOrBase64(*c.craKey)
if err != nil {
craKey = []byte(*c.craKey)
}
var craKeyBytes = []byte(*c.craKey)

var craChallenge = *c.craChallenge
craChallengeBytes, err := wampprotocli.DecodeHexOrBase64(craChallenge)
Expand All @@ -456,18 +453,15 @@ func Run(args []string) (string, error) {
}

if *c.output == wampprotocli.RawFormat {
return auth.SignCRAChallenge(craChallenge, craKey), nil
return auth.SignCRAChallenge(craChallenge, craKeyBytes), nil
}

signedChallenge := auth.SignCRAChallengeBytes(craChallenge, craKey)
signedChallenge := auth.SignCRAChallengeBytes(craChallenge, craKeyBytes)

return wampprotocli.FormatOutputBytes(*c.output, signedChallenge)

case c.verifyCRASignature.FullCommand():
craKey, err := wampprotocli.DecodeHexOrBase64(*c.verifyCRAKey)
if err != nil {
craKey = []byte(*c.verifyCRAKey)
}
var craKeyBytes = []byte(*c.verifyCRAKey)

var craChallenge = *c.verifyCRAChallenge
craChallengeBytes, err := wampprotocli.DecodeHexOrBase64(craChallenge)
Expand All @@ -477,7 +471,7 @@ func Run(args []string) (string, error) {

craSignature := wampprotocli.EnsureBase64(*c.verifyCRASign)

isVerified := auth.VerifyCRASignature(craSignature, craChallenge, craKey)
isVerified := auth.VerifyCRASignature(craSignature, craChallenge, craKeyBytes)
if !isVerified {
return "", fmt.Errorf("signature verification failed")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/wampproto/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ func TestSignCRAChallenge(t *testing.T) {

func TestVerifyCRASignature(t *testing.T) {
const (
testCRAKey = "6339432b4a757771534b667448736141457530754f70337a4a50512f705070477649456677596730726e773d"
testCRAKey = "test"
testChallenge = "foobar"
testSignature = "AQRrWsTRCROp7o4UUOZPFIa8v3uror6AWSdQ2PaR5jU="
testSignature = "8ad86238123bb29fcca4c6fd117831be6d609ae7dc42f153fa047321489277b0"
)

var command = fmt.Sprintf("wampproto auth cra verify-signature %s %s %s", testChallenge, testSignature, testCRAKey)
Expand Down
Loading