AW: Cancel operation does not return error code

Schultschik, Sven sven.schultschik at siemens.com
Fri Mar 11 13:02:02 CET 2022


[Sorry, i need to use outlook even if I don't like it, but I will try to
make things better if I know whats wrong. Outlook doesn't even format text
answers correctly :( I made it by hand ... ]

> -----Ursprüngliche Nachricht-----
> Von: Gnupg-users <gnupg-users-bounces at gnupg.org> Im Auftrag von Ingo
Klöcker
> Gesendet: Freitag, 11. März 2022 11:18
> An: gnupg-users at gnupg.org
> Betreff: Re: Cancel operation does not return error code
>
> [It would be great, if you wouldn't top-post even if this isn't easy with
Outlook or Office 365 or whatever email client you are using.]
>
> On Freitag, 11. März 2022 10:29:41 CET Schultschik, Sven via Gnupg-users
> wrote:
> > The method gpgme_op_encrypt provides the interactive possibility itself.
> > 
> > If you don't set a passphrase with gpgme_set_passphrase_cb before 
> > calling gpgme_op_encrypt, it asks itself for a passphrase.
> > 
> > See screenshot.
>
> Okay. You are using pinentry-curses.
>
> > There are more issues with this interactive view.
> > 
> > 1. Cancel does not send an error
>
> I cannot reproduce this. For me it works correctly.
> ```
> $ export GNUPGHOME=$(mktemp --directory) $ cat
>${GNUPGHOME}/gpg-agent.conf <<EOF pinentry-program /usr/bin/pinentry-curses
EOF $ ./t-encrypt-sym [Tab][Tab][Enter]
>../../../../src/gpgme/tests/gpg/t-encrypt-sym.c:67: GPGME: Operation
cancelled ```
>
> > 2. If you wait for the timeout of the passphrase form, it returns 
> > Error 0 Success as well
>
> Let's try.
> ```
> $ cat >>${GNUPGHOME}/gpg-agent.conf <<EOF pinentry-timeout 5 EOF $ gpgconf
--kill all $ ./t-encrypt-sym [wait 5 seconds ...]
>../../../../src/gpgme/tests/gpg/t-encrypt-sym.c:67: GPGME: Operation
cancelled ```
>
> > 3. Ctrl+C does not cancel the gpgme passphrase entry. See screenshot 2
>
> Pressing Ctrl+C while t-encrypt-sym is running and pinentry-curses is
asking for the password quits pinentry-curses and t-encrypt-sym without
further output. That's common behavior for command line programs.
>
> My conclusion is that gpgme_op_encrypt() is working as expected as my
experiments with the official test t-encrypt-sym proves. I suspect that
there is something wrong with your program. Please have a look at the
official test t-encrypt-sym (in tests/gpg > of gpgme's source code) and
check what you are doing differently.

I pretty much copied the tests/gpg/t-encrypt-sym.c
Only difference is to use streams instead of mem

int encryptBackup(string infile, bool cliintpw, string webpw)
{    gpgme_check_version(NULL);

    gpgme_error_t err;
    gpgme_encrypt_result_t result;

    init_gpgme();

    err = gpgme_new(&_ctx);
    fail_if_err(err, NULL, NULL);
    gpgme_set_armor(_ctx, 1);

    FILE *instream;
    instream = fopen(infile.c_str(), "r");
    if (instream == NULL)
    {
        throw runtime_error("Backup archive not found " + infile + "\n");
    }
    gpgme_data_t in = NULL;
    err = gpgme_data_new_from_stream(&in, instream);
    fail_if_err(err, in, NULL, instream);

    FILE *outstream;
    _encryptedArchiveFullFilePath = infile.append(".gpg");
    outstream = fopen(_encryptedArchiveFullFilePath.c_str(), "w");
    gpgme_data_t out = NULL;
    err = gpgme_data_new_from_stream(&out, outstream);
    fail_if_err(err, in, out, instream, outstream,
_encryptedArchiveFullFilePath);

        fprintf(stdout, "DEBUG Start encryption\n"); 
        err = gpgme_op_encrypt(_ctx, NULL, GPGME_ENCRYPT_SYMMETRIC, in,
out);
        fprintf(stdout, "DEBUG ERROR Code = \%d \%s \%s\n" ,
gpgme_err_code(err), gpgme_strsource(err) , gpgme_strerror(err));
        fprintf(stdout, "DEBUG End encryption\n"); 

    fprintf(stdout, "DEBUG Outpath = \%s\n",
_encryptedArchiveFullFilePath.c_str()); 
    fail_if_err(err, in, out, instream, outstream,
_encryptedArchiveFullFilePath);

    result = gpgme_op_encrypt_result(_ctx);

    if (result->invalid_recipients)
    {
        string err(result->invalid_recipients->fpr);
        throw runtime_error("Invalid recipient encountered: " + err + "\n");
    }

    fclose(instream);
    fclose(outstream);
    gpgme_data_release(in);
    gpgme_data_release(out);
    gpgme_release(_ctx);

    return 0;
}


> I'm using gpgme 1.17.1.

I'm on Debian 11 with 	1.14.0-1
Could it be a bug in the "old" version?

Regards
Sven
> Regards,
> Ingo
 
> > -----Ursprüngliche Nachricht-----
> > Von: Gnupg-users <gnupg-users-bounces at gnupg.org> Im Auftrag von Ingo 
> > Klöcker
> > Gesendet: Donnerstag, 10. März 2022 22:16
> > An: gnupg-users at gnupg.org
> > Betreff: Re: Cancel operation does not return error code
> > 
> > On Donnerstag, 10. März 2022 14:30:29 CET Schultschik, Sven via 
> > Gnupg-users
> > 
> > wrote:
> > > if your using gpgme with interactive password entry on the command 
> > > line and the user cancels the operation, shouldn't there be an error 
> > > returned?
> > > 
> > > Following code
> > > 
> > > err = gpgme_op_encrypt(ctx, NULL, GPGME_ENCRYPT_SYMMETRIC, in, out);
> > > 
> > > fprintf(stdout, "DEBUG ERROR Code = \%d \%s \%s\n" , 
> > > gpgme_err_code(err),
> > > gpgme_strsource(err) , gpgme_strerror(err));
> > > 
> > > If user cancel on the passwort screen, the following error code is 
> > > returned
> > > 
> > > ERROR Code = 0 Unspecified source Success
> > 
> > When I run t-encrypt-sym (in gpgme/tests/gpg) and cancel the 
> > passphrase dialog provided by pinentry-qt, then t-encrypt-sym prints
> > ../../../../src/gpgme/tests/gpg/t-encrypt-sym.c:67: GPGME: Operation 
> > cancelled
> > 
> > When I force usage of pinentry-tty and cancel the passphrase entry 
> > with
> > Ctrl+D, then I get the same result:
> > =====
> > $ ./t-encrypt-sym
> > Enter passphrase
> > 
> > Passphrase:
> > ../../../../src/gpgme/tests/gpg/t-encrypt-sym.c:67: GPGME: Operation 
> > cancelled =====
> > 
> > So, in general, gpgme_op_encrypt seems to return the correct error code.
> > What I'm wondering is how do you cancel "interactive password entry on 
> > the command line" resp. how do you do "interactive password entry on 
> > the command line"?
> > 
> > Regards,
> > Ingo

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 14944 bytes
Desc: not available
URL: <https://lists.gnupg.org/pipermail/gnupg-users/attachments/20220311/e6a984e7/attachment-0001.bin>


More information about the Gnupg-users mailing list