diff options
author | salaaad2 <arthurdurant263@gmail.com> | 2022-04-01 22:58:13 +0200 |
---|---|---|
committer | salaaad2 <arthurdurant263@gmail.com> | 2022-04-01 22:58:13 +0200 |
commit | 1758ce649422255bd2faf482c02be71ce0783865 (patch) | |
tree | c4faa014bd905a949f5c563fa91d148dacea4888 | |
parent | hehe (diff) | |
download | smith-1758ce649422255bd2faf482c02be71ce0783865.tar.gz smith-1758ce649422255bd2faf482c02be71ce0783865.tar.bz2 smith-1758ce649422255bd2faf482c02be71ce0783865.tar.xz smith-1758ce649422255bd2faf482c02be71ce0783865.tar.zst smith-1758ce649422255bd2faf482c02be71ce0783865.zip |
signing requests
Diffstat (limited to '')
-rw-r--r-- | csrc/smith.h | 2 | ||||
-rw-r--r-- | go.mod | 1 | ||||
-rw-r--r-- | gosrc/main.go | 10 | ||||
-rw-r--r-- | gosrc/pipes.go | 107 | ||||
-rw-r--r-- | gosrc/requests.go | 23 | ||||
-rw-r--r-- | sample_config.json | 5 |
6 files changed, 142 insertions, 6 deletions
diff --git a/csrc/smith.h b/csrc/smith.h index 04015ee..489c053 100644 --- a/csrc/smith.h +++ b/csrc/smith.h @@ -9,6 +9,8 @@ #ifndef SMITH_H_ #define SMITH_H_ +#include <unistd.h> + char * mr_smith(); #endif // SMITH_H_ @@ -3,6 +3,7 @@ module smith go 1.16 require ( + github.com/ebuchman/go-shell-pipes v0.0.0-20150412091402-83e132480862 // indirect github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1 // indirect github.com/rivo/tview v0.0.0-20220307222120-9994674d60a8 ) diff --git a/gosrc/main.go b/gosrc/main.go index 27cec39..9923d09 100644 --- a/gosrc/main.go +++ b/gosrc/main.go @@ -11,6 +11,7 @@ import ( "fmt" "io/ioutil" "log" + "os" ) // #include "../csrc/smith.h" @@ -28,6 +29,12 @@ func main() { "\nI will try to help you get the bag...") config_path := "./config.json" + for i, a := range os.Args[1:] { + if a == "-c" || a == "--config" { + config_path = os.Args[i + 2] + } + } + config_content, err := ioutil.ReadFile(config_path) if err != nil { log.Fatal("config file not found") @@ -35,7 +42,6 @@ func main() { var config Config err = json.Unmarshal(config_content, &config) - if err != nil { log.Fatal("error during marshall() ", err) } @@ -44,4 +50,6 @@ func main() { Styles.colorBlue + "public_key: " + Styles.colorReset + config.Public_key + "\n" + Styles.colorBlue + "secret_key: " + Styles.colorReset + config.Secret_key + "\n" + Styles.colorBlue + "mirror: " + Styles.colorReset + config.Mirror) + + make_body("qwe", "qwe", "qwe") } diff --git a/gosrc/pipes.go b/gosrc/pipes.go new file mode 100644 index 0000000..f668821 --- /dev/null +++ b/gosrc/pipes.go @@ -0,0 +1,107 @@ +package main + +import ( + "bytes" + "fmt" + "io" + "os/exec" + "strings" +) + +// Convert a shell command with a series of pipes into +// correspondingly piped list of *exec.Cmd +// If an arg has spaces, this will fail +func RunString(s string) (string, error) { + buf := bytes.NewBuffer([]byte{}) + sp := strings.Split(s, "|") + cmds := make([]*exec.Cmd, len(sp)) + // create the commands + for i, c := range sp { + cs := strings.Split(strings.TrimSpace(c), " ") + cmd := cmdFromStrings(cs) + cmds[i] = cmd + } + + cmds = AssemblePipes(cmds, nil, buf) + if err := RunCmds(cmds); err != nil { + return "", err + } + + b := buf.Bytes() + return string(b), nil +} + +func cmdFromStrings(cs []string) *exec.Cmd { + if len(cs) == 1 { + return exec.Command(cs[0]) + } else if len(cs) == 2 { + return exec.Command(cs[0], cs[1]) + } + return exec.Command(cs[0], cs[1:]...) +} + +// Convert sequence of tokens into commands, +// using "|" as a delimiter +func RunStrings(tokens ...string) (string, error) { + if len(tokens) == 0 { + return "", nil + } + buf := bytes.NewBuffer([]byte{}) + cmds := []*exec.Cmd{} + args := []string{} + // accumulate tokens until a | + for _, t := range tokens { + if t != "|" { + args = append(args, t) + } else { + cmds = append(cmds, cmdFromStrings(args)) + args = []string{} + } + } + cmds = append(cmds, cmdFromStrings(args)) + cmds = AssemblePipes(cmds, nil, buf) + if err := RunCmds(cmds); err != nil { + return "", fmt.Errorf("%s; %s", err.Error(), string(buf.Bytes())) + } + + b := buf.Bytes() + return string(b), nil +} + +// Pipe stdout of each command into stdin of next +func AssemblePipes(cmds []*exec.Cmd, stdin io.Reader, stdout io.Writer) []*exec.Cmd { + cmds[0].Stdin = stdin + cmds[0].Stderr = stdout + // assemble pipes + for i, c := range cmds { + if i < len(cmds)-1 { + cmds[i+1].Stdin, _ = c.StdoutPipe() + cmds[i+1].Stderr = stdout + } else { + c.Stdout = stdout + c.Stderr = stdout + } + } + return cmds +} + +// Run series of piped commands +func RunCmds(cmds []*exec.Cmd) error { + // start processes in descending order + for i := len(cmds) - 1; i > 0; i-- { + if err := cmds[i].Start(); err != nil { + return err + } + } + // run the first process + if err := cmds[0].Run(); err != nil { + return err + } + // wait on processes in ascending order + for i := 1; i < len(cmds); i++ { + if err := cmds[i].Wait(); err != nil { + return err + } + } + return nil +} diff --git a/gosrc/requests.go b/gosrc/requests.go new file mode 100644 index 0000000..4e94533 --- /dev/null +++ b/gosrc/requests.go @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + "log" +) + +func sign_request(body string, key string) { + fmt.Println("signing request : ", body) + + out2, err := RunStrings("/usr/bin/echo", "-n", body, "|", "/usr/bin/openssl", "dgst", "-sha256", "-hmac", key) + if err != nil { + log.Fatal("hwhat") + } + + fmt.Println(out2) + // here +} + +func make_body(order string, ticker string, price string) { + ret := "GET /sapi/v1/capital/config/getall" + sign_request(ret, "heheheheh") +} diff --git a/sample_config.json b/sample_config.json deleted file mode 100644 index db566fb..0000000 --- a/sample_config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "public_key": "lol", - "secret_key": "hehe", - "mirror": "api.binance.com" -} |