Akero (ἄγγελος, messenger) is an easy-to-use library for peer-to-peer public key cryptography. It enables two or more endpoints to exchange encrypted and/or signed messages without requiring a pre-shared secret.
Under the hood Akero uses standard OpenSSL primitives. Each instance wraps a RSA-keypair, a corresponding X.509 certificate and exchanges self-signed messages (PKCS#7) with other instances.
Akero does not try to be a substitute for a fully featured PKI. It is meant to be used as a building block in scenarios where trust-relationships and keyrings can be managed externally, and where the complexity of traditional solutions (X.509 PKI, OpenPGP, custom RSA) yields no tangible benefits.
- Secure 1-to-n messaging (sign-only -or- sign->encrypt->sign)
- Low complexity; easy to use, understand and review (only 192 lines of code)
- Transport agnostic; messages and certificates are self-contained and optionally ascii-armored (base64)
- Built on standard OpenSSL primitives, no homegrown algorithms
- 100% test coverage
gem install akero
require 'akero'
# Alice, Bob and Charlie are Akero instances
alice = Akero.new
bob = Akero.new
charlie = Akero.new
# Inspect Alice's keypair fingerprint
alice.id # => "AK:12:34:56:..."
# Alice signs a message
signed_msg = alice.sign("Hello world!")
# Anyone can receive this message and extract
# Alice's fingerprint and public key from it
msg = bob.receive(signed_msg)
msg.body # => "Hello world!"
msg.type # => :signed
msg.from # => "AK:12:34:56:..."
msg.from_pk # => "(alice-public-key)"
# Bob encrypts a message for Alice
bobs_msg = bob.encrypt(msg.from_pk, "Hello Alice!")
# Alice can receive it...
msg = alice.receive(bobs_msg)
msg.body # => "Hello Alice!"
msg.type # => :encrypted
msg.from # => "AK:ab:cd:ef:..."
msg.from_pk # => "(bob-public-key)"
# ...and Charlie can't
msg = charlie.receive(bobs_msg) # => Exception is raised
# Alice encrypts a message for Bob and Charlie
msg = alice.encrypt([bob.public_key, charlie.public_key], "Hello!")
# Save Alice to a file
File.open('/tmp/alice.akr', 'w') { |f| f.write(alice.private_key) }
# And load her again
new_alice = Akero.load(File.read('/tmp/alice.akr'))
# By default all messages are ascii armored.
# In production Alice disables the armoring
# for better performance.
signed_msg = alice.sign("Hello world!", false)
encrypted_msg = alice.encrypt(alice.public_key, "Hello!", false)
puts alice.receive(encrypted_msg).body # => "Hello!"
$ akero id -i /tmp/alice.akr
Private key not found. Generating a new 4096 bits RSA key and saving to /tmp/alice.akr ...
AK:8B:33:5B:AB:4C:78:CA:5E:CC:F5:FE:D7:75:F2:A4:74:16:28:FB:C2
$ akero id -i /tmp/bob.akr
Private key not found. Generating a new 4096 bits RSA key and saving to /tmp/bob.akr ...
AK:CF:B3:4C:BA:7C:9C:2E:31:2D:0D:1D:3F:F9:F4:05:F6:C7:B2:38:3F
$ akero pk -i /tmp/bob.akr >/tmp/bob.pk
$ echo "Hello" | akero encrypt -i /tmp/alice.akr /tmp/bob.pk | akero receive -i /tmp/bob.akr
Hello
The above charts were generated using MRI 1.9.3p362 (x86_64-linux) on an AMD Turion II Neo N40L CPU.
You may run the benchmarks on your own machine with rake benchmark
.
Copyright (c) 2012 [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.