Skip to content

Commit

Permalink
Don't decode secret to hex and base64
Browse files Browse the repository at this point in the history
  • Loading branch information
muzzammilshahid committed Jul 3, 2024
1 parent f1d6e4a commit 5bd5b45
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
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.verifyCRAKey)

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
2 changes: 1 addition & 1 deletion cmd/wampproto/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func TestSignCRAChallenge(t *testing.T) {

func TestVerifyCRASignature(t *testing.T) {
const (
testCRAKey = "6339432b4a757771534b667448736141457530754f70337a4a50512f705070477649456677596730726e773d"
testCRAKey = "c9C+JuwqSKftHsaAEu0uOp3zJPQ/pPpGvIEfwYg0rnw="
testChallenge = "foobar"
testSignature = "AQRrWsTRCROp7o4UUOZPFIa8v3uror6AWSdQ2PaR5jU="
)
Expand Down

0 comments on commit 5bd5b45

Please sign in to comment.