ENGINE-220 setting pinentry mode (surprise, surprise : no more key deletion confirmation dialog) and registering stub passphrase callback gpgme_passphrase_cb
authorEdouard Tisserant <edouard@pep-project.org>
Thu, 20 Jul 2017 13:37:21 -0400
branchgpgme_passphrase_cb
changeset 1936ad64ede64fb2
parent 1935 adc342c265ee
child 1937 e32c06c3ffba
ENGINE-220 setting pinentry mode (surprise, surprise : no more key deletion confirmation dialog) and registering stub passphrase callback
.hgignore
src/pgp_gpg.c
src/pgp_gpg_internal.h
     1.1 --- a/.hgignore	Thu Jul 20 16:46:29 2017 +0200
     1.2 +++ b/.hgignore	Thu Jul 20 13:37:21 2017 -0400
     1.3 @@ -54,3 +54,4 @@
     1.4  secring.gpg
     1.5  trustdb.gpg
     1.6  .pEp_management.db
     1.7 +test/test_home
     2.1 --- a/src/pgp_gpg.c	Thu Jul 20 16:46:29 2017 +0200
     2.2 +++ b/src/pgp_gpg.c	Thu Jul 20 13:37:21 2017 -0400
     2.3 @@ -97,6 +97,16 @@
     2.4      return true;
     2.5  }
     2.6  
     2.7 +gpgme_error_t passphrase_stub(
     2.8 +		void *hook, 
     2.9 +		const char *uid_hint, 
    2.10 +		const char *passphrase_info, 
    2.11 +		int prev_was_bad, 
    2.12 +		int fd)
    2.13 +{
    2.14 +    printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");
    2.15 +    return GPG_ERR_NO_ERROR;
    2.16 +}
    2.17  
    2.18  PEP_STATUS pgp_init(PEP_SESSION session, bool in_first)
    2.19  {
    2.20 @@ -280,6 +290,11 @@
    2.21              "gpgme_set_passphrase_cb");
    2.22          assert(gpg.gpgme_set_passphrase_cb);
    2.23  
    2.24 +        gpg.gpgme_set_pinentry_mode
    2.25 +            = (gpgme_set_pinentry_mode_t) (intptr_t) dlsym(gpgme,
    2.26 +            "gpgme_set_pinentry_mode");
    2.27 +        assert(gpg.gpgme_set_pinentry_mode);
    2.28 +
    2.29          gpg.gpgme_get_key
    2.30              = (gpgme_get_key_t) (intptr_t) dlsym(gpgme, "gpgme_get_key");
    2.31          assert(gpg.gpgme_get_key);
    2.32 @@ -395,6 +410,14 @@
    2.33      gpgme_error = _GPGERR(gpgme_error);
    2.34      assert(gpgme_error == GPG_ERR_NO_ERROR);
    2.35  
    2.36 +    gpgme_error = gpg.gpgme_set_pinentry_mode(session->ctx, GPGME_PINENTRY_MODE_LOOPBACK);
    2.37 +    gpgme_error = _GPGERR(gpgme_error);
    2.38 +    assert(gpgme_error == GPG_ERR_NO_ERROR);
    2.39 +
    2.40 +    gpgme_error = gpg.gpgme_set_passphrase_cb(session->ctx, &passphrase_stub, NULL);
    2.41 +    gpgme_error = _GPGERR(gpgme_error);
    2.42 +    assert(gpgme_error == GPG_ERR_NO_ERROR);
    2.43 +
    2.44      gpg.gpgme_set_armor(session->ctx, 1);
    2.45  
    2.46      return PEP_STATUS_OK;
     3.1 --- a/src/pgp_gpg_internal.h	Thu Jul 20 16:46:29 2017 +0200
     3.2 +++ b/src/pgp_gpg_internal.h	Thu Jul 20 13:37:21 2017 -0400
     3.3 @@ -97,6 +97,8 @@
     3.4  typedef gpgme_error_t(*gpgme_set_passphrase_cb_t)(gpgme_ctx_t ctx, 
     3.5  		gpgme_passphrase_cb_t passfunc, void *hook_value);
     3.6  
     3.7 +typedef gpgme_error_t(*gpgme_set_pinentry_mode_t)(gpgme_ctx_t ctx,
     3.8 +		gpgme_pinentry_mode_t mode);
     3.9  
    3.10  struct gpg_s {
    3.11      const char * version;
    3.12 @@ -152,4 +154,5 @@
    3.13      gpgme_io_write_t gpgme_io_write;
    3.14  
    3.15      gpgme_set_passphrase_cb_t gpgme_set_passphrase_cb;
    3.16 +    gpgme_set_pinentry_mode_t gpgme_set_pinentry_mode;
    3.17  };