rename Handshake to CryptoSetup

This commit is contained in:
Lucas Clemente
2016-04-15 22:27:14 +02:00
parent 20b48c5432
commit 91e3ac4f26
2 changed files with 15 additions and 15 deletions

View File

@@ -9,17 +9,17 @@ import (
"github.com/lucas-clemente/quic-go/protocol"
)
// The Handshake handles all things crypto for the Session
type Handshake struct {
// The CryptoSetup handles all things crypto for the Session
type CryptoSetup struct {
connID protocol.ConnectionID
version protocol.VersionNumber
aead crypto.AEAD
scfg *ServerConfig
}
// NewHandshake creates a new Handshake instance
func NewHandshake(connID protocol.ConnectionID, version protocol.VersionNumber, scfg *ServerConfig) *Handshake {
return &Handshake{
// NewCryptoSetup creates a new CryptoSetup instance
func NewCryptoSetup(connID protocol.ConnectionID, version protocol.VersionNumber, scfg *ServerConfig) *CryptoSetup {
return &CryptoSetup{
connID: connID,
version: version,
aead: &crypto.NullAEAD{},
@@ -28,17 +28,17 @@ func NewHandshake(connID protocol.ConnectionID, version protocol.VersionNumber,
}
// Open a message
func (h *Handshake) Open(packetNumber protocol.PacketNumber, associatedData []byte, ciphertext io.Reader) (*bytes.Reader, error) {
func (h *CryptoSetup) Open(packetNumber protocol.PacketNumber, associatedData []byte, ciphertext io.Reader) (*bytes.Reader, error) {
return h.aead.Open(packetNumber, associatedData, ciphertext)
}
// Seal a messageTag
func (h *Handshake) Seal(packetNumber protocol.PacketNumber, b *bytes.Buffer, associatedData []byte, plaintext []byte) {
func (h *CryptoSetup) Seal(packetNumber protocol.PacketNumber, b *bytes.Buffer, associatedData []byte, plaintext []byte) {
h.aead.Seal(packetNumber, b, associatedData, plaintext)
}
// HandleCryptoMessage handles the crypto handshake and returns the answer
func (h *Handshake) HandleCryptoMessage(data []byte) ([]byte, error) {
func (h *CryptoSetup) HandleCryptoMessage(data []byte) ([]byte, error) {
messageTag, cryptoData, err := ParseHandshakeMessage(data)
if err != nil {
return nil, err
@@ -65,16 +65,17 @@ func (h *Handshake) HandleCryptoMessage(data []byte) ([]byte, error) {
if h.version > protocol.VersionNumber(30) {
chloOrNil = data
}
proof, err := h.scfg.Sign(chloOrNil)
if err != nil {
return nil, err
}
var serverReply bytes.Buffer
WriteHandshakeMessage(&serverReply, TagREJ, map[Tag][]byte{
TagSCFG: h.scfg.Get(),
TagCERT: h.scfg.GetCertCompressed(),
TagPROF: proof,
})
return serverReply.Bytes(), nil
}

View File

@@ -22,7 +22,7 @@ type Session struct {
CurrentRemoteAddr *net.UDPAddr
ServerConfig *handshake.ServerConfig
hshk *handshake.Handshake
cryptoSetup *handshake.CryptoSetup
Entropy EntropyAccumulator
@@ -38,7 +38,7 @@ func NewSession(conn *net.UDPConn, v protocol.VersionNumber, connectionID protoc
VersionNumber: v,
ConnectionID: connectionID,
ServerConfig: sCfg,
hshk: handshake.NewHandshake(connectionID, v, sCfg),
cryptoSetup: handshake.NewCryptoSetup(connectionID, v, sCfg),
streamCallback: streamCallback,
}
}
@@ -50,7 +50,7 @@ func (s *Session) HandlePacket(addr *net.UDPAddr, publicHeaderBinary []byte, pub
s.CurrentRemoteAddr = addr
}
r, err := s.hshk.Open(publicHeader.PacketNumber, publicHeaderBinary, r)
r, err := s.cryptoSetup.Open(publicHeader.PacketNumber, publicHeaderBinary, r)
if err != nil {
return err
}
@@ -93,14 +93,13 @@ func (s *Session) HandlePacket(addr *net.UDPAddr, publicHeaderBinary []byte, pub
}
if frame.StreamID == 1 {
reply, err := s.hshk.HandleCryptoMessage(frame.Data)
reply, err := s.cryptoSetup.HandleCryptoMessage(frame.Data)
if err != nil {
return err
}
if reply != nil {
s.SendFrames([]Frame{&StreamFrame{StreamID: 1, Data: reply}})
}
// TODO: Send reply
} else {
replyFrames := s.streamCallback(frame)
if replyFrames != nil {
@@ -163,7 +162,7 @@ func (s *Session) SendFrames(frames []Frame) error {
return err
}
s.hshk.Seal(s.lastSentPacketNumber, &fullReply, fullReply.Bytes(), framesData.Bytes())
s.cryptoSetup.Seal(s.lastSentPacketNumber, &fullReply, fullReply.Bytes(), framesData.Bytes())
fmt.Printf("Sending %d bytes to %v\n", len(fullReply.Bytes()), s.CurrentRemoteAddr)
_, err := s.Connection.WriteToUDP(fullReply.Bytes(), s.CurrentRemoteAddr)