=head1 NAME Pretty Curved Privacy - File encryption using eliptic curve cryptography. =head1 SYNOPSIS Usage: pcp1 [options] General Options: -V --vault Specify an alternate vault file. The deault vault is ~/.pcpvault. -O --outfile Output file. If not specified, stdout will be used. -I --infile Input file. If not specified, stdin will be used. -i --keyid Specify a key id to import/export. -r --recipient Specify a recpipient, used for public key export and encryption. -t --text Print textual representation of some item. Specify -V to get info about a vault, -i to get info about a key id installed in the vault or -I in which case it determines itself what kind of file it is. -h --help Print this help message. -v --version Print program version. -D --debug Enable debug output. Keymanagement Options: -k --keygen Generate a CURVE25519 secret key. If the generated key is the first one in your vault, it will become the primary secret key. If an output file (-O) has been specified, don't store the generated key to the vault but export it to the file instead. You will be asked for an owner, mail and a passphrase. If you leave the passphrase empty, the key will be stored unencrypted. -l --listkeys List all keys currently stored in your vault. Only the key id's and some info about the keys will be printed, not the actual keys. -R --remove-key Remove a key from the vault. Requires option -i . -s --export-secret Export a secret key. If your vault only contains one secret key, this one will be exported. If a key id have been specified (-i), this one will be used. If there are more than one secret keys in the vault and no key id has been given, export the primary secret key. Use -O to export to a file. -p --export-public Export a public key. If no key id have been specified, the public part of your primary secret key will be exported. Use -O to export to a file. -S --import-secret Import a secret key. Use -I to import from a file. -P --import-public Import a public key. Use -I to import from a file. -y --export-yaml Export all keys stored in your vault as YAML formatted text. Use -O to put the export into a file. Encryption Options: -e --encrypt Asym-Encrypt a message. Read from stdin or specified via -I. Output will be written to stdout or the file given with -O. If a keyid (-i) has been given, use that public key for encryption. If one or more recipient (-r) has been given, encrypt the message for all recipients asymetrically, given there are matching public keys installed in the vault for them. If none of -i or -r has been given, encrypt the message symetrically. This is the same as -m (self-encryption mode). -m --encrypt-me Sym-Encrypt a message. Specify -I and/or -O for input/output file. You will be asked for a passphrase. No key material will be used. Same as -e without -r and -i. -d --decrypt Decrypt a message. Read from stdin or specified via -I. Output to stdout or written to the file specified via -O. The primary secret key will be used for decryption, if there is no primary and just one secret key in the vault, this one will be used. Otherwise you'll have to specify the keyid (-i) of the key. You need to have the public key of the sender installed in your vault. If the input is self-encrypted (symetrically) a passphrase will be requested. Signature Options: -g --sign Create a signature of file specified with -I (or from stdin) using your primary secret key. If -r has been given, a derived secret key will be used for signing. -c --check-signature Verify a signature in file against the file specified with -I (or stdin). The public key required for this must exist in your vault file. -a --detach Write a detached signature file, which doesn't contain the original content. Output will be z85 encoded always. To verify, you need to specify the original file to be verified against using -I as well (plus -a). Encoding Options: -z --z85-encode Encode something to Z85 encoding. Use -I and -O respectively, otherwise it stdin/stdout. -Z --z85-decode Decode something from Z85 encoding. Use -I and -O respectively, otherwise it stdin/stdout =head1 DESCRIPTION B (pcp1) is a commandline utility which can be used to encrypt files. B uses eliptc curve cryptography for encryption (CURVE25519 by Dan J. Bernstein). While CURVE25519 is no worldwide accepted standard it hasn't been compromised by the NSA - which might be better, depending on your point of view. B: since CURVE25519 is no accepted standard, B has to be considered as experimental software. In fact, I wrote it just to learn about the curve and see how it works. Beside some differences it works like B. So, if you already know how to use gpg, you'll feel almost home. =head1 QUICKSTART Lets say, Alicia and Bobby want to exchange encrypted messages. Here's what the've got to do. First, both have create a secret key: Alicia Bobby pcp1 -k pcp1 -k After entering their name, email address and a passphrase to protect the key, it will be stored in their B (by default ~/.pcpvault). Now, both of them have to export the public key, which has to be imported by the other one. With B you can export the public part of your primary key, but the better solution is to export a derived public key especially for the recipient: Alicia Bobby pcp1 -p -r Bobby -O alicia.pub pcp1 -p -r Alicia -O bobby.pub They've to exchange the public key somehow (which is not my problem at the moment, use ssh, encrypted mail, whatever). Once exchanged, they have to import it: Alicia Bobby pcp1 -P -I bobby.pub pcp1 -P -I alicia.pub They will see a response as this when done: key 0x29A323A2C295D391 added to .pcpvault. Now, Alicia finally writes the secret message, encrypts it and sends it to Bobby, who in turn decrypts it: Alicia Bobby echo "Love you, honey" > letter pcp1 -e -r Bobby -I letter -O letter.asc cat letter.asc | mail bobby@foo.bar pcp1 -d -I letter.asc | less And that's it. Please note the big difference to B though: both Alicia AND Bobby have to enter the passphrase for their secret key! That's the way CURVE25519 works: you encrypt a message using your secret key and the recipients public key and the recipient does the opposite, he uses his secret key and your public key to actually decrypt the message. Oh - and if you're wondering why I named them Alicia and Bobby: I was just sick of Alice and Bob. We're running NSA-free, so we're using other sample names as well. # -*-perl-*- =head1 PCP1 KEYS B keys are stored in a binary file, called B. It's by default located in B<~/.pcpvault> but you can of course specify another location using the B<-V> option. There are two kinds of keys: secret and public keys. In reality a secret key always includes its public key. Both types of keys can be exported to files and transfered to other people who can then import them. You should usually only do this with public keys though. There is a primary secret key which will always used for operations when no keyid has been specified. However, you may have as many secret keys in your vault as you like. Each key can be identified using its B which looks like this: 0xD49119E85266509F A public key exported from a secret key will have the same keyid as the secret key. If you just want to know details about a key or the vault, use the B<-t> option. =head1 ENCRYPTION There are 2 modes of encryption available in pcp1: =over =item B In this mode, which is the default, a public key as specified with B<-i> or B<-r> and your primary secret key will be used for encryption. Example command: pcp1 -e -i 0x2BD734B15CE2722D -I message.txt -O message.asc Here we didn't specify a recipient. Therefore the public key given with -i will be used directly. Another example: pcp1 -e -r Bobby -r McCoy -I message.txt -O message.asc =item B You can also encrypt a file symetrically. No public key material will be used in this mode. While this works, the security of it totally depends on the strength of the passphrase used for encryption. Example command: pcp1 -e -I message.txt -O cipher.z85 As you can see we didn't specify -i or -r and therefore pcp1 operates in self mode for encryption. It will ask you for a passphrase to protect the encryption key. =back =head1 SIGNATURES There are 3 modes for digital signatures available on pcp1: =over =item B In this mode, which is the default, an ED25519 signature will be calculated from a BLAKE2 hash of the input file content. Both the original file content plus the signature will be written to the output file. Example: pcp1 -g -I message.txt -O message.asc -g You will be asked for the passphrase to access your primary secret key. The output file will be a binary file. =item B While this mode does the very same calculations, the output slightly differs. The output file will be marked as a signature file, the signature itself will be appended with its own headers and Z85 encoded. Example: pcp1 -g -I message.txt -O message.asc -g -z You will be asked for the passphrase to access your primary secret key. The output file will be a text file. =item B In some cases you will need to have the signature separated from the original input file, e.g. to sign download files. You can generate detached signatures for such purposes. Still, the signature will be calculated the same way as in standard signatures but put out into a separate file. A detached signature file will always be Z85 encoded. Example: pcp1 -g -I message.txt -O message.asc -g --detach =back =head1 SIGNED ENCRYPTION Beside pure encryption and signatures pcp1 also supports signed encryption. In this mode an input file will be encrypted and a signature using your primary secret key from a BLAKE2 hash of the file contents will be appended to it. Example: pcp1 -e -g -r Bobby -I README.txt -O README.asc Please note the additional B<-g> parameter. The recipient can decrypt and verify the so created data like this: pcp1 -d -c -I README.asc -o README.txt Please note the additional B<-c> parameter. If decryption works, the output file will be written. If signature verification fails you will be informed, but the decrypted output will be left untouched. It is up to you how to react on an invalid signature. B Note: this behavior might change in the future. =head1 VULNERABILITIES Currently there are a couple of problems which are not addressed. These are usually protocol problems, which are not caused by pcp1. =over =item B Pretty Curved Privacy is a store-and-forward system, it works on files and can't use any cool key exchange protocols therefore. For example there would be B which guarantees a secure key exchange. But CurveCP cannot be used offline. Users have to find other means to exchange keys. That's a pity since with Curve25519 you can't just publish your public key to some key server because in order to encrypt a message, both the recipient AND the sender need to have the public key of each other. It would be possible to publish public keys, and attach the senders public key to the encrypted message, but I'm not sure if such an aproach would be secure enough. =item B At the time of this writing the ECC algorithm Curve25519 is only rarely used, in most cases by experimental software (such as Pretty Curved Privacy). As far as I know there haven't been done the kind of exessive crypto analysis as with other ECC algorithms. While I, as the author of pcp1 totally trust D.J.Bernstein, this may not be the case for you. In short, I'd suggest not to use it on critical systems yet. =back =head1 INTERNALS =head2 VAULT FORMAT The vault file contains all public and secret keys. It's a portable binary file. The file starts with a header: +-------------------------------------------+ | Field Size Description | +-------------------------------------------+ | File ID | 1 | Vault Identifier 0xC4 | +-------------------------------------------+ | Version | 4 | Big endian, version | +-------------------------------------------+ | Checksum | 32 | SHA256 Checksum | +-------------------------------------------+ The checksum is a checksum of all keys. The header is followed by the keys. Each key is preceded by a key header which looks like this: +--------------------------------------------+ | Field Size Description | +--------------------------------------------+ | Type | 1 | Key type (S,P,M) | +--------------------------------------------+ | Size | 4 | Big endian, keysize | +--------------------------------------------+ | Version | 4 | Big endian, keyversion | +--------------------------------------------+ | Checksum | 32 | SHA256 Key Checksum | +--------------------------------------------+ Type can be one of: PCP_KEY_TYPE_MAINSECRET 0x01 PCP_KEY_TYPE_SECRET 0x02 PCP_KEY_TYPE_PUBLIC 0x03 The key header is followed by the actual key, see below. =head2 SECRET KEY FORMAT A secret key is a binary structure with the following format: +---------------------------------------------------------+ | Field Size Description | +-------------+--------+----------------------------------+ | Public | 32 | Curve25519 Public Key Part | +-------------|--------|----------------------------------+ | Secret | 32 | Curve25519 Secret Key Unencrypted| +-------------|--------|----------------------------------+ | ED25519 Pub | 32 | ED25519 Public Key Part | +-------------|--------|----------------------------------+ | ED25519 Sec | 64 | ED25519 Secret Key Unencrypted | +-------------|--------|----------------------------------+ | Nonce | 24 | Nonce for secret key encryption | +-------------|--------|----------------------------------+ | Encrypted | 48 | Encrypted Curve25519 Secret Key | +-------------|--------|----------------------------------+ | Owner | 255 | String, Name of Owner | +-------------|--------|----------------------------------+ | Mail | 255 | String, Email Address | +-------------|--------|----------------------------------+ | ID | 17 | String, Key ID | +-------------|--------|----------------------------------+ | Ctime | 4 | Creation time, sec since epoch | +-------------|--------|----------------------------------+ | Version | 4 | Key version | +-------------|--------|----------------------------------+ | Serial | 4 | Serial Number | +-------------|--------|----------------------------------+ | Type | 1 | Key Type | +-------------+--------+----------------------------------+ Some notes: The secret key fields will be filled with random data if the key is encrypted. The first byte of it will be set to 0 in that case. The key id is a computed JEN Hash of the secret and public key concatenated, put into hex, as a string. The key version is a static value, currently 0x2. If the key format changes in the future, this version number will be increased to distinguish old from new keys. Exported keys will be encoded in Z85 encoding. When such an exported key is imported, only the actual Z85 encoded data will be used. Header lines and lines starting with whitespace will be ignored. They are only there for convenience. Key generation works like this: =over =item * Generate a random seed (32 bytes). =item * Generate a ED25519 sigining keypair from that seed. =item * Generate a random seed (32 bytes). =item * Generate a Curve25519 encryption keypair from that seed. =back So, while both secrets are stored in the sam PCP key, they are otherwise unrelated. If one of them leaks, the other cannot be recalculated from it. Take a look at the function B for details. =head2 ENCRYPTED OUTPUT FORMAT Encrypted output will always written as binary files. No armoring supported yet. The encryption process works as this: =over =item generate a random symetric 32 byte key B =item encrypt it asymetrically for each recipient using a unique nonce (B) =item encrypt the input file 32k blockwise using the symetric key =back Symetric encryption works the very same with the recipient stuff left out. Formal format description, asymetric encrypted files: +---------------------------------------------------------+ | Field Size Description | +-------------+--------+----------------------------------+ | Type | 1 | Filetype, 5=ASYM, 23=SYM | +-------------|--------|----------------------------------+ | Len R | 4 | Number of recipients (*) | +-------------|--------|----------------------------------+ | Recipients | R*72 | C(recipient)|C(recipient)... (*) | +-------------|--------|----------------------------------+ | Encrypted | ~ | The actual encrypted data | +-------------|--------|----------------------------------+ Left out when doing symetric encryption. Recipient field format: +---------------------------------------------------------+ | Field Size Description | +-------------+--------+----------------------------------+ | Nonce | 24 | Random Nonce, one per R | +-------------|--------|----------------------------------+ | Cipher | 48 | S encrypted with PK or R | +-------------|--------|----------------------------------+ R is calculated using public key encryption using the senders secret key, the recipients public key and a random nonce. =head2 SIGNATURE FORMAT There are different signature formats. Standard binary NACL signatures have the following format: +---------------------------------------------------------+ | Field Size Description | +-------------+--------+----------------------------------+ | Content | ~ | Original file content | +-------------|--------|----------------------------------+ | \nnacl- | 6 | Offset separator | +-------------|--------|----------------------------------+ | Hash | 64 | BLAKE2 hash of the content | +-------------|--------|----------------------------------+ | Signature | 64 | ED25519 signature of BLAKE2 Hash | +-------------|--------|----------------------------------+ The actual signature is not a signature over the whole content of an input file but of a BLAKE2 hash of the content. Armored signatures have the following format: ----- BEGIN ED25519 SIGNED MESSAGE ----- Hash: Blake2 MESSAGE ----- BEGIN ED25519 SIGNATURE ----- Version: PCP v0.2.0 195j%-^/G[cVo4dSk7hU@D>NT-1rBJ]VbJ678H4I!%@-)bzi>zOba5$KSgz7b@R]A0!kL$m MTQ-1DW(e1mma( followed by the binary signature described in B without the offset separator. =head2 Z85 ENCODING B uses Z85 to encode exported keys and armored signatures. =head3 Z85 BACKGROUND The Z85 encoding format is described here: B. It's part of ZeroMQ (B). Z85 is based on ASCII85 with a couple of modifications (portability, readability etc). To fulfil the requirements of the ZeroMQ Z85 functions, B does some additional preparations of raw input before actually doing the encoding, since the input for zmq_z85_encode() must be divisible by 4: Expand the input so that the resulting size is divisible by 4. Fill the added bytes with zeroes. Prepend the input with a one byte value which holds the number of zeroes added in the previous step. Example: Raw input: hello\0 Here, the input size is 6, which is insufficient, therefore it has to be expanded to be 8. After the process the input looks like this: 1hello\0\0 So, we padded the input with 1 zero (makes 7 bytes) and preprended it with the value 1 (the number of zeros added): makes 8 bytes total. After decoding Z85 input the process will be reversed. B. =head2 PBP COMPATIBILITY PCP tries to be fully compatible with PBP (https://github.com/stef/pbp). Encrypted files and signatures - at least their binary versions - should be exchangable. However, this is a work in progress and might not work under all circumstances. Also there's currently no shared key format between pbp and pcp. =head1 COPYRIGHT Copyright (c) 2013 by T.Linden =head1 ADDITIONAL COPYRIGHTS =over =item B Copyright (c) 2007-2013 iMatix Corporation Copyright (c) 2009-2011 250bpm s.r.o. Copyright (c) 2010-2011 Miru Limited Copyright (c) 2011 VMware, Inc. Copyright (c) 2012 Spotify AB =item B Copyright 2009 Colin Percival =item B Bob Jenkins, Public Domain. =item B Copyright (c) 2003-2013, Troy D. Hanson =item B Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. Comitted by Alexander von Gernler in rev 1.7. =back Every incorporated source code is opensource and licensed under the B as well. =head1 AUTHORS I> =head1 LICENSE Licensed under the GNU GENERAL PUBLIC LICENSE version 3. =head1 HOME The homepage of Pretty Curved Privacy can be found on http://www.daemon.de/PrettyCurvedPrivacy. The source is on Github: https://github.com/TLINDEN/pcp =cut