gpgme tutorial t-decrypt.c -> Bad passphrase
mandar.mhatre at crs-iimotion.com
Mon Jun 27 14:44:14 CEST 2016
I am a noob to Cryptography world and few weeks ago started into this
subject. Till now I could use linux console freely and perform all the
described operations. Right now I am trying to understand GPGME and going
through the provided tutorial codes. I am getting an error while running
t-decrypt.c (and t-sign.c as well) as stated in the subject line. The
passphrase_cb has been implemented in ‘t-support.h’ but somehow the code
doesn’t retrieve the required password. I tried to implement my own
callback function on the same lines and came to know that this function is
never being called.
Search on internet didn’t provide me any alternative working code nor any
solution for this problem (Apart from John Morris, Sep 7, 2012) . So I am
mailing GnuPG/GPGME profis.
My goal is to pass a hardcoded password for decryption and signing for
automatic decryption and signing . Any suggestions/modifications in the
code or tutorial codes are appreciated.
Attaching my (tutorial code from GPGME with some debug specific printf’s)
code and other info below.
Thank you in advance.
Raspberry pi 3 with installed gpg, gpg2 and GPGME with dependencies
/* t-decrypt.c - Regression test.
Copyright (C) 2000 Werner Koch (dd9jn)
Copyright (C) 2001, 2003, 2004 g10 Code GmbH
This file is part of GPGME.
GPGME is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
GPGME is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
/* We need to include config.h so that we know whether we are building
with large file system (LFS) support. */
#define _FILE_OFFSET_BITS 64
gpgme_error_t passphrase_cb1 (void *hook, const char *uid_hint, const char
*passphrase_info, int last_was_bad, int fd)
WriteFile ((HANDLE) fd, "abc\n", 4, &written, 0);
printf("in passphrase cb");
const char *pass = "abc\n";
int passlen = strlen (pass);
int off = 0;
res = write (fd, &pass[off], passlen - off);
printf("passphrase is %s", pass);
if ( res > 0)
off += res;
while(res > 0 && off != passlen);
return off == passlen ? 0 : gpgme_error_from_errno (errno);
main (int argc, char *argv)
gpgme_data_t in, out;
const char *cipher_1_asc = make_filename ("cipher-1.asc");
err = gpgme_new (&ctx);
err = gpgme_ctx_set_engine_info (ctx, GPGME_PROTOCOL_OpenPGP,
agent_info = getenv("GPG_AGENT_INFO");
if (!(agent_info && strchr (agent_info, ':')))
printf("in if loop\n");
gpgme_set_passphrase_cb (ctx, passphrase_cb1, NULL);
err = gpgme_data_new_from_file (&in, cipher_1_asc, 1);
err = gpgme_data_new (&out);
printf("data ready \n");
err = gpgme_op_decrypt (ctx, in, out);
fprintf (stderr,"Encrypt error: %s\n", gpgme_strerror (err));
result = gpgme_op_decrypt_result (ctx);
fprintf (stderr, "%s:%i: unsupported algorithm: %s\n",
__FILE__, __LINE__, result->unsupported_algorithm);
In if loop
Encrypt error: Bad passphrase
t-decrypt.c:101: GPGME: Bad passphrase
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Gnupg-users