{"action":"created","issue":{"url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/475","repository_url":"https://api.github.com/repos/ElektraInitiative/libelektra","labels_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/475/labels{/name}","comments_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/475/comments","events_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/475/events","html_url":"https://github.com/ElektraInitiative/libelektra/issues/475","id":131991646,"number":475,"title":"Add GPG-Interface","user":{"login":"petermax2","id":2538677,"avatar_url":"https://avatars.githubusercontent.com/u/2538677?v=3","gravatar_id":"","url":"https://api.github.com/users/petermax2","html_url":"https://github.com/petermax2","followers_url":"https://api.github.com/users/petermax2/followers","following_url":"https://api.github.com/users/petermax2/following{/other_user}","gists_url":"https://api.github.com/users/petermax2/gists{/gist_id}","starred_url":"https://api.github.com/users/petermax2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petermax2/subscriptions","organizations_url":"https://api.github.com/users/petermax2/orgs","repos_url":"https://api.github.com/users/petermax2/repos","events_url":"https://api.github.com/users/petermax2/events{/privacy}","received_events_url":"https://api.github.com/users/petermax2/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ElektraInitiative/libelektra/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/ElektraInitiative/libelektra/labels/work%20in%20progress","name":"work in progress","color":"006b75"}],"state":"open","locked":false,"assignee":{"login":"petermax2","id":2538677,"avatar_url":"https://avatars.githubusercontent.com/u/2538677?v=3","gravatar_id":"","url":"https://api.github.com/users/petermax2","html_url":"https://github.com/petermax2","followers_url":"https://api.github.com/users/petermax2/followers","following_url":"https://api.github.com/users/petermax2/following{/other_user}","gists_url":"https://api.github.com/users/petermax2/gists{/gist_id}","starred_url":"https://api.github.com/users/petermax2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petermax2/subscriptions","organizations_url":"https://api.github.com/users/petermax2/orgs","repos_url":"https://api.github.com/users/petermax2/repos","events_url":"https://api.github.com/users/petermax2/events{/privacy}","received_events_url":"https://api.github.com/users/petermax2/received_events","type":"User","site_admin":false},"assignees":[{"login":"petermax2","id":2538677,"avatar_url":"https://avatars.githubusercontent.com/u/2538677?v=3","gravatar_id":"","url":"https://api.github.com/users/petermax2","html_url":"https://github.com/petermax2","followers_url":"https://api.github.com/users/petermax2/followers","following_url":"https://api.github.com/users/petermax2/following{/other_user}","gists_url":"https://api.github.com/users/petermax2/gists{/gist_id}","starred_url":"https://api.github.com/users/petermax2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petermax2/subscriptions","organizations_url":"https://api.github.com/users/petermax2/orgs","repos_url":"https://api.github.com/users/petermax2/repos","events_url":"https://api.github.com/users/petermax2/events{/privacy}","received_events_url":"https://api.github.com/users/petermax2/received_events","type":"User","site_admin":false}],"milestone":null,"comments":25,"created_at":"2016-02-07T17:53:29Z","updated_at":"2016-08-16T17:53:02Z","closed_at":null,"body":"# Problem Setting\r\n\r\nThe crypto plugin is quite useless at the moment as there is no way to use it with the kdb command. \r\n\r\nThe introduction of a GPG interface enables the user to utilize her existing key-pairs for cryptographic operations in Elektra. The private key is used for encrypting a random sequence, which serves as seed for a key derivation function (KDF). This way we can safely derivate cryptographic keys for symmetric value encryption. Both OpenSSL and libgcrypt have built-in support for the PBKDF2 (see [RFC 2898](https://tools.ietf.org/html/rfc2898)). [1, 2]\r\n\r\nThe PBKDF2 needs an **iteration number** and a **salt** in order to work. Those values will be stored per Key as MetaKey.\r\n\r\n# Solution\r\n\r\nSee discussion below to find how we came to the results.\r\n\r\n## Procedure\r\n\r\nDuring the **mount phase** a random master password _r_ is being generated. _r_ is sent to the gpg binary for encryption. The resulting encrypted master password _m_ is stored in the plugin configuration at `config/masterChallenge`.\r\n\r\nDuring the **set phase** the master password _m_ is sent to the gpg binary for decryption in order to retrieve _r_. The following steps will be repeated for every Key _k_, that is supposed to be encrypted. A random salt _s(k)_ is generated. By applying the PBKDF2 (mentioned earlier) with _r_ and _s(k)_, the cryptographic key _e(k)_ and the initialization vector _i(k)_ is being derived. The value of _k_ will be encrypted using _e(k)_ and _i(k)_. The seed _s(k)_ will be encoded as prefix into the encrypted value.\r\n\r\nDuring the **get phase** the master password _m_ is sent to the gpg binary for decryption in order to retrieve _r_. The following steps will be repeated for every Key _k_, that is supposed to be decrypted. The salt _s(k)_ is read from the encrypted message. By applying the PBKDF2 with _r_ and _s(k)_ the values of _e(k)_ and _i(k)_ are restored. Then the encrypted message can be decrypted.\r\n\r\n## General notes\r\n\r\nWe do not call the gpg-agent directly. Neither KMail nor Evolution do that. Instead they both call the gpg binary directly. In `~/.gnupg/gpg.conf` the usage of the gpg-agent can be enabled by setting the `use-agent` option. The gpg binary is the best way of handeling the gpg-agent protocol.\r\n\r\nThe plugin configuration must contain at least one GPG key descriptor that can be used as **recipient** but also for decrypting messages. See `man gpg` for more information about valid GPG key descriptions.\r\n\r\n# Implementation Tasks\r\n\r\n- [x] implement module for calling the gpg binary\r\n- [x] implement module for retrieving/storing the master-challenge\r\n- [x] implement the key/IV derivation using the master-challenge in the plugin variant `crypto_gcrypt`\r\n- [ ] implement the key/IV derivation using the master-challenge in the plugin variant `crypto_openssl`\r\n- [ ] implement the key/IV derivation using the master-challenge in the plugin variant `crypto_botan`\r\n- [ ] implement plugin-variant that uses GPG directly for symmetric encryption\r\n- [ ] update the documentation and plugin description\r\n- [ ] write/update test cases\r\n- [ ] check availability of gpg binary in CMake (?)\r\n\r\n# References\r\n\r\n[1] [OpenSSL online documentation](https://www.openssl.org/docs/manmaster/crypto/PKCS5_PBKDF2_HMAC.html)\r\n[2] The Libgcrypt Reference Manual Version 1.6.4. Koch, Schulte. 2015."},"comment":{"url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/comments/240183116","html_url":"https://github.com/ElektraInitiative/libelektra/issues/475#issuecomment-240183116","issue_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/475","id":240183116,"user":{"login":"petermax2","id":2538677,"avatar_url":"https://avatars.githubusercontent.com/u/2538677?v=3","gravatar_id":"","url":"https://api.github.com/users/petermax2","html_url":"https://github.com/petermax2","followers_url":"https://api.github.com/users/petermax2/followers","following_url":"https://api.github.com/users/petermax2/following{/other_user}","gists_url":"https://api.github.com/users/petermax2/gists{/gist_id}","starred_url":"https://api.github.com/users/petermax2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petermax2/subscriptions","organizations_url":"https://api.github.com/users/petermax2/orgs","repos_url":"https://api.github.com/users/petermax2/repos","events_url":"https://api.github.com/users/petermax2/events{/privacy}","received_events_url":"https://api.github.com/users/petermax2/received_events","type":"User","site_admin":false},"created_at":"2016-08-16T17:53:02Z","updated_at":"2016-08-16T17:53:02Z","body":"> During the mount phase a random master password r is being generated. r is sent to the gpg binary for encryption. The resulting encrypted master password m is stored in the plugin configuration at config/masterChallenge.\r\n\r\nThe plugin configuration is not persisted. However the encrypted master password _r_ has to be stored somewhere where it can be retrieved later on as it is mandatory for decryption.\r\n\r\nMaybe we should expect a plugin configuration key holding the information of where to put the master password _r_ and take a default like `user/crypto/password` if not provided (although the default does not make any sense if the it is not mounted).\r\n\r\nTo illustrate what I mean here. We would mount like this:\r\n\r\n    kdb mount ~/test.ini user/test ini crypto_gcrypt password=user/test/pwd\r\n\r\nto tell the plugin to put the encrypted master password to `user/test/pwd` in this case.\r\n\r\n@markus2330 What do you think about it? Why did we plan on putting the encrypted master password into the plugin config anyway?"}}
{"actor":{"display_login":"petermax2"}}