diff options
Diffstat (limited to 'src/admin.vala')
-rw-r--r-- | src/admin.vala | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/admin.vala b/src/admin.vala index 4e32a0a..6ba0c0a 100644 --- a/src/admin.vala +++ b/src/admin.vala @@ -73,3 +73,81 @@ public class CSVMemberFile { return members; } } + +public class PGPKeyArchive { + private string keyring; + private GPG.Context gpg; + + public PGPKeyArchive(KeyFile config) { + /* check version (important!) */ + GPG.check_version(); + + /* initialize default context */ + GPG.Context.Context(out gpg); + + try { + keyring = config.get_string("PGP", "keyring"); + + /* remove quotes */ + if(keyring.has_prefix("\"") && keyring.has_suffix("\"")) + keyring = keyring.substring(1,keyring.length-2); + } catch(KeyFileError e) { + write_to_log("KeyFileError: %s", e.message); + return; + } + + /* TODO: check existence of keyring */ + + /* set home directory */ + var info = gpg.get_engine_info(); + gpg.set_engine_info(info.protocol, info.file_name, keyring); + } + + public void read() { + unowned Archive.Entry entry; + var archive = new Archive.Read(); + + /* support all formats & compression types */ + archive.support_compression_all(); + archive.support_format_all(); + + /* load test archive for now */ + /* TODO: use archive.open_memory(void *buffer, size_t size) */ + if(archive.open_filename("pgp-test.tar.gz", 4096) != Archive.Result.OK) + return; + + while(archive.next_header(out entry) == Archive.Result.OK) { + var name = entry.pathname(); + var size = entry.size(); + var content = new uint8[size]; + + /* skip entries, which contain a slash */ + if(name.contains("/")) + continue; + + /* skip files, which are big (probably not a minimal pgp key) */ + if(size > 50000) + continue; + + if(archive.read_data((void*) content, (ssize_t) size) == size) { + if(!((string) content).has_prefix("-----BEGIN PGP PUBLIC KEY BLOCK-----")) + continue; + + /* put byte data into GPG.Data object */ + GPG.Data gpgdata; + GPG.Data.create_from_memory(out gpgdata, content, false); + + /* import keys */ + gpg.op_import(gpgdata); + } + } + } + + /* TODO: implement method, which list all keys available in the gpg keyring */ + + /* TODO: implement method, which gets a key by keyid from gpg keyring */ + + /* TODO: implement method, which signs a message */ + + /* TODO: implement method, which signs & encrypts a message */ +} |