* Don't name static methods with a gpgme_ prefix to avoid confusion with
methods provided by the library. These are static and local to our
file so just give them sane non-prefixed names.
* Rework sigsum_test_bit() to not require assignment.
* Don't balk if there is more than one signature available (for now,
only check the first).
* Fix error codes in publicly visible methods to return -1, not 0, if pkg
or db are not provided.
-static alpm_list_t *gpgme_list_sigsum(gpgme_sigsum_t sigsum)
+static alpm_list_t *list_sigsum(gpgme_sigsum_t sigsum)
{
alpm_list_t *summary = NULL;
/* The docs say this can be a bitmask...not sure I believe it, but we'll code
* for it anyway and show all possible flags in the returned string. */
/* The signature is fully valid. */
- summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_VALID, "valid");
+ sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_VALID, "valid");
/* The signature is good. */
- summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_GREEN, "green");
+ sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_GREEN, "green");
/* The signature is bad. */
- summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_RED, "red");
+ sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_RED, "red");
/* One key has been revoked. */
- summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_KEY_REVOKED, "key revoked");
+ sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_KEY_REVOKED, "key revoked");
/* One key has expired. */
- summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_KEY_EXPIRED, "key expired");
+ sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_KEY_EXPIRED, "key expired");
/* The signature has expired. */
- summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_SIG_EXPIRED, "sig expired");
+ sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_SIG_EXPIRED, "sig expired");
/* Can't verify: key missing. */
- summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_KEY_MISSING, "key missing");
+ sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_KEY_MISSING, "key missing");
/* CRL not available. */
- summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_CRL_MISSING, "crl missing");
+ sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_CRL_MISSING, "crl missing");
/* Available CRL is too old. */
- summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_CRL_TOO_OLD, "crl too old");
+ sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_CRL_TOO_OLD, "crl too old");
/* A policy was not met. */
- summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_BAD_POLICY, "bad policy");
+ sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_BAD_POLICY, "bad policy");
/* A system error occured. */
- summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_SYS_ERROR, "sys error");
+ sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_SYS_ERROR, "sys error");
/* Fallback case */
if(!sigsum) {
summary = alpm_list_add(summary, (void *)"(empty)");
@@ -105,10 +104,10 @@ static alpm_list_t *gpgme_list_sigsum(gpgme_sigsum_t sigsum)
return summary;
}
-static int gpgme_init(pmhandle_t *handle)
+static int init_gpgme(pmhandle_t *handle)
{
static int init = 0;
- const char *version;
+ const char *version, *sigdir;
gpgme_error_t err;
gpgme_engine_info_t enginfo;
/**
- * Check the PGP signature for the given file.
+ * Check the PGP signature for the given file path.
+ * If base64_sig is provided, it will be used as the signature data after
+ * decoding. If base64_sig is NULL, expect a signature file next to path
+ * (e.g. "%s.sig"). The return value will be 0 if all checked signatures are
+ * valid, 1 if there was some sort of problem (but not necessarily rejection),
+ * and -1 if an error occurred while checking signatures. If 1 is returned,
+ * pm_errno should be checked to see why the signatures did not pass muster.
* @param handle the context handle
* @param path the full path to a file
- * @param base64_sig PGP signature data in base64 encoding; if NULL, expect a
- * signature file next to 'path'
- * @return a int value : 0 (valid), 1 (invalid), -1 (an error occured)
+ * @param base64_sig optional PGP signature data in base64 encoding
+ * @return a int value : 0 (valid), 1 (invalid), -1 (an error occurred)
*/
int _alpm_gpgme_checksig(pmhandle_t *handle, const char *path,
const char *base64_sig)
@@ -229,7 +233,7 @@ int _alpm_gpgme_checksig(pmhandle_t *handle, const char *path,
}
}
- if(gpgme_init(handle)) {
+ if(init_gpgme(handle)) {
/* pm_errno was set in gpgme_init() */
return -1;
}
@@ -282,14 +286,8 @@ int _alpm_gpgme_checksig(pmhandle_t *handle, const char *path,
CHECK_ERR();
result = gpgme_op_verify_result(ctx);
gpgsig = result->signatures;
- if(!gpgsig || gpgsig->next) {
- int count = 0;
- while(gpgsig) {
- count++;
- gpgsig = gpgsig->next;
- }
- _alpm_log(handle, PM_LOG_ERROR, _("Unexpected number of signatures (%d)
"),
- count);
+ if(!gpgsig) {
+ _alpm_log(handle, PM_LOG_DEBUG, "no signatures returned
");
ret = -1;
goto error;
}
@@ -298,7 +296,7 @@ int _alpm_gpgme_checksig(pmhandle_t *handle, const char *path,
alpm_list_t *summary_list, *summary;