1
0
Fork 0

added passphrase checking

This commit is contained in:
fanir 2013-11-21 23:23:28 +01:00
parent d4dd13ad97
commit 8844660add
2 changed files with 40 additions and 19 deletions

BIN
usblocker

Binary file not shown.

View file

@ -4,22 +4,30 @@ import (
"fmt"
"log"
"os"
_ "os/exec"
"path/filepath"
"strings"
"time"
)
var VERSION = "v0.1.0"
/* Shows the help message
*/
func ShowHelp() {
fmt.Println("Watches a device and locks the screen if the device is missing.")
fmt.Println()
fmt.Println("Usage:")
fmt.Println(" usblocker run: Runs USBLocker in foreground.")
fmt.Println(" usblocker run: Start USBLocker.")
//fmt.Println(" usblocker daemon: Runs in background.")
//fmt.Println(" usblocker create: Prepares a device for usage with USBLocker.")
//fmt.Println(" (Not yet implemented!)")
}
/*
*/
func ShowMOTD() {
fmt.Println("Welcome to USBLocker ", VERSION)
fmt.Println()
fmt.Println("Press Ctrl-C to exit.")
}
/* The watcher himself!
@ -35,7 +43,7 @@ func WatcherUnlocked(device string) {
}
log.Println("Locked")
var args []string
args = append(args, "-nolock")
args = append(args, "-nolock") // Fix for... something. First passed argument keeps beeing ignored, for whatever reason.
//args = append(args, "-info")
//args = append(args, "")
args = append(args, "-mode")
@ -52,17 +60,20 @@ func WatcherUnlocked(device string) {
/* Watcher for locked state / no device
*/
func WatcherLocked(lpid *os.Process) {
var passphrase []byte // TEH KEY!!1!
var passphrase string // TEH KEY!!1!
var devices []string // list of devices
var lfile *os.File // device file
ldev := "" // device file name
version := "v0" // version string
// Set the passphrase
for i := range passphrase {
passphrase[i] = 0
var passtest []byte
for i := 0; i < 1024; i++ {
passtest = append(passtest, 0)
}
// Set the passphrase
passphrase = "wictQQT86qi7YhZP3wVIZek+x9X0ELJA5LN2amEdh54xXs0yGlGx2kRrfIXC+C3iIX9iYRMKrv0bFSyR29SVTVhl2Q0LFOvvAmawiRrJ9MLwyiBrTVfhsVLcZcKNI5Up6xjebezqyhTcZBzEuRYk4VueCXbjI0ISK0LQgMdKxiybQOt1+FLAmgtYj+izB4xvEd9A+wQOnb+wKqZ8TpWh8h/HVfQLgobXDND8I7SXYC1Qm5Kv4wUBWUDg3YOWwMLWfYvyCU4ZyKi5FG3GWvLvKKMxk7vHA/YDyz/eXo3x07zmqDqZHP19k9nGex6ubzmZOWLZz1zEwsdweXCqYps9waXwhJ/9zgrx735IRE3gPL/KYP/X5WTMBXMYFkCAzT6LHNO2gWzdHqdIjyBPBoOHDtVFhKp7prN6GCn/h4Bwr5VzxC+NrUQPG3AqdQdnNGf9zmUV7VE4ZtRdC5dA5I0rJkX9xIbps7IiF9TACIHwXWVEQ+VpQFXRT063DcMxzlmP0b55k4Y2YEZsFEIYO0/hNqMl5D/ETNriiKIpr296WfRqPC6RsGgodZ6TIA8/XqRWsmkCjBHHPSv7BfVDNUbH/hiINH+8U/YfUGfFOly301HXZlEpqLjCXdEw8kzNN06anFTd+6YsTOScGLeddi1urqUCQ9v5nM1iAoXj0djOUdbZks8RgXdf583hhwHWG/Ib5HLSr4ISMQxFhjWKcHvo4ffeYLiOP85ulNsL5ZbtOUL2MX/DuLE1mKopoj50Jjb0mV+QiXUkifjZgGuXyGuZYfNYtMSmkRGERkJfrLeQyd69o+CLG7sfywOgelFWHTwkeVQNbpjRPmTLdSsq0MuJeIlcIAEKECQgBkNMOE2WuHOC2jr8Ba018wESW/hXAairG7ft7Mmf+AMCdjamFhb56YFbE9LumQ8ILgK9q6FQ6OU39qP+wCivdtSEnDnip4EVw7yItj1/0GVs1QPr20gDHO0G2t90JPyApmqtfKq4CY/tKgDhAkBwNXyGEVCrsA=="
for {
var err error
devices, err = filepath.Glob("/dev/?d?1")
@ -95,11 +106,22 @@ func WatcherLocked(lpid *os.Process) {
log.Println("Checking", ldev, "for right version...")
versiontest := []byte(" ")
length, err := lfile.Read(versiontest)
_ = lfile.Close()
if err != nil {
log.Fatal("Error while reading the device file:", err)
}
if length == 7 && strings.HasPrefix(string(versiontest), version) {
log.Println("Checking passphrase...")
length, err := lfile.Read(passtest)
_ = lfile.Close()
if err != nil {
log.Fatal("Error while reading the device file:", err)
}
fmt.Println(passphrase)
fmt.Println()
fmt.Println(string(passtest))
if length == 1024 && string(passtest) == passphrase {
// And finally: UNLOCK!
log.Println("Unlocked")
if lpid != nil {
@ -109,6 +131,7 @@ func WatcherLocked(lpid *os.Process) {
WatcherUnlocked(ldev)
}
}
}
time.Sleep(time.Duration(1) * time.Second)
}
@ -125,7 +148,7 @@ func main() {
switch os.Args[1] {
case "run":
case "daemon":
log.Fatal("Not yet implemented.")
log.Fatal("Not yet implemented. Probably won't be implemented anyway, go doesn't seem to support forking...")
case "create":
log.Fatal("Not yet implemented.")
default:
@ -137,8 +160,6 @@ func main() {
log.Fatal("YU NO GOT ROOT??")
}
// Greet the user :)
//log.Println("USBLocker", version)
ShowMOTD()
WatcherLocked(nil)
}