Documentation ¶
Overview ¶
Package sign implements Ed25519 signing, verification on files. It builds upon golang.org/x/crypto/ed25519 by adding methods for serializing and deserializing Ed25519 private & public keys.
It can sign and verify very large files - it prehashes the files with SHA-512 and then signs the SHA-512 checksum. The keys and signatures are YAML files and so, human readable.
It can encrypt files for multiple recipients - each of whom is identified by their Ed25519 public key. The encryption by default generates ephmeral Curve25519 keys and creates pair-wise shared secret for each recipient of the encrypted file. The caller can optionally use a specific secret key during the encryption process - this has the benefit of also authenticating the sender (and the receiver can verify the sender if they possess the corresponding public key).
The sign, verify, encrypt, decrypt operations can use OpenSSH Ed25519 keys *or* the keys generated by sigtool. This means, you can send encrypted files to any recipient identified by their comment in `~/.ssh/authorized_keys`.
Index ¶
Constants ¶
const PKHashLength = 16
Length of Ed25519 Public Key Hash
Variables ¶
var ( ErrIncorrectPassword = errors.New("ssh: Invalid Passphrase") ErrNoPEMFound = errors.New("no PEM block found") ErrBadPublicKey = errors.New("ssh: malformed public key") ErrKeyTooShort = errors.New("ssh: public key too short") ErrBadTrailers = errors.New("ssh: trailing junk in public key") ErrBadFormat = errors.New("ssh: invalid openssh private key format") ErrBadLength = errors.New("ssh: private key unexpected length") ErrBadPadding = errors.New("ssh: padding not as expected") )
Functions ¶
This section is empty.
Types ¶
type Decryptor ¶ added in v0.3.0
Decryptor holds the decryption context
func NewDecryptor ¶ added in v0.3.0
Create a new decryption context and if 'pk' is given, check that it matches the sender
func (*Decryptor) AuthenticatedSender ¶ added in v1.1.0
AuthenticatedSender returns true if the sender authenticated themselves (the data-encryption key is signed).
func (*Decryptor) NewStreamReader ¶ added in v0.9.0
NewStreamReader returns an io.Reader to read from the decrypted stream
func (*Decryptor) SetPrivateKey ¶ added in v0.3.0
func (d *Decryptor) SetPrivateKey(sk *PrivateKey, senderPk *PublicKey) error
Use Private Key 'sk' to decrypt the encrypted keys in the header and optionally validate the sender
type Encryptor ¶ added in v0.3.0
Encryptor holds the encryption context
func NewEncryptor ¶ added in v0.3.0
func NewEncryptor(sk *PrivateKey, blksize uint64) (*Encryptor, error)
Create a new Encryption context for encrypting blocks of size 'blksize'. If 'sk' is not nil, authenticate the sender to each receiver.
func (*Encryptor) AddRecipient ¶ added in v0.3.0
Add a new recipient to this encryption context.
func (*Encryptor) Encrypt ¶ added in v0.3.0
Encrypt the input stream 'rd' and write encrypted stream to 'wr'
func (*Encryptor) NewStreamWriter ¶ added in v0.9.0
func (e *Encryptor) NewStreamWriter(wr io.WriteCloser) (io.WriteCloser, error)
NewStreamWriter begins stream encryption to an underlying destination writer 'wr'. It returns an io.WriteCloser.
type Keypair ¶
type Keypair struct { Sec PrivateKey Pub PublicKey }
Ed25519 key pair
type PrivateKey ¶
type PrivateKey struct { Sk []byte // contains filtered or unexported fields }
Private Ed25519 key
func MakePrivateKey ¶
func MakePrivateKey(yml []byte, pw []byte) (*PrivateKey, error)
Make a private key from bytes 'yml' and password 'pw'. The bytes are assumed to be serialized version of the private key.
func PrivateKeyFromBytes ¶ added in v0.3.0
func PrivateKeyFromBytes(buf []byte) (*PrivateKey, error)
Make a private key from 64-bytes of extended Ed25519 key
func ReadPrivateKey ¶
func ReadPrivateKey(fn string, getpw func() ([]byte, error)) (*PrivateKey, error)
Read the private key in 'fn', optionally decrypting it using password 'pw' and create new instance of PrivateKey
func (*PrivateKey) PublicKey ¶ added in v0.3.0
func (sk *PrivateKey) PublicKey() *PublicKey
Given a secret key, return the corresponding Public Key
func (*PrivateKey) SignFile ¶
func (sk *PrivateKey) SignFile(fn string) (*Signature, error)
Read and sign a file
We calculate the signature differently here: We first calculate the SHA-512 checksum of the file and its size. We sign the checksum.
func (*PrivateKey) SignMessage ¶
func (sk *PrivateKey) SignMessage(ck []byte, comment string) (*Signature, error)
Sign a prehashed Message; return the signature as opaque bytes Signature is an YAML file:
Comment: source file path Signature: Ed25519 signature
type PublicKey ¶
type PublicKey struct { Pk []byte // Comment string Comment string // contains filtered or unexported fields }
Public Ed25519 key
func MakePublicKey ¶
Parse a serialized public in 'yml' and return the resulting public key instance
func ParseAuthorizedKeys ¶ added in v0.5.0
ParseAuthorizedKeys parses a public key from an authorized_keys file used in OpenSSH according to the sshd(8) manual page.
func PublicKeyFromBytes ¶ added in v0.3.0
Make a public key from a byte string
func ReadPublicKey ¶
Read the public key from 'fn' and create new instance of PublicKey
func (*PublicKey) VerifyFile ¶
Verify a signature 'sig' for file 'fn' against public key 'pk' Return True if signature matches, False otherwise
type Signature ¶
type Signature struct { Sig []byte // Ed25519 sig bytes // contains filtered or unexported fields }
An Ed25519 Signature
func MakeSignature ¶
Parse serialized signature from bytes 'b' and construct a Signature object
func ReadSignature ¶
Read serialized signature from file 'fn' and construct a Signature object
func (*Signature) IsPKMatch ¶
IsPKMatch returns true if public key 'pk' can potentially validate the signature. It does this by comparing the hash of 'pk' against 'Pkhash' of 'sig'.
func (*Signature) SerializeFile ¶
SerializeFile serializes the signature to an output file 'f'