crypt

package
v0.34.10 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: GPL-3.0 Imports: 34 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const TotpLen = 6

Variables

View Source
var (
	SkipVerify = false
)

Functions

func AddTrustedCert added in v0.28.1

func AddTrustedCert(vkey string, fp []byte)

AddTrustedCert trusts the bridge certificate with fingerprint fp for the client with vkey, in place of the one trusted for it before.

func AesEncrypt

func AesEncrypt(origData, key []byte) ([]byte, error)

func Blake2b added in v0.27.0

func Blake2b(s string) string

Blake2b Generate 64-bit BLAKE2b-256 strings

func BuildTotpUri added in v0.29.30

func BuildTotpUri(issuer, accountName, secret string) string

func ComputeHMAC added in v0.27.0

func ComputeHMAC(passwd string, timestamp int64, randomDataPieces ...[]byte) []byte

ComputeHMAC Get HMAC value

func DecryptBytes added in v0.27.0

func DecryptBytes(enc []byte, keyStr string) ([]byte, error)

DecryptBytes AES-GCM

func DecryptStringWithPrivateKey added in v0.29.2

func DecryptStringWithPrivateKey(base64Cipher string) (string, error)

func DecryptWithPrivateKey added in v0.29.2

func DecryptWithPrivateKey(base64Cipher string) ([]byte, error)

func EncryptBytes added in v0.27.0

func EncryptBytes(data []byte, keyStr string) ([]byte, error)

EncryptBytes AES-GCM

func FNV1a64 added in v0.29.9

func FNV1a64(parts ...string) string

func GenerateTOTPSecret added in v0.29.0

func GenerateTOTPSecret() (string, error)

func GenerateUUID added in v0.30.6

func GenerateUUID(nameParts ...string) uuid.UUID

func GetCert

func GetCert() tls.Certificate

func GetCertFingerprint added in v0.28.0

func GetCertFingerprint(certificate tls.Certificate) []byte

GetCertFingerprint returns the SHA-256 of certificate's leaf, as the bridge sends it to the client during the handshake, or nil if it has none.

func GetFakeDomainName added in v0.30.4

func GetFakeDomainName() string

func GetHMAC added in v0.30.4

func GetHMAC(passwd string, data ...[]byte) []byte

func GetRSAPublicKeyPEM added in v0.29.37

func GetRSAPublicKeyPEM() (string, error)

func GetRandomString

func GetRandomString(l int, id ...int) string

GetRandomString 生成指定长度的随机密钥,支持可选传入id

func GetTOTPCode added in v0.29.0

func GetTOTPCode(secret string) (string, int64, error)

func GetUUID added in v0.31.1

func GetUUID() uuid.UUID

func InitTls

func InitTls(customCert tls.Certificate)

func IsValidTOTPSecret added in v0.29.30

func IsValidTOTPSecret(secret string) bool

func Md5

func Md5(s string) string

Md5 Generate 32-bit MD5 strings

func NewPinnedTlsClientConfig added in v0.34.8

func NewPinnedTlsClientConfig(fingerprint []byte) *tls.Config

NewPinnedTlsClientConfig returns a TLS client configuration that accepts only the server certificate with fingerprint (its SHA-256), as the server sent it, encrypted with the vkey, during the bridge handshake. It ignores SkipVerify: the fingerprint is authenticated by the vkey itself.

func NewTlsClientConn

func NewTlsClientConn(conn net.Conn) net.Conn

NewTlsClientConn returns a TLS client on conn that accepts only bridge certificates trusted by AddTrustedCert, or any if SkipVerify.

func NewTlsServerConn

func NewTlsServerConn(conn net.Conn) net.Conn

func PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int) []byte

PKCS5Padding Completion when the length is insufficient

func PinFingerprint added in v0.34.8

func PinFingerprint(fingerprint []byte) *tlsconn.PinSet

PinFingerprint returns the pin set holding the certificate with fingerprint, its SHA-256 (GetCertFingerprint), or an empty set, which trusts no certificate, if fingerprint is not a SHA-256.

func PrintTOTPCode added in v0.29.0

func PrintTOTPCode(secret string)

func PrintTOTPSecret added in v0.29.0

func PrintTOTPSecret()

func ReadClientHello

func ReadClientHello(clientConn net.Conn, prefix []byte) (helloInfo *tls.ClientHelloInfo, rawData []byte, err error)

func ValidateTOTPCode added in v0.29.0

func ValidateTOTPCode(secret, code string) (bool, error)

Types

type LoginPayload added in v0.29.2

type LoginPayload struct {
	Nonce     string `json:"n"`
	Timestamp int64  `json:"t"`
	Password  string `json:"p"`
}

func ParseLoginPayload added in v0.29.2

func ParseLoginPayload(base64Cipher string) (*LoginPayload, error)

type ReadOnlyConn

type ReadOnlyConn struct {
	// contains filtered or unexported fields
}

func (*ReadOnlyConn) Close

func (c *ReadOnlyConn) Close() error

func (*ReadOnlyConn) LocalAddr

func (c *ReadOnlyConn) LocalAddr() net.Addr

func (*ReadOnlyConn) Read

func (c *ReadOnlyConn) Read(p []byte) (int, error)

func (*ReadOnlyConn) RemoteAddr

func (c *ReadOnlyConn) RemoteAddr() net.Addr

func (*ReadOnlyConn) SetDeadline

func (c *ReadOnlyConn) SetDeadline(_ time.Time) error

func (*ReadOnlyConn) SetReadDeadline

func (c *ReadOnlyConn) SetReadDeadline(_ time.Time) error

func (*ReadOnlyConn) SetWriteDeadline

func (c *ReadOnlyConn) SetWriteDeadline(_ time.Time) error

func (*ReadOnlyConn) Write

func (c *ReadOnlyConn) Write(_ []byte) (int, error)

type SniffConn

type SniffConn struct {
	net.Conn

	Rb []byte
	// contains filtered or unexported fields
}

func NewSniffConn

func NewSniffConn(conn net.Conn, maxSize int) *SniffConn

func (*SniffConn) Bytes

func (s *SniffConn) Bytes() []byte

func (*SniffConn) Read

func (s *SniffConn) Read(p []byte) (int, error)

Jump to

Keyboard shortcuts

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