security

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CipherSuite represents the cipher suite which is used to handshake between node and relay server.
	CipherSuite = noise.NewCipherSuite(noise.DH25519, noise.CipherChaChaPoly, noise.HashBLAKE2s)

	// HandshakePatternNN represents the handshake pattern which is used to exchange the DH key.
	HandshakePatternNN = noise.HandshakeNN
	HandshakePatternIK = noise.HandshakeIK
)

Functions

func Credential

func Credential(privateKey *rsa.PrivateKey, userID protocol.UserID, peerID protocol.PeerID, ip net.IP, lease time.Duration) ([]byte, error)

Credential returns a credential to identity the Peer, which contains the expiration time and the reclaimed IP address. All requests relevant to IP address, the credential is required. We will verify the triple: -> (PeerID, IP, Expiration). The schema of credential: | PeerID | PeerID | Expiration | IPLen | IP | | 8 bytes | 8 bytes | 8 bytes | 1 byte | Variant | The credential delivered to the client will be encrypted by secret key. The secret key is a private key only held by the gateway.

func Hash

func Hash(password, salt string) string

Hash returns the hash value of the password with salt

func VerifyCredential

func VerifyCredential(publicKey *rsa.PublicKey, credential []byte) (userID protocol.UserID, peerID protocol.PeerID, ip net.IP, valid bool)

VerifyCredential verifies the expiration of the credential, returns the networkID, peerID and IP

Types

type DHKey

type DHKey struct {
	Public  DHPublic  `json:"public"`
	Private DHPrivate `json:"private"`
}

DHKey a noise.DHkey wrapper for PairMesh

func FromNoiseDHKey

func FromNoiseDHKey(nKey noise.DHKey) *DHKey

FromNoiseDHKey generate a DHKey from noise.DHKey

func (*DHKey) Equals

func (k *DHKey) Equals(k2 *DHKey) bool

func (*DHKey) IsZero

func (k *DHKey) IsZero() bool

func (*DHKey) ToNoiseDHKey

func (k *DHKey) ToNoiseDHKey() noise.DHKey

ToNoiseDHKey re-generate noise.DHKey from DHKey

type DHKeyBytes

type DHKeyBytes [keySize]byte

func (DHKeyBytes) B32

func (k DHKeyBytes) B32() *[keySize]byte

B32 returns k as the *[32]byte type that's used by the golang.org/x/crypto packages. This allocates; it might not be appropriate for performance-sensitive paths.

func (DHKeyBytes) Bytes

func (k DHKeyBytes) Bytes() []byte

func (DHKeyBytes) IsZero

func (k DHKeyBytes) IsZero() bool

IsZero reports whether the DHPrivate p is the zero value.

func (DHKeyBytes) Len

func (k DHKeyBytes) Len() int

func (DHKeyBytes) MarshalText

func (k DHKeyBytes) MarshalText() ([]byte, error)

func (DHKeyBytes) ShortString

func (k DHKeyBytes) ShortString() string

ShortString returns the PairMesh conventional debug representation of a public key: the first five base64 digits of the key, in square brackets.

func (DHKeyBytes) String

func (k DHKeyBytes) String() string

func (*DHKeyBytes) UnmarshalText

func (k *DHKeyBytes) UnmarshalText(txt []byte) error

type DHPrivate

type DHPrivate struct{ DHKeyBytes }

DHPrivate represents a curve25519 private key.

func NewDHPrivate

func NewDHPrivate(s []byte) DHPrivate

NewDHPrivate returns a new private key.

type DHPublic

type DHPublic struct{ DHKeyBytes }

DHPublic represents a curve25519 public key.

func NewDHPublic

func NewDHPublic(s []byte) DHPublic

NewDHPublic returns a new public key.

Jump to

Keyboard shortcuts

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