ENGINE-220 still broken with gpgme1.6.0/gpg2.0.30 despite of more gentle callback. WIP, commit to switch back to 2.1vm gpgme_passphrase_cb
authorEdouard Tisserant <edouard@pep-project.org>
Fri, 21 Jul 2017 15:53:57 +0200
branchgpgme_passphrase_cb
changeset 1937e32c06c3ffba
parent 1936 ad64ede64fb2
child 1938 97fcdff36aa7
ENGINE-220 still broken with gpgme1.6.0/gpg2.0.30 despite of more gentle callback. WIP, commit to switch back to 2.1vm
src/pgp_gpg.c
src/pgp_gpg_internal.h
     1.1 --- a/src/pgp_gpg.c	Thu Jul 20 13:37:21 2017 -0400
     1.2 +++ b/src/pgp_gpg.c	Fri Jul 21 15:53:57 2017 +0200
     1.3 @@ -97,7 +97,7 @@
     1.4      return true;
     1.5  }
     1.6  
     1.7 -gpgme_error_t passphrase_stub(
     1.8 +gpgme_error_t passphrase_cb(
     1.9  		void *hook, 
    1.10  		const char *uid_hint, 
    1.11  		const char *passphrase_info, 
    1.12 @@ -105,7 +105,33 @@
    1.13  		int fd)
    1.14  {
    1.15      printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");
    1.16 -    return GPG_ERR_NO_ERROR;
    1.17 +
    1.18 +	gpgme_error_t error = GPG_ERR_NO_ERROR; 
    1.19 +	//char *secret = "blah";
    1.20 +  
    1.21 +	// to cancel :  
    1.22 + 	// return gpg_error(GPG_ERR_CANCELED);
    1.23 +    
    1.24 +	// TODO : use hook to retrieve client session
    1.25 +	// TODO : call adapter's client passphrase callback
    1.26 +
    1.27 +    // size_t len = strlen(secret);
    1.28 +    // size_t cursor = 0;
    1.29 +    // do {
    1.30 +	// 	ssize_t wres = gpg.gpgme_io_write(fd, secret + cursor, len - cursor);
    1.31 +	// 	if (wres < 0) {
    1.32 +	// 		error = gpg.gpgme_error_from_errno(errno);
    1.33 +	// 		goto exit_free;
    1.34 +	// 		break;
    1.35 +	// 	}
    1.36 +	// 	cursor += wres;
    1.37 +    // } while ( cursor < len );
    1.38 +
    1.39 +	gpg.gpgme_io_write( fd, "\n", 1 );
    1.40 +
    1.41 +//exit_free:
    1.42 +	//free(secret);
    1.43 +	return error;
    1.44  }
    1.45  
    1.46  PEP_STATUS pgp_init(PEP_SESSION session, bool in_first)
    1.47 @@ -240,6 +266,11 @@
    1.48              "gpgme_data_read");
    1.49          assert(gpg.gpgme_data_read);
    1.50  
    1.51 +        gpg.gpgme_error_from_errno
    1.52 +            = (gpgme_error_from_errno_t) (intptr_t) dlsym(gpgme,
    1.53 +            "gpgme_error_from_errno");
    1.54 +        assert(gpg.gpgme_error_from_errno);
    1.55 +
    1.56          gpg.gpgme_op_decrypt
    1.57              = (gpgme_op_decrypt_t) (intptr_t) dlsym(gpgme,
    1.58              "gpgme_op_decrypt");
    1.59 @@ -406,7 +437,7 @@
    1.60      }
    1.61      assert(session->ctx);
    1.62  
    1.63 -    gpgme_error = gpg.gpgme_set_protocol(session->ctx, GPGME_PROTOCOL_OpenPGP);
    1.64 +    gpgme_error = gpg.gpgme_set_passphrase_cb(session->ctx, passphrase_cb, NULL);
    1.65      gpgme_error = _GPGERR(gpgme_error);
    1.66      assert(gpgme_error == GPG_ERR_NO_ERROR);
    1.67  
    1.68 @@ -414,7 +445,7 @@
    1.69      gpgme_error = _GPGERR(gpgme_error);
    1.70      assert(gpgme_error == GPG_ERR_NO_ERROR);
    1.71  
    1.72 -    gpgme_error = gpg.gpgme_set_passphrase_cb(session->ctx, &passphrase_stub, NULL);
    1.73 +    gpgme_error = gpg.gpgme_set_protocol(session->ctx, GPGME_PROTOCOL_OpenPGP);
    1.74      gpgme_error = _GPGERR(gpgme_error);
    1.75      assert(gpgme_error == GPG_ERR_NO_ERROR);
    1.76  
     2.1 --- a/src/pgp_gpg_internal.h	Thu Jul 20 13:37:21 2017 -0400
     2.2 +++ b/src/pgp_gpg_internal.h	Fri Jul 21 15:53:57 2017 +0200
     2.3 @@ -31,6 +31,12 @@
     2.4  typedef size_t(*gpgme_data_read_t)(gpgme_data_t DH, void *BUFFER,
     2.5      size_t LENGTH);
     2.6  
     2.7 +// error handling
     2.8 +
     2.9 +typedef gpgme_error_t (*gpgme_error_from_errno_t)(int err);
    2.10 +
    2.11 +
    2.12 +
    2.13  // encrypt and decrypt
    2.14  
    2.15  typedef gpgme_error_t(*gpgme_op_decrypt_t)(gpgme_ctx_t CTX,
    2.16 @@ -93,6 +99,7 @@
    2.17  #endif
    2.18  #endif
    2.19  
    2.20 +// passphrase & pinentry
    2.21  
    2.22  typedef gpgme_error_t(*gpgme_set_passphrase_cb_t)(gpgme_ctx_t ctx, 
    2.23  		gpgme_passphrase_cb_t passfunc, void *hook_value);
    2.24 @@ -117,6 +124,7 @@
    2.25      gpgme_data_identify_t gpgme_data_identify;
    2.26      gpgme_data_seek_t gpgme_data_seek;
    2.27      gpgme_data_read_t gpgme_data_read;
    2.28 +    gpgme_error_from_errno_t gpgme_error_from_errno;
    2.29  
    2.30      gpgme_op_decrypt_t gpgme_op_decrypt;
    2.31      gpgme_op_verify_t gpgme_op_verify;