Skip to content

Commit 729a1a6

Browse files
committed
Warn user if available gpg(-agent) is not (fully) compatible
1 parent bc31037 commit 729a1a6

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

src/appimagetool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ main (int argc, char *argv[])
10701070

10711071
if (sign) {
10721072
if (!sign_appimage(destination, sign_key, verbose)) {
1073-
if (getenv("APPIMAGETOOL_FORCE_SIGN") != NULL) {
1073+
if (getenv(FORCE_SIGN_ENV_VAR) != NULL) {
10741074
fprintf(stderr, "ERROR: signing failed, aborting\n");
10751075
exit(1);
10761076
} else {

src/appimagetool_sign.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "binreloc.h"
1313
#include "appimage/appimage_shared.h"
14+
#include "appimagetool_sign.h"
1415

1516
// used to identify calls to the callback
1617
static const char gpgme_hook[] = "appimagetool gpgme hook";
@@ -349,6 +350,54 @@ bool sign_appimage(char* appimage_filename, char* key_id, bool verbose) {
349350

350351
gpg_check_call(gpgme_new(&gpgme_ctx));
351352

353+
354+
// make sure we have a compatible agent around
355+
{
356+
gpgme_engine_info_t engine_info;
357+
gpg_check_call(gpgme_get_engine_info(&engine_info));
358+
359+
while (engine_info && engine_info->protocol != gpgme_get_protocol(gpgme_ctx)) {
360+
engine_info = engine_info->next;
361+
}
362+
363+
if (engine_info == NULL) {
364+
fprintf(
365+
stderr,
366+
"[sign] could not detect gpg version for an unknown reason (engine name: %s)\n",
367+
gpgme_get_protocol_name(engine_info->protocol)
368+
);
369+
exit(1);
370+
}
371+
372+
fprintf(
373+
stderr,
374+
"[sign] using engine %s (found in %s), version %s, gpgme requires at least version %s\n",
375+
gpgme_get_protocol_name(engine_info->protocol),
376+
engine_info->file_name,
377+
engine_info->version,
378+
engine_info->req_version
379+
);
380+
381+
// check whether the version is problematic
382+
// we just need the first two items, and we assume the format will be something like "2.1*"
383+
unsigned int major;
384+
unsigned int minor;
385+
if (sscanf(engine_info->version, "%u.%u", &major, &minor) == 2) {
386+
if (major == 2) {
387+
if (minor == 0) {
388+
fprintf(stderr, "[sign] warning: loopback pinentry mode not supported with gpg 2.0.x, %s may not work\n", FORCE_SIGN_ENV_VAR);
389+
} else if (minor == 1) {
390+
fprintf(stderr, "[sign] warning: gpg 2.1.x detected, %s can only work with allow-loopback-entry set within the gpg-agent configuration\n", FORCE_SIGN_ENV_VAR);
391+
}
392+
} else {
393+
fprintf(stderr, "[sign] error: unsupported engine version, aborting\n");
394+
exit(1);
395+
}
396+
} else {
397+
fprintf(stderr, "[sign] warning: failed to validate gpg version, expect problems\n");
398+
}
399+
}
400+
352401
if (verbose) {
353402
// this should significantly increase the amount of logging we see in the status callback
354403
fprintf(stderr, "[sign] running in verbose mode, enabling full-status flag on gpgme context\n");

src/appimagetool_sign.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#pragma once
22

3+
static const char* const FORCE_SIGN_ENV_VAR = "APPIMAGETOOL_FORCE_SIGN";
4+
35
bool sign_appimage(char* appimage_filename, char* key_id, bool verbose);

0 commit comments

Comments
 (0)