github.com/TykTechnologies/tyk/signature_validator
No package summary is available.
Package
Files: 2. Third party imports: 0. Imports from organisation: 0. Tests: 0. Benchmarks: 0.
Types
Hasher
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
type Hasher interface {
Name() string
Hash(token string, sharedSecret string, timeStamp int64) []byte
}
MasheryMd5sum
This type doesn't have documentation.
type MasheryMd5sum struct{}
MasherySha256Sum
This type doesn't have documentation.
type MasherySha256Sum struct{}
SignatureValidator
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
| h |
|
No comment on field. |
type SignatureValidator struct {
h Hasher
}
Validator
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
type Validator interface {
Init(hasherName string) error
Validate(attempt, actual string, allowedClockSkew int64) error
}
Functions
func (*SignatureValidator) Init
func (v *SignatureValidator) Init(hasherName string) error {
switch hasherName {
case "MasherySHA256":
v.h = MasherySha256Sum{}
case "MasheryMD5":
v.h = MasheryMd5sum{}
default:
return errors.New(fmt.Sprintf("unsupported hasher type (%s)", hasherName))
}
return nil
}
Cognitive complexity: 6, Cyclomatic complexity: 4
func (MasheryMd5sum) Hash
func (m MasheryMd5sum) Hash(token string, sharedSecret string, timeStamp int64) []byte {
signature := md5.Sum([]byte(token + sharedSecret + strconv.FormatInt(timeStamp, 10)))
return signature[:]
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (MasheryMd5sum) Name
func (m MasheryMd5sum) Name() string {
return "MasheryMD5"
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (MasherySha256Sum) Hash
func (m MasherySha256Sum) Hash(token string, sharedSecret string, timeStamp int64) []byte {
signature := sha256.Sum256([]byte(token + sharedSecret + strconv.FormatInt(timeStamp, 10)))
return signature[:]
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (MasherySha256Sum) Name
func (m MasherySha256Sum) Name() string {
return "MasherySHA256"
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (SignatureValidator) Validate
func (v SignatureValidator) Validate(signature, key, secret string, allowedClockSkew int64) error {
signatureBytes, _ := hex.DecodeString(signature)
now := time.Now().Unix()
for i := int64(0); i <= allowedClockSkew; i++ {
if bytes.Equal(v.h.Hash(key, secret, now+i), signatureBytes) {
return nil
}
if i == int64(0) {
continue
}
if bytes.Equal(v.h.Hash(key, secret, now-i), signatureBytes) {
return nil
}
}
return errors.New("signature is not valid")
}
Cognitive complexity: 8, Cyclomatic complexity: 5
Tests
Files: 2. Third party imports: 0. Imports from organisation: 0. Tests: 3. Benchmarks: 1.
Constants
const (
token = "5bcef48a3f03d311ff27d156630baf849e3b438b8a48fec99239d5c9"
sharedSecret = "foobar"
now = 1546259837
)