-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for data transfer encryption via rc4 and aes
- Loading branch information
Matthew Topol
committed
Jul 15, 2020
1 parent
15f6da0
commit 79a050c
Showing
20 changed files
with
1,263 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package rpc | ||
|
||
import ( | ||
"crypto/aes" | ||
"crypto/cipher" | ||
"net" | ||
"time" | ||
) | ||
|
||
type aesConn struct { | ||
conn net.Conn | ||
|
||
encStream cipher.StreamWriter | ||
decStream cipher.StreamReader | ||
} | ||
|
||
func newAesConn(conn net.Conn, inKey, outKey, inIv, outIv []byte) (net.Conn, error) { | ||
c := &aesConn{conn: conn} | ||
|
||
encBlock, err := aes.NewCipher(inKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
decBlock, err := aes.NewCipher(outKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
c.encStream = cipher.StreamWriter{S: cipher.NewCTR(encBlock, inIv), W: conn} | ||
c.decStream = cipher.StreamReader{S: cipher.NewCTR(decBlock, outIv), R: conn} | ||
return c, nil | ||
} | ||
|
||
func (d *aesConn) Close() error { | ||
return d.conn.Close() | ||
} | ||
|
||
func (d *aesConn) LocalAddr() net.Addr { | ||
return d.conn.LocalAddr() | ||
} | ||
|
||
func (d *aesConn) RemoteAddr() net.Addr { | ||
return d.conn.RemoteAddr() | ||
} | ||
|
||
func (d *aesConn) SetDeadline(t time.Time) error { | ||
return d.conn.SetDeadline(t) | ||
} | ||
|
||
func (d *aesConn) SetReadDeadline(t time.Time) error { | ||
return d.conn.SetReadDeadline(t) | ||
} | ||
|
||
func (d *aesConn) SetWriteDeadline(t time.Time) error { | ||
return d.conn.SetWriteDeadline(t) | ||
} | ||
|
||
func (d *aesConn) Write(b []byte) (n int, err error) { | ||
return d.encStream.Write(b) | ||
} | ||
|
||
func (d *aesConn) Read(b []byte) (n int, err error) { | ||
return d.decStream.Read(b) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.