Finalize `GetChallengeAnswer`
This commit is contained in:
parent
acb2d934da
commit
b66451382c
|
@ -1,5 +1,12 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
import "github.com/pquerna/otp/totp"
|
||||
|
||||
func NewSession(publicHash string, privateHash string) (c *CreateSessionStruct) {
|
||||
c.PrivateHash = privateHash
|
||||
c.PublicHash = publicHash
|
||||
|
@ -8,7 +15,13 @@ func NewSession(publicHash string, privateHash string) (c *CreateSessionStruct)
|
|||
return c
|
||||
}
|
||||
|
||||
func (c *CreateSessionStruct) GetChallengeAnswer(secret string) (string, error) {
|
||||
// pvt_hash := c.PrivateHash
|
||||
return "", nil
|
||||
func (c *CreateSessionStruct) GetChallengeAnswer(challenge string) (string, error) {
|
||||
totpCode, err := totp.GenerateCode(challenge, time.Now())
|
||||
if err != nil {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
hash := sha1.New()
|
||||
hash.Write([]byte(totpCode + c.PrivateHash))
|
||||
return fmt.Sprintf("%x", hash.Sum(nil)), nil
|
||||
}
|
||||
|
|
5
go.mod
5
go.mod
|
@ -1,3 +1,8 @@
|
|||
module github.com/Intellivoid/Socialvoid-Go
|
||||
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
|
||||
github.com/pquerna/otp v1.3.0 // indirect
|
||||
)
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc h1:biVzkmvwrH8WK8raXaxBx6fRVTlJILwEwQGL1I/ByEI=
|
||||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pquerna/otp v1.3.0 h1:oJV/SkzR33anKXwQU3Of42rL4wbrffP4uvUf1SvS5Xs=
|
||||
github.com/pquerna/otp v1.3.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
Loading…
Reference in New Issue