Skip to content

Commit

Permalink
correct typo
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptix committed Mar 24, 2021
1 parent 1bf1443 commit 5bdc985
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
14 changes: 7 additions & 7 deletions internal/signinwithssb/challenges.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ import (
const challengeLength = 32

func DecodeChallengeString(c string) ([]byte, error) {
challangeBytes, err := base64.URLEncoding.DecodeString(c)
ChallengeBytes, err := base64.URLEncoding.DecodeString(c)
if err != nil {
return nil, fmt.Errorf("invalid challenge encoding: %w", err)
}

if n := len(challangeBytes); n != challengeLength {
if n := len(ChallengeBytes); n != challengeLength {
return nil, fmt.Errorf("invalid challenge length: expected %d but got %d", challengeLength, n)
}

return challangeBytes, nil
return ChallengeBytes, nil
}

func GenerateChallenge() string {
Expand All @@ -37,8 +37,8 @@ func GenerateChallenge() string {
type ClientRequest struct {
ClientID, ServerID refs.FeedRef

ClientChallange string
ServerChallange string
ClientChallenge string
ServerChallenge string
}

// recreate the signed message
Expand All @@ -49,9 +49,9 @@ func (cr ClientRequest) createMessage() []byte {
msg.WriteString(":")
msg.WriteString(cr.ClientID.Ref())
msg.WriteString(":")
msg.WriteString(cr.ServerChallange)
msg.WriteString(cr.ServerChallenge)
msg.WriteString(":")
msg.WriteString(cr.ClientChallange)
msg.WriteString(cr.ClientChallenge)
return msg.Bytes()
}

Expand Down
4 changes: 2 additions & 2 deletions internal/signinwithssb/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func TestClientRequestString(t *testing.T) {
req.ServerID = server
req.ClientID = client

req.ServerChallange = "fooo"
req.ClientChallange = "barr"
req.ServerChallenge = "fooo"
req.ClientChallenge = "barr"

want := "=http-auth-sign-in:@AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE=.test:@AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI=.test:fooo:barr"

Expand Down
6 changes: 3 additions & 3 deletions roomdb/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ type AuthFallbackService interface {
// Remove(pwid)
}

// AuthWithSSBService defines utility functions for the challange/response system of sign-in with ssb
// They are particualarly of service to check valid sessions (after the client provided a solution for a challange)
// AuthWithSSBService defines utility functions for the Challenge/response system of sign-in with ssb
// They are particualarly of service to check valid sessions (after the client provided a solution for a Challenge)
// And to log out valid sessions from the clients device.
type AuthWithSSBService interface {

// CreateToken is used to generate a token that is stored inside a cookie.
// It is used after a valid solution for a challange was provided.
// It is used after a valid solution for a Challenge was provided.
CreateToken(ctx context.Context, memberID int64) (string, error)

// CheckToken checks if the passed token is still valid and returns the member id if so
Expand Down
2 changes: 1 addition & 1 deletion roomdb/sqlite/auth_withssb.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type AuthWithSSB struct {
const siwssbTokenLength = 32

// CreateToken is used to generate a token that is stored inside a cookie.
// It is used after a valid solution for a challange was provided.
// It is used after a valid solution for a Challenge was provided.
func (a AuthWithSSB) CreateToken(ctx context.Context, memberID int64) (string, error) {

var newToken = models.SIWSSBSession{
Expand Down
10 changes: 5 additions & 5 deletions web/handlers/auth/withssb.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ func (h WithSSBHandler) login(w http.ResponseWriter, req *http.Request) (interfa
var clientReq signinwithssb.ClientRequest
clientReq.ServerID = h.roomID // fll inthe server

// validate and update client challange
// validate and update client Challenge
cc := queryParams.Get("cc")
if _, err := signinwithssb.DecodeChallengeString(cc); err != nil {
return nil, weberrors.ErrBadRequest{Where: "client-challange", Details: err}
return nil, weberrors.ErrBadRequest{Where: "client-Challenge", Details: err}
}
clientReq.ClientChallange = cc
clientReq.ClientChallenge = cc

// check who the client is
var client refs.FeedRef
Expand Down Expand Up @@ -106,9 +106,9 @@ func (h WithSSBHandler) login(w http.ResponseWriter, req *http.Request) (interfa
return nil, weberrors.ErrForbidden{Details: fmt.Errorf("sign-in: client not connected to room")}
}

// roll a challange from the server
// roll a Challenge from the server
sc := signinwithssb.GenerateChallenge()
clientReq.ServerChallange = sc
clientReq.ServerChallenge = sc

ctx, cancel := context.WithTimeout(req.Context(), 1*time.Minute)
defer cancel()
Expand Down
12 changes: 6 additions & 6 deletions web/handlers/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,15 @@ func TestAuthWithSSBHasClient(t *testing.T) {

r.Len(args, 2, "expected two args")

serverChallange, ok := args[0].(string)
serverChallenge, ok := args[0].(string)
r.True(ok, "argument[0] is not a string: %T", args[0])
a.NotEqual("", serverChallange)
a.NotEqual("", serverChallenge)
// update the challenge
req.ServerChallange = serverChallange
req.ServerChallenge = serverChallenge

clientChallange, ok := args[1].(string)
clientChallenge, ok := args[1].(string)
r.True(ok, "argument[1] is not a string: %T", args[1])
a.Equal(req.ClientChallange, clientChallange)
a.Equal(req.ClientChallenge, clientChallenge)

strptr, ok := ret.(*string)
r.True(ok, "return is not a string pointer: %T", ret)
Expand All @@ -291,7 +291,7 @@ func TestAuthWithSSBHasClient(t *testing.T) {

cc := signinwithssb.GenerateChallenge()
// update the challenge
req.ClientChallange = cc
req.ClientChallenge = cc

// prepare the url
signInStartURL := web.NewURLTo(ts.Router)(router.AuthWithSSBSignIn,
Expand Down

0 comments on commit 5bdc985

Please sign in to comment.