|
11 | 11 |
|
12 | 12 | #include "binreloc.h" |
13 | 13 | #include "appimage/appimage_shared.h" |
| 14 | +#include "appimagetool_sign.h" |
14 | 15 |
|
15 | 16 | // used to identify calls to the callback |
16 | 17 | static const char gpgme_hook[] = "appimagetool gpgme hook"; |
@@ -349,6 +350,54 @@ bool sign_appimage(char* appimage_filename, char* key_id, bool verbose) { |
349 | 350 |
|
350 | 351 | gpg_check_call(gpgme_new(&gpgme_ctx)); |
351 | 352 |
|
| 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 | + |
352 | 401 | if (verbose) { |
353 | 402 | // this should significantly increase the amount of logging we see in the status callback |
354 | 403 | fprintf(stderr, "[sign] running in verbose mode, enabling full-status flag on gpgme context\n"); |
|
0 commit comments