crypt

package
v0.35.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 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 = otp.DefaultDigits

TotpLen is the length of a TOTP code.

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, error)

BuildTotpUri returns the otpauth URI of secret for authenticator apps.

func FNV1a64 added in v0.29.9

func FNV1a64(parts ...string) string

func GenerateTOTPSecret added in v0.29.0

func GenerateTOTPSecret() (string, error)

GenerateTOTPSecret returns a new random secret in base32.

func GetCertContent added in v0.35.0

func GetCertContent(filePath, header string) (string, error)

GetCertContent returns filePath itself when it is PEM text containing header, or else the content of that file, relative to the run path.

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 GetCertType added in v0.35.0

func GetCertType(s string) string

GetCertType reports whether s is "empty", PEM "text", an existing "file" or "invalid".

func GetFakeDomainName added in v0.30.4

func GetFakeDomainName() string

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)

GetTOTPCode returns the current code of secret and the seconds it stays current.

func GetUUID added in v0.31.1

func GetUUID() uuid.UUID

func IsValidTOTPSecret added in v0.29.30

func IsValidTOTPSecret(secret string) bool

IsValidTOTPSecret reports whether secret is a usable base32 secret.

func LoadKeyPair added in v0.35.0

func LoadKeyPair(certFile, keyFile string) (tls.Certificate, error)

LoadKeyPair loads a certificate and its key, each given as PEM text or as the path of a PEM file, relative to the run path.

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, cert tls.Certificate) net.Conn

NewTlsServerConn returns a TLS server on conn that presents cert.

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)

PrintTOTPCode prints the current code of secret.

func PrintTOTPSecret added in v0.29.0

func PrintTOTPSecret()

PrintTOTPSecret prints a new secret and its QR code.

func SecretIndex added in v0.35.0

func SecretIndex(password string) string

SecretIndex names the secret tunnel of password in an attach request, so that nps finds the tunnel without a search; the password itself never travels. Like any hash of a password it is a verifier an observer could test guesses against, so it travels only inside the encrypted bridge connection.

func SecretProof added in v0.35.0

func SecretProof(password string, nonce []byte, node string) []byte

SecretProof is a visitor's proof that it knows password: an HMAC over the nonce nps sent for this attach and the visitor's node (npc uuid), so that a captured proof is good for no other attach.

func VerifyTOTP added in v0.35.0

func VerifyTOTP(secret, code string) bool

VerifyTOTP reports whether code is a current code of secret that was not accepted before.

Types

type Identity added in v0.35.0

type Identity struct {
	Cert tls.Certificate
	// contains filtered or unexported fields
}

Identity is the certificate a process presents in TLS, and the RSA key the web login encrypts credentials to.

func NewIdentity added in v0.35.0

func NewIdentity(custom tls.Certificate) (*Identity, error)

NewIdentity returns the identity of custom, or of a fresh self-signed certificate when custom holds none. The RSA key is the certificate's own when it is an RSA key, a fresh one otherwise.

func (*Identity) Fingerprint added in v0.35.0

func (id *Identity) Fingerprint() []byte

Fingerprint returns the SHA-256 of the certificate's leaf (GetCertFingerprint).

func (*Identity) ParseLoginPayload added in v0.35.0

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

ParseLoginPayload decrypts the credentials a web login sent.

func (*Identity) RSAPublicKeyPEM added in v0.35.0

func (id *Identity) RSAPublicKeyPEM() (string, error)

RSAPublicKeyPEM returns the public RSA key the web login encrypts to.

func (*Identity) TLSCert added in v0.35.0

func (id *Identity) TLSCert() tls.Certificate

TLSCert returns the certificate, none for a nil identity.

type LoginPayload added in v0.29.2

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

Jump to

Keyboard shortcuts

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