whisper

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var Base64Encoding = base64.RawURLEncoding

Functions

func CallAgent added in v0.1.0

func CallAgent(addr string, req AgentReq, in io.Reader, out io.Writer)

Return true if the passphrase is correct.

func Decode added in v0.0.5

func Decode(data []byte, receiver PrivateKey, sender []byte) ([]byte, error)

func DecodeString added in v0.0.5

func DecodeString(data string, receiver PrivateKey, sender []byte) (string, error)

func Encode added in v0.0.5

func Encode(data []byte, sender PrivateKey, receivers ...[]byte) ([]byte, error)

func EncodeString added in v0.0.5

func EncodeString(data string, sender PrivateKey, receivers ...[]byte) (string, error)

func IsAgentRunning added in v0.1.0

func IsAgentRunning(addr, version string) bool

func IsPassphraseRight added in v0.2.3

func IsPassphraseRight(addr string, prv PrivateKey) bool

func New added in v0.0.4

func New(conf Config) (piper.EncodeDecoder, error)

New data encoding flow:

data -> gzip -> encrypt -> base64
Example
package main

import (
	"fmt"
	"os"
	"path/filepath"

	whisper "github.com/ysmood/whisper/lib"
)

func main() {
	sender, senderPub := whisper.PrivateKey{read("id_ecdsa"), "test"}, read("id_ecdsa.pub")

	receiver01, receiver01Pub := whisper.PrivateKey{read("id_ecdsa01"), "test"}, read("id_ecdsa01.pub")
	receiver02, receiver02Pub := whisper.PrivateKey{read("id_ecdsa02"), "test"}, read("id_ecdsa02.pub")

	// Encrypt the message that can be decrypted by both receiver01 and receiver02.
	enc, _ := whisper.EncodeString("hello world!", sender, receiver01Pub, receiver02Pub)

	dec01, _ := whisper.DecodeString(enc, receiver01, senderPub)
	dec02, _ := whisper.DecodeString(enc, receiver02, senderPub)

	fmt.Println(dec01, dec02)

}

func read(path string) []byte {
	b, err := os.ReadFile(filepath.FromSlash("secure/test_data/" + path))
	if err != nil {
		panic(err)
	}
	return b
}
Output:

hello world! hello world!

func Version added in v0.1.0

func Version() string

Version return the md5 hash of all the files in [source].

Types

type AgentReq added in v0.1.0

type AgentReq struct {
	Version         string
	Decrypt         bool
	CheckPassphrase bool

	PublicKey secure.KeyWithFilter
	Config    Config
}

type AgentRes added in v0.1.0

type AgentRes struct {
	Running         bool
	PassphraseRight bool
	WrongPublicKey  bool
}

type AgentServer added in v0.1.0

type AgentServer struct {
	Logger *slog.Logger
	// contains filtered or unexported fields
}

AgentServer is a tcp server that can be used to avoid inputting the passphrase every time. It will do the encryption and decryption for you, not the cli client. There's no way to get the passphrase from the tcp client, the only way to get the passphrase is to have root permission and dump the os memory. If the server restarts you have to send it to server again.

func NewAgentServer added in v0.1.0

func NewAgentServer() *AgentServer

func (*AgentServer) Handle added in v0.1.0

func (a *AgentServer) Handle(s io.ReadWriteCloser) error

func (*AgentServer) Listen added in v0.1.0

func (a *AgentServer) Listen(l net.Listener)

Serve start a http server to avoid inputting the passphrase every time.

func (*AgentServer) Serve added in v0.1.0

func (a *AgentServer) Serve(addr string)

Serve start a http server to avoid inputting the passphrase every time.

type Config added in v0.1.0

type Config struct {
	GzipLevel int
	Base64    bool
	Private   PrivateKey
	Public    []secure.KeyWithFilter
}

type PrivateKey added in v0.0.5

type PrivateKey struct {
	Data []byte

	// Passphrase is used to decrypt the [PrivateKey.Data]
	Passphrase string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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