Skip to content

Commit

Permalink
pass test
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasen committed Dec 6, 2015
1 parent b20efed commit 6d68cd2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ func decryptBackendAddr(line []byte) ([]byte, error) {
if ok {
return addr, nil
}

// Try to decrypt it (AES)
addr, err := _Aes256CBC.Decrypt(_SecretPassphase, line)
if err != nil {
panic(err)
return nil, err
}

Expand Down Expand Up @@ -193,7 +195,8 @@ func handleConn(c net.Conn) {
}

if bytes.HasPrefix(bytes.ToLower(line), _cipherRequestHeader) {
cipherAddr = bytes.TrimSpace(line[(len(_cipherRequestHeader) + 1):])
// copy instead of point
cipherAddr = []byte(string(bytes.TrimSpace(line[(len(_cipherRequestHeader) + 1):])))
continue
}

Expand Down
48 changes: 24 additions & 24 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,30 @@ func testProtocol(cipherAddr []byte) {
}
}

func TestHTTPServer(t *testing.T) {
cipherAddr, err := encryptText(_httpServerAddr, _secret)
if err != nil {
panic(err)
}

client := &http.Client{}
req, _ := http.NewRequest("GET", "http://"+string(_defaultFrontdAddr), nil)
req.Header.Set(string(_cipherRequestHeader), string(cipherAddr))
res, err := client.Do(req)
if err != nil {
panic(err)
}

b, err := ioutil.ReadAll(res.Body)
if err != nil {
panic(err)
}

if bytes.Compare(b, []byte("OK")) != 0 {
t.Fail()
}
}

func TestTextDecryptAES(t *testing.T) {
o := aes256cbc.New()

Expand Down Expand Up @@ -204,30 +228,6 @@ func TestProtocolDecrypt(*testing.T) {
testProtocol(b)
}

func TestHTTPServer(t *testing.T) {
cipherAddr, err := encryptText(_httpServerAddr, _secret)
if err != nil {
panic(err)
}

client := &http.Client{}
req, _ := http.NewRequest("GET", "http://"+string(_defaultFrontdAddr), nil)
req.Header.Set(string(_cipherRequestHeader), string(cipherAddr))
res, err := client.Do(req)
if err != nil {
panic(err)
}

b, err := ioutil.ReadAll(res.Body)
if err != nil {
panic(err)
}

if bytes.Compare(b, []byte("OK")) != 0 {
t.Fail()
}
}

// TODO: test decryption with extra bytes in packet and check data

// TODO: test decryption with seperated packet simulate loss connection and check data
Expand Down

0 comments on commit 6d68cd2

Please sign in to comment.