core

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2025 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxMemoryUsage         = 1 * 1024 * 1024 * 1024 // 1GB
	PacketBufferSize       = 4096
	PacketBufferPoolSize   = MaxMemoryUsage / PacketBufferSize
	AllocateTimeToOverload = 2 // 2 seconds
	SendQueueSize          = 10240
	RecvQueueSize          = 10240
)

device

View Source
const (
	MinimalRecvIntervalMs  = 20  // millisecond
	ThreatCountBeforeBlock = 1   // block at 2nd attempt
	CookieRegenerateTime   = 120 // second
	CookieRoundTripTimeMs  = 20  // millisecond
)

session

View Source
const (
	AgentLocalTransactionResponseTimeoutMs  = 5 * 1000                                     // millisecond
	ServerLocalTransactionResponseTimeoutMs = AgentLocalTransactionResponseTimeoutMs - 300 // millisecond
	ACLocalTransactionResponseTimeoutMs     = ServerLocalTransactionResponseTimeoutMs      // millisecond

	RemoteTransactionProcessTimeoutMs   = 10 * 1000 // millisecond
	DELocalTransactionResponseTimeoutMs = 5 * 1000
)

transaction

View Source
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

View Source
const (
	InitialChainKeyString = "NHP keygen v.20230421@clouddeep.cn"
	InitialHashString     = "NHP hashgen v.20230421@deepcloudsdp.com"
)

noise

View Source
const (
	CIPHER_SCHEME_GMSM int = iota
	CIPHER_SCHEME_CURVE
)
View Source
const (
	NHP_NO_DEVICE = iota
	NHP_AGENT
	NHP_SERVER
	NHP_AC
	NHP_RELAY
	NHP_DE
)
View Source
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.
)
View Source
const (
	NHP_FLAG_EXTENDEDLENGTH = 1 << iota
	NHP_FLAG_COMPRESS
)

header flags (bit 0 - bit 11)

View Source
const (
	MinimalNSLookupTime = 300 // second
)

hostname resolve

View Source
const (
	MinimalPeerAddressHoldTime = 5 // second
)

peer

View Source
const (
	NHP_FLAG_SCHEME_GMSM = 0 << 12
)

cipher scheme combination (bit 11 - bit 15)

View Source
const ProtocolVersionMajor = 1

protocol

View Source
const ProtocolVersionMinor = 0

Variables

View Source
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 AESDecrypt added in v0.4.1

func AESDecrypt(cipherText []byte, key []byte) ([]byte, error)

func AESEncrypt added in v0.4.1

func AESEncrypt(plainText []byte, key []byte) ([]byte, error)

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

func CalculatePayloadLength(ciphertxt []byte, ivLength int, macLength int) [8]byte

Calculate the total length of the Payload (including IV, ciphertext and MAC)

func CalculatePayloadOffset added in v0.4.1

func CalculatePayloadOffset(ciphertxt []byte) [2]byte

Calculate the offset of the Payload

func CalculateTypeid added in v0.4.1

func CalculateTypeid(objectId []byte) ([4]byte, error)

Calculating TypeId

func ConvertHexStringToByteArray added in v0.4.1

func ConvertHexStringToByteArray(hexStr string) ([]byte, error)

Convert Hex string to byte array

func ErrorToErrorNumber

func ErrorToErrorNumber(err error) int

func ErrorToString

func ErrorToString(err error) string

func GenerateObjectId added in v0.4.1

func GenerateObjectId() (uuid.UUID, error)

Generate ObjectId

func HeaderTypeToDeviceType

func HeaderTypeToDeviceType(t int) int

func HeaderTypeToString

func HeaderTypeToString(t int) string

func IsZero

func IsZero(arr []byte) bool

func NewHash

func NewHash(t HashTypeEnum) (h hash.Hash)

func SM2Decrypt added in v0.4.1

func SM2Decrypt(privateKeyBase64 string, message string) (string, error)

func SM2Encrypt added in v0.4.1

func SM2Encrypt(pubKeyBase64 string, message string) (string, error)

func SetECCBindMode added in v0.4.1

func SetECCBindMode(curveParam byte, useSignature bool) [1]byte

Setting the ECC bonding mode

func SetSigConfig added in v0.4.1

func SetSigConfig(symAlgMode byte, curveParam byte, hasSignature bool) [1]byte

Set up signing configuration

func SetZero

func SetZero(arr []byte)

func WriteZtdo added in v0.4.1

func WriteZtdo(writer io.Writer, ztdo Ztdo) error

Write Ztdo data to a file

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
}

func NewCipherSuite

func NewCipherSuite(scheme int) (ciphers *CipherSuite)

init cipher suite

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 NewDevice

func NewDevice(t int, prk []byte, option *DeviceOptions) *Device

func (*Device) AddLocalTransaction

func (d *Device) AddLocalTransaction(t *LocalTransaction)

LocalTransaction

func (*Device) AddPeer

func (d *Device) AddPeer(peer Peer)

func (*Device) AllocatePoolPacket

func (d *Device) AllocatePoolPacket() *Packet

func (*Device) CheckRecvHeaderType

func (d *Device) CheckRecvHeaderType(t int) bool

Data Receiver allowed message types

func (*Device) FindLocalTransaction

func (d *Device) FindLocalTransaction(id uint64) *LocalTransaction

func (*Device) IsOverload

func (d *Device) IsOverload() bool

func (*Device) IsTransactionRequest

func (d *Device) IsTransactionRequest(t int) bool

func (*Device) IsTransactionResponse

func (d *Device) IsTransactionResponse(t int) bool

func (*Device) LocalTransactionTimeout

func (d *Device) LocalTransactionTimeout() int

func (*Device) LookupPeer

func (d *Device) LookupPeer(pk []byte) Peer

func (*Device) MsgToPacket

func (d *Device) MsgToPacket(md *MsgData) (mad *MsgAssemblerData, err error)

Synchronous linear processing.

func (*Device) NextCounterIndex

func (d *Device) NextCounterIndex() uint64

func (*Device) PacketToMsg

func (d *Device) PacketToMsg(pd *PacketData) (ppd *PacketParserData, err error)

Synchronous linear processing.

func (*Device) PublicKeyBase64

func (d *Device) PublicKeyBase64() string

func (*Device) PublicKeyExBase64

func (d *Device) PublicKeyExBase64() string

func (*Device) RecvPacketToMsg

func (d *Device) RecvPacketToMsg(pd *PacketData)

func (*Device) RecvPrecheck

func (d *Device) RecvPrecheck(pkt *Packet) (int, int, error)

func (*Device) ReleasePoolPacket

func (d *Device) ReleasePoolPacket(pkt *Packet)

func (*Device) RemoteTransactionTimeout

func (d *Device) RemoteTransactionTimeout() int

func (*Device) RemovePeer

func (d *Device) RemovePeer(pubKey string)

func (*Device) ResetPeers

func (d *Device) ResetPeers()

func (*Device) SendMsgToPacket

func (d *Device) SendMsgToPacket(md *MsgData)

func (*Device) SetOption

func (d *Device) SetOption(option DeviceOptions)

func (*Device) SetOverload

func (d *Device) SetOverload(overloaded bool)

func (*Device) Start

func (d *Device) Start()

func (*Device) Stop

func (d *Device) Stop()

type DeviceOptions

type DeviceOptions struct {
	DisableAgentPeerValidation  bool
	DisableServerPeerValidation bool
	DisableACPeerValidation     bool
	DisableRelayPeerValidation  bool
	DisableDePeerValidation     bool
}

type DeviceTypeEnum

type DeviceTypeEnum = int

type EccTypeEnum

type EccTypeEnum int
const (
	ECC_CURVE25519 EccTypeEnum = iota
	ECC_SM2
	ECC_UMI
)

type Ecdh

type Ecdh interface {
	SetPrivateKey(prk []byte) error
	PrivateKey() []byte
	PublicKey() []byte
	SharedSecret(pbk []byte) []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 ErrorCodeToError(number int) *Error

func (*Error) Error

func (e *Error) Error() string

implment NhpError interface

func (*Error) ErrorCode

func (e *Error) ErrorCode() string

func (*Error) ErrorNumber

func (e *Error) ErrorNumber() int

func (*Error) SetExtraError

func (e *Error) SetExtraError(err error)

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 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 NhpError

type NhpError interface {
	Error() string
	ErrorCode() string
	ErrorNumber() int
}

type NoiseFactory

type NoiseFactory struct {
	HashType HashTypeEnum
}

func (*NoiseFactory) HMAC1

func (n *NoiseFactory) HMAC1(dst *[HashSize]byte, key, in0 []byte)

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) Counter

func (pkt *Packet) Counter() uint64

func (*Packet) Flag

func (pkt *Packet) Flag() uint16

func (*Packet) HeaderTypeAndSize

func (pkt *Packet) HeaderTypeAndSize() (t int, s int)

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

func (p *UdpPeer) CheckRecvAddress(currTime int64, currAddr net.Addr) bool

a peer should not have multiple layer-4 addresses within its hold time

func (*UdpPeer) CopyResolveStatus

func (p *UdpPeer) CopyResolveStatus(other *UdpPeer)

func (*UdpPeer) DeviceType

func (p *UdpPeer) DeviceType() DeviceTypeEnum

func (*UdpPeer) HostOrAddr

func (p *UdpPeer) HostOrAddr() string

func (*UdpPeer) IsExpired

func (p *UdpPeer) IsExpired() bool

func (*UdpPeer) LastRecvTime

func (p *UdpPeer) LastRecvTime() int64

func (*UdpPeer) LastSendTime

func (p *UdpPeer) LastSendTime() int64

func (*UdpPeer) Name

func (p *UdpPeer) Name() string

func (*UdpPeer) PublicKey

func (p *UdpPeer) PublicKey() []byte

func (*UdpPeer) PublicKeyBase64

func (p *UdpPeer) PublicKeyBase64() string

func (*UdpPeer) RecvAddr

func (p *UdpPeer) RecvAddr() net.Addr

func (*UdpPeer) ResolvedIp

func (p *UdpPeer) ResolvedIp() string

func (*UdpPeer) SendAddr

func (p *UdpPeer) SendAddr() net.Addr

func (*UdpPeer) UpdateRecv

func (p *UdpPeer) UpdateRecv(currTime int64, currAddr net.Addr)

func (*UdpPeer) UpdateSend

func (p *UdpPeer) UpdateSend(currTime int64)

type Ztdo added in v0.4.1

type Ztdo struct {
	Header    ZtdoHeader
	Payload   ZtdoPayload
	Signature ZtdoSignature
}

Ztdo complete data structure definition

func WriteSourceFile added in v0.4.1

func WriteSourceFile(filename string, key []byte) (Ztdo, error)

Parsing source files

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

func ReadZtdoFile(filePath string) (ZtdoFile, error)

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 ZtdoMetaInfo struct {
	FileName    string `json:"fileName"`    //Source filename, e.g., test.txt
	FileExtName string `json:"FileExtName"` //Source file extension, e.g., .txt
	Owner       string `json:"owner"`
	Keywords    string `json:"keywords"`
	Description string `json:"description"`
}

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

type ZtdoSignature added in v0.4.1

type ZtdoSignature struct {
	SignerId          []byte // Signer ID
	DomainId          []byte // Domain ID
	DeclaredPublicKey []byte // Public Key Declaration
	Sig               []byte //Signature Data
}

ZtdoSignature represents the signature structure of a data object

Directories

Path Synopsis
scheme

Jump to

Keyboard shortcuts

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