summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--src/admin.vala78
-rw-r--r--src/main.vala11
3 files changed, 91 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index e44a21e..0102716 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
SRC=src/main.vala src/device.vala src/scannersession.vala src/db.vala src/audio.vala src/web.vala src/graph-data.vala src/template.vala src/websession.vala src/admin.vala src/price.vapi
-DEPS=--pkg posix --pkg linux --pkg libsoup-2.4 --pkg sqlite3 --pkg gee-1.0 --pkg gio-2.0 --pkg gstreamer-0.10
-FLAGS=-X -w --enable-experimental --thread
+DEPS=--pkg posix --pkg linux --pkg libsoup-2.4 --pkg sqlite3 --pkg gee-1.0 --pkg gio-2.0 --pkg gstreamer-0.10 --pkg libarchive --pkg gpgme
+FLAGS=-X -lgpgme -X -w --enable-experimental --thread --vapidir=vapi
barcode-scanner: $(SRC)
valac-0.16 --output $@ $(FLAGS) $(DEPS) $^
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 */
+}
diff --git a/src/main.vala b/src/main.vala
index 7f9d3c1..81f006d 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -19,6 +19,8 @@ public AudioPlayer audio;
public CSVMemberFile csvimport;
public ScannerSession localsession;
public MainLoop loop;
+public PGPKeyArchive pgp;
+public KeyFile cfg;
const OptionEntry[] option_entries = {
{ "version", 'v', OptionFlags.IN_MAIN, OptionArg.NONE, ref opt_version, "output version information and exit", null },
@@ -64,6 +66,15 @@ public static int main(string[] args) {
loop = new MainLoop();
localsession = new ScannerSession();
+ try {
+ cfg = new KeyFile();
+ cfg.load_from_file("ktt-shopsystem.cfg", KeyFileFlags.NONE);
+ } catch(Error e) {
+ error("Could not load configuration file: %s", e.message);
+ }
+
+ pgp = new PGPKeyArchive(cfg);
+
dev.received_barcode.connect((data) => {
if(localsession.interpret(data))
dev.blink(10);