updated dependencies
This commit is contained in:
parent
1410847c03
commit
cff4b58f6d
446 changed files with 57869 additions and 27621 deletions
4
vendor/github.com/pquerna/otp/README.md
generated
vendored
4
vendor/github.com/pquerna/otp/README.md
generated
vendored
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
# Why One Time Passwords?
|
||||
|
||||
One Time Passwords (OTPs) are an mechanism to improve security over passwords alone. When a Time-based OTP (TOTP) is stored on a user's phone, and combined with something the user knows (Password), you have an easy on-ramp to [Multi-factor authentication](http://en.wikipedia.org/wiki/Multi-factor_authentication) without adding a dependency on a SMS provider. This Password and TOTP combination is used by many popular websites including Google, Github, Facebook, Salesforce and many others.
|
||||
One Time Passwords (OTPs) are an mechanism to improve security over passwords alone. When a Time-based OTP (TOTP) is stored on a user's phone, and combined with something the user knows (Password), you have an easy on-ramp to [Multi-factor authentication](http://en.wikipedia.org/wiki/Multi-factor_authentication) without adding a dependency on a SMS provider. This Password and TOTP combination is used by many popular websites including Google, GitHub, Facebook, Salesforce and many others.
|
||||
|
||||
The `otp` library enables you to easily add TOTPs to your own application, increasing your user's security against mass-password breaches and malware.
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ Because TOTP is standardized and widely deployed, there are many [mobile clients
|
|||
|
||||
### User Enrollment
|
||||
|
||||
For an example of a working enrollment work flow, [Github has documented theirs](https://help.github.com/articles/configuring-two-factor-authentication-via-a-totp-mobile-app/
|
||||
For an example of a working enrollment work flow, [GitHub has documented theirs](https://help.github.com/articles/configuring-two-factor-authentication-via-a-totp-mobile-app/
|
||||
), but the basics are:
|
||||
|
||||
1. Generate new TOTP Key for a User. `key,_ := totp.Generate(...)`.
|
||||
|
|
|
|||
3
vendor/github.com/pquerna/otp/doc.go
generated
vendored
3
vendor/github.com/pquerna/otp/doc.go
generated
vendored
|
|
@ -19,7 +19,7 @@
|
|||
// one time passcodes in a Google Authenticator compatible manner.
|
||||
//
|
||||
// When adding a TOTP for a user, you must store the "secret" value
|
||||
// persistently. It is recommend to store the secret in an encrypted field in your
|
||||
// persistently. It is recommended to store the secret in an encrypted field in your
|
||||
// datastore. Due to how TOTP works, it is not possible to store a hash
|
||||
// for the secret value like you would a password.
|
||||
//
|
||||
|
|
@ -57,6 +57,7 @@
|
|||
//
|
||||
// Validating a TOTP passcode is very easy, just prompt the user for a passcode
|
||||
// and retrieve the associated user's previously stored secret.
|
||||
//
|
||||
// import "github.com/pquerna/otp/totp"
|
||||
//
|
||||
// passcode := promptForPasscode()
|
||||
|
|
|
|||
9
vendor/github.com/pquerna/otp/hotp/hotp.go
generated
vendored
9
vendor/github.com/pquerna/otp/hotp/hotp.go
generated
vendored
|
|
@ -19,6 +19,7 @@ package hotp
|
|||
|
||||
import (
|
||||
"github.com/pquerna/otp"
|
||||
"github.com/pquerna/otp/internal"
|
||||
"io"
|
||||
|
||||
"crypto/hmac"
|
||||
|
|
@ -71,6 +72,10 @@ func GenerateCode(secret string, counter uint64) (string, error) {
|
|||
// GenerateCodeCustom uses a counter and secret value and options struct to
|
||||
// create a passcode.
|
||||
func GenerateCodeCustom(secret string, counter uint64, opts ValidateOpts) (passcode string, err error) {
|
||||
//Set default value
|
||||
if opts.Digits == 0 {
|
||||
opts.Digits = otp.DigitsSix
|
||||
}
|
||||
// As noted in issue #10 and #17 this adds support for TOTP secrets that are
|
||||
// missing their padding.
|
||||
secret = strings.TrimSpace(secret)
|
||||
|
|
@ -182,7 +187,7 @@ func Generate(opts GenerateOpts) (*otp.Key, error) {
|
|||
opts.Rand = rand.Reader
|
||||
}
|
||||
|
||||
// otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example
|
||||
// otpauth://hotp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example
|
||||
|
||||
v := url.Values{}
|
||||
if len(opts.Secret) != 0 {
|
||||
|
|
@ -204,7 +209,7 @@ func Generate(opts GenerateOpts) (*otp.Key, error) {
|
|||
Scheme: "otpauth",
|
||||
Host: "hotp",
|
||||
Path: "/" + opts.Issuer + ":" + opts.AccountName,
|
||||
RawQuery: v.Encode(),
|
||||
RawQuery: internal.EncodeQuery(v),
|
||||
}
|
||||
|
||||
return otp.NewKeyFromURL(u.String())
|
||||
|
|
|
|||
35
vendor/github.com/pquerna/otp/internal/encode.go
generated
vendored
Normal file
35
vendor/github.com/pquerna/otp/internal/encode.go
generated
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// EncodeQuery is a copy-paste of url.Values.Encode, except it uses %20 instead
|
||||
// of + to encode spaces. This is necessary to correctly render spaces in some
|
||||
// authenticator apps, like Google Authenticator.
|
||||
func EncodeQuery(v url.Values) string {
|
||||
if v == nil {
|
||||
return ""
|
||||
}
|
||||
var buf strings.Builder
|
||||
keys := make([]string, 0, len(v))
|
||||
for k := range v {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, k := range keys {
|
||||
vs := v[k]
|
||||
keyEscaped := url.PathEscape(k) // changed from url.QueryEscape
|
||||
for _, v := range vs {
|
||||
if buf.Len() > 0 {
|
||||
buf.WriteByte('&')
|
||||
}
|
||||
buf.WriteString(keyEscaped)
|
||||
buf.WriteByte('=')
|
||||
buf.WriteString(url.PathEscape(v)) // changed from url.QueryEscape
|
||||
}
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
46
vendor/github.com/pquerna/otp/otp.go
generated
vendored
46
vendor/github.com/pquerna/otp/otp.go
generated
vendored
|
|
@ -18,9 +18,6 @@
|
|||
package otp
|
||||
|
||||
import (
|
||||
"github.com/boombuler/barcode"
|
||||
"github.com/boombuler/barcode/qr"
|
||||
|
||||
"crypto/md5"
|
||||
"crypto/sha1"
|
||||
"crypto/sha256"
|
||||
|
|
@ -30,8 +27,11 @@ import (
|
|||
"hash"
|
||||
"image"
|
||||
"net/url"
|
||||
"strings"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/boombuler/barcode"
|
||||
"github.com/boombuler/barcode/qr"
|
||||
)
|
||||
|
||||
// Error when attempting to convert the secret from base32 to raw bytes.
|
||||
|
|
@ -61,7 +61,6 @@ func NewKeyFromURL(orig string) (*Key, error) {
|
|||
s := strings.TrimSpace(orig)
|
||||
|
||||
u, err := url.Parse(s)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -81,7 +80,6 @@ func (k *Key) String() string {
|
|||
// to enroll a user's TOTP/HOTP key.
|
||||
func (k *Key) Image(width int, height int) (image.Image, error) {
|
||||
b, err := qr.Encode(k.orig, qr.M, qr.Auto)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -146,11 +144,45 @@ func (k *Key) Period() uint64 {
|
|||
if u, err := strconv.ParseUint(q.Get("period"), 10, 64); err == nil {
|
||||
return u
|
||||
}
|
||||
|
||||
|
||||
// If no period is defined 30 seconds is the default per (rfc6238)
|
||||
return 30
|
||||
}
|
||||
|
||||
// Digits returns a tiny int representing the number of OTP digits.
|
||||
func (k *Key) Digits() Digits {
|
||||
q := k.url.Query()
|
||||
|
||||
if u, err := strconv.ParseUint(q.Get("digits"), 10, 64); err == nil {
|
||||
switch u {
|
||||
case 8:
|
||||
return DigitsEight
|
||||
default:
|
||||
return DigitsSix
|
||||
}
|
||||
}
|
||||
|
||||
// Six is the most common value.
|
||||
return DigitsSix
|
||||
}
|
||||
|
||||
// Algorithm returns the algorithm used or the default (SHA1).
|
||||
func (k *Key) Algorithm() Algorithm {
|
||||
q := k.url.Query()
|
||||
|
||||
a := strings.ToLower(q.Get("algorithm"))
|
||||
switch a {
|
||||
case "md5":
|
||||
return AlgorithmMD5
|
||||
case "sha256":
|
||||
return AlgorithmSHA256
|
||||
case "sha512":
|
||||
return AlgorithmSHA512
|
||||
default:
|
||||
return AlgorithmSHA1
|
||||
}
|
||||
}
|
||||
|
||||
// URL returns the OTP URL as a string
|
||||
func (k *Key) URL() string {
|
||||
return k.url.String()
|
||||
|
|
|
|||
3
vendor/github.com/pquerna/otp/totp/totp.go
generated
vendored
3
vendor/github.com/pquerna/otp/totp/totp.go
generated
vendored
|
|
@ -20,6 +20,7 @@ package totp
|
|||
import (
|
||||
"github.com/pquerna/otp"
|
||||
"github.com/pquerna/otp/hotp"
|
||||
"github.com/pquerna/otp/internal"
|
||||
"io"
|
||||
|
||||
"crypto/rand"
|
||||
|
|
@ -199,7 +200,7 @@ func Generate(opts GenerateOpts) (*otp.Key, error) {
|
|||
Scheme: "otpauth",
|
||||
Host: "totp",
|
||||
Path: "/" + opts.Issuer + ":" + opts.AccountName,
|
||||
RawQuery: v.Encode(),
|
||||
RawQuery: internal.EncodeQuery(v),
|
||||
}
|
||||
|
||||
return otp.NewKeyFromURL(u.String())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue