You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

challenge.go 679B

123456789101112131415161718192021222324252627
  1. package protocol
  2. import (
  3. "crypto/rand"
  4. "encoding/base64"
  5. )
  6. // ChallengeLength - Length of bytes to generate for a challenge
  7. const ChallengeLength = 32
  8. // Challenge that should be signed and returned by the authenticator
  9. type Challenge URLEncodedBase64
  10. // Create a new challenge to be sent to the authenticator. The spec recommends using
  11. // at least 16 bytes with 100 bits of entropy. We use 32 bytes.
  12. func CreateChallenge() (Challenge, error) {
  13. challenge := make([]byte, ChallengeLength)
  14. _, err := rand.Read(challenge)
  15. if err != nil {
  16. return nil, err
  17. }
  18. return challenge, nil
  19. }
  20. func (c Challenge) String() string {
  21. return base64.RawURLEncoding.EncodeToString(c)
  22. }