Repository navigation
Tutorial KP ABE
In key-policy ABE the roles are flipped compared to CP-ABE: ciphertexts carry attributes (usually metadata describing the data) and keys carry a policy. A key decrypts every ciphertext whose attributes satisfy its policy.
Use it when the data is labelled at encryption time and access is decided later: auditing an email archive, answering a subpoena, giving an analyst a slice of a data lake.
Adapted from examples/test_kp.cpp:
#include <cassert>
#include <iostream>
#include <string>
#include <openabe/openabe.h>
#include <openabe/zsymcrypto.h>
using namespace std;
using namespace oabe;
using namespace oabe::crypto;
int main() {
InitializeOpenABE();
OpenABECryptoContext kpabe("KP-ABE");
kpabe.generateParams();
kpabe.keygen("attr1 and attr2", "key0"); // policy goes on the key
string ct, pt1 = "hello world!", pt2;
kpabe.encrypt("|attr1|attr2", pt1, ct); // attributes go on the ciphertext
bool ok = kpabe.decrypt("key0", ct, pt2);
assert(ok && pt1 == pt2);
cout << "Recovered message: " << pt2 << endl;
ShutdownOpenABE();
return 0;
}Build it exactly like the CP-ABE tutorial: see Tutorial: CP-ABE, step 2.
Every email is encrypted with its metadata as attributes. Later, an auditor receives a key that opens only the emails from Alice in a given period:
// At archiving time: one ciphertext per email
kpabe.encrypt("From:Alice|To:Bob|Date = March 7, 2017", mail1, ct1);
kpabe.encrypt("From:Alice|To:Charlie|Date = March 15, 2017", mail2, ct2);
// During the investigation: a key for exactly the slice that is needed
kpabe.keygen("From:Alice and (Date = March 1-14, 2017 or Date = February 22-28, 2017)",
"auditor");
kpabe.decrypt("auditor", ct1, out); // true: March 7 is in range
kpabe.decrypt("auditor", ct2, out); // false: March 15 is notTwo features are at work here:
-
From:Aliceuses the optionaltype:valueform to namespace attributes. -
Date = March 7, 2017is a date attribute, andDate = March 1-14, 2017a date range in the policy.
Both are described in Policy and Attribute Syntax.
./oabe_setup -s KP -p org2
./oabe_keygen -s KP -p org2 \
-i "From:Alice and (Date = March 1-14, 2017 or Date = February 22-28, 2017)" -o analystKP
./oabe_enc -s KP -p org2 -e "From:Alice|To:Bob|Date = March 7, 2017" -i input.txt -o input1.kpabe
./oabe_enc -s KP -p org2 -e "From:Alice|To:Charlie|Date = March 15, 2017" -i input.txt -o input2.kpabe
./oabe_dec -s KP -p org2 -k analystKP.key -i input1.kpabe -o ok.txt # exit 0
./oabe_dec -s KP -p org2 -k analystKP.key -i input2.kpabe -o fail.txt # exit 32| CP-ABE | KP-ABE | |
|---|---|---|
| Policy lives on | the ciphertext | the key |
| Attributes live on | the key | the ciphertext |
| Who decides access | whoever encrypts | whoever issues keys |
| Typical question | "Who may read this?" | "What may this person read?" |
| Good for | documents with known audiences | archives, audits, analytics |
- Let a context find the right key by itself: the keystore in Key Management
- Policy and Attribute Syntax
OpenABE · AGPL-3.0 · Found a mistake in this wiki? Open an issue.
Using OpenABE
Reference
Contributing
Design notes
Help