-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
53 lines (42 loc) · 866 Bytes
/
main.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
46
47
48
49
50
51
52
53
package main
import (
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
"log"
"os"
"time"
"github.com/MDM23/pam_remote_challenge/pam"
"golang.org/x/crypto/ssh/terminal"
)
func main() {
keyPem, err := ioutil.ReadFile("snakeoil.pem")
if err != nil {
log.Fatalf("read key: %s", err)
}
block, _ := pem.Decode(keyPem)
if block == nil {
log.Fatalln("bad PEM data!")
}
key, err := x509.ParsePKCS1PrivateKey(block.Bytes)
if err != nil {
log.Fatalf("parse key: %s", err)
}
challenge, err := pam.NewAuthChallenge(key)
if err != nil {
log.Fatalln(err)
}
fmt.Print(challenge, "\nEnter PIN code to continue: ")
pin, err := terminal.ReadPassword(0)
if err != nil {
log.Fatalln(err)
}
fmt.Println()
if challenge.PINMatches(string(pin)) {
os.Exit(0)
}
time.Sleep(3 * time.Second)
fmt.Println("Authentication failed!")
os.Exit(1)
}