コード例 #1
0
ファイル: main.go プロジェクト: MrGosti/rosae
func main() {
	me, err := user.Current()
	checkErr(err)

	rosa.PrivateKeyPath = me.HomeDir + "/.rosa/key.priv"
	rosa.PublicKeyPath = me.HomeDir + "/.rosa/key.pub"
	rosa.FriendListPath = me.HomeDir + "/.rosa/friend_list"

	_PrivateKey, err = rosa.LoadPrivateKey(rosa.PrivateKeyPath)

	err = rosa.LoadFriends(rosa.FriendListPath)

	var cmdList map[string]command

	cmdList = make(map[string]command)

	cmdList["friends"] = friends
	cmdList["friend"] = friend
	cmdList["add"] = add
	cmdList["delete"] = deleteFriend
	cmdList["generate"] = generate
	cmdList["public"] = public
	cmdList["help"] = help

	if len(os.Args) < 2 || cmdList[os.Args[1]] == nil {
		checkErr(cmdList["help"]())
		os.Exit(0)
	}

	checkErr(cmdList[os.Args[1]]())
}
コード例 #2
0
ファイル: get.go プロジェクト: MrGosti/slingshot
func getFile(dir string, port int, secure bool, status chan error) {

	var key *rsa.PrivateKey

	var err error

	if secure {
		key, err = rosa.LoadPrivateKey(rosa.PrivateKeyPath)
		if err != nil {
			status <- err
			return
		}
	}

	l, err := net.Listen("tcp", ":"+strconv.Itoa(port))
	if err != nil {
		status <- err
		return
	}
	defer l.Close()
	for {
		conn, err := l.Accept()
		if err != nil {
			status <- err
			return
		}
		content := make([]byte, 1)
		go func(c net.Conn) {
			var readed []byte
			defer c.Close()

			for {
				a, _ := c.Read(content)

				if a == 0 && readed != nil {
					fmt.Println(readed)
					if secure {
						readed, err = rosa.Decrypt(readed, key)
						if err != nil {
							status <- err
							return
						}
					}
					p, err := getPellet(readed)
					if err != nil {
						status <- err
						return
					}

					readed = make([]byte, 1)
					save_file(p.FileName, p.Content)
					fmt.Printf("Received => %v\n", p.FileName)
					break
				} else {
					readed = append(readed, content...)
				}
				content = make([]byte, 1)
			}
		}(conn)
	}
	status <- nil
}