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" "fmt"
"log" "log"
"os" "os"
_ "os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
"time" "time"
) )
var VERSION = "v0.1.0"
/* Shows the help message /* Shows the help message
*/ */
func ShowHelp() { func ShowHelp() {
fmt.Println("Watches a device and locks the screen if the device is missing.") fmt.Println("Watches a device and locks the screen if the device is missing.")
fmt.Println() fmt.Println()
fmt.Println("Usage:") 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 daemon: Runs in background.")
//fmt.Println(" usblocker create: Prepares a device for usage with USBLocker.") //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! /* The watcher himself!
@ -35,7 +43,7 @@ func WatcherUnlocked(device string) {
} }
log.Println("Locked") log.Println("Locked")
var args []string 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, "-info")
//args = append(args, "") //args = append(args, "")
args = append(args, "-mode") args = append(args, "-mode")
@ -52,17 +60,20 @@ func WatcherUnlocked(device string) {
/* Watcher for locked state / no device /* Watcher for locked state / no device
*/ */
func WatcherLocked(lpid *os.Process) { func WatcherLocked(lpid *os.Process) {
var passphrase []byte // TEH KEY!!1! var passphrase string // TEH KEY!!1!
var devices []string // list of devices var devices []string // list of devices
var lfile *os.File // device file var lfile *os.File // device file
ldev := "" // device file name ldev := "" // device file name
version := "v0" // version string version := "v0" // version string
// Set the passphrase var passtest []byte
for i := range passphrase { for i := 0; i < 1024; i++ {
passphrase[i] = 0 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 { for {
var err error var err error
devices, err = filepath.Glob("/dev/?d?1") devices, err = filepath.Glob("/dev/?d?1")
@ -95,18 +106,30 @@ func WatcherLocked(lpid *os.Process) {
log.Println("Checking", ldev, "for right version...") log.Println("Checking", ldev, "for right version...")
versiontest := []byte(" ") versiontest := []byte(" ")
length, err := lfile.Read(versiontest) length, err := lfile.Read(versiontest)
_ = lfile.Close()
if err != nil { if err != nil {
log.Fatal("Error while reading the device file:", err) log.Fatal("Error while reading the device file:", err)
} }
if length == 7 && strings.HasPrefix(string(versiontest), version) { if length == 7 && strings.HasPrefix(string(versiontest), version) {
// And finally: UNLOCK! log.Println("Checking passphrase...")
log.Println("Unlocked") length, err := lfile.Read(passtest)
if lpid != nil { _ = lfile.Close()
lpid.Kill() if err != nil {
_, _ = lpid.Wait() 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 {
lpid.Kill()
_, _ = lpid.Wait()
}
WatcherUnlocked(ldev)
} }
WatcherUnlocked(ldev)
} }
} }
@ -125,7 +148,7 @@ func main() {
switch os.Args[1] { switch os.Args[1] {
case "run": case "run":
case "daemon": 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": case "create":
log.Fatal("Not yet implemented.") log.Fatal("Not yet implemented.")
default: default:
@ -137,8 +160,6 @@ func main() {
log.Fatal("YU NO GOT ROOT??") log.Fatal("YU NO GOT ROOT??")
} }
// Greet the user :) ShowMOTD()
//log.Println("USBLocker", version)
WatcherLocked(nil) WatcherLocked(nil)
} }