forked from gophergala2016/huk
/
huk.go
70 lines (65 loc) · 1.72 KB
/
huk.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"fmt"
"github.com/gophergala2016/huk/client"
"github.com/gophergala2016/huk/config"
"github.com/gophergala2016/huk/key"
"github.com/gophergala2016/huk/server"
"log"
"os"
"strconv"
)
func main() {
var filePath string
var myKey string
var myAddr key.Addr
args := os.Args[1:]
action := args[0]
switch action {
case "init":
// run the initialization
config.Init()
case "send":
// server
filePath = args[1]
myAddr = key.MyAddress()
myKey = key.AddrToKey(myAddr)
fmt.Printf(
"The key for your file (%v) is %v.\n"+
"Tell your friend to run '$ huk get %v'\n"+
"Waiting for connection...\n",
filePath,
myKey,
myKey,
)
server.Run(strconv.Itoa(myAddr.Port), filePath)
// create server on port_x
// listen for connections
// validate incoming request with given key
// connection established
// recieves clients public key
// encrypt file using client's pub key
// send encrypted file over stream to client
case "get":
myKey = args[1]
//userName := args[2]
fmt.Printf(
"Searching for '%v' on your local network..\n",
myKey,
)
// Client Case
targetAddr := key.ToAddr(myKey)
// make sure key doesnt have anything but alphabet
//client.ReceiveInOneChunk(targetAddr.IP, strconv.Itoa(targetAddr.Port), userName)
client.ReceiveInOneChunk(targetAddr.IP, strconv.Itoa(targetAddr.Port), "")
// Find server IP by going through list (192.168.0.[1..255]:port_x)
// connection established
// generate pgp (private and public keys)
// send public key to server
// save encrypted file from stream
// decrypt using private key
default:
// Invalid Args
log.Fatal("I need either a filePath or a key ex: '$ huk get filePath.txt' or '$ huk key'")
}
}