finish OTP code

This commit is contained in:
Xavier Henner
2019-07-10 18:40:15 +02:00
parent 68de442333
commit 88f5ac3765
4 changed files with 36 additions and 4 deletions

16
otp.go
View File

@@ -14,11 +14,19 @@ func (s *OpenVpnMgt) GenerateOTP(user string) ([]string, error) {
// }
func (s *OpenVpnMgt) TokenPassword(c *vpnSession) (bool, string) {
//TODO implement that correcly
if c.password == "maith1wiePuw3ieb4heiNie5y" {
return true, "maith1wiePuw3ieb4heiNie5y"
now := time.Now().Unix()
if len(c.password) > 40 {
salt := c.password[:4]
for i := 0; i < 3; i++ {
test := encode64(ComputeHmac256(c.baseHash(salt, now/30-int64(i)), s.otpMasterSecrets[0]))
if salt+test == c.password {
return true, c.password
}
}
}
return false, "maith1wiePuw3ieb4heiNie5y"
salt := NewSalt()
return false, salt + encode64(ComputeHmac256(c.baseHash(salt, now/30), s.otpMasterSecrets[0]))
}
func (s *OpenVpnMgt) GenerateOTPGeneric(user string, period int, algo string, secretLen int, digits int) ([]string, error) {