Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions oath.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type OATH struct {
hash func() hash.Hash
algo crypto.Hash
provider string
issuer string
}

// Size returns the output size (in characters) of the password.
Expand Down Expand Up @@ -82,6 +83,10 @@ func (o OATH) URL(t Type, label string) string {
v.Add("provider", o.provider)
}

if o.issuer != "" {
v.Add("issuer", o.issuer)
}

u.RawQuery = v.Encode()
return u.String()

Expand Down Expand Up @@ -119,9 +124,24 @@ func (o OATH) OTP(counter uint64) string {

h := hmac.New(o.hash, o.key)
h.Write(ctr[:])
dt := truncate(h.Sum(nil)) % mod
fmtStr := fmt.Sprintf("%%0%dd", o.size)
return fmt.Sprintf(fmtStr, dt)

if o.issuer == "Steam" {
res := truncate(h.Sum(nil))

steamChars := "23456789BCDFGHJKMNPQRTVWXY"
steamCharsLen := int64(len(steamChars))
hotp := make([]byte, 5, 5)
for i := 0; i < 5; i++ {
idx := res % steamCharsLen
hotp[i] = steamChars[int(idx)]
res = res / steamCharsLen
}
return string(hotp)
} else {
dt := truncate(h.Sum(nil)) % mod
fmtStr := fmt.Sprintf("%%0%dd", o.size)
return fmt.Sprintf(fmtStr, dt)
}
}

// truncate contains the DT function from the RFC; this is used to
Expand Down
6 changes: 6 additions & 0 deletions totp.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,18 @@ func totpFromURL(u *url.URL) (*TOTP, string, error) {
}
}

var issuer = ""
if sissuer := v.Get("issuer"); sissuer != "" {
issuer = sissuer
}

key, err := base32.StdEncoding.DecodeString(Pad(secret))
if err != nil {
// assume secret isn't base32 encoded
key = []byte(secret)
}
otp := NewTOTP(key, 0, period, digits, algo)
otp.issuer = issuer
return otp, label, nil
}

Expand Down