Documentation
¶
Index ¶
- Constants
- Variables
- func AESDecrypt(cipherText []byte, key []byte) ([]byte, error)
- func AESEncrypt(plainText []byte, key []byte) ([]byte, error)
- func AeadFromKey(t GcmTypeEnum, key *[SymmetricKeySize]byte) (aead cipher.AEAD)
- func CBCDecryption(t GcmTypeEnum, key *[SymmetricKeySize]byte, ciphertext []byte, inPlace bool) ([]byte, error)
- func CBCEncryption(t GcmTypeEnum, key *[SymmetricKeySize]byte, plaintext []byte, inPlace bool) ([]byte, error)
- func CalculatePayloadLength(ciphertxt []byte, ivLength int, macLength int) [8]byte
- func CalculatePayloadOffset(ciphertxt []byte) [2]byte
- func CalculateTypeid(objectId []byte) ([4]byte, error)
- func ConvertHexStringToByteArray(hexStr string) ([]byte, error)
- func ErrorToErrorNumber(err error) int
- func ErrorToString(err error) string
- func GenerateObjectId() (uuid.UUID, error)
- func HeaderTypeToDeviceType(t int) int
- func HeaderTypeToString(t int) string
- func IsZero(arr []byte) bool
- func NewHash(t HashTypeEnum) (h hash.Hash)
- func SM2Decrypt(privateKeyBase64 string, message string) (string, error)
- func SM2Encrypt(pubKeyBase64 string, message string) (string, error)
- func SetECCBindMode(curveParam byte, useSignature bool) [1]byte
- func SetSigConfig(symAlgMode byte, curveParam byte, hasSignature bool) [1]byte
- func SetZero(arr []byte)
- func WriteZtdo(writer io.Writer, ztdo Ztdo) error
- func WriteZtdoHeader(writer io.Writer, header *ZtdoHeader) error
- func WriteZtdoPayload(writer io.Writer, payload *ZtdoPayload) error
- func WriteZtdoSignature(writer io.Writer, signature *ZtdoSignature) error
- type CipherSuite
- type ConnectionData
- func (c *ConnectionData) AddRemoteTransaction(t *RemoteTransaction)
- func (c *ConnectionData) Close()
- func (c *ConnectionData) Equal(other *ConnectionData) bool
- func (c *ConnectionData) FindRemoteTransaction(id uint64) *RemoteTransaction
- func (c *ConnectionData) ForwardInboundPacket(pkt *Packet)
- func (c *ConnectionData) ForwardOutboundPacket(pkt *Packet)
- func (c *ConnectionData) IsClosed() bool
- func (c *ConnectionData) SendBlockSignal()
- func (c *ConnectionData) SetTimeout(ms int)
- type CookieStore
- type Device
- func (d *Device) AddLocalTransaction(t *LocalTransaction)
- func (d *Device) AddPeer(peer Peer)
- func (d *Device) AllocatePoolPacket() *Packet
- func (d *Device) CheckRecvHeaderType(t int) bool
- func (d *Device) FindLocalTransaction(id uint64) *LocalTransaction
- func (d *Device) IsOverload() bool
- func (d *Device) IsTransactionRequest(t int) bool
- func (d *Device) IsTransactionResponse(t int) bool
- func (d *Device) LocalTransactionTimeout() int
- func (d *Device) LookupPeer(pk []byte) Peer
- func (d *Device) MsgToPacket(md *MsgData) (mad *MsgAssemblerData, err error)
- func (d *Device) NextCounterIndex() uint64
- func (d *Device) PacketToMsg(pd *PacketData) (ppd *PacketParserData, err error)
- func (d *Device) PublicKeyBase64() string
- func (d *Device) PublicKeyExBase64() string
- func (d *Device) RecvPacketToMsg(pd *PacketData)
- func (d *Device) RecvPrecheck(pkt *Packet) (int, int, error)
- func (d *Device) ReleasePoolPacket(pkt *Packet)
- func (d *Device) RemoteTransactionTimeout() int
- func (d *Device) RemovePeer(pubKey string)
- func (d *Device) ResetPeers()
- func (d *Device) SendMsgToPacket(md *MsgData)
- func (d *Device) SetOption(option DeviceOptions)
- func (d *Device) SetOverload(overloaded bool)
- func (d *Device) Start()
- func (d *Device) Stop()
- type DeviceOptions
- type DeviceTypeEnum
- type EccTypeEnum
- type Ecdh
- type Error
- type GcmTypeEnum
- type HashTypeEnum
- type Header
- type InitiatorScheme
- type LocalTransaction
- type MsgAssemblerData
- type MsgData
- type NhpError
- type NoiseFactory
- func (n *NoiseFactory) HMAC1(dst *[HashSize]byte, key, in0 []byte)
- func (n *NoiseFactory) HMAC2(dst *[HashSize]byte, key, in0, in1 []byte)
- func (n *NoiseFactory) KeyGen1(dst0 *[HashSize]byte, key, input []byte)
- func (n *NoiseFactory) KeyGen2(dst0, dst1 *[HashSize]byte, key, input []byte)
- func (n *NoiseFactory) KeyGen3(dst0, dst1, dst2 *[HashSize]byte, key, input []byte)
- func (n *NoiseFactory) MixHash(dst *[HashSize]byte, key []byte, input []byte)
- func (n *NoiseFactory) MixKey(dst *[SymmetricKeySize]byte, key []byte, input []byte)
- type Packet
- type PacketBuffer
- type PacketBufferPool
- type PacketData
- type PacketParserData
- type Peer
- type RemoteTransaction
- type ResponderScheme
- type UdpPeer
- func (p *UdpPeer) CheckRecvAddress(currTime int64, currAddr net.Addr) bool
- func (p *UdpPeer) CopyResolveStatus(other *UdpPeer)
- func (p *UdpPeer) DeviceType() DeviceTypeEnum
- func (p *UdpPeer) HostOrAddr() string
- func (p *UdpPeer) IsExpired() bool
- func (p *UdpPeer) LastRecvTime() int64
- func (p *UdpPeer) LastSendTime() int64
- func (p *UdpPeer) Name() string
- func (p *UdpPeer) PublicKey() []byte
- func (p *UdpPeer) PublicKeyBase64() string
- func (p *UdpPeer) RecvAddr() net.Addr
- func (p *UdpPeer) ResolvedIp() string
- func (p *UdpPeer) SendAddr() net.Addr
- func (p *UdpPeer) UpdateRecv(currTime int64, currAddr net.Addr)
- func (p *UdpPeer) UpdateSend(currTime int64)
- type Ztdo
- type ZtdoFile
- type ZtdoHeader
- type ZtdoMetaInfo
- type ZtdoPayload
- type ZtdoSignature
Constants ¶
const ( MaxMemoryUsage = 1 * 1024 * 1024 * 1024 // 1GB PacketBufferSize = 4096 PacketBufferPoolSize = MaxMemoryUsage / PacketBufferSize AllocateTimeToOverload = 2 // 2 seconds SendQueueSize = 10240 RecvQueueSize = 10240 )
device
const ( MinimalRecvIntervalMs = 20 // millisecond ThreatCountBeforeBlock = 1 // block at 2nd attempt CookieRegenerateTime = 120 // second CookieRoundTripTimeMs = 20 // millisecond )
session
const ( AgentLocalTransactionResponseTimeoutMs = 5 * 1000 // millisecond ServerLocalTransactionResponseTimeoutMs = AgentLocalTransactionResponseTimeoutMs - 300 // millisecond ACLocalTransactionResponseTimeoutMs = ServerLocalTransactionResponseTimeoutMs // millisecond RemoteTransactionProcessTimeoutMs = 10 * 1000 // millisecond DELocalTransactionResponseTimeoutMs = 5 * 1000 )
transaction
const ( HeaderCommonSize = 24 HeaderSize = 160 HeaderSizeEx = 224 SymmetricKeySize = 32 PrivateKeySize = 32 PublicKeySize = 32 PublicKeySizeEx = 64 HashSize = 32 CookieSize = 32 TimestampSize = 8 GCMNonceSize = 12 GCMTagSize = 16 PublicKeyBase64Size = 44 PublicKeyBase64SizeEx = 88 )
packet
const ( InitialChainKeyString = "NHP keygen [email protected]" InitialHashString = "NHP hashgen [email protected]" )
noise
const ( CIPHER_SCHEME_GMSM int = iota CIPHER_SCHEME_CURVE )
const ( NHP_NO_DEVICE = iota NHP_AGENT NHP_SERVER NHP_AC NHP_RELAY NHP_DE )
const ( NHP_KPL = iota // general keepalive packet NHP_KNK // agent sends knock to server NHP_ACK // server replies knock status to agent NHP_AOP // server asks ac for operation NHP_ART // ac replies server for operation result NHP_LST // agent requests server for listing services and applications NHP_LRT // server replies to agent with services and applications result NHP_COK // server sends cookie to agent NHP_RKN // agent sends reknock to server NHP_RLY // relay sends relayed packet to server NHP_AOL // ac sends online status to server NHP_AAK // server sends ack to ac after receving ac's online status NHP_OTP // agent requests server for one-time-password NHP_REG // agent asks server for registering NHP_RAK // server sends back ack when agent registers correctly NHP_ACC // agent sends to ac/resource for actual ip access NHP_EXT // agent requests immediate disconnection //DHP NHP_DRG //DE sends a message to register a data object file to the NHP Server NHP_DAK //NHP-Server sends a result of the NHP_DRG registration request to the DE. NHP_DAR //NHP Agent sends messages to get access to the file and then work with it. NHP_DAG //The NHP Server sends the authorization status of the data object to NHP Agent. NHP_DPC //The NHP Server sends a policy validation challenge to the NHP Agent NHP_DPV //The NHP Agent sends the policy validation proof to the NHP Server. )
const ( NHP_FLAG_EXTENDEDLENGTH = 1 << iota NHP_FLAG_COMPRESS )
header flags (bit 0 - bit 11)
const (
MinimalNSLookupTime = 300 // second
)
hostname resolve
const (
MinimalPeerAddressHoldTime = 5 // second
)
peer
const (
NHP_FLAG_SCHEME_GMSM = 0 << 12
)
cipher scheme combination (bit 11 - bit 15)
const ProtocolVersionMajor = 1
protocol
const ProtocolVersionMinor = 0
Variables ¶
var ( ErrSuccess = newError(C.ERR_NHP_SUCCESS, "") // device ErrCipherNotSupported = newError(C.ERR_NHP_CIPHER_NOT_SUPPORTED, "cipher scheme not supported") ErrNotApplicable = newError(C.ERR_NHP_OPERATION_NOT_APPLICABLE, "operation not applicable") ErrCreateDeviceFailed = newError(C.ERR_NHP_CREATE_DEVICE_FAILED, "failed to create nhp device") ErrCloseDeviceFailed = newError(C.ERR_NHP_CLOSE_DEVICE_FAILED, "attempt to close a non-initialized nhp device") ErrRuntimePanic = newError(C.ERR_NHP_SDK_RUNTIME_PANIC, "runtime panic encountered") // initiator and encryption ErrWrongCipherScheme = newError(C.ERR_NHP_WRONG_CIPHER_SCHEME, "a wrong cipher scheme is used") ErrEmptyPeerPublicKey = newError(C.ERR_NHP_EMPTY_PEER_PUBLIC_KEY, "remote peer public key is not set") ErrEphermalECDHPeerFailed = newError(C.ERR_NHP_EPHERMAL_ECDH_PEER_FAILED, "ephermal ECDH failed with peer") ErrDeviceECDHPeerFailed = newError(C.ERR_NHP_DEVICE_ECDH_PEER_FAILED, "device ECDH failed with peer") ErrIdentityTooLong = newError(C.ERR_NHP_IDENTITY_TOO_LONG, "identity exceeds max length") ErrDataCompressionFailed = newError(C.ERR_NHP_DATA_COMPRESSION_FAILED, "data compression failed") ErrPacketSizeExceedsBuffer = newError(C.ERR_NHP_PACKET_SIZE_EXCEEDS_BUFFER, "packet size longer than send buffer") // responder and decryption ErrCloseConnection = newError(C.ERR_NHP_CLOSE_CONNECTION, "disengage nhp access immediately") ErrIncorrectPacketSize = newError(C.ERR_NHP_INCORRECT_PACKET_SIZE, "incorrect packet size") ErrMessageTypeNotMatchDevice = newError(C.ERR_NHP_MESSAGE_TYPE_NOT_MATCH_DEVICE, "message type does not match device") ErrServerOverload = newError(C.ERR_NHP_SERVER_OVERLOAD, "the packet is dropped due to server overload") ErrHMACCheckFailed = newError(C.ERR_NHP_HMAC_CHECK_FAILED, "HMAC validation failed") ErrServerHMACCheckFailed = newError(C.ERR_NHP_SERVER_HMAC_CHECK_FAILED, "server HMAC validation failed") ErrDeviceECDHEphermalFailed = newError(C.ERR_NHP_DEVICE_ECDH_EPHERMAL_FAILED, "device ECDH failed with ephermal") ErrPeerIdentityVerificationFailed = newError(C.ERR_NHP_PEER_IDENTITY_VERIFICATION_FAILED, "failed to verify peer's identity with apk") ErrAEADDecryptionFailed = newError(C.ERR_NHP_AEAD_DECRYPTION_FAILED, "aead decryption failed") ErrDataDecompressionFailed = newError(C.ERR_NHP_DATA_DECOMPRESSION_FAILED, "data decompression failed") ErrDeviceECDHObtainedPeerFailed = newError(C.ERR_NHP_DEVICE_ECDH_OBTAINED_PEER_FAILED, "device ECDH failed with obtained peer") ErrServerRejectWithCookie = newError(C.ERR_NHP_SERVER_REJECT_WITH_COOKIE, "server overload, stop processing packet and return cookie") ErrReplayPacketReceived = newError(C.ERR_NHP_REPLAY_PACKET_RECEIVED, "received replay packet, drop") ErrFloodPacketReceived = newError(C.ERR_NHP_FLOOD_PACKET_RECEIVED, "received flood packet, drop") ErrStalePacketReceived = newError(C.ERR_NHP_STALE_PACKET_RECEIVED, "received stale packet, drop") )
device sdk errors
Functions ¶
func AESEncrypt ¶ added in v0.4.1
AESEncryption Function
func AeadFromKey ¶
func AeadFromKey(t GcmTypeEnum, key *[SymmetricKeySize]byte) (aead cipher.AEAD)
func CBCDecryption ¶
func CBCDecryption(t GcmTypeEnum, key *[SymmetricKeySize]byte, ciphertext []byte, inPlace bool) ([]byte, error)
func CBCEncryption ¶
func CBCEncryption(t GcmTypeEnum, key *[SymmetricKeySize]byte, plaintext []byte, inPlace bool) ([]byte, error)
func CalculatePayloadLength ¶ added in v0.4.1
Calculate the total length of the Payload (including IV, ciphertext and MAC)
func CalculatePayloadOffset ¶ added in v0.4.1
Calculate the offset of the Payload
func CalculateTypeid ¶ added in v0.4.1
Calculating TypeId
func ConvertHexStringToByteArray ¶ added in v0.4.1
Convert Hex string to byte array
func ErrorToErrorNumber ¶
func ErrorToString ¶
func GenerateObjectId ¶ added in v0.4.1
Generate ObjectId
func HeaderTypeToDeviceType ¶
func HeaderTypeToString ¶
func NewHash ¶
func NewHash(t HashTypeEnum) (h hash.Hash)
func SM2Decrypt ¶ added in v0.4.1
func SM2Encrypt ¶ added in v0.4.1
func SetECCBindMode ¶ added in v0.4.1
Setting the ECC bonding mode
func SetSigConfig ¶ added in v0.4.1
Set up signing configuration
func WriteZtdoHeader ¶ added in v0.4.1
func WriteZtdoHeader(writer io.Writer, header *ZtdoHeader) error
Write ZtdoHeader data
func WriteZtdoPayload ¶ added in v0.4.1
func WriteZtdoPayload(writer io.Writer, payload *ZtdoPayload) error
Writing ZtdoPayload data
func WriteZtdoSignature ¶ added in v0.4.1
func WriteZtdoSignature(writer io.Writer, signature *ZtdoSignature) error
Writing ZtdoSignature data
Types ¶
type CipherSuite ¶
type CipherSuite struct {
Scheme int
EccType EccTypeEnum
HashType HashTypeEnum
GcmType GcmTypeEnum
}
type ConnectionData ¶
type ConnectionData struct {
// atomic data, keep 64bit(8-bytes) alignment for 32-bit system compatibility
InitTime int64 // local connection setup time. immutable after created
LastRemoteSendTime int64
LastLocalSendTime int64
LastLocalRecvTime int64
sync.Mutex
sync.WaitGroup
// common
Device *Device
LocalAddr *net.UDPAddr
RemoteAddr *net.UDPAddr
CookieStore *CookieStore
TimeoutMs int
SendQueue chan *Packet
RecvQueue chan *Packet
BlockSignal chan struct{}
SetTimeoutSignal chan struct{}
StopSignal chan struct{}
// remote transactions
RemoteTransactionMutex sync.Mutex
RemoteTransactionMap map[uint64]*RemoteTransaction
// specific
RecvThreatCount int32
// contains filtered or unexported fields
}
func (*ConnectionData) AddRemoteTransaction ¶
func (c *ConnectionData) AddRemoteTransaction(t *RemoteTransaction)
RemoteTransaction
func (*ConnectionData) Close ¶
func (c *ConnectionData) Close()
func (*ConnectionData) Equal ¶
func (c *ConnectionData) Equal(other *ConnectionData) bool
func (*ConnectionData) FindRemoteTransaction ¶
func (c *ConnectionData) FindRemoteTransaction(id uint64) *RemoteTransaction
func (*ConnectionData) ForwardInboundPacket ¶
func (c *ConnectionData) ForwardInboundPacket(pkt *Packet)
func (*ConnectionData) ForwardOutboundPacket ¶
func (c *ConnectionData) ForwardOutboundPacket(pkt *Packet)
func (*ConnectionData) IsClosed ¶
func (c *ConnectionData) IsClosed() bool
func (*ConnectionData) SendBlockSignal ¶
func (c *ConnectionData) SendBlockSignal()
func (*ConnectionData) SetTimeout ¶
func (c *ConnectionData) SetTimeout(ms int)
type CookieStore ¶
type CookieStore struct {
CurrCookie [CookieSize]byte
PrevCookie [CookieSize]byte
LastCookieTime int64
}
func (*CookieStore) Clear ¶
func (cs *CookieStore) Clear()
func (*CookieStore) Set ¶
func (cs *CookieStore) Set(cookie []byte)
type Device ¶
type Device struct {
Overload atomic.Bool
DecryptedMsgQueue chan *PacketParserData
// contains filtered or unexported fields
}
func (*Device) AddLocalTransaction ¶
func (d *Device) AddLocalTransaction(t *LocalTransaction)
LocalTransaction
func (*Device) AllocatePoolPacket ¶
func (*Device) CheckRecvHeaderType ¶
Data Receiver allowed message types
func (*Device) FindLocalTransaction ¶
func (d *Device) FindLocalTransaction(id uint64) *LocalTransaction
func (*Device) IsOverload ¶
func (*Device) IsTransactionRequest ¶
func (*Device) IsTransactionResponse ¶
func (*Device) LocalTransactionTimeout ¶
func (*Device) LookupPeer ¶
func (*Device) MsgToPacket ¶
func (d *Device) MsgToPacket(md *MsgData) (mad *MsgAssemblerData, err error)
Synchronous linear processing.
func (*Device) NextCounterIndex ¶
func (*Device) PacketToMsg ¶
func (d *Device) PacketToMsg(pd *PacketData) (ppd *PacketParserData, err error)
Synchronous linear processing.
func (*Device) PublicKeyBase64 ¶
func (*Device) PublicKeyExBase64 ¶
func (*Device) RecvPacketToMsg ¶
func (d *Device) RecvPacketToMsg(pd *PacketData)
func (*Device) ReleasePoolPacket ¶
func (*Device) RemoteTransactionTimeout ¶
func (*Device) RemovePeer ¶
func (*Device) ResetPeers ¶
func (d *Device) ResetPeers()
func (*Device) SendMsgToPacket ¶
func (*Device) SetOption ¶
func (d *Device) SetOption(option DeviceOptions)
func (*Device) SetOverload ¶
type DeviceOptions ¶
type DeviceTypeEnum ¶
type DeviceTypeEnum = int
type Ecdh ¶
type Ecdh interface {
SetPrivateKey(prk []byte) error
PrivateKey() []byte
PublicKey() []byte
Name() string
PrivateKeyBase64() string
PublicKeyBase64() string
Identity() []byte
MidPublicKey() []byte
}
func ECDHFromKey ¶
func ECDHFromKey(t EccTypeEnum, prk []byte) (e Ecdh)
func NewECDH ¶
func NewECDH(t EccTypeEnum) (e Ecdh)
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
func ErrorCodeToError ¶
func (*Error) ErrorNumber ¶
func (*Error) SetExtraError ¶
type GcmTypeEnum ¶
type GcmTypeEnum int
const ( GCM_AES256 GcmTypeEnum = iota GCM_SM4 GCM_CHACHA20POLY1305 )
type HashTypeEnum ¶
type HashTypeEnum int
const ( HASH_BLAKE2S HashTypeEnum = iota HASH_SM3 HASH_SHA256 )
type Header ¶
type Header interface {
SetTypeAndPayloadSize(int, int)
TypeAndPayloadSize() (int, int)
Size() int
SetVersion(int, int)
Version() (int, int)
SetFlag(uint16)
Flag() uint16
SetCounter(uint64)
Counter() uint64
Bytes() []byte
NonceBytes() []byte
EphermeralBytes() []byte
StaticBytes() []byte
TimestampBytes() []byte
IdentityBytes() []byte
HMACBytes() []byte
}
type InitiatorScheme ¶
type InitiatorScheme interface {
CreateMsgAssemblerData(d *Device, md *MsgData) (mad *MsgAssemblerData, err error)
DeriveMsgAssemblerDataFromPrevParserData(ppd *PacketParserData, t int, message []byte) (mad *MsgAssemblerData)
SetPeerPublicKey(d *Device, mad *MsgAssemblerData, peerPk []byte) (err error)
EncryptBody(d *Device, mad *MsgAssemblerData) (err error)
}
type LocalTransaction ¶
type LocalTransaction struct {
NextPacketCh chan *Packet // higher level entities should redirect packet to this channel
ExternalMsgCh chan *PacketParserData // a channel to receive an external msg to complete the transaction
// contains filtered or unexported fields
}
func (*LocalTransaction) Run ¶
func (t *LocalTransaction) Run()
type MsgAssemblerData ¶
type MsgAssemblerData struct {
BasePacket *Packet
LocalInitTime int64
TransactionId uint64
CipherScheme int
HeaderType int
BodySize int
HeaderFlag uint16
BodyCompress bool
ExternalCookie *[CookieSize]byte
RemotePubKey []byte
ResponseMsgCh chan<- *PacketParserData
Error error
// contains filtered or unexported fields
}
func (*MsgAssemblerData) Destroy ¶
func (mad *MsgAssemblerData) Destroy()
type MsgData ¶
type MsgData struct {
RemoteAddr *net.UDPAddr // used by agent and ac create a new connection or pick an existing connection for msg sending
ConnData *ConnectionData // used by server to pick an existing connection for msg sending
PrevParserData *PacketParserData // when PrevParserData is set, CipherScheme, RemoteAddr, ConnData, TransactionId and PeerPk will be overridden
CipherScheme int // 0: curve25519/chacha20/blake2s, 1: sm2/sm4/sm3
TransactionId uint64
HeaderType int
Compress bool
ExternalPacket *Packet
ExternalCookie *[CookieSize]byte
Message []byte
PeerPk []byte
EncryptedPktCh chan *MsgAssemblerData
ResponseMsgCh chan *PacketParserData
}
type NoiseFactory ¶
type NoiseFactory struct {
HashType HashTypeEnum
}
func (*NoiseFactory) HMAC2 ¶
func (n *NoiseFactory) HMAC2(dst *[HashSize]byte, key, in0, in1 []byte)
func (*NoiseFactory) KeyGen1 ¶
func (n *NoiseFactory) KeyGen1(dst0 *[HashSize]byte, key, input []byte)
func (*NoiseFactory) KeyGen2 ¶
func (n *NoiseFactory) KeyGen2(dst0, dst1 *[HashSize]byte, key, input []byte)
func (*NoiseFactory) KeyGen3 ¶
func (n *NoiseFactory) KeyGen3(dst0, dst1, dst2 *[HashSize]byte, key, input []byte)
func (*NoiseFactory) MixHash ¶
func (n *NoiseFactory) MixHash(dst *[HashSize]byte, key []byte, input []byte)
func (*NoiseFactory) MixKey ¶
func (n *NoiseFactory) MixKey(dst *[SymmetricKeySize]byte, key []byte, input []byte)
type Packet ¶
type Packet struct {
Buf *PacketBuffer
HeaderType int
PoolAllocated bool
KeepAfterSend bool // only applicable for sending
Content []byte
}
func (*Packet) HeaderTypeAndSize ¶
type PacketBuffer ¶
type PacketBuffer = [PacketBufferSize]byte
type PacketBufferPool ¶
type PacketBufferPool struct {
// contains filtered or unexported fields
}
packet buffer pool
func (*PacketBufferPool) Get ¶
func (bp *PacketBufferPool) Get() *PacketBuffer
must be called after Init()
func (*PacketBufferPool) Init ¶
func (bp *PacketBufferPool) Init(max uint32)
func (*PacketBufferPool) Put ¶
func (bp *PacketBufferPool) Put(packet *PacketBuffer)
must be called after Init()
type PacketData ¶
type PacketData struct {
BasePacket *Packet
ConnData *ConnectionData
PrevAssemblerData *MsgAssemblerData
ConnLastRemoteSendTime *int64
ConnCookieStore *CookieStore
ConnPeerPublicKey *[PublicKeySizeEx]byte
InitTime int64
DecryptedMsgCh chan *PacketParserData
}
type PacketParserData ¶
type PacketParserData struct {
ConnData *ConnectionData
CipherScheme int
Ciphers *CipherSuite
LocalInitTime int64
SenderTrxId uint64
HeaderType int
BodySize int
HeaderFlag uint16
BodyCompress bool
Overload bool
SenderIdentity []byte
SenderMidPublicKey []byte
ConnLastRemoteSendTime *int64
ConnCookieStore *CookieStore
ConnPeerPublicKey *[PublicKeySizeEx]byte
RemotePubKey []byte
BodyMessage []byte
Error error
// contains filtered or unexported fields
}
func (*PacketParserData) Destroy ¶
func (ppd *PacketParserData) Destroy()
func (*PacketParserData) IsAllowedAtOverload ¶
func (ppd *PacketParserData) IsAllowedAtOverload() bool
type Peer ¶
type Peer interface {
DeviceType() int
Name() string
PublicKey() []byte
PublicKeyBase64() string
IsExpired() bool
HostOrAddr() string
SendAddr() net.Addr
LastSendTime() int64
UpdateSend(currTime int64)
RecvAddr() net.Addr
LastRecvTime() int64
UpdateRecv(currTime int64, currAddr net.Addr)
CheckRecvAddress(currTime int64, currAddr net.Addr) bool
}
type RemoteTransaction ¶
type RemoteTransaction struct {
NextMsgCh chan *MsgData // higher level entities should redirect message to this channel
// contains filtered or unexported fields
}
func (*RemoteTransaction) Run ¶
func (t *RemoteTransaction) Run()
type ResponderScheme ¶
type ResponderScheme interface {
CreatePacketParserData(d *Device, pd *PacketData) (ppd *PacketParserData, err error)
DerivePacketParserDataFromPrevAssemblerData(mad *MsgAssemblerData, pkt *Packet, initTime int64) (ppd *PacketParserData)
// contains filtered or unexported methods
}
type UdpPeer ¶
type UdpPeer struct {
sync.Mutex
// immutable fields. Don't change them after creation
PubKeyBase64 string `json:"pubKeyBase64"`
Hostname string `json:"host,omitempty"`
Ip string `json:"ip"`
Port int `json:"port"`
Type int `json:"type"`
ExpireTime int64 `json:"expireTime"`
// contains filtered or unexported fields
}
func (*UdpPeer) CheckRecvAddress ¶
a peer should not have multiple layer-4 addresses within its hold time
func (*UdpPeer) CopyResolveStatus ¶
func (*UdpPeer) DeviceType ¶
func (p *UdpPeer) DeviceType() DeviceTypeEnum
func (*UdpPeer) HostOrAddr ¶
func (*UdpPeer) LastRecvTime ¶
func (*UdpPeer) LastSendTime ¶
func (*UdpPeer) PublicKeyBase64 ¶
func (*UdpPeer) ResolvedIp ¶
func (*UdpPeer) UpdateSend ¶
type Ztdo ¶ added in v0.4.1
type Ztdo struct {
Header ZtdoHeader
Payload ZtdoPayload
Signature ZtdoSignature
}
Ztdo complete data structure definition
type ZtdoFile ¶ added in v0.4.1
type ZtdoFile struct {
Objectid string `json:"objectid"` //UUID
FileName string `json:"fileName"` //Source filename, e.g., test.txt
FileExt string `json:"fileExt"` //Source file extension, e.g., .txt
FileContent []byte `json:"fileContent"` //Encrypted file content, e.g., U2FsdGVkX1...
CreateDate string `json:"createDate"` //Creation Date
Owner string `json:"owner"`
Keywords string `json:"keywords"`
Description string `json:"description"`
}
func ReadZtdoFile ¶ added in v0.4.1
Read Ztdo content to ZtdoFile Object
type ZtdoHeader ¶ added in v0.4.1
type ZtdoHeader struct {
Typeid [4]byte // Type identifier of ZTDO
Objectid string // ZTDO Data Object Identifier
Version [2]byte // Version Number
PayloadOffset [2]byte // The offset relative to the starting address is the starting address of IV.
PayloadLength [8]byte // The total length of the Payload data item, including IV, ciphertext, and MAC
SignatureLength [2]byte // The length is the length of the data after the signature data structure ASN.1 encoding
ECC_Bind_Mode [1]byte // Indicates whether the data used for the elliptic curve parameter and policy binding is a GMAC tag or an ECDSA signature
SigConfig [1]byte // Indicates the data encryption algorithm and data signature algorithm of the Payload
MetaInfo ZtdoMetaInfo // Meta information
}
ZtdoHeader represents the header structure of the data object
type ZtdoMetaInfo ¶ added in v0.4.1
type ZtdoPayload ¶ added in v0.4.1
type ZtdoPayload struct {
IV [16]byte // Initialization Vector (IV)
Ciphertxt []byte // Encrypted payload data
MAC [16]byte // Message Authentication Code (MAC)
}
ZtdoPayload represents the payload structure of the data object