Documentation
¶
Index ¶
- Constants
- func CreateAESKey() []byte
- func DecryptAESGCM(encryptedBytes, key []byte) ([]byte, error)
- func DecryptOAEP(hash hash.Hash, random io.Reader, private *rsa.PrivateKey, msg []byte, ...) ([]byte, error)
- func EncryptAESGCM(rawBytes, key []byte) ([]byte, error)
- func EncryptOAEP(hash hash.Hash, random io.Reader, public *rsa.PublicKey, msg, label []byte) ([]byte, error)
- func GetDirAvailableSpace(dir string) (uint64, error)
- func ParsePrivateKey(pemBytes []byte) (*rsa.PrivateKey, error)
- func ParsePrivateKeyWithPassphrase(pemBytes []byte, passphrase []byte) (*rsa.PrivateKey, error)
- func ParsePublicKey(pemBytes []byte) (*rsa.PublicKey, error)
- type AckFrame
- type AckQueue
- type Client
- type ClientConfig
- type Close
- type Frame
- type HandshakeAck
- type HandshakeInit
- type MsgTypes
- type Packet
- type PacketAck
- type PacketQueue
- type PacketQueueItem
- type Ping
- type Pong
- type PutFileTransferInit
- type QueueListener
- type RcvPacketQueue
- type Server
- type ServerConfig
- type StatusTypes
- type TCPMsg
- type TransferAck
- type TransferComplete
- type TransferCompleteAck
- type TransferFrame
- type TransferTypes
- type UDPClient
- type UDPServer
Constants ¶
const ( ErrNoPrivateKey = bg.Error("no private key found") ErrInvalidResponse = bg.Error("invalid response from server") ErrWeakSessionkey = bg.Error("weak session key") )
const ( ErrNoKeyFound = bg.Error("no key found") ErrPassphraseMissing = bg.Error("this private key is passphrase protected") ErrNotEncryptedKey = bg.Error("not an encrypted key") ErrUnsupportedKey = bg.Error("unsupported key type") )
const ( ErrVersionMismatch = bg.Error("protocol version mismatch") ErrWeakHandshakeKey = bg.Error("weak handshake key") ErrUnsupportedType = bg.Error("unsupported transfer type") ErrFileTooLarge = bg.Error("file size is too large") )
const (
ErrAlreadySubscribed = bg.Error("already subscribed to the queue")
)
const (
ErrInvalidChecksum = bg.Error("invalid checksum")
)
Variables ¶
This section is empty.
Functions ¶
func DecryptAESGCM ¶
DecryptAESGCM will take ciphered data in bytes and an encryption key in bytes and decrypt the data using AES-GCM techniques
func DecryptOAEP ¶
func DecryptOAEP(hash hash.Hash, random io.Reader, private *rsa.PrivateKey, msg []byte, label []byte) ([]byte, error)
DecryptOAEP is a wrapper function over the crypto/rsa package function of the same name It reconstructs longer messages from chunks
func EncryptAESGCM ¶
EncryptAESGCM takes raw bytes and an encryption key and encrypts the data using AES-GCM techniques
func EncryptOAEP ¶
func EncryptOAEP(hash hash.Hash, random io.Reader, public *rsa.PublicKey, msg, label []byte) ([]byte, error)
EncryptOAEP is a wrapper function over the crypto/rsa package function of the same name It divides longer messages into chunks
func GetDirAvailableSpace ¶
GetDirAvailableSpace will check the available space within a specified directory
func ParsePrivateKey ¶
func ParsePrivateKey(pemBytes []byte) (*rsa.PrivateKey, error)
ParsePrivateKey returns a private key from a PEM encoded private key. It only supports RSA. If the private key is encrypted, it will return an error
func ParsePrivateKeyWithPassphrase ¶
func ParsePrivateKeyWithPassphrase(pemBytes []byte, passphrase []byte) (*rsa.PrivateKey, error)
ParsePrivateKeyWithPassphrase returns an RSA private key from a PEM encoded private key and passphrase.
Types ¶
type AckFrame ¶
type AckFrame struct { Status StatusTypes `json:"status"` // OK or ERROR Payload []byte `json:"payload"` // The specific ACK JSON object serialized if OK or an error message }
type AckQueue ¶
type Client ¶
type ClientConfig ¶
func (*ClientConfig) AddHostKey ¶
func (c *ClientConfig) AddHostKey(key *rsa.PrivateKey)
AddHostKey is a method for registering a private key in the server config
type Frame ¶
type Frame struct { Type MsgTypes `json:"type"` // Indicator for msg receiver Payload string `json:"payload"` // Encrypted and base64 encoded }
What is sent over the wire TCP
type HandshakeAck ¶
type HandshakeAck struct { SessionKey []byte `json:"session_key"` // Server generated, symmetric key encrypted with client pubkey Signature []byte `json:"signature"` // Server signs the serialized and hashed version of this message with their private key }
Message is encrypted with handshake key
func (HandshakeAck) Serialize ¶
func (h HandshakeAck) Serialize() []byte
func (HandshakeAck) Sign ¶
func (h HandshakeAck) Sign(privateKey *rsa.PrivateKey, rand io.Reader) ([]byte, error)
func (HandshakeAck) String ¶
func (h HandshakeAck) String() string
type HandshakeInit ¶
type HandshakeInit struct { Version uint8 `json:"version"` // Protocol version HandshakeKey []byte `json:"handshake_key"` // Client generated, symmetric key encrypted with servers pubkey Payload []byte `json:"payload"` // Clients pubkey encrypted with handshake key Signature []byte `json:"signature"` // Client signs the serialized and hashed version of this message with their private key }
func (HandshakeInit) Serialize ¶
func (h HandshakeInit) Serialize() []byte
func (HandshakeInit) Sign ¶
func (h HandshakeInit) Sign(privateKey *rsa.PrivateKey, rand io.Reader) ([]byte, error)
func (HandshakeInit) String ¶
func (h HandshakeInit) String() string
type Packet ¶
Packet encrypted with session key, sent over UDP
func DecryptPacket ¶
DecryptPacket will take an encrypted packet, decrypt it and parse it
type PacketQueue ¶
type PacketQueue struct { Queue []PacketQueueItem sync.RWMutex }
func (*PacketQueue) Ack ¶
func (q *PacketQueue) Ack(orderNumber int)
Ack changes the Acked status of a packet to true
func (*PacketQueue) CanSend ¶
func (q *PacketQueue) CanSend(orderNumber int, timeout time.Duration) bool
CanSend determines if a given packet has timed out and if it hasn't already been acked by the server
func (*PacketQueue) IsAck ¶
func (q *PacketQueue) IsAck(orderNumber int) bool
IsAck determines if a given packet was acked by the server
type PacketQueueItem ¶
type PutFileTransferInit ¶
type PutFileTransferInit struct { FileSize uint64 `json:"file_size"` // bytes FileName string `json:"file_name"` // filename.ext NumberOfPackets uint32 `json:"number_of_packets"` // total number of packets to be transfered }
encrypted with session key
func (PutFileTransferInit) Serialize ¶
func (t PutFileTransferInit) Serialize() []byte
func (PutFileTransferInit) String ¶
func (t PutFileTransferInit) String() string
type QueueListener ¶
type RcvPacketQueue ¶
func NewRcvPacketQueue ¶
func NewRcvPacketQueue() *RcvPacketQueue
NewRcvPacketQueue instantiates a new ByteQueue struct
func (*RcvPacketQueue) Pop ¶
func (q *RcvPacketQueue) Pop() Packet
Pop returns the first item in the queue and deletes it from the queue
func (*RcvPacketQueue) Push ¶
func (q *RcvPacketQueue) Push(v Packet)
Push adds a new item to the back of the queue
type Server ¶
type Server struct { Version uint8 // contains filtered or unexported fields }
func NewServer ¶
func NewServer(config *ServerConfig) *Server
NewServer creates a new instance of Server
type ServerConfig ¶
type ServerConfig struct { Rand io.Reader WorkingDir string // contains filtered or unexported fields }
func (*ServerConfig) AddHostKey ¶
func (s *ServerConfig) AddHostKey(key *rsa.PrivateKey)
AddHostKey is a method for registering a private key in the server config
type TransferAck ¶
type TransferAck struct {
UDPPort uint16 `json:"udp_port"` // Port that the server will listen on for UDP traffic
}
encrypted with session key
func (TransferAck) Serialize ¶
func (t TransferAck) Serialize() []byte
type TransferComplete ¶
type TransferComplete struct {
PacketsToResend []uint32 `json:"packets_to_resend"` // array is empty if transfer is successful
}
Encrypted with session key
func (TransferComplete) Serialize ¶
func (t TransferComplete) Serialize() []byte
type TransferCompleteAck ¶
type TransferCompleteAck struct{}
Encrypted with session key
func (TransferCompleteAck) Serialize ¶
func (t TransferCompleteAck) Serialize() []byte
type TransferFrame ¶
type TransferFrame struct { Type TransferTypes `json:"transfer_type"` // determines transfer type so server can properly handle the message Payload []byte `json:"payload"` // metadata about the particular transfer type }
func (TransferFrame) Serialize ¶
func (t TransferFrame) Serialize() []byte
func (TransferFrame) String ¶
func (t TransferFrame) String() string
type TransferTypes ¶
type TransferTypes uint8
const (
PUT_FILE TransferTypes = iota // Can support other TransferTypes in the future
)
type UDPClient ¶
type UDPClient struct {
// contains filtered or unexported fields
}
func NewUDPClient ¶
NewUDPClient will initialize the UDP client