Documentation
¶
Overview ¶
Package miniLock is a modern, authenticated, asymmetric encryption protocol that conceals metadata.
go-miniLock is a total Golang rewrite of miniLock.io, enabling native code performance, more platform flexibility, and downstream potential for automation and novel communication media not available to the original miniLock Chromium app.
go-minilock is copyright 2015, and proudly licensed under the GNU Affero General Public License, version 3 or later at your option.
To understand the code layout here, it may help to understand how minilock organises ciphertext. When creating ciphertext, minilock uses a symmetric cipher to encrypt chunks of the plaintext file, and indexes/length-prefixes each encrypted chunk. So, the raw ciphertext is a sliced and boxed version of the plaintext, using NaCL-style box encryption.
Minilock then puts some file metadata in a fileInfo datastructure including filename, file hash, and the symmetric cipher key, and encrypts this datastructure to an ephemeral key generated just for this ciphertext. This ephemeral key's private key component is then encrypted to each intended recipient, and each recipient's "decryptInfo" datastructure is added to the file header.
The resulting header, consisting of the fileInfo object and the various decryptInfo objects, is prepended to the raw ciphertext, and is in turn prepended with a Header length indicator and a magic 8-byte leader ("miniLock" in ascii). The result is a finished miniLock file.
This means that boxing or unwrapping a message has three stages of encryption/decryption, so the API of this library may at first seem daunting. One may well ask why I didn't hide all the messy details; firstly, I don't believe in hiding API details merely for aesthetics because I constantly encounter libraries that hide functions I genuinely need access to. Secondly, because there are other ways to use the fileInfo, decryptInfo and raw ciphertext objects that would require individual access to each level.
If you just want to encrypt a thing to a key, the function EncryptFileContentsWithStrings does everything at once; feed it your filename/contents, your chosen GUID (eg. your email), your passphrase, whether to include you as a recipient, and the miniLock IDs of all intended recipients, and you'll get back a finished miniLock file.
Likewise, to decrypt a miniLock file, just pass the miniLock file contents, your GUID/email, and your passphrase to DecryptFileContentsWithStrings, and you'll get back the sender's ID, filename, and file contents.
Please use responsibly; crypto is easy to do wrong and can do real harm if it exposes private information. I make no guarantees that my code is safe to use, in this sense.
Index ¶
- Variables
- func DecryptFileContents(fileContents []byte, recipientKey *taber.Keys) (senderID, filename string, contents []byte, err error)
- func DecryptFileContentsWithStrings(fileContents []byte, recipientEmail, recipientPassphrase string) (senderID, filename string, contents []byte, err error)
- func EncryptDecryptInfo(di *DecryptInfoEntry, nonce []byte, ephemKey, recipientKey *taber.Keys) ([]byte, error)
- func EncryptFileContents(filename string, fileContents []byte, sender *taber.Keys, ...) (miniLockContents []byte, err error)
- func EncryptFileContentsWithStrings(filename string, fileContents []byte, senderEmail, senderPassphrase string, ...) (miniLockContents []byte, err error)
- func EphemeralKey() (*taber.Keys, error)
- func GenerateKey(email string, passphrase string) (*taber.Keys, error)
- func ImportID(id string) (*taber.Keys, error)
- func LoadKey(private, public []byte) *taber.Keys
- func ParseFile(filepath string) (header *miniLockv1Header, ciphertext []byte, err error)
- func ParseFileContents(contents []byte) (header *miniLockv1Header, ciphertext []byte, err error)
- type DecryptInfoEntry
- type FileInfo
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBadMagicBytes is returned when magic bytes didn't match expected 'miniLock'. ErrBadMagicBytes = errors.New("Magic bytes didn't match expected 'miniLock'") // ErrBadLengthPrefix is returned when header length exceeds file length. ErrBadLengthPrefix = errors.New("Header length exceeds file length") // ErrCTHashMismatch is returned when ciphertext hash did not match. ErrCTHashMismatch = errors.New("Ciphertext hash did not match") // ErrBadRecipient is returned when decryptInfo successfully decrypted but was addressed to another key. ErrBadRecipient = errors.New("DecryptInfo successfully decrypted but was addressed to another key") // ErrCannotDecrypt is returned when could not decrypt given ciphertext with given key or nonce. ErrCannotDecrypt = errors.New("Could not decrypt given ciphertext with given key or nonce") // ErrInsufficientEntropy is returned when got insufficient random bytes from RNG. ErrInsufficientEntropy = errors.New("Got insufficient random bytes from RNG") // ErrNilPlaintext is returned when got empty plaintext, can't encrypt. ErrNilPlaintext = errors.New("Got empty plaintext, can't encrypt") )
Functions ¶
func DecryptFileContents ¶
func DecryptFileContents(fileContents []byte, recipientKey *taber.Keys) (senderID, filename string, contents []byte, err error)
DecryptFileContents parses header and ciphertext from a file, decrypts the header with recipientKey, and uses details therein to decrypt the enclosed file. Returns sender, filename, file contents if successful, or an error if not; Check the error to see if it's benign (cannot decrypt with given key) or bad.
func DecryptFileContentsWithStrings ¶
func DecryptFileContentsWithStrings(fileContents []byte, recipientEmail, recipientPassphrase string) (senderID, filename string, contents []byte, err error)
DecryptFileContentsWithStrings is the highest-level API for decryption. It uses the recipient's email and passphrase to generate their key, attempts decryption, and wipes keys when finished.
func EncryptDecryptInfo ¶
func EncryptDecryptInfo(di *DecryptInfoEntry, nonce []byte, ephemKey, recipientKey *taber.Keys) ([]byte, error)
EncryptDecryptInfo encrypts a decryptInfo struct using the ephemeral pubkey and the same nonce as the enclosed fileInfo.
func EncryptFileContents ¶
func EncryptFileContents(filename string, fileContents []byte, sender *taber.Keys, recipients ...*taber.Keys) (miniLockContents []byte, err error)
EncryptFileContents is an entry point for encrypting byte slices from a prepared sender key to prepared recipient keys. EncryptFileContentsWithStrings is much easier to use for most applications.
func EncryptFileContentsWithStrings ¶
func EncryptFileContentsWithStrings(filename string, fileContents []byte, senderEmail, senderPassphrase string, sendToSender bool, recipientIDs ...string) (miniLockContents []byte, err error)
EncryptFileContentsWithStrings is an entry point that largely defines "normal" miniLock behaviour. If sendToSender is true, then the sender's ID is added to recipients.
func EphemeralKey ¶
EphemeralKey generates a fully random key, usually for ephemeral uses.
func GenerateKey ¶
GenerateKey makes a key from an email address and passphrase, consistent with the miniLock algorithm. Passphrase is *not* currently checked for strength so it is, at present, the caller's responsibility to provide passphrases that don't suck!
func ParseFileContents ¶
ParseFileContents parses a miniLock file and returns header and ciphertext.
Types ¶
type DecryptInfoEntry ¶
type DecryptInfoEntry struct { SenderID string `json:"senderID"` RecipientID string `json:"recipientID"` FileInfoEnc []byte `json:"fileInfo"` }
DecryptInfoEntry is the container for the decryption instructions of "FileInfo", also containing sender and recipient. It is encrypted to the recipient with an ephemeral key to preserve privacy.
func DecryptDecryptInfo ¶
func DecryptDecryptInfo(diEnc, nonce []byte, ephemPubkey, recipientKey *taber.Keys) (*DecryptInfoEntry, error)
DecryptDecryptInfo is used to extract a decryptInfo object by attempting decryption with a given recipientKey. This must be attempted for each decryptInfo in the header until one works or none work, as miniLock deliberately provides no indication of intended recipients.
func NewDecryptInfoEntry ¶
func NewDecryptInfoEntry(nonce []byte, fileinfo *FileInfo, senderKey, recipientKey *taber.Keys) (*DecryptInfoEntry, error)
NewDecryptInfoEntry creates a decryptInfo entry for the given fileInfo to the intended recipientKey, from senderKey.
func (*DecryptInfoEntry) ExtractFileInfo ¶
func (di *DecryptInfoEntry) ExtractFileInfo(nonce []byte, recipientKey *taber.Keys) (*FileInfo, error)
ExtractFileInfo pulls out the fileInfo object from the decryptInfo object, authenticating encryption from the sender.
func (*DecryptInfoEntry) SenderPubkey ¶
func (die *DecryptInfoEntry) SenderPubkey() (*taber.Keys, error)
SenderPubkey returns the pubkey of the sender who (allegedly) created this DecryptInfoEntry.
type FileInfo ¶
type FileInfo struct { FileKey []byte `json:"fileKey"` FileNonce []byte `json:"fileNonce"` FileHash []byte `json:"fileHash"` }
FileInfo is the marrow at the heart of the miniLock header that contains decryption instructions for the encrypted file container.
func EncryptFileToFileInfo ¶
func EncryptFileToFileInfo(filename string, filecontents []byte) (FI *FileInfo, ciphertext []byte, err error)
EncryptFileToFileInfo symmetrically encrypts a file or plaintext and returns the fileInfo object to decrypt it and the raw ciphertext. This operation is technically independent of miniLock and could be used for other crypto-schemes as a handy way to encrypt files symmetrically.
func (*FileInfo) DecryptFile ¶
DecryptFile - Given a ciphertext, walk it into length prefixed chunks and decrypt/reassemble each chunk, then validate the hash of the file against the hash given in FileInfo. The result is a validated, decrypted filename and file contents byte-slice.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package taber - for all your NaCL needs.
|
Package taber - for all your NaCL needs. |