-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmfa_auth.go
45 lines (42 loc) · 1.02 KB
/
mfa_auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
/*
#include <security/pam_appl.h>
*/
import "C"
import (
"fmt"
"github.com/dgryski/dgoogauth"
"pam_mfa/yubico_otp"
"strings"
)
func authenticateYubicoOTP(pamh *C.pam_handle_t, yubico_otp_id string) bool {
yubiAuth, err := yubico_otp.NewYubiAuth(yubicoOtpId, yubicoOtpSecret)
if err != nil {
pamLog("Unable to setup Yubico OTP Auth")
return false
}
otp := strings.TrimSpace(requestPass(pamh, C.PAM_PROMPT_ECHO_OFF, "YubiKey OTP: "))
if !strings.HasPrefix(otp, yubico_otp_id) {
return false
}
ok, err := yubiAuth.VerifyOTP(otp)
if err != nil {
fmt.Printf("%s\n", err)
return false
}
return ok
}
func authenticateTOTP(pamh *C.pam_handle_t, totp_secret string) bool {
totp_secret = strings.ToUpper(totp_secret)
totp_config := dgoogauth.OTPConfig{
Secret: totp_secret,
WindowSize: totpWindow,
UTC: true,
}
totp_code := strings.TrimSpace(requestPass(pamh, C.PAM_PROMPT_ECHO_OFF, "TOTP: "))
ok, err := totp_config.Authenticate(totp_code)
if err != nil {
return false
}
return ok
}