From 6ad756ce3c2afd5a3286735fec6f136906779f6c Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Mon, 25 Jun 2018 13:42:15 -0400 Subject: [PATCH 01/21] add tcp port --- shyftRingWalletConn/app.go | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 shyftRingWalletConn/app.go diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go new file mode 100644 index 0000000000..6394bd2bc3 --- /dev/null +++ b/shyftRingWalletConn/app.go @@ -0,0 +1,56 @@ +package main + +//@NOTE SHYFT main func for api, sets up router and spins up a server +//to run server 'go run shyftBlockExplorerApi/*.go' +import ( +"net" +"fmt" +"os" +) + +const ( + CONN_HOST = "localhost" + CONN_PORT = "3333" + CONN_TYPE = "tcp" +) + +func main() { + + l, err := net.Listen(CONN_TYPE, CONN_HOST+":"+CONN_PORT) + if err != nil { + fmt.Println("Error listening:", err.Error()) + os.Exit(1) + } + defer l.Close() + + for { + // Listen for an incoming connection. + conn, err := l.Accept() + if err != nil { + fmt.Println("Error accepting: ", err.Error()) + os.Exit(1) + } + // Handle connections in a new goroutine. + go handleRequest(conn) + } +} + +// Handles incoming requests. +func handleRequest(conn net.Conn) { + // Make a buffer to hold incoming data. + buf := make([]byte, 1024) + // Read the incoming connection into the buffer. + msg, err := conn.Read(buf) + + if err == nil { + fmt.Println("Message is ", string(buf[:msg])) + fmt.Println("Message is ", msg) + } + if err != nil { + fmt.Println("Error reading:", err.Error()) + } + // Send a response back to person contacting us. + conn.Write([]byte("Message received.")) + // Close the connection when you're done with it. + conn.Close() +} From 6d2dcc0f90f7ab6b96b238c1f78093dff27d1272 Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Mon, 25 Jun 2018 14:35:58 -0400 Subject: [PATCH 02/21] changed server command prompt --- shyftRingWalletConn/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index 6394bd2bc3..2390bfb997 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -1,7 +1,7 @@ package main //@NOTE SHYFT main func for api, sets up router and spins up a server -//to run server 'go run shyftBlockExplorerApi/*.go' +//to run server 'go run shyftRingWalletConn/*.go' import ( "net" "fmt" From 0404cbc062cd8b239e4a41bab25df281412ed5cc Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Sat, 30 Jun 2018 15:12:47 -0400 Subject: [PATCH 03/21] decode message from client --- shyftRingWalletConn/app.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index 2390bfb997..41bc953391 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -3,9 +3,10 @@ package main //@NOTE SHYFT main func for api, sets up router and spins up a server //to run server 'go run shyftRingWalletConn/*.go' import ( -"net" -"fmt" -"os" + "net" + "fmt" + "os" + "encoding/json" ) const ( @@ -44,6 +45,19 @@ func handleRequest(conn net.Conn) { if err == nil { fmt.Println("Message is ", string(buf[:msg])) + var dat map[string]interface{} + byt := []byte(string(buf[:msg])) + + if err := json.Unmarshal(byt, &dat); err != nil { + panic(err) + } + fmt.Println(dat["address"]) + fmt.Println(dat["msg"]) + fmt.Println(dat["sig"]) + //Ecrecover takes 2 args, bytes[] and bytes[] + // we need to pass in the hash of the message as bytes + // and the bytes array of the signature + //crypto.Ecrecover() fmt.Println("Message is ", msg) } if err != nil { From 278086e5fda3cc516cad96fb2d20c9e1412ea363 Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Sat, 30 Jun 2018 15:19:45 -0400 Subject: [PATCH 04/21] rm redundancy --- shyftRingWalletConn/app.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index 41bc953391..f238331813 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -46,9 +46,8 @@ func handleRequest(conn net.Conn) { if err == nil { fmt.Println("Message is ", string(buf[:msg])) var dat map[string]interface{} - byt := []byte(string(buf[:msg])) - - if err := json.Unmarshal(byt, &dat); err != nil { + + if err := json.Unmarshal(buf[:msg], &dat); err != nil { panic(err) } fmt.Println(dat["address"]) From 9f2d6ee3fc9b8f2206fbd7a82126826931a18e78 Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Sat, 30 Jun 2018 15:28:19 -0400 Subject: [PATCH 05/21] log error from Ecrecover --- shyftRingWalletConn/app.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index f238331813..b03f308b1f 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -6,7 +6,8 @@ import ( "net" "fmt" "os" - "encoding/json" + "encoding/json" + "github.com/ethereum/go-ethereum/crypto" ) const ( @@ -56,8 +57,18 @@ func handleRequest(conn net.Conn) { //Ecrecover takes 2 args, bytes[] and bytes[] // we need to pass in the hash of the message as bytes // and the bytes array of the signature - //crypto.Ecrecover() - fmt.Println("Message is ", msg) + var msg = []byte(dat["msg"].(string)) + var sig = []byte(dat["sig"].(string)) + var address, err = crypto.Ecrecover(msg, sig) + if err != nil { + fmt.Println("The error is ") + fmt.Println(err) + } + s := string(address[:]) + fmt.Println("the address is ") + fmt.Println(s) + //fmt.Println(address) + //fmt.Println("Message is ", msg) } if err != nil { fmt.Println("Error reading:", err.Error()) From 0cbeb26f93f34eecbcfad6db126277f365e7b55e Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Sat, 30 Jun 2018 16:45:03 -0400 Subject: [PATCH 06/21] format the msg parameter to Ecrecover so it has 32 bytes --- shyftRingWalletConn/app.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index b03f308b1f..15a5bb8159 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -59,7 +59,8 @@ func handleRequest(conn net.Conn) { // and the bytes array of the signature var msg = []byte(dat["msg"].(string)) var sig = []byte(dat["sig"].(string)) - var address, err = crypto.Ecrecover(msg, sig) + new_msg := crypto.Keccak256(msg) + var address, err = crypto.Ecrecover(new_msg, sig) if err != nil { fmt.Println("The error is ") fmt.Println(err) From b09a39289aa5816cf834958b927b65ad0da201f1 Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Thu, 5 Jul 2018 13:50:08 -0400 Subject: [PATCH 07/21] more progress in verifying signature with ecrecover --- shyftRingWalletConn/app.go | 68 +++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index 15a5bb8159..68c9c7e195 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -7,7 +7,8 @@ import ( "fmt" "os" "encoding/json" - "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/common/hexutil" ) const ( @@ -16,6 +17,12 @@ const ( CONN_TYPE = "tcp" ) +// This gives context to the signed message and prevents signing of transactions. +func signHash(data []byte) []byte { + msg := fmt.Sprintf("\x19Ethereum Signed Message:\n%d%s", len(data), data) + return crypto.Keccak256([]byte(msg)) +} + func main() { l, err := net.Listen(CONN_TYPE, CONN_HOST+":"+CONN_PORT) @@ -57,17 +64,62 @@ func handleRequest(conn net.Conn) { //Ecrecover takes 2 args, bytes[] and bytes[] // we need to pass in the hash of the message as bytes // and the bytes array of the signature - var msg = []byte(dat["msg"].(string)) - var sig = []byte(dat["sig"].(string)) - new_msg := crypto.Keccak256(msg) - var address, err = crypto.Ecrecover(new_msg, sig) + var msg = dat["msg"].(string) + var sig = dat["sig"].(string) + fmt.Println("the first sig is ") + fmt.Println(sig) + var new_byte_array, err2 = hexutil.Decode(msg) + var new_sig_byte_array, err3 = hexutil.Decode(sig) + if err2 != nil { + fmt.Println("the err2 is ") + fmt.Println(err2) + } + if err3 != nil { + fmt.Println("the err3 is ") + fmt.Println(err3) + } + var fizz = hexutil.Bytes(new_byte_array) + var buzz = hexutil.Bytes(new_sig_byte_array) + buzz[64] -= 27 + fmt.Println("that bytes is") + fmt.Println(fizz) + //var bytes_msg = []byte(msg) + //var foo, err = hex.DecodeString(msg) + //fmt.Println("msg is ") + //fmt.Println(msg) + //fmt.Println("bytes_msg is ") + //fmt.Println(bytes_msg) + + //var sig = dat["sig"].(string) + //fmt.Println("The sig is ") + //fmt.Println(sig) + //decoded, er := hex.DecodeString(sig) + //if er != nil { + // log.Fatal(err) + //} + new_msg := signHash(fizz) + fmt.Println("the new_msg is ") + fmt.Println(new_msg) + fmt.Println("the buzz is ") + fmt.Println(buzz) + + var rpk, err = crypto.Ecrecover(new_msg, buzz) if err != nil { fmt.Println("The error is ") fmt.Println(err) } - s := string(address[:]) + + pubKey := crypto.ToECDSAPub(rpk) + recoveredAddr := crypto.PubkeyToAddress(*pubKey) fmt.Println("the address is ") - fmt.Println(s) + fmt.Println(recoveredAddr) + fmt.Println(recoveredAddr.Hex()) + //res, _ := new_add.MarshalText() + //fmt.Println(hexutil.Encode(address)) + //s := string(address[:]) + // + //fmt.Println(s) + //fmt.Println(address) //fmt.Println("Message is ", msg) } @@ -78,4 +130,4 @@ func handleRequest(conn net.Conn) { conn.Write([]byte("Message received.")) // Close the connection when you're done with it. conn.Close() -} +} \ No newline at end of file From 225b6e9c7d6991d366482031a61f6a3cdc7df87b Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Fri, 6 Jul 2018 14:34:33 -0400 Subject: [PATCH 08/21] ecrecover plain text message --- shyftRingWalletConn/app.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index 68c9c7e195..6a0b353b20 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -67,8 +67,15 @@ func handleRequest(conn net.Conn) { var msg = dat["msg"].(string) var sig = dat["sig"].(string) fmt.Println("the first sig is ") + fmt.Println(msg) fmt.Println(sig) - var new_byte_array, err2 = hexutil.Decode(msg) + //var new_byte_array, err2 = hexutil.Decode(msg) + var new_byte_array = []byte(msg) + var bazz = hexutil.Encode(new_byte_array) + fizz, err2 := hexutil.Decode(bazz) + fmt.Println("THE fizz is ") + fmt.Println(fizz) + //fizz = hexutil.Decode(fizz.String()) var new_sig_byte_array, err3 = hexutil.Decode(sig) if err2 != nil { fmt.Println("the err2 is ") @@ -78,11 +85,13 @@ func handleRequest(conn net.Conn) { fmt.Println("the err3 is ") fmt.Println(err3) } - var fizz = hexutil.Bytes(new_byte_array) + var buzz = hexutil.Bytes(new_sig_byte_array) buzz[64] -= 27 fmt.Println("that bytes is") fmt.Println(fizz) + + //var bytes_msg = []byte(msg) //var foo, err = hex.DecodeString(msg) //fmt.Println("msg is ") @@ -97,6 +106,7 @@ func handleRequest(conn net.Conn) { //if er != nil { // log.Fatal(err) //} + new_msg := signHash(fizz) fmt.Println("the new_msg is ") fmt.Println(new_msg) @@ -114,6 +124,8 @@ func handleRequest(conn net.Conn) { fmt.Println("the address is ") fmt.Println(recoveredAddr) fmt.Println(recoveredAddr.Hex()) + + //res, _ := new_add.MarshalText() //fmt.Println(hexutil.Encode(address)) //s := string(address[:]) From 527adcfee36258d8320ef194fffd38d772a76e6b Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Fri, 6 Jul 2018 14:44:51 -0400 Subject: [PATCH 09/21] rm comments and printlns --- shyftRingWalletConn/app.go | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index 6a0b353b20..7832ce88c4 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -61,21 +61,16 @@ func handleRequest(conn net.Conn) { fmt.Println(dat["address"]) fmt.Println(dat["msg"]) fmt.Println(dat["sig"]) - //Ecrecover takes 2 args, bytes[] and bytes[] - // we need to pass in the hash of the message as bytes - // and the bytes array of the signature + var msg = dat["msg"].(string) var sig = dat["sig"].(string) fmt.Println("the first sig is ") fmt.Println(msg) fmt.Println(sig) - //var new_byte_array, err2 = hexutil.Decode(msg) var new_byte_array = []byte(msg) var bazz = hexutil.Encode(new_byte_array) fizz, err2 := hexutil.Decode(bazz) - fmt.Println("THE fizz is ") - fmt.Println(fizz) - //fizz = hexutil.Decode(fizz.String()) + var new_sig_byte_array, err3 = hexutil.Decode(sig) if err2 != nil { fmt.Println("the err2 is ") @@ -91,22 +86,6 @@ func handleRequest(conn net.Conn) { fmt.Println("that bytes is") fmt.Println(fizz) - - //var bytes_msg = []byte(msg) - //var foo, err = hex.DecodeString(msg) - //fmt.Println("msg is ") - //fmt.Println(msg) - //fmt.Println("bytes_msg is ") - //fmt.Println(bytes_msg) - - //var sig = dat["sig"].(string) - //fmt.Println("The sig is ") - //fmt.Println(sig) - //decoded, er := hex.DecodeString(sig) - //if er != nil { - // log.Fatal(err) - //} - new_msg := signHash(fizz) fmt.Println("the new_msg is ") fmt.Println(new_msg) @@ -125,15 +104,6 @@ func handleRequest(conn net.Conn) { fmt.Println(recoveredAddr) fmt.Println(recoveredAddr.Hex()) - - //res, _ := new_add.MarshalText() - //fmt.Println(hexutil.Encode(address)) - //s := string(address[:]) - // - //fmt.Println(s) - - //fmt.Println(address) - //fmt.Println("Message is ", msg) } if err != nil { fmt.Println("Error reading:", err.Error()) From 9a4094f63456d15b1ace8fc45da47b8986581256 Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Fri, 6 Jul 2018 15:44:55 -0400 Subject: [PATCH 10/21] rm Printlns --- shyftRingWalletConn/app.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index 7832ce88c4..fa0479b064 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -65,8 +65,6 @@ func handleRequest(conn net.Conn) { var msg = dat["msg"].(string) var sig = dat["sig"].(string) fmt.Println("the first sig is ") - fmt.Println(msg) - fmt.Println(sig) var new_byte_array = []byte(msg) var bazz = hexutil.Encode(new_byte_array) fizz, err2 := hexutil.Decode(bazz) @@ -87,10 +85,6 @@ func handleRequest(conn net.Conn) { fmt.Println(fizz) new_msg := signHash(fizz) - fmt.Println("the new_msg is ") - fmt.Println(new_msg) - fmt.Println("the buzz is ") - fmt.Println(buzz) var rpk, err = crypto.Ecrecover(new_msg, buzz) if err != nil { From cda2a23d6d90b7410e0ec8962dd6967f18dbe338 Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Wed, 11 Jul 2018 21:58:48 -0400 Subject: [PATCH 11/21] rm printlns --- shyftRingWalletConn/app.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index fa0479b064..73637903d6 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -17,6 +17,9 @@ const ( CONN_TYPE = "tcp" ) +var testAddrHex = "970e8128ab834e8eac17ab8e3812f010678cf791" +var testPrivHex = "289c2857d4598e37fb9647507e47a309d6133539bf21a8b9cb6df88fd5232032" + // This gives context to the signed message and prevents signing of transactions. func signHash(data []byte) []byte { msg := fmt.Sprintf("\x19Ethereum Signed Message:\n%d%s", len(data), data) @@ -58,6 +61,8 @@ func handleRequest(conn net.Conn) { if err := json.Unmarshal(buf[:msg], &dat); err != nil { panic(err) } + + fmt.Println(dat["address"]) fmt.Println(dat["msg"]) fmt.Println(dat["sig"]) @@ -81,8 +86,6 @@ func handleRequest(conn net.Conn) { var buzz = hexutil.Bytes(new_sig_byte_array) buzz[64] -= 27 - fmt.Println("that bytes is") - fmt.Println(fizz) new_msg := signHash(fizz) @@ -95,7 +98,7 @@ func handleRequest(conn net.Conn) { pubKey := crypto.ToECDSAPub(rpk) recoveredAddr := crypto.PubkeyToAddress(*pubKey) fmt.Println("the address is ") - fmt.Println(recoveredAddr) + //fmt.Println(recoveredAddr) fmt.Println(recoveredAddr.Hex()) } @@ -105,5 +108,5 @@ func handleRequest(conn net.Conn) { // Send a response back to person contacting us. conn.Write([]byte("Message received.")) // Close the connection when you're done with it. - conn.Close() + //conn.Close() } \ No newline at end of file From 06685a7bf0389f60147d22d19e80797b614dfa46 Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Wed, 11 Jul 2018 23:25:30 -0400 Subject: [PATCH 12/21] send message back to client --- shyftRingWalletConn/app.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index 73637903d6..149ba188c0 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -7,8 +7,9 @@ import ( "fmt" "os" "encoding/json" - "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" ) const ( @@ -101,12 +102,24 @@ func handleRequest(conn net.Conn) { //fmt.Println(recoveredAddr) fmt.Println(recoveredAddr.Hex()) + conn.Write([]byte("Message received.")) + + key, _ := crypto.HexToECDSA(testPrivHex) + addr := common.HexToAddress(testAddrHex) + + new_msg2 := crypto.Keccak256([]byte("Message Received")) + new_sig , err := crypto.Sign(new_msg2, key) + + conn.Write([]byte("Message Received")) + conn.Write(new_msg2) + conn.Write(addr[:]) + conn.Write(new_sig) } if err != nil { fmt.Println("Error reading:", err.Error()) } // Send a response back to person contacting us. - conn.Write([]byte("Message received.")) + // Close the connection when you're done with it. //conn.Close() } \ No newline at end of file From 385ea04cf3afd53a60415ae6eefb25c0415d6040 Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Fri, 13 Jul 2018 15:41:42 -0400 Subject: [PATCH 13/21] more work --- shyftRingWalletConn/app.go | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index 149ba188c0..a4332bb0f7 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -8,10 +8,18 @@ import ( "os" "encoding/json" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/common" + //"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" + "bytes" ) +type Msg struct { + Message string `json:"message"` + HashedMessage string `json:"hashed_message"` + Signature string `json:"signature"` + Address string `json:"address"` +} + const ( CONN_HOST = "localhost" CONN_PORT = "3333" @@ -102,18 +110,36 @@ func handleRequest(conn net.Conn) { //fmt.Println(recoveredAddr) fmt.Println(recoveredAddr.Hex()) - conn.Write([]byte("Message received.")) + //conn.Write([]byte("Message received.")) key, _ := crypto.HexToECDSA(testPrivHex) - addr := common.HexToAddress(testAddrHex) + //addr := common.HexToAddress(testAddrHex) - new_msg2 := crypto.Keccak256([]byte("Message Received")) + f_msg := "Message Received" + first_message := []byte(f_msg) + new_msg2 := crypto.Keccak256(first_message) + + //send_message := append(new_msg2, []byte{byte(10)}...) new_sig , err := crypto.Sign(new_msg2, key) + hex_sig := hexutil.Encode(new_sig) + fmt.Println("THE hex sig is ", hex_sig) + + myNewMsg := Msg{f_msg, string(new_msg2[:]), string(new_sig[:]), testAddrHex} + reqBodyBytes := new(bytes.Buffer) + json.NewEncoder(reqBodyBytes).Encode(myNewMsg) + + fmt.Println([]byte("Message Received\n")) conn.Write([]byte("Message Received")) - conn.Write(new_msg2) - conn.Write(addr[:]) + conn.Write([]byte("\n")) conn.Write(new_sig) + conn.Write([]byte("\n")) + fmt.Println("PAUSE") + //time.Sleep(5 * time.Second) + //fmt.Println(send_message) + //conn.Write(send_message) + //conn.Write(addr[:]) + //conn.Write(append(reqBodyBytes.Bytes() ,[]byte{byte(10)}...)) } if err != nil { fmt.Println("Error reading:", err.Error()) From 6445f3c9abf6e2e4d385445536b19b07822b7868 Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Fri, 13 Jul 2018 16:01:05 -0400 Subject: [PATCH 14/21] log out hash of message as hex --- shyftRingWalletConn/app.go | 1 + 1 file changed, 1 insertion(+) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index a4332bb0f7..8dd8e848b5 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -118,6 +118,7 @@ func handleRequest(conn net.Conn) { f_msg := "Message Received" first_message := []byte(f_msg) new_msg2 := crypto.Keccak256(first_message) + fmt.Println("the hash is ", hexutil.Encode(new_msg2)) //send_message := append(new_msg2, []byte{byte(10)}...) new_sig , err := crypto.Sign(new_msg2, key) From 90087ff7015b05136ba0530a18353d79bbd36d9d Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Sat, 14 Jul 2018 16:27:43 -0400 Subject: [PATCH 15/21] change test keys and test message --- shyftRingWalletConn/app.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index 8dd8e848b5..26f0cbee32 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -26,8 +26,8 @@ const ( CONN_TYPE = "tcp" ) -var testAddrHex = "970e8128ab834e8eac17ab8e3812f010678cf791" -var testPrivHex = "289c2857d4598e37fb9647507e47a309d6133539bf21a8b9cb6df88fd5232032" +var testAddrHex = "14791697260E4c9A71f18484C9f997B308e59325" +var testPrivHex = "0123456789012345678901234567890123456789012345678901234567890123" // This gives context to the signed message and prevents signing of transactions. func signHash(data []byte) []byte { @@ -115,7 +115,7 @@ func handleRequest(conn net.Conn) { key, _ := crypto.HexToECDSA(testPrivHex) //addr := common.HexToAddress(testAddrHex) - f_msg := "Message Received" + f_msg := "Hello World" first_message := []byte(f_msg) new_msg2 := crypto.Keccak256(first_message) fmt.Println("the hash is ", hexutil.Encode(new_msg2)) @@ -130,8 +130,7 @@ func handleRequest(conn net.Conn) { reqBodyBytes := new(bytes.Buffer) json.NewEncoder(reqBodyBytes).Encode(myNewMsg) - fmt.Println([]byte("Message Received\n")) - conn.Write([]byte("Message Received")) + conn.Write([]byte(f_msg)) conn.Write([]byte("\n")) conn.Write(new_sig) conn.Write([]byte("\n")) From 8e0cfbc1a1f44bdda70a6c46e828068d8539206b Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Sun, 15 Jul 2018 09:32:22 -0400 Subject: [PATCH 16/21] add intArrToByteArr function for testing --- shyftRingWalletConn/app.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index 26f0cbee32..58e79622ad 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -148,4 +148,13 @@ func handleRequest(conn net.Conn) { // Close the connection when you're done with it. //conn.Close() -} \ No newline at end of file +} + +func intArrToByteArr(foo []int) []byte { + + ret := []byte{} + for _, value := range foo { + ret = append(ret, byte(value)) + } + return ret +} From 89e0479b7ae8c9dbb73c740de7be97ebb40717c3 Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Sun, 15 Jul 2018 15:05:29 -0400 Subject: [PATCH 17/21] add in additional message sent over tcp --- shyftRingWalletConn/app.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index 58e79622ad..9c24d6ea0d 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -130,6 +130,21 @@ func handleRequest(conn net.Conn) { reqBodyBytes := new(bytes.Buffer) json.NewEncoder(reqBodyBytes).Encode(myNewMsg) + //testArr := []byte{0xFF, 0x0a, 0xFE, 0x11, 0x0a, 0x0a, 0x0a, 0xF0, 0x0a, 0x1F, 0x22} + //testArr := []byte{0xFF, 0x0a, 0xFE, 0x11, 0x0a, 0x0a, 0xF0, 0x0a, 0x22} + //testArr := []byte{0xFF, 0x0a, 0xFE, 0xa, 0x22, 0xF3} + //testArr2 := []byte{0xF2, 0x0a, 0x1E} + //testArr3 := []byte{0xF1, 0x0a, 0xa0} + + //conn.Write(testArr) + //time.Sleep(1 * time.Second) + //conn.Write(testArr2) + //time.Sleep(1 * time.Second) + //conn.Write(testArr3) + + + conn.Write([]byte("Broadcasting Message")) + conn.Write([]byte("\n")) conn.Write([]byte(f_msg)) conn.Write([]byte("\n")) conn.Write(new_sig) From d25c879b59c9c8f13b1cd61bf4b986a5abe454fa Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Mon, 16 Jul 2018 11:09:57 -0400 Subject: [PATCH 18/21] receiving messages from wallet correctly --- shyftRingWalletConn/app.go | 199 +++++++++++++++++++------------------ 1 file changed, 102 insertions(+), 97 deletions(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index 9c24d6ea0d..617767b1ba 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -6,11 +6,10 @@ import ( "net" "fmt" "os" - "encoding/json" - "github.com/ethereum/go-ethereum/common/hexutil" //"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "bytes" + "github.com/ethereum/go-ethereum/common/hexutil" ) type Msg struct { @@ -59,106 +58,112 @@ func main() { // Handles incoming requests. func handleRequest(conn net.Conn) { // Make a buffer to hold incoming data. - buf := make([]byte, 1024) // Read the incoming connection into the buffer. - msg, err := conn.Read(buf) - if err == nil { - fmt.Println("Message is ", string(buf[:msg])) - var dat map[string]interface{} + go func() { + buf := make([]byte, 1024) + msgBuf := make([]byte, 0) + var prevMsg []byte + var addressOfClient []byte + var signatureFromClient []byte + var msgFromClient []byte - if err := json.Unmarshal(buf[:msg], &dat); err != nil { - panic(err) + for { + //var addressOfClient []byte + //var msgFromClient []byte + //var sigFromClient []byte + msg, err := conn.Read(buf) + + if err == nil { + fmt.Println("Message is ", buf[:msg]) + fmt.Println("The old msg buf is ", msgBuf) + msgBuf = append(msgBuf, buf[:msg]...) + fmt.Println("THE msgBuf is ") + fmt.Println(msgBuf) + //fmt.Println("Message is ", string(buf[:msg])) + } + index := bytes.IndexByte(msgBuf, 0x0a) + for index != -1 { + newMsg := msgBuf[:index] + rest := msgBuf[(index + 1):len(msgBuf)] + msgBuf = rest + index = bytes.IndexByte(msgBuf, 0x0a) + fmt.Println("new msg") + fmt.Println(newMsg) + fmt.Println(string(newMsg[:])) + fmt.Println("prev message ", prevMsg) + fmt.Println((prevMsg == nil)) + if prevMsg != nil { + fmt.Println("not nil") + s := string(prevMsg[:]) + if s == "-- ADDRESS --" { + fmt.Println("the address should be ") + fmt.Println(newMsg) + addressOfClient = newMsg + } + if s == "-- SIGNATURE --" { + signatureFromClient = newMsg + } + if s == "-- MESSAGE --" { + msgFromClient = newMsg + } + prevMsg = nil + } else { + fmt.Println("nil") + prevMsg = newMsg + fmt.Println("prev message is in else block ", prevMsg) + fmt.Println("index ", index) + fmt.Println("msgBuf ", msgBuf) + fmt.Println(bytes.IndexByte(msgBuf, 0x0a)) + + } + } + + if(addressOfClient != nil && signatureFromClient != nil && msgFromClient != nil ){ + fmt.Println("ALL COMPONENTS RECEIVED") + msg := string(msgFromClient[:]) + //new_msg := signHash(msgFromClient) + sig := string(signatureFromClient[:]) + addr := string(addressOfClient[:]) + fmt.Println(addr) + fmt.Println(msg) + fmt.Println(sig) + + var new_byte_array = []byte(msg) + var bazz = hexutil.Encode(new_byte_array) + fizz, err2 := hexutil.Decode(bazz) + + var new_sig_byte_array, err3 = hexutil.Decode(sig) + if err2 != nil { + fmt.Println("the err2 is ") + fmt.Println(err2) + } + if err3 != nil { + fmt.Println("the err3 is ") + fmt.Println(err3) + } + + var buzz = hexutil.Bytes(new_sig_byte_array) + buzz[64] -= 27 + + new_msg := signHash(fizz) + + var rpk, err = crypto.Ecrecover(new_msg, buzz) + if err != nil { + fmt.Println("The error is ") + fmt.Println(err) + } + + pubKey := crypto.ToECDSAPub(rpk) + recoveredAddr := crypto.PubkeyToAddress(*pubKey) + fmt.Println("the address is ") + //fmt.Println(recoveredAddr) + fmt.Println(recoveredAddr.Hex()) + } } + }() + conn.Write([]byte{byte(0x0f)}) - - fmt.Println(dat["address"]) - fmt.Println(dat["msg"]) - fmt.Println(dat["sig"]) - - var msg = dat["msg"].(string) - var sig = dat["sig"].(string) - fmt.Println("the first sig is ") - var new_byte_array = []byte(msg) - var bazz = hexutil.Encode(new_byte_array) - fizz, err2 := hexutil.Decode(bazz) - - var new_sig_byte_array, err3 = hexutil.Decode(sig) - if err2 != nil { - fmt.Println("the err2 is ") - fmt.Println(err2) - } - if err3 != nil { - fmt.Println("the err3 is ") - fmt.Println(err3) - } - - var buzz = hexutil.Bytes(new_sig_byte_array) - buzz[64] -= 27 - - new_msg := signHash(fizz) - - var rpk, err = crypto.Ecrecover(new_msg, buzz) - if err != nil { - fmt.Println("The error is ") - fmt.Println(err) - } - - pubKey := crypto.ToECDSAPub(rpk) - recoveredAddr := crypto.PubkeyToAddress(*pubKey) - fmt.Println("the address is ") - //fmt.Println(recoveredAddr) - fmt.Println(recoveredAddr.Hex()) - - //conn.Write([]byte("Message received.")) - - key, _ := crypto.HexToECDSA(testPrivHex) - //addr := common.HexToAddress(testAddrHex) - - f_msg := "Hello World" - first_message := []byte(f_msg) - new_msg2 := crypto.Keccak256(first_message) - fmt.Println("the hash is ", hexutil.Encode(new_msg2)) - - //send_message := append(new_msg2, []byte{byte(10)}...) - new_sig , err := crypto.Sign(new_msg2, key) - hex_sig := hexutil.Encode(new_sig) - fmt.Println("THE hex sig is ", hex_sig) - - - myNewMsg := Msg{f_msg, string(new_msg2[:]), string(new_sig[:]), testAddrHex} - reqBodyBytes := new(bytes.Buffer) - json.NewEncoder(reqBodyBytes).Encode(myNewMsg) - - //testArr := []byte{0xFF, 0x0a, 0xFE, 0x11, 0x0a, 0x0a, 0x0a, 0xF0, 0x0a, 0x1F, 0x22} - //testArr := []byte{0xFF, 0x0a, 0xFE, 0x11, 0x0a, 0x0a, 0xF0, 0x0a, 0x22} - //testArr := []byte{0xFF, 0x0a, 0xFE, 0xa, 0x22, 0xF3} - //testArr2 := []byte{0xF2, 0x0a, 0x1E} - //testArr3 := []byte{0xF1, 0x0a, 0xa0} - - //conn.Write(testArr) - //time.Sleep(1 * time.Second) - //conn.Write(testArr2) - //time.Sleep(1 * time.Second) - //conn.Write(testArr3) - - - conn.Write([]byte("Broadcasting Message")) - conn.Write([]byte("\n")) - conn.Write([]byte(f_msg)) - conn.Write([]byte("\n")) - conn.Write(new_sig) - conn.Write([]byte("\n")) - fmt.Println("PAUSE") - //time.Sleep(5 * time.Second) - //fmt.Println(send_message) - //conn.Write(send_message) - //conn.Write(addr[:]) - //conn.Write(append(reqBodyBytes.Bytes() ,[]byte{byte(10)}...)) - } - if err != nil { - fmt.Println("Error reading:", err.Error()) - } // Send a response back to person contacting us. // Close the connection when you're done with it. From a2a6a57c700b901114debd427d6d58d1d0bf0e63 Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Mon, 16 Jul 2018 11:23:42 -0400 Subject: [PATCH 19/21] fix var names --- shyftRingWalletConn/app.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index 617767b1ba..ced36f78f7 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -129,11 +129,11 @@ func handleRequest(conn net.Conn) { fmt.Println(msg) fmt.Println(sig) - var new_byte_array = []byte(msg) - var bazz = hexutil.Encode(new_byte_array) - fizz, err2 := hexutil.Decode(bazz) + var msgByteArr = []byte(msg) + var hexMsg = hexutil.Encode(msgByteArr) + fizz, err2 := hexutil.Decode(hexMsg) - var new_sig_byte_array, err3 = hexutil.Decode(sig) + var sigByteArr, err3 = hexutil.Decode(sig) if err2 != nil { fmt.Println("the err2 is ") fmt.Println(err2) @@ -143,12 +143,12 @@ func handleRequest(conn net.Conn) { fmt.Println(err3) } - var buzz = hexutil.Bytes(new_sig_byte_array) - buzz[64] -= 27 + var sigHex = hexutil.Bytes(sigByteArr) + sigHex[64] -= 27 - new_msg := signHash(fizz) + signedMsgHash := signHash(fizz) - var rpk, err = crypto.Ecrecover(new_msg, buzz) + var rpk, err = crypto.Ecrecover(signedMsgHash, sigHex) if err != nil { fmt.Println("The error is ") fmt.Println(err) From d7b70c03b95d1e540d0018b08052ab78a677d4c6 Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Mon, 16 Jul 2018 11:38:22 -0400 Subject: [PATCH 20/21] respond back to client with sig --- shyftRingWalletConn/app.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index ced36f78f7..3ff6175115 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -162,7 +162,31 @@ func handleRequest(conn net.Conn) { } } }() - conn.Write([]byte{byte(0x0f)}) + go func() { + key, _ := crypto.HexToECDSA(testPrivHex) + //addr := common.HexToAddress(testAddrHex) + + f_msg := "Hello World" + first_message := []byte(f_msg) + new_msg2 := crypto.Keccak256(first_message) + fmt.Println("the hash is ", hexutil.Encode(new_msg2)) + + //send_message := append(new_msg2, []byte{byte(10)}...) + new_sig , err := crypto.Sign(new_msg2, key) + if err != nil { + fmt.Println("The crypto.Sign err is ", err) + } + hex_sig := hexutil.Encode(new_sig) + fmt.Println("THE hex sig is ", hex_sig) + + conn.Write([]byte("Broadcasting Message")) + conn.Write([]byte("\n")) + conn.Write([]byte(f_msg)) + conn.Write([]byte("\n")) + conn.Write(new_sig) + conn.Write([]byte("\n")) + }() + //conn.Write([]byte{byte(0x0f)}) // Send a response back to person contacting us. From f6fee7e70ae788163416076b3f78d46eb7fa3948 Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Mon, 16 Jul 2018 16:22:43 -0400 Subject: [PATCH 21/21] cleaned up code and removed msg type --- shyftRingWalletConn/app.go | 82 +++++--------------------------------- 1 file changed, 9 insertions(+), 73 deletions(-) diff --git a/shyftRingWalletConn/app.go b/shyftRingWalletConn/app.go index 3ff6175115..0da4d787e3 100644 --- a/shyftRingWalletConn/app.go +++ b/shyftRingWalletConn/app.go @@ -12,13 +12,6 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" ) -type Msg struct { - Message string `json:"message"` - HashedMessage string `json:"hashed_message"` - Signature string `json:"signature"` - Address string `json:"address"` -} - const ( CONN_HOST = "localhost" CONN_PORT = "3333" @@ -69,18 +62,10 @@ func handleRequest(conn net.Conn) { var msgFromClient []byte for { - //var addressOfClient []byte - //var msgFromClient []byte - //var sigFromClient []byte msg, err := conn.Read(buf) if err == nil { - fmt.Println("Message is ", buf[:msg]) - fmt.Println("The old msg buf is ", msgBuf) msgBuf = append(msgBuf, buf[:msg]...) - fmt.Println("THE msgBuf is ") - fmt.Println(msgBuf) - //fmt.Println("Message is ", string(buf[:msg])) } index := bytes.IndexByte(msgBuf, 0x0a) for index != -1 { @@ -88,17 +73,9 @@ func handleRequest(conn net.Conn) { rest := msgBuf[(index + 1):len(msgBuf)] msgBuf = rest index = bytes.IndexByte(msgBuf, 0x0a) - fmt.Println("new msg") - fmt.Println(newMsg) - fmt.Println(string(newMsg[:])) - fmt.Println("prev message ", prevMsg) - fmt.Println((prevMsg == nil)) if prevMsg != nil { - fmt.Println("not nil") s := string(prevMsg[:]) if s == "-- ADDRESS --" { - fmt.Println("the address should be ") - fmt.Println(newMsg) addressOfClient = newMsg } if s == "-- SIGNATURE --" { @@ -109,67 +86,41 @@ func handleRequest(conn net.Conn) { } prevMsg = nil } else { - fmt.Println("nil") prevMsg = newMsg - fmt.Println("prev message is in else block ", prevMsg) - fmt.Println("index ", index) - fmt.Println("msgBuf ", msgBuf) - fmt.Println(bytes.IndexByte(msgBuf, 0x0a)) - } } - if(addressOfClient != nil && signatureFromClient != nil && msgFromClient != nil ){ - fmt.Println("ALL COMPONENTS RECEIVED") - msg := string(msgFromClient[:]) - //new_msg := signHash(msgFromClient) + if addressOfClient != nil && signatureFromClient != nil && msgFromClient != nil { sig := string(signatureFromClient[:]) - addr := string(addressOfClient[:]) - fmt.Println(addr) - fmt.Println(msg) - fmt.Println(sig) + var sigByteArr, error = hexutil.Decode(sig) - var msgByteArr = []byte(msg) - var hexMsg = hexutil.Encode(msgByteArr) - fizz, err2 := hexutil.Decode(hexMsg) - - var sigByteArr, err3 = hexutil.Decode(sig) - if err2 != nil { - fmt.Println("the err2 is ") - fmt.Println(err2) - } - if err3 != nil { - fmt.Println("the err3 is ") - fmt.Println(err3) + if error != nil { + fmt.Println(error) } var sigHex = hexutil.Bytes(sigByteArr) sigHex[64] -= 27 - signedMsgHash := signHash(fizz) + signedMsgHash := signHash(msgFromClient) var rpk, err = crypto.Ecrecover(signedMsgHash, sigHex) if err != nil { - fmt.Println("The error is ") fmt.Println(err) } pubKey := crypto.ToECDSAPub(rpk) recoveredAddr := crypto.PubkeyToAddress(*pubKey) - fmt.Println("the address is ") - //fmt.Println(recoveredAddr) - fmt.Println(recoveredAddr.Hex()) + fmt.Println("ADDRESS IS ::", recoveredAddr.Hex()) } } }() go func() { key, _ := crypto.HexToECDSA(testPrivHex) - //addr := common.HexToAddress(testAddrHex) f_msg := "Hello World" first_message := []byte(f_msg) new_msg2 := crypto.Keccak256(first_message) - fmt.Println("the hash is ", hexutil.Encode(new_msg2)) + fmt.Println("HASH IS ::", hexutil.Encode(new_msg2)) //send_message := append(new_msg2, []byte{byte(10)}...) new_sig , err := crypto.Sign(new_msg2, key) @@ -177,7 +128,7 @@ func handleRequest(conn net.Conn) { fmt.Println("The crypto.Sign err is ", err) } hex_sig := hexutil.Encode(new_sig) - fmt.Println("THE hex sig is ", hex_sig) + fmt.Println("HEX SIG ::", hex_sig) conn.Write([]byte("Broadcasting Message")) conn.Write([]byte("\n")) @@ -186,19 +137,4 @@ func handleRequest(conn net.Conn) { conn.Write(new_sig) conn.Write([]byte("\n")) }() - //conn.Write([]byte{byte(0x0f)}) - - // Send a response back to person contacting us. - - // Close the connection when you're done with it. - //conn.Close() -} - -func intArrToByteArr(foo []int) []byte { - - ret := []byte{} - for _, value := range foo { - ret = append(ret, byte(value)) - } - return ret -} +} \ No newline at end of file