Documentation ¶
Overview ¶
Package protocol provides the protocol used by the server and the client.
Index ¶
- func WithProcessRequestExpectReply(expectReply bool) func(*ProcessRequestOptions)
- type Action
- type ErrorCode
- type ErrorResponse
- type FetchKeyRequest
- type FetchKeyResponse
- type HashType
- type HelloRequest
- type HelloResponse
- type KeyAlgorithm
- type ProcessRequest
- type ProcessRequestOptions
- type ProcessResponse
- type RequestCommon
- type ResponseCommon
- type SetupRequest
- type SetupResponse
- type Version
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithProcessRequestExpectReply ¶
func WithProcessRequestExpectReply(expectReply bool) func(*ProcessRequestOptions)
WithProcessRequestExpectReply indicates if the client is expecting a reply from the server. This is useful to avoid the client to wait for a reply when the server doesn't need to send one. By default is true.
Types ¶
type Action ¶
type Action uint8
Action is the type of action to be performed by the client/server.
type ErrorResponse ¶
type ErrorResponse struct { ResponseCommon // contains filtered or unexported fields }
ErrorResponse is the response sent by the server to the client when an error occurs.
func NewErrorResponse ¶
func NewErrorResponse(errorCode ErrorCode, errorMessage string) ErrorResponse
NewErrorResponse creates a new ErrorResponse.
func ParseErrorResponse ¶
func ParseErrorResponse(r io.Reader, responseCommon ResponseCommon) (ErrorResponse, error)
ParseErrorResponse parses an ErrorResponse received from the server.
func (ErrorResponse) Bytes ¶
func (e ErrorResponse) Bytes() []byte
Bytes returns the byte representation of the response.
func (ErrorResponse) ErrorCode ¶
func (e ErrorResponse) ErrorCode() ErrorCode
ErrorCode returns the error code if the action failed.
func (ErrorResponse) ErrorMessage ¶
func (e ErrorResponse) ErrorMessage() string
ErrorMessage returns the error message if the action failed.
type FetchKeyRequest ¶
type FetchKeyRequest struct {
RequestCommon
}
FetchKeyRequest is the request sent by the client to the server to retrieve the public key.
func NewFetchKeyRequest ¶
func NewFetchKeyRequest() FetchKeyRequest
NewFetchKeyRequest creates a new FetchKeyRequest.
type FetchKeyResponse ¶
type FetchKeyResponse struct { ResponseCommon // contains filtered or unexported fields }
FetchKeyResponse is the response sent by the server to the client containing the public key.
func NewFetchKeyResponse ¶
func NewFetchKeyResponse(keyAlgorithm KeyAlgorithm, publicKey []byte) FetchKeyResponse
NewFetchKeyResponse creates a new NewFetchKeyResponse.
func ParseFetchKeyResponse ¶
func ParseFetchKeyResponse(r io.Reader, responseCommon ResponseCommon) (FetchKeyResponse, error)
ParseFetchKeyResponse parses a FetchKeyRespons received from a server.
func (FetchKeyResponse) Bytes ¶
func (g FetchKeyResponse) Bytes() []byte
Bytes returns the byte representation of the FetchKeyResponse.
func (FetchKeyResponse) KeyAlgorithm ¶
func (g FetchKeyResponse) KeyAlgorithm() KeyAlgorithm
KeyAlgorithm returns the algorithm used to generate the key-pair.
func (FetchKeyResponse) PublicKey ¶
func (g FetchKeyResponse) PublicKey() []byte
PublicKey returns the public key.
type HashType ¶
type HashType uint8
HashType is the hash type used for verifying the signature.
const ( HashTypeSHA1 HashType = 0x1 HashTypeSHA256 HashType = 0x2 HashTypeSHA384 HashType = 0x3 HashTypeSHA512 HashType = 0x4 )
Supported hash types.
func NewHashType ¶
NewHashType creates a new HashType from the crypto.Hash.
func (HashType) CryptoHash ¶
CryptoHash returns the crypto.Hash corresponding to the hash type.
type HelloRequest ¶
type HelloRequest struct {
RequestCommon
}
HelloRequest is the request sent by the client to the server to keep the connection alive.
func NewHelloRequest ¶
func NewHelloRequest() HelloRequest
NewHelloRequest creates a new HelloRequest.
type HelloResponse ¶
type HelloResponse struct {
ResponseCommon
}
HelloResponse is the response sent by the server to the client acknowledging that everything is fine.
func NewHelloResponse ¶
func NewHelloResponse() HelloResponse
NewHelloResponse creates a new NewHelloResponse.
type KeyAlgorithm ¶
type KeyAlgorithm uint8
KeyAlgorithm is the algorithm used to generate the key-pair.
const ( KeyAlgorithmRSA KeyAlgorithm = 0x1 KeyAlgorithmECDSA KeyAlgorithm = 0x2 KeyAlgorithmED25519 KeyAlgorithm = 0x3 )
Supported key algorithms.
func (KeyAlgorithm) String ¶
func (k KeyAlgorithm) String() string
String returns the string representation of the key algorithm.
type ProcessRequest ¶
type ProcessRequest struct { RequestCommon // contains filtered or unexported fields }
ProcessRequest is the request sent by the client to the server with a generic encrypted message.
func NewProcessRequest ¶
func NewProcessRequest( id [16]byte, message []byte, optFuncs ...func(*ProcessRequestOptions), ) ProcessRequest
NewProcessRequest creates a new ProcessRequest.
func ParseProcessRequest ¶
func ParseProcessRequest(requestCommon RequestCommon, r io.Reader) (ProcessRequest, error)
ParseProcessRequest parses a ProcessRequest received from a client. The request common part must have already been read. This could return an io.EOF error if the response is not complete.
func (ProcessRequest) Bytes ¶
func (g ProcessRequest) Bytes() []byte
Bytes returns the byte representation of the ProcessRequest.
func (ProcessRequest) ExpectReply ¶
func (g ProcessRequest) ExpectReply() bool
ExpectReply returns true if the client is expecting a reply from the server.
func (ProcessRequest) ID ¶
func (g ProcessRequest) ID() [16]byte
ID returns the id of the shared secret.
func (ProcessRequest) Message ¶
func (g ProcessRequest) Message() []byte
Message returns the encrypted message.
type ProcessRequestOptions ¶
type ProcessRequestOptions struct {
// contains filtered or unexported fields
}
ProcessRequestOptions contains the options for a ProcessRequest.
type ProcessResponse ¶
type ProcessResponse struct { ResponseCommon // contains filtered or unexported fields }
ProcessResponse is the response sent by the server to the client after generating a shared message.
func NewProcessResponse ¶
func NewProcessResponse(message []byte) ProcessResponse
NewProcessResponse creates a new NewProcessResponse.
func ParseProcessResponse ¶
func ParseProcessResponse(r io.Reader, responseCommon ResponseCommon) (ProcessResponse, error)
ParseProcessResponse parses a ProcessRespons received from a server. This could return an io.EOF error if the response is not complete.
func (ProcessResponse) Bytes ¶
func (g ProcessResponse) Bytes() []byte
Bytes returns the byte representation of the ProcessResponse.
func (ProcessResponse) Message ¶
func (g ProcessResponse) Message() []byte
Message returns the encrypted message.
type RequestCommon ¶
type RequestCommon struct {
// contains filtered or unexported fields
}
RequestCommon is the common fields for all requests.
func ParseRequestCommon ¶
func ParseRequestCommon(r io.Reader) (RequestCommon, error)
ParseRequestCommon parses the common fields of a request. It could return io.EOF if the client closes the connection.
func (RequestCommon) Action ¶
func (r RequestCommon) Action() Action
Action returns the action to be performed.
func (RequestCommon) Bytes ¶
func (r RequestCommon) Bytes() []byte
Bytes returns the byte representation of the request.
func (RequestCommon) Version ¶
func (r RequestCommon) Version() Version
Version returns the protocol version.
type ResponseCommon ¶
type ResponseCommon struct {
// contains filtered or unexported fields
}
ResponseCommon is the common fields for all responses.
func ParseResponseCommon ¶
func ParseResponseCommon(r io.Reader) (ResponseCommon, error)
ParseResponseCommon parses the common fields of a response. It could return io.EOF if the server closes the connection.
func (ResponseCommon) Bytes ¶
func (r ResponseCommon) Bytes() []byte
Bytes returns the byte representation of the response.
func (ResponseCommon) Success ¶
func (r ResponseCommon) Success() bool
Success returns true if the action was successful.
type SetupRequest ¶
type SetupRequest struct { RequestCommon // contains filtered or unexported fields }
SetupRequest is the request sent by the client to the server to register a shared secret.
func NewSetupRequest ¶
func NewSetupRequest(id [16]byte, publicKey *ecdh.PublicKey) SetupRequest
NewSetupRequest creates a new SetupRequest.
func ParseSetupRequest ¶
func ParseSetupRequest(requestCommon RequestCommon, r io.Reader) (SetupRequest, error)
ParseSetupRequest parses a SetupRequest received from a client. The request common part must have already been read.
func (SetupRequest) Bytes ¶
func (s SetupRequest) Bytes() []byte
Bytes returns the byte representation of the SetupRequest.
func (SetupRequest) ID ¶
func (s SetupRequest) ID() [16]byte
ID returns the id of the shared secret.
func (SetupRequest) PublicKey ¶
func (s SetupRequest) PublicKey() *ecdh.PublicKey
PublicKey returns the public key for the Diffie-Hellman exchange.
type SetupResponse ¶
type SetupResponse struct { ResponseCommon // contains filtered or unexported fields }
SetupResponse is the response sent by the server to the client after generating a shared secret.
func NewSetupResponse ¶
func NewSetupResponse(publicKey *ecdh.PublicKey) SetupResponse
NewSetupResponse creates a new SetupResponse.
func ParseSetupResponse ¶
func ParseSetupResponse(responseCommon ResponseCommon, r io.Reader) (SetupResponse, error)
ParseSetupResponse parses a SetupResponse received from the server. The response common part must have already been read.
func (SetupResponse) Bytes ¶
func (s SetupResponse) Bytes() []byte
Bytes returns the byte representation of the SetupResponse.
func (SetupResponse) HashType ¶
func (s SetupResponse) HashType() HashType
HashType returns the hash type used to sign the response.
func (SetupResponse) PublicKey ¶
func (s SetupResponse) PublicKey() *ecdh.PublicKey
PublicKey returns the public key for the Diffie-Hellman exchange.
func (*SetupResponse) SetSignature ¶
func (s *SetupResponse) SetSignature(hashType HashType, signature []byte)
SetSignature sets the signature of the response.
func (SetupResponse) Signature ¶
func (s SetupResponse) Signature() []byte
Signature prooves that the message was sent by the expected server, allowing to validate the response using the server's public key.