Documentation ¶
Index ¶
- Constants
- Variables
- func Decode(data []byte, conf Config) ([]byte, error)
- func DecodeString(data string, conf Config) (string, error)
- func Encode(data []byte, conf Config) ([]byte, error)
- func EncodeString(data string, conf Config) (string, error)
- func ExtractRemotePublicKey(p string) (string, bool)
- func IsPassphraseRight(prv PrivateKey) (bool, error)
- func ReadKey(unixPath string) ([]byte, error)
- func SSHDir() (string, error)
- type AgentClient
- type AgentReq
- type AgentRes
- type AgentServer
- type Config
- type Meta
- type MetaFlag
- type PrivateKey
- type PublicKey
- type Whisper
Examples ¶
Constants ¶
const ( APIVersion = "v0.4.1" FormatVersion = byte(3) )
Variables ¶
var ErrNoPrivateKey = errors.New("no private key")
var ErrPrvKeyNotFound = errors.New("private key not found")
var ErrPubKeyNotFound = errors.New("public key not found")
var ErrPubPrvNotMatch = errors.New("public and private key not match")
var ErrVersionMismatch = errors.New("whisper file format version mismatch")
var ErrWrongPublicKey = errors.New("the public key from option -a doesn't belong to the private key")
Functions ¶
func ExtractRemotePublicKey ¶ added in v0.4.0
func IsPassphraseRight ¶ added in v0.2.3
func IsPassphraseRight(prv PrivateKey) (bool, error)
Types ¶
type AgentClient ¶ added in v0.3.13
type AgentClient interface { Whisper(conf Config, in io.Reader, out io.Writer) error IsPassphraseRight(prv PrivateKey) (bool, error) IsServerRunning(version string) (bool, error) ClearCache() error }
func NewAgentClient ¶ added in v0.3.13
func NewAgentClient(addr string) AgentClient
type AgentServer ¶ added in v0.1.0
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 agent 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 { // Gzip compression level GzipLevel int // For data decryption and signature signing. Private *PrivateKey // For signature checking and meta data prefixing. Sign *PublicKey // For data encryption of different recipients. // If the list is empty, it will be a decryption process. Public []PublicKey }
func (Config) EncodeMeta ¶ added in v0.3.0
The meta format is:
[version][flags][sender][key num][key2 hash]...
"version" is the whisper file format version. "flags" about the encoding, such as if gzip, base64 are enabled or not. "sender" is the sender's public key [PublicKey.ID] and [PublicKey.Selector]. "key num" is the num of recipients. "key1 hash" is the hash of the first recipient's public key. "key2 hash" is the hash of the second recipient's public key. ...
func (Config) IsDecryption ¶ added in v0.4.0
type Meta ¶ added in v0.3.0
type Meta struct { Gzip bool Sign bool LongPubKeyHash bool Sender *PublicKey // The key is the hash of the recipient's public key, value is the index of the recipient in the key list. Recipients map[string]int }
func DecodeMeta ¶ added in v0.3.0
DecodeMeta decodes the meta from the whisper file.
func PeakMeta ¶ added in v0.4.0
func PeakMeta(in io.ReadCloser) (*Meta, io.ReadCloser, error)
PeakMeta read the meta data from the input stream, and return the unread input stream.
func (*Meta) FindSSHPrivateKey ¶ added in v0.4.0
FindSSHPrivateKey find the private key that matches the recipients' public key in the ~/.ssh folder.
type PrivateKey ¶ added in v0.0.5
type PublicKey ¶ added in v0.0.5
type PublicKey struct { Data []byte // A public ID for the public key, it can be a https url or github id. ID string // Uses to select the specific key in the URL file. // The line contains the Selector substring will be selected. Selector string }
func FetchPublicKey ¶ added in v0.4.0
func PublicKeyFromMeta ¶ added in v0.3.0
type Whisper ¶ added in v0.3.0
type Whisper struct {
// contains filtered or unexported fields
}
Whisper is a data encryption and decryption file format. The whisper file extension is ".wsp".
func New ¶ added in v0.0.4
New encoder and decoder pair. The encoding process:
data -> gzip -> cipher -> sign -> meta -> base64
The sign, gzip, base64 are optional.
Decoding is the reverse as the encoding. It will still decode the whole data even the signature check fails, it will return secure.ErrSignNotMatch error.
Example ¶
package main import ( "fmt" "os" "path/filepath" whisper "github.com/ysmood/whisper/lib" ) func main() { recipient01, recipient01Pub := keyPair("id_ecdsa01", "test") recipient02, recipient02Pub := keyPair("id_ecdsa02", "test") // Encrypt the message that can be decrypted by both recipient01 and recipient02. encrypted, _ := whisper.EncodeString("hello world!", whisper.Config{ Public: []whisper.PublicKey{recipient01Pub, recipient02Pub}, }) decrypted01, _ := whisper.DecodeString(encrypted, whisper.Config{Private: &recipient01}) decrypted02, _ := whisper.DecodeString(encrypted, whisper.Config{Private: &recipient02}) fmt.Println(decrypted01, decrypted02) } func keyPair(privateKeyName, passphrase string) (whisper.PrivateKey, whisper.PublicKey) { prv, err := os.ReadFile(filepath.FromSlash("secure/test_data/" + privateKeyName)) if err != nil { panic(err) } pub, err := os.ReadFile(filepath.FromSlash("secure/test_data/" + privateKeyName + ".pub")) if err != nil { panic(err) } return whisper.PrivateKey{prv, passphrase}, whisper.PublicKey{Data: pub} }
Output: hello world! hello world!
func (*Whisper) Decoder ¶ added in v0.3.0
Decoder decrypt data stream from the in as whisper file format.
func (*Whisper) Encoder ¶ added in v0.3.0
Encoder encrypt data stream to the out as whisper file format.
func (*Whisper) Handle ¶ added in v0.4.0
func (w *Whisper) Handle(input io.ReadCloser, output io.WriteCloser) error