예제 #1
0
static char * geanypg_result(gpgme_signature_t sig)
{
    char format[] =
    "status ....: %s\n"
    "summary ...:%s\n"
    "fingerprint: %s\n"
    "created ...: %s"
    "expires ...: %s"
    "validity ..: %s\n"
    "val.reason : %s\n"
    "pubkey algo: %s\n"
    "digest algo: %s\n"
    "pka address: %s\n"
    "pka trust .: %s\n"
    "other flags:%s%s\n"
    "notations .: %s\n"; // 210 characters
    char * buffer = (char *)calloc(2048, 1); // everything together probably won't be more
                                          // than 1061 characters, but we don't want to
                                          // take risks
    char summary[128];
    const char * pubkey = gpgme_pubkey_algo_name(sig->pubkey_algo);
    const char * hash = gpgme_hash_algo_name(sig->hash_algo);
    char created[64];
    char expires[64];
    if (sig->timestamp)
        strncpy(created, ctime((time_t*)&sig->timestamp), 64);
    else
        strcpy(created, "Unknown\n");

    if (sig->exp_timestamp)
        strncpy(expires, ctime((time_t*)&sig->exp_timestamp), 64);
    else
        strcpy(expires, "Unknown\n");

    memset(summary, 0, 128);
    sprintf(buffer, format,
        gpgme_strerror(sig->status),            // probably won't be more than 128
        geanypg_summary(sig->summary, summary), // max 105 characters
        sig->fpr ? sig->fpr : "[None]",         // max 40 characters
        created,                                // probably about 24 characters
        expires,                                // probably about 24 characters
        geanypg_validity(sig->validity),        // max 11 characters
        gpgme_strerror(sig->status),            // probably won't be more than 128
        pubkey ? pubkey : "Unknown",            // probably won't be more than 32
        hash ? hash : "Unknown",            // probably won't be more than 32
        sig->pka_address ? sig->pka_address : "[None]", // probably won't be more than 128
        sig->pka_trust == 0 ? "n/a" : sig->pka_trust == 1 ? "bad" : sig->pka_trust == 2 ? "okay": "RFU", // max 4 characters
        sig->wrong_key_usage ? " wrong-key-usage" : "", sig->chain_model ? " chain-model" : "",          // max 28 characters
        sig->notations ? "yes" : "no");         // max 3 characters
    return buffer;
}
예제 #2
0
void geanypg_encrypt_cb(GtkMenuItem * menuitem, gpointer user_data)
{
    int sign;
    encrypt_data ed;
    gpgme_error_t err;
    geanypg_init_ed(&ed);
    err = gpgme_new(&ed.ctx);
    if (err && geanypg_show_err_msg(err))
        return;
    gpgme_set_armor(ed.ctx, 1);
    gpgme_set_passphrase_cb(ed.ctx, geanypg_passphrase_cb, NULL);
    if (geanypg_get_keys(&ed) && geanypg_get_secret_keys(&ed))
    {
        gpgme_key_t * recp = NULL;
        if (geanypg_encrypt_selection_dialog(&ed, &recp, &sign))
        {
            int flags = 0;
            int stop = 0;
            gpgme_key_t * key = recp;
            while (*key)
            {
                if ((*key)->owner_trust != GPGME_VALIDITY_ULTIMATE &&
                    (*key)->owner_trust != GPGME_VALIDITY_FULL     &&
                    (*key)->owner_trust != GPGME_VALIDITY_MARGINAL)
                {
                    if (dialogs_show_question(_("The key with user ID \"%s\" has validity \"%s\".\n\n"
                        "WARNING: It is NOT certain that the key belongs to the person named in the user ID.\n\n"
                        "Are you *really* sure you want to use this key anyway?"),
                        (*key)->uids->uid, geanypg_validity((*key)->owner_trust)))
                        flags = GPGME_ENCRYPT_ALWAYS_TRUST;
                    else
                        stop = 1;
                }
                ++key;
            }
            if (*recp && !stop)
                geanypg_encrypt(&ed, recp, sign, flags);
            else if (!stop && dialogs_show_question(_("No recipients were selected,\nuse symmetric cipher?")))
                geanypg_encrypt(&ed, NULL, sign, flags);
        }
        if (recp)
            free(recp);
    }
    geanypg_release_keys(&ed);
    gpgme_release(ed.ctx);
}
예제 #3
0
static char * geanypg_result(gpgme_signature_t sig)
{
    char * format =
    _("status ....: %s\n"
      "summary ...:%s\n"
      "fingerprint: %s\n"
      "created ...: %s"
      "expires ...: %s"
      "validity ..: %s\n"
      "val.reason : %s\n"
      "pubkey algo: %s\n"
      "digest algo: %s\n"
      "pka address: %s\n"
      "pka trust .: %s\n"
      "other flags:%s%s\n"
      "notations .: %s\n");
    char * buffer;
    char summary[128];
    const char * pubkey = gpgme_pubkey_algo_name(sig->pubkey_algo);
    const char * hash = gpgme_hash_algo_name(sig->hash_algo);
    char created[64];
    char expires[64];
    size_t buffer_size;
    if (sig->timestamp)
        strncpy(created, ctime((time_t*)&sig->timestamp), 64);
    else
        strcpy(created, _("Unknown\n"));

    if (sig->exp_timestamp)
        strncpy(expires, ctime((time_t*)&sig->exp_timestamp), 64);
    else
        strcpy(expires, _("Unknown\n"));

    buffer_size = strlen(format) +
        strlen(gpgme_strerror(sig->status)) +
        strlen(geanypg_summary(sig->summary, summary)) +
        strlen(sig->fpr ? sig->fpr : _("[None]")) +
        strlen(created) +
        strlen(expires) +
        strlen(geanypg_validity(sig->validity)) +
        strlen(gpgme_strerror(sig->status)) +
        strlen(pubkey ? pubkey : _("Unknown")) +
        strlen(hash ? hash : _("Unknown")) +
        strlen(sig->pka_address ? sig->pka_address : _("[None]")) +
        strlen(sig->pka_trust == 0 ? _("n/a") : sig->pka_trust == 1 ? _("bad") : sig->pka_trust == 2 ? _("okay"): _("RFU")) +
        strlen(sig->wrong_key_usage ? _(" wrong-key-usage") : "") +
        strlen(sig->chain_model ? _(" chain-model") : "") +
        strlen(sig->notations ? _("yes") : _("no")) + 1; // and a trailing \0

    buffer = (char *)calloc(buffer_size, 1);
    memset(summary, 0, 128);
    sprintf(buffer, format,
        gpgme_strerror(sig->status),
        geanypg_summary(sig->summary, summary),
        sig->fpr ? sig->fpr : _("[None]"),
        created,
        expires,
        geanypg_validity(sig->validity),
        gpgme_strerror(sig->status),
        pubkey ? pubkey : _("Unknown"),
        hash ? hash : _("Unknown"),
        sig->pka_address ? sig->pka_address : _("[None]"),
        sig->pka_trust == 0 ? _("n/a") : sig->pka_trust == 1 ? _("bad") : sig->pka_trust == 2 ? _("okay"): _("RFU"),
        sig->wrong_key_usage ? _(" wrong-key-usage") : "", sig->chain_model ? _(" chain-model") : "",
        sig->notations ? _("yes") : _("no"));
    return buffer;
}