mirror of
https://github.com/go-gitea/gitea.git
synced 2025-11-15 10:16:03 +01:00
Support webauthn (#17957)
Migrate from U2F to Webauthn Co-authored-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
27
vendor/github.com/duo-labs/webauthn/protocol/challenge.go
generated
vendored
Normal file
27
vendor/github.com/duo-labs/webauthn/protocol/challenge.go
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
package protocol
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
)
|
||||
|
||||
// ChallengeLength - Length of bytes to generate for a challenge
|
||||
const ChallengeLength = 32
|
||||
|
||||
// Challenge that should be signed and returned by the authenticator
|
||||
type Challenge URLEncodedBase64
|
||||
|
||||
// Create a new challenge to be sent to the authenticator. The spec recommends using
|
||||
// at least 16 bytes with 100 bits of entropy. We use 32 bytes.
|
||||
func CreateChallenge() (Challenge, error) {
|
||||
challenge := make([]byte, ChallengeLength)
|
||||
_, err := rand.Read(challenge)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return challenge, nil
|
||||
}
|
||||
|
||||
func (c Challenge) String() string {
|
||||
return base64.RawURLEncoding.EncodeToString(c)
|
||||
}
|
||||
Reference in New Issue
Block a user