request

package
v0.0.0-...-4d93f28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2023 License: LGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PacketBodySize_184    = 440
	PacketBodySize_64     = 376
	PacketBodySize_192    = 448
	PacketPayloadSize     = 192 // bytes
	PacketPayloadSize_64  = 120
	PacketPayloadSize_184 = 184
	PacketPayloadSize_192 = 192
	MaxSize               = 1232 // bytes

)

Variables

This section is empty.

Functions

func BinIPAddressToIP

func BinIPAddressToIP(binIp []byte) (net.IP, error)

Returns a net.IP type from the provided byte slice. The inputted byte slice needs to be 16 bytes long and can be a IPv6 binary address or an IPv4 binary address mapped as an IPv6 address specified by RFC 4291 "IPv4-Mapped IPv6 Address".

func IPAddressToBinIP

func IPAddressToBinIP(ip net.IP) ([]byte, error)

Returns a byte slice 16 bytes long which represents an IPv4 or IPv6 address (depending on the inputted IP address). In case the inputted address is IPv4 we will follow RFC 4291 "IPv4-Mapped IPv6 address" specification for the binary representation of the address.

Types

type New

type New struct {
	ClientDeviceID   string
	ClientType       byte
	ClientVersion    string
	SignatureMethod  byte
	ClientPublicIP   net.IP
	ServerPublicIP   net.IP
	EncryptionMethod byte
}

func (*New) Create

func (n *New) Create() (Packet, error)

Creates a request packet struct and uses the fields of the New struct for the packet payload.

type Packet

type Packet struct {
	Header           header.Header
	Payload          PacketPayload
	PacketPayloadLen int
	Signature        []byte
	ByteData         []byte // header + payload encoded
	Encrypted        []byte
}

func Decode

func Decode(data []byte, serverPrivKey *rsa.PrivateKey) (Packet, error)

Decodes an encrypted OpenSPA request packet and returns a Packet struct. If we are unable to decode the packet we will return an error.

func (*Packet) AddEncryptionData

func (p *Packet) AddEncryptionData(ciphertext []byte) error

Adds encrypted data to the packet.

func (*Packet) AddSignature

func (p *Packet) AddSignature(signature []byte) error

Adds to a packet the callers packet signature

func (*Packet) Encrypt_RSA_2048_With_AES_256_CBC

func (p *Packet) Encrypt_RSA_2048_With_AES_256_CBC(pubKey *rsa.PublicKey) error

Encrypts the byte data using 2048 bit RSA with AES 256-bit CBC mode and adds it to the packet.

func (*Packet) EncryptionPlaintext

func (p *Packet) EncryptionPlaintext() ([]byte, error)

Returns the plaintext that we will encrypt.

func (*Packet) Export

func (p *Packet) Export() ([]byte, error)

Returns the encrypted byte content of the packet

func (*Packet) Sign_RSA_SHA256

func (p *Packet) Sign_RSA_SHA256(privKey *rsa.PrivateKey) error

Signs the packet using a RSA private key, by taking a SHA-256 digest of the packet signature data.

func (*Packet) SignatureData

func (p *Packet) SignatureData() ([]byte, error)

Returns the signature data to sign (header+payload).

type PacketPayload

type PacketPayload struct {
	Timestamp       time.Time
	ClientDeviceID  string
	Nonce           []byte
	ClientType      byte
	ClientVersion   string
	SignatureMethod byte
	ClientPublicIP  net.IP
	ServerPublicIP  net.IP
}

func (*PacketPayload) ClientTypeToString

func (pp *PacketPayload) ClientTypeToString() string

func (*PacketPayload) Encode

func (p *PacketPayload) Encode() ([]byte, error)

Encodes the packet payload according to the OpenSPA specification for request packet payload.

func (*PacketPayload) SignatureMethodToString

func (pp *PacketPayload) SignatureMethodToString() string

Returns the signature method as a string

func (*PacketPayload) TimestampToString

func (pp *PacketPayload) TimestampToString() string

Returns the timestamp as a string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL