Skip to content

Commit

Permalink
addresses should be case insensitive - delegated auth
Browse files Browse the repository at this point in the history
  • Loading branch information
cypherhat committed Feb 19, 2019
1 parent 5c42f96 commit 56a0650
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions path_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (b *backend) delegatedLogin(ctx context.Context, req *logical.Request, data
return nil, err
}
trustee := claims["iss"].(string)
if !contains(config.TrusteeList, trustee) {
if !containsIgnoreCase(config.TrusteeList, trustee) {
return nil, fmt.Errorf("this %s address is not trusted", trustee)
}
delegateJWT, ok := claims["delegate"].(string)
Expand Down Expand Up @@ -522,7 +522,7 @@ func (b *backend) verifyTrustee(ctx context.Context, rawToken string, trustees [
if !ok {
return nil, fmt.Errorf("JWT has no issuer - iss")
}
if !contains(trustees, ethereumAddress) {
if !containsIgnoreCase(trustees, ethereumAddress) {
return nil, fmt.Errorf("we don't trust this issuer: %s", ethereumAddress)
}
jti, ok := unverifiedJwt["jti"].(string)
Expand All @@ -546,7 +546,7 @@ func (b *backend) verifyTrustee(ctx context.Context, rawToken string, trustees [
}
address := crypto.PubkeyToAddress(*pubkey)

if ethereumAddress == address.Hex() {
if strings.ToUpper(ethereumAddress) == strings.ToUpper(address.Hex()) {
validateJwt, err := jwt.Parse(token, func(t *jwt.Token) (interface{}, error) {
return pubkey, nil
})
Expand All @@ -557,4 +557,4 @@ func (b *backend) verifyTrustee(ctx context.Context, rawToken string, trustees [
return claims, claims.Valid()
}
return nil, fmt.Errorf("Error verifying token")
}
}
5 changes: 3 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"strings"

"github.com/ethereum/go-ethereum/crypto"
)
Expand All @@ -13,9 +14,9 @@ func hashKeccak256(data string) []byte {
return hash
}

func contains(stringSlice []string, searchString string) bool {
func containsIgnoreCase(stringSlice []string, searchString string) bool {
for _, value := range stringSlice {
if value == searchString {
if strings.ToUpper(value) == strings.ToUpper(searchString) {
return true
}
}
Expand Down

0 comments on commit 56a0650

Please sign in to comment.