Пример #1
0
// CmdGet gets a file
func CmdGet() int {
	var err error
	// write to "-","",file
	// server must be specified
	// command line must be parseable
	args := flag.Args()
	if len(args) == 0 {
		log.Fatal("URL missing")
		return 1
	}
	server, messageID, _ := cmdlineURLparse(args...)
	if server == "" {
		// if server is missing, we need --server
		if OptionsVar.Server == "" {
			log.Fatal("Server must be specified: --server")
			return 1
		}
		server = OptionsVar.Server
	}
	if OptionsVar.Server != "" {
		// overwrite server if --server is given
		server = OptionsVar.Server
	}
	err = loadStoreMessage(server, messageID, OptionsVar.Outfile)
	if err != nil {
		return 1
	}
	log.Dataf("STATUS (Process):\tDONE\n")
	return 0
}
Пример #2
0
// CmdPost posts a message
func CmdPost() int {
	var inData []byte
	var err error
	if OptionsVar.Server == "" {
		log.Fatal("Server must be specified: --server")
		return 1
	}

	maxInData := int64(GlobalConfigVar.BodyLength-(message.Curve25519KeySize*2)) * 5
	inData, err = inputData(OptionsVar.Infile, maxInData)
	if err != nil {
		log.Fatalf("No input data: %s\n", err)
		return 1
	}
	log.Datas("STATUS (Process):\tPOST\n")
	proto := repproto.New(OptionsVar.Socksserver, OptionsVar.Server)
	err = proto.PostSpecific(OptionsVar.Server, inData)
	if err != nil {
		log.Fatalf("Output failed: %s\n", err)
		log.Datas("STATUS (Result):\tFAIL\n")
	} else {
		log.Datas("STATUS (Result):\tDONE\n")
	}

	log.Sync()
	return 0
}
Пример #3
0
// CmdSTM does an STM run to specific server and from specific stmdir
func CmdSTM() int {
	if OptionsVar.Server == "" {
		log.Fatal("Server must be specified: --server\n")
		return 1
	}
	if OptionsVar.Stmdir == "" {
		log.Fatal("Missing parameter: --stmdir\n")
		return 1
	}
	if !isDir(OptionsVar.Stmdir) {
		log.Fatalf("stmdir does not exist or is no directory: %s\n", OptionsVar.Stmdir)
		return 1
	}
	err := listSTM(OptionsVar.Stmdir) // Todo: Test if dir exists
	if err != nil {
		log.Errorf("STM Process errors: %s\n", err)
		return 1
	}
	return 0
}
Пример #4
0
// CmdGenTempKey generates a temporary key for a given private key
func CmdGenTempKey() int {
	var privkey message.Curve25519Key
	privkeystr := selectPrivKey(OptionsVar.Privkey, GlobalConfigVar.PrivateKey, "tty")
	if privkeystr == "" {
		log.Fatal("No private key given (-privkey)")
		return 1
	}
	copy(privkey[:], utils.B58decode(privkeystr))
	pubkey := message.GenPubKey(&privkey)
	privkeytemp, err := message.GenRandomKey()
	if err != nil {
		log.Errorf("Key generation error:%s\n", err)
		return 1
	}
	pubkeytemp := message.GenPubKey(privkeytemp)
	log.Dataf("STATUS (PrivateKey):\t%s_%s\n", utils.B58encode(privkey[:]), utils.B58encode(privkeytemp[:]))
	log.Dataf("STATUS (PublicKey):\t%s_%s\n", utils.B58encode(pubkey[:]), utils.B58encode(pubkeytemp[:]))
	log.Printf("PRIVATE key: %s_%s\n\n", utils.B58encode(privkey[:]), utils.B58encode(privkeytemp[:]))
	log.Printf("Public key: %s_%s\n", utils.B58encode(pubkey[:]), utils.B58encode(pubkeytemp[:]))
	return 0
}
Пример #5
0
func testCommands() bool {
	i := 0
	for _, x := range commands {
		if *x {
			i++
		}
	}
	if i > 1 {
		log.Fatal("Only one command may be specified")
		log.Sync()
		return false
	}
	if i == 0 {
		if len(flag.Args()) > 0 {
			*commands[cmdDecrypt] = true
		} else {
			*commands[cmdEncrypt] = true
		}
	}
	return true
}
Пример #6
0
func runCommands() (retval int) {
	log.SetMinLevel(log.LevelPrint)
	if options.Appdata {
		log.SetMinLevel(log.LevelData)
	}
	if options.Verbose {
		log.SetMinLevel(log.LevelDebug)
	}
	if options.KEYVERB {
		log.SetMinLevel(log.LevelSecret)
	}
	usercfgfile := client.UserConfigFile()
	if options.Configfile != "" || usercfgfile != "" {
		configFile := usercfgfile
		if options.Configfile != "" {
			configFile = options.Configfile
		}
		globalconfigT, err := client.LoadConfigFile(configFile)
		if err == nil {
			globalconfig = globalconfigT
		} else {
			log.Errorf("Config file failed to load: %s\n", err)
		}
	}
	for k, v := range commands {
		if *v {
			if callFunc[k] != nil {
				client.OptionsVar = options
				client.GlobalConfigVar = globalconfig
				retval = callFunc[k]()
			} else {
				log.Fatal("Command not implemented")
				return 100
			}
			log.Sync()
			break
		}
	}
	return
}
Пример #7
0
// CmdIndex returns the index for a private key
func CmdIndex() int {
	var server string
	var err error
	var pubkey *message.Curve25519Key
	var privkey message.Curve25519Key
	var messages []*structs.MessageStruct
	var moreMessages bool
	if OptionsVar.Server == "" {
		getPeers(false)
	}
	if OptionsVar.Outdir != "" && !isDir(OptionsVar.Outdir) {
		log.Fatalf("outdir does not exist or is no directory: %s", OptionsVar.Outdir)
		return 1
	}

	// privkey must be set
	privkeystr := selectPrivKey(OptionsVar.Privkey, GlobalConfigVar.PrivateKey, "tty")
	if privkeystr == "" {
		log.Fatal("Private key missing: --privkey\n")
		return 1
	}
	privT := utils.B58decode(privkeystr)
	copy(privkey[:], privT)
	pubkey = message.CalcPub(&privkey)
	if OptionsVar.Server != "" {
		server = OptionsVar.Server
	}

	proto := repproto.New(OptionsVar.Socksserver, OptionsVar.Server)
	log.Dataf("STATUS (Process):\tLIST\n")

	if server != "" {
		fmt.Println("Specific server")
		messages, moreMessages, err = proto.ListSpecific(server, pubkey[:], privkey[:], OptionsVar.Start, OptionsVar.Count)
	} else {
		fmt.Println("Any server")
		server, messages, moreMessages, err = proto.List(pubkey[:], privkey[:], OptionsVar.Start, OptionsVar.Count)
	}
	if err != nil {
		log.Fatalf("List error: %s\n", err)
		return 1
	}
	if len(messages) > 0 {
		fmt.Print("Index\t\tMessageID\n")
		fmt.Print("------------------------------------------------------------\n")
	}
	for _, msg := range messages {
		log.Dataf("STATUS (MessageList):\t%d %s %s %d %d\n", msg.Counter, utils.B58encode(msg.MessageID[:]), utils.B58encode(msg.SignerPub[:]), msg.PostTime, msg.ExpireTime)
		fmt.Printf("%d\t\t%s\n", msg.Counter, utils.B58encode(msg.MessageID[:]))
	}
	log.Dataf("STATUS (ListResult):\t%d %d %t\n", OptionsVar.Start, OptionsVar.Count, moreMessages)
	if len(messages) > 0 {
		fmt.Print("------------------------------------------------------------\n")
	}
	if moreMessages {
		fmt.Print("More messages may be available\n")
	} else {
		fmt.Print("Listing complete\n")
	}
	if OptionsVar.Outdir != "" {
		log.Dataf("STATUS (Process):\tFETCHMANY\n")
		fmt.Print("Fetching messages...")
		hasErrors := 0
		for _, msg := range messages {
			log.Dataf("STATUS (Fetch):\t%s\n", utils.B58encode(msg.MessageID[:]))
			err = loadStoreMessage(server, msg.MessageID[:], OptionsVar.Outdir+string(os.PathSeparator)+utils.B58encode(msg.MessageID[:])) // use index server for download, store with name messageID
			if err != nil {
				fmt.Print(".F")
				hasErrors++
				log.Dataf("STATUS (FetchError):\t%s\n", utils.B58encode(msg.MessageID[:]))
			} else {
				fmt.Print(".o")
				log.Dataf("STATUS (FetchComplete):\t%s\n", utils.B58encode(msg.MessageID[:]))
			}
		}
		if hasErrors > 0 {
			fmt.Print(". Some errors during download.\n")
			log.Dataf("STATUS (FetchResult):\tERROS %d\n", hasErrors)
		} else {
			fmt.Print(". Download complete.\n")
			log.Dataf("STATUS (FetchResult):\tOK\n")
		}
	}

	log.Sync()
	// server can be set
	return 0
}
Пример #8
0
// CmdIndex returns the index for a private key
func CmdIndex() int {
	var server string
	var err error
	var pubkey *message.Curve25519Key
	var privkey message.Curve25519Key
	var messages []*structs.MessageStruct
	var moreMessages bool
	if OptionsVar.Server == "" {
		// getPeers(false). Meaningless for index calls
		log.Fatal("--index requires --server to be specified.\n")
		return 1
	}
	server = OptionsVar.Server

	if OptionsVar.Outdir != "" && !isDir(OptionsVar.Outdir) {
		log.Fatalf("outdir does not exist or is no directory: %s", OptionsVar.Outdir)
		return 1
	}

	// privkey must be set
	privkeystr := selectPrivKey(OptionsVar.Privkey, GlobalConfigVar.PrivateKey, "tty")
	if privkeystr == "" {
		log.Fatal("Private key missing: --privkey\n")
		return 1
	}
	// Test if long key is given, if yes, use only first part
	if pos := strings.Index(privkeystr, "_"); pos > 0 {
		privkeystr = privkeystr[:pos]
	}
	privT := utils.B58decode(privkeystr)
	copy(privkey[:], privT)
	pubkey = message.CalcPub(&privkey)

	proto := repproto.New(OptionsVar.Socksserver, OptionsVar.Server)
	// If we want to change to using the server list instead. Not a great idea
	// proto := repproto.New(OptionsVar.Socksserver, OptionsVar.Server, GlobalConfigVar.PasteServers...)
	// re-enable if we want to use the server list: server, messages, moreMessages, err = proto.List(pubkey[:], privkey[:], OptionsVar.Start, OptionsVar.Count)

	log.Dataf("STATUS (Process):\tLIST\n")

	messages, moreMessages, err = proto.ListSpecific(server, pubkey[:], privkey[:], OptionsVar.Start, OptionsVar.Count)

	if err != nil {
		log.Fatalf("List error: %s\n", err)
		return 1
	}
	if len(messages) > 0 {
		fmt.Print("Index\t\tMessageID\n")
		fmt.Print("------------------------------------------------------------\n")
	}
	for _, msg := range messages {
		log.Dataf("STATUS (MessageList):\t%d %s %s %d %d\n", msg.Counter, utils.B58encode(msg.MessageID[:]), utils.B58encode(msg.SignerPub[:]), msg.PostTime, msg.ExpireTime)
		fmt.Printf("%d\t\t%s\n", msg.Counter, utils.B58encode(msg.MessageID[:]))
	}
	log.Dataf("STATUS (ListResult):\t%d %d %t\n", OptionsVar.Start, OptionsVar.Count, moreMessages)
	if len(messages) > 0 {
		fmt.Print("------------------------------------------------------------\n")
	}
	if moreMessages {
		fmt.Print("More messages may be available\n")
	} else {
		fmt.Print("Listing complete\n")
	}
	if OptionsVar.Outdir != "" {
		log.Dataf("STATUS (Process):\tFETCHMANY\n")
		fmt.Print("Fetching messages...")
		hasErrors := 0
		for _, msg := range messages {
			log.Dataf("STATUS (Fetch):\t%s\n", utils.B58encode(msg.MessageID[:]))
			err = loadStoreMessage(server, msg.MessageID[:], OptionsVar.Outdir+string(os.PathSeparator)+utils.B58encode(msg.MessageID[:])) // use index server for download, store with name messageID
			if err != nil {
				fmt.Print(".F")
				hasErrors++
				log.Dataf("STATUS (FetchError):\t%s\n", utils.B58encode(msg.MessageID[:]))
			} else {
				fmt.Print(".o")
				log.Dataf("STATUS (FetchComplete):\t%s\n", utils.B58encode(msg.MessageID[:]))
			}
		}
		if hasErrors > 0 {
			fmt.Print(". Some errors during download.\n")
			log.Dataf("STATUS (FetchResult):\tERROS %d\n", hasErrors)
		} else {
			fmt.Print(". Download complete.\n")
			log.Dataf("STATUS (FetchResult):\tOK\n")
		}
	}

	log.Sync()
	// server can be set
	return 0
}