fixes; reset 2fa
This commit is contained in:
parent
9e5553eff6
commit
5cabdcb686
4 changed files with 33 additions and 13 deletions
2
build.sh
2
build.sh
|
@ -1,3 +1,3 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags='-linkmode external -extldflags "-static" -s -w' -o openvpn-user
|
env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags "-linkmode external -extldflags -static -s -w" -o openvpn-user
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
version = "1.0.6"
|
version = "1.0.7"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -56,6 +56,9 @@ var (
|
||||||
registerAppCommandUserFlag = registerAppCommand.Flag("user", "Username.").Short('u').Required().String()
|
registerAppCommandUserFlag = registerAppCommand.Flag("user", "Username.").Short('u').Required().String()
|
||||||
registerAppCommandTotpFlag = registerAppCommand.Flag("totp", "TOTP.").Short('t').Required().String()
|
registerAppCommandTotpFlag = registerAppCommand.Flag("totp", "TOTP.").Short('t').Required().String()
|
||||||
|
|
||||||
|
resetAppCommand = kingpin.Command("reset-app", "register 2FA application")
|
||||||
|
resetAppCommandUserFlag = resetAppCommand.Flag("user", "Username.").Short('u').Required().String()
|
||||||
|
|
||||||
checkAppCommand = kingpin.Command("check-app", "check 2FA application")
|
checkAppCommand = kingpin.Command("check-app", "check 2FA application")
|
||||||
checkAppCommandUserFlag = checkAppCommand.Flag("user", "Username.").Short('u').Required().String()
|
checkAppCommandUserFlag = checkAppCommand.Flag("user", "Username.").Short('u').Required().String()
|
||||||
|
|
||||||
|
@ -120,6 +123,8 @@ func main() {
|
||||||
wrap(openvpnUser.RegisterOtpSecret(*updateSecretCommandUserFlag, *updateSecretCommandSecretFlag))
|
wrap(openvpnUser.RegisterOtpSecret(*updateSecretCommandUserFlag, *updateSecretCommandSecretFlag))
|
||||||
case registerAppCommand.FullCommand():
|
case registerAppCommand.FullCommand():
|
||||||
wrap(openvpnUser.RegisterOtpApplication(*registerAppCommandUserFlag, *registerAppCommandTotpFlag))
|
wrap(openvpnUser.RegisterOtpApplication(*registerAppCommandUserFlag, *registerAppCommandTotpFlag))
|
||||||
|
case resetAppCommand.FullCommand():
|
||||||
|
wrap(openvpnUser.ResetOtpApplication(*resetAppCommandUserFlag))
|
||||||
case checkAppCommand.FullCommand():
|
case checkAppCommand.FullCommand():
|
||||||
appConfigured, appErr := openvpnUser.IsSecondFactorEnabled(*checkAppCommandUserFlag)
|
appConfigured, appErr := openvpnUser.IsSecondFactorEnabled(*checkAppCommandUserFlag)
|
||||||
if appErr != nil {
|
if appErr != nil {
|
||||||
|
|
|
@ -186,7 +186,7 @@ func (oUser *OpenvpnUser) ChangeUserPassword(username, password string) (string,
|
||||||
func (oUser *OpenvpnUser) RegisterOtpSecret(username, secret string) (string, error) {
|
func (oUser *OpenvpnUser) RegisterOtpSecret(username, secret string) (string, error) {
|
||||||
if oUser.userIsActive(username) {
|
if oUser.userIsActive(username) {
|
||||||
if secret == "generate" {
|
if secret == "generate" {
|
||||||
randomStr := randStr(6, "alphanum")
|
randomStr := RandStr(6, "alphanum")
|
||||||
|
|
||||||
secret = base32.StdEncoding.EncodeToString([]byte(randomStr))
|
secret = base32.StdEncoding.EncodeToString([]byte(randomStr))
|
||||||
log.Debug("new generated secret for user %s: %s", username, secret)
|
log.Debug("new generated secret for user %s: %s", username, secret)
|
||||||
|
@ -227,6 +227,24 @@ func (oUser *OpenvpnUser) RegisterOtpApplication(username, totp string) (string,
|
||||||
}
|
}
|
||||||
return "", userIsNotActiveError
|
return "", userIsNotActiveError
|
||||||
}
|
}
|
||||||
|
func (oUser *OpenvpnUser) ResetOtpApplication(username string) (string, error) {
|
||||||
|
if oUser.userIsActive(username) {
|
||||||
|
|
||||||
|
appConfigured, appErr := oUser.IsSecondFactorEnabled(username)
|
||||||
|
if appErr != nil {
|
||||||
|
return "", appErr
|
||||||
|
}
|
||||||
|
if appConfigured {
|
||||||
|
_, err := oUser.Database.Exec("UPDATE users SET app_configured = 0 WHERE username = $2")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return "OTP application reset successful", nil
|
||||||
|
}
|
||||||
|
return "OTP application not configured", nil
|
||||||
|
}
|
||||||
|
return "", userIsNotActiveError
|
||||||
|
}
|
||||||
|
|
||||||
func (oUser *OpenvpnUser) GetUserOtpSecret(username string) (string, error) {
|
func (oUser *OpenvpnUser) GetUserOtpSecret(username string) (string, error) {
|
||||||
if oUser.userIsActive(username) {
|
if oUser.userIsActive(username) {
|
||||||
|
|
17
src/utils.go
17
src/utils.go
|
@ -2,20 +2,17 @@ package src
|
||||||
|
|
||||||
import "crypto/rand"
|
import "crypto/rand"
|
||||||
|
|
||||||
func randStr(strSize int, randType string) string {
|
func RandStr(strSize int, randType string) string {
|
||||||
|
|
||||||
var dictionary string
|
var dictionary string
|
||||||
|
|
||||||
if randType == "alphanum" {
|
switch randType {
|
||||||
dictionary = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
case "number":
|
||||||
}
|
|
||||||
|
|
||||||
if randType == "alpha" {
|
|
||||||
dictionary = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
|
||||||
}
|
|
||||||
|
|
||||||
if randType == "number" {
|
|
||||||
dictionary = "0123456789"
|
dictionary = "0123456789"
|
||||||
|
case "alpha":
|
||||||
|
dictionary = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||||
|
default:
|
||||||
|
dictionary = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||||
}
|
}
|
||||||
|
|
||||||
var bytes = make([]byte, strSize)
|
var bytes = make([]byte, strSize)
|
||||||
|
|
Loading…
Reference in a new issue