webpg-npapi 0.6.1
FB::variant webpgPluginAPI::gpgSignUID ( const std::string &  keyid,
long  sign_uid,
const std::string &  with_keyid,
long  local_only = NULL,
long  trust_sign = NULL,
long  trust_level = NULL 
)

Signs the UID index of the specified keyid using the signing key with_keyid.

Parameters:
keyidThe ID of the key with the desired UID to sign.
sign_uidThe 0 based index of the UID.
with_keyidThe ID of the key to create the signature with.
local_onlySpecifies if the signature is local only (non exportable).
trust_signSpecifies if this is a trust signature.
trust_levelThe level of trust to assign.

Definition at line 1681 of file webpgPluginAPI.cpp.

References get_gpgme_ctx(), get_preference(), and gpgSetPreference().

Referenced by webpgPluginAPI().

{
    gpgme_ctx_t ctx = get_gpgme_ctx();
    gpgme_error_t err;
    gpgme_data_t out = NULL;
    gpgme_key_t key = NULL;
    FB::VariantMap result;
    current_uid = i_to_str(sign_uid);

    /* set the default key to the with_keyid 
        gpgSetPreference returns the orginal value (if any) of
        the 'default-key' configuration parameter. We will put
        this into a variable so we can restore the setting when
        our UID Signing operation is complete (or failed)
    */

    /* collect the original value so we can restore when done */
    std::string original_value = get_preference("default-key");
    webpgPluginAPI::gpgSetPreference("default-key", 
        (char *) with_keyid.c_str());

    /* Release the context and create it again to catch the changes */
    gpgme_release (ctx);
    ctx = get_gpgme_ctx();
    err = gpgme_op_keylist_start (ctx, keyid.c_str(), 0);
    if (err != GPG_ERR_NO_ERROR)
        result = get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__);

    err = gpgme_op_keylist_next (ctx, &key);
    if (err != GPG_ERR_NO_ERROR)
        result = get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__);

    err = gpgme_op_keylist_end (ctx);
    if (err != GPG_ERR_NO_ERROR)
        result = get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__);

    err = gpgme_data_new (&out);
    if (err != GPG_ERR_NO_ERROR)
        result = get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__);

    edit_status = "gpgSignUID(keyid='" + keyid + "', sign_uid='" + i_to_str(sign_uid) + 
        "', with_keyid='" + with_keyid + "', local_only='" + i_to_str(local_only) + "', trust_sign='" + 
        i_to_str(trust_sign) + "', trust_level='" + i_to_str(trust_level) + "');\n";
    err = gpgme_op_edit (ctx, key, edit_fnc_sign, out, out);
    if (err != GPG_ERR_NO_ERROR) {
        if (err == GPGME_STATUS_ALREADY_SIGNED) {
            result = get_error_map(__func__, err, "The selected UID has already been signed with this key.", __LINE__, __FILE__);
        } else if (err == GPGME_STATUS_KEYEXPIRED) {
            result =  get_error_map(__func__, err, "This key is expired; You cannot sign using an expired key.", __LINE__, __FILE__);
        } else if (err == GPGME_STATUS_SIGEXPIRED) {
            result =  get_error_map(__func__, err, "This key is expired; You cannot sign using an expired key.", __LINE__, __FILE__);
        } else {
            result = get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__);
        }
    }

    /* if the original value was not empty, reset it to the previous value */
    if (strcmp ((char *) original_value.c_str(), "0")) {
        webpgPluginAPI::gpgSetPreference("default-key", original_value);
    }

    FB::VariantMap response;
    response["error"] = false;
    response["result"] = "success";

    gpgme_data_release (out);
    gpgme_key_unref (key);
    gpgme_release (ctx);

    if (result.size())
        return result;

    return response;
}

Here is the call graph for this function:

 All Classes Functions