diff --git a/g10/ChangeLog b/g10/ChangeLog index 4b5f2f141..892878030 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,12029 +1,12041 @@ +2011-11-06 Werner Koch + + * card-util.c (generate_card_keys): Add arg CTRL. + + * call-agent.c (agent_readkey): New. + * keygen.c (do_create_from_keygrip): New. + (ask_algo): Add arg R_KEYGRIP and a prompt to enter it. + (generate_subkeypair): Call do_create_from_keygrip if required. + (generate_subkeypair): Add arg CTRL. Change caller. + (ask_algo): Add arg CTRL. + (generate_keypair): Ditto. + 2011-09-23 Werner Koch * gpgv.c (disable_dotlock): Rename to dotlock_disable. (create_dotlock): Rename to dotlock_create. (destroy_dotlock): Rename to dotlock_destroy. (make_dotlock): Rename to dotlock_take. (release_dotlock): Rename to dotlock_release. (lockfiles_remove): Rename to dotlock_remove_lockfiles. 2011-09-20 Werner Koch * free-packet.c (free_public_key): Allow a NULL argument. * keyedit.c (keyedit_passwd): No more need to check that PK is NULL. (menu_addrevoker): Ditto. * passphrase.c (passphrase_get, passphrase_to_dek_ext): Ditto. * skclist.c (release_sk_list): Ditto. * revoke.c (gen_desig_revoke): Ditto. * pubkey-enc.c (get_session_key): Ditto. * pkclist.c (build_pk_list): Ditto. 2011-09-20 Jim Meyering avoid use of freed pointer If we free pk2 at the top of the for-loop, set it to NULL so that we don't free it again just before returning. * revoke.c (gen_desig_revoke): Don't use pk2 after freeing it. 2011-09-20 Werner Koch * sign.c (sign_file, clearsign_file, sign_symencrypt_file): s/gcry_md_start_debug/gcry_md_debug/ in preparation for Libgcrypt 1.6. * mainproc.c (proc_plaintext, proc_tree): Ditto. * decrypt-data.c (decrypt_data): Ditto. * cipher.c (write_header): Ditto. 2011-08-10 Werner Koch * export.c (transfer_format_to_openpgp): Don't parse unneeded CSUM. * import.c (import_secret_one): Use arg OPTIONS instead of global import options var. * sig-check.c (do_check): Remove unused var CTX. * build-packet.c (do_user_id): Return value. 2011-07-29 Werner Koch * tdbio.c (open_db): Do not print read-only warning in quiet mode. 2011-07-18 Werner Koch * parse-packet.c (parse_key): Print the decoded iteration count. Fixes bug#1355. 2011-07-07 Werner Koch * card-util.c (ask_card_keysize): Bump key size limit to 4096. * call-agent.c (scd_genkey_parm_s): New. (agent_scd_genkey): Use new struct. (scd_genkey_cb): Implement chunked mode for KEY-DATA. (scd_genkey_cb_append_savedbytes): New. 2011-06-16 Werner Koch * card-util.c (ask_card_keysize): Bump key size limit to 4096. * call-agent.c (scd_genkey_parm_s): New. (agent_scd_genkey): Use new struct. (scd_genkey_cb): Implement chunked mode for KEY-DATA. (scd_genkey_cb_append_savedbytes): New. 2011-06-13 Werner Koch * pkglue.c (mpi_from_sexp): Use GCRYMPI_FMT_USG to avoid problems with leading zeroed. The latest Libgcrypt does this now correctly. Given that the default of gcry_sexp_nth_mpi would use a signed MPI, which is not implemented, the assertion would fail. 2011-06-01 Marcus Brinkmann * parse-packet.c (parse_pubkeyenc): Change type of N to size_t. (parse_key): Likewise. * seskey.c (encode_session_key): Convert nframe to int for debugging. * build-packet.c (gpg_mpi_write): Change type of N to unsigned int. * import.c (transfer_secret_keys): Likewise. 2011-04-29 Werner Koch * keydb.c (keydb_get_keyblock, keydb_add_resource): Use gpg_error. (keydb_get_keyblock): Return VALUE_NOT_FOUND instead of -1. (keydb_update_keyblock, keydb_insert_keyblock) (keydb_delete_keyblock): Ditto. (keydb_locate_writable): Ditto. (keydb_search_reset): Ditto. (keydb_search2): Return GPG_ERR_NOT_FOUND instead of -1. Change all callers. (keydb_search_first, keydb_search_next, keydb_search_kid) (keydb_search_fpr): Ditto. 2011-04-29 Marcus Brinkmann * import.c (import_secret_one): Leave all checks to import_one. Cancel secret key import if public key was skipped due to merge-only request. Fix import status for non-new secret key import by checking stat counter. 2011-04-29 Marcus Brinkmann * delkey.c (do_delete_key): Access public keyblock even for secret key operations. But deleting secret key is not supported yet, so give an error. Limit secret-key-exists error case to public keys. 2011-04-28 Werner Koch * ecdh.c (pk_ecdh_encrypt_with_shared_point): Remove memory leak of SECRET_X in the error case. Replace an assert by an error return. 2011-04-26 Werner Koch * export.c (transfer_format_to_openpgp): Do not apply encode_s2k_iterations to S2K_COUNT. 2011-04-25 Werner Koch * delkey.c (do_delete_key): Mark classify_user_id for use with OpenPGP. * trustdb.c (register_trusted_key): Ditto. * revoke.c (gen_revoke): Ditto. * keyserver.c (keyserver_export, keyidlist, keyserver_export): Ditto. * getkey.c (key_byname): Ditto. * export.c (do_export_stream): Ditto. 2011-04-20 Marcus Brinkmann * keylist.c (list_keyblock_colon): Use get_ownertrust_info, not get_ownertrust (which lead to binary zeroes in the output!). 2011-03-23 Werner Koch * parse-packet.c (read_rest): Drop unsed PARTIAL arg. Rewrite to detect premature EOF. Suggested by Timo Schulz. 2011-03-10 Werner Koch * passphrase.c (hash_passphrase): Remove. (passphrase_to_dek_ext): Use gcry_kdf_derive. 2011-03-03 Werner Koch * keylist.c (print_card_key_info): Re-implement using the agent. * card-util.c (card_status) [GNUPG_MAJOR_VERSION!=1]: Call print_card_key_info. * keyid.c (hash_public_key): Remove shadowing NBITS. * misc.c (pubkey_nbits): Replace GCRY_PK_ by PUBKEY_ALGO_. (get_signature_count): Remove warning. * armor.c (armor_filter): Don't take a copy of radbuf while writing the checksum. This works around a faulty gcc 4.4 warning. 2011-03-02 Werner Koch * call-agent.c (agent_scd_pksign, agent_scd_pkdecrypt) (hash_algo_option): Remove these unused functions. 2011-02-10 Werner Koch * seskey.c (encode_md_value): Change last fix to avoid a regression for DSA with SHA-2 hashes. 2011-02-09 Werner Koch * keyserver.c: Replace all printf by es_printf. 2011-02-08 Werner Koch * call-dirmngr.c (gpg_dirmngr_ks_fetch): New. * keyserver.c (keyserver_fetch): Rewrite to use dirmngr. 2011-02-07 Werner Koch * seskey.c (encode_md_value): Truncate to MDLEN and not to QBYTES which makes a difference with 521 bit ECC keys. For clarity rename QBYTES to QBITS and adjust accordingly. 2011-02-04 Werner Koch * sig-check.c (do_check_messages): Remove the long deprecated SIGEXPIRED status line. 2011-02-03 Werner Koch * export.c (transfer_format_to_openpgp) [!HAVE_GCRY_PK_GET_CURVE]: Fix syntax error. * decrypt-data.c: Include status.h. (decrypt_data): Emit a DECRYPTION_INFO status line. * misc.c (has_invalid_email_chars): Relax mailbox name checking. Fixes bug#1315. * sign.c (do_sign): Use openpgp_pk_algo_name. * keygen.c (ask_algo): Show ECC algos only in expert mode. Add non-combined menu entries for ECDSA and ECDH. (ask_key_flags): Use openpgp_pk_algo_name. 2011-02-03 Werner Koch Finished ECC integration. Wrote change description for 2011-01-13. 2011-02-02 Werner Koch * encrypt.c (write_pubkey_enc_from_list): Don't compute the fingerprint. * pkglue.c (pk_encrypt): Replace PK_FP by PK and compute the fingerprint only when needed. * pkglue.h: Include packet.h. * import.c (transfer_secret_keys): Make sure keyids are available. * keyid.c (hash_public_key): Adjust for the ECC case. 2011-02-01 Werner Koch * gpg.c (main): Call setup_libgcrypt_logging. * import.c (transfer_secret_keys): Implement ECC case. (one_mpi_from_pkey): New. * export.c (transfer_format_to_openpgp): Ditto. * keygen.c (gpg_curve_to_oid): New. (ecckey_from_sexp): Factor curve name mapping out to new function. 2011-01-31 Werner Koch * ecdh.c (pk_ecdh_encrypt_with_shared_point): Return an opaque MPI. * build-packet.c (mpi_write): Rename to gpg_mpi_write and make global. 2011-01-30 Werner Koch * keyid.c (keygrip_from_pk): Adjust ECC cases. * pkglue.c (pk_verify): Ditto. * parse-packet.c (parse_key): Simply ECC case. (parse_pubkeyenc): Ditto. * misc.c (pubkey_get_npkey): Special case ECC. (pubkey_get_nskey): Ditto. (mpi_print): Support printing of opaque values. (openpgp_oid_to_str): New. (pubkey_nbits): For ECC pass curve parameter. * ecdh.c (pk_ecdh_default_params): Change to return an opaque MPI. * build-packet.c (do_key): Automatically handle real and opaque key parameters. (write_fake_data): Return an error code. (mpi_write): Support writing opaque MPIs. (do_pubkey_enc): Simplify ECC handling. 2011-01-28 Werner Koch * keygen.c (gen_ecc): Rewrite. Select a named curve and create a keyspec based on that. (pk_ecc_build_key_params): Remove. (get_parameter_algo): Map algo number. (ecckey_from_sexp): New. * misc.c (map_pk_gcry_to_openpgp): New. 2011-01-25 Werner Koch * ecdh.c (pk_ecdh_default_params_to_mpi): Remove. (pk_ecdh_default_params): Rewrite. Factor KEK table out to .. (kek_params_table): .. here. (pk_ecdh_generate_ephemeral_key): New. (pk_ecdh_encrypt): Remove. (pk_ecdh_encrypt_with_shared_point): Make public. * pubkey-enc.c (get_it): Fix assertion. Use GPG_ERR_WRONG_SECKEY instead of log_fatal. Add safety checks for NFRAME. * keygen.c (pk_ecc_keypair_gen): Make static. (ask_keysize): Use proper rounding for ECC. (pk_ecc_build_key_params): Remove NBITSSTR. 2011-01-20 Werner Koch * keyserver.c: Rewrite most stuff for use with dirmngr. Get rid of all spawn code. More work pending. * export.c (export_pubkeys_buffer): New. * import.c (import_keys_es_stream): New. * call-dirmngr.c, call-dirmngr.h: New. * gpg.h (server_control_s): Add DIRMNGR_LOCAL. * gpg.c: Include call-dirmngr.h. (gpg_deinit_default_ctrl): Call gpg_dirmngr_deinit_session_data. 2011-01-13 Andrey Jivsov (wk) Integrated ECC support. Below are the changes finally merged into the git master after some cleanup by wk until 2011-02-03. * ecdh.c: New. * sign.c (mpi_from_sexp): Remove. (match_dsa_hash): Uses SHA-512 for ECDSA with 521 bits. (hash_for): Support ECDSA. (make_keysig_packet): Ditto. * seskey.c (encode_session_key): Add arg OPENPGP_PK_ALGO. Support ECDH. (encode_md_value): Map pkalgo. Extend size checks to ECDSA. * pubkey-enc.c (get_it): Support ECDH. * pkglue.c (mpi_from_sexp): Make global. (pk_verify, pk_encrypt, pk_check_secret_key): Support ECC. * parse-packet.c (read_size_body): New. (parse_pubkeyenc): Support ECC. (parse_key): Ditto. * misc.c (map_pk_openpgp_to_gcry, map_pk_gcry_to_openpgp): New. (openpgp_pk_test_algo, openpgp_pk_test_algo2): Map algo numbers. (openpgp_pk_algo_usage): Support ECDH and ECDSA. (openpgp_pk_algo_name): Simplify. (ecdsa_qbits_from_Q): New. * mainproc.c (proc_pubkey_enc): Support ECC. * keyid.c (pubkey_letter): Add 'E' and 'e'. (keygrip_from_pk): Supporf ECC. * keygen.c: Include pkglue.h. (ask_algo): Add option 9 for ECDSA and ECDH. (ask_keysize): Support ECDSA and ECDH. (do_create): Ditto. (gen_ecc): New. (pk_ecc_build_key_params): New. * getkey.c (cache_public_key): Support ECC. * encrypt.c (write_pubkey_enc_from_list): Pass PK to PK_ENCRYPT and the pkalgo to encode_session_key. * build-packet.c (do_key, do_pubkey_enc): Support ECC. (write_size_body_mpi): New. 2011-01-06 Werner Koch * gpg.c (main): Use keyserver_spec_t. * options.h (struct opt): Factor definition of struct keyserver out to ../common/keyserver.h. (keyserver_spec_t): New. 2011-01-21 Werner Koch * seskey.c (encode_md_value): Truncate the DSA hash again. * misc.c (openpgp_pk_algo_name): Always use the gcrypt function. 2010-12-09 Werner Koch * tdbio.c (tdbio_set_dbname) [W32CE]: Take care of missing errno. (strerror) [W32CE]: Dummy replacement. (open_db) [W32CE]: Use CreateFile. 2010-12-02 Werner Koch * misc.c (openpgp_cipher_algo_name): Use gnupg_cipher_algo_name. 2010-11-23 Werner Koch * Makefile.am (gpg2_LDFLAGS, gpgv2_LDFLAGS): Add extra_bin_ldflags. * plaintext.c (handle_plaintext): Change to use estream. s/rc/err/. Replace some xmalloc by xtrymalloc. Use more gpg_strerror. * options.h (struct): Change type of OUTFP to estream_t. * decrypt.c (decrypt_message_fd): Adjust accordingly. 2010-11-17 Werner Koch * keyedit.c (find_pk_from_sknode): Remove. * misc.c (get_signature_count): Call agent. * keygen.c (gen_card_key): Rework. Remove arg PARA. (generate_keypair): Change arg BACKUP_ENCRYPTION_DIR to the flag CARD_BACKUP_KEY. (pBACKUPENCDIR): Change to pCARDBACKUPKEY. (struct output_control_s): Remove struct SEC. Remove all usages of it. (gen_card_key_with_backup): Remove arg BACKUP_DIR. * call-agent.c (agent_scd_genkey): Remove extra memset. 2010-11-16 Werner Koch * keygen.c (generate_card_subkeypair): Remove arg SEC_KEYBLOCK and change to return an error code. Rework for removed secring code. * card-util.c (card_generate_subkey): Remove arg SEC_KEYBLOCK. Return an error code instead of a success flag. Change caller. 2010-10-29 David Shaw * pkclist.c (select_algo_from_prefs): Make sure the scores can't overflow when picking an algorithm (not a security issue since we can't pick something not present in all preference lists, but we might pick something that isn't scored first choice). * pkclist.c (select_algo_from_prefs): Slightly improve the handling of MD5 in preference lists. Instead of replacing MD5 with SHA-1, just remove MD5 from the list altogether, and let the next-highest ranked algorithm be chosen. 2010-10-27 Werner Koch * keygen.c (ask_expire_interval): Do not print the y2038 if we have an unsigned time_t. * keyid.c (IS_INVALID_TIME_T): New. (mk_datestr): Use it to detect the y2038 problem. 2010-10-26 Werner Koch * keyedit.c (change_passphrase): Handle the passwd_nonce. * call-agent.c (cache_nonce_parm_s): New. (cache_nonce_status_cb): Use that new struct. (agent_genkey, agent_import_key, agent_export_key, agent_passwd): Adjust for that change. 2010-10-25 Werner Koch * passphrase.c (gpg_format_keydesc): Fix printing of main keyid. * keyedit.c (JNLIB_NEED_LOG_LOGV): Define. * call-agent.c (agent_passwd): New. 2010-10-21 Werner Koch * keyedit.c (keyedit_passwd): Simplify. (change_passphrase): Return an error code and not the change flag. Remove editing of the keyring. * seckey-cert.c: Remove. * Makefile.am (gpg2_SOURCES): Remove seckey-cert.c * revoke.c (gen_revoke): Check that the secret key is available. 2010-10-20 Werner Koch * verify.c (verify_signatures): Use gpg_strerror on open failure for consistency of error messages. * packet.h (PKT_public_key): s/mdc_feature/flags.mdc/. Change all users. (PKT_public_key): Split is_disabled into flags.disabled_valid and flags.disabled. Change all users. (pk_is_disabled): Adjust for change. (PKT_public_key): s/is_primary/flags.primary/. Change all users. (PKT_public_key): s/is_revoked/flags.revoked/. Change all users. (PKT_public_key): s/maybe_revoked/flags.maybe_revoked/. Change all users. (PKT_public_key): s/is_valid/flags.valid/. Change all users. (PKT_public_key): s/dont_cache/flags.dont_cache/. Change all users. (PKT_public_key): s/backsig/flags.backsig/. Change all users. * sign.c (openpgp_card_v1_p): New. (hash_for): Re-implement test for v1 cards. * packet.h (PKT_public_key): Add field serialno and flags.serialno_valid. * free-packet.c (release_public_key_parts): Free serialno. * parse-packet.c (parse_key): Cast -1 to size_t. * trustdb.c (validate_keys): Cast -1 to size_t. Suggested by Steven M. Schweda. 2010-10-18 Werner Koch * call-agent.c (agent_scd_pksign): Replace sprintf by bin2hex. (agent_scd_pkdecrypt, agent_pksign): Ditto. * sign.c (do_sign): Remove warning and commented old code. 2010-10-14 Werner Koch * call-agent.c (agent_genkey): Add arg NO_PROTECTION. * keygen.c (do_create, gen_elg, gen_dsa, gen_rsa, common_gen): Add arg KEYGEN_FLAGS. (read_parameter_file): Add options no-protection and transient-key. (KEYGEN_FLAG_NO_PROTECTION, KEYGEN_FLAG_TRANSIENT_KEY): New. (gen_rsa, gen_dsa, gen_elg): Use transient-key. 2010-10-13 Werner Koch * call-agent.c (start_agent): Send option agent-awareness. (status_sc_op_failure): Take care of GPG_ERR_FULLY_CANCELED. * passphrase.c (passphrase_get): Ditto. * import.c (transfer_secret_keys): Ditto. * card-util.c (write_sc_op_status): Ditto. * getkey.c (enum_secret_keys): Rewrite. * pubkey-enc.c (get_session_key): Skip keys without an encryption capability. Handle GPG_ERR_FULLY_CANCELED. * gpg.c: Add option --try-secret-key. * options.h (struct opt): Add field secret_keys_to_try. * passphrase.c (next_to_last_passphrase): Remove. 2010-10-12 Werner Koch * keygen.c (generate_subkeypair): Check availibility of secret parts. * keylist.c (print_card_serialno): Change to take a hexified serialno. (list_keyblock_print): Print serialno and stub key indicators. (list_keyblock_colon): Ditto. * getkey.c (have_any_secret_key): Remove. Replace all calls by agent_probe_any_secret_key. * gpgv.c (agent_probe_any_secret_key): New. (agent_get_keyinfo): New. 2010-10-08 Werner Koch * gpg.c: Add option --with-keygrip. * options.h (struct opt): Add WITH_KEYGRIP. * keylist.c (list_keyblock_print, list_keyblock_colon): Implement new option. 2010-10-06 Werner Koch * import.c (transfer_secret_keys): Ignore missing key parameters. Provide dummy IV. Ignore stub keys. 2010-10-01 Werner Koch * export.c (do_export_stream): Rewrite to take the secret keys from the agent. (canon_pubkey_algo, transfer_format_to_openpgp): New. 2010-09-29 Werner Koch * keygen.c (key_from_sexp): Fix memory leak in the error case. * call-agent.c (agent_export_key): New. 2010-09-29 Werner Koch * build-packet.c (build_packet): Fix up the pkttype. * keyid.c (keystr_with_sub): Make SUB_KID optional. (keystr_from_pk_with_sub): Ditto. * call-agent.c (agent_scd_pksign): Add missing space. * mainproc.c (struct mainproc_context): Add field CTRL. (proc_packets): Add arg CTRL. Change all callers. (proc_signature_packets, proc_signature_packets_by_fd) (proc_encryption_packets): Add arg CTRL. Change all callers. * compress.c (handle_compressed): Ditto. * getkey.c (get_pubkey_byname): Ditto. * keyserver.c (keyserver_spawn, keyserver_work): Ditto. (show_prompt, keyserver_export, keyserver_import) (keyserver_import_fprint, keyserver_import_keyid) (keyserver_refresh, keyserver_search, keyserver_fetch) (keyserver_import_name, keyserver_search_prompt) (keyserver_import_pka, keyserver_import_cert): Ditto. callers. * verify.c (verify_signatures, verify_files): Ditto. * sign.c (sign_file): Ditto. * encrypt.c (encrypt_crypt, encrypt_crypt_files): Ditto. * pkclist.c (find_and_check_key, build_pk_list): Ditto. * keylist.c (locate_one, public_key_list, secret_key_list): Ditto. * card-util.c (fetch_url, card_edit): Ditto. * import.c (check_prefs, import_one, revocation_present): Ditto. * keyedit.c (menu_addrevoker, keyedit_menu): Ditto. * decrypt-data.c (decrypt_data): Ditto. * decrypt.c (decrypt_message, decrypt_messages) (decrypt_message_fd): Ditto. * gpgv.c (main): Add CTRL structure. 2010-09-28 Werner Koch * options.h (struct opt): Remove SIMPLE_SK_CHECKSUM. * export.c (parse_export_options): Remove option export-resert-subkey-passwd. (do_export_stream, do_export, export_pubkeys) (export_pubkeys_stream, export_seckeys, export_secsubkeys): Add arg CTRL. Change all callers. * call-agent.c (hash_algo_option): New. (agent_scd_pksign): Use it. 2010-09-17 Werner Koch * call-agent.c (agent_probe_any_secret_key): New. 2010-09-28 David Shaw * options.skel: Make the example for force-v3-sigs match reality (it has defaulted to off since 2007-10-25). 2010-09-06 Werner Koch * card-util.c (card_status): Remove stub creation for GnuPG >= 2. (card_store_subkey): Temporary disable this code. * keyedit.c (show_key_with_all_names): Merge secret and public key parts. (show_basic_key_info): Ditto. * delkey.c (do_delete_key): Ditto. * export.c (subkey_in_list_p, exact_subkey_match_p): Ditto. (new_subkey_list_item): Ditto. * keyid.c (keystr_from_sk, keystr_from_sk_with_sub) (keyid_from_sk, nbits_from_sk, datestr_from_sk) (expirestr_from_sk, colon_datestr_from_sk, fingerprint_from_sk) (serialno_and_fpr_from_sk, do_fingerprint_md_sk): Remove. * import.c (print_import_ok): Remove arg SK. (import_secret_one): Adjust for seckey_info format. (transfer_secret_keys): Ditto. Use gpg_format_keydesc. (sec_to_pub_keyblock): Simplify. (pub_to_sec_keyblock): Remove. (auto_create_card_key_stub): Remove - not anymore needed. (update_sec_keyblock_with_cardinfo): Remove. (import_secret_one): Use arg option instead of the global option. * free-packet.c (copy_public_key): Adjust for seckey_info format. (copy_public_parts_to_secret_key, copy_secret_key) (cmp_secret_keys, cmp_public_secret_key): Remove. * passphrase.c (gpg_format_keydesc): Add arg MODE and change all callers. * keyring.c (keyring_search): Remove special case for secret keys. * mainproc.c (struct mainproc_context): Remove unused field LAST_SECKEY. * parse-packet.c (parse_key): Rewrite to cope with new seckey_info format. * build-packet.c (do_public_key, do_secret_key): Merge code into ... (do_key): .. new. Cope with seckey_info format. 2010-09-03 Werner Koch * packet.h (struct seckey_info): New. (PKT_public_key): Increase size of PKEY to allow storing of secret keys. Add field SECKEY_INFO. (PKT_secret_key): Remove. * free-packet.c (release_public_key_parts): Take care of change. (release_secret_key_parts, free_secret_key): Remove. 2010-09-02 Werner Koch * import.c (transfer_secret_keys, import_secret_one): Enable stats. (import_secret_one): Enable secret key merging. 2010-09-01 Werner Koch * sign.c (do_sign, write_signature_packets, complete_sig): Add arg CACHE_NONCE. (make_keysig_packet): Ditto. * keygen.c (make_backsig, write_direct_sig, write_selfsigs) (write_keybinding): Add arg CACHE_NONCE. (do_generate_keypair): Use cache_nonce to avoid a pinentry for the self-signatures. * passphrase.c (gpg_format_keydesc): Remove now superfluous algo_name fallback. * keygen.c (gen_elg, gen_dsa, gen_rsa, do_create, common_gen): Add arg CACHE_NONCE_ADDR. (generate_subkeypair): Pass NULL for CACHE_NONCE_ADDR. (do_generate_keypair): Add cache nonce handling. * import.c (transfer_secret_keys): Support a cache nonce. * call-agent.c (cache_nonce_status_cb): New. (agent_genkey, agent_import_key): Add arg CACHE_NONCE_ADDR. (agent_pksign): Ditto. 2010-08-30 Werner Koch * keyid.c (KEYID_STR_SIZE): New (keystr): Use snprintf and new macro. (keystr_with_sub): New. (keystr_from_sk_with_sub): New. (keystr_from_pk_with_sub): New. 2010-08-27 Werner Koch * gpg.c (main): Change scope of CTRL to the entire function. * import.c (import_secret_one, import, import_keys_internal) (import_keys, import_keys_stream): Add arg CTRL. * call-agent.c (agent_keywrap_key): New. (agent_import_key, inq_import_key_parms): New. 2010-08-26 Werner Koch * misc.c (openpgp_pk_algo_name): New. (openpgp_md_algo_name): New. 2010-08-24 Werner Koch * options.h (IMPORT_SK2PK): Remove. * import.c (parse_import_options): Turn convert-sk-to-pk into a dummy option. (sec_to_pub_keyblock): Use modern functions. 2010-08-16 Werner Koch * gpg.c (list_config, gpgconf_list): Use es_printf. (print_hex, print_hashline, print_algo_numbers) (print_algo_names): Use es_printf. 2010-07-20 Werner Koch * mainproc.c (print_pkenc_list): Write a STATUS_ERROR. Fixes bug#1255. 2010-06-17 Werner Koch * gpg.c (main): Use CAST5 as default s2k algo. The macro USE_CAST5 was only used with GnuPG 1.x. 2010-06-07 Werner Koch * cpr.c: Use estream for status output. 2010-05-12 Werner Koch * armor.c (radix64_read): Extended 2006-04-28 fix to fix bug#1179. * plaintext.c (handle_plaintext): Check return code of fflush. Fixes bug#1207. 2010-05-07 Werner Koch * import.c (fix_bad_direct_key_sigs): New. (import_one): Call it. (chk_self_sigs): Re-indent, slighly re-arrange code, use test macros for the sig class. Check direct key signatures. Fixes bug#1223. 2010-04-27 Werner Koch * passphrase.c (gpg_format_keydesc): New. * pubkey-enc.c (get_it): Use it. * sign.c (do_sign): Use it. 2010-04-26 Werner Koch * keygen.c (keygen_set_std_prefs): Explicitly include Z0 in the default preferences if no compression algorithms are available. Remove a possible trailing space in the dummy_string. 2010-04-23 Werner Koch * pubkey-enc.c (get_it): Use the agent for decryption. * call-agent.c (agent_pkdecrypt, inq_ciphertext_cb): New. 2010-04-22 Werner Koch * photoid.c (show_photos): Remove arg SK. * pubkey-enc.c (get_session_key, get_it): Change to use the public key object. (get_it): Remove card related stuff. Now automagically handled by the agent. * skclist.c (build_sk_list): Remove UNLOCK arg. * keylist.c (print_fingerprint): Remove arg SK. * mainproc.c (list_node): Disable listing of secret key packets. * keyring.c (struct keyring_name, struct keyring_handle): Remove field SECRET. (keyring_register_filename, keyring_new, orename_tmp_file) (do_copy): Remove arg SECRET. * keydb.c (struct resource_item): Remove field SECRET. (keydb_add_resource): Remove arg SECRET. (keydb_new): Remove code fro secret keyrings. * gpg.c (main): Ignore --secret-keyring. Remove all secret keyring related code. 2010-04-21 Werner Koch * pkclist.c (default_recipient): Change to use public keys. * keydb.c (keydb_new): Remove arg SECRET. Change all callers. * getkey.c (get_seckey): Change to take a public key. (have_secret_key): Rename to have_any_secret_key and make use of the agent. (key_byname): Rmemove unused arg SK. (get_seckey_byname2): Remove and move code to (get_seckey_byname): .. here. Remove INLOCK arg. (get_seckey_bynames): Remove. (get_seckey_next): Remove. (get_seckey_end): Remove. Use get_pubkey_end instead. (get_seckey_byfprint, get_seckeyblock_byfprint): Change to use public keys. (seckey_available): Rename to .. (have_secret_key_with_kid): .. this and change to employ the agent. Change all callers. (sk_from_block): Remove. * call-agent.c (agent_probe_secret_key): New. (agent_havekey): Remove. * gpgv.c (agent_probe_secret_key): New. * keyedit.c (keyedit_menu) (sign_uids, menu_adduid, menu_deluid, menu_delkey) (menu_addrevoker, menu_expire, menu_backsign) (menu_set_primary_uid, menu_set_preferences) (menu_set_keyserver_url, menu_set_notation, menu_revsig) (menu_revuid, menu_revkey, menu_revsubkey): Remove all code to manage the secret keyring. 2010-04-20 Werner Koch * keylist.c (list_keyblock_colon): Print the keygrip. * sign.c (do_sign): Call the agent to create the signature. (mpi_from_sexp): New. * keyid.c (keygrip_from_pk, hexkeygrip_from_pk): New. * call-agent.c (agent_pksign): New. * pkglue.c (pk_sign): Remove. * keygen.c (generate_keypair): Do not ask for a passphrase. 2010-04-15 Werner Koch * keygen.c (gen_dsa, gen_elg, gen_rsa): Remove args SEC_ROOT, DEK, S2K and RET_SK. Change to use the gpg-agent based key generation. Factor common code out to ... (common_gen): New. (do_create): Remove args SEC_ROOT, DEK, S2K and RET_SK. (do_generate_keypair, write_selfsigs, write_direct_sig) (write_keybinding, make_backsig): Adjust for above changes. (generate_subkeypair): Remove arg SEC_KEYBLOCK. (genhelp_protect, genhelp_factors): Remove. (get_parameter_dek, get_parameter_s2k): Remove. * call-agent.c (start_agent): Add dummy arg CTRL. (agent_havekey, keyinfo_status_cb, agent_get_keyinfo) (agent_genkey): New. * seckey-cert.c (check_secret_key): Remove (is_secret_key_protected): Take a public key as arg. (protect_secret_key): Remove. * seskey.c (encode_md_value): Remove SK arg. 2010-04-14 Werner Koch * cpr.c (myread) [W32CE]: Do not use raise. * misc.c (check_compress_algo): Rewrite to handle the new HAVE_ZIP. * compress.c (push_compress_filter2): Ditto. (init_compress, do_compress, init_uncompress, do_uncompress) (compress_filter) [!HAVE_ZIP]: Do not build. * main.h (DEFAULT_COMPRESS_ALGO): Depend on HAVE_ZIP. * keygen.c (keygen_set_std_prefs): Use check_compress_algo also for ZIP and ZLIB. * Makefile.am (install-exec-hook) [W32CE]: New. (bin_PROGRAMS) [W32CE]: Do not build gpgv2. (gpg2_LDADD): Add extra_syslibs. 2010-04-06 Werner Koch * openfile.c (mkdir): Remove. (try_make_homedir): Use gnupg_mkdir. 2010-04-01 Werner Koch Use gpg_err_set_errno to set ERRNO. 2010-03-26 Werner Koch * signal.c (pause_on_sigusr): Remove. It was used in ancient gpg version with shared memory IPC. Last caller removed on 2006-04-18. 2010-03-24 Werner Koch * openfile.c (CMP_FILENAME): Depend on HAVE_DOSISH_SYSTEM instead of HAVE_DRIVE_LETTERS. 2010-03-15 Werner Koch * card-util.c: Replace stdio by estream. * keylist.c: Ditto. 2010-03-12 Werner Koch * plaintext.c (setup_plaintext_name): Do not encode pipe like filenames. This helps with bug#1201. * seckey-cert.c (do_check): Return GPG_ERR_CANCELED. * keyedit.c (change_passphrase): Add arg R_ERR. (keyedit_passwd): Return the correct error or emit a success status message. 2010-03-11 Werner Koch * misc.c (mpi_print): Change to take a estream_t arg. * parse-packet.c (listfp): Change to an estream_t. Change all users to use estream functions. * kbnode.c (dump_kbnode): Change to use log functions. * pkclist.c (do_show_revocation_reason): Ditto * armor.c (parse_header_line): Replace print_string by es_print_sanitized. (fake_packet): Ditto. * keyedit.c (print_and_check_one_sig_colon): Ditto. (show_key_with_all_names_colon): Ditto. (ask_revoke_sig): Ditto. * keylist.c (list_keyblock_colon): Ditto. * mainproc.c (print_userid, list_node): Ditto. * trustdb.c (dump_key_array): Ditto. * gpg.c (list_config): ditto. * gpg.c: Include "asshelp.h". (main): Remove assuan_set_assuan_log_prefix. Add assuan_set_log_cb. * server.c (gpg_server): Remove assuan_set_log_stream. 2010-03-10 Werner Koch * Makefile.am (needed_libs): Remove libjnlib.a. * main.h: Remove "estream.h". 2010-03-08 Werner Koch * main.h: Include "estream.h" * openfile.c (open_outfile): Replace dup/iobuf_fdopen by iobuf_fdopen_nc. * mainproc.c (proc_signature_packets_by_fd): Return error on memory failure. * plaintext.c (hash_datafile_by_fd): Ditto. * verify.c (gpg_verify): Use iobuf_fdopen_nc. Change OUT_FP to an estream_t. * server.c (cmd_verify): Do not dup the fds. Use macros for iobuf_ioctl commands. 2010-02-17 Werner Koch * keygen.c (ask_user_id): Avoid infinite loop in case of invalid data. Fixes bug#1186. 2010-02-02 Werner Koch * keyedit.c (keyedit_menu): Change prompt to "gpg". * card-util.c (card_edit): Change prompt to "gpg/card". 2010-01-11 Werner Koch * sign.c (only_old_style, write_onepass_sig_packets, hash_for) (write_signature_packets, print_status_sig_created) (clearsign_file, make_keysig_packet, mk_notation_policy_etc) (complete_sig, do_sign, update_keysig_packet): Replace all secret key access by the matching public key. * keylist.c (print_seckey_info): Ditto. * revoke.c (gen_desig_revoke): Ditto. * skclist.c (release_sk_list): Ditto. * keyedit.c (sign_uids): Ditto. * misc.c (get_signature_count): Ditto. * main.h (struct expand_args): s/sk/pksk/. Change all users. * keyedit.c (keyedit_passwd): Finish implementation. 2010-01-10 Werner Koch * skclist.c (GCRYCTL_FAKED_RANDOM_P): Remove because we require libgcrypt 1.4. (is_insecure, key_present_in_sk_list): Work with public keys. (build_sk_list): Change to work on public keys. * keydb.h (struct sk_list): Replace field SK by a PK field. * keylist.c (list_keyblock_print): Always look for the public key and ignore all secret key packets. (list_keyblock_colon): Ditto. (print_capabilities): Remove arg SK and all secret key stuff. Adjust all callers. (dump_attribs): Ditto. * getkey.c (getkey_bynames, getkey_next, get_pubkey_end): New. (getkey_byname): New. (getkey_ctx_s): Add WANT_SECRET. (key_byname): Set it. (merge_keys_and_selfsig): Remove all the secret key merging. (lookup): Simplify by removing secret key code. * keylist.c (list_all): Scan public keys and use have_secret_key to filter secret keys. (list_one): Use the new get_key functions. * gpg.h (kbnode_t): Add as alias for KBNODE. * keydb.h (getkey_ctx_t): Add as alias for GETKEY_CTX. 2010-01-09 Werner Koch * getkey.c, keylist.c: Re-indent. 2010-01-08 Werner Koch * cpr.c (write_status_error): Rename to write_status_errcode. Change all callers. (write_status_error): New. * gpg.c: Add option --passwd. (aPasswd): New. (main): Implement. * keyedit.c (keyedit_passwd): New. * gpg.c (oPasswd, oPasswdFD, oPasswdFile, oPasswdRepeat): Change to oPassphrase, oPassphraseFD, oPassphraseFile, oPassphraseRepeat. * options.h (struct): s/passwd_repeat/passphrase_repeat/. * gpg.c (main): Ditto. * passphrase.c (passphrase_to_dek_ext): Ditto. 2009-12-21 Werner Koch * call-agent.c (agent_get_s2k_count): New. * gpg.c (main): Set s2k_count to 0. * (encode_s2k_iterations): Move ... * passphrase.c (encode_s2k_iterations): ... here. Call agent_get_s2k_count if called with a 0 arg. (passphrase_to_dek_ext): Set S2K_COUNT via encode_s2k_iterations. 2009-12-17 Werner Koch * sig-check.c (do_check_messages): Evaluate the HAS_EXPIRED flag. Fixes bug#1059. * gpg.c: Add new option --faked-system-time. 2009-12-15 Werner Koch * keydb.c (keydb_add_resource): s/readonly/read_only/g. * keyring.c (keyring_register_filename): Ditto. * tdbio.c (tdbio_set_dbname): Do not call log_fatal after creating the directory. Fixes bug#1169. Reported by Daniel Leidert. 2009-12-08 Werner Koch * keyring.h: Include userids.h. * gpg.h (KEYDB_SEARCH_DESC): Remove. * packet.h: Include userids.h. (PKT_user_id): Declare using gpg_pkt_user_id_s. * keydb.h (KeydbSearchMode, struct keydb_search_desc): Remove. We now use those in ../kbx. * getkey.c (classify_user_id): Remove. It is now in common/. (key_byname): Adjust for changed classify_user_id. * delkey.c (do_delete_key): Ditto. * trustdb.c (register_trusted_key): Ditto. * revoke.c (gen_desig_revoke, gen_revoke): Ditto. * keyserver.c (parse_keyrec, keyserver_export, keyserver_import) (keyidlist): Ditto. * export.c (do_export_stream): Ditto. * pkclist.c (find_and_check_key): Replace GPG_ERR_INV_NAME by GPG_ERR_INV_USER_ID. 2009-12-04 Werner Koch * keygen.c (DEFAULT_STD_ALGO, DEFAULT_STD_KEYSIZE): New. (ask_keysize): Use new macro. (gen_rsa): Set default size if NBITS is 0. (get_parameter_algo): Add algo name "default". Add arg R_DEFAULT. (proc_parameter_file): Process default flag. 2009-12-03 Werner Koch * gpg.c (set_debug): Allow for numerical debug leveles. Print active debug flags. 2009-11-27 Werner Koch * keyedit.c (cmds, keyedit_menu): New command "checkbkupkey". 2009-11-25 Marcus Brinkmann * server.c (gpg_server): Use assuan_fd_t and assuan_fdopen on fds. 2009-11-23 Werner Koch * gpg.c (gpgconf_list): Add key "default_pubkey_algo". 2009-11-18 Werner Koch * gpg.c: Add option --skip-hidden-recipients and no- variant. * options.h (struct opt): Add field SKIP_HIDDEN_RECIPIENTS. * pubkey-enc.c (get_session_key): Implement that option. 2009-11-04 Werner Koch * server.c (register_commands): Add NULL arg to assuan_register_command. 2009-11-02 Marcus Brinkmann * server.c (reset_notify, input_notify, output_notify): Update to new assuan interface. (register_commands): Use assuan_handler_t. 2009-10-19 Werner Koch * options.h (glo_ctrl): Add field LASTERR. * mainproc.c (proc_encrypted): Set LASTERR. * server.c (cmd_decrypt): Check LASTERR. 2009-10-02 Werner Koch * server.c (cmd_encrypt, cmd_decrypt): Implement. * decrypt.c (decrypt_message_fd): New. * options.h (struct opt): Add field OUTFP. * plaintext.c (handle_plaintext): Support opt.outfp. * encr-data.c: Rename to decrypt-data.c to reflect the action and not the processed packet type. 2009-10-02 Werner Koch * encr-data.c (decode_filter_context_s): Add fields PARTIAL and LENGTH. (decrypt_data): Set them. Simplify premature EOF detection. (mdc_decode_filter): Take fixed length packets in account. (decode_filter): Ditto. Better EOF detection. * parse-packet.c (parse_encrypted): Store ed->LEN without the MDC version byte. 2009-09-30 Werner Koch * parse-packet.c (skip_packet, parse_gpg_control) : Take care of premature EOFs. * gpg.c (main): Remove obsolete GCRYCTL_DISABLE_INTERNAL_LOCKING. 2009-09-29 Werner Koch * openfile.c (open_outfile): Re-indent. Use xstrconcat. (NAME_OF_DEV_NULL): New. (open_outfile): Use it. (overwrite_filep): Use it. Also use case insensitive compare when needed. Re-indent. (open_outfile): Add arg INP_FD. Change all callers. * encrypt.c (encrypt_crypt): Add new args FILEFD, OUTPUTFD and PROVIDED_KEYS. Change all callers. 2009-09-28 Werner Koch * server.c (skip_options, has_option): New. (cmd_recipient): Implement. * keydb.h (pk_list_t): New. * pkclist.c (send_status_inv_recp): New. Replace direct calls. (build_pk_list): Factor some code out to ... (find_and_check_key): ... new. * encode.c: Rename to encrypt.c. Re-indent all. * encrypt.c (encode_symmetric, encode_store, encode_seskey) (encode_simple, encode_crypt, encode_filter) (encode_crypt_files): Rename all to encrypt_*. Change all callers. * trustdb.c (get_validity_info): Take care of a NULL PK. Fixes bug#1138. (get_validity_string): Ditto. 2009-09-25 Werner Koch * pkglue.c (pk_sign, pk_verify, pk_encrypt, pk_decrypt) (pk_check_secret_key): Allow deprecated RSA identifiers 2 and 3. Fixes bug#1139. 2009-09-23 Marcus Brinkmann * call-agent.c: Include "scdaemon.h" before because of GPG_ERR_SOURCE_DEFAULT check. (learn_status_cb, dummy_data_cb, get_serialno_cb, default_inq_cb) (learn_status_cb, inq_writecert_parms, inq_writekey_parms) (scd_genkey_cb, membuf_data_cb): Return gpg_error_t instead of int. * gpg.c: Include "scdaemon.h" before because of GPG_ERR_SOURCE_DEFAULT check. (main): Update to new Assuan API. * server.c: Include "scdaemon.h" before because of GPG_ERR_SOURCE_DEFAULT check. (option_handler, cmd_recipient, cmd_signer, cmd_encrypt) (cmd_decrypt, cmd_verify, cmd_sign, cmd_import, cmd_export) (cmd_delkeys, cmd_message, do_listkeys, cmd_listkeys) (cmd_listsecretkeys, cmd_genkey, cmd_getinfo): Return gpg_error_t instead of int. (register_commands): Allocate assuan context before starting server. (gpg_server): Allocate assuan_context before starting server. 2009-09-04 Werner Koch * keyedit.c (menu_select_uid): Use IDX ==-1 t select all. (menu_select_key): Ditto. (keyedit_menu) : Allow '*' to select all. 2009-09-03 Werner Koch * keyedit.c (menu_adduid): Pass keyblock to generate_user_id. * keygen.c (generate_user_id): Add arg KEYBLOCK. Factor code out to ... (uid_from_string): ... new. (ask_user_id): Add arg KEYBLOCK and check for duplicates. Fix bug#1122. * Makefile.am (uninstall-local): New. * compress-bz2.c (do_uncompress): Detect unexpected EOF. Fix bug#1011. 2009-08-26 Werner Koch * keyedit.c (menu_revsig): Check for signature right away. Fix Debian-bug#543530. 2009-08-20 Daiki Ueno * mainproc.c (proc_encrypted): Clear passphrase cached with S2K cache ID if decryption failed. * passphrase.c (passphrase_to_dek_ext): Set dek->s2k_cacheid. * gpgv.c (passphrase_clear_cache): New stub. 2009-08-11 Werner Koch * call-agent.c (get_serialno_cb): New. From ../agent/call-scd.c. (gpg_agent_get_confirmation): New. (select_openpgp): New. (agent_scd_pkdecrypt, agent_scd_pksign): Use it here. 2009-08-06 Werner Koch * skclist.c (build_sk_list): Print INV_SGNR status line. * seckey-cert.c (do_check): Return G10ERR_UNU_SECKEY instead of general error. 2009-08-05 Werner Koch * card-util.c: Enable readline support also in GnuPG-2. * call-agent.c (agent_learn): Always select the card first. * gpg.c: Add --key-edit alias. * call-agent.c (scd_genkey_cb): Forward progress status lines. * card-util.c (generate_card_keys): Remove special case for GnuPG-2. Ask for the keysize and change it. (card_generate_subkey): Ask for the keysize and change it. (get_info_for_key_operation): Read KEY-ATTR. (show_keysize_warning, ask_card_keysize): New. (do_change_keysize): New. 2009-07-31 David Shaw * gpg.c (main): --pgp6 includes --disable-mdc. 2009-07-23 David Shaw * keyserver.c (keyserver_import_ldap): Try a DNS-SD lookup to find a domain-specific LDAP server before resorting to keys.{domain}. 2009-07-22 Werner Koch * card-util.c (generate_card_keys): Ask for off-card keys only if the card supports it. (get_info_for_key_operation): Read EXTCAP. (card_store_subkey): Check for non matching sizes. * call-agent.h (struct agent_card_info_s): Add field EXTCAP. * call-agent.c (agent_learn): Use a direct SCD command. (did_early_card_test): New. (start_agent): Perform an early test for the card. Add arg FOR_CARD. (status_sc_op_failure): New. (agent_scd_setattr, agent_scd_writekey, agent_scd_genkey) (agent_scd_pksign, agent_scd_pkdecrypt, agent_scd_change_pin) (agent_scd_checkpin): Call new function. (learn_status_cb): Parse KEY_TIME and EXTCAP. * gpg.c (main) : Show commands to run. * trustdb.c (how_to_fix_the_trustdb): New. * tdbio.c (tdbio_invalid): Show commands to re-create the trustdb. Fixes bug#929. 2009-07-20 Werner Koch * keygen.c (generate_keypair): Allow Elgamal > 3072 in BOTH mode. Reported by Jeroen Schot. Fixes bug#1091. 2009-07-17 Werner Koch * keyring.c (keyring_rebuild_cache): Replace the assert by a proper error message and allow to delete a bad keyblock. 2009-07-13 Werner Koch * exec.c: Fix function name indentation. (expand_args): Simplify by using membuf functions. (exec_write): Fix memory leak on error. (w32_system): Use DETACHED_PROCESS so that a new console is not created. 2009-07-09 Werner Koch * card-util.c (card_store_subkey): Do not restrict to 1024 bit keys. Print an error message on write errors. * gpg.c (main): Remove the SHA-1 default from the personal digest list. This was used in the past as a hack to avoid preferring RMD-160. * keygen.c (keygen_set_std_prefs): Remove RMD-160 from the list. Change order to SHA-256, SHA-1, SHA-384, SHA-512, SHA-224. (gen_dsa): Use a 256 bit Q for 2048 bit P. Round to FIPS allowed values in non-expert mode. 2009-07-07 Werner Koch * gpg.c (set_opt_session_env): New. (main): Allocate opt.session_env. Use it for oDisplay, oTTYname, oTTYtype and oXauthority. * options.h: Include session_env.h. (opt): Add field SESSION_ENV, remove obsolete fields. * call-agent.c (start_agent): Adjust start_new_gpg_agent for changed args. 2009-06-24 Werner Koch * keyedit.c (menu_select_key): Remove dead assign to I. (menu_select_uid): Ditto. * keyring.c (keyring_search): Remove dead assign to NAME. * card-util.c (card_edit): Remove useless DID_CHECKPIN. * call-agent.c (unhexify_fpr): Remove dead op on N. * passphrase.c (passphrase_to_dek_ext): Do not deref a NULL PW. * revoke.c (gen_revoke): Remove unused malloc of PK. * parse-packet.c (mpi_read): Init NREAD. Reported by Fabian Keil. 2009-06-17 Werner Koch * parse-packet.c (parse): Use a casted -1 instead of a 32 bit constant to check for a garbled package. Fixes bug#1040. * card-util.c (put_data_to_file, read_cert): New. (card_edit): Add command "readcert". (fetch_url): Allow code also for this gnupg major version 2. * call-agent.c (agent_scd_readcert): New. 2009-06-15 Werner Koch * keyserver.c (keyserver_search_prompt): No prompt in batch+colons mode. 2009-06-09 Werner Koch * card-util.c (write_sc_op_status): New. (change_pin): Use it. (change_url, change_login, change_private_do, change_cert) (change_lang, change_sex, change_cafpr, toggle_forcesig) (check_pin_for_key_operation): Ditto. 2009-06-05 David Shaw * gpg.c (main), misc.c (openpgp_cipher_test_algo): Remove Camellia restriction. * misc.c (map_cipher_openpgp_to_gcry), main.h: Add macros for openpgp_cipher_open, openpgp_cipher_get_algo_keylen, and openpgp_cipher_get_algo_blklen to wrap around the corresponding gcry_* functions, but pass the algorithm number through map_cipher_openpgp_to_gcry. This is needed in case the gcry algorithm number doesn't match the OpenPGP number (c.f. Camellia). * encr-data.c, pubkey-enc.c, mainproc.c, cipher.c, encode.c, seskey.c, passphrase.c, seckey-cert.c: Use new openpgp_cipher_* macros here. 2009-06-02 Werner Koch * card-util.c (get_manufacturer): Add new manufacturer. 2009-05-26 Werner Koch * parse-packet.c (mpi_read): Workaround for zero-length MPI bug in libgcrypt<1.5.0. 2009-05-22 Werner Koch * signal.c (got_fatal_signal): Call new function tty_cleanup_after_signal. 2009-05-20 Werner Koch * gpg.c (main): Fix --fingerprint/--with-fingerprint command detection. Fixes bug#1044. * keygen.c (ask_keysize): Allow selection of DSA key size even without --enable-dsa2. (gen_dsa): Remove size check. * keygen.c (ask_key_flags): Fix bug in the translation check. Fixes bug#1056. 2009-05-18 Daiki Ueno (wk) * encode.c (encode_simple): Tell passphrase_to_dek to cache the passphrase. (setup_symkey): Ditto. * mainproc.c (proc_symkey_enc): Tell passphrase_to_dek to cache the passphrase. (proc_encrypted): Ditto. * passphrase.c (hash_passphrase): Remove arg CREATE. (passphrase_to_dek): New mode 3 and 4 for caching passphrase for symmetric encryption. 2009-05-17 Werner Koch * keygen.c (ask_algo): Add arg R_SUBKEY_ALGO. Change return value semantics. Change presented order of algorithms. Make RSA+RSA the default. (generate_keypair): Adjust for change. (ask_keysize): Add arg PRIMARY_KEYSIZE for subkey creation. Change callers. 2009-05-15 Werner Koch * keygen.c (gen_card_key_with_backup): Get the size of the key from the card. * call-agent.h (struct agent_card_info_s): Add field KEY_ATTR. * call-agent.c (learn_status_cb): Support KEY-ATTR. * card-util.c (card_status): Print key attributes. 2009-05-15 Marcus Brinkmann * gpg.c (gpgconf_list): Remove dead entry "allow-pka-lookup" (a verify option for a couple of years now). 2009-05-14 Werner Koch * call-agent.c (agent_get_passphrase): Add arg CHECK. * passphrase.c (passphrase_get): Pass new arg. * keygen.c (gen_card_key_with_backup): Print a status error. (do_generate_keypair): Ditto. (do_ask_passphrase): Add arg MODE. (generate_raw_key): Call with mode 1. * passphrase.c (ask_passphrase): Remove becuase it is not used. (passphrase_to_dek): Factor code out to ... (passphrase_to_dek_ext): .. New. Add args CUSTDESC and CUSTPROMPT. 2009-05-13 Werner Koch * keygen.c (parse_expire_string): Base ISO date string at noon. Also allow full ISO timestamp. 2009-05-11 Werner Koch * parse-packet.c (parse_key): Print the key id in list mode. * skclist.c (build_sk_list): Use log_info for "duplicated entry". Fixes bug#1045. * encode.c (encode_simple): Print empty file warning only in verbose mode. Closes bug#1039. (encode_crypt): Ditto. * sign.c (write_plaintext_packet): Ditto. 2009-05-10 David Shaw * keyserver.c (keyserver_typemap): gpgkeys_hkp handles hkps as well. From 1.4. 2009-05-06 Werner Koch * getkey.c (finish_lookup): Remove dead code. * keyring.c (keyring_get_keyblock): Fix memory leak due to ring trust packets. Fixes bug#1034. 2009-04-03 Werner Koch * gpgv.c (main): Open keyrings readonly. * keydb.c (keydb_add_resource): Add readonly flag bit. (keydb_rebuild_caches): Don't act on readonly resources. * keyring.c (keyring_register_filename): Add arg READONLY. (struct keyring_name): Add field READONLY. (keyring_is_writable): Implement readonly feature. (keyring_update_keyblock): Return GPG_ERR_EACCES for readonly keyrings. (keyring_insert_keyblock, keyring_delete_keyblock): Ditto. 2009-04-01 Werner Koch * gpg.c (main): Properly handle UTF8 usernames with --sign-key and --lsign-key. From 1.4, David 2008-12-21. 2009-03-20 David Shaw (wk) * keyring.c (rename_tmp_file): Force a fsync (via iobuf_ioctl) on secret keyring files to be extra safe on filesystems that may not sync data and metadata together (ext4). Also check return code from the cache invalidation to make sure we're safe over NFS and similar. 2009-03-31 Werner Koch * passphrase.c (ask_passphrase): Use percent_plus_unescape. * misc.c (unescape_percent_string): Remove. * call-agent.c (unescape_status_string): Chnage to use percent_plus_unescape. 2009-03-25 Werner Koch * mainproc.c (print_pkenc_list): Use snprintf. 2009-03-17 Werner Koch * call-agent.c (my_percent_plus_escape): Remove. (agent_get_passphrase): Rewrite using percent_plus_escape. 2009-03-17 Daiki Ueno * passphrase.c (passphrase_get): Add extra arg REPEAT and adjust callers; remove special treatment for MODE==2. (passphrase_to_dek): Move --passphrase-repeat handling to gpg-agent. * call-agent.c (agent_get_passphrase): Add extra arg REPEAT. * call-agent.h: Ditto. 2009-03-16 Werner Koch * gpg.c (my_strusage): Revert last change. Systems w/o a gpg1 may, and actually do, install gpg2 as gpg. * gpgv.c (my_strusage): Ditto. 2009-03-14 David Shaw * gpg.c (my_strusage): gpg2 and gpgv2 (not gpg and gpgv). * gpgv.c (my_strusage): Same. * gpgv.c (my_strusage): Fix name of program in "Syntax" line. 2009-02-27 Werner Koch * call-agent.c (agent_scd_pksign, agent_scd_pkdecrypt): First send the SERIALNO command. 2009-02-24 Werner Koch * pkglue.c (pk_verify): Return an error for improper DATA instead of calling BUG(). 2009-02-09 Werner Koch * keylist.c (print_capabilities): Take care of cert-only keys. Fixes bug#998. * keyedit.c (show_key_with_all_names_colon): Print the capabilities. 2009-01-26 Werner Koch * card-util.c (card_status): Detect a Geldkarte. 2009-01-13 Werner Koch * call-agent.c (dummy_data_cb): New. (agent_learn): Use it. * card-util.c (card_status): Print type of non-OpenPGP card. * call-agent.h (agent_card_info_s): Add field APPTYPE. 2009-01-12 Werner Koch * getkey.c (finish_lookup): Take care of keys with a zero timestamp. Reported by Peter Gutmann. 2009-01-08 Werner Koch * misc.c (has_invalid_email_chars): Let non-ascii pass through. * cpr.c [USE_SHM_COPROCESSING]: Remove this code. 2008-12-12 Werner Koch * passphrase.c (passphrase_get): Write a STATUS_ERROR. * cpr.c (write_status_error): New. * Makefile.am (common_source): Add rmd160.h. 2008-12-11 Werner Koch * sig-check.c (signature_check2): Change algorithm used to compute the SIG_ID. (check_revocation_keys): Close message digest. * rmd160.c, rmd160.h: New. Based on code from GnuPG-1.4. * t-rmd160.c: New. * Makefile.am: Add support to run tests. * keyid.c (namehash_from_uid): Use rmd160_hash_buffer. 2008-12-10 Werner Koch * trustdb.h (NAMEHASH_HASH): Remove unsued constant. * gpg.c (print_mds): Print RMD160 only is enabled. * keygen.c (keygen_set_std_prefs): Include RMD160 only if available. 2008-12-09 Werner Koch * gpg.c (main) [IS_DEVELOPMENT_VERSION]: Fix strusage use. 2008-12-09 Werner Koch * keygen.c (proc_parameter_file): Check that key and subkey usages are allowed. 2008-12-09 David Shaw (wk) * trustdb.c (validate_one_keyblock): Fix the trust signature calculations so that we lower the trust depth of signatures to fit within the current chain, rather than discarding any signature that does not fit within the trust depth. 2008-12-09 Werner Koch * keyserver.c (show_prompt): Flush stdout. * gpg.c (open_info_file): Add arg BINARY and adjust callers. * gpg.c (main): Call i18n_init before init_common_subsystems. * gpgv.c (main): Ditto. * keylist.c (set_attrib_fd): Do not close ATTRIB_FP if it is the log stream. (set_attrib_fd) [W32]: Set to binary mode. (dump_attribs): Flush the stream after writing. 2008-12-05 Werner Koch * call-agent.c (percent_plus_escape): Rename to my_percent_plus_escape and also escape the percent character. Change all callers. 2008-11-18 Werner Koch * gpg.c (build_lib_list): Remove. (make_libversion): New. (my_strusage): Use it. * gpgv.c (make_libversion): New. (my_strusage): Print libgcrypt version. 2008-11-13 Werner Koch * gpgv.c: Use new ARGPARSE macros and re-indent. 2008-11-11 Werner Koch * gpg.c (opts): Use new ARGPARSE macros for clarity. 2008-10-24 Werner Koch * keyedit.c (change_passphrase): Clear passphrase cache. 2008-10-20 Werner Koch * gpgv.c: Mark all args of the stub fucntions as unused. * card-util.c (generate_card_keys): Remove unused arg SERIALNO and adjust caller. * build-packet.c (write_sign_packet_header): Mark unused arg. * gpg.c (gpg_init_default_ctrl, gpg_deinit_default_ctrl): Ditto. * getkey.c (skip_unusable): Ditto. (write_version): Ditto. * keydb.c (keydb_locate_writable): Ditto. * keyring.c (update_offset_hash_table): Ditto. (keyring_lock): Ditto. * misc.c (register_secured_file): Ditto. (unregister_secured_file): Ditto. (is_secured_file): Ditto. (is_secured_filename): Ditto. * parse-packet.c (parse_marker): Ditto. (parse_key, parse_attribute): Ditto. (parse_trust, parse_compressed, parse_mdc, parse_gpg_control): Ditto. * cpr.c (progress_cb): Ditto. * passphrase.c (passphrase_clear_cache): Ditto. (ask_passphrase): Ditto. * keyedit.c (keyedit_completion): Ditto. * import.c (import_revoke_cert): Ditto. (chk_self_sigs, delete_inv_parts, append_uid): Ditto. (merge_sigs, merge_keysigs, append_key): Ditto. * trustdb.c (list_trust_path): Ditto. (enum_cert_paths, enum_cert_paths_print): Ditto. * tdbdump.c (list_trustdb): Ditto. * keygen.c (keygen_upd_std_prefs): Ditto. (genhelp_factors): Ditto. * call-agent.c (agent_scd_setattr): Ditto. (agent_scd_writekey, agent_scd_change_pin, agent_scd_genkey): Ditto. (agent_clear_pin_cache): Ditto. * server.c (option_handler): Mark non yet used arg. (input_notify, output_notify): Ditto. (cmd_recipient, cmd_signer, cmd_encrypt, cmd_decrypt, cmd_verify) (cmd_sign, cmd_import, cmd_export, cmd_delkeys, do_listkeys) (cmd_genkey): Ditto. * verify.c (gpg_verify): Ditto. 2008-10-17 Werner Koch * main.h (idea_cipher_warn): Use do while construct in place of an empty definition. 2008-10-03 David Shaw * main.h, mainproc.c (check_sig_and_print) * keylist.c (list_keyblock_print) * pkclist.c (do_edit_ownertrust) * keyedit.c (menu_showphoto) * photoid.c (generate_photo_id, show_photos) * misc.c (pct_expando): Add %v and %V expandos so that displaying photo IDs can show the attribute validity tag (%v) and string (%V). Originally by Daniel Gillmor. 2008-09-29 Werner Koch * gpg.c (main): Remove -sat kludge. Note that we printed a warning for two years. * seskey.c (encode_md_value): Remove extra gcry_md_test_algo since it is not needed with Libgcrypt 1.4. * skclist.c (random_is_faked): Simplify. * sign.c (match_dsa_hash): Remove runtime check for SHA224. * gpg.c (print_mds): Use GCRY_MD_SHA224 constant. 2008-09-25 David Shaw * keyedit.c (keyedit_menu): Fix bug where a modified keyring loses its modified status after a "clean" or "minimize" that doesn't need to do anything. 2008-09-25 Werner Koch * parse-packet.c (parse): Remove special treatment for compressed new style packets. Fixes bug#931. * card-util.c (change_pin): Support setting of the reset code. 2008-09-24 Werner Koch * call-agent.h (struct agent_card_info_s): Add field IS_V2. * call-agent.c (learn_status_cb): That that field. * card-util.c (change_pin): Rename first arg to UNBLOCK_v2 and use it this way. (card_edit): Add new command UNBLOCK. 2008-09-23 David Shaw * pkclist.c (select_algo_from_prefs): Redo function to rank prefs and pick a consensus winner across all keys. 2008-09-16 Werner Koch * card-util.c (fpr_is_ff): New. (card_status): Do not print general key info for an all-ff fpr. (change_login, change_private_do): Factor common code out to ... (get_data_from_file): .. new. (change_cert): New. (card_edit): Add command "writecert". * call-agent.c (writecert_parm_s): New. (inq_writecert_parms, agent_scd_writecert): New. 2008-09-04 David Shaw * keyserver.c (keyserver_import_cert): Allow keyserver URLs in addition to full URLs in CERT records. 2008-08-11 Werner Koch * keygen.c (ask_expire_interval): Check for time overflow of an u32. Fixes bug #947. 2008-08-01 Werner Koch * tdbio.c (open_db) [!EROFS]: Move closing parens out of the ifdef. Reported by Ken Takusagawa. 2008-06-25 Marcus Brinkmann * gpg.c (enum cmd_and_opt_values): Remove option oEnableW32HandleTranslation. (opts): Remove option --enable-w32-handle-translation. (main): Remove variable w32_handle_translation. 2008-06-19 Werner Koch * gpg.c (gpgconf_list): Add "group". 2008-06-18 Marcus Brinkmann * gpg.c (enum cmd_and_opt_values): New option oEnableW32HandleTranslation. (opts): New option --enable-w32-handle-translation. (main): New variable w32_handle_translation to keep track of option. 2008-06-16 Werner Koch * keygen.c (output_control_s): Add ASK_PASSPHRASE. (read_parameter_file): Add commands %ask-passphrase and %no-ask-passphrase. 2008-06-11 Werner Koch * gpg.c: Make --fixed-list-mode a dummy. * options.h (struct): Removed FIXED_LIST_MODE. * keyid.c (colon_strtime, colon_datestr_from_pk) (colon_datestr_from_sk, colon_datestr_from_sig) (colon_expirestr_from_sig): Remove fixed_list_mode case. * keylist.c (list_keyblock_colon): Ditto. Remove all now unsed code and reindent. 2008-05-31 Werner Koch * keygen.c (ask_user_id): Change the string printed as header of the user ID generation. Use code to not break existing translations. Suggested by Eric Tetz. 2008-05-08 Werner Koch * sig-check.c (do_check_messages): Print a revocation diagnostic in verbose mode. 2008-05-07 Werner Koch * gpg.c: New command --locate-keys. New options --with-sig-list and --with-sig-check. * keylist.c (locate_one): New. (public_key_list): Add arg LOCATE_MODE and use locate_one. * getkey.c (get_pubkey_byname): Fix nodefault case. Add option RETCTX, change all callers. (struct getkey_ctx_s): Add field extra_ptr; (get_pubkey_end): Free it. 2008-04-18 Werner Koch * misc.c (map_cipher_openpgp_to_gcry, map_cipher_gcry_to_openpgp) (openpgp_cipher_test_algo): Add camellia-192. (openpgp_cipher_blocklen): New. * parse-packet.c (parse_key): Use new function here. 2008-04-15 David Shaw * getkey.c (merge_selfsigs_subkey): If there are multiple 0x19 backsigs, take the most recent one. 2008-04-08 Werner Koch * options.h (opt): Add AKL_NODEFAULT and AKL_LOCAL. * getkey.c (parse_auto_key_locate): Parse them. (get_pubkey_byname): Implement them. Add arg NO_AKL and use that in all cases where a local key is expected. * import.c (import_one): Fill in the fingerprint in all cases. Use log_get_stream. * keyserver.c (keyserver_import_pka): Set FPR to NULL on error. Return G10ERR_NO_PUBKEY if no PKA info is available or no key URI is given in the PKA record.. (keyserver_import_cert): Return G10ERR_NO_PUBKEY if a CERT record was not found. * getkey.c (get_pubkey_byname): Release FPR in the error case. Continue with next mechanism on error. Better diagnostics. 2008-04-07 Werner Koch * keyserver.c (parse_keyserver_uri): Allow a default host name. * getkey.c (get_pubkey_byname): Replace sprintf by bin2hex. 2008-04-02 Werner Koch * gpg.c (main): Do not allow DSA2 with a too old Libgcrypt. 2008-03-26 Werner Koch * tdbio.c (lookup_hashtable): Make cmp args const. (cmp_trec_fpr): Make FPR const. (tdbio_search_trust_byfpr): Remove cast. 2008-03-25 Werner Koch * keyserver.c (parse_keyrec): Take care of char defaulting to unsigned when using hextobyte. 2008-03-25 David Shaw (wk) * import.c (collapse_uids): Fix bug 894: possible memory corruption around deduplication of user IDs. 2008-03-25 Werner Koch * parse-packet.c (parse_key): Parse a secret key encrypted with Camellia. * options.skel: Make the default keyserver keys.gnupg.net. 2008-03-18 Werner Koch * seckey-cert.c (do_check): Use GCRYMPI_FMT_PGP for v3 keys. Reported by Petr Cerny. 2008-03-13 Werner Koch * passphrase.c (PROMPTSTRING): Change string to me more similar to the X.509 prompt. 2008-02-26 Werner Koch * getkey.c (get_pubkey_byname): Fix comment. 2008-02-14 Werner Koch * call-agent.c (default_inq_cb): New. (agent_learn, agent_scd_getattr, agent_scd_pksign) (agent_scd_pkdecrypt, agent_scd_change_pin, agent_scd_checkpin) (agent_get_passphrase, agent_clear_passphrase): Use new callback. (inq_writekey_parms): Fall back to the new callback for other inquiries. (start_agent): Tell agent that we accept pinentry notifications. 2008-02-11 Werner Koch * server.c (cmd_getinfo): New. (register_commands): Register GETINFO. 2008-02-09 Marcus Brinkmann * gpg.c (main): New variable default_configname. Use it if save_configname is NULL (can happen if default configfile does not exist). Move default configname determination to ... (get_default_configname): ... this new function. 2008-01-30 Werner Koch * keydb.c (maybe_create_keyring): Fixed last change. * tdbio.c (tdbio_set_dbname): Also test for forward slash. 2008-01-29 Werner Koch * keydb.c (maybe_create_keyring): Take care of a missing slash. (maybe_create_keyring) [W32]: Also test for forward slash. 2008-01-26 Werner Koch * card-util.c (get_manufacturer): Add vendor 0004. 2008-01-02 Werner Koch * gpg.c: Add --logger-file as an alias for log-file. 2007-12-14 Werner Koch * gpg.c (main): Set opt.no_homedir_creation during the first option parsing pass. 2007-12-12 Werner Koch * misc.c (print_pubkey_algo_note): Print a warning if a type 20 key is used. (openpgp_pk_test_algo, openpgp_pk_test_algo2) (openpgp_pk_algo_usage): Allow type 20 keys only in rfc2440 mode. 2007-12-12 David Shaw (wk) * trustdb.c (sanitize_regexp): New. Protect against dangerous regexps (malloc bombs) by force-commenting any characters aside from the ones we explicitly want. (check_regexp): Use it here before passing the regexp to regcomp(). 2007-12-12 Werner Koch * misc.c (map_cipher_openpgp_to_gcry): New. Used to map Camellia algorithms to Gcrypt. (openpgp_cipher_test_algo): Call new map function. Replace all remaining calls to gcry_cipher_test_algo by a call to this. (openpgp_cipher_algo_name): New. Replace all remaining calls to gcry_cipher_algo_name by a call to this. (map_cipher_gcry_to_openpgp): New. (string_to_cipher_algo): Use it. * gpg.c (main): Print a warning if Camellia support is build in. * gpg.c (print_algo_names): New. From the 1.4 branch by David. (list_config): Use it here for the "ciphername" and "digestname" config items so we can get a script-parseable list of the names. * parse-packet.c (parse_onepass_sig): Sigclass is hex, so include the 0x. * sign.c (match_dsa_hash): Remove conditional builds dending on USE_SHAxxx. We don't need this becuase it can be expected that libgcrypt provides it. However we need to runtime test for SHA244 becuase that is only available with libgcrypt 2.4. 2007-12-11 Werner Koch * mainproc.c (proc_pubkey_enc): Allow type 20 Elgamal key for decryption. 2007-12-10 Werner Koch * import.c (auto_create_card_key_stub): Do not clear the entire fingerprint. This finally makes the stub creation work. My past tests seemed to work because there was a key with a all zero fingerprint available (Elgamal signing keys). 2007-12-08 Werner Koch * misc.c (openpgp_pk_algo_usage): Allow Elgamal type 20 for encryption. 2007-12-04 Werner Koch * helptext.c (get_help_from_file): New. (display_online_help): Use it to geting the help through a file. (helptexts): Remove. 2007-12-03 Werner Koch * keygen.c (ask_key_flags): Add a translation remark and implement a workaround. * gpg.c (reopen_std): Moved to ../common and renamed to gnupg_reopen_std. * gpg.c: Remove second inclusion of fcntl.h. 2007-11-19 Werner Koch * keyedit.c (keyedit_menu): String grammar fix. 2007-11-15 Werner Koch * gpg.c (main): New option --xauthority. * call-agent.c (start_agent): Adjust changed start_new_gpg_agent. 2007-11-12 Werner Koch * cpr.c (do_get_from_fd): s/bool/getbool/ to overcome problems with Mac OS 10.5 which seems to include stdbool.h silently. 2007-11-07 Werner Koch Replace all includes of errors.h by status.h (found in common/). * status.h: Remove. * status.h: Move prototypes to main.h. * status.c: Rename to .. * cpr.c: .. this. (get_status_string): Remove. We take this now from common/. 2007-10-25 David Shaw (wk) From 1.4 (October): * gpg.c (main): Add --require-cross-certification to --openpgp/--rfc4880 mode. * gpg.c (main): Disable --rfc2440-text and --force-v3-sigs by default. Enable --require-cross-certification by default. --openpgp (--rfc4880) is the same as --rfc2440 except with "--enable-dsa2 --no-rfc2440-text --escape-from-lines". * misc.c (compliance_option_string, compliance_failure): Minor cleanup. * armor.c (is_armor_header): Comment about 4880. * options.h, gpg.c (main): Add --rfc4880, and make --openpgp an alias to it. --rfc2440 now stands alone. For now, use the old 2440 defaults for 4880. * misc.c (compliance_option_string): Ditto. * keyedit.c (keyedit_menu): Use compliance_option_string() instead of printing the compliance modes here. 2007-10-25 David Shaw (wk) From 1.4 (September): * import.c (collapse_uids): Significant speedup for de-duping user IDs. 2007-10-25 David Shaw (wk) From 1.4 (July): * armor.c (parse_header_line): Improve test so that the header test only allows "Hash" in the signed data section. * armor.c (is_armor_tag): New. Detect if an armor header matches 2440bis-21. (parse_header_line): Call it here, as bis-21 requires warning the user (but continuing to process the message) when seeing an unknown header. * encode.c (encode_crypt): Missed one call to setup_plaintext_name(). This is bug#809. * sign.c (mk_notation_policy_etc): Expect all sigs that this is called for are >=v4. (write_signature_packets, make_keysig_packet): Only call it for >=v4 sigs. This allows --force-v3-sigs and --force-v4-certs to enable or disable notations, policies, and keyserver URLs. This is bug#800. 2007-10-19 Werner Koch * passphrase.c (passphrase_get): Use new utf8 switching fucntions. 2007-09-14 Werner Koch * gpg.c (build_lib_list): New. (my_strusage): Print lib info. 2007-08-27 Werner Koch * trustdb.c (USE_INTERNAL_REGEX): Remove support. 2007-08-24 Werner Koch * keyring.c (keyring_register_filename): Use same_file_p(). 2007-08-21 Werner Koch * misc.c (openpgp_md_test_algo): Remove rfc2440bis hash algorithms. (openpgp_cipher_test_algo): Likewise for algos 5 and 6. 2007-08-02 Werner Koch * gpg.c: Include gc-opt-flags.h and remove their definition here. 2007-07-17 Werner Koch * gpg.c (gpgconf_list): Declare --encrypt-to and --default-key. * card-util.c (get_manufacturer): Add the unmanaged S/N range. 2007-07-12 Werner Koch * gpg.c (main): Use translate_sys2libc_fd_int when passing an int value. * gpgv.c (main): Ditto. 2007-07-05 Werner Koch * card-util.c (card_generate_subkey, card_store_subkey): Enable the code also for GnuPG-2. * keygen.c (make_backsig): Add arg TIMESTAMP. (write_keybinding): Add arg TIMESTAMP, pass it to make_backsig. (write_direct_sig, write_selfsigs): Add arg TIMESTAMP. (gen_elg, gen_dsa, gen_rsa): Add arg TIMESTAMP. (do_create): Ditto. (do_generate_keypair): Use the same timestamp for key creation time and all key signatures. Return an error if write_direct_sig for the secret key fails. (generate_subkeypair): Ditto. (gen_card_key): New arg TIMESTAMP. (generate_card_subkeypair): Pass current time to gen_card_key. (gen_card_key_with_backup): New arg TIMESTAMP. (read_parameter_file): Add option Creation-Date. (parse_creation_string): New. (do_generate_keypair): Use the Creation-Date if available. (save_unprotected_key_to_card): Use P for P and not D. * call-agent.c (agent_scd_genkey): Add arg CREATETIME. * keyedit.c (menu_backsign): Use the same timestamp for all backsigs. 2007-06-26 Werner Koch * openfile.c (try_make_homedir): Support W32; use standard_homedir. 2007-06-25 Werner Koch * gpg.c, gpgv.c: Include sysutils.h. (main): Replace iobuf_translate_file_handle by translate_sys2libc_fd. 2007-06-21 Werner Koch * main.h: Include util.h. * call-agent.c (start_agent): Factored almost all code out to ../common/asshelp.c. * gpg.h (ctrl_t): Remove. It is now declared in ../common/util.h. 2007-06-20 Werner Koch * misc.c (setsysinfo, trap_unaligned): Remove. It is also in common/sysutils.c. (disable_core_dumps, get_session_marker): * sign.c (sleep): Remove sleep wrapper. 2007-06-18 Marcus Brinkmann * gpg.c (gpgconf_list): Percent escape output of --gpgconf-list. 2007-06-14 Werner Koch * call-agent.c (start_agent): Use gnupg_module_name. 2007-06-12 Werner Koch * openfile.c (copy_options_file): Use gnupg_datadir. * misc.c (get_libexecdir): Remove. Changed all callers to use gnupg_libexecdir. * gpg.c (check_permissions): Use gnupg_libdir. * gpg.c (main): Replace some calls by init_common_subsystems. * gpgv.c (main): Ditto. 2007-06-11 Werner Koch * Makefile.am (needed_libs): Use libcommonstd macro. * gpgv.c (main) [W32]: Call pth_init. * gpg.c (main) [W32]: Call pth_init. 2007-06-08 Werner Koch * Makefile.am (gpg2_LDADD): Syntax fix. 2007-06-06 Werner Koch * passphrase.c (passphrase_get) [!ENABLE_NLS]: Do not define orig_codeset. * Makefile.am (gpgv2_LDADD, gpg2_LDADD): Include LDADD before libgcrypt. * plaintext.c (handle_plaintext): Replace eof by eof_seen as W32's io.h has a symbol with that name. * misc.c: Do not include dynload.h. (w32_shgetfolderpath): Remove. It is now in common/homedir.c. * gpgv.c (i18n_init): Remove. * gpg.c (i18n_init): Remove. (main): Make --load-extension a dummy 2007-05-19 Marcus Brinkmann * passphrase.c (passphrase_get): Use PACKAGE_GT, not PACKAGE. * passphrase.c (passphrase_get): Free ORIG_CODESET on error. 2007-05-16 Werner Koch * sig-check.c (check_backsig): Check the digest algorithm before using it. Fixed bug 797. 2007-05-09 Werner Koch * openfile.c (overwrite_filep, open_outfile) [W32]: Need to use just "nul". Though, I am pretty sure that some MSDOS versions grok the extra /dev/. 2007-05-07 Werner Koch * openfile.c (open_outfile, overwrite_filep) [W32]: Use "/dev/nul". 2007-05-02 David Shaw * packet.h, mainproc.c (reset_literals_seen): New function to reset the literals count. * verify.c (verify_one_file), decrypt.c (decrypt_messages): Call it here so we allow multiple literals in --multifile mode (in different files - not concatenated together). 2007-04-26 Marcus Brinkmann * passphrase.c (passphrase_to_dek): Write missing passphrase status message in case of cancellation. 2007-04-16 Werner Koch * build-packet.c (mpi_write): Made buffer a bit larger. Reported by Alexander Feigl. 2007-04-13 Werner Koch * call-agent.c (start_agent): Don't use log_error when using the fallback hack to start the agent. This is bug 782. 2007-04-05 David Shaw From STABLE-BRANCH-1-4 * parse-packet.c (parse_marker): New. Enforce that the marker contains 'P', 'G', 'P', and nothing but. (parse): Call it here. (skip_packet): No longer need to handle marker packets here. 2007-03-14 David Shaw From STABLE-BRANCH-1-4 * keyserver.c: Windows Vista doesn't grok X_OK and so fails access() tests. Previous versions interpreted X_OK as F_OK anyway, so we'll just use F_OK directly. 2007-03-09 David Shaw From STABLE-BRANCH-1-4 * parse-packet.c (parse_signature): It's hex. * getkey.c (merge_selfsigs_subkey): Avoid listing the contents of a backsig when list mode is on. Noted by Timo Schulz. 2007-03-08 Werner Koch * plaintext.c (handle_plaintext): Add two extra fflush for stdout. 2007-03-08 David Shaw (wk) * keyedit.c (keyedit_menu): If we modify the keyblock (via fix_keyblock() or collapse_uids()) make sure we reprocess the keyblock so the flags are correct. Noted by Robin H. Johnson. * getkey.c (fixup_uidnode): Properly clear flags that don't apply to us (revoked, expired) so that we can reprocess a uid. 2007-03-05 Werner Koch Converted this file to UTF-8. Ported David and my multiple messages changes from 1.4.7. * options.h, gpg.c (main), mainproc.c (check_sig_and_print): Allow multiple sig verification again as this is protected via the multiple-messages code. New option --allow-multiple-messages and --no variant. * status.h (STATUS_ERROR): New status code. * status.c (get_status_string): Ditto. * mainproc.c (proc_plaintext): Emit it if multiple messages are detected. Error out if more than one plaintext packet is encountered. * mainproc.c (literals_seen): New. 2007-02-26 Werner Koch * gpg.c (main): Add verify option show-primary-uid-only. * options.h (VERIFY_SHOW_PRIMARY_UID_ONLY): New. * mainproc.c (check_sig_and_print): Implement it. 2007-02-22 Werner Koch * encr-data.c (decrypt_data): Correctly test for unknown algorithm. * import.c (check_prefs): Ditto. * keyedit.c (show_prefs): Ditto. * mainproc.c (proc_symkey_enc): Ditto. 2007-02-06 Werner Koch * export.c (do_export_stream): Allow reset-subkey-passwd along with sexp-format. 2007-02-04 Werner Koch * parse-packet.c (parse_signature): Limit bytes read for an unknown alogorithm. Fixes Debian bug#402592. 2007-01-31 Werner Koch * verify.c (verify_signatures): Do no dereference a NULL afx. * passphrase.c (passphrase_get): Set the cancel flag on all error from the agent. Fixes a bug reported by Tom Duerbusch. 2007-01-30 Werner Koch * status.c (write_status_begin_signing): New. * sign.c (sign_file, sign_symencrypt_file): Call it. * textfilter.c (copy_clearsig_text): Call it. * call-agent.c (agent_scd_pksign): Pass --hash-rmd160 to SCD if required. * gpg.c (main): Let --no-use-agent and --gpg-agent-info print a warning. * misc.c (obsolete_option): New. 2007-01-29 Werner Koch * pkclist.c (do_we_trust_pre): Issue a user-id-hint status code. 2007-01-15 Werner Koch * parse-packet.c (read_protected_v3_mpi): Make sure to stop reading even for corrupted packets. * keygen.c (generate_user_id): Need to allocate one byte more. Reported by Felix von Leitner. 2006-12-21 Werner Koch * gpg.c (main): New command --server. * gpg.h (struct server_control_s, ctrl_t): New. * server.c: New. * verify.c (gpg_verify): New. * mainproc.c (mainproc_context): Made SIGNED_DATA a structure. (proc_signature_packets_by_fd): New. (proc_compressed_cb): Divert depending on SIGNED_DATA. * plaintext.c (hash_datafile_by_fd): New. * mainproc.c (proc_tree): Use it here. * verify.c (verify_signatures): Init AFX only when needed. Don't leak a context on error. (verify_one_file): Don't leak a context on error. 2006-12-07 Werner Koch * openfile.c (copy_options_file): Use log_info instead of log_error to avoid an error return of gpg due to a missing skeleton file. 2006-12-07 David Shaw * Makefile.am: Link to iconv for jnlib dependency. 2006-12-05 Werner Koch * passphrase.c (passphrase_to_dek): Handle a Cancel request correctly. [Bug#737] * mainproc.c (proc_symkey_enc): Removed workaround for bogus cancel processing. * encode.c (encode_simple): Distinguish error message between cancel and invalid passphrase. (setup_symkey): Ditto. * sign.c (sign_symencrypt_file): Ditto * keyedit.c (change_passphrase): Allow cancellation. * keygen.c (do_ask_passphrase): New arg R_CANCELED. (generate_keypair): Handle a passphrase cancellation. (generate_raw_key): Ditto. (generate_subkeypair): Ditto. 2006-12-04 Werner Koch * filter.h (armor_filter_context_t): New element REFCOUNT. * armor.c (armor_filter): Made static. (push_armor_filter, release_armor_context, new_armor_context): New. (armor_filter): Release the context. * gpg.c (main): Use new armor context functions and push_armor_filter. * export.c (do_export): Ditto. * encode.c (encode_simple, encode_crypt): Ditto. * decrypt.c (decrypt_message, decrypt_messages): Ditto. * dearmor.c (dearmor_file, enarmor_file): Ditto. * verify.c (verify_signatures, verify_one_file): Ditto. * sign.c (sign_file, clearsign_file, sign_symencrypt_file): Ditto. * revoke.c (gen_desig_revoke, gen_revoke): Ditto. * keyserver.c (keyserver_spawn): Ditto. * keygen.c (output_control_s): Turn AFX fields into pointers. (read_parameter_file): Allocate and release AFX fields. (do_generate_keypair): Use push_armor_filter. * import.c (import): Replace iobuf_push_filter2 hack by the new armor context stuff. 2006-12-03 Werner Koch * filter.h: New element REFCOUNT. (handle_progress): Remove prototype. * progress.c (new_progress_context, release_progress_context): New. (progress_filter): Use new function to release context. Made static. (handle_progress): Bumb reference counter. No more check for enabled progress as this is handled by new_progress_context. * verify.c (verify_signatures, verify_one_file): Replace stack based progress context by a heap based one. * sign.c (sign_file, clearsign_file, sign_symencrypt_file): Ditto. * plaintext.c (ask_for_detached_datafile, hash_datafiles): Ditto. * encode.c (encode_simple, encode_crypt): Ditto. * decrypt.c (decrypt_message, decrypt_messages): Ditto. * keyedit.c (menu_clean): Made strings translatable. 2006-12-03 David Shaw * keyedit.c (menu_clean): Show "already minimized" rather than "already clean" when a minimized key is minimized again. From Dirk Traulsen. 2006-12-02 David Shaw * options.h, gpg.c (main), passphrase.c (passphrase_to_dek): Add --passphrase-repeat option to control how many times gpg will re-prompt for a passphrase to ensure the user has typed it correctly. Defaults to 1. 2006-12-02 Werner Koch * encr-data.c: Allocate DFX context on the heap and not on the stack. Changes at several places. Fixes CVE-2006-6235. 2006-11-27 Werner Koch * openfile.c (ask_outfile_name): Fixed buffer overflow occurring if make_printable_string returns a longer string. Fixes bug 728. 2006-11-21 Werner Koch * Makefile.am (needed_libs): libgnu needs to come after libcommon. * keygen.c (ask_expire_interval): Print y2038 warning only for 32 bit time_t. (save_unprotected_key_to_card): Made RSA_N_LEN et al a size_t. Cast printf args. (get_parameter_algo): Allow "ELG" as alias for "ELG-E". * seckey-cert.c (do_check): Made NBYTES a size_t. (do_check): Made NDATA a size_t. (protect_secret_key): Made NARR a size_t. (protect_secret_key): Made NVYES a size_t. * pubkey-enc.c (get_it): Made INDATALEN a size_t. (get_it): Made NFRAME a size_t. * keyid.c (hash_public_key): Made NBITS an unsigned int. * misc.c (checksum_mpi): Made NBYTES a size_t. (openpgp_pk_test_algo2): Made USE_BUF a size_t. * seskey.c (encode_session_key): Made NFRAME a size_t. (do_encode_md): Ditto. (encode_md_value): Cast size_t argument of printf. (encode_md_value): Ditto. 2006-11-10 Werner Koch * parse-packet.c (mpi_read): Changed NREAD to size_t to match the gcry_mpi-scan prototype. (mpi_read): Fixed double increment of bytes read to correctly detect overlong MPIs. 2006-11-05 Werner Koch * gpg.c (main): Remove the default --require-cross-certification. * options.skel: Enable require-cross-certification. 2006-10-31 Werner Koch * pkclist.c (warn_missing_aes_from_pklist): New. * encode.c (encrypt_filter, encode_crypt): Use it here. 2006-10-27 Werner Koch * pkclist.c (warn_missing_mdc_from_pklist): New. * encode.c (use_mdc): Use it here. 2006-10-24 Marcus Brinkmann * Makefile.am (AM_CFLAGS): Add $(LIBASSUAN_CFLAGS). 2006-10-23 Werner Koch * gpg.c (main): New command --gpgconf-test. * Makefile.am (bzip2_source): New. 2006-10-20 Werner Koch * getkey.c (classify_user_id): Reserve '&' for search by keygrip. 2006-10-19 Werner Koch * keygen.c (get_parameter_algo): Add special case for ELG_E which is not supported by libgcrypt's mapping function. 2006-10-18 Werner Koch * keyid.c (v3_keyid): Don't use mempcy as we need to hold the keyids in the native endian format. * import.c (import_print_stats): Use log_printf. * build-packet.c (do_public_key): Care about mpi_write errors. (do_secret_key, do_pubkey_enc, do_signature): Ditto. (mpi_write): Print an extra warning on error. 2006-10-17 Werner Koch * Makefile.am (LDADD): Replaced W32LIBS by NETLIBS. 2006-10-12 David Shaw * parse-packet.c (parse_symkeyenc): Show the unpacked as well as the packed s2k iteration count. * main.h, options.h, gpg.c (encode_s2k_iterations, main), passphrase.c (hash_passphrase): Add --s2k-count option to specify the number of s2k hash iterations. 2006-10-08 Werner Koch * gpgv.c: Remove the tty stubs as we are now required to link to tty anyway (it is included in libcommand and has dependencies to other modules as well). * keyedit.c (keyedit_menu): Use keyedit_completion only if readline is available. It would be better to move this code into gpgrlhelp.c 2006-10-06 Werner Koch * Makefile.am (AM_CFLAGS): Use PTH version of libassuan. 2006-10-06 David Shaw * keyserver.c (keyserver_spawn): Write the 16-digit keyid rather than whatever key selector the user used on the command line. 2006-10-05 Werner Koch * status.c (progress_cb): Changed to libgcrypt API. (set_status_fd): Register the progress cb. * seskey.c (encode_md_value): Check that the hash algo is valid before getting the OID. 2006-10-04 Werner Koch * passphrase.c: Allow for a static passphrase in batch mode. * call-agent.c (agent_havekey): Removed. (percent_plus_escape): New. (agent_get_passphrase): New. (agent_clear_passphrase): New. * passphrase.c: Changed so that we always require the agent. (agent_send_option, agent_send_all_options, agent_open): Removed. (agent_get_passphrase): Cleaned up. Does now use the call-agent functions. Renamed to (passphrase_get): .. this. Changed all callers. (passphrase_clear_cache): Rewritten. (passphrase_to_dek, hash_passphrase): Re-indented. * gpg.c (main): Made --use-agent a dummy option. * seckey-cert.c (check_secret_key): We require the agent, so always allow for 3 tries. * gpg.c (main): Print a warning if -sat has been used. (main): Removed the special treatment of the -k option. -k is now an alias for --list-keys. (main): Removed --list-ownertrust. 2006-10-02 Werner Koch * encr-data.c (decrypt_data, mdc_decode_filter): Check the MDC right here and don't let parse-packet handle the MDC. 2006-09-29 Werner Koch * compress.c (do_uncompress): Removed use of Z_PARTIAL_FLUSH. This is outdated and old zlib versions which still require it have security problems. 2006-09-27 Werner Koch Replaced all STRLIST by strlist_t. 2006-09-21 Werner Koch * signal.c (got_fatal_signal): Replaced readline stuff by a tty function. * Makefile.am (LDADD): Include libgpgrl.a. * gpg.c (main): Call gpg_rl_initialize. * keyedit.c: Removed double inclusion of stdio.h. 2006-09-20 Werner Koch * call-agent.c: Include asshelp.h. (start_agent): Use send_pinentry_environment. 2006-09-14 Werner Koch Replaced all call gpg_error_from_errno(errno) by gpg_error_from_syserror(). 2006-09-13 Werner Koch * gpg.c (main): Made --require-cross-certification the default. 2006-09-06 Marcus Brinkmann * Makefile.am (gpg2_LDADD, gpgv2_LDADD): Replace -lassuan and -lgpg-error with $(LIBASSUAN_LIBS) and $(GPG_ERROR_LIBS). (AM_CFLAGS): Add $(LIBASSUAN_CFLAGS) and $(GPG_ERROR_CFLAGS). 2006-09-06 Werner Koch * gpg.c (main): Enable new assuan API. * call-agent.c: Changed to new Assuan API. 2006-09-01 Werner Koch * call-agent.c: Do not force using the pipe server. * gpg.c (main): Enable card related commands. 2006-08-22 Werner Koch * mainproc.c (proc_plaintext): Fixed a #warning 2006-08-21 Werner Koch * skclist.c (random_is_faked): Implemented. (is_insecure): Also test for the old uppercase version of the insecure string. * gpg.c (main): Renamed --quick-random to debug-quick-quick-random. * gpg.c (print_mds): Do not use the USE_SHA macros. * mainproc.c (proc_encrypted): Remove assign inside condition for better readibility. * packet.h: Moved consts to new header ../common/openpgpdefs.h. 2006-08-16 Werner Koch * keyserver.c (GPGKEYS_PREFIX): Rename to gpg2keys_. This is so that we can install helpers from 1.4 and 2 without conflicts and first of all don't get lost with weird bug reports. * keyid.c (serialno_and_fpr_from_sk): New. Actually lost during the last 1.4 to 1.9 merge. * gpg.c (list_config): Output ccid-reader-id only for gnupg 1. * call-agent.c (agent_scd_writekey): New. (inq_writekey_parms): New. * gpgv.c: Include call-agent.h for use by stubs. * misc.c: Include call-agent.h for use by get_signature_count. 2006-07-27 Werner Koch * parse-packet.c (parse_comment): Cap comments at 65k. (parse_gpg_control): Skip too large control packets. 2006-07-24 David Shaw (wk) * keydb.h, pkclist.c (select_algo_from_prefs, algo_available): Pass a union for preference hints rather than doing void * games. * sign.c (sign_file): Use it here. * sign.c (sign_file): When signing with multiple DSA keys, one being DSA1 and one being DSA2 and encrypting at the same time, if the recipient preferences give a hash that can work with the DSA2 key, then allow the DSA1 key to be promoted rather than giving up and using hash_for(). * pkclist.c (algo_available): Automatically enable DSA2 mode when handling a key that clearly isn't DSA1 (i.e. q!=160). 2006-06-30 Werner Koch * misc.c (checksum_mpi): No need for nbits as they are alredy included in the buffer. 2006-06-29 Werner Koch * parse-packet.c (parse_signature, parse_key): Need store the length of opaque data as number of bits. * card-util.c (card_store_subkey): Ditto. * mainproc.c (print_pkenc_list, check_sig_and_print): Replaced log_get_stream by calls to log_printf. This avoids the extra LFs inserted by the logging function. They are a bit too smart sometimes. * pkclist.c (do_show_revocation_reason): Print final LF through log_printf to avoid extra LFs. * pubkey-enc.c (get_it): Ditto. * seskey.c (encode_md_value): Fix call to gcry. 2006-06-27 Werner Koch Applied patches from 1.4.x (2006-05-22 to 2006-06-23) from David: * keygen.c (keygen_upd_std_prefs, keygen_add_std_prefs) (proc_parameter_file): Add --default-keyserver-url to specify a keyserver URL at key generation time, and "Keyserver:" keyword for doing the same through a batch file. * options.h, gpg.c (main): Ditto. * sign.c (do_sign): For now don't accept a truncated hash even for DSA1 keys (be liberal in what you accept, etc). * import.c (import_one): Add a flag (from_sk) so we don't check prefs on an autoconverted public key. The check should only happen on the sk side. Noted by Dirk Traulsen. * keygen.c (gen_card_key): Add optional argument to return a pointer (not a copy) of the stub secret key for the secret key we just generated on the card. (generate_card_subkeypair): Use it here so that the signing key on the card can use the card to generate the 0x19 backsig on the primary key. Noted by Janko Heilgeist and Jonas Oberg. * parse-packet.c (parse_user_id): Cap the user ID size at 2048 bytes. This prevents a memory allocation attack with a very large user ID. A very large packet length could even cause the allocation (a u32) to wrap around to a small number. Noted by Evgeny Legerov on full-disclosure. * keygen.c (gen_dsa): Allow generating DSA2 keys. Allow specifying sizes > 1024 when --enable-dsa2 is set. The size of q is set automatically based on the key size. (ask_keysize, generate_keypair): Ask for DSA size when --enable-dsa2 is set. * exec.c (make_tempdir) [W32]: Fix bug with a temporary directory on W32 that is over 256 bytes long. Noted by Israel G. Lugo. * gpg.c (reopen_std): New function to reopen fd 0, 1, or 2 if we are called with them closed. This is to protect our keyring/trustdb files from corruption if they get attached to one of the standard fds. Print a warning if possible that this has happened, and fail completely if we cannot reopen (should never happen). (main): Call it here. * parse-packet.c (dump_sig_subpkt, parse_signature): Fix meaning of key expiration and sig expiration subpackets - zero means "never expire" according to 2440, not "expire instantly". * build-packet.c (build_sig_subpkt_from_sig): Ditto. * getkey.c (fixup_uidnode, merge_selfsigs_main) (merge_selfsigs_subkey): Ditto. * keygen.c (keygen_add_key_expire): Ditto. * getkey.c (get_pubkey_byname) * import.c (import_one): Fix key selection problem when auto-key-locate returns a list of keys, not all of which are usable (revoked, expired, etc). Noted by Simon Josefsson. 2006-05-24 Werner Koch * keyid.c (hash_public_key): Do not double hash the length bytes, they are already included by mpi_print. * misc.c (openpgp_pk_test_algo2): Get test call right. * misc.c (string_to_cipher_algo, string_to_digest_algo): New. * keygen.c (keygen_set_std_prefs): use them here. * gpg.c (main): and here. 2006-05-23 Werner Koch * card-util.c (generate_card_keys): Removed temporary kludge for generate_keypair. * call-agent.c (agent_scd_setattr): Add arg SERIALNO. (agent_scd_genkey): Ditto. (agent_scd_change_pin): Ditto. * call-agent.h (struct agent_card_info_s): Updated to match the one of 1.4.3. * Makefile.am (LDADD): Include ZLIBS. * gpgv.c: Removed stubs not anymore useful due to libgcrypt. 2006-05-22 Werner Koch * keyserver.c (keyidlist): Replaced mpi_get_keyid by v3_keyid. * keydb.h (v3_keyid): Added. * import.c (import): Better initialize KEYBLOCK as to quiet compiler warning. * skclist.c (random_is_faked): New. * mainproc.c: Include pka.h. 2006-05-19 Werner Koch * misc.c (openpgp_pk_test_algo2): Need to use gcry_pk_algo_info directly. (string_count_chr): New. * armor.c (parse_header_line): Use renamed function length_sans_trailing_ws. * options.h, gpg.c: Option --strict is not used thus removed code but kept option. 2006-04-28 David Shaw (wk) * keyserver.c (direct_uri_map): New. (keyserver_spawn): Used here to add "_uri" to certain gpgkeys_xxx helpers when the meaning is different if a path is provided (i.e. ldap). (keyserver_import_cert): Show warning if there is a CERT fingerprint, but no --keyserver set. * keyserver.c: Fix build problem with platforms that stick libcurl in a place not in the regular include search path. * options.h, gpg.c (main): Add --enable-dsa2 and --disable-dsa2. Defaults to disable. * pkclist.c (algo_available): If --enable-dsa2 is set, we're allowed to truncate hashes to fit DSA keys. * sign.c (match_dsa_hash): New. Return the best match hash for a given q size. (do_sign, hash_for, sign_file): When signing with a DSA key, if it has q==160, assume it is an old DSA key and don't allow truncation unless --enable-dsa2 is also set. q!=160 always allows truncation since they must be DSA2 keys. (make_keysig_packet): If the user doesn't specify a --cert-digest-algo, use match_dsa_hash to pick the best hash for key signatures. * gpg.c (print_mds): Add SHA-224. * armor.c (armor_filter, parse_hash_header): Add SHA-224. * sign.c (write_plaintext_packet): Factor common literal packet setup code from here, to... * encode.c (encode_simple): .. there. * main.h, plaintext.c (setup_plaintext_name): Here. New. Make sure the literal packet filename field is UTF-8 encoded. * options.h, gpg.c (main): Make sure --set-filename is UTF-8 encoded and note when filenames are already UTF-8. * keyedit.c (menu_backsign): Give some more verbose errors when we have no need to backsign. * getkey.c (parse_auto_key_locate): Fix dupe-removal code. * keyedit.c (menu_backsign): Allow backsigning even if the secret subkey doesn't have a binding signature. * armor.c (radix64_read): Don't report EOF when reading only a pad (=) character. The EOF actually starts after the pad. * gpg.c (main): Make --export, --send-keys, --recv-keys, --refresh-keys, and --fetch-keys follow their arguments from left to right. Suggested by Peter Palfrader. 2006-04-18 Werner Koch * tdbio.c (open_db, migrate_from_v2): Removed feature to migration from old trustdb version 2. * gpg.c, mainproc.c: Removed pipemode feature. * status.c: Removed shared memory coprocess stuff Merged with current gpg 1.4.3 code. * keygen.c, keyid.c, misc.c, openfile.c, verify.c, trustdb.c * textfilter.c, tdbio.c, tdbdump.c, status.c, skclist.c, signal.c * sign.c, sig-check.c, seskey.c, seckey-cert.c, revoke.c * pubkey-enc.c, progress.c, plaintext.c, pkclist.c, photoid.c * passphrase.c, parse-packet.c, mdfilter.c, mainproc.c * keyserver.c, keyring.c, keylist.c, keyedit.c, keydb.c, kbnode.c * import.c, getkey.c, gpgv.c, helptext.c, free-packet.c * build-packet.c, cipher.c, compress.c, dearmor.c, decrypt.c * delkey.c, encr-data.c, encode.c, exec.c, export.c * gpg.c, armor.c: Updated from gnupg-1.4.3 and merged back gcry and gnupg-1.9 related changes. * trustdb.h, tdbio.h, status.h, photoid.h, packet.h, options.h * main.h, keyserver-internal.h, keyring.h, keydb.h, filter.h * exec.h: Ditto. * global.h: Removed after merging constants with gpg.h. * comment.c, pipemode.c: Removed. * card-util.c: Updated from gnupg-1.4.3. * compress-bz2.c: New. 2005-06-15 Werner Koch * g10.c (print_hashline, add_group): Fixes for signed/unsigned pointer mismatch warnings. 2005-06-01 Werner Koch * mkdtemp.c: Removed. * exec.c: Include mkdtemp.h 2004-12-21 Werner Koch * gpgv.c, g10.c (main): Use default_hoemdir (). 2004-12-18 Werner Koch * gpg.h (map_assuan_err): Define in terms of map_assuan_err_with_source. 2004-12-15 Werner Koch * Makefile.am (LDADD): Remove ZLIBS. 2004-10-22 Werner Koch * g10.c (main): Display a bit fat warning that this gpg should not be used. * card-util.c (fetch_url): Disable for gnupg 1.9 (card_generate_subkey): Ditto. (card_store_subkey): Ditto. 2004-09-30 Werner Koch * gpgv.c (i18n_init): Always use LC_ALL. * Makefile.am (LDADD): Adjusted for gettext 0.14. 2004-09-20 Werner Koch * keyedit.c (show_key_with_all_names): Print the card S/N. 2004-09-11 Moritz Schulte * openfile.c (copy_options_file): Fixed last commit (added a `+'). 2004-08-31 Werner Koch * openfile.c (copy_options_file): Use gpg-conf.skel. Better take the length of SKELEXT into account, someone might make it larger. * Makefile.am: Install options.skel as gpg-conf.skel. 2004-08-18 Marcus Brinkmann * passphrase.c (agent_get_passphrase): Fix detection of gpg-agent cancellation. 2004-07-01 Werner Koch * card-util.c (change_login): Kludge to allow reading data from a file. (card_edit): Pass ARG_STRING to change_login. (card_status): Print CA fingerprints. (change_cafpr): New. (card_edit): New command CAFPR. * call-agent.h: Add members for CA fingerprints. * call-agent.c (agent_release_card_info): Invalid them. (learn_status_cb): Store them. 2004-04-30 Werner Koch * g10.c (main) : Use gpg.conf and not /dev/null as default filename. 2004-04-28 Werner Koch * card-util.c (card_edit): Remove PIN verification. (generate_card_keys): New arg SERIALNO. Do PIN verification here after resetting forced_chv1. 2004-04-26 Werner Koch * card-util.c (change_name): Check that the NAME is not too long. (change_url): Likewise. (change_login): Likewise. 2004-03-23 Werner Koch * g10.c: New options --gpgconf-list, --debug-level and --log-file (set_debug): Add arg DEBUG_LEVEL. (main): Look at less and less version specific config files. From gnupg 1.3. 2004-02-17 Werner Koch * call-agent.c (start_agent): Ignore an empty GPG_AGENT_INFO. * passphrase.c (agent_open): Ditto. 2004-02-12 Werner Koch * gpgv.c: Removed g10defs.h. * Makefile.am: Include cmacros.am for common flags. 2004-02-11 Werner Koch * openfile.c (try_make_homedir): Use GNUPG_DEFAULT_HOMEDIR. * gpgv.c (main): Ditto. * g10.c (main): Ditto. 2004-01-19 Moritz Schulte * keygen.c (do_generate_keypair): Print member fname, instead of newfname, again. (do_generate_keypair): Don't try to execute certain pieces of code in case an error occured. (gen_card_key): Don't print out a message, which is already printed by do_generate_keypair(). 2004-01-18 Moritz Schulte * keygen.c (do_generate_keypair): Print member fname, instead of newfname. 2003-12-17 Werner Koch * card-util.c (print_name): Fixed bad format string usage. (print_isoname): Ditto. * trustdb.c (check_regexp): s/exp/expr/. * keyedit.c (trustsig_prompt): Removed a "> 255" term; it is always false due to the data type. * passphrase.c (agent_get_passphrase): Use xasprintf and avoid non-literal format strings. * tdbio.c (upd_hashtable, drop_from_hashtable, lookup_hashtable): Fixed log_error format string bugs. Kudos to the now working gcc-3.3 -Wformat-nonliteral and Florian Weimer's investigations in gnupg 1.2.3. 2003-12-15 Werner Koch * seckey-cert.c (protect_secret_key): Use gry_create_nonce for the IV; there is not need for real strong random here and it even better protect the random bits used for the key. 2003-11-16 Moritz Schulte * signal.c: Removed unused file. 2003-11-10 Moritz Schulte * Makefile.am (INCLUDES): Added: @LIBGCRYPT_CFLAGS@. 2003-10-25 Werner Koch * call-agent.c (learn_status_cb, scd_genkey_cb): Fixed faulty use of !spacep(). 2003-10-20 Werner Koch * card-util.c (card_edit): New command "passwd". Add logic to check the PIN in advance. (card_status): Add new args to return the serial number. Changed all callers. * call-agent.c (agent_scd_checkpin): New. 2003-10-08 Werner Koch * call-agent.c (agent_scd_getattr): Don't clear the passed info structure, so that it can indeed be updated. * card-util.c (fpr_is_zero): New. (generate_card_keys): New. (card_edit): New command "generate". * keygen.c (generate_keypair): New arg CARD_SERIALNO, removed call to check_smartcard. (check_smartcard,show_smartcard): Removed. (show_sha1_fpr,fpr_is_zero): Removed. 2003-10-01 Werner Koch * card-util.c: Tweaked to use this source also under 1.3. 2003-09-30 Werner Koch * keylist.c (print_card_serialno): New. (list_keyblock_print): Use it here. * card-util.c (toggle_forcesig): New. (card_edit): New command "forcesig". * card-util.c (print_name, print_isoname): Use 0 and not LF fro the max_n arg of tty_print_utf8_string2. * call-agent.c (agent_scd_getattr): New. (learn_status_cb): Release values before assignment so that it can be used by getattr to update the structure. * card-util.c (change_pin): Simplified. We now have only a PIN and an Admin PIN. 2003-09-27 Werner Koch * sign.c (do_sign): Removed disabled testcode. 2003-09-26 Timo Schulz * card_status (card_status): Do not use fputs since the fp parameter can be NULL. This fixes a segv. 2003-09-24 Werner Koch * card-util.c (print_isoname,card_status): Handle opt.with_colons. (print_sha1_fpr_colon): New. 2003-09-23 Werner Koch Merged most of David Shaw's changes in 1.3 since 2003-06-03. * Makefile.am: Include W32LIBS where appropriate. * armor.c (parse_hash_header,armor_filter): Drop TIGER/192 support. * g10.c (print_hex,print_mds): Ditto. * pkclist.c (algo_available): Ditto. * armor.c (armor_filter): Allow using --comment multiple times to get multiple Comment header lines. --no-comments resets list. * options.h, g10.c (main): Ditto. Deprecate --default-comment in favor of --no-comments. * g10.c (main): Trim --help to commonly used options. Remove -f. * g10.c (main): Add --multifile as an alias to turn --encrypt into --encrypt-files (plus --verify-files, --decrypt-files). Error out if --multifile is used with the commands that don't support it yet. * encode.c (use_mdc), g10.c (main): Use RFC1991 and RFC2440 directly to check for MDC usability. Do not set the force_mdc or disable_mdc flags since there is no point any longer. * g10.c (main): Use "keyserver-url" instead of "preferred-keyserver" for the sake of short and simple commands. (add_keyserver_url): Clarify a few strings. It's a "preferred keyserver URL". * keyedit.c (keyedit_menu): Ditto. * sign.c (mk_notation_policy_etc): Ditto. * main.h, keygen.c (keygen_add_keyserver_url): Signature callback for adding a keyserver URL. * keyedit.c (keyedit_menu, menu_set_keyserver_url): New command to set preferred keyserver to specified (or all) user IDs. * build-packet.c (build_sig_subpkt): Set preferred keyserver flag while building a preferred keyserver subpacket. * keylist.c (show_policy_url, show_keyserver_url): URLs might be UTF8. * keyedit.c (menu_addrevoker): Fix leaking a few bytes. * keyedit.c (show_key_with_all_names): Use list-option show-long-keyid in main --edit-key display. * keyedit.c (print_and_check_one_sig): Use list-option show-long-keyid in --edit-key "check" function. * passphrase.c (agent_send_all_options): Make use of $GPG_TTY. * g10.c (main): Disable use-agent if passphrase-fd is given later. Suggested by Kurt Garloff. * exec.c, g10.c, gpgv.c, passphrase.c, photoid.c: s/__MINGW32__/_WIN32/ to help building on native Windows compilers. Requested by Brian Gladman. From Werner on stable branch. * options.h, g10.c (main): Add list-option list-preferred-keyserver. * keyedit.c (change_passphrase): When responding 'no' to the blank passphrase question, re-prompt for a new passphrase. This is bug #202. * mainproc.c (check_sig_and_print): Use two different preferred keyserver displays - one if the key is not present (to tell the user where to get the key), the other if it is present (to tell the user where the key can be refreshed). * packet.h, parse-packet.c (parse_signature): Set flag if a preferred keyserver is present. * keylist.c (list_keyblock_print): Show keyserver url in listings with list-option show-keyserver-url. * mainproc.c (check_sig_and_print): Get the uid validity before printing any sig results to avoid munging the output with trustdb warnings. * g10.c (main): Don't include --show-keyring in --help as it is deprecated. * options.skel: Note that keyserver.pgp.com isn't synchronized, and explain the roundrobin a bit better. * sig-check.c (check_key_signature2), import.c (import_one, import_revoke_cert, chk_self_sigs, delete_inv_parts, collapse_uids, merge_blocks): Make much quieter during import of slightly munged, but recoverable, keys. Use log_error for unrecoverable import failures. * keyring.c (keyring_rebuild_cache): Comment. * sign.c (mk_notation_and_policy): Making a v3 signature with notations or policy urls is an error, not an info (i.e. increment the errorcount). Don't print the notation or policy url to stdout since it can be mixed into the output stream when piping and munge the stream. * packet.h, sig-check.c (signature_check2, do_check, do_check_messages): Provide a signing-key-is-revoked flag. Change all callers. * status.h, status.c (get_status_string): New REVKEYSIG status tag for a good signature from a revoked key. * mainproc.c (do_check_sig, check_sig_and_print): Use it here. * import.c (import_revoke_cert, merge_blocks, merge_sigs): Compare actual signatures on import rather than using keyid or class matching. This does not change actual behavior with a key, but does mean that all sigs are imported whether they will be used or not. * parse-packet.c (parse_signature): Don't give "signature packet without xxxx" warnings for experimental pk algorithms. An experimental algorithm may not have a notion of (for example) a keyid (i.e. PGP's x.509 stuff). * options.h, g10.c (main), keylist.c (list_keyblock_print), keyedit.c (print_and_check_one_sig): New "show-sig-expire" list-option to show signature expiration dates (if any). * options.h, g10.c (main, add_keyserver_url): Add --sig-preferred-keyserver to implant a "where to get my key" subpacket into a signature. * sign.c (mk_notation_and_policy): Rename to mk_notation_policy_etc and add preferred keyserver support for signatures. * keygen.c (do_add_key_flags): Don't set the certify flag for subkeys. (ask_algo): Provide key flags for DSA, Elgamal_e, and Elgamal subkeys. (generate_keypair): Provide key flags for the default DSA/Elgamal keys. * sig-check.c (signature_check, signature_check2, check_key_signature, check_key_signature2): Allow passing NULLs for unused parameters in the x2 form of each function to avoid the need for dummy variables. getkey.c, mainproc.c: Change all callers. * trustdb.h, trustdb.c (read_trust_options): New. Returns items from the trustdb version record. * keylist.c (public_key_list): Use it here for the new "tru" record. * gpgv.c (read_trust_options): Stub. * keyedit.c (show_key_with_all_names): Use list-option show-validity in --edit-key interface as well. * options.h, g10.c (main), mainproc.c (check_sig_and_print): Add verify-options "show-validity" and "show-long-keyid" to show trustdb validity and long keyids during (file) signature verification. * packet.h, main.h, sig-check.c (signature_check2) (check_key_signature2, do_check): If ret_pk is set, fill in the pk used to verify the signature. Change all callers in getkey.c, mainproc.c, and sig-check.c. * keylist.c (list_keyblock_colon): Use the ret_pk from above to put the fingerprint of the signing key in "sig" records during a --with-colons --check-sigs. This requires --no-sig-cache as well since we don't cache fingerprints. * parse-packet.c (parse_signature): No need to reserve 8 bytes for the unhashed signature cache any longer. * misc.c (pct_expando): Add two new expandos - signer's fingerprint (%g), and signer's primary fingerprint (%p). * g10.c (main): Add --rfc2440 alias for --openpgp since in a few months, they won't be the same thing. * keyserver.c (parse_keyserver_uri): Accept "http" as an alias for "hkp", since it is occasionally written that way. (keyserver_spawn): Use ascii_isspace to avoid locale issues. * keygen.c (ask_user_id): Make --allow-freeform-uid apply to the email field as well as the name field, and allow mixing fields when it is set. * trustdb.c (validate_one_keyblock): Certifications on revoked or expired uids do not count in the web of trust. * signal.c (init_one_signal, pause_on_sigusr, do_block): Only use sigprocmask() if we have sigset_t, and only use sigaction() if we have struct sigaction. This is for Forte c89 on Solaris which seems to define only the function call half of the two pairs by default. (pause_on_sigusr): Typo. (do_block): If we can't use sigprocmask() and sigset_t, try to get the number of signals from NSIG as well as MAXSIG, and if we can't, fail with an explanation. * signal.c, tdbio.c: Comment out the transaction code. It was not used in this version, and was causing some build problems on quasi-posix platforms (Solaris and Forte c89). * keylist.c (list_keyblock_colon): Don't include validity values when listing secret keys since they can be incorrect and/or misleading. This is a temporary kludge, and will be handled properly in 1.9/2.0. * mainproc.c (check_sig_and_print): Only show the "key available from" preferred keyserver line if the key is not currently present. * keyedit.c (sign_uids): Do not sign expired uids without --expert (same behavior as revoked uids). Do not allow signing a user ID without a self-signature. --expert overrides. Add additional prompt to the signature level question. (menu_expire): When changing expiration dates, don't replace selfsigs on revoked uids since this would effectively unrevoke them. There is also no point in replacing expired selfsigs. This is bug #181 * g10.c (add_notation_data): Make sure that only ascii is passed to iscntrl. Noted by Christian Biere. * getkey.c (classify_user_id2): Replaced isspace by spacep * keygen.c (ask_user_id): Ditto. (get_parameter_algo): Ditto. * keyedit.c (keyedit_menu): Ditto. * tdbdump.c (import_ownertrust): Ditto. s/isxdigit/hexdigitp/. * revoke.c (ask_revocation_reason): * keyserver.c (keyserver_spawn): Dito. * parse-packet.c (parse): Disallow old style partial length for all key material packets to avoid possible corruption of keyrings. * import.c (import_keys_internal): Invalidate the cache so that the file descriptor gets closed. Fixes bug reported by Juan F. Codagnone. * options.h, g10.c (main), main.h, keylist.c (show_keyserver_url), mainproc.c (check_sig_and_print), parse-packet.c (dump_sig_subpkt, parse_one_sig_subpkt, can_handle_critical): Add read-only support for preferred keyserver subpackets. They're basically policy URLs with a different name. Add a verify-option "show-preferred-keyserver" to turn them on and off (on by default, as per stable branch). * g10.c (main): Add "--set-notation" as alias to "--notation-data" this is to make things consistent with --set-policy-url meaning both sigs and certs. * options.h, g10.c (main), keylist.c (list_keyblock_print): Add "show-validity" and "show-long-keyid" list-options. * gpgv.c (get_validity, trust_value_to_string): Stubs. * g10.c (main): Use SAFE_VERSION instead of VERSION in the version-specific gpg.conf file so it can be overridden on RISCOS. * keyedit.c (show_key_with_all_names): Fix assertion failure when using toggle to see a secret key. Reported by Maxim Britov. 2003-09-22 Timo Schulz * card-util.c (card_status): Free pk in case of an error and return if the card is no OpenPGP card. 2003-09-18 Werner Koch * g10.c: New command --card-edit. * card-util.c (card_status): Use tty_fprintf for all output. (print_sha1_fpr, print_isoname): Ditto. (get_one_name,change_name, change_url, change_login,change_lang) (change_sex): New; taken from keygen.c. * keygen.c (smartcard_get_one_name, smartcard_change_name) (smartcard_change_url, smartcard_change_login_data) (smartcard_change_lang, smartcard_change_sex): Removed. (check_smartcard): Removed most menu items. 2003-09-06 Werner Koch * misc.c (openpgp_pk_algo_usage): Allow AUTH where SIGN is allowed. * keygen.c (ask_passphrase): No need to allocated S2K in secure memory. 2003-09-04 Werner Koch * keygen.c (do_add_key_flags, parse_parameter_usage) (do_generate_keypair): Add support the proposed AUTH key flag. * getkey.c (fixup_uidnode, merge_selfsigs_main) (merge_selfsigs_subkey, premerge_public_with_secret): Ditto. * keylist.c (print_capabilities): Ditto. 2003-08-25 Timo Schulz * pkglue.c (mpi_from_sexp): New. Used to factor out some common code. 2003-08-24 Werner Koch * keygen.c (do_generate_keypair): Print a reminder to use --gen-revoke. 2003-08-18 Timo Schulz * encode.c (encode_sesskey): Checked the code and removed the warning since all compatibility checks with PGP succeeded. * mainproc.c (symkey_decrypt_sesskey): Better check for the algorithm and check the return values of some functions. * mdc.c (use_mdc): Simplified. 2003-08-07 Werner Koch * pkglue.c (pk_sign): Fix last change. (pk_verify): Check for valid DATA array so that we don't segv in Libgcrypt. (pk_verify): Ditto. 2003-08-06 Werner Koch * pkglue.c (pk_sign): Allow signing using RSA. 2003-08-05 Werner Koch * Makefile.am (install-data-local): Dropped check for the ancient gpgm tool. (bin_PROGRAMS): Renamed gpg to gpg2 and gpgv to gpgv2. This is so that it won't conflict with the current stable version of gpg. * pkglue.c (pk_check_secret_key): New. * seckey-cert.c (do_check): Reenable this test here again. * g10.c (main): Add command -K as an alias for --list-secret-keys. Command "-k" is now an alias to --list-keys. Remove special treatment of -kv and -kvv. (set_cmd): Ditto. (main): Strip a "-cvs" suffix when testing for a version specific config file. * status.h, status.c, g10.c [USE_SHM_COPROCESSING]: Removed. This is not any longer available. 2003-07-29 Werner Koch * g10.c (main): Add secmem features and set the random seed file. (g10_exit): Update the random seed file. * parse-packet.c (parse_signature,read_protected_v3_mpi) (parse_key): Fixed use of mpi_set_opaque. * keygen.c (gen_card_key): Ditto. 2003-07-28 Werner Koch * status.c (progress_cb): Adjusted for use with Libcgrypt. (set_status_fd): Register that callback. * keygen.c (smartcard_change_login_data): New. (smartcard_change_lang): New. (smartcard_change_sex): New. (check_smartcard): Add menu entries to edit the above. (gen_elg,gen_dsa,gen_rsa): Reimplemented in terms of Libgcrypt. (genhelp_protect, genhelp_factors, key_from_sexp): New. * comment.c (make_comment_node_from_buffer): New. (make_comment_node): Reimplemented in terms of above. 2003-07-27 Werner Koch Adjusted for gcry_mpi_print and gcry_mpi_scan API change. 2003-07-24 Werner Koch * g10.c: New command --card-status. * card-util.c (card_status): New. * call-agent.c (learn_status_cb): Parse more information. * keylist.c (print_pubkey_info): Add FP arg for optional printing to a stream. Changed all callers. 2003-07-23 Werner Koch * keygen.c (generate_keypair): Create an AUTHKEYTYPE entry for cards. (do_generate_keypair): Abd generate the authkey. (check_smartcard): Changed menu accordingly. 2003-07-22 Werner Koch * g10.c: New command --change-pin. * card-util.c: New. * call-agent.c (agent_scd_change_pin): New. (agent_release_card_info): New. * keygen.c (check_smartcard): Use it here. 2003-07-16 Werner Koch * export.c (parse_export_options): New option sexp-format. (export_seckeys,export_secsubkeys): Check sexp-format option. (do_export): Ignore armor for sexp format. (do_export_stream): Handle sexp-format. (write_sexp_line,write_sexp_keyparm, build_sexp_seckey): New. (build_sexp): New. 2003-07-03 Werner Koch * options.h (DBG_CIPHER): Reintroduced it. * seskey.c (encode_session_key): Debug output of the session key. * pubkey-enc.c (get_it): Handle card case. * call-agent.c (agent_scd_pkdecrypt): New. * pkglue.c (pk_encrypt): Add RSA support. * g10.c (main): Default to --use-agent. * keygen.c (show_smartcard): Print info about the public key. (check_smartcard): Check for existing key here. (gen_card_key): And not anymore here. (fpr_is_zero): New. (generate_keypair): Generate both keys for a card. (smartcard_change_url): Nw. 2003-07-02 Werner Koch * seckey-cert.c (is_secret_key_protected): Let it handle mode 1002. 2003-07-01 Werner Koch * keygen.c (gen_card_key): Obviously we should use the creation date received from SCDAEMON, so that the fingerprints will match. * sign.c (do_sign): Pass the serialno to the sign code. * keyid.c (serialno_and_fpr_from_sk): New. 2003-06-30 Werner Koch * call-agent.h (agent_card_info_s): Add field serialno. * call-agent.c (store_serialno): New. (learn_status_cb): Store the serial number. * keygen.c (gen_card_key): Store the serial number (check_smartcard): New argument to return the serial number. (generate_keypair): Get the serial number from check_smartcard and store it as a parameter. * parse-packet.c (parse_key): Use the protect.iv field to store the serial number. * build-packet.c (do_secret_key): Write the serial number. 2003-06-27 Werner Koch * seckey-cert.c (check_secret_key): Bypass the unprotection for mode 1002. * sign.c (do_sign): Handle card case (i.e. mode 1002). 2003-06-26 Werner Koch * build-packet.c (do_secret_key): Implement special protection mode 1002. * parse-packet.c (parse_key): Likewise. * keygen.c (smartcard_gen_key): New. * call-agent.c (agent_scd_setattr): New. 2003-06-24 Werner Koch * Makefile.am: Removed signal.c * g10.c (emergency_cleanup): New. (main): Use gnupg_init_signals and register malloc for assuan. 2003-06-23 Werner Koch * keyid.c (do_fingerprint_md): Made it work again. 2003-06-19 Werner Koch Fixed all "==" comparisons against error code constants to use gpg_err_code(). * import.c (import_secret_one): (import_revoke_cert): (chk_self_sigs): * misc.c (openpgp_md_map_name): Check also for the Hx format. (openpgp_cipher_map_name): Check also for the Sx format. (pubkey_get_npkey): Adjusted for changed gcrypt API. (pubkey_get_nskey): Ditto. (pubkey_get_nsig): Ditto. (pubkey_get_nenc): Ditto. 2003-06-18 Werner Koch Finished the bulk of changes for gnupg 1.9. This included switching to libgcrypt functions, using shared error codes from libgpg-error, replacing the old functions we used to have in ../util by those in ../jnlib and ../common, renaming the malloc functions and a couple of types. Note, that not all changes are listed below becuause they are too similar and done at far too many places. As of today the code builds using the current libgcrypt from CVS but it is very unlikely that it actually works. * sig-check.c (cmp_help): Removed. Was never used. * pkglue.c: New. Most stuff taken from gnupg 1.1.2. * pkglue.h: New. * misc.c (pull_in_libs): Removed. * keygen.c (count_chr): New. (ask_user_id): Removed faked RNG support. * misc.c (openpgp_md_map_name,openpgp_cipher_map_name) (openpgp_pk_map_name): New. * skclist.c (build_sk_list): Removed faked RNG support. (is_insecure): Removed. * comment.c (make_mpi_comment_node): Use gcry MPI print function. * keyid.c (v3_keyid): New. * misc.c (mpi_write,mpi_write_opaque,mpi_read,mpi_read_opaque) (mpi_print): New. Taken from gnupg 1.1.2. (checksum_mpi): Replaced by implementation from 1.1.2. * g10.c (my_strusage): Renamed from strusage and return NULL instead calling a default function. (add_to_strlist2): New. Taken from ../util/strgutil.c of gnupg 1.2. * plaintext.c (handle_plaintext): New arg CREATE_FILE to cope with the fact that gpg-error does not have this error code anymore. * mainproc.c (symkey_decrypt_sesskey): Ditto. * seskey.c (make_session_key): Adjusted for use with libgcrypt. (encode_session_key): Ditto. (do_encode_md): Ditto. (encode_md_value): Ditto. * keyring.c: Use libgpg-error instead of READ_ERROR etc. * g10.c: Adjusted all algorithm name/id mapping functions. (set_debug): Pass MPI and CRYPTO debug values to libgcrypt. * Makefile.am (INCLUDES): Define LOCALEDIR and the default error source. * g10.c (i18n_init): s/G10_LOCALEDIR/LOCALEDIR/. Renamed m_alloc et al to xmalloc et al. s/g10_errstr/gpg_strerror/ s/MPI/gcry_mpi_t/ Adjusted all md_open calls to the libgcrypt API. * build-packet.c (do_comment): Return error code from iobuf write function. (do_user_id): Ditto. (do_public_key): Ditto. * Makefile.am: Add new files, link gpg with libgpg-error. * g10.c, options.h: New option --agent-program. * call-agent.c: New. * gpg.h, call-agent.h: New. 2003-06-03 David Shaw * options.h, g10.c (main), keylist.c (list_keyblock_print): Add "show-validity" and "show-long-keyid" list-options. * gpgv.c (get_validity, trust_value_to_string): Stubs. * g10.c (main): Use SAFE_VERSION instead of VERSION in the version-specific gpg.conf file so it can be overridden on RISCOS. 2003-06-01 David Shaw * g10.c (main), keylist.c (show_policy_url, show_notation), mainproc.c (check_sig_and_print): Emulate the old policy and notation behavior (display by default). Send to status-fd whether it is displayed on the screen or not. * g10.c (main): Since we now have some options in devel that won't work in a stable branch gpg.conf file, try for a version-specific gpg.conf-VERSION file before falling back to gpg.conf. * main.h, options.h: Move various option flags to options.h. 2003-05-31 David Shaw * mainproc.c (check_sig_and_print), main.h, keylist.c (show_policy, show_notation): Collapse the old print_notation_data into show_policy() and show_notation() so there is only one function to print notations and policy URLs. * options.h, main.h, g10.c (main), keyedit.c (print_and_check_one_sig), keylist.c (list_one, list_keyblock_print), pkclist.c (do_edit_ownertrust), sign.c (mk_notation_and_policy): New "list-options" and "verify-options" commands. These replace the existing --show-photos/--no-show-photos, --show-notation/--no-show-notation, --show-policy-url/--no-show-policy-url, and --show-keyring options. The new method is more flexible since a user can specify (for example) showing photos during sig verification, but not in key listings. The old options are emulated. * main.h, misc.c (parse_options): New general option line parser. Fix the bug in the old version that did not handle report syntax errors after a valid entry. * import.c (parse_import_options), export.c (parse_export_options): Call it here instead of duplicating the code. 2003-05-30 David Shaw * keylist.c (list_one): Don't show the keyring filename when in --with-colons mode. Actually translate "Keyring" string. * mainproc.c (proc_tree): We can't currently handle multiple signatures of different classes or digests (we'd pretty much have to run a different hash context for each), but if they are all the same, make an exception. This is Debian bug #194292. * sig-check.c (check_key_signature2): Make string translatable. * packet.h, getkey.c (fixup_uidnode): Mark real primary uids differently than assumed primaries. * keyedit.c (no_primary_warning): Use the differently marked primaries here in a new function to warn when an --edit-key command might rearrange the self-sig dates enough to change which uid is primary. (menu_expire, menu_set_preferences): Use no_primary_warning() here. * Makefile.am: Use @DLLIBS@ for -ldl. 2003-05-26 David Shaw * getkey.c (premerge_public_with_secret): Made "no secret subkey for" warning a verbose item and translatable. (From wk on stable branch) * sig-check.c (check_key_signature2): Made "no subkey for subkey binding packet" a verbose item instead of a !quiet one. There are too many garbled keys out in the wild. (From wk on stable branch) * filter.h: Remove const from WHAT. (From wk on stable branch) * progress.c (handle_progress): Store a copy of NAME. (progress_filter): Release WHAT, make sure not to print a NULL WHAT. (From wk on stable branch) * openfile.c (open_sigfile): Adjust free for new progress semantics. (From wk on stable branch) * plaintext.c (ask_for_detached_datafile): Don't dealloc pfx->WHAT. (From wk on stable branch) * seckey-cert.c (do_check): Issue the RSA_OR_IDEA status when the cipher algo is IDEA to make it easier to track down the problem. (From twoaday on stable branch) 2003-05-24 David Shaw * armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c, getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c, options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c, signal.c, textfilter.c: Edit all preprocessor instructions to remove whitespace before the '#'. This is not required by C89, but there are some compilers out there that don't like it. 2003-05-21 David Shaw * trustdb.h, trustdb.c (is_disabled), gpgv.c (is_disabled): Rename is_disabled to cache_disabled_value, which now takes a pk and not just the keyid. This is for speed since there is no need to re-fetch a key when we already have that key handy. Cache the result of the check so we don't need to hit the trustdb more than once. * getkey.c (skip_disabled): New function to get a pk and call is_disabled on it. (key_byname): Use it here. * packet.h, getkey.c (skip_disabled), keylist.c (print_capabilities): New "pk_is_disabled" macro to retrieve the cached disabled value if available, and fill it in via cache_disabled_value if not available. * trustdb.c (get_validity): Cache the disabled value since we have it handy and it might be useful later. * parse-packet.c (parse_key): Clear disabled flag when parsing a new key. Just in case someone forgets to clear the whole key. * getkey.c (merge_selfsigs_main): Add an "if all else fails" path for setting a single user ID primary when there are multiple set primaries all at the same second, or no primaries set and the most recent user IDs are at the same second, or no signed user IDs at all. This is arbitrary, but deterministic. * exec.h, photoid.h: Add copyright message. * keylist.c (list_keyblock_print): Don't dump attribs for revoked/expired/etc uids for non-colon key listings. This is for consistency with --show-photos. * main.h, keylist.c (dump_attribs), mainproc.c (check_sig_and_print): Dump attribs if --attrib-fd is set when verifying signatures. * g10.c (main): New --gnupg option to disable the various --openpgp, --pgpX, etc. options. This is the same as --no-XXXX for those options. * revoke.c (ask_revocation_reason): Clear old reason if user elects to repeat question. This is bug 153. * keyedit.c (sign_uids): Show keyid of the key making the signature. 2003-05-21 Werner Koch * progress.c (handle_progress) * sign.c (write_plaintext_packet) * encode.c (encode_simple,encode_crypt): Make sure that a filename of "-" is considered to be stdin so that iobuf_get_filelength won't get called. This fixes bug 156 reported by Gregery Barton. 2003-05-02 David Shaw * packet.h, build-packet.c (build_sig_subpkt), export.c (do_export_stream), import.c (remove_bad_stuff, import), parse-packet.c (dump_sig_subpkt, parse_one_sig_subpkt): Remove vestigal code for the old sig cache subpacket. This wasn't completely harmless as it caused subpacket 101 to disappear on import and export. * options.h, armor.c, cipher.c, g10.c, keyedit.c, pkclist.c, sign.c, encode.c, getkey.c, revoke.c: The current flags for different levels of PGP-ness are massively complex. This is step one in simplifying them. No functional change yet, just use a macro to check for compliance level. * sign.c (sign_file): Fix bug that causes spurious compression preference warning. * sign.c (clearsign_file): Fix bug that prevents proper warning message from appearing when clearsigning in --pgp2 mode with a non-v3 RSA key. * main.h, misc.c (compliance_option_string, compliance_string, compliance_failure), pkclist.c (build_pk_list), sign.c (sign_file, clearsign_file), encode.c (encode_crypt, write_pubkey_enc_from_list): New functions to put the "this message may not be usable...." warning in one place. * options.h, g10.c (main): Part two of the simplification. Use a single enum to indicate what we are compliant to (1991, 2440, PGPx, etc.) * g10.c (main): Show errors for failure in export, send-keys, recv-keys, and refresh-keys. * options.h, g10.c (main): Give algorithm warnings for algorithms chosen against the --pgpX and --openpgp rules. * keydb.h, pkclist.c (algo_available): Make TIGER192 invalid in --openpgp mode. * sign.c (sign_file), pkclist.c (algo_available): Allow passing a hint of 0. 2003-05-01 David Shaw * tdbio.c (create_version_record): Only create new trustdbs with TM_CLASSIC or TM_PGP. * trustdb.h, trustdb.c (trust_string, get_ownertrust_string, get_validity_string, ask_ownertrust, validate_keys), pkclist.c (do_edit_ownertrust): Rename trust_string to trust_value_to_string for naming consistency. * trustdb.h, trustdb.c (string_to_trust_value): New function to translate a string to a trust value. * g10.c (main): Use string_to_trust_value here for --force-ownertrust. * options.h, g10.c (main), trustdb.c (trust_model_string, init_trustdb, check_trustdb, update_trustdb, get_validity, validate_one_keyblock): An "OpenPGP" trust model is misleading since there is no official OpenPGP trust model. Use "PGP" instead. 2003-04-30 David Shaw * build-packet.c (build_sig_subpkt): Comments. * exec.c (exec_write): Cast NULL to void* to properly terminate varargs list. * keyedit.c (show_key_with_all_names): Just for safety, catch an invalid pk algorithm. * sign.c (make_keysig_packet): Crucial that the call to mksubpkt comes LAST before the calls to finalize the sig as that makes it possible for the mksubpkt function to get a reliable pointer to the subpacket area. * pkclist.c (do_we_trust_pre): If an untrusted key was chosen by a particular user ID, use that ID as the one to ask about when prompting whether to use the key anyway. (build_pk_list): Similar change here when adding keys to the recipient list. * trustdb.c (update_validity): Fix bug that prevented more than one validity record per trust record. (get_validity): When retrieving validity for a (user) supplied user ID, return the validity for that user ID only, and do not fall back to the general key validity. (validate_one_keyblock): Some commentary on whether non-self-signed user IDs belong in the web of trust (arguably, they do). 2003-04-27 David Shaw * g10.c (main): Add --no-textmode. * export.c (do_export_stream), keyedit.c (show_key_with_all_names, menu_addrevoker), mainproc.c (check_sig_and_print), photoid.c (show_photos), sign.c (mk_notation_and_policy), trustdb.c (get_validity, reset_trust_records, validate_keys): Make some strings translatable. * mainproc.c (check_sig_and_print): Show digest algorithm and sig class when verifying a sig with --verbose on, and add version, pk and hash algorithms and sig class to VALIDSIG. * parse-packet.c (enum_sig_subpkt): Make a warning message a --verbose warning message since we don't need to warn every time we see an unknown critical (we only need to invalidate the signature). * trustdb.c (init_trustdb): Check the trustdb options even with TM_AUTO since the auto may become TM_CLASSIC or TM_OPENPGP. 2003-04-26 David Shaw * sign.c (do_sign): Show the hash used when making a signature in verbose mode. * tdbio.h, tdbio.c (tdbio_read_model): New function to return the trust model used in a given trustdb. * options.h, g10.c (main), trustdb.c (init_trustdb, check_trustdb, update_trustdb): Use tdbio_read_model to implement an "auto" trust model which is set via the trustdb. 2003-04-23 David Shaw * import.c (import_revoke_cert): Remove ultimate trust when revoking an ultimately trusted key. * keyedit.c (sign_uids): Allow replacing expired signatures. Allow duplicate signatures with --expert. * pkclist.c (check_signatures_trust): Don't display a null fingerprint when checking a signature with --always-trust enabled. * filter.h (progress_filter_context_t), progress.c (handle_progress), plaintext.c (ask_for_detached_datafile, hash_datafiles): Fix compiler warnings. Make "what" constant. * build-packet.c (do_plaintext): Do not create invalid literal packets with >255-byte names. 2003-04-15 Werner Koch * Makefile.am (AM_CFLAGS): Make use of AM_CFLAGS and AM_LDFLAGS. * g10.c, options.h: New option --enable-progress-filter. * progress.c (handle_progress): Make use of it. 2003-04-15 Marcus Brinkmann * progress.c: New file. * Makefile.am (common_source): Add progress.c. * filter.h (progress_filter_context_t): New type. (progress_filter, handle_progress): New prototypes. * main.h (open_sigfile): New argument for prototype. * openfile.c (open_sigfile): New argument to install progress filter. * encode.c (encode_simple): New variable PFX. Register progress filter. Install text_filter after that. (encode_crypt): Likewise. * sign.c (sign_file): Likewise. (clearsign_file): Likewise. * decrypt.c (decrypt_message): Likewise. (decrypt_messages): Likewise. * verify.c (verify_signatures): Likewise. (verify_one_file): Likewise. * plaintext.c (hash_datafiles): Likewise. (ask_for_detached_datafile): Likewise. 2003-04-10 Werner Koch * passphrase.c (read_passphrase_from_fd): Do a dummy read if the agent is to be used. Noted by Ingo Klöcker. (agent_get_passphrase): Inhibit caching when we have no fingerprint. This is required for key generation as well as for symmetric only encryption. * passphrase .c (agent_get_passphrase): New arg CANCELED. (passphrase_to_dek): Ditto. Passed to above. Changed all callers to pass NULL. * seckey-cert.c (do_check): New arg CANCELED. (check_secret_key): Terminate loop when canceled. * keyedit.c (change_passphrase): Pass ERRTEXT untranslated to passphrase_to_dek and translate where appropriate. * seckey-cert.c (check_secret_key): Ditto. * keygen.c (ask_passphrase): Ditto. * passphrase.c (agent_get_passphrase): Translate the TRYAGAIN_TEXT. Switch the codeset to utf-8. 2003-04-09 Werner Koch * decrypt.c (decrypt_messages): Fixed error handling; the function used to re-loop with same file after an error. Reported by Joseph Walton. 2003-04-08 David Shaw * main.h, g10.c (main), import.c (parse_import_options, fix_pks_corruption): It's really PKS corruption, not HKP corruption. Keep the old repair-hkp-subkey-bug command as an alias. * g10.c (main): Rename --no-version to --no-emit-version for consistency. Keep --no-version as an alias. 2003-04-04 David Shaw * pkclist.c (algo_available): PGP 8 can use the SHA-256 hash. * sign.c (sign_file, clearsign_file, sign_symencrypt_file): Remove unused code. 2003-04-01 Werner Koch * mainproc.c (check_sig_and_print): Add primary key fpr to VALIDSIG status. 2003-03-24 David Shaw * keydb.h: Err on the side of making an unknown signature a SIG rather than a CERT. * import.c (delete_inv_parts): Discard any key signatures that aren't key types (i.e. 0x00, 0x01, etc.) * g10.c (main): Add deprecated option warning for --list-ownertrust. Add --compression-algo alias for --compress-algo. Change --version output strings to match "showpref" strings, and make translatable. * status.c (do_get_from_fd): Accept 'y' as well as 'Y' for --command-fd boolean input. * trustdb.c: Fix typo (DISABLE_REGEXP -> DISABLE_REGEX) * keyedit.c (show_key_with_all_names_colon): Show no-ks-modify flag. 2003-03-11 David Shaw * options.h, g10.c (main), keyserver.c (kopts): Add "try-dns-srv" keyserver option. Defaults to on. * passphrase.c (agent_get_passphrase): Fix memory leak with symmetric messages. Fix segfault with symmetric messages. Fix incorrect prompt with symmetric messages. 2003-03-10 Werner Koch * compress.c (init_uncompress): Use a 15 bit window size so that the output of implementations which don't run for PGP 2 compatibility won't get garbled. 2003-03-04 David Shaw * trustdb.c (validate_keys): Mask the ownertrust when building the list of fully valid keys so that disabled keys are still counted in the web of trust. (get_ownertrust_with_min): Do the same for the minimum ownertrust calculation. * parse-packet.c (dump_sig_subpkt): Show the notation names for not-human-readable notations. Fix cosmetic off-by-one length counter. * options.skel: Add explantion and commented-out "no-mangle-dos-filenames". * mainproc.c (proc_encrypted): Make string translatable. * keyserver.c (keyserver_spawn): Quote ':', '%', and any 8-bit characters in the uid strings sent to the keyserver helper. * keyring.c (keyring_rebuild_cache): Lock the keyring while rebuilding the signature caches to prevent another gpg from tampering with the temporary copy. * keygen.c (keygen_set_std_prefs): Include AES192 and AES256 in default prefs. * keyedit.c (show_prefs): Make strings translatable. * keydb.c: Double the maximum number of keyrings to 40. * gpgv.c (main): Fix bug #113 - gpgv should accept the --ignore-time-conflict option. * g10.c (main): --openpgp disables --pgpX. Double the amount of secure memory to 32k (keys are getting bigger these days). * Makefile.am: Makefile.am: Use @CAPLIBS@ to link in -lcap if we are using capabilities. 2003-02-26 David Shaw * keyserver.c (keyserver_spawn): Include various pieces of information about the key in the data sent to the keyserver helper. This allows the helper to use it in instructing a remote server which may not have any actual OpenPGP smarts in parsing keys. * main.h, export.c (export_pubkeys_stream, do_export_stream): Add ability to return only the first match in an exported keyblock for keyserver usage. This should be replaced at some point with a more flexible solution where each key can be armored seperately. 2003-02-22 David Shaw * sign.c (sign_file): Do not push textmode filter onto an unopened IOBUF (segfault). Noted by Marcus Brinkmann. Push and reinitialize textmode filter for each file in a multiple file list. * packet.h, getkey.c (fixup_uidnode), keyedit.c (show_prefs): Set and show the keyserver no-modify flag. * keygen.c (add_keyserver_modify): New. (keygen_upd_std_prefs): Call it here. (keygen_set_std_prefs): Accept "ks-modify" and "no-ks-modify" as prefs to set and unset keyserver modify flag. * g10.c (main): Accept "s1" in addition to "idea" to match the other ciphers. * main.h, misc.c (idea_cipher_warn): We don't need this if IDEA has been disabled. 2003-02-21 David Shaw * keygen.c (keygen_set_std_prefs): Don't put AES or CAST5 in default prefs if they are disabled. * g10.c (main): Use 3DES instead of CAST5 if we don't have CAST5 support. Use 3DES for the s2k cipher in --openpgp mode. (print_mds): #ifdef all of the optional digest algorithms. 2003-02-12 David Shaw * keydb.h, getkey.c (classify_user_id, classify_user_id2): Make 'exact' a per-desc item. Merge into one function since 'force_exact' is no longer needed. (key_byname): Use new classify_user_id function, and new exact flag in KEYDB_SEARCH_DESC. * keyring.h, keyring.c (keyring_search): Return an optional index to show which KEYDB_SEARCH_DESC was the matching one. * keydb.h, keydb.c (keydb_search): Rename to keydb_search2, and pass the optional index to keyring_search. Add a macro version of keydb_search that calls this new function. * export.c (do_export_stream): If the keyid! syntax is used, export only that specified key. If the key in question is a subkey, export the primary plus that subkey only. 2003-02-11 David Shaw * exec.c (set_exec_path): Add debugging line. * g10.c (print_hex, print_mds): Print long hash strings a lot neater. This assumes at least an 80-character display, as there are a few other similar assumptions here and there. Users who need unformatted hashes can still use with-colons. Check that SHA384 and 512 are available before using them as they are no longer always available. * Makefile.am: Use a local copy of libexecdir along with @PACKAGE@ as GNUPG_LIBEXECDIR so it can be easily overridden at make time. 2003-02-04 David Shaw * armor.c (parse_hash_header, armor_filter): Accept the new SHAs in the armor Hash: header. * g10.c (print_hex): Print long hash strings a little neater. (print_mds): Add the new SHAs to the hash list. 2003-02-02 David Shaw * keyedit.c (menu_revuid): Properly handle a nonselfsigned uid on a v4 key (treat as a v4 revocation). * import.c (print_import_check): Do not re-utf8 convert user IDs. 2003-01-27 David Shaw * mainproc.c (list_node): Show signature expiration date in with-colons sig records. * keylist.c (list_keyblock_colon), mainproc.c (list_node): Show trust sig information in with-colons sig records. 2003-01-16 David Shaw * g10.c (add_group): Trim whitespace after a group name so it does not matter where the user puts the = sign. * options.skel: Comment out the first three lines in case someone manually copies the skel file to their homedir. * sign.c (clearsign_file): Only use pgp2mode with v3 keys and MD5. This matches what we do when decoding such messages and prevents creating a message (v3+RIPEMD/160) that we can't verify. * sig-check.c (signature_check2): Use G10ERR_GENERAL as the error for signature digest conflict. BAD_SIGN implies that a signature was checked and we may try and print out a user ID for a key that doesn't exist. 2003-01-15 David Shaw * trustdb.c (init_trustdb, get_validity): Don't use a changed trust model to indicate a dirty trustdb, and never auto-rebuild a dirty trustdb with the "always" trust model. * g10.c (add_group): Last commit missed the \t ;) 2003-01-14 David Shaw * packet.h, parse-packet.c (setup_user_id), free-packet.c (free_user_id), keydb.h, keyid.c (namehash_from_uid): New function to rmd160-hash the contents of a user ID packet and cache it in the uid object. * keylist.c (list_keyblock_colon): Use namehash in field 8 of uids. Show dates for creation (selfsig date), and expiration in fields 6 and 7. * trustdb.c (get_validity, get_validity_counts, update_validity): Use new namehash function rather than hashing it locally. 2003-01-14 Werner Koch * g10.c (add_group): Fixed group parsing to allow more than one delimiter in a row and also allow tab as delimiter. 2003-01-12 David Shaw * tdbio.c (tdbio_set_dbname): Fix assertion failure with non-fully-qualified trustdb names. 2003-01-11 David Shaw * trustdb.c (get_validity_info, get_ownertrust_info, trust_letter): Simplify by returning a ? for error directly. * keyedit.c (show_key_with_all_names): Use get_validity_string and get_ownertrust_string to show full word versions of trust (i.e. "full" instead of 'f'). * trustdb.h, trustdb.c (get_ownertrust_string, get_validity_string): Same as get_ownertrust_info, and get_validity_info, except returns a full string. * trustdb.c (get_ownertrust_with_min): New. Same as 'get_ownertrust' but takes the min_ownertrust value into account. 2003-01-10 David Shaw * armor.c (armor_filter): Comment about PGP's end of line tab problem. * trustdb.h, trustdb.c (trust_letter): Make static. (get_ownertrust_info, get_validity_info): Don't mask the trust level twice. * trustdb.h, gpgv.c, trustdb.c (get_validity, get_validity_info), keylist.c (list_keyblock_colon), keyedit.c (show_key_with_all_names_colon, menu_revuid): Pass a user ID in rather than a namehash, so we only have to do the hashing in one place. * packet.h, pkclist.c (build_pk_list), free-packet.c (release_public_key_parts): Remove unused namehash element for public keys. 2003-01-07 David Shaw * keygen.c (keygen_set_std_prefs): Warn when setting an IDEA preference when IDEA is not available. 2003-01-06 David Shaw * trustdb.c (get_validity_info): 'd' for disabled is not a validity value any more. * packet.h, tdbio.h, tdbio.c (tdbio_read_record, tdbio_write_record), trustdb.c (update_validity): Store temporary full & marginal counts in the trustdb. (clear_validity, get_validity_counts): Return and clear temp counts. (store_validation_status): Keep track of which keyids have been stored. (validate_one_keyblock, validate_key_list): Use per-uid copies of the full & marginal counts so they can be recalled for multiple levels. (validate_keys): Only use unused keys for each new round. (reset_unconnected_keys): Rename to reset_trust_records, and only skip specifically excluded records. * keylist.c (print_capabilities): Show 'D' for disabled keys in capabilities section. * trustdb.c (is_disabled): Remove incorrect comment. 2003-01-03 David Shaw * import.c (import_one): Only do the work to create the status display for interactive import if status is enabled. * keyring.c (keyring_search): skipfnc didn't work properly with non-keyid searches. Noted by Stefan Bellon. * getkey.c (merge_selfsigs_main): Remove some unused code and make sure that the pk selfsigversion member accounts for 1F direct sigs. 2003-01-02 Werner Koch * keydb.c (keydb_add_resource): Don't assume that try_make_homedir terminates but check again for the existence of the directory and continue then. * openfile.c (copy_options_file): Print a warning if the skeleton file has active options. 2002-12-29 David Shaw * getkey.c (merge_selfsigs_main), main.h, sig-check.c (check_key_signature2): Pass the ultimately trusted pk directly to check_key_signature2 to avoid going through the key selection mechanism. This prevents a deadly embrace when two keys without selfsigs each sign the other. 2002-12-27 David Shaw * keyserver.c (keyserver_refresh): Don't print the "refreshing..." line if there are no keys to refresh or if there is no keyserver set. * getkey.c (merge_selfsigs_main): Any valid user ID should make a key valid, not just the last one. This also fixes Debian bug #174276. 2002-12-27 Stefan Bellon * import.c (print_import_check): Changed int to size_t. 2002-12-27 David Shaw * keyedit.c (keyedit_menu, menu_revuid): Add "revuid" feature to revoke a user ID. This is the same as issuing a revocation for the self-signature, but a much simpler interface to do it. 2002-12-26 David Shaw * keydb.h, getkey.c (key_byname): Flag to enable or disable including disabled keys. Keys specified via keyid (i.e. 0x...) are always included. * getkey.c (get_pubkey_byname, get_seckey_byname2, get_seckey_bynames), keyedit.c (keyedit_menu, menu_addrevoker): Include disabled keys in these functions. * pkclist.c (build_pk_list): Do not include disabled keys for -r or the key prompt. Do include disabled keys for the default key and --encrypt-to. * trustdb.h, trustdb.c (is_disabled): New skipfnc for skipping disabled keys. * gpgv.c (is_disabled): Stub. * keygen.c (keygen_add_key_expire): Properly handle updating a key expiration to a no-expiration value. * keyedit.c (enable_disable_key): Comment. * import.c (import_one): When in interactive mode and --verbose, don't repeat some key information twice. 2002-12-22 Timo Schulz * import.c (print_import_check): New. (import_one): Use it here. Use merge_keys_and_selfsig in the interactive mode to avoid wrong key information. * status.h: Add new status code. * status.c: Ditto. 2002-12-13 David Shaw * pkclist.c (do_we_trust): Tweak language to refer to the "named user" rather than "owner". Noted by Stefan Bellon. * trustdb.h, trustdb.c (trustdb_pending_check): New function to check if the trustdb needs a check. * import.c (import_keys_internal): Used here so we don't rebuild the trustdb if it is still clean. (import_one, chk_self_sigs): Only mark trustdb dirty if the key that is being imported has any sigs other than self-sigs. Suggested by Adrian von Bidder. * options.skel: Include the required '=' sign in the sample 'group' option. Noted by Stefan Bellon. * import.c (chk_self_sigs): Don't try and check a subkey as if it was a signature. 2002-12-11 David Shaw * tdbio.c (tdbio_read_record, tdbio_write_record): Compact the RECTYPE_TRUST records a bit. * g10.c (main): Comment out --list-trust-path until it can be implemented. * import.c (import_one): Warn when importing an Elgamal primary that this may take some time (to verify self-sigs). (chk_self_sigs): Try and cache all self-sigs so the keyblock is written to the keyring with a good rich cache. * keygen.c (ask_algo): Make the Elgamal sign+encrypt warning stronger, and remove the RSA sign+encrypt warning. 2002-12-06 Stefan Bellon * options.h: Fixed typo (mangle_dos_names instead of mangle_dos_filenames). 2002-12-05 Werner Koch * g10.c: New options --[no-]mangle-dos-filenames. * options.h (opt): Added mangle-dos-filenames. * openfile.c (open_outfile) [USE_ONLY_8DOT3]: Truncate the filename only when this option is set; this is the default. 2002-12-04 David Shaw * main.h, keyedit.c, keygen.c: Back out previous (2002-12-01) change. Minimal isn't always best. * sign.c (update_keysig_packet): Use the current time rather then a modification of the original signature time. Make sure that this doesn't cause a time warp. * keygen.c (keygen_add_key_expire): Properly handle a key expiration date in the past (use a duration of 0). * keyedit.c (menu_expire): Use update_keysig_packet so any sig subpackets are maintained during the update. * build-packet.c (build_sig_subpkt): Mark sig expired or unexpired when the sig expiration subpacket is added. (build_sig_subpkt_from_sig): Handle making an expiration subpacket from a sig that has already expired (use a duration of 0). * packet.h, sign.c (update_keysig_packet), keyedit.c (menu_set_primary_uid, menu_set_preferences): Add ability to issue 0x18 subkey binding sigs to update_keysig_packet and change all callers. * trustdb.c (validate_keys): Show trust parameters when building the trustdb, and make sure that the version record update was successful. (init_trustdb): If the current parameters aren't what was used for building the trustdb, the trustdb is invalid. * tbio.c (tdbio_db_matches_options): Update to work with new trustdbs. 2002-12-03 David Shaw * tdbio.h, tdbio.c (tdbio_read_record, tdbio_write_record): Store trust model in the trustdb version record. (tdbio_update_version_record): New function to update version record values during a trustdb check or update. (tdbio_dump_record): Show trust model in dump. * trustdb.c (validate_keys): Call tdbio_update_version_record on success so that the correct options are stored in the trustdb. * options.h: rearrange trust models so that CLASSIC is 0 and OPENPGP is 1. * options.h, g10.c (main), encode.c (write_pubkey_enc_from_list), pkclist.c (algo_available), revoke.c (gen_revoke): Add --pgp8 mode. This is basically identical to --pgp7 in all ways except that signing subkeys, v4 data sigs (including expiration), and SK comments are allowed. * getkey.c (finish_lookup): Comment. * main.h, keylist.c (reorder_keyblock), keyedit.c (keyedit_menu): Reorder user ID display in the --edit-key menu to match that of the --list-keys display. * g10.c (add_notation_data): Fix initialization. 2002-12-01 David Shaw * keyedit.c (menu_expire): Don't lose key flags when changing the expiration date of a subkey. This is not the most optimal solution, but it is minimal change on the stable branch. * main.h, keygen.c (do_copy_key_flags): New function to copy key flags, if any, from one sig to another. (do_add_key_expire): New function to add key expiration to a sig. (keygen_copy_flags_add_expire): New version of keygen_add_key_expire that also copies key flags. (keygen_add_key_flags_and_expire): Use do_add_key_expire. * import.c (fix_hkp_corruption): Comment. 2002-11-25 Stefan Bellon * plaintext.c (handle_plaintext) [__riscos__]: If nooutput is set, no filetype is needed obviously. 2002-11-24 David Shaw * main.h, misc.c (default_cipher_algo, default_compress_algo): New. Return the default algorithm by trying --cipher-algo/--compress-algo, then the first item in the pref list, then s2k-cipher-algo or ZIP. * sign.c (sign_file, sign_symencrypt_file), encode.c (encode_simple, encode_crypt): Call default_cipher_algo and default_compress_algo to get algorithms. * g10.c (main): Allow pref selection for compress algo with --openpgp. * mainproc.c (proc_encrypted): Use --s2k-digest-algo for passphrase mangling rather than --digest-algo. * sign.c (hash_for): If --digest-algo is not set, but --personal-digest-preferences is, then use the first hash algorithm in the personal list. If the signing algorithm is DSA, then use the first 160-bit hash algorithm in the personal list. If --pgp2 is set and it's a v3 RSA key, use MD5. * g10.c (main), keydb.c (keydb_add_resource, keydb_locate_writable): Rename --default-keyring as --primary-keyring. Stefan wins the naming contest. 2002-11-23 David Shaw * g10.c (add_notation_data): Disallow notation names that do not contain a '@', unless --expert is set. This is to help prevent people from polluting the (as yet unused) IETF namespace. * main.h: Comments about default algorithms. * photoid.c (image_type_to_string): Comments about 3-letter file extensions. * encode.c (encode_simple), passphrase.c (passphrase_to_dek), sign.c (sign_symencrypt_file): Use --s2k-digest-algo for passphrase mangling rather than --digest-algo. 2002-11-21 David Shaw * keygen.c (keygen_set_std_prefs): Properly handle an empty preference string. * misc.c (string_to_compress_algo): "none" is a bad choice since it conflicts with the "none" in setpref. 2002-11-14 David Shaw * g10.c (main): Allow compression algorithm names as the argument to --compress-algo. The old algorithm names still work for backwards compatibility. * misc.c (string_to_compress_algo): Allow "none" as an alias for "uncompressed". 2002-11-13 Stefan Bellon * getkey.c (get_pubkey_byfprint_fast): Fixed type incompatibility, was unsigned char instead of byte. 2002-11-13 David Shaw * encode.c (encode_simple): Make sure that files larger than about 4G use partial length encoding. This is required because OpenPGP allows only for 32 bit length fields. From Werner on stable branch. * getkey.c (get_pubkey_direct): Renamed to... (get_pubkey_fast): this and made extern. (get_pubkey_byfprint_fast): New. From Werner on stable branch. * keydb.h, import.c (import_one): Use get_pubkey_fast instead of get_pubkey. We don't need a merged key and actually this might lead to recursions. (revocation_present): Likewise for search by fingerprint. From Werner on stable branch. * g10.c (main): Try to create the trustdb even for non-colon-mode list-key operations. This is required because getkey needs to know whether a a key is ultimately trusted. From Werner on stable branch. * exec.c [__CYGWIN32__]: Keep cygwin separate from Mingw32; we don't need it here as it behaves more like a Posix system. From Werner on stable branch. * passphrase.c (agent_get_passphrase): Ditto. From Werner on stable branch. * tdbio.c (MY_O_BINARY): Need binary mode with Cygwin. From Werner on stable branch. * g10.c, gpgv.c (main) [__CYGWIN32__]: Don't get the homedir from the registry. From Werner on stable branch. * keyedit.c (show_key_with_all_names_colon): Make --with-colons --edit display match the validity and trust of --with-colons --list-keys. * passphrase.c (agent_send_all_options): Fix compile warning. * keylist.c (list_keyblock_colon): Validity for subkeys should match that of the primary key, and not that of the last user ID. * getkey.c (merge_selfsigs): Revoked/expired/invalid primary keys carry these facts onto all their subkeys, but only after the subkey has a chance to be marked valid. This is to fix an incorrect "invalid public key" error verifying a signature made by a revoked signing subkey, with a valid unrevoked primary key. 2002-11-09 Werner Koch * passphrase.c (agent_send_all_options): Use tty_get_ttyname to get the default ttyname. 2002-11-07 David Shaw * keyring.h, keyring.c (keyring_register_filename): Return the pointer if a given keyring is registered twice. * keydb.h, keydb.c (keydb_add_resource): Use flags to indicate a default keyring. (keydb_locate_writable): Prefer the default keyring if possible. * g10.c (main): Add --default-keyring option. 2002-11-06 David Shaw * options.h, g10.c (main), trustdb.c (ask_ownertrust): Add --force-ownertrust option for debugging purposes. This allows setting a whole keyring to a given trust during an --update-trustdb. Not for normal use - it's just easier than hitting "4" all the time to test a large trustdb. * pubkey-enc.c (get_session_key): With hidden recipients or try a given passphrase against all secret keys rather than trying all secret keys in turn. Don't if --try-all-secrets or --status-fd is enabled. * passphrase.c (passphrase_to_dek): Mode 1 means do a regular passphrase query, but don't prompt with the key info. * seckey-cert.c (do_check, check_secret_key): A negative ask count means to enable passphrase mode 1. * keydb.h, getkey.c (enum_secret_keys): Add flag to include secret-parts-missing keys (or not) in the list. 2002-11-05 David Shaw * keyserver.c (keyserver_search_prompt): When --with-colons is enabled, don't try and fit the search output to the screen size - just dump the whole list. 2002-11-04 David Shaw * keyserver.c (keyserver_search_prompt): When --with-colons is enabled, just dump the raw keyserver protocol to stdout and don't print the menu. * keyserver.c (show_prompt): Don't show a prompt when command-fd is being used. * trustdb.c (trust_model_string, check_trustdb, update_trustdb, validate_one_keyblock): It's not clear what a trustdb rebuild or check means with a trust model other than "classic" or "openpgp", so disallow this. 2002-11-03 David Shaw * options.h, g10.c (main): Add --trust-model option. Current models are "openpgp" which is classic+trustsigs, "classic" which is classic only, and "always" which is the same as the current option --always-trust (which still works). Default is "openpgp". * trustdb.c (validate_one_keyblock): Use "openpgp" trust model to enable trust sigs. * gpgv.c (main), mainproc.c (check_sig_and_print), pkclist.c (do_we_trust, do_we_trust_pre, check_signatures_trust): Use new --trust-model option in place of --always-trust. * keyedit.c (sign_mk_attrib, trustsig_prompt, sign_uids, keyedit_menu): Prompt for and create a trust signature with "tsign". This is functional, but needs better UI text. * build-packet.c (build_sig_subpkt): Able to build trust and regexp subpackets. * pkclist.c (do_edit_ownertrust): Comment. 2002-11-02 David Shaw * keygen.c (set_one_pref, keygen_set_std_prefs): Allow using the full algorithm name (CAST5, SHA1) rather than the short form (S3, H2). * main.h, keygen.c (keygen_get_std_prefs), keyedit.c (keyedit_menu): Return and use a fake uid packet rather than a string since we already have a nice parser/printer in keyedit.c:show_prefs. * main.h, misc.c (string_to_compress_algo): New. 2002-11-01 David Shaw * g10.c (main): Add --no-throw-keyid. * keydb.h, encode.c (write_pubkey_enc_from_list), g10.c (main), pkclist.c (build_pk_list): Add --hidden-recipient (-R) and --hidden-encrypt-to, which do a single-user variation on --throw-keyid. The "hide this key" flag is carried in bit 0 of the pk_list flags field. * keyserver.c (parse_keyrec): Fix shadowing warning. 2002-10-31 Stefan Bellon * compress.c (init_compress) [__riscos__]: Use riscos_load_module() to load ZLib module. * g10.c (main) [__riscos__]: Renames due to changes in riscos.c (e.g. prefixes all RISC OS specific functions with riscos_*). * photoid.c (show_photos) [__riscos__]: Likewise. * signal.c (got_fatal_signal) [__riscos__]: Likewise. * trustdb.c (check_regexp) [__riscos__]: Branch to RISC OS RegEx handling. 2002-10-31 David Shaw * build-packet.c (do_plaintext), encode.c (encode_sesskey, encode_simple, encode_crypt), sign.c (write_plaintext_packet): Use wipememory() instead of memset() to wipe sensitive memory as the memset() might be optimized away. 2002-10-30 David Shaw * trustdb.c (check_regexp): Modern regexps require REG_EXTENDED. 2002-10-29 David Shaw * packet.h, trustdb.h, trustdb.c (trust_string): New. Return a string like "fully trusted", "marginally trusted", etc. (get_min_ownertrust): New. Return minimum ownertrust. (update_min_ownertrust): New. Set minimum ownertrust. (check_regexp): New. Check a regular epression against a user ID. (ask_ownertrust): Allow specifying a minimum value. (get_ownertrust_info): Follow the minimum ownertrust when returning a letter. (clear_validity): Remove minimum ownertrust when a key becomes invalid. (release_key_items): Release regexp along with the rest of the info. (validate_one_keyblock, validate_keys): Build a trust sig chain while validating. Call check_regexp for regexps. Use the minimum ownertrust if the user does not specify a genuine ownertrust. * pkclist.c (do_edit_ownertrust): Only allow user to select a trust level greater than the minimum value. * parse-packet.c (can_handle_critical): Can handle critical trust and regexp subpackets. * trustdb.h, trustdb.c (clear_ownertrusts), delkey.c (do_delete_key), import.c (import_one): Rename clear_ownertrust to clear_ownertrusts and have it clear the min_ownertrust value as well. * keylist.c (list_keyblock_print): Indent uid to match pub and sig. * keyedit.c (print_and_check_one_sig, show_key_and_fingerprint, menu_addrevoker), keylist.c (list_keyblock_print, print_fingerprint): Show "T" or the trust depth for trust signatures, and add spaces to some strings to make room for it. * packet.h, parse-packet.c (dump_sig_subpkt, parse_one_sig_subpkt, parse_signature): Parse trust signature values. * tdbio.h, tdbio.c (tdbio_read_record, tdbio_write_record): Reserve a byte for the minimum ownertrust value (for use with trust signatures). 2002-10-29 Stefan Bellon * build-packet.c (calc_plaintext, do_plaintext): Removed RISC OS specific filetype parts (it's now done in make_basename()). * plaintext.c (handle_plaintext): Tidied up RISC OS specific filetype parts. * encode.c (encode_simple, encode_crypt): Added argument to make_basename() call. * sign.c (write_plaintext_packet): Added argument to make_basename() call. 2002-10-28 Stefan Bellon * build-packet.c (calc_plaintext, do_plaintext): Added filetype handling for RISC OS' file types. * plaintext.c (handle_plaintext) [__riscos__]: Added filetype handling for RISC OS' file types. 2002-10-23 David Shaw * main.h, import.c (sec_to_pub_keyblock, import_secret_one, parse_import_options), g10.c (main): New import-option "convert-sk-to-pk" to convert a secret key into a public key during import. It is on by default. 2002-10-23 Werner Koch * pubkey-enc.c (get_it): Fix segv, test for revoked only when PK has been assigned. 2002-10-18 Timo Schulz * keylist.c: (print_pubkey_info): New. (print_seckey_info): New. * main.h: Prototypes for the new functions. * delkey.c (do_delete_key): Use it here. * revoke.c (gen_desig_revoke): Ditto. 2002-10-17 Werner Koch * pkclist.c (do_edit_ownertrust): Show all user IDs. This should be enhanced to also show the current trust level. Suggested by Florian Weimer. 2002-10-17 David Shaw * g10.c (main): Handle --strict and --no-strict from the command line before the options file is loaded. 2002-10-15 David Shaw * g10.c (main): Disable --textmode when encrypting (symmetric or pk) in --pgp2 mode as PGP 2 can't handle the unknown length literal packet. Reported by Michael Richardson. 2002-10-14 David Shaw * keyserver-internal.h, keyserver.c (print_keyrec, parse_keyrec, show_prompt, keyserver_search_prompt, keyserver_spawn): Go to version 1 of the keyserver protocol. This is a better design, similar to --with-colons, that allows for keys with multiple user IDs rather than using multiple keys. It also matches the machine readable pksd format. Also use a prettier --search-keys listing format that can fill different size windows (currently set at 24 lines). 2002-10-12 Werner Koch * keygen.c (print_status_key_created): New. (do_generate_keypair): Use it to print the fingerprint. (generate_subkeypair): Likewise. 2002-10-11 David Shaw * keyedit.c (menu_addrevoker): Properly back out if the signature fails. Also, do not allow appointing the same revoker twice, and report ALREADY_SIGNED if the user tries it. 2002-10-07 David Shaw * import.c (import_keys_internal): Missed one s/inp/inp2/. * keylist.c (print_capabilities): Properly indicate per-key capabilities of sign&encrypt primary keys that have secret-parts-missing (i.e. no capabilities at all) * mainproc.c (symkey_decrypt_sesskey): Fix compiler warning. 2002-10-04 David Shaw * getkey.c (get_pubkey_direct): Don't cache keys retrieved via this function as they may not have all their fields filled in. * sig-check.c (signature_check2): Use new is_primary flag to check rather than comparing main_keyid with keyid as this still works in the case of a not fully filled in pk. 2002-10-04 Werner Koch * import.c (import_keys_internal): s/inp/inp2/ to avoid shadowing warning. * passphrase.c (agent_get_passphrase): Fixed signed/unsigned char problem in %-escaping. Noted by Ingo Klöcker. 2002-10-03 David Shaw * options.h, g10.c (main): Add --strict and --no-strict to switch the log_warning severity level from info to error. * keylist.c (print_capabilities): Secret-parts-missing keys should show that fact in the capabilities, and only primary signing keys can certify other keys. * packet.h, parse_packet.c (parse_key): Add is_primary flag for public keys (it already exists for secret keys). 2002-10-02 David Shaw * import.c (import_secret_one): Check for an illegal (>110) protection cipher when importing a secret key. * keylist.c (list_keyblock_print): Show a '#' for a secret-parts-missing key. * parse_packet.c (parse_key): Some comments. * revoke.c (gen_revoke): Remove some debugging code. * trustdb.c (verify_own_keys): Make trusted-key a non-deprecated option again. * seckey-cert.c (do_check): Don't give the IDEA warning unless the cipher in question is in fact IDEA. 2002-10-01 David Shaw * import.c (import_one): Make sure that a newly imported key starts with a clean ownertrust. 2002-10-01 Werner Koch * getkey.c (get_pubkey_direct): New. (merge_selfsigs_main): Use it here to look for an ultimately trusted key. Using the full get_pubkey might lead to an infinitive recursion. 2002-09-29 David Shaw * keyserver.c (parse_keyserver_uri): Force the keyserver URI scheme to lowercase to be case-insensitive. 2002-09-28 David Shaw * export.c (do_export_stream): Comment. * sig-check.c (check_key_signature2): Properly handle a non-designated revocation import. 2002-09-26 Werner Koch * g10.c (set_homedir): New. Changed all direct assignments to use this. * gpgv.c (set_homedir): Ditto. 2002-09-25 David Shaw * Makefile.am: Link gpg with EGDLIBS (i.e. NETLIBS) as EGD uses sockets. Remove the old NETLIBS variable since the keyserver stuff is no longer internal. 2002-09-24 David Shaw * import.c (import_keys_stream): Fix compiler type warning. * keyring.c (keyring_rebuild_cache), sig-check.c (check_key_signature2), import.c (import, chk_self_sigs): Minor language cleanups. 2002-09-23 Stefan Bellon * main.h: Introduced fast-import as import option. Removed fast as separate option from prototypes. * import.c (parse_import_options): Added fast-import option. (import_*): Removed fast as separate option. * g10.c (main): Added option fast-import, removed old fast as separate argument. * keyserver.c (keyserver_spawn): Removed old fast as separate argument. 2002-09-22 Stefan Bellon * import.c (import_keys, import_keys_stream, import_keys_internal): Added trustdb update/check to key import if not fast-import and interactive set/no-auto-check-trustdb unset. Avoided function clone by introducing import_keys_internal. 2002-09-19 David Shaw * keyserver.c (keyserver_spawn): Properly handle line truncation. Don't leak memory (~10-20 bytes) on searches. (keyserver_search_prompt): Cleanup. * keylist.c (list_keyblock_colon): Show 1F direct key signatures in --with-colons listing. 2002-09-16 David Shaw * keyedit.c (menu_addrevoker): The direct key signature for revocation keys must be at least v4 to carry the revocation key subpacket. Add a PGP 2.x warning for revocation keys. 2002-09-14 David Shaw * g10.c (check_permissions): Rearrange strings to make translating easier (don't incorporate string parts). * keyedit.c (sign_uids): Make strings translatable. * sig-check.c (check_key_signature2): Make string translatable. 2002-09-13 David Shaw * getkey.c (check_revocation_keys): Move.... * main.h, sig-check.c (check_revocation_keys): to here. Also return the signature_check error code rather than 0/1 and cache the sig result. * sig-check.c (check_key_signature2): Divert to check_revocation_keys if a revocation sig is made by someone other than the pk owner. * getkey.c (merge_selfsigs_main): Tidy. 2002-09-13 Werner Koch * g10.c (main) [__MINGW32__]: Activate oLoadExtension. 2002-09-12 David Shaw * Makefile.am, hkp.c, hkp.h, keyserver.c (keyserver_work): Remove internal HKP support. * keyserver.c (keyserver_spawn): Remove whitespace after keyserver commands. 2002-09-10 David Shaw * exec.c (expand_args): Remove loop left over from earlier implementation. (exec_write): Missed one tick. 2002-09-10 Werner Koch * g10.c, options.h: Removed option --emulate-checksum-bug. * misc.c (checksum_u16_nobug): Removed. (checksum_u16): Removed the bug emulation. (checksum_mpi): Ditto. (checksum_mpi_counted_nbits): Removed and replaced all calls with checksum_mpi. * parse-packet.c (read_protected_v3_mpi): New. (parse_key): Use it here to store it as an opaque MPI. * seckey-cert.c (do_check): Changed the v3 unprotection to the new why to store these keys. (protect_secret_key): Likewise. * build-packet.c (do_secret_key): And changed the writing. * tdbio.c (tdbio_set_dbname, open_db): Use new macro MY_O_BINARY to avoid silly ifdefs. (open_db): Fallback to RDONLY so that gpg may be used from a RO-medium. * encode.c (encode_simple): Make sure we don't use an ESK packet when we don't have a salt in the S2K. * misc.c (pct_expando) : Make sure that LEN is initialized. * exec.c (exec_finish): Use ticks to denote filenames in messages. (make_tempdir, exec_write): Changed format of messages. * keyserver.c (print_keyinfo): Release USERID in on error. (keyserver_work) [!DISABLE_KEYSERVER_HELPERS]: Exclude the unused code. 2002-09-09 Werner Koch * parse-packet.c (make_attribute_uidname): Add new ar MAX_NAMELEN for sanity checks. Changed both callers. Limit the size of an %s. * options.skel: Comment lock-once out, so that this file does not change anything when copied to a new home directory. * openfile.c (try_make_homedir): Don't exit after copying the option skeleton. * options.h: Don't use a comma when declaring variables over more than one line. * mainproc.c (symkey_decrypt_sesskey): Check length of the session key. * hkp.c (dehtmlize): Use ascii_tolower to protect against weird locales. Cast the argument for isspace for the sake of broken HP/UXes. (parse_hkp_index): s/ascii_memcasecmp/ascii_strncasecmp/. * g10.c: Removed option --emulate-3des-s2k-bug. * passphrase.c (hash_passphrase): Was used here. * export.c (parse_export_options) * keyserver.c (parse_keyserver_options) * import.c (parse_import_options) * g10.c (check_permissions): s/ascii_memcasecmp/ascii_strncasecmp/. 2002-09-09 David Shaw * g10.c (add_group): Use '=' to separate group name from group members. Use a better error message for when no = is found. * hkp.c (hkp_export): Use CRLF in headers. 2002-09-03 David Shaw * mainproc.c (print_pkenc_list): Don't increment the error counter when printing the list of keys a message was encrypted to. This would make gpg give a non-zero exit code even for completely valid messages if the message was encrypted to more than one key that the user owned. 2002-09-02 Werner Koch * g10.c (main): Try to set a default character set. Print the used one in verbosity level 3. * gpgv.c (main): Try to set a default character set. * status.c, status.h (STATUS_IMPORT_OK): New. * import.c (import_one,import_secret_one): Print new status. 2002-08-30 David Shaw * pkclist.c (build_pk_list): Add new status code to indicate an untrusted user. This (or a disabled key) fail with "unavailable pubkey" (G10ERR_UNU_PUBKEY). * pkclist.c (build_pk_list): Fail if any recipient keys are unusable. * options.skel: The PGP LDAP keyserver is back. Use MIT keyserver as a sample rather than cryptnet as cryptnet does not support searching yet. * keyedit.c (show_key_with_all_names): Fix error message (preferences are userid/selfsig and not key specific). 2002-08-30 Werner Koch * pkclist.c (do_we_trust_pre): Changed the wording of a warning. * encode.c (encode_simple,encode_crypt): Use new style CTB for compressssed packets when using MDC. We need to do this so that concatenated messages are properly decrypted. Old style compression assumes that it is the last packet; given that we can't determine the length in advance, the uncompressor does not know where to start. Actually we should use the new CTB always but this would break PGP 2 compatibility. * parse-packet.c (parse): Special treatment for new style CTB compressed packets. * build-packet.c (do_mdc): Removed. Was not used. (do_encrypted_mdc): Count in the version number and the MDC packet. 2002-08-28 David Shaw * sig-check.c (do_check_messages, do_check): Show keyid in error messages. * keyserver.c (print_keyinfo): More readable key listings for --search-keys responses. 2002-08-26 David Shaw * hkp.c (parse_hkp_index, dehtmlize): Move HTML functionality into new "dehtmlize" function. Remove HTML before trying to parse each line from the keyserver. If the keyserver provides key type information in the listing, use it. 2002-08-23 David Shaw * sig-check.c (do_check, do_check_messages): Emit the usual sig warnings even for cached sigs. This also serves to protect against missing a sig expiring while cached. * getkey.c (merge_selfsigs_main): Don't check UID self-sigs twice. 2002-08-22 David Shaw * import.c (clean_subkeys, chk_self_sigs): Merge clean_subkeys into chk_self_sigs. This improves efficiency as the same signatures are not checked multiple times. Clarify when a subkey is revoked (any revocation signature, even if it is dated before the binding signature). * getkey.c (merge_selfsigs_subkey): Subkey revocation comments. * keylist.c (list_one): Stats are only for public key listings. * g10.c (main), options.skel: Default should be include-revoked for keyserver operations. 2002-08-21 Werner Koch * import.c (import_print_stats): Print new non_imported counter which is currently not used because we terminate on errors. 2002-08-20 David Shaw * options.skel: Document no-include-attributes for keyserver-options. * keylist.c, keyedit.c, keyserver.c, sign.c: Some TODOs and comments. * export.c (do_export_stream): Fix noop bug in exporting sensitive revocation keys. * pkclist.c (do_edit_ownertrust): Comment out the option for showing trust paths until it can be implemented. 2002-08-19 Werner Koch * getkey.c (get_user_id_native): Renamed to .. (get_user_id_printable): this. Filter out all dangerous characters. Checked all usages. (get_user_id_string_native): Renamed to.. (get_user_id_string_printable): this. Filter out all dangerous characters. Checked all usages. * keyedit.c (show_basic_key_info): New. * keylist.c (print_fingerprint): New mode 3. * import.c (import_one): Use new function to display the user ID. 2002-08-16 Timo Schulz * g10.c (main): Enable opt.interactive. * import.c (import_one): Ask the user if the key shall be imported when the interactive mode is used. Useful to extract selected keys from a file. 2002-08-16 Werner Koch * seckey-cert.c: Workaround to allow decryption of v3 keys created with a bug in the mpi_get_secure_buffer. 2002-08-14 David Shaw * hkp.c (parse_hkp_index): Properly handle really large keys (5 digit key length) in HKP searches. 2002-08-13 David Shaw * encode.c (encode_simple): Fix problem with using compression algo 2 and symmetric compressed files. * encode.c (encode_simple, encode_crypt): If we are not using a MDC, compress even if a file is already compressed. This is to help against the chosen ciphertext attack. * pkclist.c (select_algo_from_prefs): Fix requested algorithm bug so the request succeeds even if the requested algorithm is not the first found. * cipher.c (write_header), encode.c (use_mdc, encode_simple, encode_crypt, encrypt_filter), g10.c (main): Be more eager to use a MDC. We use a MDC if the keys directly support it, if the keys list AES (any) or TWOFISH anywhere in the prefs, or if the cipher chosen does not have a 64 bit blocksize. 2002-08-08 David Shaw * options.skel: Some language tweaks, and remove the load-extension section for random gatherers. * keyring.c (create_tmp_file, rename_tmp_file): Create tmp files with user-only permissions, but restore the original permissions if the user has something special set. * openfile.c (copy_options_file): Create new options file (gpg.conf) with user-only permissions. * keydb.c (keydb_add_resource): Create new keyrings with user-only permissions. * tdbio.c (tdbio_set_dbname): Create new trustdbs with user-only permissions. 2002-08-07 David Shaw * sig-check.c (signature_check2): Sanity check that the md has a context for the hash that the sig is expecting. This can happen if a onepass sig header does not match the actual sig, and also if the clearsign "Hash:" header is missing or does not match the actual sig. * keyedit.c (menu_revsig): Properly show a uid is revoked without restarting gpg. This is Debian bug 124219, though their supplied patch will not do the right thing. * main.h, tdbio.c (tdbio_set_dbname), misc.c (removed check_permissions), keydb.c (keydb_add_resource), g10.c (main, check_permissions): Significant reworking of the permission check mechanism. The new behavior is to check everything in the homedir by checking the homedir itself. If the user wants to put (possibly shared) keyrings outside the homedir, they are not checked. The options file and any extension files are checked wherever they are, as well as their enclosing directories. This is Debian bug 147760. 2002-08-06 Stefan Bellon * g10.c (main): Use of EXTSEP_S in new gpg.conf string. * openfile.c (copy_options_file): Ditto. 2002-08-06 David Shaw * options.h, g10.c (main), mainproc.c (proc_encrypted): --ignore-mdc-error option to turn a MDC check error into a warning. * encode.c (encode_crypt), g10.c (main), sign.c (sign_file, clearsign_file): Use the same --pgpX warning string everywhere to ease translations. * encode.c (write_pubkey_enc_from_list): Warn when using --throw-keyid with --pgpX. Noted by Vedaal Nistar. * revoke.c (export_minimal_pk, gen_desig_revoke, gen_revoke): Export a minimal pk along with the revocation cert when in --pgpX mode so that PGP can import it. 2002-08-06 Werner Koch * options.skel: Changed comments. * g10.c (main): Try to use "gpg.conf" as default option file. * openfile.c (copy_options_file): Changed name of created file. 2002-08-02 Werner Koch * Makefile.am (LDFLAGS): Removed DYNLINK_LDFLAGS. 2002-07-30 David Shaw * options.h, g10.c (main), mainproc.c (proc_encrypted): Return a decryption failed error if a MDC does not verify. Warn if a MDC is not present (can disable via --no-mdc-warning). * exec.c (exec_write), g10.c (main), keyserver.c (keyserver_spawn): Use new DISABLE_KEYSERVER_PATH rather than FIXED_EXEC_PATH. 2002-07-28 David Shaw * sig-check.c (do_check): Properly validate v4 sigs with no hashed section at all. 2002-07-25 Werner Koch * delkey.c (do_delete_key): Always allow to delete a key in batch mode when specified by fingerprint. Suggested by Enzo Michelangeli. 2002-07-25 David Shaw * keyedit.c (menu_revsig): Change "revsig" to honor selected uids so the user can revoke sigs from particular uids only. * keylist.c (list_keyblock_print): Don't display expired uids in --list-keys unless -v and not --list-sigs (just like revoked uids). * exec.c, export.c, import.c, keyedit.c, keyserver.c, misc.c: "Warning" -> "WARNING" 2002-07-24 David Shaw * main.h, import.c (parse_import_options, fix_hkp_corruption, import_one, delete_inv_parts), g10.c (main): New import-option "repair-hkp-subkey-bug", which repairs as much as possible the HKP mangling multiple subkeys bug. It is on by default for keyserver receives, and off by default for regular --import. * main.h, import.c (import, import_one, delete_inv_parts), hkp.c (hkp_ask_import), keyserver.c (keyserver_spawn): Use keyserver import options when doing keyserver receives. * options.h, exec.h, exec.c (set_exec_path, exec_write), g10.c (main), keyserver.c (keyserver_spawn): If the user does not use "exec-path", completely replace $PATH with GNUPG_LIBEXECDIR before calling the keyserver helper. If the user does use "exec-path", append GNUPG_LIBEXECDIR after the specified path. 2002-07-23 David Shaw * import.c (parse_import_options), export.c (parse_export_options): Fix offset problem with reversed ("no-") meanings. * import.c (delete_inv_parts): Discard subkey signatures (0x18 and 0x28) if found in the userid section of the key. * sig-check.c (signature_check2): Signatures made by invalid subkeys (bad/missing binding sig) are also invalid. * keylist.c (print_fingerprint): Show the primary as well as the secondary key fingerprint in modes 1 & 2. 2002-07-22 David Shaw * options.h, main.h, g10.c (main), import.c (parse_import_options, delete_inv_parts), keyserver.c (parse_keyserver_options): add new --import-options option. The only current flag is "allow-local-sigs". * g10.c (main): Don't disable MDC in pgp7 mode. * options.h, g10.c (main), keyserver.c (parse_keyserver_options): Remove old keyserver-option include-attributes now that there is an export-option for the same thing. * options.h, main.h, export.c (parse_export_options, do_export_stream), g10.c (main): add new --export-options option. Current flags are "include-non-rfc", "include-local-sigs", "include-attributes", and "include-sensitive-revkeys". * options.h, hkp.c (hkp_export), keyserver.c (parse_keyserver_options, keyserver_spawn): try passing unknown keyserver options to export options, and if successful, use them when doing a keyserver --send-key. * build-packet.c (build_sig_subpkt): We do not generate SIGSUBPKT_PRIV_VERIFY_CACHE anymore. * revoke.c (gen_desig_revoke): Lots more comments about including sensitive revkeys along with the revocation sig itself. * keyserver.c (parse_keyserver_options): Simpler implementation that can skip one pass over the options. 2002-07-18 David Shaw * keyedit.c (keyedit_menu, menu_addrevoker): Allow specifying "sensitive" as an argument to an addrevoker command. This sets the 0x40 sensitive revoker flag. * revoke.c (gen_desig_revoke): When generating a designated revocation, include the direct key sig that contains the designated revoker subpacket. This allows sensitive designated revocation subpackets to be exported. Also indicate which revokers are sensitive in the first place. 2002-07-17 David Shaw * keyedit.c (show_key_with_all_names_colon): The 0x40 class bit in a designated revoker means "sensitive", not "local". It's exportable under the right circumstances. * main.h, options.h, export.c (do_export_stream), g10.c (main), hkp.c (hkp_export), keyserver.c (keyserver_spawn: Add a flag to skip attribute packets and their signatures while exporting. This is to accomodate keyservers (pksd again) that choke on attributes. Use keyserver-option "include-attributes" to control it. This defaults to ON (i.e. don't skip). 2002-07-09 David Shaw * options.h, keyserver.c (parse_keyserver_uri, keyserver_spawn, keyserver_work), hkp.c (hkp_ask_import, hkp_export, hkp_search): Use a much more strict reading of RFC-2396 for the keyserver URIs. Specifically, don't try and be smart about checking the value of ":port" so long as it is all digits, and properly handle opaque data (those scheme specific parts that do not start with "//"). 2002-07-04 David Shaw * photoid.c (get_default_photo_command, show_photos): Honor FIXED_PHOTO_VIEWER and DISABLE_PHOTO_VIEWER. * mainproc.c (check_sig_and_print): Use --show-photos to show photos when verifying a sig made by a key with a photo. * keyserver.c (parse_keyserver_uri): Properly parse a URI with no :port section and an empty file path, but with a terminating '/'. (keyserver_work): Honor DISABLE_KEYSERVER_HELPERS. * hkp.c (hkp_ask_import): Display keyserver URI as a URI, but only if verbose. * exec.c, g10.c: USE_EXEC_PATH -> FIXED_EXEC_PATH 2002-07-03 David Shaw * exec.h, exec.c (set_exec_path, exec_write), g10.c (main): If USE_EXEC_PATH is defined at compile time, use it to lock the exec-path and not allow the user to change it. 2002-07-02 David Shaw * options.h, g10.c (main), keyserver.c (keyserver_refresh): Maintain and use the original keyserver URI for cosmetics rather than trying to recreate it when needed. * mainproc.c (check_sig_and_print): Properly disregard expired uids. Make sure that the first uid listed is a real uid and not an attribute (attributes should only be listed in the "aka" section). When there are no valid textual userids, try for an invalid textual userid before using any attribute uid. 2002-07-01 David Shaw * options.skel: Fix a few typos, clarify "group", and remove sample photo viewers for Win32 since they are the defaults now. * parse-packet.c (make_attribute_uidname), keylist.c (dump_attribs): Fix two typecast warnings. * packet.h, build-packet.c (build_attribute_subpkt), exec.c (expand_args), mkdtemp.c (mkdtemp), photoid.c (parse_image_header): Fix some signedness compiler warnings. 2002-07-01 Werner Koch * photoid.c (get_default_photo_command): Also use __MINGW32__ instead of HAVE_DOSISH_SYSTEM. * encode.c (encode_symmetric): Do not use the new encryption code. 2002-06-30 Werner Koch * photoid.c: Use __MINGW32__ to include windows because HAVE_DOSISH_SYSTEM is also set for OS/2 and plain DOS. Provide constant missing in older mingw installations. 2002-06-21 Stefan Bellon * g10.c [__riscos__]: Moved RISC OS specific stuff to util/riscos.c and include/util.h. * gpgv.c [__riscos__]: Likewise. 2002-06-20 David Shaw * keydb.h, pkclist.c (select_algo_from_prefs): Allow passing a suggested algorithm which will be used if available. * encode.c (encode_crypt, encrypt_filter), sign.c (sign_file): Use new select_algo_from_prefs feature to check if forcing an algorithm would violate the recipient preferences. * photoid.c (get_default_photo_command, show_photos): Use different default viewers on different platforms. Currently we have Win 9x, Win NT (2k, xp), Mac OSX, RISC OS, and "everybody else". These are #ifdefs as much as possible to avoid clutter. * g10.c (strusage, build_list), keyedit.c (show_prefs), main.h, misc.c (compress_algo_to_string, check_compress_algo), pkclist.c (algo_available), keygen.c (keygen_set_std_prefs): New algo_to_string and check functions for compress algorithms. 2002-06-20 Werner Koch * misc.c (setsysinfo): Removed a #warning for Alpha's uniligedn trap disabling - it is quite possible that this is a debug relict. 2002-06-20 Stefan Bellon * g10.c [__riscos__]: Added image file system feature. * gpgv.c [__riscos__]: Added image file system feature. * photoid.c (show_photos) [__riscos__]: Set RISC OS filetype of photo id according to MIME type. 2002-06-19 David Shaw * hkp.c (parse_hkp_index): Don't leak memory when failing out of a bad HKP keyserver. * g10.c (add_notation_data): Relax slightly the rules as to what can go into a notation name - 2440 allows "@", for example. 2002-06-17 David Shaw * import.c (clean_subkeys, import_one): Only allow at most 1 binding sig and at most 1 revocation sig on a subkey, as per 2440:11.1. * hkp.c (parse_hkp_index, hkp_search): Error if the keyserver returns an unparseable HKP response. 2002-06-15 David Shaw * keyedit.c (show_key_with_all_names), keylist.c (list_keyblock_print): Show "[expired]" before expired uids. * keyedit.c (show_key_with_all_names_colon), mainproc.c (list_node), keylist.c (list_keyblock_colon): Show flag 'e' for expired user ids. Use "uat" for user attribute packets instead of "uid". Also use ' ' rather than the fake user id string on attributes. * keygen.c (keygen_add_revkey): Remove unused code. * misc.c (check_permissions): Check directory permissions properly - they are not special files. * pkclist.c (expand_id, expand_group, build_pk_list): When expanding groups before building a pk list, inherit flags from the original pre-expanded string. * pubkey-enc.c (is_algo_in_prefs): Don't use prefs from expired uids. 2002-06-14 David Shaw * free-packet.c (copy_signature): Properly copy a signature that carries a revocation key on it. * pkclist.c (expand_id, expand_group, build_pk_list): Groups now work properly when used in the "Enter the user ID" prompt. 2002-06-14 David Shaw * keyedit.c (show_key_with_all_names): Display warning if a user tries to show prefs on a v3 key with a v3 selfsig. * kbnode.c (dump_kbnode): Show if a uid is expired. * import.c (merge_blocks, import_revoke_cert): Show user ID receiving a revocation certificate. * free-packet.c (cmp_user_ids): Properly compare attribute ids. * pkclist.c (expand_groups): Maintain the strlist flags while expanding. Members of an expansion inherit their flags from the expansion key. * options.h, cipher.c (write_header), g10.c (main), keygen.c (keygen_set_std_prefs): remove the personal_mdc flag. It no longer serves a purpose now that the personal preference lists are split into cipher/digest/zip. 2002-06-14 Timo Schulz * skclist.c (is_insecure): Implemented. 2002-06-12 David Shaw * keyserver.c (keyserver_spawn): Properly handle PROGRAM responses when they have a CRLF ending. Noted by Keith Ray. * keyserver.c (keyserver_spawn): Handle CRLF endings from keyserver helpers. Also don't leak the last line worth of memory from the keyserver response. * main.h, misc.c (deprecated_warning): New function to warn about deprecated options and commands. * g10.c (main), keyserver-internal.h, keyserver.c (parse_keyserver_uri): Use new deprecated function to warn about honor-http-proxy, auto-key-retrieve, and x-broken-hkp. 2002-06-11 David Shaw * Makefile.am: link gpg with NETLIBS for the built-in HKP access. 2002-06-10 David Shaw * options.h, keyserver.c (keyserver_opts), g10.c (main): New keyserver option "include-subkeys". This feature already existed, but now can be turned off. It defaults to on. * options.h, keyserver.c (parse_keyserver_options, keyserver_spawn): There are now enough options to justify making a structure for the keyserver options rather than a page of if-then-else-if-then-etc. * getkey.c (merge_keys_and_selfsig, merge_selfsigs_main): Fix bug in calculating key expiration dates. 2002-06-09 David Shaw * keydb.h, getkey.c (get_user_id_native), import.c (import_one): Display user ID while importing a key. Note this applies to both --import and keyserver --recv-keys. * exec.c (exec_finish): Log unnatural exit (core dump, killed manually, etc) for fork/exec/pipe child processes. 2002-06-08 Timo Schulz * encode.c (encode_symmetric): Disable the compat flag when the expert mode is enabled. 2002-06-07 David Shaw * options.skel, options.h, main.h, keydb.h, pkclist.c (build_pk_list, expand_groups), g10.c (main, add_group): Add new "group" command to allow one name to expand into multiple keys. For simplicity, and to avoid potential loops, we only expand once - you can't make an alias that points to an alias. * main.h, g10.c (main), keygen.c (build_personal_digest_list): Simplify the default digest list - there is really no need for the other hashes since they will never be used after SHA-1 in the list. * options.skel, options.h, g10.c (main), hkp.c (hkp_ask_import, hkp_export, hkp_search), keyserver.c (parse_keyserver_options, parse_keyserver_uri, keyserver_work, keyserver_refresh): Make the "x-broken-hkp" keyserver scheme into keyserver-option "broken-http-proxy". Move honor_http_proxy into keyserver_options. Canonicalize the three variations of "hkp", "x-hkp", and "x-broken-hkp" into "hkp". 2002-06-07 Stefan Bellon * g10.c [__riscos__]: Added --attribute-file to do the same as --attribute-fd, but with a filename not a fd as argument. Added magic symbol for RISC OS to use different memory management. * gpgv.c [__riscos__]: Added magic symbol for RISC OS to use different memory management. 2002-06-06 David Shaw * main.h, g10.c (main), keygen.c (build_personal_digest_list): Put in a default digest preference list consisting of SHA-1, followed by every other installed digest except MD5. Note this is the same as having no digest preference at all except for SHA-1 being favored. * options.h, g10.c (main), keygen.c (keygen_set_std_prefs), pkclist.c (select_algo_from_prefs): Split --personal-preference-list into three: --personal-{cipher|digest|compress}-preferences. This allows a user to set one without affecting another (i.e. setting only a digest pref doesn't imply an empty cipher pref). * exec.c (exec_read): This is a safer way of guessing the return value of system(). Noted by Stefan Bellon. 2002-06-05 David Shaw * hkp.c (parse_hkp_index): Be more robust with keyservers returning very unparseable responses. * exec.c (exec_read): Catch and display an error when the remote process exits unnaturally (i.e. segfault) so the user knows what happened. Also fix exec_write stub which has a different number of arguments now. 2002-06-05 Timo Schulz * encode.c (encode_simple): Ignore the new mode for RFC1991. * mainproc.c (symkey_decrypt_sesskey): Better check for weird keysizes. 2002-06-05 Timo Schulz * encode.c (encode_sesskey): New. (encode_simple): Use it here. But by default we use the compat mode which supress to generate encrypted session keys. 2002-06-05 Timo Schulz * mainproc.c (symkey_decrypt_sesskey): New. (proc_symkey_enc): Support for encrypted session keys. 2002-06-04 David Shaw * sign.c (hash_for, sign_file): When encrypting and signing at the same time, consult the various hash prefs to pick a hash algorithm to use. Pass in a 160-bit hint if any of the signing keys are DSA. * keydb.h, pkclist.c (select_algo_from_prefs, algo_available): Pass a "hints" opaque pointer in to let the caller give hints as to what algorithms would be acceptable. The only current hint is for PREFTYPE_HASH to require a 160-bit hash for DSA. Change all callers in encode.c (encode_crypt, encrypt_filter) and sign.c (sign_file). If we settle on MD5 as the best algorithm based solely on recepient keys and SHA1 is also a possibility, use SHA1 unless the user intentionally chose MD5. This is as per 2440:13. * exec.c (make_tempdir): Fix duplicated filename problem. 2002-06-03 David Shaw * packet.h, parse-packet.c (enum_sig_subpkt): Report back from enum_sig_subpkt when a subpacket is critical and change all callers in keylist.c (show_policy_url, show_notation), mainproc.c (print_notation_data), and pkclist.c (do_show_revocation_reason). * keylist.c (show_policy_url, show_notation): Display if the policy or notation is critical. 2002-06-03 David Shaw * main.h, g10.c (main), keylist.c (dump_attribs, set_attrib_fd, list_keyblock_print, list_keyblock_colon), status.h, status.c (get_status_string): New --attribute-fd feature to dump the contents of attribute subpackets for frontends. If --status-fd is also used, then a new status tag ATTRIBUTE is provided for each subpacket. * packet.h, getkey.c (fixup_uidnode, merge_selfsigs_main, merge_selfsigs_subkey), parse-packet.c (setup_user_id): Keep track of the expiration time of a user ID, and while we're at it, use the expired flag from the selfsig rather than reparsing the SIG_EXPIRE subpacket. * photoid.c (generate_photo_id): When adding a new photo ID, showing the photo for confirmation is not safe when noninteractive since the "user" may not be able to dismiss a viewer window. Noted by Timo Schulz. 2002-06-03 David Shaw * options.skel: Sample photo viewers for Win32. * misc.c (pct_expando): Use the seckey for %k/%K if the pubkey is not available. * photoid.h, photoid.c (show_photos): Include the seckey in case a user tries to view a photo on a secret key, and change all callers in keyedit.c (menu_showphoto), keylist.c (list_keyblock_print), and photoid.c (generate_photo_id). 2002-06-02 David Shaw * photoid.c (show_photos): Work properly when not called with a public key. 2002-05-31 David Shaw * sign.c (mk_notation_and_policy): Free unneeded buffer. * hkp.c (parse_hkp_index): Properly handle the '&' character (i.e. "&") in HKP responses. * getkey.c (merge_selfsigs_main): Fix reversed expiration time check with self-sigs. * keyedit.c (sign_uids): When making a new self-sig on a v3 key, make a v3 self-sig unless it is currently a v3 self-sig being promoted to v4. 2002-05-31 Timo Schulz * pkclist.c (do_show_revocation_reason): Don't use capital letters for non-interactive output. (show_revocation_reason): Now it is global. * pubkey-enc.c (get_it): Show if the key has been revoked. 2002-05-30 David Shaw * sign.c (write_signature_packets, sign_file, clearsign_file, sign_symencrypt_file): Make a v4 signature if a policy URL or notation is set, unless v3 sigs are forced via rfc1991 or force-v3-sigs. Also remove some doubled code and clarify an error message (we don't sign in PGP2 mode - just detach-sign). * parse-packet.c (parse_one_sig_subpkt): Add KS_FLAGS to the "any size" section. 2002-05-29 David Shaw * keygen.c (keygen_set_std_prefs, add_feature_mdc): Use "mdc" and "no-mdc" in the prefs string to allow switching on and off the MDC feature. This is needed to properly export a key from GnuPG for use on PGP which does not support MDC - without this, MDC-capable implementations will still try and generate MDCs which will break PGP. * keygen.c (keygen_get_std_prefs): Show "[mdc]" in prefs string if it is enabled. * options.h, g10.c (main), cipher.c (write_header), keygen.c (keygen_set_std_prefs): For consistency, allow the user to specify mdc/no-mdc in the --personal-preference-list. If disabled, it acts just like --disable-mdc. 2002-05-29 David Shaw * options.h, exec.c: Add some debugging info, using the 1024 debug flag. * exec.c (win_system): New system()-like function for win32 that does not return until the child process terminates. Of course, this doesn't help if the process itself exits before it is finished. 2002-05-29 Werner Koch * encode.c (encode_simple): Intialize PKT when --no-literal is used. * keyedit.c (show_key_with_all_names_colon): Renamed the record for revocation keys to "rvk". 2002-05-27 Werner Koch * keyedit.c (show_key_with_all_names_colon): New. (show_key_with_all_names): Divert to new function when required. Sanitize printing of revoker name. 2002-05-27 David Shaw * build-packet.c (build_sig_subpkt): Handle setting sig flags for certain subpacket types (notation, policy url, exportable, revocable). keyedit.c (sign_mk_attrib): Flags no longer need to be set here. * packet.h, parse-packet.c (parse_one_sig_subpkt), build-packet.c (build_sig_subpkt): Call parse_one_sig_subpkt to sanity check buffer lengths before building a sig subpacket. 2002-05-26 David Shaw * sign.c (mk_notation_and_policy): Include secret key to enable %s expandos, and pass notations through pct_expando as well. * main.h, misc.c (pct_expando): Add %s and %S expandos for signer's keyid. 2002-05-25 David Shaw * g10.c (strusage, build_list): Add compress algorithms to --version list. Show algorithm numbers when --verbose --version is done. 2002-05-22 David Shaw * options.h, main.h, keygen.c (keygen_set_set_prefs, keygen_get_std_prefs, keygen_upd_std_prefs), keyedit.c (keyedit_menu), g10.c (main), pkclist.c (select_algo_from_prefs): Add --personal-preference-list which allows the user to factor in their own preferred algorithms when the preference lists are consulted. Obviously, this does not let the user violate a recepient's preferences (and the RFC) - this only influences the ranking of the agreed-on (and available) algorithms from the recepients. Suggested by David Hollenberg. * options.h, keygen.c (keygen_set_std_prefs), g10.c (main): Rename --preference-list to --default-preference-list (as that is what it really is), and make it a true default in that if the user selects "default" they get this list and not the compiled-in list. 2002-05-22 Werner Koch * g10.c (main): Add missing LF in a info printout and made it translatable. Noted by Michael Tokarev. 2002-05-21 Werner Koch * g10.c (main): Removed the undef of USE_SHM_COPROCESSING which was erroneously introduced on 2002-01-09. * signal.c (got_fatal_signal): Don't write the Nul to stderr. Reported by David Hollenberg. 2002-05-18 David Shaw * main.h, g10.c (main), revoke.c (gen_desig_revoke): Generate a designated revocation via --desig-revoke * keyedit.c (keyedit_menu, menu_addrevoker): New "addrevoker" command to add a designated revoker to a key. 2002-05-17 David Shaw * gpgv.c: Add stub for get_ownertrust(). * g10.c (main): --allow-freeform-uid should be implied by OpenPGP. Add --no-allow-freeform-uid. * keyedit.c (sign_uids): Issue a warning when signing a non-selfsigned uid. * getkey.c (merge_selfsigs_main): If a key has no selfsigs, and allow-non-selfsigned-uid is not set, still try and make the key valid by checking all uids for a signature from an ultimately trusted key. 2002-05-16 David Shaw * main.h, keygen.c (keygen_add_revkey): Add revocation key subpackets to a signature (callable by make_keysig_packet). (write_direct_sig): Write a 1F direct key signature. (parse_revocation_key): Parse a string in algo:fpr:sensitive format into a revocation key. (get_parameter_revkey, do_generate_keypair): Call above functions when prompted from a batch key generation file. * build-packet.c (build_sig_subpkt): Allow multiple revocation key subpackets in a single sig. * keydb.h, getkey.c (get_seckey_byfprint): Same as get_pubkey_byfprint, except for secret keys. We only know the fingerprint of a revocation key, so this is needed to retrieve the secret key needed to issue a revokation. * packet.h, parse-packet.c (parse_signature, parse_revkeys): Split revkey parsing off into a new function that can be used to reparse after manipulating the revkey list. * sign.c (make_keysig_packet): Ability to make 1F direct key signatures. 2002-05-15 David Shaw * options.skel: keyserver.pgp.com is gone, so list pgp.surfnet.nl as a sample LDAP server instead. * getkey.c (merge_selfsigs_main): Properly handle multiple revocation keys in a single packet. Properly handle revocation keys that are in out-of-order packets. Remove duplicates in revocation key list. 2002-05-14 Timo Schulz * exec.c (make_tempdir) [MINGW32]: Added missing '\'. 2002-05-14 Stefan Bellon * exec.c (make_tempdir): Make use of EXTSEP_S instead of hardcoded dot as extension separator. 2002-05-13 David Shaw * photoid.c (show_photos): Use the long keyid as the filename for the photo. Use the short keyid as the filename on 8.3 systems. * exec.h, exec.c (make_tempdir, exec_write, exec_finish): Allow caller to specify filename. This should make things easier on windows and macs where the file extension is required, but a whole filename is even better. * keyedit.c (show_key_with_all_names, show_prefs): Show proper prefs for a v4 key uid with no selfsig at all. * misc.c (check_permissions): Don't check permissions on non-normal files (pipes, character devices, etc.) 2002-05-11 Werner Koch * mainproc.c (proc_symkey_enc): Avoid segv in case the parser encountered an invalid packet. * keyserver.c (keyserver_export): Get confirmation before sending all keys. 2002-05-10 Stefan Bellon * g10.c, hkp.c, keyedit.c, keyserver.c: Replaced all occurrances of strcasecmp with ascii_strcasecmp and all occurrances of strncasecmp with ascii_memcasecmp. 2002-05-10 David Shaw * packet.h, getkey.c (fixup_uidnode), keyedit.c (show_prefs): Show assumed prefs for hash and compression as well as the cipher pref. Show assumed prefs if there are no prefs at all on a v4 self-signed key. * options.h, g10.c (main), sign.c (make_keysig_packet): New --cert-digest-algo function to override the default key signing hash algorithm. 2002-05-09 David Shaw * getkey.c (merge_selfsigs_main): Make sure the revocation key list starts clean as this function may be called more than once (e.g. from functions in --edit). * g10.c, encode.c (encode_crypt), sign.c (sign_file, sign_symencrypt_file): Make --compress-algo work like the documentation says. It should be like --cipher-algo and --digest-algo in that it can override the preferences calculation and impose the setting the user wants. No --compress-algo setting allows the usual preferences calculation to take place. * main.h, compress.c (compress_filter): use new DEFAULT_COMPRESS_ALGO define, and add a sanity check for compress algo value. 2002-05-08 David Shaw * pkclist.c (select_algo_from_prefs): There is an assumed compression preference for uncompressed data. 2002-05-07 David Shaw * options.h, g10.c (main), getkey.c (finish_lookup), pkclist.c (algo_available): --pgp7, identical to --pgp6 except that it permits a few algorithms that PGP 7 added: AES128, AES192, AES256, and TWOFISH. Any more of these --pgpX flags, and it'll be time to start looking at a generic --emulate-pgp X option. * export.c (do_export_stream): Warn the user when exporting a secret key if it or any of its secret subkeys are protected with SHA1 while simple_sk_checksum is set. * parse-packet.c (parse_key): Show when the SHA1 protection is used in --list-packets. * options.h, build-packet.c (do_comment), g10.c (main): Rename --no-comment as --sk-comments/--no-sk-comments (--no-comment still works) and make the default be --no-sk-comments. 2002-05-07 Werner Koch * keygen.c (get_parameter_algo): Never allow generation of the deprecated RSA-E or RSA-S flavors of PGP RSA. (ask_algo): Allow generation of RSA sign and encrypt in expert mode. Don't allow ElGamal S+E unless in expert mode. * helptext.c: Added entry keygen.algo.rsa_se. 2002-05-07 David Shaw * keyedit.c (sign_uids): If --expert is set, allow re-signing a uid to promote a v3 self-sig to a v4 one. This essentially deletes the old v3 self-sig and replaces it with a v4 one. * packet.h, parse-packet.c (parse_key), getkey.c (merge_keys_and_selfsig, merge_selfsigs_main): a v3 key with a v4 self-sig must never let the v4 self-sig express a key expiration time that extends beyond the original v3 expiration time. 2002-05-06 David Shaw * keyedit.c (sign_uids): When making a self-signature via "sign" don't ask about sig level or expiration, and include the usual preferences and such for v4 self-sigs. (menu_set_preferences): Convert uids from UTF8 to native before printing. * keyedit.c (sign_uids): Convert uids from UTF8 to native before printing. (menu_set_primary_uid): Show error if the user tries to make a uid with a v3 self-sig primary. 2002-05-05 David Shaw * import.c (import_one): When merging with a key we already have, don't let a key conflict (same keyid but different key) stop the import: just skip the bad key and continue. * exec.c (make_tempdir): Under Win32, don't try environment variables for temp directories - GetTempDir tries environment variables internally, and it's better not to second-guess it in case MS adds some sort of temp dir handling to Windows at some point. 2002-05-05 Timo Schulz * mainproc.c (proc_symkey_enc): Don't ask for a passphrase in the list only mode. 2002-05-05 David Shaw * keyserver.c (keyserver_refresh): --refresh-keys implies --merge-only so as not to import keys with keyids that match the ones being refreshed. Noted by Florian Weimer. 2002-05-04 Stefan Bellon * free-packet.c (copy_public_key): Don't call m_alloc(0), therefore added consistency check for revkey and numrefkeys. * getkey.c (check_revocation_keys): Added consistency check for revkey and numrefkeys. * keyedit.c (show_key_with_all_names): Likewise. 2002-05-03 David Shaw * photoid.c: Provide default image viewer for Win32. * misc.c (pct_expando): %t means extension, not name ("jpg", not "jpeg"). * keyserver.c (keyserver_spawn), photoid.c (show_photos), exec.h, exec.c: Allow the caller to determine the temp file extension when starting an exec_write and change all callers. * keyedit.c (sign_uids): Nonrevocable key signatures cause an automatic promotion to v4. * exec.c: Provide stubs for exec_ functions when NO_EXEC is defined. 2002-05-02 David Shaw * photoid.h, photoid.c (parse_image_header, image_type_to_string): Useful functions to return data about an image. * packet.h, parse-packet.c (make_attribute_uidname, parse_attribute_subpkts, parse_attribute), photoid.h, photoid.c (show_photos): Handle multiple images in a single attribute packet. * main.h, misc.c (pct_expando), sign.c (mk_notation_and_policy), photoid.c (show_photos): Simpler expando code that does not require using compile-time string sizes. Call image_type_to_string to get image strings (i.e. "jpg", "image/jpeg"). Change all callers. * keyedit.c (menu_showphoto), keylist.c (list_keyblock_print): Allow viewing multiple images within a single attribute packet. * gpgv.c: Various stubs for link happiness. 2002-05-02 David Shaw * build-packet.c (build_sig_subpkt), keyedit.c (sign_uids), options.h, sign.c (mk_notation_and_policy), g10.c (main, add_notation_data, add_policy_url (new), check_policy_url (removed)): Allow multiple policy URLs on a given signature. Split "--notation-data" into "--cert-notation" and "--sig-notation" so the user can set different policies for key and data signing. For backwards compatibility, "--notation-data" sets both, as before. 2002-05-02 Werner Koch * options.skel: Removed the comment on trusted-keys because this option is now deprecated. 2002-05-01 David Shaw * keyedit.c (menu_adduid): 2440bis04 says that multiple attribute packets on a given key are legal. * keyserver.c (keyserver_refresh): the fake v3 keyid hack applies to "mailto" URLs as well since they are also served by pksd. 2002-04-29 Werner Koch Added a copyright year for files changed this year. 2002-04-25 Werner Koch * g10.c, options.h: New options --display, --ttyname, --ttytype, --lc-ctype, --lc-messages to be used with future versions of the gpg-agent. * passphrase.c (agent_send_option,agent_send_all_options): New. (agent_open): Send options to the agent. * trustdb.c (update_ownertrust, clear_ownertrust): Do an explicit do_sync because revalidation_mark does it only if when the timestamp actually changes. 2002-04-23 David Shaw * main.h, keygen.c (do_generate_keypair), keylist.c (print_signature_stats, list_all, list_one, list_keyblock, list_keyblock_print, list_keyblock_colon): After generating a new key, show the key information (name, keyid, fingerprint, etc.) Also do not print uncheckable signatures (missing key..) in --check-sigs. Print statistics (N missing keys, etc.) after --check-sigs. * keyedit.c (sign_uids): When signing a key with an expiration date on it, the "Do you want your signature to expire at the same time?" question should default to YES. 2002-04-22 David Shaw * parse-packet.c (parse_plaintext), packet.h, plaintext.c (handle_plaintext): Fix bug in handling literal packets with zero-length data (no data was being confused with partial body length). * misc.c (pct_expando), options.skel: %t means extension ("jpg"). %T means MIME type ("image/jpeg"). * import.c (import_one): Only trigger trust update if the keyring is actually changed. * export.c (do_export_stream): Missing a m_free. 2002-04-22 Stefan Bellon * keyid.c (expirestr_from_sk, expirestr_from_sig): Added _() to string constant. * exec.c (make_tempdir) [__riscos__]: Better placement of temporary file. 2002-04-20 David Shaw * keygen.c (generate_subkeypair): 2440bis04 adds that creating subkeys on v3 keys is a MUST NOT. * getkey.c (finish_lookup): The --pgp6 "use the primary key" behavior should only apply while data signing and not encryption. Noted by Roger Sondermann. 2002-04-19 Werner Koch * keygen.c (keygen_set_std_prefs): Put back 3DES because the RFC says it is good form to do so. 2002-04-19 David Shaw * keyedit.c (menu_deluid): Only cause a trust update if we delete a non-revoked user id. * hkp.c (hkp_ask_import), keyserver.c (parse_keyserver_options, keyserver_spawn), options.h: Remove fast-import keyserver option (no longer meaningful). * g10.c (main), keyedit.c (sign_uids), options.h: Change --default-check-level to --default-cert-check-level as it makes clear what it operates on. * g10.c (main): --pgp6 also implies --no-ask-sig-expire. * delkey.c (do_delete_key): Comment. * keyedit.c (sign_uids, keyedit_menu, menu_deluid, menu_delsig, menu_expire, menu_revsig, menu_revkey): Only force a trustdb check if we did something that changes it. * g10.c: add "--auto-check-trustdb" to override a "--no-auto-check-trustdb" 2002-04-19 Werner Koch * tdbio.c (tdbio_write_nextcheck): Return a status whether the stamp was actually changed. * trustdb.c (revalidation_mark): Sync the changes. Removed the sync operation done by its callers. (get_validity): Add logic for maintaining a pending_check flag. (clear_ownertrust): New. * keyedit.c (sign_uids): Don't call revalidation_mark depending on primary_pk. (keyedit_menu): Call revalidation_mark after "trust". (show_key_with_all_names): Print a warning on the wrong listed key validity. * delkey.c (do_delete_key): Clear the owenertrust information when deleting a public key. 2002-04-18 Werner Koch * seskey.c (encode_md_value): Print an error message if a wrong digest algorithm is used with DSA. Changed all callers to cope with a NULL return. Problem noted by Imad R. Faiad. 2002-04-18 David Shaw * trustdb.c (mark_usable_uid_certs): Properly handle nonrevocable signatures that can expire. In short, the only thing that can override an unexpired nonrevocable signature is another unexpired nonrevocable signature. * getkey.c (finish_lookup): Always use primary signing key for signatures when --pgp6 is on since pgp6 and 7 do not understand signatures made by signing subkeys. 2002-04-18 Werner Koch * trustdb.c (validate_keys): Never schedule a nextcheck into the past. (validate_key_list): New arg curtime use it to set next_expire. (validate_one_keyblock): Take the current time from the caller. (clear_validity, reset_unconnected_keys): New. (validate_keys): Reset all unconnected keys. * getkey.c (premerge_public_with_secret): Fixed 0x12345678! syntax for use with secret keys. (lookup): Advance the searchmode after a search FIRST. * seckey-cert.c (do_check): Always calculate the old checksum for use after unprotection. * g10.c, options.skel: New option --no-escape-from. Made --escape-from and --force-v3-sigs the default and removed them from the options skeleton. 2002-04-16 Werner Koch * parse-packet.c (parse_key): Support a SHA1 checksum as per draft-rfc2440-bis04. * packet.h (PKT_secret_key): Add field sha1chk. * seckey-cert.c (do_check): Check the SHA1 checksum (protect_secret_key): And create it. * build-packet.c (do_secret_key): Mark it as sha-1 protected. * g10.c, options.h: New option --simple-sk-checksum. 2002-04-13 David Shaw * parse-packet.c (parse_signature): Minor fix - signatures should expire at their expiration time and not one second later. * keygen.c (proc_parameter_file): Allow specifying preferences string (i.e. "s5 s2 z1 z2", etc) in a batchmode key generation file. * keyedit.c (keyedit_menu): Print standard error message when signing a revoked key (no new translation). * getkey.c (merge_selfsigs): Get the default set of key prefs from the real (not attribute) primary uid. 2002-04-12 David Shaw * pkclist.c (build_pk_list): Fix bug that allowed a key to be selected twice in batch mode if one instance was the default recipient and the other was an encrypt-to. Noted by Stefan Bellon. * parse-packet.c (dump_sig_subpkt): Show data in trust and regexp sig subpackets. * keyedit.c (keyedit_menu): Use new function real_uids_left to prevent deleting the last real (i.e. non-attribute) uid. Again, according to the attribute draft. (menu_showphoto): Make another string translatable. 2002-04-11 David Shaw * build-packet.c (build_sig_subpkt): Delete subpackets from both hashed and unhashed area on update. (find_subpkt): No longer needed. * keyedit.c (sign_uids): With --pgp2 on, refuse to sign a v3 key with a v4 signature. As usual, --expert overrides. Try to tweak some strings to a closer match so they can all be translated in one place. Use different helptext keys to allow different help text for different questions. * keygen.c (keygen_upd_std_prefs): Remove preferences from both hashed and unhashed areas if they are not going to be used. 2002-04-10 David Shaw * misc.c (pct_expando), options.skel: Use %t to indicate type of a photo ID (in this version, it's always "jpeg"). Also tweak string expansion loop to minimize reallocs. * mainproc.c (do_check_sig): Variable type fix. * keyedit.c (menu_set_primary_uid): Differentiate between true user IDs and attribute user IDs when making one of them primary. That is, if we are making a user ID primary, we alter user IDs. If we are making an attribute packet primary, we alter attribute packets. This matches the language in the latest attribute packet draft. * keyedit.c (sign_uids): No need for the empty string hack. * getkey.c (fixup_uidnode): Only accept preferences from the hashed segment of the self-sig. 2002-04-10 Werner Koch * tdbio.c (migrate_from_v2): Fixed the offset to read the old ownertrust value and only add entries to the table if we really have a value. 2002-04-08 David Shaw * status.h, status.c (get_status_string): Add KEYEXPIRED, EXPSIG, and EXPKEYSIG. Add "deprecated-use-keyexpired-instead" to SIGEXPIRED. * sig-check.c (do_check): Start transition from SIGEXPIRED to KEYEXPIRED, since the actual event is signature verification by an expired key and not an expired signature. (do_signature_check, packet.h): Rename as signature_check2, make public, and change all callers. * mainproc.c (check_sig_and_print, do_check_sig): Use status EXPSIG for an expired, but good, signature. Add the expiration time (or 0) to the VALIDSIG status line. Use status KEYEXPSIG for a good signature from an expired key. * g10.c (main): remove checks for no arguments now that argparse does it. 2002-04-06 Werner Koch * keyring.c (keyring_get_keyblock): Disable the keylist mode here. * encode.c (encode_simple, encode_crypt): Only test on compressed files if a compress level was not explicity set. * keygen.c (keygen_set_std_prefs): Removed Blowfish and Twofish from the list of default preferences, swapped the preferences of RMD160 and SHA1. Don't include a preference to 3DES unless the IDEA kludge gets used. * free-packet.c (free_packet): call free_encrypted also for PKT_ENCRYPTED_MDC. * compress.c (release_context): New. (handle_compressed): Allocate the context and setup a closure to release the context. This is required because there is no guarantee that the filter gets popped from the chain at the end of the function. Problem noted by Timo and probably also the cause for a couple of other reports. (compress_filter): Use the release function if set. * tdbio.c [__CYGWIN32__]: Don't rename ftruncate. Noted by Disastry. * parse-packet.c (parse_signature): Put parens around a bit test. * exec.c (make_tempdir): Double backslash for TMP directory creation under Windows. Better strlen the DIRSEP_S constants for allocation measurements. * decrypt.c (decrypt_messages): Release the passphrase aquired by get_last_passphrase. 2002-04-02 Werner Koch * Makefile.am (EXTRA_DIST): Removed OPTIONS an pubring.asc - they are no longer of any use. 2002-04-03 David Shaw * keyserver.c (parse_keyserver_options): fix auto-key-retrieve to actually work as a keyserver-option (noted by Roger Sondermann). * keylist.c (reorder_keyblock): do not reorder the primary attribute packet - the first user ID must be a genuine one. 2002-03-31 David Shaw * keylist.c (list_keyblock_colon): Fix ownertrust display with --with-colons. * keygen.c (generate_user_id), photoid.c (generate_photo_id): Properly initialize the user ID refcount. A few more "y/n" -> "y/N" in photoid.c. * keyedit.c (ask_revoke_sig): Warn the user if they are about to revoke an expired sig (not a problem, but they should know). Also tweak a few prompts to change "y/n" to "y/N", which is how most other prompts are written. * keyserver.c (keyserver_search_prompt): Control-d escapes the keyserver search prompt. * pkclist.c (show_revocation_reason & callers): If a subkey is considered revoked solely because the parent key is revoked, print the revocation reason from the parent key. * trustdb.c (get_validity): Allow revocation/expiration to apply to a uid/key with no entry in the trustdb. 2002-03-29 David Shaw * keyserver.c (printunquoted): unquote backslashes from keyserver searches * hkp.c (write_quoted): quote backslashes from keyserver searches 2002-03-26 Werner Koch * keygen.c (ask_keysize): Removed the warning for key sizes > 1536. 2002-03-25 Werner Koch * keyedit.c (sign_uids): Use 2 strings and not a %s so that translations can be done the right way. * helptext.c: Fixed small typo. 2002-03-23 David Shaw * import.c (append_uid, merge_sigs): it is okay to import completely non-signed uids now (with --allow-non-selfsigned-uid). * getkey.c (get_primary_uid, merge_selfsigs_main): do not choose an attribute packet (i.e. photo) as primary uid. This prevents oddities like "Good signature from [image of size 2671]". This is still not perfect (one can still select an attribute packet as primary in --edit), but is closer to the way the draft is going. * g10.c (build_list): algorithms should include 110. * g10.c (main): --pgp2 implies --no-ask-sig-expire and --no-ask-cert-expire as those would cause a v4 sig/cert. * armor.c (is_armor_header): be more lenient in what constitutes a valid armor header (i.e. -----BEGIN blah blah-----) as some Windows programs seem to add spaces at the end. --openpgp makes it strict again. 2002-03-18 David Shaw * keyserver.c (keyserver_search_prompt): Properly handle a "no keys found" case from the internal HKP code (external HKP is ok). Also, make a COUNT -1 (i.e. streamed) keyserver response a little more efficient. * g10.c (main): Add --no-allow-non-selfsigned-uid 2002-03-17 David Shaw * g10.c (main): --openpgp implies --allow-non-selfsigned-uid. * getkey.c (merge_selfsigs_main): If none of the uids are primary (because none are valid) then pick the first to be primary (but still invalid). This is for cosmetics in case some display needs to print a user ID from a non-selfsigned key. Also use --allow-non-selfsigned-uid to make such a key valid and not --always-trust. The key is *not* automatically trusted via --allow-non-selfsigned-uid. * mainproc.c (check_sig_and_print): Make sure non-selfsigned uids print [uncertain] on verification even though one is primary now. * getkey.c (merge_selfsigs): If the main key is not valid, then neither are the subkeys. * import.c (import_one): Allow --allow-non-selfsigned-uid to work on completely unsigned keys. Print the uids in UTF8. Remove mark_non_selfsigned_uids_valid(). * keyedit.c (show_key_with_all_names): Show revocation key as UTF8. * sign.c (clearsign_file): Allow --not-dash-escaped to work with v3 keys. 2002-03-14 Werner Koch * main.h: Changed the default algorithms to CAST5 and SHA1. 2002-03-13 David Shaw * import.c (chk_self_sigs): Show which user ID a bad self-sig (invald sig or unsupported public key algorithm) resides on. * import.c (chk_self_sigs): any valid self-sig should mark a user ID or subkey as valid - otherwise, an attacker could DoS the user by inventing a bogus invalid self-signature. 2002-03-07 David Shaw * g10.c (main): make a few more strings translatable. * options.h, options.skel, g10.c (main), gpgv.c, mainproc.c (check_sig_and_print), keyserver.c (parse_keyserver_options): --auto-key-retrieve should really be a keyserver-option variable. * import.c (revocation_present): new function to print a warning if a key is imported that has been revoked by designated revoker, but the designated revoker is not present to verify the revocation. If keyserver-options auto-key-retrieve is set, try and fetch the designated revoker from the keyserver. * import.c (import_one): call revocation_present after importing a new key. Note that this applies to --import, --recv-keys, and --search-keys. * keyserver-internal.h, keyserver.c (keyserver_import_fprint): import via fingerprint (for revocation keys). * keyserver.c (keyserver_import_keyid): much simpler implementation now that we're using KEYDB_SEARCH_DESC internally. 2002-03-04 David Shaw * revoke.c (gen_revoke): do not prompt for revocation reason for v3 revocations (unless force-v4-certs is on) since they wouldn't be used anyway. * keyedit.c (menu_revsig): show the status of the sigs (exportable? revocable?) to the user before prompting for which sig to revoke. Also, make sure that local signatures get local revocations. * keyedit.c (ask_revoke_sig): remind the user which sigs are local. * g10.c (main): Add "exec-path" variable to override PATH for execing programs. * export.c (do_export_stream): properly check return code from classify_user_id to catch unclassifiable keys. 2002-03-03 David Shaw * parse-packet.c (parse_signature): variable type tweak for RISC OS (from Stefan) 2002-02-28 David Shaw * getkey.c (check_revocation_keys): New function to check a revocation against a list of potential revocation keys. Note the loop-breaking code here. This is to prevent blowing up if A is B's revocation key, while B is also A's. Note also that this is written so that a revoked revoker can still issue revocations: i.e. If A revokes B, but A is revoked, B is still revoked. I'm not completely convinced this is the proper behavior, but it matches how PGP does it. It does at least have the advantage of much simpler code - my first version of this had lots of loop maintaining code so you could chain revokers many levels deep and if D was revoked, C was not, which meant that B was, and so on. It was sort of scary, actually. * getkey.c (merge_selfsigs_main): Add any revocation keys onto the pk. This is particularly interesting since we normally only get data from the most recent 1F signature, but you need multiple 1F sigs to properly handle revocation keys (PGP does it this way, and a revocation key could be marked "sensitive" and hence in a different signature). Also, if a pk has a revocation key set, check for revocation sigs that were not made by us - if made by a valid revocation key, mark the pk revoked. * packet.h, getkey.c (cache_public_key): do not cache key if "dont_cache" is set. This allows the revocation key code to look up a key and return information that may be inaccurate to prevent loops without caching the fake data. * packet.h, sig-check.c (do_signature_check): Record if a signature was made by a revoked pk. * packet.h, parse-packet.c (parse_one_sig_subpkt, can_handle_critical, parse_signature): Get revocation key information out of direct sigs. * keylist.c (list_keyblock_print): don't assume that the presence of a 0x20 signature means the key is revoked. With revocation keys, this may not be true if the revocation key is not around to verify it or if verification failed. Also, 0x1F should get listed as "sig", and not "unexpected signature class". * keyedit.c (show_key_with_all_names): Add a flag for printing revoker information and change all callers. * import.c (merge_blocks): merge in any new direct key (0x1F) sigs. * import.c (import_revoke_cert): don't keep processing after a revocation is rejected. * import.c (delete_inv_parts): Allow importing a revocation signature even if it was not issued by the key. This allows a revocation key to issue it. Of course, the sig still needs to be checked before we trust it. * free-packet.c (copy_public_key): Include a new copy of the revocation keys when duping a pk. * free-packet.c (free_seckey_enc, release_public_key_parts): Free any revocation keys that are attached to a sig or pk. * export.c (do_export_stream): Do not export signatures with "sensitive" revocation keys in them. 2002-02-27 David Shaw * export.c (do_export_stream): Do not include v3 keys in a --export-secret-subkeys export. * getkey.c (merge_selfsigs_main): If a key isn't valid (say, because of no self-signature), allow --always-trust to force it valid so it can be trusted. 2002-02-25 David Shaw * hkp.c (hkp_ask_import), hkp.h, keyserver.c (all): treat key lists internally as fingerprints when possible. All this is via KEYDB_SEARCH_DESC - no point in reinventing the wheel. This allows the helper program to search the keyserver by fingerprint if desired (and the keyserver supports it). Note that automatic fingerprint promotion during refresh only applies to v4 keys as a v4 fingerprint can be easily changed into a long or short key id, and a v3 cannot. * pubkey-enc.c, getkey.c, misc.c, main.h: Take two copies of hextobyte() from pubkey-enc.c and getkey.c and make them into one copy in misc.c. 2002-02-22 David Shaw * keyserver.c (keyserver_search_prompt): Detect a "no keys found" case even if the helper program does not explicitly say how many keys were found. * hkp.c (parse_hkp_index): Bug fix - don't report non-revoked keys as revoked in HKP key searches. 2002-02-19 Werner Koch * parse-packet.c (parse_trust): Made parsing more robust. 2002-02-19 David Shaw * hkp.c (parse_hkp_index): Catch corruption in HKP index lines (can be caused by broken or malicious keyservers). * keyserver.c (keyserver_work): Add KEYSERVER_NOT_SUPPORTED for unsupported actions (say, a keyserver that has no way to search, or a readonly keyserver that has no way to add). Also add a USE_EXTERNAL_HKP define to disable the internal HKP keyserver code. 2002-02-14 Werner Koch * g10.c: New option --no-use-agent. * pkclist.c (check_signatures_trust): Always print the warning for unknown and undefined trust. Removed the did_add cruft. Reported by Janusz A. Urbanowicz. 2002-02-11 David Shaw * hkp.c (parse_hkp_index): Bug fix - properly handle user IDs with colons (":") in them while HKP searching. 2002-02-09 David Shaw * misc.c (pct_expando): More comments. * keydb.h, sign.c (mk_notation_and_policy): Clarify what is a sig and what is a cert. A sig has sigclass 0x00, 0x01, 0x02, or 0x40, and everything else is a cert. * g10.c (main), keyedit.c (keyedit_menu): Add a "nrlsign" for nonrevocable and local key signatures. * g10.c (main): Add a --no-force-mdc to undo --force-mdc. * options.h, g10.c (main), cipher.c (write_header): Add a knob to --disable-mdc/--no-disable-mdc. Off by default, of course, but is used in --pgp2 and --pgp6 modes. * pkclist.c (build_pk_list): Allow specifying multiple users in the "Enter the user ID" loop. Enter a blank line to stop. Show each key+id as it is added. * keylist.c (show_policy_url), mainproc.c (print_notation_data): It is not illegal (though possibly silly) to have multiple policy URLs in a given signature, so print all that are present. * hkp.c (hkp_search): More efficient implementation of URL-ifying code. 2002-02-04 David Shaw * main.h, misc.c (pct_expando): New function to generalize %-expando processing in any arbitrary string. * photoid.c (show_photo): Call the new pct_expando function rather than expand strings internally. * sign.c (mk_notation_and_policy): Show policy URLs and notations when making a signature if show-policy/show-notation is on. %-expand policy URLs during generation. This lets the user have policy URLs of the form "http://notary.jabberwocky.com/keysign/%K" which will generate a per-signature policy URL. * main.h, keylist.c (show_policy_url, show_notation): Add amount to indent so the same function can be used in key listings as well as during sig generation. Change all callers. 2002-02-04 David Shaw * keyserver.c, options.h (parse_keyserver_options, keyidlist): Workaround for the pksd and OKS keyserver bug that calculates v4 RSA keyids as if they were v3. The workaround/hack is to fetch both the v4 (e.g. 99242560) and v3 (e.g. 68FDDBC7) keyids. This only happens for key refresh while using the HKP scheme and the refresh-add-fake-v3-keyids keyserver option must be set. This should stay off by default. 2002-02-03 David Shaw * keyserver.c (keyserver_spawn): Bug fix - do not append keys to each other when --sending more than one. 2002-02-02 David Shaw * options.h, g10.c (main), keyedit.c (sign_uids), sign.c (mk_notation_and_policy): Split "--set-policy-url" into "--cert-policy-url" and "--sig-policy-url" so the user can set different policies for key and data signing. For backwards compatibility, "--set-policy-url" sets both, as before. 2002-01-30 Werner Koch * g10.c (main): --gen-random --armor does now output a base64 encoded string. 2002-01-28 David Shaw * g10.c (main), options.h, pkclist.c (algo_available): --pgp6 flag. This is not nearly as involved as --pgp2. In short, it turns off force_mdc, turns on no_comment, escape_from, and force_v3_sigs, and sets compression to 1. It also restricts the user to IDEA (if present), 3DES, CAST5, MD5, SHA1, and RIPEMD160. See the comments above algo_available() for lots of discussion on why you would want to do this. 2002-01-27 David Shaw * keygen.c (keygen_set_std_prefs): Comment * keyedit.c (sign_uids): Bug fix - when signing with multiple secret keys at the same time, make sure each key gets the sigclass prompt. * exec.c (exec_finish): Close the iobuf and FILE before trying to waitpid, so the remote process will get a SIGPIPE and exit. This is only a factor when using a pipe to communicate. * exec.c (exec_write): Disable cache-on-close of the fd iobuf (is this right? Why is a fd iobuf cached at all?) 2002-01-26 Werner Koch * g10.c, options.h: New option --gpg-agent-info * passphrase.c (agent_open): Let it override the environment info. * seckey-cert.c (check_secret_key): Always try 3 times when the agent is enabled. * options.skel: Describe --use-agent. 2002-01-24 David Shaw * pubkey-enc.c (is_algo_in_prefs, get_it): Only check preferences against keys with v4 self sigs - there is really little point in warning for every single non-IDEA message encrypted to an old key. * pkclist.c (select_algo_from_prefs): Only put in the fake IDEA preference if --pgp2 is on. * mainproc.c (check_sig_and_print): Print "Expired" for expired but good signatures (this still prints "BAD" for expired but bad signatures). 2002-01-23 David Shaw * keygen.c (ask_keysize): Cosmetic: don't present a RSA signing key as a "keypair" which can be 768 bits long (as RSA minimum is 1024). * pubkey-enc.c (is_algo_in_prefs): Allow IDEA as a fake preference for v3 keys with v3 selfsigs. 2002-01-22 David Shaw * packet.h, getkey.c (merge_selfsigs_main), pkclist.c (select_algo_from_prefs): Implement the fake IDEA preference as per RFC2440:12.1. This doesn't mean that IDEA will be used (the plugin may not be present), but it does mean that a v3 key with a v3 selfsig has an implicit IDEA preference instead of 3DES. v3 keys with v4 selfsigs use preferences as normal. * encode.c (encode_crypt): if select_algo_from_prefs fails, this means that we could not find a cipher that both keys like. Since all v4 keys have an implicit 3DES preference, this means there is a v3 key with a v3 selfsig in the list. Use 3DES in this case as it is the safest option (we know the v4 key can handle it, and we'll just hope the v3 key is being used in an implementation that can handle it). If --pgp2 is on, warn the user what we're doing since it'll probably break PGP2 compatibility. * g10.c (main): Do not force using IDEA for encrypted files in --pgp2 mode - let the fake IDEA preference choose this for us for better compatibility when encrypting to multiple keys, only some of which are v3. * keygen.c (keygen_set_std_prefs): Put 3DES on the end of the default cipher pref list (RFC2440: "...it is good form to place it there explicitly."). If the user has the IDEA plugin installed, put a preference for IDEA *after* 3DES to effectively disable its use for everything except encrypting along with v3 keys. * encode.c, g10.c, sign.c: Change the PGP2 warning line from "... will not be usable ..." to "... may not be usable ..." as the user could be using one of the enhanced PGP2 variations. * helptext.c: Revise the sign_uid.class help text as suggested by Stefan. 2002-01-20 Werner Koch * passphrase.c (passphrase_to_dek): Add tryagain_text arg to be used with the agent. Changed all callers. (agent_get_passphrase): Likewise and send it to the agent * seckey-cert.c (do_check): New arg tryagain_text. (check_secret_key): Pass the string to do_check. * keygen.c (ask_passphrase): Set the error text is required. * keyedit.c (change_passphrase): Ditto. * passphrase.c (agent_open): Disable opt.use_agent in case of a problem with the agent. (agent_get_passphrase): Ditto. (passphrase_clear_cache): Ditto. 2002-01-19 Werner Koch * passphrase.c (agent_open): Add support for the new Assuan based gpg-agent. New arg to return the used protocol version. (agent_get_passphrase): Implemented new protocol here. (passphrase_clear_cache): Ditto. (readline): New. 2002-01-15 Timo Schulz * encode.c (encode_crypt_files): Fail if --output is used. * g10.c: New command --decrypt-files. * decrypt.c (decrypt_messages): New. 2002-01-09 David Shaw * g10.c, misc.c, gpgv.c: move idea_cipher_warn to misc.c so gpgv.c doesn't need a stub for it any longer. * g10.c (get_temp_dir), main.h: no longer used (it's in exec.c now) * g10.c (main), delkey.c (delete_keys), main.h : Allow --delete-key (now --delete-keys, though --delete-key still works, of course) to delete multiple keys in one go. This applies to --delete-secret-key(s) and --delete-secret-and-public-key(s) as well. 2002-01-09 Timo Schulz * encode.c (encode_crypt_files): Now it behaves like verify_files. * g10.c (main): We don't need to check argc for encode_crypt_files any longer. 2002-01-09 Timo Schulz * exec.c: Include windows.h for dosish systems. 2002-01-08 Timo Schulz * g10.c (main): New description for --encrypt-files. 2002-01-08 Werner Koch * g10.c (main): Must register the secring for encryption because it is needed to figure out the default recipient. Reported by Roger Sondermann. 2002-01-05 David Shaw * keyedit.c (menu_adduid): Require --expert before adding a photo ID to a v3 key, and before adding a second photo ID to any key. * keyedit.c (keyedit_menu): Don't allow adding photo IDs in rfc1991 or pgp2 mode. * getkey.c (merge_selfsigs_subkey): Permit v3 subkeys. Believe it or not, this is allowed by rfc 2440, and both PGP 6 and PGP 7 work fine with them. * g10.c, options.h, keyedit.c, sign.c: Move the "ask for expiration" switch off of --expert, which was getting quite overloaded, and onto ask-sig-expire and ask-cert-expire. Both default to off. * g10.c (main): Change the default compression algo to 1, to be more OpenPGP compliant (PGP also uses this, so it'll help with interoperability problems as well). * encode.c (encode_crypt): Handle compression algo 2, since the default is now 1. * build-packet.c (build_attribute_subpkt): Fix off-by-one error. 2002-01-05 Werner Koch * g10.c (main): Do not register the secret keyrings for certain commands. * keydb.c (keydb_add_resource): Use access to test for keyring existence. This avoids cached opened files which are bad under RISC OS. 2002-01-04 David Shaw * sign.c (sign_file, sign_symencrypt_file): always use one-pass packets unless rfc1991 is enabled. This allows a signature made with a v3 key to work in PGP 6 and 7. Signatures made with v4 keys are unchanged. * g10.c (main): Disallow non-detached signatures in PGP2 mode. Move the "you must use files and not pipes" PGP2 warning up so all the PGP2 stuff is together. * encode.c (encode_simple): Use the actual filesize instead of partial length packets in the internal literal packet from a symmetric message. This breaks PGP5(?), but fixes PGP2, 6, and 7. It's a decent tradeoff. Note there was only an issue with old-style RFC1991 symmetric messages. 2440-style messages in 6 and 7 work with or without partial length packets. 2002-01-03 David Shaw * g10.c (main): Removed --no-default-check-level option, as it is not consistent with other "default" options. Plus, it is the same as saying --default-check-level 0. * exec.c (exec_read): Disallow caching tempfile from child process, as this keeps the file handle open and can cause unlink problems on some platforms. * keyserver.c (keyserver_search_prompt): Minor tweak - don't bother to transform keyids into textual form if they're just going to be transformed back to numbers. 2002-01-03 Timo Schulz * g10.c: New command --encrypt-files. * verify.c (print_file_status): Removed the static because encode_crypt_files also uses this function. * main.h (print_files_status): New. (encode_crypt_files): New. * encode.c (encode_crypt_files): New. 2002-01-02 Stefan Bellon * keyserver.c: Moved util.h include down in order to avoid redefinition problems on RISC OS. * keyring.c (keyring_lock): Only lock keyrings that are writable. * keyring.c (keyring_update_keyblock): Close unused iobuf. * hkp.c (parse_hkp_index, hkp_search) [__riscos__]: Changed unsigned char* to char* because of compiler issues. * exec.c (exec_finish) [__riscos__]: Invalidate close cache so that file can be unlinked. 2001-12-28 David Shaw * g10.c (main): Use a different strlist to check extensions since they need to be handled seperately now. * misc.c,main.h (check_permissions): Properly handle permission and ownership checks on files in the lib directory (e.g. /usr/local/lib/gnupg), which are owned by root and are world-readable, and change all callers to specify extension or per-user file. * photoid.c (show_photo), keyserver.c (keyserver_spawn): Bug fix - don't call exec_finish if exec_write fails. * keyserver.c (keyserver_spawn): Look for OPTIONS from the keyserver helper - specifically, a "OUTOFBAND" option for the email keyserver. * mainproc.c (list_node), keylist.c (list_keyblock_colon), import.c (delete_inv_parts), export.c (do_export_stream): Use signature flags for exportability check rather than re-parsing the subpacket. * keyid.c, keydb.h (get_lsign_letter): No longer needed. 2001-12-27 David Shaw * exec.c (exec_finish): Show errors when temp files cannot be deleted for whatever reason. * exec.c (exec_read): Don't rely on WEXITSTATUS being present. * exec.c (make_tempdir): Add temp file creator for win32. Don't create an incoming temp file if the exec is write-only. * keyserver.c (keyserver_spawn): Clean up error handling, for when the spawn fails. * photoid.c (show_photo): Clean up error handling. * misc.c (check_permissions): Neaten. 2001-12-25 David Shaw * mkdtemp.c (mkdtemp): Add copyleft info and tweak the 'X' counter to be a bit simpler. * keyserver.c, photoid.c: Remove unused headers left over from when the exec functions lived there. 2001-12-23 Timo Schulz * misc.c (check_permissions): Do not use it for W32 systems. * tdbio.c (migrate_from_v2): Define ftruncate as chsize() for W32. * mkdtemp.c: W32 support. * photoid.c: Ditto. * exec.c: Ditto. 2001-12-22 David Shaw * exec.c (make_tempdir): avoid compiler warning with const * mkdtemp.c (mkdtemp): catch the empty ("") string case in case someone repurposes mkdtemp at some point. * photoid.c (generate_photo_id, show_photo): some type changes from Stefan Bellon. * exec.c (make_tempdir): handle Win32 systems, suggested by Timo Schulz. 2001-12-22 Werner Koch * encode.c (encode_simple, encode_crypt): i18n 2 strings. 2001-12-22 Timo Schulz * encode.c (encode_simple, encode_crypt): Use is_file_compressed to avoid to compress compressed files. 2001-12-22 Werner Koch * keyserver.c (keyserver_spawn): Removed some variables declaration due to shadowing warnings. * build-packet.c (build_attribute_subpkt): s/index/idx/ to avoid compiler warnig due to index(3). * getkey.c (get_ctx_handle): Use KEYDB_HANDLE as return value. * keylist.c (list_one): Made resname const. * keyedit.c (keyedit_menu): Allow "addphoto" only when --openpgp is not used. * options.skel: Changed one example photo viewer to qiv. 2001-12-21 David Shaw * Makefile.am: add exec.c, exec.h, photoid.c, and photoid.h * build-packet.c (build_attribute_subpkt): new function to build the raw attribute subpacket. Note that attribute subpackets have the same format as signature subpackets. * exec.c: new file with generic exec-a-program functionality. Used by both photo IDs and keyserver helpers. This is pretty much the same code that used to be keyserver specific, with some changes to be usable generically. * free-packet.c (free_attributes (new)): function to free an attribute packet. * gpgv.c: added stub show_photo * keyedit.c (keyedit_menu, menu_adduid, menu_showphoto): can add a photo (calls generate_photo_id), or display a photo (calls show_photo) from the --edit menu. New commands are "addphoto", and "delphoto" (same as "deluid"). * keylist.c (list_keyblock_print): show photos during key list if --show-photos enabled. * keyserver.c (keyserver_spawn): use the generic exec_xxx functions to call keyserver helper. * g10.c, options.h: three new options - --{no-}show-photos, and --photo-viewer to give the command line to display a picture. * options.skel: instructions for the photo viewer * parse-packet.c (parse_user_id, setup_user_id (new)): common code for both user IDs and attribute IDs moved to setup_user_id. * parse-packet.c (make_attribute_uidname (new)): constructs a fake "name" for attribute packets (e.g. "[image of size ...]") * parse-packet.c (parse_attribute (replaces parse_photo_id), parse_attribute_subpkts): Builds an array of individual attributes. Currently only handles attribute image / type jpeg subpackets. * sign.c (hash_uid): Fix bug in signing attribute (formerly photo_id) packets. * packet.h, and callers: globally change "photo_id" to "attribute" and add structures for attributes. The packet format is generic attributes, even though the only attribute type thus far defined is jpeg. 2001-12-21 David Shaw * parse-packet.c (can_handle_critical): Can handle critical revocation subpackets now. * trustdb.c (mark_usable_uid_certs): Disregard revocations for nonrevocable sigs. Note that this allows a newer revocable signature to override an older nonrevocable signature. * sign.c (make_keysig_packet): add a duration field and change all callers. This makes make_keysig_packet closer to write_signature_packets and removes some duplicated expiration code. * keyedit.c (keyedit_menu, menu_revsig, sign_uids, sign_mk_attrib): Add nrsign command, don't allow revoking a nonrevocable signature, * g10.c (main): Add --nrsign option to nonrevocably sign a key from the command line. * build-packet.c (build_sig_subpkt_from_sig): Comment to explain the use of CRITICAL. 2001-12-21 Werner Koch * g10.c. options.h : New option --show-keyring * getkey.c (get_ctx_handle): New. * keylist.c (list_one): Implement option here. By David Champion. 2001-12-20 David Shaw * keyserver.c (keyserver_spawn): Use mkdtemp() to make temp directory. * mkdtemp.c: replacement function for those platforms that don't have mkdtemp (make a temp directory securely). 2001-12-19 David Shaw * misc.c (check_permissions): New function to stat() and ensure the permissions of GNUPGHOME and the files have safe permissions. * keydb.c (keydb_add_resource): Check keyring permissions. * tdbio.c (tdbio_set_dbname): Check permissions of trustdb.gpg * keyserver.c (keyserver_spawn): Disable keyserver schemes that involve running external programs if the options file has unsafe permissions or ownership. * g10.c, options.h: New option --no-permission-warning to disable the permission warning message(s). This also permits use of the keyserver if it had been disabled (see above). Also check the permissions/ownership of random_seed. * keyserver.c (keyserver_spawn): The new glibc prints a warning when using mktemp() (the code was already secure, but the warning was bound to cause confusion). Use a different implementation based on get_random_bits() instead. Also try a few times to get the temp dir before giving up. 2001-12-19 Werner Koch * g10.c, passphrase.c [CYGWIN32]: Allow this as an alias for MINGW32. 2001-12-18 David Shaw * g10.c (idea_cipher_warn): Add a flag to show the warning always or once per session and change all callers (show always except for the secret key protection and unknown cipher from an encrypted message errors). Also make the strings translatable. * pubkey-enc.c (get_it): Add the IDEA cipher warning if the user tries to decrypt an IDEA encrypted message without the IDEA plugin. * keyserver.c (parse_keyserver_uri): More strict checking of the keyserver URI. Specifically, fail if the ":port" section is anything except a number between 1 and 65535. 2001-12-17 David Shaw * keyserver.c (print_keyinfo): No need to check for control/illegal characters, as utf8_to_native does this for us. * mainproc.c (proc_encrypted): Use generic IDEA warning. * gpgv.c: add stub for idea_cipher_warn * g10.c, hkp.c, keyserver.c: Fix capitalization and plural issues. * encode.c (encode_crypt), sign.c (sign_file, clearsign_file): disable pgp2 mode after the message is no longer pgp2 compatible. * g10.c (main): Tweak the PGP2.x IDEA warning to use the generic warning, and not merely fail if the IDEA plugin isn't there. * g10.c (main, idea_cipher_warn), keygen.c (set_one_pref), seckey-cert.c (do_check): Add a generic IDEA warning for when the IDEA plugin is not present. This pops up when the user uses "--cipher-algo idea", when setpref is used to set a "S1" preference, and when a secret key protected with IDEA is used. 2001-12-15 Werner Koch * keyserver.c (keyserver_spawn): Assert that we have dropped privs. 2001-12-13 Werner Koch * pubkey-enc.c (get_session_key): Check that the public key algorithm is indeed usable for en/decryption. This avoid a strange error message from pubkey_decrypt if for some reasons a bad algorithm indentifier is passed. 2001-12-12 David Shaw * Fixed some types for portability. Noted by Stefan Bellon. 2001-12-11 Werner Koch * hkp.c (hkp_export): Do not print possible control characters from a keyserver response. (parse_hkp_index): Made uid an unsigned char* because it is passed to isspace(). (hkp_search): Ditto for the char* vars. * g10.c (main): Print the IDEA warning also for -c and -se. * g10.c (get_temp_dir): Assert that we have dropped privs * encode.c (encode_crypt): Include the first key into the --pgp2 check. 2001-12-07 David Shaw * g10.c, options.h: New option --pgp2. This is identical to "--rfc1991 --cipher-algo idea --compress-algo 1 --digest-algo md5 --force_v3_sigs" with the addition of an warning to advise the user not to use a pipe (which would break pgp2 compatibility). * encode.c (encode_crypt): warn if the user tries to encrypt to any key that is not RSA and <= 2048 bits when the --pgp2 option is used. * sign.c (sign_file, clearsign_file): When using --pgp2, make a v3 sig, and warn if the signature is made with a non-v3 key. 2001-12-05 David Shaw * sign.c (sign_file, clearsign_file, sign_symencrypt_file): Prompt for sig expiration if --expert is set and --force-v3-sigs is not set (v3 sigs cannot expire). * mainproc.c (check_sig_and_print): After checking a sig, print expiration status. This causes a error return if the sig is expired. * build-packet.c (build_sig_subpkt_from_sig): Include a critical sig expiration subpacket if the sig is to expire. * keyedit.c (sign_uids): Do not sign an expired key unless --expert is set, in which case prompt. Also, offer to expire a signature when the key the user is signing expires. * keygen.c (ask_expire_interval): Add a value to determine whether to prompt for a key or sig expiration and change all callers. * keyid.c: New functions: expirestr_from_sig and colon_expirestr_from_sig. * keylist.c (list_keyblock_colon): Show sig expiration date in the --with-colons listing. * sign.c (make_keysig_packet, write_signature_packets): Pass in an optional timestamp for the signature packet, and change all callers. * keyedit.c (sign_mk_attrib): Include a critical expiration subpacket in the signature if an expiration date is given. 2001-12-04 David Shaw * keyedit.c (sign_uids): If the user tries to sign a locally-signed key, allow the cert to be promoted to a full exportable signature. This essentially deletes the old non-exportable sig, and replaces it with a new exportable one. 2001-12-04 David Shaw * keyedit.c (keyedit_menu): Do not allow signing a revoked key unless --expert is set, and ask even then. * keyedit.c (sign_uids): Do not allow signing a revoked UID unless --expert is set, and ask even then. * g10.c, options.h : New option --expert 2001-11-16 David Shaw * Allow the user to select no compression via "--compress-algo 0" on the command line. * keyedit.c (show_prefs): Show compression preferences in the long-form "showpref" style. * keygen.c (set_one_pref): Permit setting a no-compression ("Z0") preference. * getkey.c (fixup_uidnode): Fix compression preference corruption bug. 2001-12-02 David Shaw * g10.c: Add advisory --for-your-eyes-only option as per section 5.9 of 2440. 2001-12-05 David Shaw * Force a V4 sig if the user has a notation or policy URL set. 2001-12-04 David Shaw * g10.c: Add options --keyserver-options, --temp-directory, and auto-key-retrieve (the opposite of no-auto-key-retrieve). * hkp.c (hkp_search): New function to handle searching a HKP keyserver for a key * hkp.c (hkp_ask_import, hkp_export): Pretty large changes to make them communicate via the generic functions in keyserver.c * keyserver.c: new file with generic keyserver routines for getting keys from a keyserver, sending keys to a keyserver, and searching for keys on a keyserver. Calls the internal HKP stuff in hkp.c for HKP keyserver functions. Other calls are handled by an external program which is spawned and written to and read from via pipes. Platforms that don't have pipes use temp files. 2001-11-20 David Shaw * options.h, g10.c: New options show-notation, no-show-notation, default-check-level, no-default-check-level, show-policy-url, no-show-policy-url. * packet.h, sign.c (make_keysig_packet), parse-packet.c (parse_signature), free-packet.c (free_seckey_enc): Fill in structures for notation, policy, sig class, exportability, etc. * keyedit.c, keylist.c (print_and_check_one_sig, list_keyblock_print): Show flags in signature display for cert details (class, local, notation, policy, revocable). If selected, show the notation and policy url. * keyedit.c (sign_uids): Prompt for and use different key sig classes. * helptext.c (helptexts): Add help text to explain different key signature classes 2001-11-26 David Shaw * trustdb.c (mark_usable_uid_certs): Fix segfault from bad initialization and fix reversed key signature expiration check. 2001-11-09 Werner Koch * export.c (do_export_stream): Put all given names into a search description and change the loop so that all matching names are returned. 2001-11-08 Werner Koch * pubkey-enc.c (get_it): To reduce the number of questions on the MLs print the the name of cipher algorithm 1 with the error message. * mainproc.c: Changed the way old rfc1991 encryption cipher is selected. Based on a patch by W Lewis. * pkclist.c (do_edit_ownertrust): Allow to skip over keys, the non working "show info" is now assigned to "i" * trustdb.c (ask_ownertrust, validate_keys): Implement a real quit here. Both are by David Shaw. * trustdb.c (validate_keys): Make sure next_exipire is initialized. * sign.c (make_keysig_packet): Use SHA-1 with v4 RSA keys. * g10.c, options.h : New option --[no-]froce-v4-certs. * sign.c (make_keysig_packet): Create v4 sigs on v4 keys even with a v3 key. Use that new option. By David Shaw * revoke.c (ask_revocation_reason): Allow to select "no reason". By David Shaw. * keyid.c (fingerprint_from_sk): Calculation of an v3 fpr was plain wrong - nearly the same code in fingerprint_from_pk is correct. * build-packet.c (do_secret_key): Added a few comments to the code. 2001-11-07 Werner Koch * g10.c (main): Print a warning when -r is used w/o encryption. Suggested by Pascal Scheffers. 2001-10-23 Werner Koch * keyedit.c (keyedit_menu): Changed helptext for showpref command. Suggested by Reinhard Wobst. * keyring.c (keyring_search): When marking the offtbl ready, take into account that we may have more than one keyring. 2001-10-22 Werner Koch * Makefile.am: Do not use OMIT_DEPENDENCIES * build-packet.c (build_sig_subpkt): Default is now to put all types of subpackets into the hashed area and only list those which should go into the unhashed area. 2001-10-18 Werner Koch * keydb.c (keydb_add_resource): Rearranged the way we keep track of the resource. There will now be an entry for each keyring here and not in keyring.c itself. Store a token to allow creation of a keyring handle. Changed all functions to utilize this new design. (keydb_locate_writable): Make a real implementation. * keyring.c (next_kr): Removed and changed all callers to set the resource directly from the one given with the handle. (keyring_is_writable): New. (keyring_rebuild_cache): Add an arg to pass the token from keydb. 2001-10-17 Werner Koch * keyring.c (keyring_search): Enabled word search mode but print a warning that it is buggy. 2001-10-11 Werner Koch * hkp.c (hkp_ask_import): No more need to set the port number for the x-hkp scheme. (hkp_export): Ditto. 2001-10-06 Stefan Bellon * passphrase.c [__riscos__]: Disabled agent specific stuff. * g10.c: New option --no-force-v3-sigs. 2001-10-04 Werner Koch * export.c (do_export_stream): Do not push the compress filter here because the context would run out of scope due to the iobuf_close done by the caller. (do_export): Do it here instead. 2001-09-28 Werner Koch * keyedit.c (sign_uids): Always use the primary key to sign keys. * getkey.c (finish_lookup): Hack to return only the primary key if a certification key has been requested. * trustdb.c (cmp_kid_for_make_key_array): Renamed to (validate_one_keyblock): this and changed arg for direct calling. (make_key_array): Renamed to (validate_one_keyblock): this and changed args for direct calling. (mark_usable_uid_certs, validate_one_keyblock) (validate_key_list): Add next_expire arg to keep track of expiration times. (validate_keys): Ditto for UTKs and write the stamp. * tdbio.c (migrate_from_v2): Check return code of tbdio_sync. * tdbdump.c (import_ownertrust): Do a tdbio_sync(). * keyring.c: Made the offtbl an global object. 2001-09-27 Werner Koch * pkclist.c (do_edit_ownertrust): Allow settin of ultimate trust. * trustdb.c (mark_keyblock_seen): New. (make_key_array): Use it to mark the subkeys too. (validate_keys): Store validity for ultimatly trusted keys. 2001-09-26 Werner Koch * pkclist.c (check_signatures_trust, do_we_trust): Removed the invocation of add_ownertrust. Minor changes to the wording. (add_ownertrust, add_ownertrust_cb): Removed. * trustdb.c (get_validity): Allow to lookup the validity using a subkey. * trustdb.c (new_key_hash_table): Increased the table size to 1024 and changed the masks accordingly. (validate): Changed stats printing. (mark_usable_uid_certs): New. (cmp_kid_for_make_key_array): Does now check the signatures and figures out a usable one. 2001-09-25 Werner Koch * keyring.c (new_offset_item,release_offset_items) (new_offset_hash_table, lookup_offset_hash_table) (update_offset_hash_table, update_offset_hash_table_from_kb): New. (keyring_search): Use a offset table to optimize search for unknown keys. (keyring_update_keyblock, keyring_insert_keyblock): Insert new offsets. * getkey.c (MAX_UNK_CACHE_ENTRIES): Removed the unknown keys caching code. * g10.c, options.h, import.c: Removed the entire allow-secret-key-import stuff because the validity is now controlled by other means. * g10.c: New command --rebuild-keydb-caches. * keydb.c (keydb_rebuild_caches): New. * keyring.c (do_copy): Moved some code to (create_tmp_file, rename_tmp_file, write_keyblock): new functions. (keyring_rebuild_cache): New. * packet.h (PKT_ring_trust): Add sigcache field. * parse-packet.c (parse_trust): Parse sigcache. * keyring.c (do_copy): Always insert a sigcache packet. (keyring_get_keyblock): Copy the sigcache packet to the signature. * sig-check.c (cache_sig_result): Renamed from cache_selfsig_result. Changed implementation to use the flag bits and changed all callers. (mdc_kludge_check): Removed this unused code. (do_check): Do not set the sig flags here. * import.c (read_block): Make sure that ring_trust packets are never imported. * export.c (do_export_stream): and never export them. * trustdb.c (make_key_array): Skip revoked and expired keys. 2001-09-24 Werner Koch * g10.c, options.h: New option --no-auto-check-trustdb. * keygen.c (do_generate_keypair): Set newly created keys to ultimately trusted. * tdbio.h, tdbio.c: Removed all support for records DIR, KEY, UID, PREF, SIG, SDIR and CACH. Changed migration function to work direct on the file. (tdbio_read_nextcheck): New. (tdbio_write_nextcheck): New. 2001-09-21 Werner Koch Revamped the entire key validation system. * trustdb.c: Complete rewrite. No more validation on demand, removed some functions, adjusted to all callers to use the new and much simpler interface. Does not use the LID anymore. * tdbio.c, tdbio.h: Add new record types trust and valid. Wrote a migration function to convert to the new trustdb layout. * getkey.c (classify_user_id2): Do not allow the use of the "#" prefix. * keydb.h: Removed the TDBIDX mode add a skipfnc to the descriptor. * keyring.c (keyring_search): Implemented skipfnc. * passphrase.c (agent_open): Add missing bracket. Include windows.h. 2001-09-19 Werner Koch * keylist.c (print_fingerprint): Renamed from fingerprint, made global available. Added new arg to control the print style. * mainproc.c (print_fingerprint): Removed. * pkclist.c (print_fpr, fpr_info): Removed and changed callers to use print_fingerprint. * keyedit.c (show_fingerprint): Ditto. * passphrase.c (writen, readn) (agent_open, agent_close) (agent_get_passphrase) (passphrase_clear_cache): Support for W32. Contributed by Timo. * import.c (import_one): Release keydb handles at 2 more places. * keyring.c (keyring_release): Close the iobuf. (keyring_get_keyblock): Init ret_kb to NULL and store error contidion. * import.c (import_new_stats_handle): New. (import_release_stats_handle): New. (import_print_stats): Renamed from static fnc print_stats. (import_keys, import_keys_stream): Add an optional status handle arg and changed all callers. * hkp.c (hkp_ask_import): Add an stats_handle arg and changed all callers. * mainproc.c (print_pkenc_list): Use print_utf8_string2(). 2001-09-18 Werner Koch * g10.c: New command --refresh-keys. * hkp.c (hkp_refresh_keys): New. Contributed by Timo Schulz. * parse-packet.c (parse): Stop on impossible packet lengths. 2001-09-17 Werner Koch * mainproc.c (print_notation_data): Wrap notation data status lines after 50 chars. * mainproc.c (proc_pubkey_enc): Make option try-all-secrets work. By disastry@saiknes.lv. 2001-09-14 Werner Koch * parse-packet.c (dump_sig_subpkt): List key server preferences and show the revocable flag correctly. Contributed by David Shaw. 2001-09-09 Werner Koch * keyedit.c (keyedit_menu): No need to define another p. * keylist.c (print_capabilities): s/used/use/ so that it does not shadow a global. * sign.c (sign_file): Renamed arg encrypt to encryptflag * keygen.c: Replaced all "usage" by "use". * misc.c (openpgp_pk_algo_usage): Ditto. * pubkey-enc.c (get_it): Renamed arg k to enc so that the later defined k does not shadow it. * parse-packet.c (parse_gpg_control): No need to define another i. * getkey.c (get_pubkey_byfprint): Must use the enum values and not the fprint_len. * keyring.c (keyring_search): Removed a non-sense break. Both bugs pointed out by Stefan. 2001-09-07 Werner Koch * status.c, status.h: Added NO_RECP and ALREADY_SIGNED. * pkclist.c (build_pk_list): Issue NO_RECP. * keyedit.c (sign_uids): Added experimental ALREADY_SIGNED * hkp.c (hkp_import): Use log_error. Bug reported by Neal H Walfield. * getkey.c (classify_user_id2): Change args to take the desc union direct. It was a stupid idea to pass the individual fields of an union to this function. Changed all callers. (classify_user_id): Ditto and allow to pass NULL as the description. 2001-09-06 Werner Koch * getkey.c (fixup_uidnode): Features flag is now a bit vector. * keygen.c (add_feature_mdc): Ditto. Revamped the entire key I/O code to be prepared for other ways of key storages and to get rid of the existing shit. GDBM support has gone. * keydb.c: New * keyring.c, keyring.h: New. * ringedit.c: Removed. Moved some stuff to keyring.c * getkey.c: Changed everything related to the key retrieving functions which are now using the keydb_ functions. (prepare_search, word_match_chars, word_match) (prepare_word_match, compare_name): Moved to keyring.c (get_pubkey_byname): Removed ctx arg and add ret_kdbhd arg. Changed all callers. (key_byname): Use get_pubkey_end to release the context and take new ret_kbdhd arg. Changed all callers. (classify_user_id2): Fill the 16 byte fingerprint up with 4 null bytes not with zero bytes of value 4, tsss. * import.c (import_one): Updated to use the new keydb interface. (import_secret_one): Ditto. (import_revoke_cert): Ditto. * delkey.c (do_delete_key): Ditto. * keyedit.c (keyedit_menu): Ditto. (get_keyblock_byname): Removed. * revoke.c (gen_revoke): Ditto. * export.c (do_export_stream): Ditto. * trustdb.c (update_trustdb): Ditto. * g10.c, gpgv.c (main): Renamed add_keyblock_resource to keydb_add_resource. * Makefile.am: Added and removed files. * keydb.h: Moved KBNODE typedef and MAX_FINGERPRINT_LEN to * global.h: this new header. 2001-09-03 Werner Koch * passphrase.c (agent_get_passphrase): Changed nread to size_t. (passphrase_clear_cache): Ditto. * keyid.c (mk_datestr): Avoid trigraphs. (fingerprint_from_pk): Cache the keyid in the pk. * options.h: Add opt.with_fingerprint so that we know whether the corresponding options was used. * g10.c (main): Set it here. * pkclist.c (check_signatures_trust): Always print fingerprint when this option is used. Mixed a minor memory leak. * status.c, status.h: New status INV_RECP. * pkclist.c (build_pk_list): Issue this status. 2001-08-31 Werner Koch * parse-packet.c (parse_key,parse_pubkeyenc) (parse_signature): Return error on reading bad MPIs. * mainproc.c (check_sig_and_print): Always print the user ID even if it is not bound by a signature. Use the primary UID in the status messages and encode them in UTF-8 * status.c (write_status_text_and_buffer): New. 2001-08-30 Werner Koch * packet.h (sigsubpkttype_t): Add SIGSUBPKT_FEATURES. (PKT_public_key, PKT_user_id): Add a flag for it. * parse-packet.c, build-packet.c: Add support for them. * getkey.c (fixup_uidnode, merge_selfsigs): Set the MDC flags. * keygen.c (add_feature_mdc): New. (keygen_upd_std_prefs): Always set the MDC feature. * keyedit.c (show_prefs): List the MDC flag * pkclist.c (select_mdc_from_pklist): New. * encode.c (encode_crypt, encrypt_filter): Test whether MDC should be used. * cipher.c (write_header): Set MDC use depending on the above test. Print more status info. * delkey.c (do_delete_key): Kludge to delete a secret key with no public key available. * ringedit.c (find_secret_keyblock_direct): New. * getkey.c (seckey_available): Simplified. * ringedit.c (cmp_seckey): Now compares the secret key against the public key while ignoring all secret parts. (keyring_search): Use a public key packet as arg. Allow to search for subnkeys (search): Likewise. Changed all callers. (find_secret_keyblock_bypk): New. (find_secret_keyblock_byname): First locate the pubkey and then find the correponding secret key. * parse-packet.c (parse): Renamed pkttype arg to onlykeypkts and changed code accordingly. Changed all callers. (search_packet): Removed pkttype arg. * keyedit.c (keyedit_menu): First locate the public key and then try to locate a secret key. * ringedit.c (locate_keyblock_by_fpr): Removed. (locate_keyblock_by_keyid): Removed. (find_keyblock_bysk): Removed. * sig-check.c (check_key_signature2): Print the keyid along with the wrong sig class errors. 2001-08-24 Werner Koch * sign.c (sign_file): Stripped the disabled comment packet code. (sign_file, sign_symencrypt_file): Moved common code to .. (write_onepass_sig_packets): .. this new function. (sign_file, clearsign_file, sign_symencrypt_file): Moved common code to (write_signature_packets): this new function. (write_signature_packets, make_keysig_packet) (update_keysig_packet): Moved common code to (hash_uid, hash_sigclass_to_magic): these new functions (sign_file, sign_symencrypt_file): Moved common code to (write_plaintext_packet): this new function. 2001-08-21 Stefan Bellon * trustdb.c (query_trust_info): Changed trustlevel to signed int. * g10.c [__riscos__]: Fixed handling of --use-agent --lock-multiple. 2001-08-20 Werner Koch * encr-data.c (decrypt_data): Keep track on whether we already printed information about the used algorithm. * mainproc.c (proc_encrypted): Removed the non-working IDEA hack and print a message about the assumed algorithm. * passphrase.c (passphrase_to_dek): Use the same algorithm as above. (proc_symkey_enc): Print the algorithm, so that the user knows it before entering the passphrase. (proc_pubkey_enc, proc_pubkey_enc): Zero the DEK out. * encode.c (encode_crypt, encrypt_filter): Ditto. * g10.c: Allow for --sign --symmetric. * sign.c (sign_and_symencrypt): New. Applied patches from Stefan Bellon to support RISC OS. Nearly all of these patches are identified by the __riscos__ macro. * compress.c: Added a couple of casts. * g10.c [__riscos__]: Some patches and new options foo-file similar to all foo-fd options. * gpgv.c, openfile.c, ringedit.c, tdbio.c: Minor fixes. Mainly replaced hardcoded path separators with EXTSEP_S like macros. * passprase.c [__riscos__]: Disabled agent stuff * trustdb.c (check_trust): Changed r_trustlevel to signed int to avoid mismatch problems in pkclist.c * pkclist.c (add_ownertrust): Ditto. * plaintext.c (handle_plaintext) [__riscos__]: Print a note when file can't be created. * options.h [__riscos__]: Use an extern unless included from the main module. * signal.c (got_fatal_signal) [__riscos__]: Close all files. 2001-08-14 Werner Koch * keygen.c (ask_algo): New arg r_usage. Allow for RSA keys. (gen_rsa): Enabled the code. (do_create): Enabled RSA branch. (parse_parameter_usage): New. (proc_parameter_file): Handle usage parameter. (read_parameter_file): Ditto. (generate_keypair): Ditto. (generate_subkeypair): Ditto. (do_generate_keypair): Ditto. (do_add_key_flags): New. (keygen_add_std_prefs): Use the new function. (keygen_add_key_flags_and_expire): New. (write_selfsig, write_keybinding): Handle new usage arg. * build-packet.c (build_sig_subpkt): Make sure that key flags go into the hashed area. * keygen.c (write_uid): Initialize the reference cunter. * keyedit.c (keyedit_menu): No more need to update the trustdb for preferences. Added calls to merge keblock. * kbnode.c (dump_kbnode): Print some more flags. 2001-08-10 Werner Koch Revamped the preference handling. * packet.h (prefitem_t, preftype_t): New. (PKT_public_key): Added a uid field. (PKT_user_id): Added field to store preferences and a reference counter. * parse-packet.c (parse_user_id,parse_photo_id): Initialize them * free-packet.c (free_user_id): Free them. (copy_user_id): Removed. (scopy_user_id): New. (cmp_user_ids): Optimized for identical pointers. (release_public_key_parts): Release the uid. (copy_public_key_with_new_namehash): Removed. (copy_prefs): New. * keyedit.c (menu_adduid): Use the new shallow copy user id. (show_prefs): Adjusted implementation. (keyedit_menu): No more need to update the trustdb after changing preferences. * getkey.c (fixup_uidnode): Store preferences. (find_by_name): Return a user id packet and remove namehash stuff. (lookup): Removed the unused namehash stuff. (finish_lookup): Added foundu arg. (pk_from_block): Removed the namehash arg and changed all callers. (merge_selfsigs): Copy prefs to all keys. * trustdb.c (get_pref_data): Removed. (is_algo_in_prefs): Removed. (make_pref_record): Deleted and removed all class. * pkclist.c (select_algo_from_prefs): Adjusted for the new preference implementation. * pubkey-enc.c (is_algo_in_prefs): New. (get_it): Use that new function. 2001-08-09 Werner Koch * build-packet.c (build_sig_subpkt): Fixed calculation of newarea->size. * g10.c (main): New option "--preference-list" * keyedit.c (keyedit_menu): New commands "setpref" and "updpref". (menu_set_preferences): New. * keygen.c (keygen_set_std_prefs): New. (set_one_pref): New. (check_zip_algo): New. (keygen_get_std_prefs): New. (keygen_upd_std_prefs): New (keygen_add_std_prefs): Move the pref setting code into the above fnc. * build-packet.c (build_sig_subpkt): Updated the list of allowed to update subpackets. 2001-08-08 Werner Koch * packet.h (subpktarea_t): New. (PKT_signature): Use that type for hashed_data and unhashed_data and removed the _data prefix from those fields. Changed all users. * parse-packet.c (parse_signature): Changed allocation for that. (parse_sig_subpkt): Changed declaration (enum_sig_subpkt): Ditto and changed implementation accordingly. * free-packet.c (cp_subpktarea): Renamed from cp_data_block and adjusted implementation. Changed caller. * sig-check.c (mdc_kludge_check): Adjusted the hashing. (do_check): Ditto. * sign.c (sign_file, clearsign_file, make_keysig_packet, update_keysig_packet): Ditto. * build-packet.c (build_sig_subpkt): Partial rewrite. (find_subpkt): Adjusted and made static. (delete_sig_subpkt): Adjusted. (do_signature): Ditto. * keygen.c (ask_keysize): Do not print the notes about suggested key sizes if just a DSA key is generated. * trustdb.c (add_ultimate_key): s/log_error/log_info/ for duplicated inserted trusted keys. 2001-08-07 Werner Koch * sign.c (sleep): Redefine for W32. * g10.c, options.h: Set new flag opt.no_homedir_creation when --no-options is given. * openfile.c (try_make_homedir): Don't create the homedir in that case. 2001-08-03 Werner Koch * armor.c (armor_filter): Removed the default comment string because it could get us in trouble due to translations using non ascii characters. 2001-08-01 Werner Koch * keylist.c (list_keyblock_print): Do not list revoked UIDs unless in verbose mode and we do no signature listing. * getkey.c (finish_lookup): Skip subkeys which are not yet valid. * g10.c, options.h: New option --ignore-valid-from. * sign.c (make_keysig_packet): Added new sigversion argument to allow the caller to force generation of required signature version. Changed all callers. Suggested by Thomas Roessler. * keyedit.c (sign_uids): Force v4 signature generation for local sigs. Removed the check for local signature and pre-v4 keys. 2001-07-27 Werner Koch * keyedit.c (sign_uids): Check that we are not trying to to a lsign with a pre-v4 key. Bug noticed by Thomas Roessler. 2001-07-26 Werner Koch * parse-packet.c (parse_photo_id): Reset all variables. * getkey.c (merge_selfsigs_main): Removed checks on PHOTO_ID because this is handled identically to a user ID. 2001-07-06 Werner Koch * cipher.c (write_header): Don't use MDC with --rfc1991. Suggested by disastry@saiknes.lv. 2001-07-05 Werner Koch * g10.c, options.h: New option --preserve-permissions. * ringedit.c (add_keyblock_resource): Use it here (keyring_copy): and here. * trustdb.c (verify_own_keys): Be more silent on --quiet. Suggested by Thomas Roessler. * sig-check.c (check_key_signature2): Ditto. * mainproc.c (proc_encrypted, proc_tree): Ditto * getkey.c (lookup): Ditto. 2001-07-04 Werner Koch * ringedit.c (add_keyblock_resource): Restore filename in case of error. 2001-06-25 Werner Koch * kbnode.c (dump_kbnode): Print the signature timestamp. * keyedit.c (keyedit_menu): New menu point "primary". (change_primary_uid_cb): New. (menu_set_primary_uid): New. * sign.c (update_keysig_packet): New. * build-packet.c (build_sig_subpkt): Put the primary UID flag into the hashed area. Allow update of some more packets. 2001-06-15 Werner Koch * getkey.c (merge_selfsigs): Exit gracefully when a secret key is encountered. May happen if a secret key is in public keyring. Reported by Francesco Potorti. 2001-06-12 Werner Koch * getkey.c (compare_name): Use ascii_memistr(), ascii_memcasecmp() * keyedit.c (keyedit_menu): Use ascii_strcasecmp(). * armor.c (radix64_read): Use ascii_toupper(). * ringedit.c (do_bm_search): Ditto. * keygen.c (read_parameter_file): Ditto. * openfile.c (CMP_FILENAME): Ditto. * g10.c (i18n_init): We can now use just LC_ALL. 2001-05-29 Werner Koch * keygen.c (generate_subkeypair): Print a warning if a subkey is created on a v3 key. Suggested by Brian M. Carlson. 2001-05-27 Werner Koch * keyid.c (get_lsign_letter): New. * keylist.c (list_keyblock_colon): Use it here. * mainproc.c (list_node): and here. * getkey.c, packet.h, free-packet.c: Removed that useless key created field; I dunno why I introducded this at all - the creation time is always bound to the key packet and subject to fingerprint calculation etc. * getkey.c (fixup_uidnode): Add keycreated arg and use this instead of the signature timestamp to calculate the help_key_expire. Bug reported by David R. Bergstein. (merge_selfsigs_main): Correct key expiration time calculation. (merge_selfsigs_subkey): Ditto. 2001-05-25 Werner Koch * revoke.c (gen_revoke): Add a cast to a tty_printf arg. * delkey.c (do_delete_key): Ditto. * keyedit.c (print_and_check_one_sig): Ditto. (ask_revoke_sig): Ditto. (menu_revsig): Ditto. (check_all_keysigs): Removed unused arg. 2001-05-23 Werner Koch * g10.c (opts): Typo fix by Robert C. Ames. 2001-05-06 Werner Koch * revoke.c: Small typo fix 2001-05-04 Werner Koch * passphrase.c (passphrase_clear_cache): Shortcut if agent usage is not enabled. 2001-05-01 Werner Koch * passphrase.c (writen): Replaced ssize_t by int. Thanks to to Robert Joop for reporting that SunOS 4.1.4 does not have it. 2001-04-28 Werner Koch * getkey.c (merge_public_with_secret): pkttype was not set to subkey. 2001-04-27 Werner Koch * skclist.c (build_sk_list): Changed one log_debug to log_info. 2001-04-25 Werner Koch * keyedit.c (show_prefs): Add a verbose mode. (show_key_with_all_names): Pass verbose flag for special value of with_pref. (keyedit_menu): New command "showpref" (show_key_with_all_names): Mark revoked uids and the primary key. 2001-04-24 Werner Koch * getkey.c (get_primary_uid): Return a different string in case of error and made it translatable. * build-packet.c (do_secret_key): Ugly, we wrote a zero instead of the computed ndays. Thanks to M Taylor for complaining about a secret key import problem. 2001-04-23 Werner Koch * hkp.c (hkp_ask_import): Allow to specify a port number for the keyserver. Add a kudge to set the no_shutdown flag. (hkp_export): Ditto. * options.skel: Document the changes 2001-04-20 Werner Koch * options.skel: Add some more comments. 2001-04-19 Werner Koch * keyid.c (mk_datestr): New. Handles negative times. We must do this because Windoze segvs on negative times passed to gmtime(). Changed all datestr_from function to use this one. * keyid.c, keyid.h (colon_strtime): New. To implement the fixed-list-mode. (colon_datestr_from_pk): New. (colon_datestr_from_sk): New. (colon_datestr_from_sig): New. * keylist.c (list_keyblock_colon): Use these functions here. * mainproc.c (list_node): Ditto. 2001-04-18 Werner Koch * openfile.c (open_sigfile): Fixed the handling of ".sign". * mainproc.c (proc_tree): Use iobuf_get_real_fname. Both are by Vincent Broman. 2001-04-14 Werner Koch * getkey.c (fixup_uidnode): Removed check for !sig which is pointless here. Thanks to Jan Niehusmann. 2001-04-10 Werner Koch * sig-check.c (check_key_signature2): Use log_info instead of log_error so that messed up keys do not let gpg return an error. Suggested by Christian Kurz. * getkey.c (merge_selfsigs_main): Do a fixup_uidnode only if we have both, uid and sig. Thanks to M Taylor. 2001-04-05 Werner Koch * armor.c (unarmor_pump_new,unarmor_pump_release): New. (unarmor_pump): New. * pipemode.c (pipemode_filter): Use the unarmor_pump to handle armored or non-armored detached signatures. We can't use the regular armor_filter because this does only check for armored signatures the very first time. In pipemode we may have a mix of armored and binary detached signatures. * mainproc.c (proc_tree): Do not print the "old style" notice when this is a pipemode processes detached signature. (proc_plaintext): Special handling of pipemode detached sigs. * packet.h (CTRLPKT_PLAINTEXT_MARK): New. * parse-packet.c (create_gpg_control): New. * kbnode.c (dump_kbnode): Support it here. * mainproc.c (check_sig_and_print): Fixed the check for bad sequences of multiple signatures. (proc_plaintext): Add the marker packet. (proc_tree): We can now check multiple detached signatures. 2001-04-02 Werner Koch The length of encrypted packets for blocksizes != 8 was not correct encoded. I think this is a minor problem, because we usually use partial length packets. Kudos to Kahil D. Jallad for pointing this out. * packet.h: Add extralen to PKT_encrypted. * cipher.c (write_header): Set extralen. * build-packet.c (do_encrypted): Use extralen instead of const 10. (do_encrypted_mdc): Ditto. * parse-packet.c (parse_encrypted): Set extralen to 0 because we don't know it here. 2001-03-30 Werner Koch * getkey.c (premerge_public_with_secret): Changed wording an add the keyID to the info message. 2001-03-29 Werner Koch * getkey.c (premerge_public_with_secret): Use log_info instead of log_error when no secret key was found for a public one. Fix the usage if the secret parts of a key are not available. * openfile.c (ask_outfile_name): Trim spaces. (open_outfile): Allow to enter an alternate filename. Thanks to Stefan Bellon. * plaintext.c (handle_plaintext): Ditto. 2001-03-28 Werner Koch * mainproc.c (do_check_sig): Allow direct key and subkey revocation signature. * sig-check.c (check_key_signature2): Check direct key signatures. Print the signature class along with an error. 2001-03-27 Werner Koch * packet.h: Add a missing typedef to an enum. Thanks to Stefan Bellon. * g10.c: New option --no-sig-create-check. * sign.c (do_sign): Implement it here. * g10.c: New option --no-sig-cache. * sig-check.c (check_key_signature2): Implement it here. (cache_selfsig_result): and here. * keylist.c (list_keyblock): Removed debugging stuff. * getkey.c (cache_public_key): Made global. * keygen.c (write_selfsig, write_keybinding): Cache the new key. * getkey.c (key_byname): Add new arg secmode and changed all callers to request explicitly the mode. Deriving this information from the other supplied parameters does not work if neither pk nor sk are supplied. 2001-03-25 Werner Koch * packet.h (ctrlpkttype_t): New. * mainproc.c (add_gpg_control,proc_plaintext,proc_tree): Use the new enum values. * pipemode.c (make_control): Ditto. * armor.c (armor_filter): Ditto. 2001-03-24 Werner Koch * sign.c (do_sign): Verify the signature right after creation. 2001-03-23 Werner Koch * status.c, status.h (STATUS_UNEXPECTED): New. * mainproc.c (do_proc_packets): And emit it here. 2001-03-21 Werner Koch * status.c: Add sys/types.h so that it runs on Ultrix. Reported by Georg Schwarz.x * build-packet.c (build_sig_subpkt): Fixed generaton of packet length header in case where 2 bytes headers are needed. Thanks to Piotr Krukowiecki. 2001-03-19 Werner Koch * g10.c (main): the default keyring is no always used unless --no-default-keyring is given. * ringedit.c (add_keyblock_resource): invalidate cache after file creation. 2001-03-15 Werner Koch * keygen.c (ask_algo): Changed the warning of the ElGamal S+E Algo. * keylist.c (print_capabilities): New. (list_keyblock_colon): and use it here. 2001-03-13 Werner Koch * main.c, options.h: New option --fixed_list_mode. * keylist.c (list_keyblock_colon): use it here. * getkey.c (merge_keys_and_selfsig): Divert merging of public keys to the function used in key selection.. * keylist.c (is_uid_valid): Removed. (list_keyblock): Splitted into .. (list_keyblock_print, list_keyblock_colon): .. these. functions. Changed them to use the flags set in the key lookup code. (reorder_keyblock): New, so that primary user IDs are listed first. * ringedit.c (keyring_copy): flush the new iobuf chaces before rename or remove operations. This is mainly needed for W32. * hkp.c [HAVE_DOSISH_SYSTEM]: Removed the disabled code because we have now W32 socket support in ../util/http.c * skclist.c (key_present_in_sk_list): New. (is_duplicated_entry): New. (build_sk_list): Check for duplicates and do that before unlocking. 2001-03-12 Werner Koch * armor.c (parse_header_line): Removed double empty line check. (parse_header_line): Replaced trim_trailing_ws with a counting function so that we can adjust for the next read. * options.skel: Fixed 3 typos. By Thomas Klausner. Replaced the keyserver example by a better working server. * parse-packet.c (parse_symkeyenc): Return Invalid_Packet on error. (parse_pubkeyenc): Ditto. (parse_onepass_sig): Ditto. (parse_plaintext): Ditto. (parse_encrypted): Ditto. (parse_signature): Return error at other places too. (parse_key): Ditto. * g10.c (main): Set opt.list_packets to another value when invoked with the --list-packets command. * mainproc.c (do_proc_packets): Don's stop processing when running under --list-packets command. * signal.c (do_sigaction): Removed. (init_one_signal): New to replace the above. Needed to support systems without sigactions. Suggested by Dave Dykstra. (got_fatal_signal,init_signals): Use the above here. (do_block): Use sigset() if sigprocmask() is not available. * armor.c (parse_hash_header): Test on TIGER192, which is the correct value as per rfc2440. By Edwin Woudt. 2001-03-08 Werner Koch * misc.c: Include time.h. By James Troup. * getkey.c: Re-enabled the unknown user Id and PK caches and increased their sizes. * getkey.c (merge_selfsigs_main): Set expire date and continue processing even if we found a revoked key. (merge_selfsigs_subkeys): Ditto. * packet.h: Add an is_revoked flag to the user_id packet. * getkey.c (fixup_uidnode): Set that flag here. (merge_selfsigs_main): Fix so that the latest signature is used to find the self-signature for an UID. * parse-packet.c (parse_user_id): Zero out all fields. * mainproc.c (check_sig_and_print): Print the primary user ID according the the node flag and then all other non-revoked user IDs. (is_uid_revoked): Removed; it is now handled by the key selection code. Changed the year list of all copyright notices. 2001-03-07 Werner Koch * getkey.c (finish_lookup): Print an info message only in verbose mode. 2001-03-05 Werner Koch * packet.h: Replaced sigsubpkt_t value 101 by PRIV_VERIFY_CACHE. We have never used the old value, so we can do this without any harm. * parse-packet.c (dump_sig_subpkt): Ditto. (parse_one_sig_subpkt): Parse that new sub packet. * build-packet.c (build_sig_subpkt): Removed the old one from the hashed area. (delete_sig_subpkt): New. (build_sig_subpkt): Allow an update of that new subpkt. * sig-check.c (check_key_signature2): Add verification caching (cache_selfsig_result): New. * export.c (do_export_stream): Delete that sig subpkt before exporting. * import.c (remove_bad_stuff): New. (import): Apply that function to all imported data 2001-03-03 Werner Koch * getkey.c: Introduced a new lookup context flag "exact" and used it in all place where we once used primary. (classify_user_id2): Replaced the old function and add an extra argument to return whether an exact keyID has been requested. (key_byname): Removed the unused ctx.primary flag (get_seckey_byname2): Ditto. (finish_lookup): Changed debugging output. 2001-03-02 Werner Koch * keylist.c (list_one): Remove the merge key calls. 2001-03-01 Werner Koch * getkey.c (finish_lookup): Don't use it if we no specific usage has been requested. (merge_selfsigs_main): fix UID only if we have an signature. (lookup): Return UNU_PUBKEY etc. instead of NO_PUBKEY if we found a key but the requested usage does not allow this key. * import.c (import_one): Take UNU_PUBKEY into account. * mainproc.c (list_node): Ditto. * keylist.c (list_keyblock): Ditto. * keyedit.c (print_and_check_one_sig): Ditto. 2001-02-09 Werner Koch * delkey.c (delete_key): Removed that silly assert which rendered the whole new stuff meaningless. 2001-02-08 Werner Koch * getkey.c (key_byname): It can happen that we have both, sk and pk NULL, fix for that. * parse-packet.c (parse_one_sig_subpkt): Add support for primary_uid and key_flags. (can_handle_critical): Ditto * parse-packet.c (parse_encrypted): Fixed listing of pktlen for MDC packets. * getkey.c: Backported the version of this file from gpg 1.1. this involved some changes in other files too. * parse-packet.c (parse_key): Clear req_usage. * skclist.c (build_sk_list): Use req_usage to pass the usage information to the lookup function. * pkclist.c (build_pk_list): Ditto. * free-packet.c (copy_public_parts_to_secret_key): New. * keydb.h: Add IS_* macros to check the sig_class. * misc.c (openpgp_cipher_test_algo): New. (openpgp_pk_test_algo): New. (openpgp_pk_algo_usage): New. (openpgp_md_test_algo): New. * packet.h: Add a few fields to PKT_{public,secret}_key and PKT_user_id. * seckey-cert.c (do_check): Use the new main_keyid field. 2001-02-04 Werner Koch * encr-data.c (decrypt_data): Catch error when we had problems to parse the encrypted packet. By Timo. 2001-01-29 Werner Koch * g10.c (main): --batch does now set nogreeting. * delkey.c (do_delete_key): Fixed delete-both functionality. 2001-01-22 Werner Koch * g10.c: New command --delete-secret-and-public-key. * delkey.c (delete_key): Add new arg allow_both. (do_delete_key): Move most stuff from above to this new function. 2001-01-12 Werner Koch * passphrase.c (passphrase_to_dek): Use MD5 when IDEA is installed and we have no S2K. * mainproc.c (proc_encrypted): Likewise 2001-01-11 Werner Koch * sig-check.c (do_check): Print the signature key expire message only in verbose mode and added the keyID. 2001-01-09 Werner Koch * status.c, status.h: New status USERID_HINT. (write_status_text): Replace LF and CR int text by C-escape sequence. * passphrase.c (passphrase_to_dek): Fixed the NEED_PASSPHRASE output. It does now always print 2 keyIDs. Emit the new USERID_HINT. 2001-01-08 Werner Koch * g10.c, options.h: New option --no-expensive-trust-checks. * keylist.c (list_keyblock): Act on this option. 2001-01-04 Werner Koch * g10.c (main): Set homedir only in the pre-parsing phase and replace backslashes in the W32 version. 2001-01-03 Werner Koch * status.c, status.h : New status KEY_CREATED * keygen.c (do_generate_keypair,generate_subkeypair): Emit it. 2000-12-28 Werner Koch * signal.c (got_fatal_signal): Remove lockfiles here because the atexit stuff does not work due to the use of raise. Suggested by Peter Fales. * gpgv.c (remove_lockfiles): New stub. 2000-12-19 Werner Koch * status.c, status.h (cpr_get_no_help): New. * keyedit.c (keyedit_menu): Use it here because we have our own help list here. 2000-12-18 Werner Koch * mainproc.c (print_failed_pkenc): Don't print the sometimes confusing message about unavailabe secret key. Renamed ... (print_pkenc_list): ... to this and introduced failed arg. (proc_encrypted): Print the failed encryption keys and then the one to be used. (proc_pubkey_enc): Store also the key we are going to use. * mainproc.c (check_sig_and_print): Don't list revoked user IDs. (is_uid_revoked): New. 2000-12-08 Werner Koch * pipemode.c: Made the command work. Currently only for non-armored detached signatures. * mainproc.c (release_list): Reset the new pipemode vars. (add_gpg_control): Handle the control packets for pipemode * status.c, status.h: New stati {BEGIN,END}_STREAM. 2000-12-07 Werner Koch * g10.c: New option --allow-secret-key-import. * import.c (import_keys,import_keys_stream): Honor this option. (import): New arg allow_secret and pass that arg down to ... (import_secret_one): to this and print a warning if secret key importing is not allowed. 2000-12-05 Werner Koch * cipher.c (cipher_filter): Moved the end_encryption status ... * encode.c (encode_simple,encode_crypt): to here * sign.c (sign_file): and here. * status.c (mywrite): Removed. (get_status_string): Removed the LFs from the strings. (set_status_fd,is_status_enabed,write_status_text, write_status_buffer): Replaced all mywrite by stdio calls and use fdopen to create a strem. This is needed to make things smoother in the W32 version. 2000-12-04 Werner Koch * import.c (merge_blocks): Increment n_sigs for revocations. 2000-11-30 Werner Koch * g10.c (main): Use iobuf_translate_file_handle for all options with filehandles as arguments. This is function does some magic for the W32 API. * verify.c (verify_signatures): Add a comment rant about the detached signature problem. * mainproc.c (proc_tree): Issue an error if a detached signature is assumed but a standard one was found. * plaintext.c (hash_datafiles): Don't fall back to read signature from stdin. * openfile.c (open_sigfile): Print verbose message only if the file could be accessed. 2000-11-24 Werner Koch * passphrase.c [HAVE_DOSISH_SYSTEM]: Disabled all the agent stuff. 2000-11-16 Werner Koch * g10.c: New option --use-agent * passphrase.c (agent_open,agent_close): New. (agent_get_passphrase,agent_clear_passphrase): New. (passphrase_clear_cache): New. (passphrase_to_dek): Use the agent here. * seckey-cert.c (do_check): Clear cached passphrases. 2000-11-15 Werner Koch * status.c (write_status_text): Moved the big switch to ... (get_status_string): ... new function. (write_status_buffer): New. * status.c (mywrite): New and replaced all write() by this. * status.c, status.h: Add 3 status lcodes for notaions and policy. * mainproc.c (print_notation_data): Do status output of notations. 2000-11-13 Werner Koch * sign.c (clearsign_file): Use LF macro to print linefeed. 2000-11-11 Paul Eggert Clean up the places in the code that incorrectly use "long" or "unsigned long" for file offsets. The correct type to use is "off_t". The difference is important on large-file hosts, where "off_t" is longer than "long". * keydb.h (struct keyblock_pos_struct.offset): Use off_t, not ulong, for file offsets. * packet.h (dbg_search_packet, dbg_copy_some_packets, search_packet, copy_some_packets): Likewise. * parse-packet.c (parse, dbg_search_packet, search_packet, dbg_copy_some_packets, copy_some_packets): Likewise. * ringedit.c (keyring_search): Likewise. * parse-packet.c (parse): Do not use %lu to report file offsets in error diagnostics; it's not portable. * ringedit.c (keyring_search): Likewise. 2000-11-09 Werner Koch * g10.c (main): New option --enable-special-filenames. 2000-11-07 Werner Koch * g10.c (main): New command --pipemode. * pipemode.c: New. 2000-10-23 Werner Koch * armor.c (armor_filter): Changed output of hdrlines, so that a CR is emitted for DOS systems. * keygen.c (read_parameter_file): Add a cast for isspace(). * status.c (myread): Use SIGINT instead of SIGHUP for DOS. 2000-10-19 Werner Koch * g10.c: New option --ignore-crc-error * armor.c (invalid_crc): New. (radix64_read): Act on new option. * openfile.c (try_make_homedir): Klaus Singvogel fixed a stupid error introduced on Sep 6th. 2000-10-18 Werner Koch * misc.c (print_cipher_algo_note): Don't print the note for AES. Changed wording. 2000-10-16 Werner Koch * mainproc.c (do_proc_packets): Hack to fix the problem that signatures are not detected when there is a MDC packet but no compression packet. * g10.c (print_hashline): New. (print_mds): Use above func with --with-colons. * mainproc.c (check_sig_and_print): Detect multiple signatures and don't verify them. 2000-10-14 Werner Koch * mainproc.c (add_onepass_sig): There is an easier solution to the error fixed yesterday; just check that we only have onepass packets. However, the other solution provides an cleaner interface and opens the path to get access to other information from the armore headers. (release_list): Reset some more variables. 2000-10-13 Werner Koch * mainproc.c (add_gpg_control): New. (do_proc_packets): use it. (proc_plaintext): Changed logic to detect clearsigns. (proc_tree): Check the cleartext sig with some new code. * packet.h: New packet PKT_GPG_CONTROL. * parse-packet.c (parse_gpg_control): New. * misc.c (get_session_marker): New. * armor.c (armor_filter): Replaced the faked 1-pass packet by the new control packet. * keyedit.c (keyedit_menu): Allow batchmode with a command_fd. * status.c (my_read): New. (do_get_from_fd): use it. 2000-10-12 Werner Koch * keygen.c (keygen_add_std_prefs): Add Rijndael to the prefs. 2000-10-07 Werner Koch * gpgv.c: Add more stubs for ununsed code to make the binary smaller. Wed Oct 4 15:50:18 CEST 2000 Werner Koch * sign.c (hash_for): New arg to take packet version in account, changed call callers. * gpgv.c: New. * Makefile.am: Rearranged source files so that gpgv can be build with at least files as possible. Mon Sep 18 12:13:52 CEST 2000 Werner Koch * hkp.c (not_implemented): Print a notice for W32 Fri Sep 15 18:40:36 CEST 2000 Werner Koch * keygen.c (keygen_add_std_prefs): Changed order of preferences to twofish, cast5, blowfish. * pkclist.c (algo_available): Removed hack to disable Twofish. Thu Sep 14 17:45:11 CEST 2000 Werner Koch * parse-packet.c (dump_sig_subpkt): Dump key flags. Print special warning in case of faked ARRs. * getkey.c (finsih_lookup): Hack so that for v4 RSA keys the subkey is used for encryption. Thu Sep 14 14:20:38 CEST 2000 Werner Koch * g10.c (main): Default S2K algorithms are now SHA1 and CAST5 - this should solve a lot of compatibility problems with other OpenPGP apps because those algorithms are SHOULD and not optional. The old way to force it was by using the --openpgp option whith the drawback that this would disable a couple of workarounds for PGP. * g10.c (main): Don't set --quite along with --no-tty. By Frank Tobin. * misc.c (disable_core_dump): Don't display a warning here but a return a status value and ... * g10.c (main): ...print warnining here. Suggested by Sam Roberts. Wed Sep 13 18:12:34 CEST 2000 Werner Koch * keyedit.c (keyedit_menu): Allow to use "debug" on the secret key. * ringedit.c (cmp_seckey): Fix for v4 RSA keys. * seckey-cert.c (do_check): Workaround for PGP 7 bug. Wed Sep 6 17:55:47 CEST 2000 Werner Koch * misc.c (print_pubkey_algo_note): Do not print the RSA notice. * sig-check.c (do_signature_check): Do not emit the RSA status message. * pubkey-enc.c (get_session_key): Ditto. * encode.c (encode_simple, encode_crypt): Fix for large files. * sign.c (sign_file): Ditto. Wed Sep 6 14:59:09 CEST 2000 Werner Koch * passphrase.c (hash_passphrase): Removed funny assert. Reported by David Mathog. * openfile.c (try_make_homedir): Changes for non-Posix systems. * g10.c (main): Take the default homedir from macro. * g10.c: The --trusted-key option is back. * trustdb.c (verify_own_key): Handle this option. (add_ultimate_key): Moved stuff from verify_own_key to this new func. (register_trusted_key): New. Fri Aug 25 16:05:38 CEST 2000 Werner Koch * parse-packet.c (dump_sig_subpkt): Print info about the ARR. * openfile.c (overwrite_filep): Always return okay if the file is called /dev/null. (make_outfile_name): Add ".sign" to the list of know extensions. (open_sigfile): Ditto. Wed Aug 23 19:52:51 CEST 2000 Werner Koch * g10.c: New option --allow-freeform-uid. By Jeroen C. van Gelderen. * keygen.c (ask_user_id): Implemented here. Fri Aug 4 14:23:05 CEST 2000 Werner Koch * status.c (do_get_from_fd): Ooops, we used fd instead of opt.command_fd. Thanks to Michael Tokarev. Tue Aug 1 20:06:23 CEST 2000 Werner Koch * g10.c: New opttion --try-all-secrets on suggestion from Matthias Urlichs. * pubkey-enc.c (get_session_key): Quite easy to implement here. Thu Jul 27 17:33:04 CEST 2000 Werner Koch * g10.c: New option --merge-only. Suggested by Brendan O'Dea. * import.c (import_one): Implemented it here (import_secret_one): Ditto. (print_stats): and give some stats. Thu Jul 27 12:01:00 CEST 2000 Werner Koch * g10.c: New options --show-session-key and --override-session-key * pubkey-enc.c (hextobyte): New. (get_override_session_key): New. * mainproc.c (proc_pubkey_enc): Add session-key stuff. * status.h, status.c (STATUS_SESSION_KEY): New. Thu Jul 27 10:02:38 CEST 2000 Werner Koch * g10.c (main): Use setmode(O_BINARY) for MSDOS while generating random bytes (print_mds): Likewise for stdin. * plaintext.c (handle_plaintext): Likewise for stdout. Mon Jul 24 10:30:17 CEST 2000 Werner Koch * keyedit.c (menu_expire): expire date for primary key can be set again. Wed Jul 19 11:26:43 CEST 2000 Werner Koch * keylist.c (is_uid_valid): New. (list_keyblock): Print validity information for all user IDs. Note, this has to be done at other places too; for now we have only minimal support. Wed Jul 12 13:32:06 CEST 2000 Werner Koch * helptext.c, pkclist.c: s/superseeded/superseded/ Mon Jul 10 16:08:57 CEST 2000 Werner Koch * parse-packet.c (enum_sig_subpkt): Fixed testing on crtitical bit in case of a NULL buffer. Reported by Peter Marschall. Wed Jul 5 13:28:45 CEST 2000 Werner Koch * keyedit.c, keyid.c: Add some _() * argparse.c: Changed the flag to suppress --version handling to also suppress --help. Wed Jun 28 11:54:44 CEST 2000 Werner Koch * armor.c (armor_filter): Set sigclass to 0 in case of non-dash-escaped clearsig. This makes this mode work again. * mainproc.c (proc_tree): Fixed handling of one-pass-sig packets in textmode. Disabled the ugly workaround for PGP 5 - let's see whether thi breaks less cases. Found by Ted Cabeen. * options.h (DBG_HASHING): New. All commented md_start_debug are now controlled by this debug option. * sign.c (print_status_sig_created): New and called from 2 places. * keygen.c (gen_rsa): New, but commented. (ask_algo): Commented support for RSA. * seckey-cert.c (protect_secret_key): Started to fix the code for v4 RSA keys - it is not solved yet. However, we have time until, Sep 20th ;) Wed Jun 14 12:27:09 CEST 2000 Werner Koch * status.c (init_shm_coprocessing): Changed the sequence of the get,attach to cope with the changes in newer Linux kernels. This bug has been found by who also proposed this solution. Hopefully this does not break gpg on to many systems. * cipher.c (write_header): Protect the IV with the MDC too. * encr-data.c (decrypt_data): Likewise. Fri Jun 9 10:09:52 CEST 2000 Werner Koch * g10.c: New options --no-auto-key-retrieve * options.h (auto_key_retrieve): New. * mainproc.c (check_sig_and_print): Implemented that. Wed Jun 7 19:19:09 CEST 2000 Werner Koch * sig-check.c (do_check): Use EMULATE_MDENCODE also on v4 packets. Wed Jun 7 17:25:38 CEST 2000 Werner Koch * cipher.c (write_header): Use plain CFB mode for MDC encrypted packets. * encr-data.c (decrypt_data): Ditto. Mon Jun 5 23:41:54 CEST 2000 Werner Koch * seskey.c (do_encode_md, encode_md_value): Add new arg v3compathack to work around a bug in old versions. * sig-check.c (do_check): use the aboved workaround when enabled. * g10.c: New option --emulate-md-decode-bug Mon Jun 5 12:37:43 CEST 2000 Werner Koch * build-packet.c (do_mdc): New. (do_encrypted_mdc): Changed for the new proposal. * parse-packet.c (parse_mdc): New. (parse_encrypted): Fixed for the new proposal. * packet.h (PKT_MDC): New. * cipher.c (cipher_filter): Build the MDC packet here. * g10.c (main): Enable --force-mdc. * encr-data.c (mdc_decode_filter): Fixed for new MDC method * options.h(rfc2440): New. * g10.c (main): Changed the selected values for --openpgp to not include optional algorithms. Thu May 18 11:38:54 CEST 2000 Werner Koch * keyedit.c (keyedit_menu): Add a keyword arg to the prompt. * status.c, status.h: Added 3 new status tokens. * status.c (do_get_from_fd): New. (cpr_enabled,cpr_get,cpr_get_hidden,cpr_kill_prompt, cpr_get_answer_is_yes,cpr_get_answer_yes_no_quit): Modified to work with the new function. * g10.c: Add new option --command-fd. * status.c (progress_cb): New. (set_status_fd): Register progress functions Fri May 12 14:01:20 CEST 2000 Werner Koch * delkey.c (delete_key): Add 2 new status messages * status.c, status.h (STATUS_DELETE_PROBLEM): New. Fixed years of copyright in all source files. Mon May 1 17:08:14 CEST 2000 Werner Koch * trustdb.c (propagate_validity): Fixed the bug that only one uid gets fully trusted even when all are signed by an ultimate key. Mon May 1 15:38:04 CEST 2000 Werner Koch * getkey.c (key_byname): Always returned a defined context. Fixed a segv for invalid user id specifications. Reported by Walter Koch. * getkey.c (get_user_id): I18ned "no user id" string. By Walter. * pkclist.c (do_show_revocation_reason): Typo fixes. * helptext.c: Ditto. * armor.c (armor_filter): Fixed some CRLF issues. By Mike McEwan. Fri Apr 14 19:37:08 CEST 2000 Werner Koch * pkclist.c (do_show_revocation_reason): New. (show_revocation_reason): New and called at various places. * g10.c (main): Fixed small typo. * pkclist.c (do_we_trust): Act on always_trust but not for revoked keys. Suggested by Chip Salzenberg. * g10.c: New option --lock-never. * ringedit.c (get_writable_keyblock_file): New. * keygen.c (do_generate_keypair): Use this instead of the hardwired one. * keygen.c (ask_user_id): Check that the email address is in the correct field. Suggested by Christian Kurz. Mon Apr 10 13:34:19 CEST 2000 Werner Koch * keyedit.c (show_key_with_all_names): s/sbb/ssb/ Tue Mar 28 14:26:58 CEST 2000 Werner Koch * trustdb.c (verify_own_keys): Do not print warning about unprotected key when in quiet mode. Wed Mar 22 13:50:24 CET 2000 Werner Koch * mainproc.c (print_userid): Do UTF8 conversion before printing. * import.c (import_one): Ditto. (import_secret_one): Ditto. (delete_inv_parts): Ditto. Thu Mar 16 16:20:23 CET 2000 Werner Koch * keylist.c (print_key_data): Handle a NULL pk gracefully. * getkey.c (merge_one_pk_and_selfsig): Fixed silly code for getting the primary keys keyID but kept using the one from the subkey. * pubkey-enc.c (get_it): Print a note for expired subkeys. * getkey.c (has_expired): New. (subkeys_expiretime): New. (finish_lookup): Check for expired subkeys needed for encryption. (merge_keys_and_selfsig): Fixed expiration date merging for subkeys. * keylist.c (list_keyblock): Print expiration time for "sub". (list_one): Add missing merging for public keys. * mainproc.c (list_node): Ditto. 2000-03-14 13:49:38 Werner Koch (wk@habibti.openit.de) * keygen.c (keyedit_menu): Do not allow to use certain commands while the secret key is selected. 2000-03-09 12:53:09 Werner Koch (wk@habibti.openit.de) * keygen.c (ask_expire_interval): Movede parsig to ... (parse_expire_string): ... this new function. And some new control commands. (proc_parameter_file): Add expire date parsing. (do_generate_keypair): Allow the use of specified output files. 2000-03-08 10:38:38 Werner Koch (wk@habibti.openit.de) * keygen.c (ask_algo): Removed is_v4 return value and the commented code to create Elg keys in a v3 packet. Removed the rounding of key sizes here. (do_create): Likewise removed arg v4_packet. (gen_elg): Likewise removed arg version. Now rounding keysizes here. (gen_dsa): Rounding keysize now here. (release_parameter_list): New (get_parameter*): New. (proc_parameter_file): New. (read_parameter_file): New. (generate_keypair): Splitted. Now uses read_parameter_file when in batch mode. Additional argument to specify a parameter file. (do_generate_keypair): Main bulk of above fucntion and uses the parameter list. (do_create): Don't print long notice in batch mode. * g10.c (main): Allow batched key generation. Thu Mar 2 15:37:46 CET 2000 Werner Koch * pubkey-enc.c (get_it): Print a note about unknown cipher algos. * g10.c (opts): Add a note to the help listing about the man page and removed some options from the help listing. * keyedit.c (print_and_check_one_sig): Use a new function to truncate the output of the user ID. Suggested by Jan-Benedict Glaw. Wed Feb 23 10:07:57 CET 2000 Werner Koch * helptext.c: typo fix. Thu Feb 17 13:39:32 CET 2000 Werner Koch * revoke.c: Removed a bunch of commented code. * packet.h (SIGSUBPKT_REVOC_REASON): New. * build-packet.c (build_sig_subpkt): Support new sub packet. * parse-packet.c (parse_one_sig_subpkt): Ditto. (dump_sig_subpkt): Ditto. * revoke.c (ask_revocation_reason): New. (release_revocation_reason_info): New. (revocation_reason_build_cb): New. (gen_revoke): Ask for reason. * main.h (struct revocation_reason_info): Add declaration. * keyedit.c (menu_revsig): Add support for revocation reason. (menu_revkey): Ditto. (sign_uid_mk_attrib): Renamed to ... (sign_mk_attrib): ... this, made static and add support for reasons. Tue Feb 15 08:48:13 CET 2000 Werner Koch * build-packet.c (build_packet): Fixed fixing of old comment packets. * import.c (import_keys): Fixed importing from stdin when called with nnames set to zero as it normally happens. Mon Feb 14 14:30:20 CET 2000 Werner Koch * sig-check.c (check_key_signature2): Add new arg r_expired. (do_signature_check): New arg to pass it down to ... (do_check): New arg r-expire which is set when the signature has expired. * trustdb.c (check_sig_record): Set SIGF_EXPIRED flag and set the expiretime to zero so that thi signature will not be checked anymore. Fri Feb 11 17:44:40 CET 2000 Werner Koch * g10.c (g10_exit): Update the random seed_file. (main): Set the random seed file. New option --no-random-seed-file. Thu Feb 10 17:39:44 CET 2000 Werner Koch * keyedit.c (menu_expire): Fixed segv due to unitialized sub_pk. By Rémi. Thu Feb 10 11:39:41 CET 2000 Werner Koch * keylist.c (list_keyblock): Don't print warnings in the middle of regulat output lines. By Rémi. * sig-check.c: Include options.h Wed Feb 9 15:33:44 CET 2000 Werner Koch * gpg.c: New option --ignore-time-conflict * sig-check.c (do_check): Implemented this option. * trustdb.c (check_trust): Ditto. * sign.c (do_sign): Ditto. * keygen.c (generate_subkeypair): Ditto. * encode.c (encode_simple): use iobuf_cancel after open failure. Reported by Huy Le. Fri Jan 14 18:32:01 CET 2000 Werner Koch * packet.h (STRING2KEY): Changed mode from byte to int. * parse-packet.c (parse_key): Add the special GNU protection stuff * build-packet.c (so_secret_key): Ditto. * seckey-cert.c (do_check): Ditto. * keyedit.c (change_passphrase): Ditto. * export.c (export_secsubkeys): New. (do_export_stream): Hack to export the primary key using mode 1001. * g10.c: New command --export-secret-subkeys Thu Jan 13 19:31:58 CET 2000 Werner Koch * armor.c (is_armored): Check for 1-pass-sig packets. Reported by David Hallinan . (armor_filter): Replaced one LF by the LF macro. Reported by Wolfgang Redtenbacher. Wed Jan 5 11:51:17 CET 2000 Werner Koch * g10.c (main): Reset new global flag opt.pgp2_workarounds when --openpgp is used. * mainproc.c (proc_plaintext): Do the PGP2,5 workarounds only when the global flag is set. (proc_tree): Ditto. * textfilter.c (copy_clearsig_text): Ditto. * armor.c (armor_filter): Ditto. * g10.c: New option --list-only * mainproc.c (proc_tree): Don't do it if opt.list_only is active. (proc_pubkey_enc): Implement option. * status.h, status.c ({BEGIN,END}_{EN,DE}CRYPTION): New. * cipher.c (cipher_filter): New status outputs. * mainproc.c (proc_encrypted): New status outputs. Fri Dec 31 14:08:15 CET 1999 Werner Koch * armor.c (armor_filter): Made the "Comment:" header translatable. * hkp.c (hkp_import): Make sure that the program does not return success when there is a connection problem. Reported by Phillip Jones. Sun Dec 19 15:22:26 CET 1999 Werner Koch * armor.c (LF): Use this new macro at all places where a line LF is needed. This way DOSish textfiles should be created when the input data is also in dos mode. * sign.c (LF): Ditto. * textfilter.c (LF): Ditto. (copy_clearsig_text): Disabled the forcing of CR,LF sequences for DOS systems. * plaintext.c (handle_plaintext): Fixes for line endings on DOS. and react on a LF in cleartext. * armor.c (fake_packet): Restore the original line ending after removing trailing spaces. * signal.c (got_fatal_signal): DOS fix. Thu Dec 16 10:07:58 CET 1999 Werner Koch * mainproc.c (print_failed_pkenc): Fix for unknown algorithm. Found by fygrave@epr0.org. Thu Dec 9 10:31:05 CET 1999 Werner Koch * hkp.c: i18n the strings. Sat Dec 4 15:32:20 CET 1999 Werner Koch * trustdb.c (verify_key): Shortcut for ultimately trusted keys. Sat Dec 4 12:30:28 CET 1999 Werner Koch * pkclist.c (build_pk_list): Validate the trust using the namehash if this one has been set by the key lookup. * g10.c: Add --delete-secret-key to the help page. * openfile.c (copy_options_file): Made static. (try_make_homedir): New. * ringedit.c (add_keyblock_resource): Use the try_make_hoemdir logic. * tdbio.c (tdbio_set_dbname): Likewise. * keygen.c (generate_user_id): Use m_alloc_clear() here. We should better use an allocation function specific to the user_id packet. * keygen.c (keygen_add_std_prefs): Changed symmetric preferences to include Blowfish again. This is due to it's better speed compared to CAST5. * g10.c (strusage): Print the home directory. * armor.c (armor_filter): Take action on the cancel control msg. * filter.h (armor_filter_context_t): Add cancel flag. Mon Nov 29 21:52:11 CET 1999 Werner Koch * g10.c: New option --fast-list-mode .. * keylist.c (list_keyblock): .. and implemented. * mainproc.c (list_node): Ditto. * import.c (mark_non_selfsigned_uids_valid): Fixed the case that there is a uid without any packet following. Mon Nov 22 11:14:53 CET 1999 Werner Koch * mainproc.c (proc_plaintext): Never enable the hash processing when skip_verify is active. * armor.c (parse_header_line): Stop parsing on a WS line too. Suggested by Aric Cyr. * tdbdump.c (HEXTOBIN): Changed the name of the argument, so that traditional cpp don't mess up the macros. Suggested by Jos Backus. * mainproc.c (list_node): Print the PK algo in the --with-colon mode. * keylist.c (list_keyblock): Ditto. * signal.c (got_fatal_signal): Found the reason why exit(8) did not work - it is better to set the disposition back to default before raising the signal. Print the notice on stderr always. Fri Nov 12 20:33:19 CET 1999 Werner Koch * g10.c (make_username): Swapped the logic. * keylist.c (public_key_list): Now takes a STRLIST as arg and moved the creation ot this list to the caller, so that he can copy with UTF-conversion of user IDs. Changed all callers. (secret_key_list): Likewise. * getkey.c (get_user_id_string_native): New and ... * encode.c (write_pubkey_enc_from_list): ... use it here. * pubring.asc: Updated. * packet.h (PKT_PHOTO_ID): New. * parse-packet.c (parse_photo_id): New. * build-packet.c (do_user_id: Handle photo IDs. (build_packet): Change CTB for photo IDs * free-packet.c (free_user_id): Release memory used for photo IDs * sig-check.c (hash_uid_node): Handle photo IDs too. * trustdb.c (print_uid_from_keyblock): Hash photo ID. (make_uid_records): Ditto. * getkey.c (find_by_name): Ditto. * keyedit.c (show_prefs): Ditto. * keylist.c (list_keyblock): Ditto. Thu Oct 28 16:08:20 CEST 1999 Werner Koch * keygen.c (ask_expire_interval): Print a warning for systems with a signed 32 time_t if the exiration time is beyoind 2038. Fri Oct 8 20:40:50 CEST 1999 Werner Koch * ringedit.c (enum_keyblocks): The last fix way really stupid; reverted and set rt to Unknown. Fri Oct 8 20:32:01 CEST 1999 Werner Koch * ringedit.c (enum_keyblocks): Zero the entire kbpos out on open. * g10.c (oEntropyDLL): Removed option. (main): Made the warning on development versions more verbose. * g10.c (oHonorHttpProxy): New option. * hkp.c (hkp_ask_import,hkp_export): Implement this option. * options.skel: Enable this option for new installations Mon Oct 4 21:23:04 CEST 1999 Werner Koch * import.c (import_keys): Changed calling interface, adjusted caller. (import): Moved printing of stats out ... (print_stats): New. ... to here. (import_keys_stream): Call stats print here. (import_keys): Print stats as totals for all files. * tdbio.h (DIRF_NEWKEYS): New * tdbio.c (tdbio_dump_record): Print the new flag. * trustdb.c (check_trust_record): New arg sigs_only. Adapted all callers. (do_update_trust_record): Removed recheck arg and add a new sigs_only do we can later improve on the performance. Changed all callers too. (check_trustdb): Evalutate the new flag and add a status output. Do a check when the dir record has not been checked. (build_cert_tree): Evaluate the new flag. (check_trust): Ditto. Do a trust_record check, when the dir record is not marked as checked. (mark_fresh_keys): New. (clear_lid_table): New. (sync_trustdb): New. * import.c (import_keys): Call sync_trustdb() after processing. (import_keys_stream): Ditto. * tdbdump.c (import_ownertrust): Ditto. * import.c (import_revoke_cert): Notify the trust DB. (do_update_trust_record): Use |= to set the REVOKED bit and not &=; shame on me for this bad copy+paste introduced bug. (do_we_trust): Add trustmask to allow revoked key override to work. Chnaged are to allow return of a mofified trustlevel. Adapted the one caller. * g10.c: New options --emulate-3des-s2k-bug * passphrase.c (hash_passphrase): Implemented above. * mainproc.c (proc_tree): Check for standalone signatures. (do_check_sig): Print a notice for a standalone revocation (check_sig_and_print): Do not print an error for unchecked standalone revocations. Tue Sep 28 20:54:37 CEST 1999 Werner Koch * encode.c (encode_simple): Use new CTB when we don't have the length of the file. This is somewhat strange as the comment above indicates that this part is actually fixed for PGP 5 - maybe I simply lost the source line, tsss. * armor.c (armor_filter): Set a flag if no OpenPGP data has been found. * verify.c (verify_signatures): Add an error helptext. Thu Sep 23 19:24:30 CEST 1999 Werner Koch * openfile.c (open_outfile): Fixed the 8dot3 handling. * passphrase.c (passphrase_to_dek): Print uid using utf8 func. * delkey.c (delete_key): Ditto. * pkclist.c (show_paths,do_edit_ownertrust,do_we_trust): Ditto (do_we_trust_pre): Ditto. * trustdb.c (print_user_id,check_uidsigs): Ditto. * revoke.c (gen_revoke,ask_revoke_sig): Ditto. Thu Sep 23 09:52:58 CEST 1999 Werner Koch * verify.c (print_file_status): New. (verify_one_file): Moved status print to th new fnc. Add error status. * status.c, status.h (STATUS_FILE_ERROR): New Wed Sep 22 10:14:17 CEST 1999 Werner Koch * openfile.c (make_outfile_name): Use case-insenstive compare for DOS systems. Add ".pgp" to the list of know extensions. (open_outfile): For DOS systems try to replace the suffiy instead of appending it. * status.c, status.h: Add STATUS_FILE_{START,DONE}. * verify.c (verify_one_file): Emit these new stati. * sign.c (clearsign_file): Avoid duplicated Entries in the "Hash:" line. Those headers are now only _not_ printed when there are only old-style keys _and_ all hashs are MD5. Mon Sep 20 12:24:41 CEST 1999 Werner Koch * verify.c (verify_files, ferify_one_file): New. * g10.c: New command --verify-files Fri Sep 17 12:56:42 CEST 1999 Werner Koch * g10.c: Add UK spelling as alias for armor options ;-) * import.c (append_uid): Fixed a SEGV when there is no selfsig and no subkey. (merge_sigs): Ditto. Removed the assertion. Wed Sep 15 16:22:17 CEST 1999 Werner Koch * g10.c: New option --entropy-dll-name Mon Sep 13 10:51:29 CEST 1999 Werner Koch * signal.c (got_fatal_signal): Print message using write(2) and only for development versions. Mon Sep 6 19:59:08 CEST 1999 Werner Koch * tdbio.c (tdbio_set_dbname): Use mkdir macro * ringedit.c (add_keyblock_resource): Ditto. Fri Sep 3 10:04:45 CEST 1999 Werner Koch * pkclist.c (build_pk_list): Skip keys set with --encrypt-to also when asking for a key. * plaintext.c (handle_plaintext): Make sure that we don't read a second EOF in the read loop for partial length packets. * mainproc.c (check_sig_and_print): print user ID as utf-8. Thu Sep 2 16:40:55 CEST 1999 Werner Koch * import.c (merge_blocks): First add new subkeys, then merge subkey certificates. (merge_sigs): Don't merge subkey signatures here. Wed Sep 1 15:30:44 CEST 1999 Werner Koch * keygen.c (ask_expire_interval): Fixed bug related to cpr_xx (tnx Francis J. Lacoste). Tue Aug 31 17:20:44 CEST 1999 Werner Koch * plaintext.c (do_hash): Hash CR,LF for a single CR. (ask_for_detached_datafile): Changed arguments to be closer to those of hash_datafiles and cleanup the code a bit. * mainproc.c (proc_tree): Workaround for pgp5 textmode detached signatures. Changed behavior of asking for data file to be the same as with provided data files. * keylist.c (list_keyblock): Use UTF8 print functions. Mon Aug 30 20:38:33 CEST 1999 Werner Koch * import.c (chk_self_sigs): some s/log_error/log_info/ so that gpg does not return an error if a key has some invalid packets. * helptext.c: Fixed some typos and changed the way the translation works. The english text is now the keyword for gettext and not anymore the keyword supplied to the function. Done after some discussion with Walter who thinks this is much easier for the translators. * misc.c (disable_core_dumps): Don't do it for DOSish systems. * signal.c (signal_name): Bounds check on signum. Wed Aug 4 10:34:18 CEST 1999 Werner Koch * pubring.asc: Updated. * pkclist.c (do_we_trust_pre,check_signatures_trust): Do not print the warning about --always_trust when --quiet is used. * pkclist.c (fpr_info): New and called at several places. * parse-packet.c (dump_sig_subpkt): List revocation key contents. Mon Jul 26 09:34:46 CEST 1999 Werner Koch * pkclist.c (build_pk_list): Fixed typo in format string. * trustdb.c (create_shadow_dir): Don't translate the error string. * g10.c (main): Fixed spelling of user-id. * getkey.c (find_by_name_pk,find_by_name_sk, find_by_keyid,find_by_keyid_sk): Ditto and translate it. * import.c (mark_non_selfsigned_uids_valid,delete_inv_parts): Ditto. Mon Jul 26 01:01:39 CEST 1999 Michael Roth * g10.c, options.h: New options --no-literal and --set-filesize * encode.c (encode_simple, encode_crypt): Support for the options --no-literal and --set-filesize. * sign.c (sign_file): ditto. Fri Jul 23 13:53:03 CEST 1999 Werner Koch * ringedit.c (enum_keyblocks): Removed annoying error message in cases when we have no keyring at all to enum. * getkey.c (classify_user_id): Rewrote to relax the recognition of keyIDs and fingerprints (Michael). * mainproc.c (check_sig_and_print): Print status NO_PUBKEY. (print_failed_pkenc): Print status NO_SECKEY. * import.c (mark_non_selfsigned_uids_valid): New. * g10.c: New option --allow-non-selfsigned-uid. * pkclist.c (print_fpr): New. (do_we_trust_pre): Print the fpr before asking whether to use the key anyway. (do_edit_ownertrust): Likewise. Thu Jul 22 20:03:03 CEST 1999 Werner Koch * ringedit.c (enum_keyblocks): Removed annoying error message in cases when we have no keyring at all to enum. * getkey.c (classify_user_id): Rewrote to relax the recognition of keyIDs and fingerprints (Michael). * mainproc.c (check_sig_and_print): Print status NO_PUBKEY. (print_failed_pkenc): Print status NO_SECKEY. * import.c (mark_non_selfsigned_uids_valid): New. * g10.c: New option --allow-non-selfsigned-uid. Thu Jul 15 10:15:35 CEST 1999 Werner Koch * g10.c: New options --disable-{cipher,pubkey}-algo. Wed Jul 14 19:42:08 CEST 1999 Werner Koch * status.h (STATUS_IMPORTED): New. * import.c (import): Print some status information (Holger Schurig). * g10.c (main): Make --no-greeting work again. Add a warning when --force-mds is used. Tue Jul 13 17:39:25 CEST 1999 Werner Koch * pkclist.c (do_edit_ownertrust): Changed the way help works. (build_pk_list): Implemented default recipient stuff. * g10.c: New options --default-recipient[-self] (main): Suppress greeting in most cases, entering a passphrase or a missing value is not considered to be interactive use. Merged --print-md and --print-mds; the latter is now obsolete. Changed the way --gen-random works and documented it. Changed the way --gen-prime works and add a man entry. * g10.c (MAINTAINER_OPTIONS): Removed. Mon Jul 12 18:45:57 CEST 1999 Werner Koch * keyedit.c (keyedit_menu): Add arg sign_mode and changed callers * g10.c (main): New command --lsign-key. Mon Jul 12 14:55:34 CEST 1999 Werner Koch * mainproc.c (kidlist_item): New. (release_list): Release failed pk-enc-list. (print_failed_pkenc): New (proc_encrypted): Print info about failed PK enc. * openfile.c (make_outfile_name): s/error/info/ * passphrase.c (passphrase_to_dek): Return an empty passphrase when in batch mode and don't make the warning message fatal * seckey-cert.c (check_secret_key): Try only once when in batch mode. * g10.c (make_username): New. Thu Jul 8 16:21:27 CEST 1999 Werner Koch * packet.h (PKT_ring_trust): New * parse-packet.c (parse_trust): Store trust value * build-packet (build_packet): Ignore ring trust packets. * mainproc.c (add_ring_trust): New. (list_node): Print "rtv" records. * g10.c: New option --with-fingerprint. * trustdb.c (verify_own_keys): Don't insert if we are dry running (check_trust): Ditto. Wed Jul 7 13:08:40 CEST 1999 Werner Koch * Makefile.am: Support for libtool. * keygen.c (ask_expire_interval): Hack to allow for an expire date. * trustdb.c (do_update_trust_record,update_trust_record): Splitted. (check_trust_record): New. (check_trust,build_cert_tree): Check the dir record as needed. (upd_pref_record): Removed. (make_pref_record): New. (propagate_validity): Stop as soon as we have enough validity. * tbdio.c (MAX_CACHE_ENTRIES_HARD): Increased the limit. Fri Jul 2 11:45:54 CEST 1999 Werner Koch * g10.c (g10_exit): Dump random stats. * sig-check.c (check_key_signature,check_key_signature2): Enhanced version and wrapper for old function. (do_signature_check,signature_check): Ditto. Thu Jul 1 12:47:31 CEST 1999 Werner Koch * keyedit.c (show_key_with_all_names): Print a notice for disabled keys. (enable_disable_keys): Add functionality * pkclist.c (edit_ownertrust): preserve disabled state. (build_pk_list): Skip disabled keys. * trustdb.c (upd_one_ownertrust): Ditto. (build_cert_tree): Mask the ownertrust. (trust_letter): Mask the value. (do_check): Take disabled flag into account. * passphrase.c (passphrase_to_dek): Add a pubkey_algo arg and changed all callers. * g10.c (utf8_strings): 2 new options. * trustdb.c (insert_trust_record_by_pk): New, replaces the next one. (insert_trust_record): Now takes a keyblock as arg. Changed all callers to use the appropritae function. * openfile.c (ask_outfile_name): New. * plaintext.c (handle_plaintext): Ask for filename if there is no valid syntax. Don't use fname varbatim but filter it. Tue Jun 29 21:44:25 CEST 1999 Werner Koch * trustdb.h (TRUST_FLAG_DISABLED): New. * status.c (USE_CAPABILITIES): Capabilities support (Remi). * tdbio.c : Added new fields to the DIR record. (tdbio_write_record): Fixed the update of the hash tables. (tdbio_delete_record): Drop the record from the hash tables. (drop_from_hashtbl): New. * status.c (cpr_get): Special online help mode. * helptext.c ("keyedit.cmd"): Removed. * keyedit.c (keyedit_menu): Use only help system. (enable_disable_key): New bit doies not yet work. Sat Jun 26 12:15:59 CEST 1999 Werner Koch * dearmor.c (enarmor_file): Fixed comment string. * tdbdump.c (export_ownertrust): Text fix. * tbio.c (tdbio_invalid): Ditto. * parse-packet.c (parse_key): Made temp buffer larger. * Makefile.am (install-data-local): Add missing backslashes Tue Jun 15 12:21:08 CEST 1999 Werner Koch * g10.c (main): Made iterated+salted the default S2K method. * Makefile.am (install-data-local): Use DESTDIR. * passphrase.c (passphrase_to_dek): Emit missing-passphrase while in batchmode. * parse-packet.c (parse_pubkeyenc): Fixed a SEGV. Mon Jun 14 21:18:54 CEST 1999 Michael Roth * g10.c: New options --openpgp, --no-tty, --emit-version, --default-comment and --lock-multiple Thu Jun 10 14:18:23 CEST 1999 Werner Koch * free-packet.c (free_encrypted): Fixed EOF case (Remi). (free_plaintext): Ditto. * helptext.c (keyedit.delsig.unknown): New (Remi). * keyedit.c (print_and_check_one_sig): Add arg print_without_key and changed all callers to make use of it (Remi): Tue Jun 8 13:36:25 CEST 1999 Werner Koch * keylist.c (print_key_data): New and called elsewhere. * g10.c: New option --with-key-data Wed Jun 2 14:17:19 CEST 1999 Werner Koch * mainproc.c (proc_tree): Yet another bad hack to cope with broken pgp2 created detached messages in textmode. Tue Jun 1 16:01:46 CEST 1999 Werner Koch * openfile.c (make_outfile_name): New. * plaintext.c (handle_plaintext): Outputfile is now the inputfile without the suffix. * g10.c: New option --use-embedded-filename Mon May 31 19:41:10 CEST 1999 Werner Koch * g10.c (main): Fix for SHM init (Michael). * compress.c, encr-data.c, mdfilter.c, plaintext.c, free-packet.c: Speed patches (Rémi). Thu May 27 09:40:55 CEST 1999 Werner Koch * status.c (cpr_get_answer_yes_no_quit): New. * keyedit.c (menu_delsig): New. (check_all_keysigs): Splitted. (print_and_check_one_sig): New. Wed May 26 14:36:29 CEST 1999 Werner Koch * build-packet.c (build_sig_subpkt): Support large packets. * parse-packet.c (enum_sig_subpkt): Replaces parse_sig_subpkt. * mainproc.c (print_notation_data): Print all notation packets. * g10.c (add_notation_data): Add a way to specify the critical flag. (main): Add option --set-policy-url. (check_policy_url): Basic checks. * sign.c (mk_notation_and_policy): Replaces mk_notation. * parse-packet.c (can_handle_critical): Moved decision whether we can handle critical subpacket to an extra function. Tue May 25 19:50:32 CEST 1999 Werner Koch * sign.c (sign_file): Always use compression algo 1 for signed onyl file becuase we can´ be sure the the verifier supports other algorithms. * build-packet.c (build_sig_subpkt): Support for notation data. * sign.c (sign_file,clearsign_file,make_keysig_packet): Ditto. (mk_notation): New. * g10.c (add_notation_data): New and add option -N * mainproc.c (print_notation_data): New. (check_sig_and_print): Print any notation data of the signed text. Sun May 23 14:20:22 CEST 1999 Werner Koch * pkclist.c (check_signatures_trust): Print a warning and return immediateley if opt.always_trust is true. * g10.c (main): Corrected handling of no-default-keyring * pkclist.c (algo_available): Disable Twofish until we have settled how to do the MDC. * hkp.c: Disable everything for mingw32 Sat May 22 22:47:26 CEST 1999 Werner Koch * mainproc.c (check_sig_and_print): Add sig creation time to the VALIDSIG status output. Add more info to the ERRSIG output. * sig-check.c (signature_check): Add sig time after epoch to SIG_ID. * import.c (import_one): Merge duplicate user IDs. (collapse_uids): New. * kbnode.c (move_kbnode): New. (remove_kbnode): New. * keyedit.c (keyedit_menu): Call collapse_uids. * g10.c: new option --logger-fd. * import.c: s/log_*_f/log_*/ Thu May 20 14:04:08 CEST 1999 Werner Koch * misc.c (pull_in_libs): do the volatile only for gcc * sig-check (signature_check): Emit SIG_iD only for classes 0 and 1. * armor.c (armor_filter): Add detection of PGP2 created clearsigs. (fake_packet): A tab is not a WS for pgp2 - handle this. * textfilter.c (len_without_trailing_chars): New. (copy_clearsig_text): Add pgp2mode arg. * sign.c (clearsign_file): pass old_style to the above fnc. Wed May 19 16:04:30 CEST 1999 Werner Koch * g10.c: New option --interactive. * mainproc.c (proc_plaintext): Add workaround for pgp2 bug (do_check_sig): Ditto. (proc_tree): Ditto. * plaintext.c (do_hash): Ditto. (hash_datafiles): Ditto, add an arg, changed all callers. * mdfilter.c (md_filter): Add support for the alternate hash context. Mon May 17 21:54:43 CEST 1999 Werner Koch * parse-packet.c (parse_encrypted): Support for PKT_ENCRYPTED_MDC. * build-packet.c (do_encrypted_mdc): Ditto. * cipher.c (write_header): Add mdc hashing. (cipher_filter): write out the hash. * mainproc.c (do_proc_packets): Add PKT_ENCRYPTED_MDC. * encr-data.c (decrypt_data): Add mdc hashing. (mdc_decode_filter): New. * parse-packet.c (parse_sig_subpkt): Fixed stupid bug for subpkt length calculation (parse_signature): Fixed even more stupid bug. Sat May 8 19:28:08 CEST 1999 Werner Koch * build-packet.c (do_signature): Removed MDC hack. * encode.c (encode_crypt_mdc): Removed. * mainproc.c (do_check_sig): Removed MDC hack. (check_sig_and_print): Ditto. * parse-packet.c (parse_signature): Ditto. * sig-check.c (mdc_kludge_check): Ditto. * free-packte.c (copy_signature, free_seckey_enc): Ditto. * parse-packet.c (parse_signature,parse_key): Store data of unknown algorithms with mpi_set_opaque inseatd of the old faked data stuff. (read_rest): Removed. (read_rest2): Renamed to read_rest * build-packet.c (write_fake_data): Use mpi_get_opaque. * free-packet.c (cp_fake_data): Removed and cahnged all callers to use mpi_copy. (free_pubkey_enc,free_seckey_enc,release_public_key_parts, release_secret_key_parts): Use mpi_free for opaque data. Thu May 6 14:18:17 CEST 1999 Werner Koch * trustdb.c (check_trust): Check for revoked subkeys. * pkclist.c (do_we_trust): Handled revoked subkeys. (do_we_trust_pre): Ditto. (check_signatures_trust): Ditto. * build-packet.c (hash_public_key): Fix for ancient g10 keys. * mainproc.c (do_proc_packets): Return EOF if no data has been read. * g10.c (main): Catch errors for default operation. Thu Apr 29 12:29:22 CEST 1999 Werner Koch * sign.c (sign_file): Fixed hashing in case of no subpackets. (clearsign_file): Ditto. (make_keysig_packet): Ditto. Wed Apr 28 13:03:03 CEST 1999 Werner Koch * keyedit.c (keyedit_menu): Add new command revkey. * (menu_revkey): New. Mon Apr 26 17:48:15 CEST 1999 Werner Koch * parse-packet.c (parse_signature): Add the MDC hack. * build-packet.c (do_signature): Ditto. * free-packet.c (free_seckey_enc,copy_signature,cmp_signatures): Ditto. * mainproc.c (do_check_sig): Ditto. * sig-check.c (mdc_kludge_check): New. * encode.c (encrypt_mdc_file): New. * keyedit.c (check_all_keysigs): List revocations. * (menu_revsig): New. * sign (make_keysig_packet): Support for class 0x30. Sun Apr 18 20:48:15 CEST 1999 Werner Koch * pkclist.c (select_algo_from_prefs): Fixed the case that one key has no preferences (Remi Guyomarch). keylist.c (list_keyblock): ulti_hack to propagate trust to all uids. Sun Apr 18 10:11:28 CEST 1999 Werner Koch * seckey-cert.c (do_check): Use real IV instead of a 0 one, so that it works even if the length of the IV doesn't match the blocksize. Removed the save_iv stuff. (protect_secret_key): Likewise. Create the IV here. * packet.h (PKT_secret_key): Increased size of IV field and add a ivlen field. * parse-packet.c (parse_key): Use the len protect.ivlen. * build-packet.c (do_secret_key). Ditto. * getkey.c (key_byname): Close keyblocks. * Makefile.am (gpgm): Removed this * g10.c: Merged gpg and gpgm * import.c (import): Utilize option quiet. * tdbio.c (tdbio_set_dbname): Ditto. * ringedit.c (add_keyblock_resource,keyring_copy): Ditto. * keyedit.c (sign_uids): Add some batch support. * g10.c (main): add call to tty_batchmode. Fri Apr 9 12:26:25 CEST 1999 Werner Koch * status.c (write_status_text): Some more status codes. * passphrase_to_dek (passphrase_to_dek): add a status code. * seckey_cert.c (check_secret_key): Likewise. * encr-data.c (decrypt_data): Reverse the last changes * cipher.c (write_header): Ditto. * parse-packet.c (parse_key): Dropped kludge for ancient blowfish mode. Thu Apr 8 09:35:53 CEST 1999 Werner Koch * mainproc.c (proc_encrypted): Add a new status output * passphrase.c (passphrase_to_dek): Ditto. * status.h status.c: Add new status tokens. Wed Apr 7 20:51:39 CEST 1999 Werner Koch * encr-data.c (decrypt_data): Fixes for 128 bit blocksize * cipher.c (write_header): Ditto. * seckey-cert.c (do_check): Ditto. (protect_secret_key). Ditto. * misc.c (print_cipher_algo_note): Twofish is now a standard algo. * keygen.c (do_create): Fixed spelling (Gaël Quéri) (ask_keysize): Only allow keysizes up to 4096 * ringedit.c (add_keyblock_resource): chmod newly created secrings. * import.c (delete_inv_parts): Fixed accidently deleted subkeys. Tue Apr 6 19:58:12 CEST 1999 Werner Koch * armor.c: Removed duped include (John Bley) * mainproc.c: Ditto. * build-packet.c (hash_public_key): Fixed hashing of the header. * import.c (delete_inv_parts): Allow import of own non-exportable sigs. Sat Mar 20 13:59:47 CET 1999 Werner Koch * armor.c (fake_packet): Fix for not not-dash-escaped Sat Mar 20 11:44:21 CET 1999 Werner Koch * g10.c (main): Added command --recv-keys * hkp.c (hkp_import): New. Wed Mar 17 13:09:03 CET 1999 Werner Koch * trustdb.c (check_trust): add new arg add_fnc and changed all callers. (do_check): Ditto. (verify_key): Ditto. (propagate_validity): Use the new add_fnc arg. (print_user_id): Add the FILE arg. (propagate_ownertrust): New. * pkclist.c (add_ownertrust_cb): New and changed the add_ownertrust logic. * getkey.c (get_keyblock_bylid): New. * trustdb.c (print_uid_from_keyblock): New. (dump_tn_tree_with_colons): New. (list_trust_path): Add colon print mode. * trustdb.c (insert_trust_record): Always use the primary key. * encode.c (encode_simple): Added text_mode filter (Rémi Guyomarch) (encode_crypt): Ditto. * mainproc.c (proc_pubkey_enc): Added status ENC_TO. * armor.c (armor_filter): Added status NODATA. * passphrase.c (passphrase_to_dek): Always print NEED_PASSPHRASE * seckey_cert.c (check_secret_key): Added BAD_PASS status. * g10.c (main): Set g10_opt_homedir. Sun Mar 14 19:34:36 CET 1999 Werner Koch * keygen.c (do_create): Changed wording of the note (Hugh Daniel) Thu Mar 11 16:39:46 CET 1999 Werner Koch * tdbdump.c: New * trustdb.c (walk_sigrecs,do_list_sigs,list_sigs, list_records,list_trustdb,export_ownertrust,import_ownertrust): Moved to tdbdump.c (init_trustdb): renamed to setup_trustdb. Changed all callers. (do_init_trustdb): renamed to init_trustdb(). * trustdb.c (die_invalid_db): replaced by tdbio_invalid. * tdbio.c (tdbio_invalid): New. * import.c (delete_inv_parts): Skip non exportable signatures. * keyedit.c (sign_uid_mk_attrib): New. (sign_uids): Add the local argument. (keyedit_menu): New "lsign" command. * trustdb.c (register_trusted_key): Removed this and all related stuff. * g10.c (oTrustedKey): Removed option. * tdbio.h (dir.valcheck): New trustdb field. * tdbio.c: Add support for this field (tdbio_read_modify_stamp): New. (tdbio_write_modify_stamp): New. * trustdb.c (do_check): Check against this field. Removed cache update. (verify_key): Add cache update. (upd_uid_record): Some functional changes. (upd_cert_record): Ditto Wed Mar 10 11:26:18 CET 1999 Werner Koch * keylist.c (list_keyblock): Fixed segv in uid. Print 'u' as validity of sks. Mon Mar 8 20:47:17 CET 1999 Werner Koch * getkey.c (classify_user_id): Add new mode 12 (#). * seckey-cert.c (check_secret_key): replaced error by info. * trustdb.c (query_trust_info): Add another arg, changed all callers. (check_trust): Ditto. (do_check): Ditto. (verify_key): Handle namehash. * keylist.c (list_keyblock): print trust info for user ids. * sig-check.c (signature_check): Add sig-created to status output. Tue Mar 2 16:44:57 CET 1999 Werner Koch * textfilter.c (copy_clearsig_text): New. (clearsign): Removed. * sign.c (clearsign_file): does not use textfiler anymore. * keygen.c (ask_user_id): print a note about the used charset. Tue Mar 2 10:38:42 CET 1999 Werner Koch * sig-check.c (signature_check): sig-id now works for all algos. * armor.c (armor_filter): Fixed armor bypassing. Sun Feb 28 19:11:00 CET 1999 Werner Koch * keygen.c (ask_user_id): Don't change the case of email addresses. (has_invalid_email_chars): Adjusted. * keylist.c (list_one): Really list serect keys (Remi Guyomarch) * keyedit.c (menu_select_uid): Add some braces to make egcs happy. (menu_select_key): Ditto. * mainproc.c (do_proc_packets): List sym-enc packets (Remi Guyomarch) Fri Feb 26 17:55:41 CET 1999 Werner Koch * pkclist.c (build_pk_list): Return error if there are no recipients. * sig-check.c (signature_check): New signature id feature. * armor.c (make_radic64_string): New. * mainproc.c (proc_pubkey_enc): early check for seckey availability. * pkclist.c (do_we_trust_pre): print user id before asking. * ringedit.c (add_keyblock_resource,get_keyblock_handle): Cleaner handling of default resource. Thu Feb 25 18:47:39 CET 1999 Werner Koch * pkclist.c (algo_available): New. (select_algo_from_prefs): Check whether algo is available. * ringedit.c (keyring_copy): Take care of opt.dry_run. (do_gdbm_store): Ditto. * openfile.c (open_outfile). Ditto. (copy_options_file): Ditto. * trustdb.c (update_trustdb): Ditto. (clear_trust_checked_flag): Ditto. (update_trust_record): Ditto. (insert_trust_record): Ditto. Wed Feb 24 11:07:27 CET 1999 Werner Koch * keylist.c (secret_key_list): Now really list the secret key. * trustdb.c (do_init_trustdb): New. Init is now deferred. Mon Feb 22 20:04:00 CET 1999 Werner Koch * getkey.c (lookup_sk): Return G10ERR_NO_SECKEY and not x_PUBKEY. Fri Feb 19 15:49:15 CET 1999 Werner Koch * pkclist.c (select_algo_from_prefs): retrieve LID if not there. * armor.c (fake_packet): Replaced ugly lineending handling. * g10.c (oNoEncryptTo): New. * pkclist.c (build_pk_list): Implemented this option. * g10.c (main): Greeting is now printed to stderr and not to tty. Use add_to_strlist() instead of direct coding. * import.c (import): Use iobuf_push_filter2. * mainproc.c (check_sig_and_print): Print all user ids for good signatures. * getkey.c (get_pubkeyblock): New. * import.c (chk_self_sigs): Fixed SEGV for unbounded class 0x18 keys. (delete_inv_parts): Delete special marked packets. Tue Feb 16 14:10:02 CET 1999 Werner Koch * g10.c (main): New option --encrypt-to * pkclist.c (build_pk_list): Implemented encrypt-to. * parse-packet.c (parse_user_id): Removed the hack to work with utf-8 strings. * g10.c (main): Install lockfile cleanup handler. * tdbio.c (cleanup): Removed: this is now handled by dotlock. Sat Feb 13 14:13:04 CET 1999 Werner Koch * tdbio.c (tdbio_set_dbname): Init lockhandle for a new trustdb Wed Feb 10 17:15:39 CET 1999 Werner Koch * g10.c (main): check for development version now in configure * tdbio.c (tdbio_write_record): Add uid.validity (tdbio_read_record) : Ditto. (tdbio_dump_record) : Ditto. * keygen.c (keygen_add_std_prefs): Replaced Blowfish by Twofish, removed MD5 and Tiger. * pubkey-enc.c (get_it): Suppress warning about missing Blowfish in preferences in certain cases. * ringedit.c (lock_rentry,unlock_rentry): New. * getkey.c (key_byname): Pass ret_kb down to lookup_xx. * armor.c (armor_filter): No output of of empty comment lines. Add option --no-version to suppress the output of the version string. * getkey.c: Release the getkey context for auto context variables. Sun Jan 24 18:16:26 CET 1999 Werner Koch * getkey.c: Changed the internal design to allow simultaneous lookup of multible user ids (get_pubkey_bynames): New. (get_seckey_bynames): New. (get_seckey_next): New. (get_seckey_end): New. * keylist.c (list_one): Use the new functions. * keylist.c (list_keyblock): add a newline for normal listings. * g10.c (--recipient): New option name to replace --remote-user Wed Jan 20 18:59:49 CET 1999 Werner Koch * textfilter.c: Mostly rewritten * plaintext.c (handle_plaintext): Use now text_filter semantics. Tue Jan 19 19:34:58 CET 1999 Werner Koch * export.c (export_pubkeys_stream): New. (do_export_stream): New. * g10.c (aSendKeys): New command. * hkp.c (hkp_export): New. * compress.c (do_uncompress): Hack for algo 1 and 1.1.3 Sun Jan 17 11:04:33 CET 1999 Werner Koch * textfilter.c (text_filter): Now uses iobuf_read_line(). (read_line): Removed. * armor.c (trim_trailing_spaces): Removed and replaced by trim_trailing_ws from libutil Sat Jan 16 12:03:27 CET 1999 Werner Koch * hkp.c (hkp_ask_import): Use only the short keyid Sat Jan 16 09:27:30 CET 1999 Werner Koch * import.c (import_key_stream): New (import): New, moved most of import_keys here. * g10.c: New option --keyserver * mainproc.c (check_sig_and_print): Hook to import a pubkey. * pref.c pref.h : Removed * hkp.c hkp.h: New Wed Jan 13 14:10:15 CET 1999 Werner Koch * armor.c (radix64_read): Print an error if a bad armor was detected. Wed Jan 13 12:49:36 CET 1999 Werner Koch * armor.c (radix64_read): Now handles malformed armors produced by some buggy MUAs. Tue Jan 12 11:17:18 CET 1999 Werner Koch * ringedit.c (find_keyblock_bysk): New. * skc_list.c (is_insecure): New. (build_sk_list): usage check for insecure keys. * import.c (chk_self_sigs): Add handling for subkeys. (delete_inv_parts): Skip unsigned subkeys * sig-check.c (do_check): Print info if the signature is older than the key. * keygen.c (generate_subkeypair): Fail on time warp. * sign.c (do_sign): Ditto. Sun Jan 10 15:10:02 CET 1999 Werner Koch * armor.c (fake_packet): Fixed not-dash-escaped bug. Sat Jan 9 16:02:23 CET 1999 Werner Koch * sig-check.c (do_check): Output time diff on error * status.c (STATUS_VALIDSIG): New. (is_status_enabled): New. * mainproc.c (check_sig_and_print): Issue that status message. * plaintext.c (special_md_putc): Removed * armor.c (armor_filter): print error for truncated lines. * free-packet.c (free_encrypted): Revomed call to set_block_mode. (free_plaintext): Ditto. Thu Jan 7 18:00:58 CET 1999 Werner Koch * pkclist.c (add_ownertrust): Fixed return value. * encr-data.c (decrypt_data): Disabled iobuf_set_limit and iobuf_pop_filter stuff. * compress.c (handle_compressed): Disabled iobuf_pop_filter. * packet.h (PKT_secret_key): Add is_primary flag. * parse-packet.c (parse_key): Set this flag. * passphrase.c (passphrase_to_dek): Kludge to print the primary keyid - changed the API: keyid must now hold 2 keyids. * getkey.c (get_primary_seckey): New. * seckey-cert.c (do_check): pass primary keyid to passphrase query * tbdio.c (open_db): removed the atexit (tdbio_set_dbname): and moved it to here. * armor.c: Rewrote large parts. Tue Dec 29 19:55:38 CET 1998 Werner Koch * revoke.c (gen_revoke): Removed compression. * pkclist.c (do_we_trust_pre): special check for revoked keys * trustdb.c (update_trust_record): Fixed revoke flag. Tue Dec 29 14:41:47 CET 1998 Werner Koch * misc.c (disable_core_dumps): Check for EINVAL (Atari) * getkey (merge_one_pk_and_selfsig): Fixed search of expiredate. (merge_keys_and_selfsig): Ditto. * free-packet.c (cmp_public_keys): cmp expire only for v3 packets (cmp_secret_keys): Ditto. (cmp_public_secret_key): Ditto. Wed Dec 23 17:12:24 CET 1998 Werner Koch * armor.c (find_header): Reset not_dashed at every header Wed Dec 23 13:18:14 CET 1998 Werner Koch * pkclist.c (add_ownertrust): Refresh validity values. * trustdb.c (enum_cert_paths_print): New arg refresh. * ringedit.c: Fixed problems fix keyrings * parse-packet.c (dbg_parse_packet): New debug functions. * getkey.c (getkey_disable_caches): New. * import.c (import_keys): Disable caches. Thu Dec 17 18:31:15 CET 1998 Werner Koch * misc.c (trap_unaligned): Only for glibc 1 * sign.c (write_dash_escaped): Now escapes "From " lines * g10.c: New option --escape-from-lines * trustdb.c (sort_tsl_list): New (list_trust_path): Now prints sorted list. (enum_cert_paths): Likewise. (enum_cert_paths_print): New. (print_paths): New printing format. * pkclist.c (add_ownertrust): New arg quit. (edit_ownertrust): New quit selection and does not query the recipients ownertrust anymore. (add_ownertrust): Print the ceritficate path. Mon Dec 14 21:18:49 CET 1998 Werner Koch * parse-packet.c (parse_signature): Now checks for critical bit (parse_sig_subpkt): Splitted. (parse_one_sig_subpkt): New. * sig-check.c (do_check): handle critical bit. Sun Dec 13 14:10:56 CET 1998 Werner Koch * pcklist.c (select_algo_from_prefs): Preferences should now work (lost the != ? ) Thu Dec 10 20:15:36 CET 1998 Werner Koch * ringedit.c (gdbm_store): Fix for inserts * g10.c (main): New option --export-all * export.c (export_pubkeys): New arg. (do_export): Now may skip old keys. * status.c: Minor patches for Sun's cc * keygen.c (ask_algo): Disabled v3 ElGamal choice, rearranged the numbers. Add a warning question when a sign+encrypt key is selected. * g10.c (do_not_use_RSA): Removed. * misc.c (print_pubkey_algo_note): New as replacement for the do_not_use_RSA() and chnaged all callers. (print_cipher_algo_note): New. (print_hash_algo_note): New. * cipher.c (write_header): Add a call to print_cipher_algo_note. * seckey-cert.c (protect_secret_key): Ditto * sign.c (do_sign): Add a call to print_digest_algo_note. * getkey.c (get_long_user_id_string): New. * mainproc.c (check_sig_and_print): Changed the format of the status output. * encrypt.c (write_pubkey_enc_from_list): print used symmetric cipher. * pkclist.c (do_we_trust): Changed a message. Wed Dec 9 13:41:06 CET 1998 Werner Koch * misc.c (trap_unaligned) [ALPHA]: Only if UAC_SIGBUS is defined. * sign.c (write_dash_escaped): Add the forgotten patch by Brian Moore. * compress.c (do_uncompress): Fixed the inflating bug. Tue Dec 8 13:15:16 CET 1998 Werner Koch * trustdb.c (upd_uid_record): Now uses the newest self-signature (insert_trust_record): Now calls update with recheck set to true. (register_trusted_key): New. (verify_own_keys): Enhanced by list of trusted keys. * g10.c (main): Print a warning when a devel version is used. (main): New option --trusted-key * import.c (merge_blocks): Fixed merging of new user ids and added merging of subkeys. (append_uid): Ditto. (merge_keysig): New. (append_key): New. * getkey.c (merge_one_pk_and_selfsig): Get the expiration time from the newest self-signature. (merge_keys_and_selfsig): Ditto. * free-packet.c (cmp_secret_key): New. Fri Nov 27 21:37:41 CET 1998 Werner Koch * g10.c: New option --lock-once * tdbio.c (open_db): Add an atexit (cleanup): New. (tdbio_sync): Add locking. (tdbio_end_transaction): Ditto. (put_record_into_cache): Ditto. * ringedit.c (keyring_copy): Ditto. (cleanup): New. (add_keyblock_resource): Add an atexit. Fri Nov 27 15:30:24 CET 1998 Werner Koch * armor.c (find_header): Another fix for clearsigs. Fri Nov 27 12:39:29 CET 1998 Werner Koch * status.c (display_help): Removed. * helptext.c: New and removed the N_() from all cpr_gets. Fri Nov 20 16:54:52 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (main): New option --not-dash-escaped * sign.c (write_dashed_escaped): Ditto. * armor.c (find_header): Support for NotDashEscaped header. * getkey.c: print "disabled cache.." only if verbose is used. Thu Nov 19 07:17:31 1998 Werner Koch * parse-packet.c (dump_sig_subpkt): Fixed expire listing * getkey.c (merge_keys_and_selfsig): Fixed expire calculation. (merge_one_pk_and_selfsig): Ditto. * keyedit.c (menu_expire). Ditto. * keygen.c (keygen_add_key_expire): Ditto. (ask_expire_interval): New and changed all local function to use this instead. (keygen_add_key_expire): Opaque should now be a public key; changed all callers. * parse.packet.c (parse): use skip_rest to skip packets. * keyedit.c (keyedit_menu): New arg for cmdline cmds. Wed Nov 18 20:33:50 1998 Werner Koch (wk@isil.d.shuttle.de) * trustdb.c (check_trustdb): Now rechecks all gived userids. (collect_paths): Some fixes. (upd_pref_records): Skips empty items, evaluate all items. * parse-packet.c (dump_sig_subpkt): Better listing of prefs. (skip_packet): Now knows about marker packet * g10.c: removed cmd "--edit-sig". * pubring.asc: Updated. Sat Nov 14 14:01:29 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (main): Changed syntax of --list-trust-path * trustdb.c (list_trust_path): Replaced max_depth by opt.max_cert_depth Fri Nov 13 07:39:58 1998 Werner Koch * trustdb.c (collect_paths): Removed a warning message. (enum_trust_web): Removed. (enum_cert_paths): New. * pkclist.c (add_ownertrust): Changed to use enum_cert_paths. (edit_ownertrust): Now list ceritficates on request. (show_paths): New. Wed Nov 11 18:05:44 1998 Werner Koch * g10.c (main): New option --max-cert-depth * tdbio.h: add new fields to ver and dir record. * tdbio.c: read/write/dump of these fields. (tdbio_db_matches_options): New. * trustdb.c: replaced MAC_CERT_DEPTH by opt.max_cert_depth. (do_check): cache validity and changed other functions to reset the cached value. * keylist.c (list_one): Now lists the ownertrust. * mainproc.c (list_node): Ditto. Tue Nov 10 10:08:59 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (g10_exit): Now looks at the new g10_errors_seen. * mainproc.c (check_sig_and_print): Sets g10_errors_seen. * *.c : i18n many more strings. * ringedit.c (locate_keyblock_by_keyid): Add HAVE_LIBGDBM (locate_keyblock_by_fpr): Ditto. * g10.c (main): removed unsused "int errors". (main): Add new option --charset. * g10.c (main): special message for the unix newbie. Mon Nov 9 07:17:42 1998 Werner Koch * getkey.c (finish_lookup): Kludge to prefere algo 16. * trustdb.c (new_lid_table): Clear cached item. * status.c (cpr_get_utf8): New. * pkclist.c (build_pk_list): Uses this. Sun Nov 8 17:20:39 1998 Werner Koch (wk@isil.d.shuttle.de) * mainproc.c (check_sig_and_print): Why did I use strlen()-1 in the printf? - This truncated the TZ. Sat Nov 7 15:57:28 1998 me,,, (wk@tobold) * getkey.c (lookup): Changes to support a read_next. (get_pubkey): Fixed a memory leak. * keylist.c (list_one): Now lists all matching user IDs. Tue Nov 3 16:19:21 1998 Werner Koch (wk@isil.d.shuttle.de) * keygen.c (ask_user_id): Now converted to UTF-8 * g10.c (main): Kludge for pgp clearsigs and textmode. Fri Oct 30 16:40:39 1998 me,,, (wk@tobold) * signal.c (block_all_signals): New. (unblock_all_signals): New * tdbio.c (tdbio_end_transaction): Now blocks all signals. * trustdb.c (new_lid_table): Changed the representation of the former local_lid_info stuff. * trustdb.c (update_trust_record): Reorganized the whole thing. * sig-check.c (check_key_signature): Now handles class 0x28 Wed Oct 28 18:56:33 1998 me,,, (wk@tobold) * export.c (do_export): Takes care of the exportable sig flag. Tue Oct 27 14:53:04 1998 Werner Koch (wk@isil.d.shuttle.de) * trustdb.c (update_trust_record): New "fast" parameter. Sun Oct 25 19:32:05 1998 Werner Koch (wk@isil.d.shuttle.de) * openfile.c (copy_options_File): New. * ringedit.c (add_keyblock_resource): Creates options file * tdbio.c (tdbio_set_dbname): Ditto. Sat Oct 24 14:10:53 1998 brian moore * mainproc.c (proc_pubkey_enc): Don't release the DEK (do_proc_packets): Ditto. Fri Oct 23 06:49:38 1998 me,,, (wk@tobold) * keyedit.c (keyedit_menu): Comments are now allowed * trustdb.c: Rewrote large parts. Thu Oct 22 15:56:45 1998 Michael Roth (mroth@nessie.de) * encode.c: (encode_simple): Only the plain filename without a given directory is stored in generated packets. (encode_crypt): Ditto. * sign.c: (sign_file) Ditto. Thu Oct 22 10:53:41 1998 Werner Koch (wk@isil.d.shuttle.de) * trustdb.c (update_trust_record): Add new optional arg. * import.c (import_keys): Add statistics output * trustdb.c (update_trustdb): Ditto. (insert_trustdb): Ditto. * tdbio.c (tdbio_begin_transaction): New. (tdbio_end_transaction): New. (tdbio_cancel_transaction): New. * g10.c (main): New option --quit. * trustdb.c (check_hint_sig): No tests for user-id w/o sig. This caused an assert while checking the sigs. * trustdb.c (upd_sig_record): Splitted into several functions. * import.c (import_keys): New arg "fast". * g10.c (main): New command --fast-import. Wed Oct 21 18:19:36 1998 Michael Roth * ringedit.c (add_keyblock_resource): Directory is now created. * tdbio.c (tdbio_set_dbname): New info message. Wed Oct 21 11:52:04 1998 Werner Koch (wk@isil.d.shuttle.de) * trustdb.c (update_trustdb): released keyblock in loop. * keylist.c (list_block): New. (list_all): Changed to use list_block. * trustdb.c: Completed support for GDBM * sign.c (only_old_style): Changed the way force_v3 is handled (sign_file): Ditto. (clearsign_file): Ditto. * keygen.c (has_invalid_email_chars): Splitted into mailbox and host part. * keylist.c (list_one): Add a merge_keys_and_selfsig. * mainproc.c (proc_tree): Ditto. Sun Oct 18 11:49:03 1998 Werner Koch (wk@isil.d.shuttle.de) * sign.c (only_old_style): Add option force_v3_sigs (sign_file): Fixed a bug in sig->version (clearsign_file): Ditto. * parse-packet.c (dump_sig_subpkt): New * keyedit.c (menu_expire): New. * free-packet.c (cmp_signatures): New Sat Oct 17 10:22:39 1998 Werner Koch (wk@isil.d.shuttle.de) * armor.c: changed output line length from 72 to 64. * keyedit.c (fix_keyblock): New. Fri Oct 16 10:24:47 1998 Werner Koch (wk@isil.d.shuttle.de) * trustdb.c: Rewrote most. * tdbio.c: Add cache and generalized hash tables. * options.h (ENABLE_COMMENT_PACKETS): New but undef'ed. * encode.c, sign.c, keygen.c: Disabled comment packets. * export.c (do_export): Comment packets are never exported, except for those in the secret keyring. * g10.c (main): Removed option do-no-export-rsa; should be be replaced by a secpial tool. * export.c (do_export): Removed the code for the above option. * armor.c (find_header): Support for new only_keyblocks. * import.c (import_keys): Only looks for keyblock armors. * packet.h: replaced valid_days by expiredate and changed all users. * build-packet.c (do_public_key): calculates valid-days (do_secret_key): Ditto. * parse-packet.c (parse_key): expiredate is calucated from the valid_period in v3 packets. * keyid.c (do_fingerprint_md): calculates valid_dates. * keygen.c (add_key_expire): fixed key expiration time for v4 packets. * armor.c (find_header): A LF in the first 28 bytes was skipped for non-armored data. Thu Oct 8 11:35:51 1998 Werner Koch (wk@isil.d.shuttle.de) * armor.c (is_armored): Add test on old comment packets. * tdbio.c (tdbio_search_dir_bypk): fixed memory leak. * getkey.c: Changed the caching algorithms. Wed Oct 7 19:33:28 1998 Werner Koch (wk@isil.d.shuttle.de) * kbnodes.c (unused_nodes): New. Wed Oct 7 11:15:36 1998 Werner Koch (wk@isil.d.shuttle.de) * keyedit.c (sign_uids): Fixed a problem with SK which could caused a save of an unprotected key. (menu_adduid): Ditto. * keyedit.c (keyedit_menu): Prefs are now correctly listed for new user ids. * trustdb.c (update_trust_record): New. (insert_trust_record): Now makes use of update_trust_record. Tue Oct 6 16:18:03 1998 Werner Koch (wk@isil.d.shuttle.de) * trustdb.c (read_record): replaces most of the tdbio_read_records. (write_record): Ditto. Sat Oct 3 11:01:21 1998 Werner Koch (wk@isil.d.shuttle.de) * keygen.c (ask_alogo): enable ElGamal enc-only only for addmode. Wed Sep 30 10:15:33 1998 Werner Koch (wk@isil.d.shuttle.de) * import.c (import_one): Fixed update of wrong keyblock. Tue Sep 29 08:32:08 1998 me,,, (wk@tobold) * mainproc.c (proc_plaintext): Display note for special filename. * plaintext.c (handle_plaintext): Suppress output of special file. Mon Sep 28 12:57:12 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (verify_own_keys): Add warning if a key is not protected. * passphrase (hash_passphrase): Fixed iterated+salted mode and setup for keysizes > hashsize. * g10.c (main): New options: --s2k-{cipher,digest,mode}. Fri Sep 25 09:34:23 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c: Chnaged some help texts. Tue Sep 22 19:34:39 1998 Werner Koch (wk@isil.d.shuttle.de) * passphrase.c (read_passphrase_from_fd): fixed bug for long passphrases. Mon Sep 21 11:28:05 1998 Werner Koch (wk@(none)) * getkey.c (lookup): Add code to use the sub key if the primary one does not match the usage. * armor.c (armor_filter): New error message: no valid data found. (radix64_read): Changes to support multiple messages. (i18n.h): New. * mainproc.c (add_onepass_sig): bug fix. Mon Sep 21 08:03:16 1998 Werner Koch (wk@isil.d.shuttle.de) * pkclist.c (do_we_trust): Add keyid to most messages. * passphrase.c (read_passphrase_from_fd): New. (have_static_passphrase): New (get_passphrase_fd): Removed. (set_passphrase_fd): Removed. * g10.c (main): passphrase is now read here. * keyedit.c (keyedit_menu): "help" texts should now translate fine. Mon Sep 21 06:40:02 1998 Werner Koch (wk@isil.d.shuttle.de) * encode.c (encode_simple): Now disables compression when --rfc1991 is used. (encode_crypt): Ditto. Fri Sep 18 16:50:32 1998 Werner Koch (wk@isil.d.shuttle.de) * getkey.c (merge_key_and_selfsig): New. Fri Sep 18 10:20:11 1998 Werner Koch (wk@isil.d.shuttle.de) * pkclist.c (select_algo_from_prefs): Removed 3DES kludge. * seskey.c (make_session_key): Fixed SERIOUS bug introduced by adding the weak key detection code. * sign.c (sign_file): Changed aremor header in certain cases. Tue Sep 15 17:52:55 1998 Werner Koch (wk@isil.d.shuttle.de) * mainproc.c (check_sig_and_print): Replaced ascime by asctimestamp. Mon Sep 14 11:40:52 1998 Werner Koch (wk@isil.d.shuttle.de) * seskey.c (make_session_key): Now detects weak keys. * trustdb (clear_trust_checked_flag): New. * plaintext.c (handle_plaintext): Does no anymore suppress CR from cleartext signed messages. Sun Sep 13 12:54:29 1998 Werner Koch (wk@isil.d.shuttle.de) * trustdb.c (insert_trust_record): Fixed a stupid bug in the free liunked list loops. Sat Sep 12 15:49:16 1998 Werner Koch (wk@isil.d.shuttle.de) * status.c (remove_shmid): New. (init_shm_comprocess): Now sets permission to the real uid. Wed Sep 9 11:15:03 1998 Werner Koch (wk@isil.d.shuttle.de) * packet.h (PKT_pubkey_enc): New flah throw_keyid, and add logic to implement it. * g10.c (main): New Option --throw-keyid * getkey.c (enum_secret_keys): Add new ar and changed all callers. Tue Sep 8 20:04:09 1998 Werner Koch (wk@isil.d.shuttle.de) * delkey.c (delete_key): Moved from keyedit.c. Mon Sep 7 16:37:52 1998 Werner Koch (wk@isil.d.shuttle.de) * build-packet.c (calc_length_header): New arg new_ctb to correctly calculate the length of new style packets. * armor.c (is_armored): Checks for symkey_enc packets. * pkclist.c (select_algo_from_prefs): 3DEs substitute is now CAST5. Tue Aug 11 17:54:50 1998 Werner Koch (wk@isil.d.shuttle.de) * build-packet.c (do_secret_key): Fixed handling of old keys. * getkey.c (compare_name): Fixed exact and email matching * openfile.c (open_outfile): Changed arguments and all callers. Tue Aug 11 09:14:35 1998 Werner Koch (wk@isil.d.shuttle.de) * encode.c (encode_simple): Applied option set-filename and comment. (encode_crypt): Ditto. * sign.c (sign_file): Ditto. * armor.c (armor_filter): Applied option comment. * encode.c (encode_crypt): Moved init_packet to the begin. (encode_simple): add an init_packet(). * comment (write_comment): Now enforces a hash sign as the 1st byte. * import.c (import_one): Add explanation for "no user ids". * compress.c (do_uncompress): Applied Brian Warner's patch to support zlib 1.1.3 etc. * trustdb.c (check_trust): Fixed a problem after inserting new keys. * getkey (lookup): do not return the primary key if usage is given (lookup_sk): Ditto and take usage into account. * status.c (cpr_get_answer_is_yes): add display_help. Mon Aug 10 10:11:28 1998 Werner Koch (wk@isil.d.shuttle.de) * getkey.c (lookup_sk): Now always returns the primary if arg primary is true. (lookup): Likewise. (get_pubkey_byname): Now returns the primary key (get_seckey_byname): Ditto. Mon Aug 10 08:34:03 1998 Werner Koch (wk@isil.d.shuttle.de) * keyid.c (pubkey_letter): ELG_E is now a small g. Sat Aug 8 17:26:12 1998 Werner Koch (wk@isil.d.shuttle.de) * openfile (overwrite_filep): Changed semantics and all callers. Sat Aug 8 12:17:07 1998 Werner Koch (wk@isil.d.shuttle.de) * status.c (display_help): New. Thu Aug 6 16:30:41 1998 Werner Koch,mobil,,, (wk@tobold) * seskey.c (encode_session_key): Now uses get_random_bits(). Thu Aug 6 07:34:56 1998 Werner Koch,mobil,,, (wk@tobold) * ringedit.c (keyring_copy): No more backupfiles for secret keyrings and add additional warning in case of a failed secret keyring operation. Wed Aug 5 11:54:37 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (check_opts): Moved to main. Changed def_cipher_algo semantics and chnaged all users. * pubkey-enc.c (get_sssion_key): New informational output about preferences. * parse-packet.c (parse_symkeyenc): Fixed salted+iterated S2K (parse_key): Ditto. * build-packet.c (do_secret_key): Ditto. (do_symkey_enc): Ditto. Tue Aug 4 08:59:10 1998 Werner Koch (wk@isil.d.shuttle.de) * getkey.c (enum_secret_keys): Now returns only primary keys. * getkey (lookup): Now sets the new namehash field. * parse-packet.c (parse_sig_subpkt2): New. * sign.c (sign_file): one-pass sigs are now emiited reverse. Preference data is considered when selecting the compress algo. Wed Jul 29 12:53:03 1998 Werner Koch (wk@isil.d.shuttle.de) * free-packet.c (copy_signature): New. * keygen.c (generate_subkeypair): rewritten * g10.c (aKeyadd): Removed option --add-key Mon Jul 27 10:37:28 1998 Werner Koch (wk@isil.d.shuttle.de) * seckey-cert.c (do_check): Additional check on cipher blocksize. (protect_secret_key): Ditto. * encr-data.c: Support for other blocksizes. * cipher.c (write_header): Ditto. Fri Jul 24 16:47:59 1998 Werner Koch (wk@isil.d.shuttle.de) * kbnode.c (insert_kbnode): Changed semantics and all callers. * keyedit.c : More or less a complete rewrite Wed Jul 22 17:10:04 1998 Werner Koch (wk@isil.d.shuttle.de) * build-packet.c (write_sign_packet_header): New. Tue Jul 21 14:37:09 1998 Werner Koch (wk@isil.d.shuttle.de) * import.c (import_one): Now creates a trustdb record. * g10.c (main): New command --check-trustdb Mon Jul 20 11:15:07 1998 Werner Koch (wk@isil.d.shuttle.de) * genkey.c (generate_keypair): Default key is now DSA with encryption only ElGamal subkey. Thu Jul 16 10:58:33 1998 Werner Koch (wk@isil.d.shuttle.de) * keyid.c (keyid_from_fingerprint): New. * getkey.c (get_pubkey_byfprint): New. Tue Jul 14 18:09:51 1998 Werner Koch (wk@isil.d.shuttle.de) * keyid.c (fingerprint_from_pk): Add argument and changed all callers. (fingerprint_from_sk): Ditto. Tue Jul 14 10:10:03 1998 Werner Koch (wk@isil.d.shuttle.de) * plaintext.c (handle_plaintext): Now returns create error if the file could not be created or the user responded not to overwrite the file. * mainproc.c (proc_plaintext): Tries again if the file could not be created to check the signature without output. * misc.c (disable_core_dumps): New. * g10.c (main): disable coredumps for gpg * g10.c (MAINTAINER_OPTIONS): New to disable some options Mon Jul 13 16:47:54 1998 Werner Koch (wk@isil.d.shuttle.de) * plaintext.c (hash_datafiles): New arg for better support of detached sigs. Changed all callers. * mainproc.c (proc_signature_packets): Ditto. * g10.c (main): New option "compress-sigs" * sig.c (sign_file): detached signatures are not anymore compressed unless the option --compress-sigs is used. Thu Jul 9 19:54:54 1998 Werner Koch (wk@isil.d.shuttle.de) * armor.c: Fixes to allow zero length cleartext signatures Thu Jul 9 14:52:47 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (build_list): Now drops setuid. (main): Changed the way keyrings and algorithms are registered . Wed Jul 8 14:17:30 1998 Werner Koch (wk@isil.d.shuttle.de) * packet.h (PKT_public_key): Add field keyid. * parse-packet.c (parse_key): Reset the above field. * keyid.c (keyid_from_pk): Use above field as cache. * tdbio.c, tdbio.h: New * trustdb.c: Moved some functions to tdbio.c. (print_keyid): New. * pkclist.c (check_signatures_trust): New. Wed Jul 8 10:45:28 1998 Werner Koch (wk@isil.d.shuttle.de) * plaintext.c (special_md_putc): New. (handle_plaintext): add clearsig argument * mainproc.c (proc_plaintext): detection of clearsig * sign.c (write_dased_escaped): Changed clearsig format Tue Jul 7 18:56:19 1998 Werner Koch (wk@isil.d.shuttle.de) * armor.c (find_header): Now makes sure that there is only one empty line for clearsigs, as this is what OP now says. Mon Jul 6 13:09:07 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (main): New option default-secret-key * getkey.c (get_seckey_byname): support for this option. Mon Jul 6 09:03:49 1998 Werner Koch (wk@isil.d.shuttle.de) * getkey.c (add_keyring): Keyrings are now added to end of the list of keyrings. The first added keyringwill be created. (add_secret_keyring): Likewise. * ringedit.c (add_keyblock_resource): Files are created here. * g10.c (aNOP): Removed * getkey.c (lookup): Add checking of usage for name lookups * packet.h (pubkey_usage): Add a field which may be used to store usage capabilities. * pkclist.c (build_pk_list): getkey now called with usage arg. * skclist.c (build_sk_list): Ditto. * sign.c (clearsign_file): Fixed "Hash:" headers Sat Jul 4 13:33:31 1998 Werner Koch (wk@isil.d.shuttle.de) * trustdb.c (list_ownertrust): New. * g10.c (aListOwnerTrust): New. * g10.c (def_pubkey_algo): Removed. * trustdb.c (verify_private_data): Removed and also the call to it. (sign_private_data): Removed. Fri Jul 3 13:26:10 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (aEditKey): was aEditSig. Changed usage msg. * keyedit.c: Done some i18n stuff. * g10.c (do_not_use_RSA): New. * sign.c (do_sign): Add call to above function. * encode.c (write_pubkey_enc_from_list): Ditto. Thu Jul 2 21:01:25 1998 Werner Koch (wk@isil.d.shuttle.de) * parse-packet.c: Now is able sto store data of unknown algorithms. * free-packet.c: Support for this. * build-packet.c: Can write data of packet with unknown algos. Thu Jul 2 11:46:36 1998 Werner Koch (wk@isil.d.shuttle.de) * parse-packet.c (parse): fixed 4 byte length header Wed Jul 1 12:36:55 1998 Werner Koch (wk@isil.d.shuttle.de) * packet.h (new_ctb): New field for some packets * build-packet.c (build_packet): Support for new_ctb * parse-packet.c (parse): Ditto. Mon Jun 29 12:54:45 1998 Werner Koch (wk@isil.d.shuttle.de) * packet.h: changed all "_cert" to "_key", "subcert" to "subkey". * free-packet.c (free_packet): Removed memory leak for subkeys. Sun Jun 28 18:32:27 1998 Werner Koch (wk@isil.d.shuttle.de) * import.c (import_keys): Renamed from import_pubkeys. (import_secret_one): New. * g10.c (aExportSecret): New. * export.c (export_seckeys): New. * parse-packet.c (parse_certificate): Cleaned up. (parse_packet): Trust packets are now considered as unknown. (parse_pubkey_warning): New. Fri Jun 26 10:37:35 1998 Werner Koch (wk@isil.d.shuttle.de) * keygen.c (has_invalid_email_chars): New. Wed Jun 24 16:40:22 1998 Werner Koch (wk@isil.d.shuttle.de) * armor.c (armor_filter): Now creates valid onepass_sig packets with all detected hash algorithms. * mainproc.c (proc_plaintext): Now uses the hash algos as specified in the onepass_sig packets (if there are any) Mon Jun 22 11:54:08 1998 Werner Koch (wk@isil.d.shuttle.de) * plaintext.c (handle_plaintext): add arg to disable outout * mainproc.c (proc_plaintext): disable output when in sigs_only mode. Thu Jun 18 13:17:27 1998 Werner Koch (wk@isil.d.shuttle.de) * keygen.c: Removed all rsa packet stuff, chnaged defaults for key generation. Sun Jun 14 21:28:31 1998 Werner Koch (wk@isil.d.shuttle.de) * misc.c (checksum_u16): Fixed a stupid bug which caused a wrong checksum calculation for the secret key protection and add a backward compatibility option. * g10.c (main): Add option --emulate-checksum-bug. Thu Jun 11 13:26:44 1998 Werner Koch (wk@isil.d.shuttle.de) * packet.h: Major changes to the structure of public key material which is now stored in an array and not anaymore in a union of algorithm specific structures. These is needed to make the system more extendable and makes a lot of stuff much simpler. Changed all over the system. * dsa.c, rsa.c, elg.c: Removed. Wed Jun 10 07:22:02 1998 Werner Koch,mobil,,, (wk@tobold) * g10.c ("load-extension"): New option. Mon Jun 8 22:23:37 1998 Werner Koch (wk@isil.d.shuttle.de) * seckey-cert.c (do_check): Removed cipher constants (protect_secret_key): Ditto. Fri May 29 10:00:28 1998 Werner Koch (wk@isil.d.shuttle.de) * trustdb.c (query_trust_info): New. * keylist.c (list_one): Add output of trust info * mainproc (list_node): ditto. * g10.c (main): full trustdb init if -with-colons and any of the key list modes. Thu May 28 10:34:42 1998 Werner Koch (wk@isil.d.shuttle.de) * status.c (STATUS_RSA_OR_IDEA): New. * sig-check.c (check_signature): Output special status message. * pubkey-enc.c (get_session_key): Ditto. * mainproc.c (check_sig_and_print): Changed format of output. * passpharse.c (passphrase_to_dek): Likewise. Wed May 27 13:46:48 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (aListSecretKeys): New option --list-secret-keys * keylist.c (std_key_list): Renamed to public_key_list. (secret_key_list): New (list_one, list_all): Add support for secret keys. * getkey.c (get_secret_keyring): New. * mainproc.c (list_node): Add option --with-colons for secret keys * sig-check.c (check_key_signature): detection of selfsigs * mainproc.c (list_node): fixed listing. * g10.c (aListSecretKeys): New option --always-trust * pkclist.c (do_we_trust): Override per option added * status.c (write_status_text): Add a prefix to every output line. Wed May 27 07:49:21 1998 Werner Koch (wk@isil.d.shuttle.de) * g10 (--compress-keys): New. * options.h (compress_keys): New. * export.c (export_pubkeys): Only compresses with the new option. Tue May 26 11:24:33 1998 Werner Koch (wk@isil.d.shuttle.de) * passphrase.c (get_last_passphrase): New (set_next_passphrase): New. (passphrase_to_dek): add support for the above functions. * keyedit.c (make_keysig_packet): Add sigclass 0x18, changed all callers due to a new argument. * keygen.c (write_keybinding): New (generate_subkeypair): Add functionality (ask_algo, ask_keysize, ask_valid_days): Broke out of generate_keypair (ask_user_id, ask_passphrase): Ditto. Thu May 21 11:26:13 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c,gpgd.c (main): Does now return an int, so that egcs does not complain. * armor.c (fake_packet): Removed erro message and add a noticed that this part should be fixed. * sign.c (sign_file): Compression now comes in front of encryption. * encode.c (encode_simple): Ditto. (encode_crypt): Ditto. Tue May 19 16:18:19 1998 Werner Koch (wk@isil.d.shuttle.de) * armor.c (fake_packet): Changed assertion to log_error Sat May 16 16:02:06 1998 Werner Koch (wk@isil.d.shuttle.de) * build-packet.c (build_packet): Add SUBKEY packets. Fri May 15 17:57:23 1998 Werner Koch (wk@isil.d.shuttle.de) * sign.c (hash_for): New and used in all places here. * main.h (DEFAULT_): new macros. * g10.c (opt.def_digest_algo): Now set to 0 * compress.c (init_compress): Add support for algo 1 * options.h (def_compress_algo): New * g10.c (main): New option --compress-algo Fri May 15 13:23:59 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (print_mds): New feature to print only one hash, chnaged formatting. Thu May 14 15:36:24 1998 Werner Koch (wk@isil.d.shuttle.de) * misc.c (trap_unaligned) [__alpha__]: New * g10.c (trap_unaligned): Add call to this to track down SIGBUS on Alphas (to avoid the slow emulation code). Wed May 13 11:48:27 1998 Werner Koch (wk@isil.d.shuttle.de) * build-packet.c (do_signature): Support for v4 pakets. * keyedit.c (make_keysig_packet): Ditto. * build-packet.c (build_sig_subpkt_from_sig): New. (build_sig_subpkt): New. * elg.c (g10_elg_sign): removed keyid_from_skc. * dsa.c (g10_dsa_sign): Ditto. * rsa.c (g10_rsa_sign): Ditto. * keyedit.c (make_keysig_packet): Add call to keyid_from_skc * sign.c (clearsign_file): Support for v4 signatures. (sign_file): Ditto. Wed May 6 09:31:24 1998 Werner Koch (wk@isil.d.shuttle.de) * parse-packet.c (do_parse): add support for 5 byte length leader. (parse_subpkt): Ditto. * build-packet.c (write_new_header): Ditto. * packet.h (SIGSUBPKT_): New constants. * parse-packet.c (parse_sig_subpkt): Changed name, made global, and arg to return packet length, chnaged all callers Tue May 5 22:11:59 1998 Werner Koch (wk@isil.d.shuttle.de) * keygen.c (gen_dsa): New. * build_packet.c (do_secret_cert): Support for DSA Mon May 4 19:01:25 1998 Werner Koch (wk@isil.d.shuttle.de) * compress.c: doubled buffer sizes * parse-packet.c (do_plaintext): now uses iobuf_read/write. Mon May 4 09:35:53 1998 Werner Koch (wk@isil.d.shuttle.de) * seskey.c (encode_md_value): Add optional argument hash_algo, changed all callers. * passphrase.c (make_dek_from_passphrase): Removed * (get_passhrase_hash): Changed name to passphrase_to_dek, add arg, changed all callers. * all: Introduced the new ELG identifier and added support for the encryption only one (which is okay to use by GNUPG for signatures). Sun May 3 17:50:26 1998 Werner Koch (wk@isil.d.shuttle.de) * packet.h (PKT_OLD_COMMENT): New name for type 16. * parse-packet.c (parse_comment): Now uses type 61 Fri May 1 12:44:39 1998 Werner Koch,mobil,,, (wk@tobold) * packet.h (count): Chnaged s2k count from byte to u32. * seckey-cert.c (do_check): Changed s2k algo 3 to 4, changed reading of count. * build-packet.c (do_secret_cert): ditto. * parse-packet.c (parse_certificate): ditto. * parse-packet.c (parse_symkeyenc): New. * build-packet.c (do_symkey_enc): New. Thu Apr 30 16:33:34 1998 Werner Koch (wk@isil.d.shuttle.de) * sign.c (clearsign_file): Fixed "Hash: " armor line. Tue Apr 28 14:27:42 1998 Werner Koch (wk@isil.d.shuttle.de) * parse-packet.c (parse_subpkt): Some new types. Mon Apr 27 12:53:59 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (main): Add option --skip-verify. * mainproc.c (check_sig_and_print): Ditto. * g10.c (print_mds): Add output for Tiger. * sign.c (sign_file): Now uses partial length headers if used in canonical textmode (kludge to fix a bug). * parse-packet.c (parse_certificate): Changed BLOWFISH id. * pubkey-enc.c (get_session_key): Ditto. * seskey.c (make_session_key): Ditto. * seckey-cert.c (protect_secret_key,do_check): Add BLOWFISH160. Fri Apr 24 17:38:48 1998 Werner Koch,mobil,,, (wk@tobold) * sig-check.c (check_key_signature): Add sig-class 0x14..0x17 * keyedit.c (sign-key): Some changes to start with support of the above new sig-classes. Wed Apr 22 09:01:57 1998 Werner Koch,mobil,,, (wk@tobold) * getkey.c (compare_name): add email matching Tue Apr 21 16:17:12 1998 Werner Koch,mobil,,, (wk@tobold) * armor.c (armor_filter): fixed missing last LF before CSUM. Thu Apr 9 11:35:22 1998 Werner Koch (wk@isil.d.shuttle.de) * seckey-cert.c (do_check): New; combines all the check functions into one. * sign.c: removed all key management functions * keyedit.c: New. Thu Apr 9 09:49:36 1998 Werner Koch (wk@isil.d.shuttle.de) * import.c (chk_self_sigs): Changed an error message. Wed Apr 8 16:19:39 1998 Werner Koch (wk@isil.d.shuttle.de) * packet.h: packet structs now uses structs from the pubkey, removed all copy operations from packet to pubkey structs. Wed Apr 8 13:40:33 1998 Werner Koch (wk@isil.d.shuttle.de) * trustdb.c (verify_own_certs): Fixed "public key not found". * getkey.c (key_byname): New, combines public and secret key search. * pkclist.c (build_pkc_list): Add new arg usage, changed all callers. * skclist.c (build_skc_list): Likewise. * ringedit.c (find_keyblock, keyring_search2): Removed. Wed Apr 8 09:47:21 1998 Werner Koch (wk@isil.d.shuttle.de) * sig-check.c (do_check): Applied small fix from Ulf Möller. Tue Apr 7 19:28:07 1998 Werner Koch (wk@isil.d.shuttle.de) * cipher.c, encr-data.c, seckey-cert.c: Now uses cipher_xxxx functions instead of blowfish_xxx or cast_xxx Tue Apr 7 11:04:02 1998 Werner Koch (wk@isil.d.shuttle.de) * Makefile.am (g10maint.o): Changed the way it is created. Mon Apr 6 11:17:08 1998 Werner Koch (wk@isil.d.shuttle.de) * misc.c: New. * keygen.c (checksum,checksum_u16,checksum_mpi): Moved to misc.c * seckey-cert.c: Kludge for wrong ELG checksum implementation. Sat Apr 4 20:07:01 1998 Werner Koch (wk@isil.d.shuttle.de) * cipher.c (cipher_filter): Support for CAST5 * encr-data.c (decode_filter): Ditto. (decrypt_data): Ditto. * seskey.c (make_session_key): Ditto. * seckey-cert.c (check_elg, check_dsa): Ditto, (protect_secret_key): Ditto. * pubkey-enc.c (get_session_key): Ditto. * passphrase.c (hash_passphrase): Ditto. Thu Apr 2 20:22:35 1998 Werner Koch (wk@isil.d.shuttle.de) * gpgd.c: New Thu Apr 2 10:38:16 1998 Werner Koch (wk@isil.d.shuttle.de) * keygen.c (generate_keypair): Add valid_days stuff. * trustdb.c (check_trust): Add check for valid_days. Wed Apr 1 16:15:58 1998 Werner Koch (wk@isil.d.shuttle.de) * keygen.c (generate_keypair): Addional question whether the selected large keysize is really needed. Wed Apr 1 15:56:33 1998 Werner Koch (wk@isil.d.shuttle.de) * seckey-cert.c (protect_secret_key): merged protect_xxx to here. Wed Apr 1 10:34:46 1998 Werner Koch (wk@isil.d.shuttle.de) * Makefile.am (g10maint.c): Changed creation rule, so that it works on FreeBSD (missing CFLAGS). * parse-packet.c (parse_subkey): Removed. Thu Mar 19 15:22:36 1998 Werner Koch (wk@isil.d.shuttle.de) * ringedit.c (keyring_enum): Fixed problem with reading too many packets. Add support to read secret keyrings. * getkey.c (scan_keyring): Removed (lookup): New to replace scan_keyring. (scan_secret_keyring): Removed. (lookup_skc): New. Wed Mar 18 11:47:34 1998 Werner Koch (wk@isil.d.shuttle.de) * ringedit.c (enum_keyblocks): New read mode 11. * keyid.c (elg_fingerprint_md): New and changed all other functions to call this if the packet version is 4 or above. Tue Mar 17 20:46:16 1998 Werner Koch (wk@isil.d.shuttle.de) * parse-packet.c (parse_certificate): Add listing support for subkeys. Tue Mar 17 20:32:22 1998 Werner Koch (wk@isil.d.shuttle.de) * armor.c (is_armored): Allow marker packet. Thu Mar 12 13:36:49 1998 Werner Koch (wk@isil.d.shuttle.de) * trustdb.c (check_trust): Checks timestamp of pubkey. * sig-check. (do_check): Compares timestamps. Tue Mar 10 17:01:56 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (main): Add call to init_signals. * signal.c: New. Mon Mar 9 12:43:42 1998 Werner Koch (wk@isil.d.shuttle.de) * dsa.c: New * packet.h, free-packet.c, parse-packet.c : Add support for DSA * sig-check.c, getkey.c, keyid.c, ringedit.c: Ditto. * seckey-cert.c: Ditto. * packet.h : Moved .digest_algo of signature packets to outer structure. Changed all references Sun Mar 8 13:06:42 1998 Werner Koch (wk@isil.d.shuttle.de) * openfile.c : Support for stdout filename "-". * mainproc.c (check_sig_and_print): Enhanced status output: * status.c (write_status_text): New. Fri Mar 6 16:10:54 1998 Werner Koch (wk@isil.d.shuttle.de) * kbnode.c (clone_kbnode): Fixed private_flag. * mainproc.c (list_node): Output of string "Revoked" as user-id. Fri Mar 6 14:26:39 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (main): Add userids to "-kv" and cleaned up this stuff. Fri Mar 6 12:45:58 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (main): Changed semantics of the list-... commands and added a new one. Removed option "-d" * decrypt.c: New. * trustdb.c (init_trustdb): Autocreate directory only if it ends in "/.gnupg". Thu Mar 5 12:12:11 1998 Werner Koch (wk@isil.d.shuttle.de) * mainproc.c (do_proc_packets): New. Common part of proc_packet. (proc_signature_packets): special version to handle signature data. * verify.c: New. * g10.c (aVerify): New. * plaintext.c (hash_datafiles): New. * compress.c (handle_compressed): Add callback arg, changed caller. Thu Mar 5 10:20:06 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c: Is nom the common source for gpg and gpgm * g10maint.c: Removed * Makefile.am: Add rule to build g10maint.c Thu Mar 5 08:43:59 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (main): Changed the way clear text sigs are faked. Wed Mar 4 19:47:37 1998 Werner Koch (wk@isil.d.shuttle.de) * g10maint.c (aMuttKeyList): New * keylist.c: New. Wed Mar 4 17:20:33 1998 Werner Koch (wk@isil.d.shuttle.de) * getkey.c (get_pubkey_byname): Kludge to allow 0x prefix. Tue Mar 3 13:46:55 1998 Werner Koch (wk@isil.d.shuttle.de) * g10maint.c (main): New option --gen-random. Tue Mar 3 09:50:08 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (aDeleteSecretKey): New. (aEditSig): Add option "--edit-key" as synonym for "--edit-sig". (aDeleteSecretKey): New. * getkey.c (seckey_available): New. * sign.c (delete_key): Enhanced to delete secret keys, changed all callers. Mon Mar 2 21:23:48 1998 Werner Koch (wk@isil.d.shuttle.de) * pkc_list.c (build_pkc_list): Add interactive input of user ID. Mon Mar 2 20:54:05 1998 Werner Koch (wk@isil.d.shuttle.de) * pkclist.c (do_we_trust_pre): New. (add_ownertrust): Add message. * trustdb.c (enum_trust_web): Quick fix. Mon Mar 2 13:50:53 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (main): New action aDeleteKey * sign.c (delete_key): New. Sun Mar 1 16:38:58 1998 Werner Koch (wk@isil.d.shuttle.de) * trustdb.c (do_check): No returns TRUST_UNDEFINED instead of eof error. Fri Feb 27 18:14:03 1998 Werner Koch (wk@isil.d.shuttle.de) * armor.c (find_header): Removed trailing CR on headers. Fri Feb 27 18:02:48 1998 Werner Koch (wk@isil.d.shuttle.de) * ringedit.c (keyring_search) [MINGW32]: Open and close file here because rename does not work on open files. Chnaged callers. Fri Feb 27 16:43:11 1998 Werner Koch (wk@isil.d.shuttle.de) * sig-check.c (do_check): Add an md_enable. * mainproc.c (do_check_sig): Use md_open in case of detached sig (proc_tree): Take detached sigs into account. Fri Feb 27 15:22:46 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (main): Make use of GNUPGHOME envvar. * g10main.c (main): Ditto. Wed Feb 25 11:40:04 1998 Werner Koch (wk@isil.d.shuttle.de) * plaintext.c (ask_for_detached_datafile): add opt.verbose to info output. * openfile.c (open_sigfile): Try also name ending in ".asc" Wed Feb 25 08:41:00 1998 Werner Koch (wk@isil.d.shuttle.de) * keygen.c (generate_keypair): Fixed memory overflow. Tue Feb 24 15:51:55 1998 Werner Koch (wk@isil.d.shuttle.de) * parse-packet.c (parse_certificate): Support for S2K. * build-packet.c (do_secret_cert): Ditto. * keygen.c (gen_elg): Ditto. * seckey-cert.c (check_elg): Ditto (protect_elg): Ditto. * sign.c (chnage_passphrase): Ditto. * passphrase.c (get_passphrase_hash): Support for a salt and changed all callers. (make_dek_from_passphrase): Ditto. Tue Feb 24 12:30:56 1998 Werner Koch (wk@isil.d.shuttle.de) * build-packet.c (hash_public_cert): Disabled debug output. Fri Feb 20 17:22:28 1998 Werner Koch (wk@isil.d.shuttle.de) * trustdb.c (init_trustdb) [MINGW32]: Removed 2nd mkdir arg. (keyring_copy) [MINGW32]: Add a remove prior to the renames. Wed Feb 18 18:39:02 1998 Werner Koch (wk@isil.d.shuttle.de) * Makefile.am (OMIT_DEPENDENCIES): New. * rsa.c: Replaced log_bug by BUG. Wed Feb 18 13:35:58 1998 Werner Koch (wk@isil.d.shuttle.de) * mainproc.c (do_check_sig): Now uses hash_public_cert. * parse-packet.c (parse_certificate): Removed hashing. * packet.h (public_cert): Removed hash variable. * free-packet.c (copy_public_cert, free_public_cert): Likewise. * sig-check.c (check_key_signatures): Changed semantics. Wed Feb 18 12:11:28 1998 Werner Koch (wk@isil.d.shuttle.de) * trustdb.c (do_check): Add handling for revocation certificates. (build_sigrecs): Ditto. (check_sigs): Ditto. Wed Feb 18 09:31:04 1998 Werner Koch (wk@isil.d.shuttle.de) * armor.c (armor_filter): Add afx->hdrlines. * revoke.c (gen_revoke): Add comment line. * dearmor.c (enarmor_file): Ditto. * sig-check.c (check_key_signature): Add handling for class 0x20. * mainproc.c : Ditto. Tue Feb 17 21:24:17 1998 Werner Koch (wk@isil.d.shuttle.de) * armor.c : Add header lines "...ARMORED FILE .." * dearmor.c (enarmor_file): New. * g10maint.c (main): New option "--enarmor" Tue Feb 17 19:03:33 1998 Werner Koch (wk@isil.d.shuttle.de) * mainproc.c : Changed a lot, because the packets are now stored a simple linlked list and not anymore in a complicatd tree structure. Tue Feb 17 10:14:48 1998 Werner Koch (wk@isil.d.shuttle.de) * free_packet.c (cmp_public_certs): New. (cmp_user_ids): New. * kbnode.c (clone_kbnode): New. (release_kbnode): Add clone support. * ringedit.c (find_keyblock_bypkc): New. * sign.c (remove_keysigs): Self signatures are now skipped, changed arguments and all callers. * import.c : Add functionality. Tue Feb 17 09:31:40 1998 Werner Koch (wk@isil.d.shuttle.de) * options.h (homedir): New option. * g10.c, g10maint.c, getkey.c, keygen.c, trustdb.c (opt.homedir): New. * trustdb.c (init_trustdb): mkdir for hoem directory (sign_private_data): Renamed "sig" to "g10.sig" Mon Feb 16 20:02:03 1998 Werner Koch (wk@isil.d.shuttle.de) * kbnode.c (commit_kbnode): New. (delete_kbnode): removed unused first arg. Changed all Callers. * ringedit.c (keyblock_resource_name): New. (get_keyblock_handle): NULL for filename returns default resource. Mon Feb 16 19:38:48 1998 Werner Koch (wk@isil.d.shuttle.de) * sig-check.s (check_key_signature): Now uses the supplied public key to check the signature and not any more the one from the getkey.c (do_check): New. (check_signature): Most work moved to do_check. Mon Feb 16 14:48:57 1998 Werner Koch (wk@isil.d.shuttle.de) * armor.c (find_header): Fixed another bug. Mon Feb 16 12:18:34 1998 Werner Koch (wk@isil.d.shuttle.de) * getkey.c (scan_keyring): Add handling of compressed keyrings. Mon Feb 16 10:44:51 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c, g10maint.c (strusage): Rewrote. (build_list): New Mon Feb 16 08:58:41 1998 Werner Koch (wk@isil.d.shuttle.de) * armor.c (use_armor): New. Sat Feb 14 14:30:57 1998 Werner Koch (wk@isil.d.shuttle.de) * mainproc.c (proc_tree): Sigclass fix. Sat Feb 14 14:16:33 1998 Werner Koch (wk@isil.d.shuttle.de) * armor.c (armor_filter): Changed version and comment string. * encode.c, sign.c, keygen.c: Changed all comment packet strings. Sat Feb 14 12:39:24 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (aGenRevoke): New command. * revoke.c: New. * sign.c (make_keysig_packet): Add support for sigclass 0x20. Fri Feb 13 20:18:14 1998 Werner Koch (wk@isil.d.shuttle.de) * ringedit.c (enum_keyblocks, keyring_enum): New. Fri Feb 13 19:33:40 1998 Werner Koch (wk@isil.d.shuttle.de) * export.c: Add functionality. * keygen.c (generate_keypair): Moved the leading comment behind the key packet. * kbnode.c (walk_kbnode): Fixed. * g10.c (main): listing armored keys now work. Fri Feb 13 16:17:43 1998 Werner Koch (wk@isil.d.shuttle.de) * parse-packet.c (parse_publickey, parse_signature): Fixed calls to mpi_read used for ELG b. Fri Feb 13 15:13:23 1998 Werner Koch (wk@isil.d.shuttle.de) * g10.c (main): changed formatting of help output. Thu Feb 12 22:24:42 1998 Werner Koch (wk@frodo) * pubkey-enc.c (get_session_key): rewritten Copyright 1998,1999,2000,2001,2002,2003,2004,2005, 2006,2007,2008,2009,2010,2011 Free Software Foundation, Inc. This file is free software; as a special exception the author gives unlimited permission to copy and/or distribute it, with or without modifications, as long as this notice is preserved. This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, to the extent permitted by law; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/g10/call-agent.c b/g10/call-agent.c index 5a10dbdb9..445102951 100644 --- a/g10/call-agent.c +++ b/g10/call-agent.c @@ -1,1966 +1,1963 @@ /* call-agent.c - Divert GPG operations to the agent. * Copyright (C) 2001, 2002, 2003, 2006, 2007, 2008, 2009, - * 2010 Free Software Foundation, Inc. + * 2010, 2011 Free Software Foundation, Inc. * * This file is part of GnuPG. * * GnuPG is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * GnuPG is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ #include #include #include #include #include #include #include #include #ifdef HAVE_LOCALE_H #include #endif #include "gpg.h" #include #include "util.h" #include "membuf.h" #include "options.h" #include "i18n.h" #include "asshelp.h" #include "sysutils.h" #include "call-agent.h" #include "status.h" #ifndef DBG_ASSUAN # define DBG_ASSUAN 1 #endif static assuan_context_t agent_ctx = NULL; static int did_early_card_test; struct cipher_parm_s { ctrl_t ctrl; assuan_context_t ctx; unsigned char *ciphertext; size_t ciphertextlen; }; struct writecert_parm_s { assuan_context_t ctx; const unsigned char *certdata; size_t certdatalen; }; struct writekey_parm_s { assuan_context_t ctx; const unsigned char *keydata; size_t keydatalen; }; struct genkey_parm_s { ctrl_t ctrl; assuan_context_t ctx; const char *keyparms; }; struct import_key_parm_s { ctrl_t ctrl; assuan_context_t ctx; const void *key; size_t keylen; }; struct cache_nonce_parm_s { char **cache_nonce_addr; char **passwd_nonce_addr; }; struct scd_genkey_parm_s { struct agent_card_genkey_s *cgk; char *savedbytes; /* Malloced space to save key parameter chunks. */ }; static gpg_error_t learn_status_cb (void *opaque, const char *line); /* If RC is not 0, write an appropriate status message. */ static void status_sc_op_failure (int rc) { switch (gpg_err_code (rc)) { case 0: break; case GPG_ERR_CANCELED: case GPG_ERR_FULLY_CANCELED: write_status_text (STATUS_SC_OP_FAILURE, "1"); break; case GPG_ERR_BAD_PIN: write_status_text (STATUS_SC_OP_FAILURE, "2"); break; default: write_status (STATUS_SC_OP_FAILURE); break; } } /* Try to connect to the agent via socket or fork it off and work by pipes. Handle the server's initial greeting */ static int start_agent (ctrl_t ctrl, int for_card) { int rc; (void)ctrl; /* Not yet used. */ /* Fixme: We need a context for each thread or serialize the access to the agent. */ if (agent_ctx) rc = 0; else { rc = start_new_gpg_agent (&agent_ctx, GPG_ERR_SOURCE_DEFAULT, opt.homedir, opt.agent_program, opt.lc_ctype, opt.lc_messages, opt.session_env, opt.verbose, DBG_ASSUAN, NULL, NULL); if (!rc) { /* Tell the agent that we support Pinentry notifications. No error checking so that it will work also with older agents. */ assuan_transact (agent_ctx, "OPTION allow-pinentry-notify", NULL, NULL, NULL, NULL, NULL, NULL); /* Tell the agent about what version we are aware. This is here used to indirectly enable GPG_ERR_FULLY_CANCELED. */ assuan_transact (agent_ctx, "OPTION agent-awareness=2.1.0", NULL, NULL, NULL, NULL, NULL, NULL); } } if (!rc && for_card && !did_early_card_test) { /* Request the serial number of the card for an early test. */ struct agent_card_info_s info; memset (&info, 0, sizeof info); rc = assuan_transact (agent_ctx, "SCD SERIALNO openpgp", NULL, NULL, NULL, NULL, learn_status_cb, &info); if (rc) { switch (gpg_err_code (rc)) { case GPG_ERR_NOT_SUPPORTED: case GPG_ERR_NO_SCDAEMON: write_status_text (STATUS_CARDCTRL, "6"); break; default: write_status_text (STATUS_CARDCTRL, "4"); log_info ("selecting openpgp failed: %s\n", gpg_strerror (rc)); break; } } if (!rc && is_status_enabled () && info.serialno) { char *buf; buf = xasprintf ("3 %s", info.serialno); write_status_text (STATUS_CARDCTRL, buf); xfree (buf); } agent_release_card_info (&info); if (!rc) did_early_card_test = 1; } return rc; } /* Return a new malloced string by unescaping the string S. Escaping is percent escaping and '+'/space mapping. A binary nul will silently be replaced by a 0xFF. Function returns NULL to indicate an out of memory status. */ static char * unescape_status_string (const unsigned char *s) { return percent_plus_unescape (s, 0xff); } /* Take a 20 byte hexencoded string and put it into the the provided 20 byte buffer FPR in binary format. */ static int unhexify_fpr (const char *hexstr, unsigned char *fpr) { const char *s; int n; for (s=hexstr, n=0; hexdigitp (s); s++, n++) ; if (*s || (n != 40)) return 0; /* no fingerprint (invalid or wrong length). */ for (s=hexstr, n=0; *s; s += 2, n++) fpr[n] = xtoi_2 (s); return 1; /* okay */ } /* Take the serial number from LINE and return it verbatim in a newly allocated string. We make sure that only hex characters are returned. */ static char * store_serialno (const char *line) { const char *s; char *p; for (s=line; hexdigitp (s); s++) ; p = xtrymalloc (s + 1 - line); if (p) { memcpy (p, line, s-line); p[s-line] = 0; } return p; } /* This is a dummy data line callback. */ static gpg_error_t dummy_data_cb (void *opaque, const void *buffer, size_t length) { (void)opaque; (void)buffer; (void)length; return 0; } /* A simple callback used to return the serialnumber of a card. */ static gpg_error_t get_serialno_cb (void *opaque, const char *line) { char **serialno = opaque; const char *keyword = line; const char *s; int keywordlen, n; for (keywordlen=0; *line && !spacep (line); line++, keywordlen++) ; while (spacep (line)) line++; if (keywordlen == 8 && !memcmp (keyword, "SERIALNO", keywordlen)) { if (*serialno) return gpg_error (GPG_ERR_CONFLICT); /* Unexpected status line. */ for (n=0,s=line; hexdigitp (s); s++, n++) ; if (!n || (n&1)|| !(spacep (s) || !*s) ) return gpg_error (GPG_ERR_ASS_PARAMETER); *serialno = xtrymalloc (n+1); if (!*serialno) return out_of_core (); memcpy (*serialno, line, n); (*serialno)[n] = 0; } return 0; } /* This is the default inquiry callback. It mainly handles the Pinentry notifications. */ static gpg_error_t default_inq_cb (void *opaque, const char *line) { (void)opaque; if (!strncmp (line, "PINENTRY_LAUNCHED", 17) && (line[17]==' '||!line[17])) { /* There is no working server mode yet thus we use AllowSetForegroundWindow window right here. We might want to do this anyway in case gpg is called on the console. */ gnupg_allow_set_foregound_window ((pid_t)strtoul (line+17, NULL, 10)); /* We do not pass errors to avoid breaking other code. */ } else log_debug ("ignoring gpg-agent inquiry `%s'\n", line); return 0; } /* Release the card info structure INFO. */ void agent_release_card_info (struct agent_card_info_s *info) { if (!info) return; xfree (info->serialno); info->serialno = NULL; xfree (info->apptype); info->apptype = NULL; xfree (info->disp_name); info->disp_name = NULL; xfree (info->disp_lang); info->disp_lang = NULL; xfree (info->pubkey_url); info->pubkey_url = NULL; xfree (info->login_data); info->login_data = NULL; info->cafpr1valid = info->cafpr2valid = info->cafpr3valid = 0; info->fpr1valid = info->fpr2valid = info->fpr3valid = 0; } static gpg_error_t learn_status_cb (void *opaque, const char *line) { struct agent_card_info_s *parm = opaque; const char *keyword = line; int keywordlen; int i; for (keywordlen=0; *line && !spacep (line); line++, keywordlen++) ; while (spacep (line)) line++; if (keywordlen == 8 && !memcmp (keyword, "SERIALNO", keywordlen)) { xfree (parm->serialno); parm->serialno = store_serialno (line); parm->is_v2 = (strlen (parm->serialno) >= 16 && xtoi_2 (parm->serialno+12) >= 2 ); } else if (keywordlen == 7 && !memcmp (keyword, "APPTYPE", keywordlen)) { xfree (parm->apptype); parm->apptype = unescape_status_string (line); } else if (keywordlen == 9 && !memcmp (keyword, "DISP-NAME", keywordlen)) { xfree (parm->disp_name); parm->disp_name = unescape_status_string (line); } else if (keywordlen == 9 && !memcmp (keyword, "DISP-LANG", keywordlen)) { xfree (parm->disp_lang); parm->disp_lang = unescape_status_string (line); } else if (keywordlen == 8 && !memcmp (keyword, "DISP-SEX", keywordlen)) { parm->disp_sex = *line == '1'? 1 : *line == '2' ? 2: 0; } else if (keywordlen == 10 && !memcmp (keyword, "PUBKEY-URL", keywordlen)) { xfree (parm->pubkey_url); parm->pubkey_url = unescape_status_string (line); } else if (keywordlen == 10 && !memcmp (keyword, "LOGIN-DATA", keywordlen)) { xfree (parm->login_data); parm->login_data = unescape_status_string (line); } else if (keywordlen == 11 && !memcmp (keyword, "SIG-COUNTER", keywordlen)) { parm->sig_counter = strtoul (line, NULL, 0); } else if (keywordlen == 10 && !memcmp (keyword, "CHV-STATUS", keywordlen)) { char *p, *buf; buf = p = unescape_status_string (line); if (buf) { while (spacep (p)) p++; parm->chv1_cached = atoi (p); while (*p && !spacep (p)) p++; while (spacep (p)) p++; for (i=0; *p && i < 3; i++) { parm->chvmaxlen[i] = atoi (p); while (*p && !spacep (p)) p++; while (spacep (p)) p++; } for (i=0; *p && i < 3; i++) { parm->chvretry[i] = atoi (p); while (*p && !spacep (p)) p++; while (spacep (p)) p++; } xfree (buf); } } else if (keywordlen == 6 && !memcmp (keyword, "EXTCAP", keywordlen)) { char *p, *p2, *buf; int abool; buf = p = unescape_status_string (line); if (buf) { for (p = strtok (buf, " "); p; p = strtok (NULL, " ")) { p2 = strchr (p, '='); if (p2) { *p2++ = 0; abool = (*p2 == '1'); if (!strcmp (p, "ki")) parm->extcap.ki = abool; else if (!strcmp (p, "aac")) parm->extcap.aac = abool; } } xfree (buf); } } else if (keywordlen == 7 && !memcmp (keyword, "KEY-FPR", keywordlen)) { int no = atoi (line); while (*line && !spacep (line)) line++; while (spacep (line)) line++; if (no == 1) parm->fpr1valid = unhexify_fpr (line, parm->fpr1); else if (no == 2) parm->fpr2valid = unhexify_fpr (line, parm->fpr2); else if (no == 3) parm->fpr3valid = unhexify_fpr (line, parm->fpr3); } else if (keywordlen == 8 && !memcmp (keyword, "KEY-TIME", keywordlen)) { int no = atoi (line); while (* line && !spacep (line)) line++; while (spacep (line)) line++; if (no == 1) parm->fpr1time = strtoul (line, NULL, 10); else if (no == 2) parm->fpr2time = strtoul (line, NULL, 10); else if (no == 3) parm->fpr3time = strtoul (line, NULL, 10); } else if (keywordlen == 6 && !memcmp (keyword, "CA-FPR", keywordlen)) { int no = atoi (line); while (*line && !spacep (line)) line++; while (spacep (line)) line++; if (no == 1) parm->cafpr1valid = unhexify_fpr (line, parm->cafpr1); else if (no == 2) parm->cafpr2valid = unhexify_fpr (line, parm->cafpr2); else if (no == 3) parm->cafpr3valid = unhexify_fpr (line, parm->cafpr3); } else if (keywordlen == 8 && !memcmp (keyword, "KEY-ATTR", keywordlen)) { int keyno, algo, nbits; sscanf (line, "%d %d %d", &keyno, &algo, &nbits); keyno--; if (keyno >= 0 && keyno < DIM (parm->key_attr)) { parm->key_attr[keyno].algo = algo; parm->key_attr[keyno].nbits = nbits; } } return 0; } /* Call the agent to learn about a smartcard */ int agent_learn (struct agent_card_info_s *info) { int rc; rc = start_agent (NULL, 1); if (rc) return rc; /* Send the serialno command to initialize the connection. We don't care about the data returned. If the card has already been initialized, this is a very fast command. The main reason we need to do this here is to handle a card removed case so that an "l" command in --card-edit can be used to show ta newly inserted card. We request the openpgp card because that is what we expect. */ rc = assuan_transact (agent_ctx, "SCD SERIALNO openpgp", NULL, NULL, NULL, NULL, NULL, NULL); if (rc) return rc; memset (info, 0, sizeof *info); rc = assuan_transact (agent_ctx, "SCD LEARN --force", dummy_data_cb, NULL, default_inq_cb, NULL, learn_status_cb, info); /* Also try to get the key attributes. */ if (!rc) agent_scd_getattr ("KEY-ATTR", info); return rc; } /* Call the agent to retrieve a data object. This function returns the data in the same structure as used by the learn command. It is allowed to update such a structure using this commmand. */ int agent_scd_getattr (const char *name, struct agent_card_info_s *info) { int rc; char line[ASSUAN_LINELENGTH]; if (!*name) return gpg_error (GPG_ERR_INV_VALUE); /* We assume that NAME does not need escaping. */ if (12 + strlen (name) > DIM(line)-1) return gpg_error (GPG_ERR_TOO_LARGE); stpcpy (stpcpy (line, "SCD GETATTR "), name); rc = start_agent (NULL, 1); if (rc) return rc; rc = assuan_transact (agent_ctx, line, NULL, NULL, default_inq_cb, NULL, learn_status_cb, info); return rc; } /* Send an setattr command to the SCdaemon. SERIALNO is not actually used here but required by gpg 1.4's implementation of this code in cardglue.c. */ int agent_scd_setattr (const char *name, const unsigned char *value, size_t valuelen, const char *serialno) { int rc; char line[ASSUAN_LINELENGTH]; char *p; (void)serialno; if (!*name || !valuelen) return gpg_error (GPG_ERR_INV_VALUE); /* We assume that NAME does not need escaping. */ if (12 + strlen (name) > DIM(line)-1) return gpg_error (GPG_ERR_TOO_LARGE); p = stpcpy (stpcpy (line, "SCD SETATTR "), name); *p++ = ' '; for (; valuelen; value++, valuelen--) { if (p >= line + DIM(line)-5 ) return gpg_error (GPG_ERR_TOO_LARGE); if (*value < ' ' || *value == '+' || *value == '%') { sprintf (p, "%%%02X", *value); p += 3; } else if (*value == ' ') *p++ = '+'; else *p++ = *value; } *p = 0; rc = start_agent (NULL, 1); if (!rc) { rc = assuan_transact (agent_ctx, line, NULL, NULL, default_inq_cb, NULL, NULL, NULL); } status_sc_op_failure (rc); return rc; } /* Handle a CERTDATA inquiry. Note, we only send the data, assuan_transact takes care of flushing and writing the END command. */ static gpg_error_t inq_writecert_parms (void *opaque, const char *line) { int rc; struct writecert_parm_s *parm = opaque; if (!strncmp (line, "CERTDATA", 8) && (line[8]==' '||!line[8])) { rc = assuan_send_data (parm->ctx, parm->certdata, parm->certdatalen); } else rc = default_inq_cb (opaque, line); return rc; } /* Send a WRITECERT command to the SCdaemon. */ int agent_scd_writecert (const char *certidstr, const unsigned char *certdata, size_t certdatalen) { int rc; char line[ASSUAN_LINELENGTH]; struct writecert_parm_s parms; rc = start_agent (NULL, 1); if (rc) return rc; memset (&parms, 0, sizeof parms); snprintf (line, DIM(line)-1, "SCD WRITECERT %s", certidstr); line[DIM(line)-1] = 0; parms.ctx = agent_ctx; parms.certdata = certdata; parms.certdatalen = certdatalen; rc = assuan_transact (agent_ctx, line, NULL, NULL, inq_writecert_parms, &parms, NULL, NULL); return rc; } /* Handle a KEYDATA inquiry. Note, we only send the data, assuan_transact takes care of flushing and writing the end */ static gpg_error_t inq_writekey_parms (void *opaque, const char *line) { int rc; struct writekey_parm_s *parm = opaque; if (!strncmp (line, "KEYDATA", 7) && (line[7]==' '||!line[7])) { rc = assuan_send_data (parm->ctx, parm->keydata, parm->keydatalen); } else rc = default_inq_cb (opaque, line); return rc; } /* Send a WRITEKEY command to the SCdaemon. */ int agent_scd_writekey (int keyno, const char *serialno, const unsigned char *keydata, size_t keydatalen) { int rc; char line[ASSUAN_LINELENGTH]; struct writekey_parm_s parms; (void)serialno; rc = start_agent (NULL, 1); if (rc) return rc; memset (&parms, 0, sizeof parms); snprintf (line, DIM(line)-1, "SCD WRITEKEY --force OPENPGP.%d", keyno); line[DIM(line)-1] = 0; parms.ctx = agent_ctx; parms.keydata = keydata; parms.keydatalen = keydatalen; rc = assuan_transact (agent_ctx, line, NULL, NULL, inq_writekey_parms, &parms, NULL, NULL); status_sc_op_failure (rc); return rc; } static gpg_error_t scd_genkey_cb_append_savedbytes (struct scd_genkey_parm_s *parm, const char *line) { gpg_error_t err = 0; char *p; if (!parm->savedbytes) { parm->savedbytes = xtrystrdup (line); if (!parm->savedbytes) err = gpg_error_from_syserror (); } else { p = xtrymalloc (strlen (parm->savedbytes) + strlen (line) + 1); if (!p) err = gpg_error_from_syserror (); else { strcpy (stpcpy (p, parm->savedbytes), line); xfree (parm->savedbytes); parm->savedbytes = p; } } return err; } /* Status callback for the SCD GENKEY command. */ static gpg_error_t scd_genkey_cb (void *opaque, const char *line) { struct scd_genkey_parm_s *parm = opaque; const char *keyword = line; int keywordlen; gpg_error_t rc = 0; for (keywordlen=0; *line && !spacep (line); line++, keywordlen++) ; while (spacep (line)) line++; if (keywordlen == 7 && !memcmp (keyword, "KEY-FPR", keywordlen)) { parm->cgk->fprvalid = unhexify_fpr (line, parm->cgk->fpr); } else if (keywordlen == 8 && !memcmp (keyword, "KEY-DATA", keywordlen)) { gcry_mpi_t a; const char *name = line; while (*line && !spacep (line)) line++; while (spacep (line)) line++; if (*name == '-' && spacep (name+1)) rc = scd_genkey_cb_append_savedbytes (parm, line); else { if (parm->savedbytes) { rc = scd_genkey_cb_append_savedbytes (parm, line); if (!rc) rc = gcry_mpi_scan (&a, GCRYMPI_FMT_HEX, parm->savedbytes, 0, NULL); } else rc = gcry_mpi_scan (&a, GCRYMPI_FMT_HEX, line, 0, NULL); if (rc) log_error ("error parsing received key data: %s\n", gpg_strerror (rc)); else if (*name == 'n' && spacep (name+1)) parm->cgk->n = a; else if (*name == 'e' && spacep (name+1)) parm->cgk->e = a; else { log_info ("unknown parameter name in received key data\n"); gcry_mpi_release (a); rc = gpg_error (GPG_ERR_INV_PARAMETER); } xfree (parm->savedbytes); parm->savedbytes = NULL; } } else if (keywordlen == 14 && !memcmp (keyword,"KEY-CREATED-AT", keywordlen)) { parm->cgk->created_at = (u32)strtoul (line, NULL, 10); } else if (keywordlen == 8 && !memcmp (keyword, "PROGRESS", keywordlen)) { write_status_text (STATUS_PROGRESS, line); } return rc; } /* Send a GENKEY command to the SCdaemon. SERIALNO is not used in this implementation. If CREATEDATE is not 0, it will be passed to SCDAEMON so that the key is created with this timestamp. INFO will receive information about the generated key. */ int agent_scd_genkey (struct agent_card_genkey_s *info, int keyno, int force, const char *serialno, u32 createtime) { int rc; char line[ASSUAN_LINELENGTH]; gnupg_isotime_t tbuf; struct scd_genkey_parm_s parms; (void)serialno; memset (&parms, 0, sizeof parms); parms.cgk = info; rc = start_agent (NULL, 1); if (rc) return rc; if (createtime) epoch2isotime (tbuf, createtime); else *tbuf = 0; snprintf (line, DIM(line)-1, "SCD GENKEY %s%s %s %d", *tbuf? "--timestamp=":"", tbuf, force? "--force":"", keyno); line[DIM(line)-1] = 0; memset (info, 0, sizeof *info); rc = assuan_transact (agent_ctx, line, NULL, NULL, default_inq_cb, NULL, scd_genkey_cb, &parms); xfree (parms.savedbytes); status_sc_op_failure (rc); return rc; } /* Issue an SCD SERIALNO openpgp command and if SERIALNO is not NULL ask the user to insert the requested card. */ gpg_error_t select_openpgp (const char *serialno) { gpg_error_t err; /* Send the serialno command to initialize the connection. Without a given S/N we don't care about the data returned. If the card has already been initialized, this is a very fast command. We request the openpgp card because that is what we expect. Note that an opt.limit_card_insert_tries of 1 means: No tries at all whereas 0 means do not limit the number of tries. Due to the sue of a pinentry prompt with a cancel option we use it here in a boolean sense. */ if (!serialno || opt.limit_card_insert_tries == 1) err = assuan_transact (agent_ctx, "SCD SERIALNO openpgp", NULL, NULL, NULL, NULL, NULL, NULL); else { char *this_sn = NULL; char *desc; int ask; char *want_sn; char *p; want_sn = xtrystrdup (serialno); if (!want_sn) return gpg_error_from_syserror (); p = strchr (want_sn, '/'); if (p) *p = 0; do { ask = 0; err = assuan_transact (agent_ctx, "SCD SERIALNO openpgp", NULL, NULL, NULL, NULL, get_serialno_cb, &this_sn); if (gpg_err_code (err) == GPG_ERR_CARD_NOT_PRESENT) ask = 1; else if (gpg_err_code (err) == GPG_ERR_NOT_SUPPORTED) ask = 2; else if (err) ; else if (this_sn) { if (strcmp (want_sn, this_sn)) ask = 2; } xfree (this_sn); this_sn = NULL; if (ask) { char *formatted = NULL; char *ocodeset = i18n_switchto_utf8 (); if (!strncmp (want_sn, "D27600012401", 12) && strlen (want_sn) == 32 ) formatted = xtryasprintf ("(%.4s) %.8s", want_sn + 16, want_sn + 20); err = 0; desc = xtryasprintf ("%s:\n\n" " \"%s\"", ask == 1 ? _("Please insert the card with serial number") : _("Please remove the current card and " "insert the one with serial number"), formatted? formatted : want_sn); if (!desc) err = gpg_error_from_syserror (); xfree (formatted); i18n_switchback (ocodeset); if (!err) err = gpg_agent_get_confirmation (desc); xfree (desc); } } while (ask && !err); xfree (want_sn); } return err; } static gpg_error_t membuf_data_cb (void *opaque, const void *buffer, size_t length) { membuf_t *data = opaque; if (buffer) put_membuf (data, buffer, length); return 0; } /* Send a READCERT command to the SCdaemon. */ int agent_scd_readcert (const char *certidstr, void **r_buf, size_t *r_buflen) { int rc; char line[ASSUAN_LINELENGTH]; membuf_t data; size_t len; *r_buf = NULL; rc = start_agent (NULL, 1); if (rc) return rc; init_membuf (&data, 2048); snprintf (line, DIM(line)-1, "SCD READCERT %s", certidstr); line[DIM(line)-1] = 0; rc = assuan_transact (agent_ctx, line, membuf_data_cb, &data, default_inq_cb, NULL, NULL, NULL); if (rc) { xfree (get_membuf (&data, &len)); return rc; } *r_buf = get_membuf (&data, r_buflen); if (!*r_buf) return gpg_error (GPG_ERR_ENOMEM); return 0; } /* Change the PIN of an OpenPGP card or reset the retry counter. CHVNO 1: Change the PIN 2: For v1 cards: Same as 1. For v2 cards: Reset the PIN using the Reset Code. 3: Change the admin PIN 101: Set a new PIN and reset the retry counter 102: For v1 cars: Same as 101. For v2 cards: Set a new Reset Code. SERIALNO is not used. */ int agent_scd_change_pin (int chvno, const char *serialno) { int rc; char line[ASSUAN_LINELENGTH]; const char *reset = ""; (void)serialno; if (chvno >= 100) reset = "--reset"; chvno %= 100; rc = start_agent (NULL, 1); if (rc) return rc; snprintf (line, DIM(line)-1, "SCD PASSWD %s %d", reset, chvno); line[DIM(line)-1] = 0; rc = assuan_transact (agent_ctx, line, NULL, NULL, default_inq_cb, NULL, NULL, NULL); status_sc_op_failure (rc); return rc; } /* Perform a CHECKPIN operation. SERIALNO should be the serial number of the card - optionally followed by the fingerprint; however the fingerprint is ignored here. */ int agent_scd_checkpin (const char *serialno) { int rc; char line[ASSUAN_LINELENGTH]; rc = start_agent (NULL, 1); if (rc) return rc; snprintf (line, DIM(line)-1, "SCD CHECKPIN %s", serialno); line[DIM(line)-1] = 0; rc = assuan_transact (agent_ctx, line, NULL, NULL, default_inq_cb, NULL, NULL, NULL); status_sc_op_failure (rc); return rc; } /* Dummy function, only used by the gpg 1.4 implementation. */ void agent_clear_pin_cache (const char *sn) { (void)sn; } /* Note: All strings shall be UTF-8. On success the caller needs to free the string stored at R_PASSPHRASE. On error NULL will be stored at R_PASSPHRASE and an appropriate fpf error code returned. */ gpg_error_t agent_get_passphrase (const char *cache_id, const char *err_msg, const char *prompt, const char *desc_msg, int repeat, int check, char **r_passphrase) { int rc; char line[ASSUAN_LINELENGTH]; char *arg1 = NULL; char *arg2 = NULL; char *arg3 = NULL; char *arg4 = NULL; membuf_t data; *r_passphrase = NULL; rc = start_agent (NULL, 0); if (rc) return rc; /* Check that the gpg-agent understands the repeat option. */ if (assuan_transact (agent_ctx, "GETINFO cmd_has_option GET_PASSPHRASE repeat", NULL, NULL, NULL, NULL, NULL, NULL)) return gpg_error (GPG_ERR_NOT_SUPPORTED); if (cache_id && *cache_id) if (!(arg1 = percent_plus_escape (cache_id))) goto no_mem; if (err_msg && *err_msg) if (!(arg2 = percent_plus_escape (err_msg))) goto no_mem; if (prompt && *prompt) if (!(arg3 = percent_plus_escape (prompt))) goto no_mem; if (desc_msg && *desc_msg) if (!(arg4 = percent_plus_escape (desc_msg))) goto no_mem; snprintf (line, DIM(line)-1, "GET_PASSPHRASE --data --repeat=%d%s -- %s %s %s %s", repeat, check? " --check --qualitybar":"", arg1? arg1:"X", arg2? arg2:"X", arg3? arg3:"X", arg4? arg4:"X"); line[DIM(line)-1] = 0; xfree (arg1); xfree (arg2); xfree (arg3); xfree (arg4); init_membuf_secure (&data, 64); rc = assuan_transact (agent_ctx, line, membuf_data_cb, &data, default_inq_cb, NULL, NULL, NULL); if (rc) xfree (get_membuf (&data, NULL)); else { put_membuf (&data, "", 1); *r_passphrase = get_membuf (&data, NULL); if (!*r_passphrase) rc = gpg_error_from_syserror (); } return rc; no_mem: rc = gpg_error_from_syserror (); xfree (arg1); xfree (arg2); xfree (arg3); xfree (arg4); return rc; } gpg_error_t agent_clear_passphrase (const char *cache_id) { int rc; char line[ASSUAN_LINELENGTH]; if (!cache_id || !*cache_id) return 0; rc = start_agent (NULL, 0); if (rc) return rc; snprintf (line, DIM(line)-1, "CLEAR_PASSPHRASE %s", cache_id); line[DIM(line)-1] = 0; return assuan_transact (agent_ctx, line, NULL, NULL, default_inq_cb, NULL, NULL, NULL); } /* Ask the agent to pop up a confirmation dialog with the text DESC and an okay and cancel button. */ gpg_error_t gpg_agent_get_confirmation (const char *desc) { int rc; char *tmp; char line[ASSUAN_LINELENGTH]; rc = start_agent (NULL, 0); if (rc) return rc; tmp = percent_plus_escape (desc); if (!tmp) return gpg_error_from_syserror (); snprintf (line, DIM(line)-1, "GET_CONFIRMATION %s", tmp); line[DIM(line)-1] = 0; xfree (tmp); rc = assuan_transact (agent_ctx, line, NULL, NULL, default_inq_cb, NULL, NULL, NULL); return rc; } /* Return the S2K iteration count as computed by gpg-agent. */ gpg_error_t agent_get_s2k_count (unsigned long *r_count) { gpg_error_t err; membuf_t data; char *buf; *r_count = 0; err = start_agent (NULL, 0); if (err) return err; init_membuf (&data, 32); err = assuan_transact (agent_ctx, "GETINFO s2k_count", membuf_data_cb, &data, NULL, NULL, NULL, NULL); if (err) xfree (get_membuf (&data, NULL)); else { put_membuf (&data, "", 1); buf = get_membuf (&data, NULL); if (!buf) err = gpg_error_from_syserror (); else { *r_count = strtoul (buf, NULL, 10); xfree (buf); } } return err; } /* Ask the agent whether a secret key for the given public key is available. Returns 0 if available. */ gpg_error_t agent_probe_secret_key (ctrl_t ctrl, PKT_public_key *pk) { gpg_error_t err; char line[ASSUAN_LINELENGTH]; char *hexgrip; err = start_agent (ctrl, 0); if (err) return err; err = hexkeygrip_from_pk (pk, &hexgrip); if (err) return err; snprintf (line, sizeof line, "HAVEKEY %s", hexgrip); xfree (hexgrip); err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); return err; } /* Ask the agent whether a secret key is availabale for any of the keys (primary or sub) in KEYBLOCK. Returns 0 if available. */ gpg_error_t agent_probe_any_secret_key (ctrl_t ctrl, kbnode_t keyblock) { gpg_error_t err; char line[ASSUAN_LINELENGTH]; char *p; kbnode_t kbctx, node; int nkeys; unsigned char grip[20]; err = start_agent (ctrl, 0); if (err) return err; err = gpg_error (GPG_ERR_NO_SECKEY); /* Just in case no key was found in KEYBLOCK. */ p = stpcpy (line, "HAVEKEY"); for (kbctx=NULL, nkeys=0; (node = walk_kbnode (keyblock, &kbctx, 0)); ) if (node->pkt->pkttype == PKT_PUBLIC_KEY || node->pkt->pkttype == PKT_PUBLIC_SUBKEY || node->pkt->pkttype == PKT_SECRET_KEY || node->pkt->pkttype == PKT_SECRET_SUBKEY) { if (nkeys && ((p - line) + 41) > (ASSUAN_LINELENGTH - 2)) { err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (err != gpg_err_code (GPG_ERR_NO_SECKEY)) break; /* Seckey available or unexpected error - ready. */ p = stpcpy (line, "HAVEKEY"); nkeys = 0; } err = keygrip_from_pk (node->pkt->pkt.public_key, grip); if (err) return err; *p++ = ' '; bin2hex (grip, 20, p); p += 40; nkeys++; } if (!err && nkeys) err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); return err; } static gpg_error_t keyinfo_status_cb (void *opaque, const char *line) { char **serialno = opaque; const char *s, *s2; if (!strncmp (line, "KEYINFO ", 8) && !*serialno) { s = strchr (line+8, ' '); if (s && s[1] == 'T' && s[2] == ' ' && s[3]) { s += 3; s2 = strchr (s, ' '); if ( s2 > s ) { *serialno = xtrymalloc ((s2 - s)+1); if (*serialno) { memcpy (*serialno, s, s2 - s); (*serialno)[s2 - s] = 0; } } } } return 0; } /* Return the serial number for a secret key. If the returned serial number is NULL, the key is not stored on a smartcard. Caller needs to free R_SERIALNO. */ gpg_error_t agent_get_keyinfo (ctrl_t ctrl, const char *hexkeygrip, char **r_serialno) { gpg_error_t err; char line[ASSUAN_LINELENGTH]; char *serialno = NULL; *r_serialno = NULL; err = start_agent (ctrl, 0); if (err) return err; if (!hexkeygrip || strlen (hexkeygrip) != 40) return gpg_error (GPG_ERR_INV_VALUE); snprintf (line, DIM(line)-1, "KEYINFO %s", hexkeygrip); line[DIM(line)-1] = 0; err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, keyinfo_status_cb, &serialno); if (!err && serialno) { /* Sanity check for bad characters. */ if (strpbrk (serialno, ":\n\r")) err = GPG_ERR_INV_VALUE; } if (err) xfree (serialno); else *r_serialno = serialno; return err; } /* Status callback for agent_import_key, agent_export_key and agent_genkey. */ static gpg_error_t cache_nonce_status_cb (void *opaque, const char *line) { struct cache_nonce_parm_s *parm = opaque; const char *keyword = line; int keywordlen; for (keywordlen=0; *line && !spacep (line); line++, keywordlen++) ; while (spacep (line)) line++; if (keywordlen == 11 && !memcmp (keyword, "CACHE_NONCE", keywordlen)) { if (parm->cache_nonce_addr) { xfree (*parm->cache_nonce_addr); *parm->cache_nonce_addr = xtrystrdup (line); } } else if (keywordlen == 12 && !memcmp (keyword, "PASSWD_NONCE", keywordlen)) { if (parm->passwd_nonce_addr) { xfree (*parm->passwd_nonce_addr); *parm->passwd_nonce_addr = xtrystrdup (line); } } return 0; } /* Handle a KEYPARMS inquiry. Note, we only send the data, assuan_transact takes care of flushing and writing the end */ static gpg_error_t inq_genkey_parms (void *opaque, const char *line) { struct genkey_parm_s *parm = opaque; gpg_error_t err; if (!strncmp (line, "KEYPARAM", 8) && (line[8]==' '||!line[8])) { err = assuan_send_data (parm->ctx, parm->keyparms, strlen (parm->keyparms)); } else err = default_inq_cb (parm->ctrl, line); return err; } /* Call the agent to generate a new key. KEYPARMS is the usual S-expression giving the parameters of the key. gpg-agent passes it gcry_pk_genkey. If NO_PROTECTION is true the agent is advised not to protect the generated key. */ gpg_error_t agent_genkey (ctrl_t ctrl, char **cache_nonce_addr, const char *keyparms, int no_protection, gcry_sexp_t *r_pubkey) { gpg_error_t err; struct genkey_parm_s gk_parm; struct cache_nonce_parm_s cn_parm; membuf_t data; size_t len; unsigned char *buf; char line[ASSUAN_LINELENGTH]; *r_pubkey = NULL; err = start_agent (ctrl, 0); if (err) return err; err = assuan_transact (agent_ctx, "RESET", NULL, NULL, NULL, NULL, NULL, NULL); if (err) return err; init_membuf (&data, 1024); gk_parm.ctrl = ctrl; gk_parm.ctx = agent_ctx; gk_parm.keyparms = keyparms; snprintf (line, sizeof line, "GENKEY%s%s%s", no_protection? " --no-protection":"", cache_nonce_addr && *cache_nonce_addr? " ":"", cache_nonce_addr && *cache_nonce_addr? *cache_nonce_addr:""); cn_parm.cache_nonce_addr = cache_nonce_addr; cn_parm.passwd_nonce_addr = NULL; err = assuan_transact (agent_ctx, line, membuf_data_cb, &data, inq_genkey_parms, &gk_parm, cache_nonce_status_cb, &cn_parm); if (err) { xfree (get_membuf (&data, &len)); return err; } buf = get_membuf (&data, &len); if (!buf) err = gpg_error_from_syserror (); else { err = gcry_sexp_sscan (r_pubkey, NULL, buf, len); xfree (buf); } return err; } - -/* FIXME: Call the agent to read the public key part for a given keygrip. If +/* Call the agent to read the public key part for a given keygrip. If FROMCARD is true, the key is directly read from the current smartcard. In this case HEXKEYGRIP should be the keyID (e.g. OPENPGP.3). */ -/* int */ -/* agent_readkey (ctrl_t ctrl, int fromcard, const char *hexkeygrip, */ -/* ksba_sexp_t *r_pubkey) */ -/* { */ -/* int rc; */ -/* membuf_t data; */ -/* size_t len; */ -/* unsigned char *buf; */ -/* char line[ASSUAN_LINELENGTH]; */ - -/* *r_pubkey = NULL; */ -/* rc = start_agent (ctrl); */ -/* if (rc) */ -/* return rc; */ - -/* rc = assuan_transact (agent_ctx, "RESET",NULL, NULL, NULL, NULL, NULL, NULL); */ -/* if (rc) */ -/* return rc; */ - -/* snprintf (line, DIM(line)-1, "%sREADKEY %s", */ -/* fromcard? "SCD ":"", hexkeygrip); */ -/* line[DIM(line)-1] = 0; */ - -/* init_membuf (&data, 1024); */ -/* rc = assuan_transact (agent_ctx, line, */ -/* membuf_data_cb, &data, */ -/* default_inq_cb, ctrl, NULL, NULL); */ -/* if (rc) */ -/* { */ -/* xfree (get_membuf (&data, &len)); */ -/* return rc; */ -/* } */ -/* buf = get_membuf (&data, &len); */ -/* if (!buf) */ -/* return gpg_error (GPG_ERR_ENOMEM); */ -/* if (!gcry_sexp_canon_len (buf, len, NULL, NULL)) */ -/* { */ -/* xfree (buf); */ -/* return gpg_error (GPG_ERR_INV_SEXP); */ -/* } */ -/* *r_pubkey = buf; */ -/* return 0; */ -/* } */ +gpg_error_t +agent_readkey (ctrl_t ctrl, int fromcard, const char *hexkeygrip, + unsigned char **r_pubkey) +{ + gpg_error_t err; + membuf_t data; + size_t len; + unsigned char *buf; + char line[ASSUAN_LINELENGTH]; + + *r_pubkey = NULL; + err = start_agent (ctrl, 0); + if (err) + return err; + + err = assuan_transact (agent_ctx, "RESET",NULL, NULL, NULL, NULL, NULL, NULL); + if (err) + return err; + + snprintf (line, DIM(line)-1, "%sREADKEY %s", fromcard? "SCD ":"", hexkeygrip); + + init_membuf (&data, 1024); + err = assuan_transact (agent_ctx, line, + membuf_data_cb, &data, + default_inq_cb, NULL, NULL, NULL); + if (err) + { + xfree (get_membuf (&data, &len)); + return err; + } + buf = get_membuf (&data, &len); + if (!buf) + return gpg_error_from_syserror (); + if (!gcry_sexp_canon_len (buf, len, NULL, NULL)) + { + xfree (buf); + return gpg_error (GPG_ERR_INV_SEXP); + } + *r_pubkey = buf; + return 0; +} /* Call the agent to do a sign operation using the key identified by the hex string KEYGRIP. DESC is a description of the key to be displayed if the agent needs to ask for the PIN. DIGEST and DIGESTLEN is the hash value to sign and DIGESTALGO the algorithm id used to compute the digest. If CACHE_NONCE is used the agent is advised to first try a passphrase associated with that nonce. */ gpg_error_t agent_pksign (ctrl_t ctrl, const char *cache_nonce, const char *keygrip, const char *desc, unsigned char *digest, size_t digestlen, int digestalgo, gcry_sexp_t *r_sigval) { gpg_error_t err; char line[ASSUAN_LINELENGTH]; membuf_t data; *r_sigval = NULL; err = start_agent (ctrl, 0); if (err) return err; if (digestlen*2 + 50 > DIM(line)) return gpg_error (GPG_ERR_GENERAL); err = assuan_transact (agent_ctx, "RESET", NULL, NULL, NULL, NULL, NULL, NULL); if (err) return err; snprintf (line, DIM(line)-1, "SIGKEY %s", keygrip); line[DIM(line)-1] = 0; err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (err) return err; if (desc) { snprintf (line, DIM(line)-1, "SETKEYDESC %s", desc); line[DIM(line)-1] = 0; err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (err) return err; } snprintf (line, sizeof line, "SETHASH %d ", digestalgo); bin2hex (digest, digestlen, line + strlen (line)); err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (err) return err; init_membuf (&data, 1024); snprintf (line, sizeof line, "PKSIGN%s%s", cache_nonce? " -- ":"", cache_nonce? cache_nonce:""); err = assuan_transact (agent_ctx, line, membuf_data_cb, &data, default_inq_cb, ctrl, NULL, NULL); if (err) xfree (get_membuf (&data, NULL)); else { unsigned char *buf; size_t len; buf = get_membuf (&data, &len); if (!buf) err = gpg_error_from_syserror (); else { err = gcry_sexp_sscan (r_sigval, NULL, buf, len); xfree (buf); } } return err; } /* Handle a CIPHERTEXT inquiry. Note, we only send the data, assuan_transact takes care of flushing and writing the END. */ static gpg_error_t inq_ciphertext_cb (void *opaque, const char *line) { struct cipher_parm_s *parm = opaque; int rc; if (!strncmp (line, "CIPHERTEXT", 10) && (line[10]==' '||!line[10])) { assuan_begin_confidential (parm->ctx); rc = assuan_send_data (parm->ctx, parm->ciphertext, parm->ciphertextlen); assuan_end_confidential (parm->ctx); } else rc = default_inq_cb (parm->ctrl, line); return rc; } /* Call the agent to do a decrypt operation using the key identified by the hex string KEYGRIP and the input data S_CIPHERTEXT. On the success the decoded value is stored verbatim at R_BUF and its length at R_BUF; the callers needs to release it. */ gpg_error_t agent_pkdecrypt (ctrl_t ctrl, const char *keygrip, const char *desc, gcry_sexp_t s_ciphertext, unsigned char **r_buf, size_t *r_buflen) { gpg_error_t err; char line[ASSUAN_LINELENGTH]; membuf_t data; size_t n, len; char *p, *buf, *endp; if (!keygrip || strlen(keygrip) != 40 || !s_ciphertext || !r_buf || !r_buflen) return gpg_error (GPG_ERR_INV_VALUE); *r_buf = NULL; err = start_agent (ctrl, 0); if (err) return err; err = assuan_transact (agent_ctx, "RESET", NULL, NULL, NULL, NULL, NULL, NULL); if (err) return err; snprintf (line, sizeof line, "SETKEY %s", keygrip); err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (err) return err; if (desc) { snprintf (line, DIM(line)-1, "SETKEYDESC %s", desc); line[DIM(line)-1] = 0; err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (err) return err; } init_membuf_secure (&data, 1024); { struct cipher_parm_s parm; parm.ctrl = ctrl; parm.ctx = agent_ctx; err = make_canon_sexp (s_ciphertext, &parm.ciphertext, &parm.ciphertextlen); if (err) return err; err = assuan_transact (agent_ctx, "PKDECRYPT", membuf_data_cb, &data, inq_ciphertext_cb, &parm, NULL, NULL); xfree (parm.ciphertext); } if (err) { xfree (get_membuf (&data, &len)); return err; } put_membuf (&data, "", 1); /* Make sure it is 0 terminated. */ buf = get_membuf (&data, &len); if (!buf) return gpg_error_from_syserror (); assert (len); /* (we forced Nul termination.) */ if (*buf != '(') { xfree (buf); return gpg_error (GPG_ERR_INV_SEXP); } if (len < 13 || memcmp (buf, "(5:value", 8) ) /* "(5:valueN:D)\0" */ { xfree (buf); return gpg_error (GPG_ERR_INV_SEXP); } len -= 11; /* Count only the data of the second part. */ p = buf + 8; /* Skip leading parenthesis and the value tag. */ n = strtoul (p, &endp, 10); if (!n || *endp != ':') { xfree (buf); return gpg_error (GPG_ERR_INV_SEXP); } endp++; if (endp-p+n > len) { xfree (buf); return gpg_error (GPG_ERR_INV_SEXP); /* Oops: Inconsistent S-Exp. */ } memmove (buf, endp, n); *r_buflen = n; *r_buf = buf; return 0; } /* Retrieve a key encryption key from the agent. With FOREXPORT true the key shall be used for export, with false for import. On success the new key is stored at R_KEY and its length at R_KEKLEN. */ gpg_error_t agent_keywrap_key (ctrl_t ctrl, int forexport, void **r_kek, size_t *r_keklen) { gpg_error_t err; membuf_t data; size_t len; unsigned char *buf; char line[ASSUAN_LINELENGTH]; *r_kek = NULL; err = start_agent (ctrl, 0); if (err) return err; snprintf (line, DIM(line)-1, "KEYWRAP_KEY %s", forexport? "--export":"--import"); init_membuf_secure (&data, 64); err = assuan_transact (agent_ctx, line, membuf_data_cb, &data, default_inq_cb, ctrl, NULL, NULL); if (err) { xfree (get_membuf (&data, &len)); return err; } buf = get_membuf (&data, &len); if (!buf) return gpg_error_from_syserror (); *r_kek = buf; *r_keklen = len; return 0; } /* Handle the inquiry for an IMPORT_KEY command. */ static gpg_error_t inq_import_key_parms (void *opaque, const char *line) { struct import_key_parm_s *parm = opaque; gpg_error_t err; if (!strncmp (line, "KEYDATA", 7) && (line[7]==' '||!line[7])) { err = assuan_send_data (parm->ctx, parm->key, parm->keylen); } else err = default_inq_cb (parm->ctrl, line); return err; } /* Call the agent to import a key into the agent. */ gpg_error_t agent_import_key (ctrl_t ctrl, const char *desc, char **cache_nonce_addr, const void *key, size_t keylen) { gpg_error_t err; struct import_key_parm_s parm; struct cache_nonce_parm_s cn_parm; char line[ASSUAN_LINELENGTH]; err = start_agent (ctrl, 0); if (err) return err; if (desc) { snprintf (line, DIM(line)-1, "SETKEYDESC %s", desc); line[DIM(line)-1] = 0; err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (err) return err; } parm.ctrl = ctrl; parm.ctx = agent_ctx; parm.key = key; parm.keylen = keylen; snprintf (line, sizeof line, "IMPORT_KEY%s%s", cache_nonce_addr && *cache_nonce_addr? " ":"", cache_nonce_addr && *cache_nonce_addr? *cache_nonce_addr:""); cn_parm.cache_nonce_addr = cache_nonce_addr; cn_parm.passwd_nonce_addr = NULL; err = assuan_transact (agent_ctx, line, NULL, NULL, inq_import_key_parms, &parm, cache_nonce_status_cb, &cn_parm); return err; } /* Receive a secret key from the agent. HEXKEYGRIP is the hexified keygrip, DESC a prompt to be displayed with the agent's passphrase question (needs to be plus+percent escaped). On success the key is stored as a canonical S-expression at R_RESULT and R_RESULTLEN. */ gpg_error_t agent_export_key (ctrl_t ctrl, const char *hexkeygrip, const char *desc, char **cache_nonce_addr, unsigned char **r_result, size_t *r_resultlen) { gpg_error_t err; struct cache_nonce_parm_s cn_parm; membuf_t data; size_t len; unsigned char *buf; char line[ASSUAN_LINELENGTH]; *r_result = NULL; err = start_agent (ctrl, 0); if (err) return err; if (desc) { snprintf (line, DIM(line)-1, "SETKEYDESC %s", desc); err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (err) return err; } snprintf (line, DIM(line)-1, "EXPORT_KEY --openpgp %s%s %s", cache_nonce_addr && *cache_nonce_addr? "--cache-nonce=":"", cache_nonce_addr && *cache_nonce_addr? *cache_nonce_addr:"", hexkeygrip); init_membuf_secure (&data, 1024); cn_parm.cache_nonce_addr = cache_nonce_addr; cn_parm.passwd_nonce_addr = NULL; err = assuan_transact (agent_ctx, line, membuf_data_cb, &data, default_inq_cb, ctrl, cache_nonce_status_cb, &cn_parm); if (err) { xfree (get_membuf (&data, &len)); return err; } buf = get_membuf (&data, &len); if (!buf) return gpg_error_from_syserror (); *r_result = buf; *r_resultlen = len; return 0; } /* Ask the agent to change the passphrase of the key identified by HEXKEYGRIP. If DESC is not NULL, display DESC instead of the default description message. If CACHE_NONCE_ADDR is not NULL the agent is advised to first try a passphrase associated with that nonce. If PASSWD_NONCE_ADDR is not NULL the agent will try to use the passphrase associated with that nonce. */ gpg_error_t agent_passwd (ctrl_t ctrl, const char *hexkeygrip, const char *desc, char **cache_nonce_addr, char **passwd_nonce_addr) { gpg_error_t err; struct cache_nonce_parm_s cn_parm; char line[ASSUAN_LINELENGTH]; err = start_agent (ctrl, 0); if (err) return err; if (!hexkeygrip || strlen (hexkeygrip) != 40) return gpg_error (GPG_ERR_INV_VALUE); if (desc) { snprintf (line, DIM(line)-1, "SETKEYDESC %s", desc); err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (err) return err; } snprintf (line, DIM(line)-1, "PASSWD %s%s %s%s %s", cache_nonce_addr && *cache_nonce_addr? "--cache-nonce=":"", cache_nonce_addr && *cache_nonce_addr? *cache_nonce_addr:"", passwd_nonce_addr && *passwd_nonce_addr? "--passwd-nonce=":"", passwd_nonce_addr && *passwd_nonce_addr? *passwd_nonce_addr:"", hexkeygrip); cn_parm.cache_nonce_addr = cache_nonce_addr; cn_parm.passwd_nonce_addr = passwd_nonce_addr; err = assuan_transact (agent_ctx, line, NULL, NULL, default_inq_cb, ctrl, cache_nonce_status_cb, &cn_parm); return err; } diff --git a/g10/call-agent.h b/g10/call-agent.h index 1e7e15abc..43de14fe3 100644 --- a/g10/call-agent.h +++ b/g10/call-agent.h @@ -1,182 +1,186 @@ /* call-agent.h - Divert operations to the agent * Copyright (C) 2003 Free Software Foundation, Inc. * * This file is part of GnuPG. * * GnuPG is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * GnuPG is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ #ifndef GNUPG_G10_CALL_AGENT_H #define GNUPG_G10_CALL_AGENT_H struct agent_card_info_s { int error; /* private. */ char *apptype; /* Malloced application type string. */ char *serialno; /* malloced hex string. */ char *disp_name; /* malloced. */ char *disp_lang; /* malloced. */ int disp_sex; /* 0 = unspecified, 1 = male, 2 = female */ char *pubkey_url; /* malloced. */ char *login_data; /* malloced. */ char *private_do[4]; /* malloced. */ char cafpr1valid; char cafpr2valid; char cafpr3valid; char cafpr1[20]; char cafpr2[20]; char cafpr3[20]; char fpr1valid; char fpr2valid; char fpr3valid; char fpr1[20]; char fpr2[20]; char fpr3[20]; u32 fpr1time; u32 fpr2time; u32 fpr3time; unsigned long sig_counter; int chv1_cached; /* True if a PIN is not required for each signing. Note that the gpg-agent might cache it anyway. */ int is_v2; /* True if this is a v2 card. */ int chvmaxlen[3]; /* Maximum allowed length of a CHV. */ int chvretry[3]; /* Allowed retries for the CHV; 0 = blocked. */ struct { /* Array with key attributes. */ int algo; /* Algorithm identifier. */ unsigned int nbits; /* Supported keysize. */ } key_attr[3]; struct { unsigned int ki:1; /* Key import available. */ unsigned int aac:1; /* Algorithm attributes are changeable. */ } extcap; }; struct agent_card_genkey_s { char fprvalid; char fpr[20]; u32 created_at; gcry_mpi_t n; gcry_mpi_t e; }; /* Release the card info structure. */ void agent_release_card_info (struct agent_card_info_s *info); /* Return card info. */ int agent_learn (struct agent_card_info_s *info); /* Update INFO with the attribute NAME. */ int agent_scd_getattr (const char *name, struct agent_card_info_s *info); /* Send a SETATTR command to the SCdaemon. */ int agent_scd_setattr (const char *name, const unsigned char *value, size_t valuelen, const char *serialno); /* Send a WRITECERT command to the SCdaemon. */ int agent_scd_writecert (const char *certidstr, const unsigned char *certdata, size_t certdatalen); /* Send a WRITEKEY command to the SCdaemon. */ int agent_scd_writekey (int keyno, const char *serialno, const unsigned char *keydata, size_t keydatalen); /* Send a GENKEY command to the SCdaemon. */ int agent_scd_genkey (struct agent_card_genkey_s *info, int keyno, int force, const char *serialno, u32 createtime); /* Send a READKEY command to the SCdaemon. */ int agent_scd_readcert (const char *certidstr, void **r_buf, size_t *r_buflen); /* Change the PIN of an OpenPGP card or reset the retry counter. */ int agent_scd_change_pin (int chvno, const char *serialno); /* Send the CHECKPIN command to the SCdaemon. */ int agent_scd_checkpin (const char *serialno); /* Dummy function, only implemented by gpg 1.4. */ void agent_clear_pin_cache (const char *sn); /* Send the GET_PASSPHRASE command to the agent. */ gpg_error_t agent_get_passphrase (const char *cache_id, const char *err_msg, const char *prompt, const char *desc_msg, int repeat, int check, char **r_passphrase); /* Send the CLEAR_PASSPHRASE command to the agent. */ gpg_error_t agent_clear_passphrase (const char *cache_id); /* Present the prompt DESC and ask the user to confirm. */ gpg_error_t gpg_agent_get_confirmation (const char *desc); /* Return the S2K iteration count as computed by gpg-agent. */ gpg_error_t agent_get_s2k_count (unsigned long *r_count); /* Check whether a secret key for public key PK is available. Returns 0 if the secret key is available. */ gpg_error_t agent_probe_secret_key (ctrl_t ctrl, PKT_public_key *pk); /* Ask the agent whether a secret key is availabale for any of the keys (primary or sub) in KEYBLOCK. Returns 0 if available. */ gpg_error_t agent_probe_any_secret_key (ctrl_t ctrl, kbnode_t keyblock); /* Return infos about the secret key with HEXKEYGRIP. */ gpg_error_t agent_get_keyinfo (ctrl_t ctrl, const char *hexkeygrip, char **r_serialno); /* Generate a new key. */ gpg_error_t agent_genkey (ctrl_t ctrl, char **cache_nonce_addr, const char *keyparms, int no_protection, gcry_sexp_t *r_pubkey); +/* Read a public key. */ +gpg_error_t agent_readkey (ctrl_t ctrl, int fromcard, const char *hexkeygrip, + unsigned char **r_pubkey); + /* Create a signature. */ gpg_error_t agent_pksign (ctrl_t ctrl, const char *cache_nonce, const char *hexkeygrip, const char *desc, unsigned char *digest, size_t digestlen, int digestalgo, gcry_sexp_t *r_sigval); /* Decrypt a ciphertext. */ gpg_error_t agent_pkdecrypt (ctrl_t ctrl, const char *keygrip, const char *desc, gcry_sexp_t s_ciphertext, unsigned char **r_buf, size_t *r_buflen); /* Retrieve a key encryption key. */ gpg_error_t agent_keywrap_key (ctrl_t ctrl, int forexport, void **r_kek, size_t *r_keklen); /* Send a key to the agent. */ gpg_error_t agent_import_key (ctrl_t ctrl, const char *desc, char **cache_nonce_addr, const void *key, size_t keylen); /* Receive a key from the agent. */ gpg_error_t agent_export_key (ctrl_t ctrl, const char *keygrip, const char *desc, char **cache_nonce_addr, unsigned char **r_result, size_t *r_resultlen); /* Change the passphrase of a key. */ gpg_error_t agent_passwd (ctrl_t ctrl, const char *hexkeygrip, const char *desc, char **cache_nonce_addr, char **passwd_nonce_addr); #endif /*GNUPG_G10_CALL_AGENT_H*/ diff --git a/g10/card-util.c b/g10/card-util.c index 9c124bbfc..14268dfeb 100644 --- a/g10/card-util.c +++ b/g10/card-util.c @@ -1,2016 +1,2016 @@ /* card-util.c - Utility functions for the OpenPGP card. * Copyright (C) 2003, 2004, 2005, 2009 Free Software Foundation, Inc. * * This file is part of GnuPG. * * GnuPG is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * GnuPG is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ #include #include #include #include #include #include #ifdef HAVE_LIBREADLINE # define GNUPG_LIBREADLINE_H_INCLUDED # include #endif /*HAVE_LIBREADLINE*/ #if GNUPG_MAJOR_VERSION != 1 # include "gpg.h" #endif /*GNUPG_MAJOR_VERSION != 1*/ #include "util.h" #include "i18n.h" #include "ttyio.h" #include "status.h" #include "options.h" #include "main.h" #include "keyserver-internal.h" #if GNUPG_MAJOR_VERSION == 1 # include "cardglue.h" #else /*GNUPG_MAJOR_VERSION!=1*/ # include "call-agent.h" #endif /*GNUPG_MAJOR_VERSION!=1*/ #define CONTROL_D ('D' - 'A' + 1) static void write_sc_op_status (gpg_error_t err) { switch (gpg_err_code (err)) { case 0: write_status (STATUS_SC_OP_SUCCESS); break; #if GNUPG_MAJOR_VERSION != 1 case GPG_ERR_CANCELED: case GPG_ERR_FULLY_CANCELED: write_status_text (STATUS_SC_OP_FAILURE, "1"); break; case GPG_ERR_BAD_PIN: write_status_text (STATUS_SC_OP_FAILURE, "2"); break; default: write_status (STATUS_SC_OP_FAILURE); break; #endif /* GNUPG_MAJOR_VERSION != 1 */ } } /* Change the PIN of a an OpenPGP card. This is an interactive function. */ void change_pin (int unblock_v2, int allow_admin) { struct agent_card_info_s info; int rc; rc = agent_learn (&info); if (rc) { log_error (_("OpenPGP card not available: %s\n"), gpg_strerror (rc)); return; } log_info (_("OpenPGP card no. %s detected\n"), info.serialno? info.serialno : "[none]"); agent_clear_pin_cache (info.serialno); if (opt.batch) { agent_release_card_info (&info); log_error (_("can't do this in batch mode\n")); return; } if (unblock_v2) { if (!info.is_v2) log_error (_("This command is only available for version 2 cards\n")); else if (!info.chvretry[1]) log_error (_("Reset Code not or not anymore available\n")); else { rc = agent_scd_change_pin (2, info.serialno); write_sc_op_status (rc); if (rc) tty_printf ("Error changing the PIN: %s\n", gpg_strerror (rc)); else tty_printf ("PIN changed.\n"); } } else if (!allow_admin) { rc = agent_scd_change_pin (1, info.serialno); write_sc_op_status (rc); if (rc) tty_printf ("Error changing the PIN: %s\n", gpg_strerror (rc)); else tty_printf ("PIN changed.\n"); } else for (;;) { char *answer; tty_printf ("\n"); tty_printf ("1 - change PIN\n" "2 - unblock PIN\n" "3 - change Admin PIN\n" "4 - set the Reset Code\n" "Q - quit\n"); tty_printf ("\n"); answer = cpr_get("cardutil.change_pin.menu",_("Your selection? ")); cpr_kill_prompt(); if (strlen (answer) != 1) continue; rc = 0; if (*answer == '1') { /* Change PIN. */ rc = agent_scd_change_pin (1, info.serialno); write_sc_op_status (rc); if (rc) tty_printf ("Error changing the PIN: %s\n", gpg_strerror (rc)); else tty_printf ("PIN changed.\n"); } else if (*answer == '2') { /* Unblock PIN. */ rc = agent_scd_change_pin (101, info.serialno); write_sc_op_status (rc); if (rc) tty_printf ("Error unblocking the PIN: %s\n", gpg_strerror (rc)); else tty_printf ("PIN unblocked and new PIN set.\n"); } else if (*answer == '3') { /* Change Admin PIN. */ rc = agent_scd_change_pin (3, info.serialno); write_sc_op_status (rc); if (rc) tty_printf ("Error changing the PIN: %s\n", gpg_strerror (rc)); else tty_printf ("PIN changed.\n"); } else if (*answer == '4') { /* Set a new Reset Code. */ rc = agent_scd_change_pin (102, info.serialno); write_sc_op_status (rc); if (rc) tty_printf ("Error setting the Reset Code: %s\n", gpg_strerror (rc)); else tty_printf ("Reset Code set.\n"); } else if (*answer == 'q' || *answer == 'Q') { break; } } agent_release_card_info (&info); } static const char * get_manufacturer (unsigned int no) { /* Note: Make sure that there is no colon or linefeed in the string. */ switch (no) { case 0x0001: return "PPC Card Systems"; case 0x0002: return "Prism"; case 0x0003: return "OpenFortress"; case 0x0004: return "Wewid AB"; case 0x0005: return "ZeitControl"; case 0x002A: return "Magrathea"; case 0xF517: return "FSIJ"; /* 0x00000 and 0xFFFF are defined as test cards per spec, 0xFFF00 to 0xFFFE are assigned for use with randomly created serial numbers. */ case 0x0000: case 0xffff: return "test card"; default: return (no & 0xff00) == 0xff00? "unmanaged S/N range":"unknown"; } } static void print_sha1_fpr (estream_t fp, const unsigned char *fpr) { int i; if (fpr) { for (i=0; i < 20 ; i+=2, fpr += 2 ) { if (i == 10 ) tty_fprintf (fp, " "); tty_fprintf (fp, " %02X%02X", *fpr, fpr[1]); } } else tty_fprintf (fp, " [none]"); tty_fprintf (fp, "\n"); } static void print_sha1_fpr_colon (estream_t fp, const unsigned char *fpr) { int i; if (fpr) { for (i=0; i < 20 ; i++, fpr++) es_fprintf (fp, "%02X", *fpr); } es_putc (':', fp); } static void print_name (estream_t fp, const char *text, const char *name) { tty_fprintf (fp, "%s", text); /* FIXME: tty_printf_utf8_string2 eats everything after and including an @ - e.g. when printing an url. */ if (name && *name) { if (fp) print_utf8_buffer2 (fp, name, strlen (name), '\n'); else tty_print_utf8_string2 (name, strlen (name), 0); } else tty_fprintf (fp, _("[not set]")); tty_fprintf (fp, "\n"); } static void print_isoname (estream_t fp, const char *text, const char *tag, const char *name) { if (opt.with_colons) es_fprintf (fp, "%s:", tag); else tty_fprintf (fp, "%s", text); if (name && *name) { char *p, *given, *buf = xstrdup (name); given = strstr (buf, "<<"); for (p=buf; *p; p++) if (*p == '<') *p = ' '; if (given && given[2]) { *given = 0; given += 2; if (opt.with_colons) es_write_sanitized (fp, given, strlen (given), ":", NULL); else if (fp) print_utf8_buffer2 (fp, given, strlen (given), '\n'); else tty_print_utf8_string2 (given, strlen (given), 0); if (opt.with_colons) es_putc (':', fp); else if (*buf) tty_fprintf (fp, " "); } if (opt.with_colons) es_write_sanitized (fp, buf, strlen (buf), ":", NULL); else if (fp) print_utf8_buffer2 (fp, buf, strlen (buf), '\n'); else tty_print_utf8_string2 (buf, strlen (buf), 0); xfree (buf); } else { if (opt.with_colons) es_putc (':', fp); else tty_fprintf (fp, _("[not set]")); } if (opt.with_colons) es_fputs (":\n", fp); else tty_fprintf (fp, "\n"); } /* Return true if the SHA1 fingerprint FPR consists only of zeroes. */ static int fpr_is_zero (const char *fpr) { int i; for (i=0; i < 20 && !fpr[i]; i++) ; return (i == 20); } /* Return true if the SHA1 fingerprint FPR consists only of 0xFF. */ static int fpr_is_ff (const char *fpr) { int i; for (i=0; i < 20 && fpr[i] == '\xff'; i++) ; return (i == 20); } /* Print all available information about the current card. */ void card_status (estream_t fp, char *serialno, size_t serialnobuflen) { struct agent_card_info_s info; PKT_public_key *pk = xcalloc (1, sizeof *pk); int rc; unsigned int uval; const unsigned char *thefpr; int i; if (serialno && serialnobuflen) *serialno = 0; rc = agent_learn (&info); if (rc) { if (opt.with_colons) es_fputs ("AID:::\n", fp); log_error (_("OpenPGP card not available: %s\n"), gpg_strerror (rc)); xfree (pk); return; } if (opt.with_colons) es_fprintf (fp, "AID:%s:", info.serialno? info.serialno : ""); else tty_fprintf (fp, "Application ID ...: %s\n", info.serialno? info.serialno : "[none]"); if (!info.serialno || strncmp (info.serialno, "D27600012401", 12) || strlen (info.serialno) != 32 ) { if (info.apptype && !strcmp (info.apptype, "NKS")) { if (opt.with_colons) es_fputs ("netkey-card:\n", fp); log_info ("this is a NetKey card\n"); } else if (info.apptype && !strcmp (info.apptype, "DINSIG")) { if (opt.with_colons) es_fputs ("dinsig-card:\n", fp); log_info ("this is a DINSIG compliant card\n"); } else if (info.apptype && !strcmp (info.apptype, "P15")) { if (opt.with_colons) es_fputs ("pkcs15-card:\n", fp); log_info ("this is a PKCS#15 compliant card\n"); } else if (info.apptype && !strcmp (info.apptype, "GELDKARTE")) { if (opt.with_colons) es_fputs ("geldkarte-card:\n", fp); log_info ("this is a Geldkarte compliant card\n"); } else { if (opt.with_colons) es_fputs ("unknown:\n", fp); } log_info ("not an OpenPGP card\n"); agent_release_card_info (&info); xfree (pk); return; } if (!serialno) ; else if (strlen (serialno)+1 > serialnobuflen) log_error ("serial number longer than expected\n"); else strcpy (serialno, info.serialno); if (opt.with_colons) es_fputs ("openpgp-card:\n", fp); if (opt.with_colons) { es_fprintf (fp, "version:%.4s:\n", info.serialno+12); uval = xtoi_2(info.serialno+16)*256 + xtoi_2 (info.serialno+18); es_fprintf (fp, "vendor:%04x:%s:\n", uval, get_manufacturer (uval)); es_fprintf (fp, "serial:%.8s:\n", info.serialno+20); print_isoname (fp, "Name of cardholder: ", "name", info.disp_name); es_fputs ("lang:", fp); if (info.disp_lang) es_write_sanitized (fp, info.disp_lang, strlen (info.disp_lang), ":", NULL); es_fputs (":\n", fp); es_fprintf (fp, "sex:%c:\n", (info.disp_sex == 1? 'm': info.disp_sex == 2? 'f' : 'u')); es_fputs ("url:", fp); if (info.pubkey_url) es_write_sanitized (fp, info.pubkey_url, strlen (info.pubkey_url), ":", NULL); es_fputs (":\n", fp); es_fputs ("login:", fp); if (info.login_data) es_write_sanitized (fp, info.login_data, strlen (info.login_data), ":", NULL); es_fputs (":\n", fp); es_fprintf (fp, "forcepin:%d:::\n", !info.chv1_cached); for (i=0; i < DIM (info.key_attr); i++) if (info.key_attr[0].algo) es_fprintf (fp, "keyattr:%d:%d:%u:\n", i+1, info.key_attr[i].algo, info.key_attr[i].nbits); es_fprintf (fp, "maxpinlen:%d:%d:%d:\n", info.chvmaxlen[0], info.chvmaxlen[1], info.chvmaxlen[2]); es_fprintf (fp, "pinretry:%d:%d:%d:\n", info.chvretry[0], info.chvretry[1], info.chvretry[2]); es_fprintf (fp, "sigcount:%lu:::\n", info.sig_counter); for (i=0; i < 4; i++) { if (info.private_do[i]) { es_fprintf (fp, "private_do:%d:", i+1); es_write_sanitized (fp, info.private_do[i], strlen (info.private_do[i]), ":", NULL); es_fputs (":\n", fp); } } es_fputs ("cafpr:", fp); print_sha1_fpr_colon (fp, info.cafpr1valid? info.cafpr1:NULL); print_sha1_fpr_colon (fp, info.cafpr2valid? info.cafpr2:NULL); print_sha1_fpr_colon (fp, info.cafpr3valid? info.cafpr3:NULL); es_putc ('\n', fp); es_fputs ("fpr:", fp); print_sha1_fpr_colon (fp, info.fpr1valid? info.fpr1:NULL); print_sha1_fpr_colon (fp, info.fpr2valid? info.fpr2:NULL); print_sha1_fpr_colon (fp, info.fpr3valid? info.fpr3:NULL); es_putc ('\n', fp); es_fprintf (fp, "fprtime:%lu:%lu:%lu:\n", (unsigned long)info.fpr1time, (unsigned long)info.fpr2time, (unsigned long)info.fpr3time); } else { tty_fprintf (fp, "Version ..........: %.1s%c.%.1s%c\n", info.serialno[12] == '0'?"":info.serialno+12, info.serialno[13], info.serialno[14] == '0'?"":info.serialno+14, info.serialno[15]); tty_fprintf (fp, "Manufacturer .....: %s\n", get_manufacturer (xtoi_2(info.serialno+16)*256 + xtoi_2 (info.serialno+18))); tty_fprintf (fp, "Serial number ....: %.8s\n", info.serialno+20); print_isoname (fp, "Name of cardholder: ", "name", info.disp_name); print_name (fp, "Language prefs ...: ", info.disp_lang); tty_fprintf (fp, "Sex ..............: %s\n", info.disp_sex == 1? _("male"): info.disp_sex == 2? _("female") : _("unspecified")); print_name (fp, "URL of public key : ", info.pubkey_url); print_name (fp, "Login data .......: ", info.login_data); if (info.private_do[0]) print_name (fp, "Private DO 1 .....: ", info.private_do[0]); if (info.private_do[1]) print_name (fp, "Private DO 2 .....: ", info.private_do[1]); if (info.private_do[2]) print_name (fp, "Private DO 3 .....: ", info.private_do[2]); if (info.private_do[3]) print_name (fp, "Private DO 4 .....: ", info.private_do[3]); if (info.cafpr1valid) { tty_fprintf (fp, "CA fingerprint %d .:", 1); print_sha1_fpr (fp, info.cafpr1); } if (info.cafpr2valid) { tty_fprintf (fp, "CA fingerprint %d .:", 2); print_sha1_fpr (fp, info.cafpr2); } if (info.cafpr3valid) { tty_fprintf (fp, "CA fingerprint %d .:", 3); print_sha1_fpr (fp, info.cafpr3); } tty_fprintf (fp, "Signature PIN ....: %s\n", info.chv1_cached? _("not forced"): _("forced")); if (info.key_attr[0].algo) { tty_fprintf (fp, "Key attributes ...:"); for (i=0; i < DIM (info.key_attr); i++) tty_fprintf (fp, " %u%c", info.key_attr[i].nbits, info.key_attr[i].algo == 1? 'R': info.key_attr[i].algo == 17? 'D': '?'); tty_fprintf (fp, "\n"); } tty_fprintf (fp, "Max. PIN lengths .: %d %d %d\n", info.chvmaxlen[0], info.chvmaxlen[1], info.chvmaxlen[2]); tty_fprintf (fp, "PIN retry counter : %d %d %d\n", info.chvretry[0], info.chvretry[1], info.chvretry[2]); tty_fprintf (fp, "Signature counter : %lu\n", info.sig_counter); tty_fprintf (fp, "Signature key ....:"); print_sha1_fpr (fp, info.fpr1valid? info.fpr1:NULL); if (info.fpr1valid && info.fpr1time) tty_fprintf (fp, " created ....: %s\n", isotimestamp (info.fpr1time)); tty_fprintf (fp, "Encryption key....:"); print_sha1_fpr (fp, info.fpr2valid? info.fpr2:NULL); if (info.fpr2valid && info.fpr2time) tty_fprintf (fp, " created ....: %s\n", isotimestamp (info.fpr2time)); tty_fprintf (fp, "Authentication key:"); print_sha1_fpr (fp, info.fpr3valid? info.fpr3:NULL); if (info.fpr3valid && info.fpr3time) tty_fprintf (fp, " created ....: %s\n", isotimestamp (info.fpr3time)); tty_fprintf (fp, "General key info..: "); thefpr = (info.fpr1valid? info.fpr1 : info.fpr2valid? info.fpr2 : info.fpr3valid? info.fpr3 : NULL); /* If the fingerprint is all 0xff, the key has no asssociated OpenPGP certificate. */ if ( thefpr && !fpr_is_ff (thefpr) && !get_pubkey_byfprint (pk, thefpr, 20)) { kbnode_t keyblock = NULL; print_pubkey_info (fp, pk); #if GNUPG_MAJOR_VERSION == 1 if ( !get_seckeyblock_byfprint (&keyblock, thefpr, 20) ) print_card_key_info (fp, keyblock); else if ( !get_keyblock_byfprint (&keyblock, thefpr, 20) ) { release_kbnode (keyblock); keyblock = NULL; if (!auto_create_card_key_stub (info.serialno, info.fpr1valid? info.fpr1:NULL, info.fpr2valid? info.fpr2:NULL, info.fpr3valid? info.fpr3:NULL)) { if ( !get_seckeyblock_byfprint (&keyblock, thefpr, 20) ) print_card_key_info (fp, keyblock); } } #else /* GNUPG_MAJOR_VERSION != 1 */ if (!get_keyblock_byfprint (&keyblock, thefpr, 20)) print_card_key_info (fp, keyblock); #endif /* GNUPG_MAJOR_VERSION != 1 */ release_kbnode (keyblock); } else tty_fprintf (fp, "[none]\n"); } free_public_key (pk); agent_release_card_info (&info); } static char * get_one_name (const char *prompt1, const char *prompt2) { char *name; int i; for (;;) { name = cpr_get (prompt1, prompt2); if (!name) return NULL; trim_spaces (name); cpr_kill_prompt (); for (i=0; name[i] && name[i] >= ' ' && name[i] <= 126; i++) ; /* The name must be in Latin-1 and not UTF-8 - lacking the code to ensure this we restrict it to ASCII. */ if (name[i]) tty_printf (_("Error: Only plain ASCII is currently allowed.\n")); else if (strchr (name, '<')) tty_printf (_("Error: The \"<\" character may not be used.\n")); else if (strstr (name, " ")) tty_printf (_("Error: Double spaces are not allowed.\n")); else return name; xfree (name); } } static int change_name (void) { char *surname = NULL, *givenname = NULL; char *isoname, *p; int rc; surname = get_one_name ("keygen.smartcard.surname", _("Cardholder's surname: ")); givenname = get_one_name ("keygen.smartcard.givenname", _("Cardholder's given name: ")); if (!surname || !givenname || (!*surname && !*givenname)) { xfree (surname); xfree (givenname); return -1; /*canceled*/ } isoname = xmalloc ( strlen (surname) + 2 + strlen (givenname) + 1); strcpy (stpcpy (stpcpy (isoname, surname), "<<"), givenname); xfree (surname); xfree (givenname); for (p=isoname; *p; p++) if (*p == ' ') *p = '<'; if (strlen (isoname) > 39 ) { tty_printf (_("Error: Combined name too long " "(limit is %d characters).\n"), 39); xfree (isoname); return -1; } rc = agent_scd_setattr ("DISP-NAME", isoname, strlen (isoname), NULL ); if (rc) log_error ("error setting Name: %s\n", gpg_strerror (rc)); xfree (isoname); return rc; } static int change_url (void) { char *url; int rc; url = cpr_get ("cardedit.change_url", _("URL to retrieve public key: ")); if (!url) return -1; trim_spaces (url); cpr_kill_prompt (); if (strlen (url) > 254 ) { tty_printf (_("Error: URL too long " "(limit is %d characters).\n"), 254); xfree (url); return -1; } rc = agent_scd_setattr ("PUBKEY-URL", url, strlen (url), NULL ); if (rc) log_error ("error setting URL: %s\n", gpg_strerror (rc)); xfree (url); write_sc_op_status (rc); return rc; } /* Fetch the key from the URL given on the card or try to get it from the default keyserver. */ static int fetch_url (ctrl_t ctrl) { int rc; struct agent_card_info_s info; memset(&info,0,sizeof(info)); rc=agent_scd_getattr("PUBKEY-URL",&info); if(rc) log_error("error retrieving URL from card: %s\n",gpg_strerror(rc)); else { struct keyserver_spec *spec=NULL; rc=agent_scd_getattr("KEY-FPR",&info); if(rc) log_error("error retrieving key fingerprint from card: %s\n", gpg_strerror(rc)); else if (info.pubkey_url && *info.pubkey_url) { spec=parse_keyserver_uri(info.pubkey_url,1,NULL,0); if(spec && info.fpr1valid) { /* This is not perfectly right. Currently, all card fingerprints are 20 digits, but what about fingerprints for a future v5 key? We should get the length from somewhere lower in the code. In any event, the fpr/keyid is not meaningful for straight HTTP fetches, but using it allows the card to point to HKP and LDAP servers as well. */ rc = keyserver_import_fprint (ctrl, info.fpr1, 20, spec); free_keyserver_spec(spec); } } else if (info.fpr1valid) { rc = keyserver_import_fprint (ctrl, info.fpr1, 20, opt.keyserver); } } return rc; } /* Read data from file FNAME up to MAXLEN characters. On error return -1 and store NULL at R_BUFFER; on success return the number of bytes read and store the address of a newly allocated buffer at R_BUFFER. */ static int get_data_from_file (const char *fname, size_t maxlen, char **r_buffer) { estream_t fp; char *data; int n; *r_buffer = NULL; fp = es_fopen (fname, "rb"); #if GNUPG_MAJOR_VERSION == 1 if (fp && is_secured_file (fileno (fp))) { fclose (fp); fp = NULL; errno = EPERM; } #endif if (!fp) { tty_printf (_("can't open `%s': %s\n"), fname, strerror (errno)); return -1; } data = xtrymalloc (maxlen? maxlen:1); if (!data) { tty_printf (_("error allocating enough memory: %s\n"), strerror (errno)); es_fclose (fp); return -1; } if (maxlen) n = es_fread (data, 1, maxlen, fp); else n = 0; es_fclose (fp); if (n < 0) { tty_printf (_("error reading `%s': %s\n"), fname, strerror (errno)); xfree (data); return -1; } *r_buffer = data; return n; } /* Write LENGTH bytes from BUFFER to file FNAME. Return 0 on success. */ static int put_data_to_file (const char *fname, const void *buffer, size_t length) { estream_t fp; fp = es_fopen (fname, "wb"); #if GNUPG_MAJOR_VERSION == 1 if (fp && is_secured_file (fileno (fp))) { fclose (fp); fp = NULL; errno = EPERM; } #endif if (!fp) { tty_printf (_("can't create `%s': %s\n"), fname, strerror (errno)); return -1; } if (length && es_fwrite (buffer, length, 1, fp) != 1) { tty_printf (_("error writing `%s': %s\n"), fname, strerror (errno)); es_fclose (fp); return -1; } es_fclose (fp); return 0; } static int change_login (const char *args) { char *data; int n; int rc; if (args && *args == '<') /* Read it from a file */ { for (args++; spacep (args); args++) ; n = get_data_from_file (args, 254, &data); if (n < 0) return -1; } else { data = cpr_get ("cardedit.change_login", _("Login data (account name): ")); if (!data) return -1; trim_spaces (data); cpr_kill_prompt (); n = strlen (data); } if (n > 254 ) { tty_printf (_("Error: Login data too long " "(limit is %d characters).\n"), 254); xfree (data); return -1; } rc = agent_scd_setattr ("LOGIN-DATA", data, n, NULL ); if (rc) log_error ("error setting login data: %s\n", gpg_strerror (rc)); xfree (data); write_sc_op_status (rc); return rc; } static int change_private_do (const char *args, int nr) { char do_name[] = "PRIVATE-DO-X"; char *data; int n; int rc; assert (nr >= 1 && nr <= 4); do_name[11] = '0' + nr; if (args && (args = strchr (args, '<'))) /* Read it from a file */ { for (args++; spacep (args); args++) ; n = get_data_from_file (args, 254, &data); if (n < 0) return -1; } else { data = cpr_get ("cardedit.change_private_do", _("Private DO data: ")); if (!data) return -1; trim_spaces (data); cpr_kill_prompt (); n = strlen (data); } if (n > 254 ) { tty_printf (_("Error: Private DO too long " "(limit is %d characters).\n"), 254); xfree (data); return -1; } rc = agent_scd_setattr (do_name, data, n, NULL ); if (rc) log_error ("error setting private DO: %s\n", gpg_strerror (rc)); xfree (data); write_sc_op_status (rc); return rc; } static int change_cert (const char *args) { char *data; int n; int rc; if (args && *args == '<') /* Read it from a file */ { for (args++; spacep (args); args++) ; n = get_data_from_file (args, 16384, &data); if (n < 0) return -1; } else { tty_printf ("usage error: redirection to file required\n"); return -1; } rc = agent_scd_writecert ("OPENPGP.3", data, n); if (rc) log_error ("error writing certificate to card: %s\n", gpg_strerror (rc)); xfree (data); write_sc_op_status (rc); return rc; } static int read_cert (const char *args) { const char *fname; void *buffer; size_t length; int rc; if (args && *args == '>') /* Write it to a file */ { for (args++; spacep (args); args++) ; fname = args; } else { tty_printf ("usage error: redirection to file required\n"); return -1; } rc = agent_scd_readcert ("OPENPGP.3", &buffer, &length); if (rc) log_error ("error reading certificate from card: %s\n", gpg_strerror (rc)); else rc = put_data_to_file (fname, buffer, length); xfree (buffer); write_sc_op_status (rc); return rc; } static int change_lang (void) { char *data, *p; int rc; data = cpr_get ("cardedit.change_lang", _("Language preferences: ")); if (!data) return -1; trim_spaces (data); cpr_kill_prompt (); if (strlen (data) > 8 || (strlen (data) & 1)) { tty_printf (_("Error: invalid length of preference string.\n")); xfree (data); return -1; } for (p=data; *p && *p >= 'a' && *p <= 'z'; p++) ; if (*p) { tty_printf (_("Error: invalid characters in preference string.\n")); xfree (data); return -1; } rc = agent_scd_setattr ("DISP-LANG", data, strlen (data), NULL ); if (rc) log_error ("error setting lang: %s\n", gpg_strerror (rc)); xfree (data); write_sc_op_status (rc); return rc; } static int change_sex (void) { char *data; const char *str; int rc; data = cpr_get ("cardedit.change_sex", _("Sex ((M)ale, (F)emale or space): ")); if (!data) return -1; trim_spaces (data); cpr_kill_prompt (); if (!*data) str = "9"; else if ((*data == 'M' || *data == 'm') && !data[1]) str = "1"; else if ((*data == 'F' || *data == 'f') && !data[1]) str = "2"; else { tty_printf (_("Error: invalid response.\n")); xfree (data); return -1; } rc = agent_scd_setattr ("DISP-SEX", str, 1, NULL ); if (rc) log_error ("error setting sex: %s\n", gpg_strerror (rc)); xfree (data); write_sc_op_status (rc); return rc; } static int change_cafpr (int fprno) { char *data; const char *s; int i, c, rc; unsigned char fpr[20]; data = cpr_get ("cardedit.change_cafpr", _("CA fingerprint: ")); if (!data) return -1; trim_spaces (data); cpr_kill_prompt (); for (i=0, s=data; i < 20 && *s; ) { while (spacep(s)) s++; if (*s == ':') s++; while (spacep(s)) s++; c = hextobyte (s); if (c == -1) break; fpr[i++] = c; s += 2; } xfree (data); if (i != 20 || *s) { tty_printf (_("Error: invalid formatted fingerprint.\n")); return -1; } rc = agent_scd_setattr (fprno==1?"CA-FPR-1": fprno==2?"CA-FPR-2": fprno==3?"CA-FPR-3":"x", fpr, 20, NULL ); if (rc) log_error ("error setting cafpr: %s\n", gpg_strerror (rc)); write_sc_op_status (rc); return rc; } static void toggle_forcesig (void) { struct agent_card_info_s info; int rc; int newstate; memset (&info, 0, sizeof info); rc = agent_scd_getattr ("CHV-STATUS", &info); if (rc) { log_error ("error getting current status: %s\n", gpg_strerror (rc)); return; } newstate = !info.chv1_cached; agent_release_card_info (&info); rc = agent_scd_setattr ("CHV-STATUS-1", newstate? "\x01":"", 1, NULL); if (rc) log_error ("error toggling signature PIN flag: %s\n", gpg_strerror (rc)); write_sc_op_status (rc); } /* Helper for the key generation/edit functions. */ static int get_info_for_key_operation (struct agent_card_info_s *info) { int rc; memset (info, 0, sizeof *info); rc = agent_scd_getattr ("SERIALNO", info); if (rc || !info->serialno || strncmp (info->serialno, "D27600012401", 12) || strlen (info->serialno) != 32 ) { log_error (_("key operation not possible: %s\n"), rc ? gpg_strerror (rc) : _("not an OpenPGP card")); return rc? rc: -1; } rc = agent_scd_getattr ("KEY-FPR", info); if (!rc) rc = agent_scd_getattr ("CHV-STATUS", info); if (!rc) rc = agent_scd_getattr ("DISP-NAME", info); if (!rc) rc = agent_scd_getattr ("EXTCAP", info); if (!rc) rc = agent_scd_getattr ("KEY-ATTR", info); if (rc) log_error (_("error getting current key info: %s\n"), gpg_strerror (rc)); return rc; } /* Helper for the key generation/edit functions. */ static int check_pin_for_key_operation (struct agent_card_info_s *info, int *forced_chv1) { int rc = 0; agent_clear_pin_cache (info->serialno); *forced_chv1 = !info->chv1_cached; if (*forced_chv1) { /* Switch off the forced mode so that during key generation we don't get bothered with PIN queries for each self-signature. */ rc = agent_scd_setattr ("CHV-STATUS-1", "\x01", 1, info->serialno); if (rc) { log_error ("error clearing forced signature PIN flag: %s\n", gpg_strerror (rc)); *forced_chv1 = 0; } } if (!rc) { /* Check the PIN now, so that we won't get asked later for each binding signature. */ rc = agent_scd_checkpin (info->serialno); if (rc) { log_error ("error checking the PIN: %s\n", gpg_strerror (rc)); write_sc_op_status (rc); } } return rc; } /* Helper for the key generation/edit functions. */ static void restore_forced_chv1 (int *forced_chv1) { int rc; if (*forced_chv1) { /* Switch back to forced state. */ rc = agent_scd_setattr ("CHV-STATUS-1", "", 1, NULL); if (rc) { log_error ("error setting forced signature PIN flag: %s\n", gpg_strerror (rc)); } } } /* Helper for the key generation/edit functions. */ static void show_card_key_info (struct agent_card_info_s *info) { tty_fprintf (NULL, "Signature key ....:"); print_sha1_fpr (NULL, info->fpr1valid? info->fpr1:NULL); tty_fprintf (NULL, "Encryption key....:"); print_sha1_fpr (NULL, info->fpr2valid? info->fpr2:NULL); tty_fprintf (NULL, "Authentication key:"); print_sha1_fpr (NULL, info->fpr3valid? info->fpr3:NULL); tty_printf ("\n"); } /* Helper for the key generation/edit functions. */ static int replace_existing_key_p (struct agent_card_info_s *info, int keyno) { assert (keyno >= 0 && keyno <= 3); if ((keyno == 1 && info->fpr1valid) || (keyno == 2 && info->fpr2valid) || (keyno == 3 && info->fpr3valid)) { tty_printf ("\n"); log_info ("WARNING: such a key has already been stored on the card!\n"); tty_printf ("\n"); if ( !cpr_get_answer_is_yes( "cardedit.genkeys.replace_key", _("Replace existing key? (y/N) "))) return -1; } return 0; } static void show_keysize_warning (void) { static int shown; if (shown) return; shown = 1; tty_printf (_("NOTE: There is no guarantee that the card " "supports the requested size.\n" " If the key generation does not succeed, " "please check the\n" " documentation of your card to see what " "sizes are allowed.\n")); } /* Ask for the size of a card key. NBITS is the current size configured for the card. KEYNO is the number of the key used to select the prompt. Returns 0 to use the default size (i.e. NBITS) or the selected size. */ static unsigned int ask_card_keysize (int keyno, unsigned int nbits) { unsigned int min_nbits = 1024; unsigned int max_nbits = 4096; char *prompt, *answer; unsigned int req_nbits; for (;;) { prompt = xasprintf (keyno == 0? _("What keysize do you want for the Signature key? (%u) "): keyno == 1? _("What keysize do you want for the Encryption key? (%u) "): _("What keysize do you want for the Authentication key? (%u) "), nbits); answer = cpr_get ("cardedit.genkeys.size", prompt); cpr_kill_prompt (); req_nbits = *answer? atoi (answer): nbits; xfree (prompt); xfree (answer); if (req_nbits != nbits && (req_nbits % 32) ) { req_nbits = ((req_nbits + 31) / 32) * 32; tty_printf (_("rounded up to %u bits\n"), req_nbits); } if (req_nbits == nbits) return 0; /* Use default. */ if (req_nbits < min_nbits || req_nbits > max_nbits) { tty_printf (_("%s keysizes must be in the range %u-%u\n"), "RSA", min_nbits, max_nbits); } else { tty_printf (_("The card will now be re-configured " "to generate a key of %u bits\n"), req_nbits); show_keysize_warning (); return req_nbits; } } } /* Change the size of key KEYNO (0..2) to NBITS and show an error message if that fails. */ static gpg_error_t do_change_keysize (int keyno, unsigned int nbits) { gpg_error_t err; char args[100]; snprintf (args, sizeof args, "--force %d 1 %u", keyno+1, nbits); err = agent_scd_setattr ("KEY-ATTR", args, strlen (args), NULL); if (err) log_error (_("error changing size of key %d to %u bits: %s\n"), keyno+1, nbits, gpg_strerror (err)); return err; } static void -generate_card_keys (void) +generate_card_keys (ctrl_t ctrl) { struct agent_card_info_s info; int forced_chv1; int want_backup; int keyno; if (get_info_for_key_operation (&info)) return; if (info.extcap.ki) { char *answer; /* FIXME: Should be something like cpr_get_bool so that a status GET_BOOL will be emitted. */ answer = cpr_get ("cardedit.genkeys.backup_enc", _("Make off-card backup of encryption key? (Y/n) ")); want_backup = answer_is_yes_no_default (answer, 1/*(default to Yes)*/); cpr_kill_prompt (); xfree (answer); } else want_backup = 0; if ( (info.fpr1valid && !fpr_is_zero (info.fpr1)) || (info.fpr2valid && !fpr_is_zero (info.fpr2)) || (info.fpr3valid && !fpr_is_zero (info.fpr3))) { tty_printf ("\n"); log_info (_("NOTE: keys are already stored on the card!\n")); tty_printf ("\n"); if ( !cpr_get_answer_is_yes ("cardedit.genkeys.replace_keys", _("Replace existing keys? (y/N) "))) { agent_release_card_info (&info); return; } } /* If no displayed name has been set, we assume that this is a fresh card and print a hint about the default PINs. */ if (!info.disp_name || !*info.disp_name) { tty_printf ("\n"); tty_printf (_("Please note that the factory settings of the PINs are\n" " PIN = `%s' Admin PIN = `%s'\n" "You should change them using the command --change-pin\n"), "123456", "12345678"); tty_printf ("\n"); } if (check_pin_for_key_operation (&info, &forced_chv1)) goto leave; /* If the cards features changeable key attributes, we ask for the key size. */ if (info.is_v2 && info.extcap.aac) { unsigned int nbits; for (keyno = 0; keyno < DIM (info.key_attr); keyno++) { nbits = ask_card_keysize (keyno, info.key_attr[keyno].nbits); if (nbits && do_change_keysize (keyno, nbits)) { /* Error: Better read the default key size again. */ agent_release_card_info (&info); if (get_info_for_key_operation (&info)) goto leave; /* Ask again for this key size. */ keyno--; } } /* Note that INFO has not be synced. However we will only use the serialnumber and thus it won't harm. */ } - generate_keypair (NULL, info.serialno, want_backup); + generate_keypair (ctrl, NULL, info.serialno, want_backup); leave: agent_release_card_info (&info); restore_forced_chv1 (&forced_chv1); } /* This function is used by the key edit menu to generate an arbitrary subkey. */ gpg_error_t card_generate_subkey (KBNODE pub_keyblock) { gpg_error_t err; struct agent_card_info_s info; int forced_chv1 = 0; int keyno; err = get_info_for_key_operation (&info); if (err) return err; show_card_key_info (&info); tty_printf (_("Please select the type of key to generate:\n")); tty_printf (_(" (1) Signature key\n")); tty_printf (_(" (2) Encryption key\n")); tty_printf (_(" (3) Authentication key\n")); for (;;) { char *answer = cpr_get ("cardedit.genkeys.subkeytype", _("Your selection? ")); cpr_kill_prompt(); if (*answer == CONTROL_D) { xfree (answer); err = gpg_error (GPG_ERR_CANCELED); goto leave; } keyno = *answer? atoi(answer): 0; xfree(answer); if (keyno >= 1 && keyno <= 3) break; /* Okay. */ tty_printf(_("Invalid selection.\n")); } if (replace_existing_key_p (&info, keyno)) { err = gpg_error (GPG_ERR_CANCELED); goto leave; } err = check_pin_for_key_operation (&info, &forced_chv1); if (err) goto leave; /* If the cards features changeable key attributes, we ask for the key size. */ if (info.is_v2 && info.extcap.aac) { unsigned int nbits; ask_again: nbits = ask_card_keysize (keyno-1, info.key_attr[keyno-1].nbits); if (nbits && do_change_keysize (keyno-1, nbits)) { /* Error: Better read the default key size again. */ agent_release_card_info (&info); err = get_info_for_key_operation (&info); if (err) goto leave; goto ask_again; } /* Note that INFO has not be synced. However we will only use the serialnumber and thus it won't harm. */ } err = generate_card_subkeypair (pub_keyblock, keyno, info.serialno); leave: agent_release_card_info (&info); restore_forced_chv1 (&forced_chv1); return err; } /* Store the key at NODE into the smartcard and modify NODE to carry the serialno stuff instead of the actual secret key parameters. USE is the usage for that key; 0 means any usage. */ int card_store_subkey (KBNODE node, int use) { log_info ("FIXME: card_store_subkey has not yet been implemented\n"); /* struct agent_card_info_s info; */ /* int okay = 0; */ /* int rc; */ /* int keyno, i; */ /* PKT_secret_key *copied_sk = NULL; */ /* PKT_secret_key *sk; */ /* size_t n; */ /* const char *s; */ /* int allow_keyno[3]; */ /* unsigned int nbits; */ /* assert (node->pkt->pkttype == PKT_SECRET_KEY */ /* || node->pkt->pkttype == PKT_SECRET_SUBKEY); */ /* sk = node->pkt->pkt.secret_key; */ /* if (get_info_for_key_operation (&info)) */ /* return 0; */ /* if (!info.extcap.ki) */ /* { */ /* tty_printf ("The card does not support the import of keys\n"); */ /* tty_printf ("\n"); */ /* goto leave; */ /* } */ /* show_card_key_info (&info); */ /* nbits = nbits_from_sk (sk); */ /* if (!is_RSA (sk->pubkey_algo) || (!info.is_v2 && nbits != 1024) ) */ /* { */ /* tty_printf ("You may only store a 1024 bit RSA key on the card\n"); */ /* tty_printf ("\n"); */ /* goto leave; */ /* } */ /* allow_keyno[0] = (!use || (use & (PUBKEY_USAGE_SIG))); */ /* allow_keyno[1] = (!use || (use & (PUBKEY_USAGE_ENC))); */ /* allow_keyno[2] = (!use || (use & (PUBKEY_USAGE_SIG|PUBKEY_USAGE_AUTH))); */ /* tty_printf (_("Please select where to store the key:\n")); */ /* if (allow_keyno[0]) */ /* tty_printf (_(" (1) Signature key\n")); */ /* if (allow_keyno[1]) */ /* tty_printf (_(" (2) Encryption key\n")); */ /* if (allow_keyno[2]) */ /* tty_printf (_(" (3) Authentication key\n")); */ /* for (;;) */ /* { */ /* char *answer = cpr_get ("cardedit.genkeys.storekeytype", */ /* _("Your selection? ")); */ /* cpr_kill_prompt(); */ /* if (*answer == CONTROL_D || !*answer) */ /* { */ /* xfree (answer); */ /* goto leave; */ /* } */ /* keyno = *answer? atoi(answer): 0; */ /* xfree(answer); */ /* if (keyno >= 1 && keyno <= 3 && allow_keyno[keyno-1]) */ /* { */ /* if (info.is_v2 && !info.extcap.aac */ /* && info.key_attr[keyno-1].nbits != nbits) */ /* { */ /* tty_printf ("Key does not match the card's capability.\n"); */ /* } */ /* else */ /* break; /\* Okay. *\/ */ /* } */ /* else */ /* tty_printf(_("Invalid selection.\n")); */ /* } */ /* if (replace_existing_key_p (&info, keyno)) */ /* goto leave; */ /* /\* Unprotect key. *\/ */ /* switch (is_secret_key_protected (sk) ) */ /* { */ /* case 0: /\* Not protected. *\/ */ /* break; */ /* case -1: */ /* log_error (_("unknown key protection algorithm\n")); */ /* goto leave; */ /* default: */ /* if (sk->protect.s2k.mode == 1001) */ /* { */ /* log_error (_("secret parts of key are not available\n")); */ /* goto leave; */ /* } */ /* if (sk->protect.s2k.mode == 1002) */ /* { */ /* log_error (_("secret key already stored on a card\n")); */ /* goto leave; */ /* } */ /* /\* We better copy the key before we unprotect it. *\/ */ /* copied_sk = sk = copy_secret_key (NULL, sk); */ /* rc = 0/\*check_secret_key (sk, 0)*\/; */ /* if (rc) */ /* goto leave; */ /* } */ /* #warning code save_unprotected_key_to_card */ /* /\* rc = save_unprotected_key_to_card (sk, keyno); *\/ */ /* /\* if (rc) *\/ */ /* /\* { *\/ */ /* /\* log_error (_("error writing key to card: %s\n"), gpg_strerror (rc)); *\/ */ /* /\* goto leave; *\/ */ /* /\* } *\/ */ /* /\* Get back to the maybe protected original secret key. *\/ */ /* if (copied_sk) */ /* { */ /* free_secret_key (copied_sk); */ /* copied_sk = NULL; */ /* } */ /* sk = node->pkt->pkt.secret_key; */ /* /\* Get rid of the secret key parameters and store the serial numer. *\/ */ /* n = pubkey_get_nskey (sk->pubkey_algo); */ /* for (i=pubkey_get_npkey (sk->pubkey_algo); i < n; i++) */ /* { */ /* gcry_mpi_release (sk->skey[i]); */ /* sk->skey[i] = NULL; */ /* } */ /* i = pubkey_get_npkey (sk->pubkey_algo); */ /* sk->skey[i] = gcry_mpi_set_opaque (NULL, xstrdup ("dummydata"), 10*8); */ /* sk->is_protected = 1; */ /* sk->protect.s2k.mode = 1002; */ /* s = info.serialno; */ /* for (sk->protect.ivlen=0; sk->protect.ivlen < 16 && *s && s[1]; */ /* sk->protect.ivlen++, s += 2) */ /* sk->protect.iv[sk->protect.ivlen] = xtoi_2 (s); */ /* okay = 1; */ /* leave: */ /* if (copied_sk) */ /* free_secret_key (copied_sk); */ /* agent_release_card_info (&info); */ /* return okay; */ return -1; } /* Data used by the command parser. This needs to be outside of the function scope to allow readline based command completion. */ enum cmdids { cmdNOP = 0, cmdQUIT, cmdADMIN, cmdHELP, cmdLIST, cmdDEBUG, cmdVERIFY, cmdNAME, cmdURL, cmdFETCH, cmdLOGIN, cmdLANG, cmdSEX, cmdCAFPR, cmdFORCESIG, cmdGENERATE, cmdPASSWD, cmdPRIVATEDO, cmdWRITECERT, cmdREADCERT, cmdUNBLOCK, cmdINVCMD }; static struct { const char *name; enum cmdids id; int admin_only; const char *desc; } cmds[] = { { "quit" , cmdQUIT , 0, N_("quit this menu")}, { "q" , cmdQUIT , 0, NULL }, { "admin" , cmdADMIN , 0, N_("show admin commands")}, { "help" , cmdHELP , 0, N_("show this help")}, { "?" , cmdHELP , 0, NULL }, { "list" , cmdLIST , 0, N_("list all available data")}, { "l" , cmdLIST , 0, NULL }, { "debug" , cmdDEBUG , 0, NULL }, { "name" , cmdNAME , 1, N_("change card holder's name")}, { "url" , cmdURL , 1, N_("change URL to retrieve key")}, { "fetch" , cmdFETCH , 0, N_("fetch the key specified in the card URL")}, { "login" , cmdLOGIN , 1, N_("change the login name")}, { "lang" , cmdLANG , 1, N_("change the language preferences")}, { "sex" , cmdSEX , 1, N_("change card holder's sex")}, { "cafpr" , cmdCAFPR , 1, N_("change a CA fingerprint")}, { "forcesig", cmdFORCESIG, 1, N_("toggle the signature force PIN flag")}, { "generate", cmdGENERATE, 1, N_("generate new keys")}, { "passwd" , cmdPASSWD, 0, N_("menu to change or unblock the PIN")}, { "verify" , cmdVERIFY, 0, N_("verify the PIN and list all data")}, { "unblock" , cmdUNBLOCK,0, N_("unblock the PIN using a Reset Code") }, /* Note, that we do not announce these command yet. */ { "privatedo", cmdPRIVATEDO, 0, NULL }, { "readcert", cmdREADCERT, 0, NULL }, { "writecert", cmdWRITECERT, 1, NULL }, { NULL, cmdINVCMD, 0, NULL } }; #ifdef HAVE_LIBREADLINE /* These two functions are used by readline for command completion. */ static char * command_generator(const char *text,int state) { static int list_index,len; const char *name; /* If this is a new word to complete, initialize now. This includes saving the length of TEXT for efficiency, and initializing the index variable to 0. */ if(!state) { list_index=0; len=strlen(text); } /* Return the next partial match */ while((name=cmds[list_index].name)) { /* Only complete commands that have help text */ if(cmds[list_index++].desc && strncmp(name,text,len)==0) return strdup(name); } return NULL; } static char ** card_edit_completion(const char *text, int start, int end) { (void)end; /* If we are at the start of a line, we try and command-complete. If not, just do nothing for now. */ if(start==0) return rl_completion_matches(text,command_generator); rl_attempted_completion_over=1; return NULL; } #endif /*HAVE_LIBREADLINE*/ /* Menu to edit all user changeable values on an OpenPGP card. Only Key creation is not handled here. */ void card_edit (ctrl_t ctrl, strlist_t commands) { enum cmdids cmd = cmdNOP; int have_commands = !!commands; int redisplay = 1; char *answer = NULL; int allow_admin=0; char serialnobuf[50]; if (opt.command_fd != -1) ; else if (opt.batch && !have_commands) { log_error(_("can't do this in batch mode\n")); goto leave; } for (;;) { int arg_number; const char *arg_string = ""; const char *arg_rest = ""; char *p; int i; int cmd_admin_only; tty_printf("\n"); if (redisplay ) { if (opt.with_colons) { card_status (es_stdout, serialnobuf, DIM (serialnobuf)); fflush (stdout); } else { card_status (NULL, serialnobuf, DIM (serialnobuf)); tty_printf("\n"); } redisplay = 0; } do { xfree (answer); if (have_commands) { if (commands) { answer = xstrdup (commands->d); commands = commands->next; } else if (opt.batch) { answer = xstrdup ("quit"); } else have_commands = 0; } if (!have_commands) { tty_enable_completion (card_edit_completion); answer = cpr_get_no_help("cardedit.prompt", _("gpg/card> ")); cpr_kill_prompt(); tty_disable_completion (); } trim_spaces(answer); } while ( *answer == '#' ); arg_number = 0; /* Yes, here is the init which egcc complains about */ cmd_admin_only = 0; if (!*answer) cmd = cmdLIST; /* Default to the list command */ else if (*answer == CONTROL_D) cmd = cmdQUIT; else { if ((p=strchr (answer,' '))) { *p++ = 0; trim_spaces (answer); trim_spaces (p); arg_number = atoi(p); arg_string = p; arg_rest = p; while (digitp (arg_rest)) arg_rest++; while (spacep (arg_rest)) arg_rest++; } for (i=0; cmds[i].name; i++ ) if (!ascii_strcasecmp (answer, cmds[i].name )) break; cmd = cmds[i].id; cmd_admin_only = cmds[i].admin_only; } if (!allow_admin && cmd_admin_only) { tty_printf ("\n"); tty_printf (_("Admin-only command\n")); continue; } switch (cmd) { case cmdHELP: for (i=0; cmds[i].name; i++ ) if(cmds[i].desc && (!cmds[i].admin_only || (cmds[i].admin_only && allow_admin))) tty_printf("%-10s %s\n", cmds[i].name, _(cmds[i].desc) ); break; case cmdADMIN: if ( !strcmp (arg_string, "on") ) allow_admin = 1; else if ( !strcmp (arg_string, "off") ) allow_admin = 0; else if ( !strcmp (arg_string, "verify") ) { /* Force verification of the Admin Command. However, this is only done if the retry counter is at initial state. */ char *tmp = xmalloc (strlen (serialnobuf) + 6 + 1); strcpy (stpcpy (tmp, serialnobuf), "[CHV3]"); allow_admin = !agent_scd_checkpin (tmp); xfree (tmp); } else /* Toggle. */ allow_admin=!allow_admin; if(allow_admin) tty_printf(_("Admin commands are allowed\n")); else tty_printf(_("Admin commands are not allowed\n")); break; case cmdVERIFY: agent_scd_checkpin (serialnobuf); redisplay = 1; break; case cmdLIST: redisplay = 1; break; case cmdNAME: change_name (); break; case cmdURL: change_url (); break; case cmdFETCH: fetch_url (ctrl); break; case cmdLOGIN: change_login (arg_string); break; case cmdLANG: change_lang (); break; case cmdSEX: change_sex (); break; case cmdCAFPR: if ( arg_number < 1 || arg_number > 3 ) tty_printf ("usage: cafpr N\n" " 1 <= N <= 3\n"); else change_cafpr (arg_number); break; case cmdPRIVATEDO: if ( arg_number < 1 || arg_number > 4 ) tty_printf ("usage: privatedo N\n" " 1 <= N <= 4\n"); else change_private_do (arg_string, arg_number); break; case cmdWRITECERT: if ( arg_number != 3 ) tty_printf ("usage: writecert 3 < FILE\n"); else change_cert (arg_rest); break; case cmdREADCERT: if ( arg_number != 3 ) tty_printf ("usage: readcert 3 > FILE\n"); else read_cert (arg_rest); break; case cmdFORCESIG: toggle_forcesig (); break; case cmdGENERATE: - generate_card_keys (); + generate_card_keys (ctrl); break; case cmdPASSWD: change_pin (0, allow_admin); break; case cmdUNBLOCK: change_pin (1, allow_admin); break; case cmdQUIT: goto leave; case cmdNOP: break; case cmdINVCMD: default: tty_printf ("\n"); tty_printf (_("Invalid command (try \"help\")\n")); break; } /* End command switch. */ } /* End of main menu loop. */ leave: xfree (answer); } diff --git a/g10/gpg.c b/g10/gpg.c index c31a55863..aa37a88b6 100644 --- a/g10/gpg.c +++ b/g10/gpg.c @@ -1,4405 +1,4405 @@ /* gpg.c - The GnuPG utility (main for gpg) * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 * 2008, 2009, 2010, 2011 Free Software Foundation, Inc. * * This file is part of GnuPG. * * GnuPG is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * GnuPG is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ #include #include #include #include #include #include #include #include #ifdef HAVE_STAT #include /* for stat() */ #endif #include #ifdef HAVE_W32_SYSTEM #include #endif #define INCLUDED_BY_MAIN_MODULE 1 #include "gpg.h" #include #include "../common/iobuf.h" #include "util.h" #include "packet.h" #include "main.h" #include "options.h" #include "keydb.h" #include "trustdb.h" #include "cipher.h" #include "filter.h" #include "ttyio.h" #include "i18n.h" #include "sysutils.h" #include "status.h" #include "keyserver-internal.h" #include "exec.h" #include "gc-opt-flags.h" #include "asshelp.h" #include "call-dirmngr.h" #if defined(HAVE_DOSISH_SYSTEM) || defined(__CYGWIN__) #define MY_O_BINARY O_BINARY #ifndef S_IRGRP # define S_IRGRP 0 # define S_IWGRP 0 #endif #else #define MY_O_BINARY 0 #endif enum cmd_and_opt_values { aNull = 0, oArmor = 'a', aDetachedSign = 'b', aSym = 'c', aDecrypt = 'd', aEncr = 'e', oInteractive = 'i', aListKeys = 'k', oDryRun = 'n', oOutput = 'o', oQuiet = 'q', oRecipient = 'r', oHiddenRecipient = 'R', aSign = 's', oTextmodeShort= 't', oLocalUser = 'u', oVerbose = 'v', oCompress = 'z', oSetNotation = 'N', aListSecretKeys = 'K', oBatch = 500, oMaxOutput, oSigNotation, oCertNotation, oShowNotation, oNoShowNotation, aEncrFiles, aEncrSym, aDecryptFiles, aClearsign, aStore, aKeygen, aSignEncr, aSignEncrSym, aSignSym, aSignKey, aLSignKey, aListConfig, aGPGConfList, aGPGConfTest, aListPackets, aEditKey, aDeleteKeys, aDeleteSecretKeys, aDeleteSecretAndPublicKeys, aImport, aFastImport, aVerify, aVerifyFiles, aListSigs, aSendKeys, aRecvKeys, aLocateKeys, aSearchKeys, aRefreshKeys, aFetchKeys, aExport, aExportSecret, aExportSecretSub, aCheckKeys, aGenRevoke, aDesigRevoke, aPrimegen, aPrintMD, aPrintMDs, aCheckTrustDB, aUpdateTrustDB, aFixTrustDB, aListTrustDB, aListTrustPath, aExportOwnerTrust, aImportOwnerTrust, aDeArmor, aEnArmor, aGenRandom, aRebuildKeydbCaches, aCardStatus, aCardEdit, aChangePIN, aPasswd, aServer, oTextmode, oNoTextmode, oExpert, oNoExpert, oDefSigExpire, oAskSigExpire, oNoAskSigExpire, oDefCertExpire, oAskCertExpire, oNoAskCertExpire, oDefCertLevel, oMinCertLevel, oAskCertLevel, oNoAskCertLevel, oFingerprint, oWithFingerprint, oWithKeygrip, oAnswerYes, oAnswerNo, oKeyring, oPrimaryKeyring, oSecretKeyring, oShowKeyring, oDefaultKey, oDefRecipient, oDefRecipientSelf, oNoDefRecipient, oTrySecretKey, oOptions, oDebug, oDebugLevel, oDebugAll, oDebugCCIDDriver, oStatusFD, oStatusFile, oAttributeFD, oAttributeFile, oEmitVersion, oNoEmitVersion, oCompletesNeeded, oMarginalsNeeded, oMaxCertDepth, oLoadExtension, oGnuPG, oRFC1991, oRFC2440, oRFC4880, oOpenPGP, oPGP2, oPGP6, oPGP7, oPGP8, oRFC2440Text, oNoRFC2440Text, oCipherAlgo, oDigestAlgo, oCertDigestAlgo, oCompressAlgo, oCompressLevel, oBZ2CompressLevel, oBZ2DecompressLowmem, oPassphrase, oPassphraseFD, oPassphraseFile, oPassphraseRepeat, oCommandFD, oCommandFile, oQuickRandom, oNoVerbose, oTrustDBName, oNoSecmemWarn, oRequireSecmem, oNoRequireSecmem, oNoPermissionWarn, oNoMDCWarn, oNoArmor, oNoDefKeyring, oNoGreeting, oNoTTY, oNoOptions, oNoBatch, oHomedir, oWithColons, oWithKeyData, oWithSigList, oWithSigCheck, oSkipVerify, oSkipHiddenRecipients, oNoSkipHiddenRecipients, oCompressKeys, oCompressSigs, oAlwaysTrust, oTrustModel, oForceOwnertrust, oSetFilename, oForYourEyesOnly, oNoForYourEyesOnly, oSetPolicyURL, oSigPolicyURL, oCertPolicyURL, oShowPolicyURL, oNoShowPolicyURL, oSigKeyserverURL, oUseEmbeddedFilename, oNoUseEmbeddedFilename, oComment, oDefaultComment, oNoComments, oThrowKeyids, oNoThrowKeyids, oShowPhotos, oNoShowPhotos, oPhotoViewer, oForceV3Sigs, oNoForceV3Sigs, oForceV4Certs, oNoForceV4Certs, oForceMDC, oNoForceMDC, oDisableMDC, oNoDisableMDC, oS2KMode, oS2KDigest, oS2KCipher, oS2KCount, oDisplayCharset, oNotDashEscaped, oEscapeFrom, oNoEscapeFrom, oLockOnce, oLockMultiple, oLockNever, oKeyServer, oKeyServerOptions, oImportOptions, oExportOptions, oListOptions, oVerifyOptions, oTempDir, oExecPath, oEncryptTo, oHiddenEncryptTo, oNoEncryptTo, oLoggerFD, oLoggerFile, oUtf8Strings, oNoUtf8Strings, oDisableCipherAlgo, oDisablePubkeyAlgo, oAllowNonSelfsignedUID, oNoAllowNonSelfsignedUID, oAllowFreeformUID, oNoAllowFreeformUID, oAllowSecretKeyImport, oEnableSpecialFilenames, oNoLiteral, oSetFilesize, oHonorHttpProxy, oFastListMode, oListOnly, oIgnoreTimeConflict, oIgnoreValidFrom, oIgnoreCrcError, oIgnoreMDCError, oShowSessionKey, oOverrideSessionKey, oNoRandomSeedFile, oAutoKeyRetrieve, oNoAutoKeyRetrieve, oUseAgent, oNoUseAgent, oGpgAgentInfo, oMergeOnly, oTryAllSecrets, oTrustedKey, oNoExpensiveTrustChecks, oFixedListMode, oNoSigCache, oNoSigCreateCheck, oAutoCheckTrustDB, oNoAutoCheckTrustDB, oPreservePermissions, oDefaultPreferenceList, oDefaultKeyserverURL, oPersonalCipherPreferences, oPersonalDigestPreferences, oPersonalCompressPreferences, oAgentProgram, oDisplay, oTTYname, oTTYtype, oLCctype, oLCmessages, oXauthority, oGroup, oUnGroup, oNoGroups, oStrict, oNoStrict, oMangleDosFilenames, oNoMangleDosFilenames, oEnableProgressFilter, oMultifile, oKeyidFormat, oExitOnStatusWriteError, oLimitCardInsertTries, oRequireCrossCert, oNoRequireCrossCert, oAutoKeyLocate, oNoAutoKeyLocate, oAllowMultisigVerification, oEnableDSA2, oDisableDSA2, oAllowMultipleMessages, oNoAllowMultipleMessages, oFakedSystemTime, oNoop }; static ARGPARSE_OPTS opts[] = { ARGPARSE_group (300, N_("@Commands:\n ")), ARGPARSE_c (aSign, "sign", N_("make a signature")), ARGPARSE_c (aClearsign, "clearsign", N_("make a clear text signature")), ARGPARSE_c (aDetachedSign, "detach-sign", N_("make a detached signature")), ARGPARSE_c (aEncr, "encrypt", N_("encrypt data")), ARGPARSE_c (aEncrFiles, "encrypt-files", "@"), ARGPARSE_c (aSym, "symmetric", N_("encryption only with symmetric cipher")), ARGPARSE_c (aStore, "store", "@"), ARGPARSE_c (aDecrypt, "decrypt", N_("decrypt data (default)")), ARGPARSE_c (aDecryptFiles, "decrypt-files", "@"), ARGPARSE_c (aVerify, "verify" , N_("verify a signature")), ARGPARSE_c (aVerifyFiles, "verify-files" , "@" ), ARGPARSE_c (aListKeys, "list-keys", N_("list keys")), ARGPARSE_c (aListKeys, "list-public-keys", "@" ), ARGPARSE_c (aListSigs, "list-sigs", N_("list keys and signatures")), ARGPARSE_c (aCheckKeys, "check-sigs",N_("list and check key signatures")), ARGPARSE_c (oFingerprint, "fingerprint", N_("list keys and fingerprints")), ARGPARSE_c (aListSecretKeys, "list-secret-keys", N_("list secret keys")), ARGPARSE_c (aKeygen, "gen-key", N_("generate a new key pair")), ARGPARSE_c (aGenRevoke, "gen-revoke",N_("generate a revocation certificate")), ARGPARSE_c (aDeleteKeys,"delete-keys", N_("remove keys from the public keyring")), ARGPARSE_c (aDeleteSecretKeys, "delete-secret-keys", N_("remove keys from the secret keyring")), ARGPARSE_c (aSignKey, "sign-key" ,N_("sign a key")), ARGPARSE_c (aLSignKey, "lsign-key" ,N_("sign a key locally")), ARGPARSE_c (aEditKey, "edit-key" ,N_("sign or edit a key")), ARGPARSE_c (aEditKey, "key-edit" ,"@"), ARGPARSE_c (aPasswd, "passwd", N_("change a passphrase")), ARGPARSE_c (aDesigRevoke, "desig-revoke","@" ), ARGPARSE_c (aExport, "export" , N_("export keys") ), ARGPARSE_c (aSendKeys, "send-keys" , N_("export keys to a key server") ), ARGPARSE_c (aRecvKeys, "recv-keys" , N_("import keys from a key server") ), ARGPARSE_c (aSearchKeys, "search-keys" , N_("search for keys on a key server") ), ARGPARSE_c (aRefreshKeys, "refresh-keys", N_("update all keys from a keyserver")), ARGPARSE_c (aLocateKeys, "locate-keys", "@"), ARGPARSE_c (aFetchKeys, "fetch-keys" , "@" ), ARGPARSE_c (aExportSecret, "export-secret-keys" , "@" ), ARGPARSE_c (aExportSecretSub, "export-secret-subkeys" , "@" ), ARGPARSE_c (aImport, "import", N_("import/merge keys")), ARGPARSE_c (aFastImport, "fast-import", "@"), #ifdef ENABLE_CARD_SUPPORT ARGPARSE_c (aCardStatus, "card-status", N_("print the card status")), ARGPARSE_c (aCardEdit, "card-edit", N_("change data on a card")), ARGPARSE_c (aChangePIN, "change-pin", N_("change a card's PIN")), #endif ARGPARSE_c (aListConfig, "list-config", "@"), ARGPARSE_c (aGPGConfList, "gpgconf-list", "@" ), ARGPARSE_c (aGPGConfTest, "gpgconf-test", "@" ), ARGPARSE_c (aListPackets, "list-packets","@"), ARGPARSE_c (aExportOwnerTrust, "export-ownertrust", "@"), ARGPARSE_c (aImportOwnerTrust, "import-ownertrust", "@"), ARGPARSE_c (aUpdateTrustDB,"update-trustdb", N_("update the trust database")), ARGPARSE_c (aCheckTrustDB, "check-trustdb", "@"), ARGPARSE_c (aFixTrustDB, "fix-trustdb", "@"), ARGPARSE_c (aDeArmor, "dearmor", "@"), ARGPARSE_c (aDeArmor, "dearmour", "@"), ARGPARSE_c (aEnArmor, "enarmor", "@"), ARGPARSE_c (aEnArmor, "enarmour", "@"), ARGPARSE_c (aPrintMD, "print-md", N_("print message digests")), ARGPARSE_c (aPrimegen, "gen-prime", "@" ), ARGPARSE_c (aGenRandom,"gen-random", "@" ), ARGPARSE_c (aServer, "server", N_("run in server mode")), ARGPARSE_group (301, N_("@\nOptions:\n ")), ARGPARSE_s_n (oArmor, "armor", N_("create ascii armored output")), ARGPARSE_s_n (oArmor, "armour", "@"), ARGPARSE_s_s (oRecipient, "recipient", N_("|USER-ID|encrypt for USER-ID")), ARGPARSE_s_s (oHiddenRecipient, "hidden-recipient", "@"), ARGPARSE_s_s (oRecipient, "remote-user", "@"), /* (old option name) */ ARGPARSE_s_s (oDefRecipient, "default-recipient", "@"), ARGPARSE_s_n (oDefRecipientSelf, "default-recipient-self", "@"), ARGPARSE_s_n (oNoDefRecipient, "no-default-recipient", "@"), ARGPARSE_s_s (oTempDir, "temp-directory", "@"), ARGPARSE_s_s (oExecPath, "exec-path", "@"), ARGPARSE_s_s (oEncryptTo, "encrypt-to", "@"), ARGPARSE_s_n (oNoEncryptTo, "no-encrypt-to", "@"), ARGPARSE_s_s (oHiddenEncryptTo, "hidden-encrypt-to", "@"), ARGPARSE_s_s (oLocalUser, "local-user", N_("|USER-ID|use USER-ID to sign or decrypt")), ARGPARSE_s_s (oTrySecretKey, "try-secret-key", "@"), ARGPARSE_s_i (oCompress, NULL, N_("|N|set compress level to N (0 disables)")), ARGPARSE_s_i (oCompressLevel, "compress-level", "@"), ARGPARSE_s_i (oBZ2CompressLevel, "bzip2-compress-level", "@"), ARGPARSE_s_n (oBZ2DecompressLowmem, "bzip2-decompress-lowmem", "@"), ARGPARSE_s_n (oTextmodeShort, NULL, "@"), ARGPARSE_s_n (oTextmode, "textmode", N_("use canonical text mode")), ARGPARSE_s_n (oNoTextmode, "no-textmode", "@"), ARGPARSE_s_n (oExpert, "expert", "@"), ARGPARSE_s_n (oNoExpert, "no-expert", "@"), ARGPARSE_s_s (oDefSigExpire, "default-sig-expire", "@"), ARGPARSE_s_n (oAskSigExpire, "ask-sig-expire", "@"), ARGPARSE_s_n (oNoAskSigExpire, "no-ask-sig-expire", "@"), ARGPARSE_s_s (oDefCertExpire, "default-cert-expire", "@"), ARGPARSE_s_n (oAskCertExpire, "ask-cert-expire", "@"), ARGPARSE_s_n (oNoAskCertExpire, "no-ask-cert-expire", "@"), ARGPARSE_s_i (oDefCertLevel, "default-cert-level", "@"), ARGPARSE_s_i (oMinCertLevel, "min-cert-level", "@"), ARGPARSE_s_n (oAskCertLevel, "ask-cert-level", "@"), ARGPARSE_s_n (oNoAskCertLevel, "no-ask-cert-level", "@"), ARGPARSE_s_s (oOutput, "output", N_("|FILE|write output to FILE")), ARGPARSE_p_u (oMaxOutput, "max-output", "@"), ARGPARSE_s_n (oVerbose, "verbose", N_("verbose")), ARGPARSE_s_n (oQuiet, "quiet", "@"), ARGPARSE_s_n (oNoTTY, "no-tty", "@"), ARGPARSE_s_n (oForceV3Sigs, "force-v3-sigs", "@"), ARGPARSE_s_n (oNoForceV3Sigs, "no-force-v3-sigs", "@"), ARGPARSE_s_n (oForceV4Certs, "force-v4-certs", "@"), ARGPARSE_s_n (oNoForceV4Certs, "no-force-v4-certs", "@"), ARGPARSE_s_n (oForceMDC, "force-mdc", "@"), ARGPARSE_s_n (oNoForceMDC, "no-force-mdc", "@"), ARGPARSE_s_n (oDisableMDC, "disable-mdc", "@"), ARGPARSE_s_n (oNoDisableMDC, "no-disable-mdc", "@"), ARGPARSE_s_n (oDryRun, "dry-run", N_("do not make any changes")), ARGPARSE_s_n (oInteractive, "interactive", N_("prompt before overwriting")), ARGPARSE_s_n (oUseAgent, "use-agent", "@"), ARGPARSE_s_n (oNoUseAgent, "no-use-agent", "@"), ARGPARSE_s_s (oGpgAgentInfo, "gpg-agent-info", "@"), ARGPARSE_s_n (oBatch, "batch", "@"), ARGPARSE_s_n (oAnswerYes, "yes", "@"), ARGPARSE_s_n (oAnswerNo, "no", "@"), ARGPARSE_s_s (oKeyring, "keyring", "@"), ARGPARSE_s_s (oPrimaryKeyring, "primary-keyring", "@"), ARGPARSE_s_s (oSecretKeyring, "secret-keyring", "@"), ARGPARSE_s_n (oShowKeyring, "show-keyring", "@"), ARGPARSE_s_s (oDefaultKey, "default-key", "@"), ARGPARSE_s_s (oKeyServer, "keyserver", "@"), ARGPARSE_s_s (oKeyServerOptions, "keyserver-options", "@"), ARGPARSE_s_s (oImportOptions, "import-options", "@"), ARGPARSE_s_s (oExportOptions, "export-options", "@"), ARGPARSE_s_s (oListOptions, "list-options", "@"), ARGPARSE_s_s (oVerifyOptions, "verify-options", "@"), ARGPARSE_s_s (oDisplayCharset, "display-charset", "@"), ARGPARSE_s_s (oDisplayCharset, "charset", "@"), ARGPARSE_s_s (oOptions, "options", "@"), ARGPARSE_p_u (oDebug, "debug", "@"), ARGPARSE_s_s (oDebugLevel, "debug-level", "@"), ARGPARSE_s_n (oDebugAll, "debug-all", "@"), ARGPARSE_s_i (oStatusFD, "status-fd", "@"), ARGPARSE_s_s (oStatusFile, "status-file", "@"), ARGPARSE_s_i (oAttributeFD, "attribute-fd", "@"), ARGPARSE_s_s (oAttributeFile, "attribute-file", "@"), ARGPARSE_s_n (oNoop, "sk-comments", "@"), ARGPARSE_s_n (oNoop, "no-sk-comments", "@"), ARGPARSE_s_i (oCompletesNeeded, "completes-needed", "@"), ARGPARSE_s_i (oMarginalsNeeded, "marginals-needed", "@"), ARGPARSE_s_i (oMaxCertDepth, "max-cert-depth", "@" ), ARGPARSE_s_s (oTrustedKey, "trusted-key", "@"), ARGPARSE_s_s (oLoadExtension, "load-extension", "@"), /* Dummy. */ ARGPARSE_s_n (oGnuPG, "gnupg", "@"), ARGPARSE_s_n (oGnuPG, "no-pgp2", "@"), ARGPARSE_s_n (oGnuPG, "no-pgp6", "@"), ARGPARSE_s_n (oGnuPG, "no-pgp7", "@"), ARGPARSE_s_n (oGnuPG, "no-pgp8", "@"), ARGPARSE_s_n (oRFC1991, "rfc1991", "@"), ARGPARSE_s_n (oRFC2440, "rfc2440", "@"), ARGPARSE_s_n (oRFC4880, "rfc4880", "@"), ARGPARSE_s_n (oOpenPGP, "openpgp", N_("use strict OpenPGP behavior")), ARGPARSE_s_n (oPGP2, "pgp2", "@"), ARGPARSE_s_n (oPGP6, "pgp6", "@"), ARGPARSE_s_n (oPGP7, "pgp7", "@"), ARGPARSE_s_n (oPGP8, "pgp8", "@"), ARGPARSE_s_n (oRFC2440Text, "rfc2440-text", "@"), ARGPARSE_s_n (oNoRFC2440Text, "no-rfc2440-text", "@"), ARGPARSE_s_i (oS2KMode, "s2k-mode", "@"), ARGPARSE_s_s (oS2KDigest, "s2k-digest-algo", "@"), ARGPARSE_s_s (oS2KCipher, "s2k-cipher-algo", "@"), ARGPARSE_s_i (oS2KCount, "s2k-count", "@"), ARGPARSE_s_s (oCipherAlgo, "cipher-algo", "@"), ARGPARSE_s_s (oDigestAlgo, "digest-algo", "@"), ARGPARSE_s_s (oCertDigestAlgo, "cert-digest-algo", "@"), ARGPARSE_s_s (oCompressAlgo,"compress-algo", "@"), ARGPARSE_s_s (oCompressAlgo, "compression-algo", "@"), /* Alias */ ARGPARSE_s_n (oThrowKeyids, "throw-keyid", "@"), ARGPARSE_s_n (oThrowKeyids, "throw-keyids", "@"), ARGPARSE_s_n (oNoThrowKeyids, "no-throw-keyid", "@"), ARGPARSE_s_n (oNoThrowKeyids, "no-throw-keyids", "@"), ARGPARSE_s_n (oShowPhotos, "show-photos", "@"), ARGPARSE_s_n (oNoShowPhotos, "no-show-photos", "@"), ARGPARSE_s_s (oPhotoViewer, "photo-viewer", "@"), ARGPARSE_s_s (oSetNotation, "set-notation", "@"), ARGPARSE_s_s (oSetNotation, "notation-data", "@"), /* Alias */ ARGPARSE_s_s (oSigNotation, "sig-notation", "@"), ARGPARSE_s_s (oCertNotation, "cert-notation", "@"), ARGPARSE_group (302, N_( "@\n(See the man page for a complete listing of all commands and options)\n" )), ARGPARSE_group (303, N_("@\nExamples:\n\n" " -se -r Bob [file] sign and encrypt for user Bob\n" " --clearsign [file] make a clear text signature\n" " --detach-sign [file] make a detached signature\n" " --list-keys [names] show keys\n" " --fingerprint [names] show fingerprints\n")), /* More hidden commands and options. */ ARGPARSE_c (aPrintMDs, "print-mds", "@"), /* old */ ARGPARSE_c (aListTrustDB, "list-trustdb", "@"), /* Not yet used: ARGPARSE_c (aListTrustPath, "list-trust-path", "@"), */ ARGPARSE_c (aDeleteSecretAndPublicKeys, "delete-secret-and-public-keys", "@"), ARGPARSE_c (aRebuildKeydbCaches, "rebuild-keydb-caches", "@"), ARGPARSE_s_s (oPassphrase, "passphrase", "@"), ARGPARSE_s_i (oPassphraseFD, "passphrase-fd", "@"), ARGPARSE_s_s (oPassphraseFile, "passphrase-file", "@"), ARGPARSE_s_i (oPassphraseRepeat,"passphrase-repeat", "@"), ARGPARSE_s_i (oCommandFD, "command-fd", "@"), ARGPARSE_s_s (oCommandFile, "command-file", "@"), ARGPARSE_s_n (oQuickRandom, "debug-quick-random", "@"), ARGPARSE_s_n (oNoVerbose, "no-verbose", "@"), ARGPARSE_s_s (oTrustDBName, "trustdb-name", "@"), ARGPARSE_s_n (oNoSecmemWarn, "no-secmem-warning", "@"), ARGPARSE_s_n (oRequireSecmem, "require-secmem", "@"), ARGPARSE_s_n (oNoRequireSecmem, "no-require-secmem", "@"), ARGPARSE_s_n (oNoPermissionWarn, "no-permission-warning", "@"), ARGPARSE_s_n (oNoMDCWarn, "no-mdc-warning", "@"), ARGPARSE_s_n (oNoArmor, "no-armor", "@"), ARGPARSE_s_n (oNoArmor, "no-armour", "@"), ARGPARSE_s_n (oNoDefKeyring, "no-default-keyring", "@"), ARGPARSE_s_n (oNoGreeting, "no-greeting", "@"), ARGPARSE_s_n (oNoOptions, "no-options", "@"), ARGPARSE_s_s (oHomedir, "homedir", "@"), ARGPARSE_s_n (oNoBatch, "no-batch", "@"), ARGPARSE_s_n (oWithColons, "with-colons", "@"), ARGPARSE_s_n (oWithKeyData,"with-key-data", "@"), ARGPARSE_s_n (oWithSigList,"with-sig-list", "@"), ARGPARSE_s_n (oWithSigCheck,"with-sig-check", "@"), ARGPARSE_s_n (aListKeys, "list-key", "@"), /* alias */ ARGPARSE_s_n (aListSigs, "list-sig", "@"), /* alias */ ARGPARSE_s_n (aCheckKeys, "check-sig", "@"), /* alias */ ARGPARSE_s_n (oSkipVerify, "skip-verify", "@"), ARGPARSE_s_n (oSkipHiddenRecipients, "skip-hidden-recipients", "@"), ARGPARSE_s_n (oNoSkipHiddenRecipients, "no-skip-hidden-recipients", "@"), ARGPARSE_s_n (oCompressKeys, "compress-keys", "@"), ARGPARSE_s_n (oCompressSigs, "compress-sigs", "@"), ARGPARSE_s_i (oDefCertLevel, "default-cert-check-level", "@"), /* old */ ARGPARSE_s_n (oAlwaysTrust, "always-trust", "@"), ARGPARSE_s_s (oTrustModel, "trust-model", "@"), ARGPARSE_s_s (oForceOwnertrust, "force-ownertrust", "@"), ARGPARSE_s_s (oSetFilename, "set-filename", "@"), ARGPARSE_s_n (oForYourEyesOnly, "for-your-eyes-only", "@"), ARGPARSE_s_n (oNoForYourEyesOnly, "no-for-your-eyes-only", "@"), ARGPARSE_s_s (oSetPolicyURL, "set-policy-url", "@"), ARGPARSE_s_s (oSigPolicyURL, "sig-policy-url", "@"), ARGPARSE_s_s (oCertPolicyURL, "cert-policy-url", "@"), ARGPARSE_s_n (oShowPolicyURL, "show-policy-url", "@"), ARGPARSE_s_n (oNoShowPolicyURL, "no-show-policy-url", "@"), ARGPARSE_s_s (oSigKeyserverURL, "sig-keyserver-url", "@"), ARGPARSE_s_n (oShowNotation, "show-notation", "@"), ARGPARSE_s_n (oNoShowNotation, "no-show-notation", "@"), ARGPARSE_s_s (oComment, "comment", "@"), ARGPARSE_s_n (oDefaultComment, "default-comment", "@"), ARGPARSE_s_n (oNoComments, "no-comments", "@"), ARGPARSE_s_n (oEmitVersion, "emit-version", "@"), ARGPARSE_s_n (oNoEmitVersion, "no-emit-version", "@"), ARGPARSE_s_n (oNoEmitVersion, "no-version", "@"), /* alias */ ARGPARSE_s_n (oNotDashEscaped, "not-dash-escaped", "@"), ARGPARSE_s_n (oEscapeFrom, "escape-from-lines", "@"), ARGPARSE_s_n (oNoEscapeFrom, "no-escape-from-lines", "@"), ARGPARSE_s_n (oLockOnce, "lock-once", "@"), ARGPARSE_s_n (oLockMultiple, "lock-multiple", "@"), ARGPARSE_s_n (oLockNever, "lock-never", "@"), ARGPARSE_s_i (oLoggerFD, "logger-fd", "@"), ARGPARSE_s_s (oLoggerFile, "log-file", "@"), ARGPARSE_s_s (oLoggerFile, "logger-file", "@"), /* 1.4 compatibility. */ ARGPARSE_s_n (oUseEmbeddedFilename, "use-embedded-filename", "@"), ARGPARSE_s_n (oNoUseEmbeddedFilename, "no-use-embedded-filename", "@"), ARGPARSE_s_n (oUtf8Strings, "utf8-strings", "@"), ARGPARSE_s_n (oNoUtf8Strings, "no-utf8-strings", "@"), ARGPARSE_s_n (oWithFingerprint, "with-fingerprint", "@"), ARGPARSE_s_n (oWithKeygrip, "with-keygrip", "@"), ARGPARSE_s_s (oDisableCipherAlgo, "disable-cipher-algo", "@"), ARGPARSE_s_s (oDisablePubkeyAlgo, "disable-pubkey-algo", "@"), ARGPARSE_s_n (oAllowNonSelfsignedUID, "allow-non-selfsigned-uid", "@"), ARGPARSE_s_n (oNoAllowNonSelfsignedUID, "no-allow-non-selfsigned-uid", "@"), ARGPARSE_s_n (oAllowFreeformUID, "allow-freeform-uid", "@"), ARGPARSE_s_n (oNoAllowFreeformUID, "no-allow-freeform-uid", "@"), ARGPARSE_s_n (oNoLiteral, "no-literal", "@"), ARGPARSE_p_u (oSetFilesize, "set-filesize", "@"), ARGPARSE_s_n (oHonorHttpProxy, "honor-http-proxy", "@"), ARGPARSE_s_n (oFastListMode, "fast-list-mode", "@"), ARGPARSE_s_n (oFixedListMode, "fixed-list-mode", "@"), ARGPARSE_s_n (oListOnly, "list-only", "@"), ARGPARSE_s_n (oIgnoreTimeConflict, "ignore-time-conflict", "@"), ARGPARSE_s_n (oIgnoreValidFrom, "ignore-valid-from", "@"), ARGPARSE_s_n (oIgnoreCrcError, "ignore-crc-error", "@"), ARGPARSE_s_n (oIgnoreMDCError, "ignore-mdc-error", "@"), ARGPARSE_s_n (oShowSessionKey, "show-session-key", "@"), ARGPARSE_s_s (oOverrideSessionKey, "override-session-key", "@"), ARGPARSE_s_n (oNoRandomSeedFile, "no-random-seed-file", "@"), ARGPARSE_s_n (oAutoKeyRetrieve, "auto-key-retrieve", "@"), ARGPARSE_s_n (oNoAutoKeyRetrieve, "no-auto-key-retrieve", "@"), ARGPARSE_s_n (oNoSigCache, "no-sig-cache", "@"), ARGPARSE_s_n (oNoSigCreateCheck, "no-sig-create-check", "@"), ARGPARSE_s_n (oAutoCheckTrustDB, "auto-check-trustdb", "@"), ARGPARSE_s_n (oNoAutoCheckTrustDB, "no-auto-check-trustdb", "@"), ARGPARSE_s_n (oMergeOnly, "merge-only", "@" ), ARGPARSE_s_n (oAllowSecretKeyImport, "allow-secret-key-import", "@"), ARGPARSE_s_n (oTryAllSecrets, "try-all-secrets", "@"), ARGPARSE_s_n (oEnableSpecialFilenames, "enable-special-filenames", "@"), ARGPARSE_s_n (oNoExpensiveTrustChecks, "no-expensive-trust-checks", "@"), ARGPARSE_s_n (oPreservePermissions, "preserve-permissions", "@"), ARGPARSE_s_s (oDefaultPreferenceList, "default-preference-list", "@"), ARGPARSE_s_s (oDefaultKeyserverURL, "default-keyserver-url", "@"), ARGPARSE_s_s (oPersonalCipherPreferences, "personal-cipher-preferences","@"), ARGPARSE_s_s (oPersonalDigestPreferences, "personal-digest-preferences","@"), ARGPARSE_s_s (oPersonalCompressPreferences, "personal-compress-preferences", "@"), ARGPARSE_s_s (oFakedSystemTime, "faked-system-time", "@"), /* Aliases. I constantly mistype these, and assume other people do as well. */ ARGPARSE_s_s (oPersonalCipherPreferences, "personal-cipher-prefs", "@"), ARGPARSE_s_s (oPersonalDigestPreferences, "personal-digest-prefs", "@"), ARGPARSE_s_s (oPersonalCompressPreferences, "personal-compress-prefs", "@"), ARGPARSE_s_s (oAgentProgram, "agent-program", "@"), ARGPARSE_s_s (oDisplay, "display", "@"), ARGPARSE_s_s (oTTYname, "ttyname", "@"), ARGPARSE_s_s (oTTYtype, "ttytype", "@"), ARGPARSE_s_s (oLCctype, "lc-ctype", "@"), ARGPARSE_s_s (oLCmessages, "lc-messages","@"), ARGPARSE_s_s (oXauthority, "xauthority", "@"), ARGPARSE_s_s (oGroup, "group", "@"), ARGPARSE_s_s (oUnGroup, "ungroup", "@"), ARGPARSE_s_n (oNoGroups, "no-groups", "@"), ARGPARSE_s_n (oStrict, "strict", "@"), ARGPARSE_s_n (oNoStrict, "no-strict", "@"), ARGPARSE_s_n (oMangleDosFilenames, "mangle-dos-filenames", "@"), ARGPARSE_s_n (oNoMangleDosFilenames, "no-mangle-dos-filenames", "@"), ARGPARSE_s_n (oEnableProgressFilter, "enable-progress-filter", "@"), ARGPARSE_s_n (oMultifile, "multifile", "@"), ARGPARSE_s_s (oKeyidFormat, "keyid-format", "@"), ARGPARSE_s_n (oExitOnStatusWriteError, "exit-on-status-write-error", "@"), ARGPARSE_s_i (oLimitCardInsertTries, "limit-card-insert-tries", "@"), ARGPARSE_s_n (oAllowMultisigVerification, "allow-multisig-verification", "@"), ARGPARSE_s_n (oEnableDSA2, "enable-dsa2", "@"), ARGPARSE_s_n (oDisableDSA2, "disable-dsa2", "@"), ARGPARSE_s_n (oAllowMultipleMessages, "allow-multiple-messages", "@"), ARGPARSE_s_n (oNoAllowMultipleMessages, "no-allow-multiple-messages", "@"), /* These two are aliases to help users of the PGP command line product use gpg with minimal pain. Many commands are common already as they seem to have borrowed commands from us. Now I'm returning the favor. */ ARGPARSE_s_s (oLocalUser, "sign-with", "@"), ARGPARSE_s_s (oRecipient, "user", "@"), ARGPARSE_s_n (oRequireCrossCert, "require-backsigs", "@"), ARGPARSE_s_n (oRequireCrossCert, "require-cross-certification", "@"), ARGPARSE_s_n (oNoRequireCrossCert, "no-require-backsigs", "@"), ARGPARSE_s_n (oNoRequireCrossCert, "no-require-cross-certification", "@"), /* New options. Fixme: Should go more to the top. */ ARGPARSE_s_s (oAutoKeyLocate, "auto-key-locate", "@"), ARGPARSE_s_n (oNoAutoKeyLocate, "no-auto-key-locate", "@"), ARGPARSE_end () }; #ifdef ENABLE_SELINUX_HACKS #define ALWAYS_ADD_KEYRINGS 1 #else #define ALWAYS_ADD_KEYRINGS 0 #endif int g10_errors_seen = 0; static int utf8_strings = 0; static int maybe_setuid = 1; static char *build_list( const char *text, char letter, const char *(*mapf)(int), int (*chkf)(int) ); static void set_cmd( enum cmd_and_opt_values *ret_cmd, enum cmd_and_opt_values new_cmd ); static void print_mds( const char *fname, int algo ); static void add_notation_data( const char *string, int which ); static void add_policy_url( const char *string, int which ); static void add_keyserver_url( const char *string, int which ); static void emergency_cleanup (void); static char * make_libversion (const char *libname, const char *(*getfnc)(const char*)) { const char *s; char *result; if (maybe_setuid) { gcry_control (GCRYCTL_INIT_SECMEM, 0, 0); /* Drop setuid. */ maybe_setuid = 0; } s = getfnc (NULL); result = xmalloc (strlen (libname) + 1 + strlen (s) + 1); strcpy (stpcpy (stpcpy (result, libname), " "), s); return result; } static const char * my_strusage( int level ) { static char *digests, *pubkeys, *ciphers, *zips, *ver_gcry; const char *p; switch( level ) { case 11: p = "gpg (GnuPG)"; break; case 13: p = VERSION; break; case 17: p = PRINTABLE_OS_NAME; break; case 19: p = _("Please report bugs to <@EMAIL@>.\n"); break; case 20: if (!ver_gcry) ver_gcry = make_libversion ("libgcrypt", gcry_check_version); p = ver_gcry; break; #ifdef IS_DEVELOPMENT_VERSION case 25: p="NOTE: THIS IS A DEVELOPMENT VERSION!"; break; case 26: p="It is only intended for test purposes and should NOT be"; break; case 27: p="used in a production environment or with production keys!"; break; #endif case 1: case 40: p = _("Usage: gpg [options] [files] (-h for help)"); break; case 41: p = _("Syntax: gpg [options] [files]\n" "sign, check, encrypt or decrypt\n" "default operation depends on the input data\n"); break; case 31: p = "\nHome: "; break; #ifndef __riscos__ case 32: p = opt.homedir; break; #else /* __riscos__ */ case 32: p = make_filename(opt.homedir, NULL); break; #endif /* __riscos__ */ case 33: p = _("\nSupported algorithms:\n"); break; case 34: if (!pubkeys) pubkeys = build_list (_("Pubkey: "), 0, openpgp_pk_algo_name, openpgp_pk_test_algo ); p = pubkeys; break; case 35: if( !ciphers ) ciphers = build_list(_("Cipher: "), 'S', openpgp_cipher_algo_name, openpgp_cipher_test_algo ); p = ciphers; break; case 36: if( !digests ) digests = build_list(_("Hash: "), 'H', gcry_md_algo_name, openpgp_md_test_algo ); p = digests; break; case 37: if( !zips ) zips = build_list(_("Compression: "),'Z', compress_algo_to_string, check_compress_algo); p = zips; break; default: p = NULL; } return p; } static char * build_list( const char *text, char letter, const char * (*mapf)(int), int (*chkf)(int) ) { int i; const char *s; size_t n=strlen(text)+2; char *list, *p, *line=NULL; if (maybe_setuid) gcry_control (GCRYCTL_INIT_SECMEM, 0, 0); /* Drop setuid. */ for(i=0; i <= 110; i++ ) if( !chkf(i) && (s=mapf(i)) ) n += strlen(s) + 7 + 2; list = xmalloc( 21 + n ); *list = 0; for(p=NULL, i=0; i <= 110; i++ ) { if( !chkf(i) && (s=mapf(i)) ) { if( !p ) { p = stpcpy( list, text ); line=p; } else p = stpcpy( p, ", "); if(strlen(line)>60) { int spaces=strlen(text); list=xrealloc(list,n+spaces+1); /* realloc could move the block, so find the end again */ p=list; while(*p) p++; p=stpcpy(p, "\n"); line=p; for(;spaces;spaces--) p=stpcpy(p, " "); } p = stpcpy(p, s ); if(opt.verbose && letter) { char num[8]; sprintf(num," (%c%d)",letter,i); p = stpcpy(p,num); } } } if( p ) p = stpcpy(p, "\n" ); return list; } static void wrong_args( const char *text) { fputs(_("usage: gpg [options] "),stderr); fputs(text,stderr); putc('\n',stderr); g10_exit(2); } static char * make_username( const char *string ) { char *p; if( utf8_strings ) p = xstrdup(string); else p = native_to_utf8( string ); return p; } static void set_opt_session_env (const char *name, const char *value) { gpg_error_t err; err = session_env_setenv (opt.session_env, name, value); if (err) log_fatal ("error setting session environment: %s\n", gpg_strerror (err)); } /* Setup the debugging. With a LEVEL of NULL only the active debug flags are propagated to the subsystems. With LEVEL set, a specific set of debug flags is set; thus overriding all flags already set. */ static void set_debug (const char *level) { int numok = (level && digitp (level)); int numlvl = numok? atoi (level) : 0; if (!level) ; else if (!strcmp (level, "none") || (numok && numlvl < 1)) opt.debug = 0; else if (!strcmp (level, "basic") || (numok && numlvl <= 2)) opt.debug = DBG_MEMSTAT_VALUE; else if (!strcmp (level, "advanced") || (numok && numlvl <= 5)) opt.debug = DBG_MEMSTAT_VALUE|DBG_TRUST_VALUE|DBG_EXTPROG_VALUE; else if (!strcmp (level, "expert") || (numok && numlvl <= 8)) opt.debug = (DBG_MEMSTAT_VALUE|DBG_TRUST_VALUE|DBG_EXTPROG_VALUE |DBG_CACHE_VALUE|DBG_FILTER_VALUE|DBG_PACKET_VALUE); else if (!strcmp (level, "guru") || numok) { opt.debug = ~0; /* Unless the "guru" string has been used we don't want to allow hashing debugging. The rationale is that people tend to select the highest debug value and would then clutter their disk with debug files which may reveal confidential data. */ if (numok) opt.debug &= ~(DBG_HASHING_VALUE); } else { log_error (_("invalid debug-level `%s' given\n"), level); g10_exit (2); } if (opt.debug & DBG_MEMORY_VALUE ) memory_debug_mode = 1; if (opt.debug & DBG_MEMSTAT_VALUE ) memory_stat_debug_mode = 1; if (opt.debug & DBG_MPI_VALUE) gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 2); if (opt.debug & DBG_CIPHER_VALUE ) gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1); if (opt.debug & DBG_IOBUF_VALUE ) iobuf_debug_mode = 1; gcry_control (GCRYCTL_SET_VERBOSITY, (int)opt.verbose); if (opt.debug) log_info ("enabled debug flags:%s%s%s%s%s%s%s%s%s%s%s%s%s\n", (opt.debug & DBG_PACKET_VALUE )? " packet":"", (opt.debug & DBG_MPI_VALUE )? " mpi":"", (opt.debug & DBG_CIPHER_VALUE )? " cipher":"", (opt.debug & DBG_FILTER_VALUE )? " filter":"", (opt.debug & DBG_IOBUF_VALUE )? " iobuf":"", (opt.debug & DBG_MEMORY_VALUE )? " memory":"", (opt.debug & DBG_CACHE_VALUE )? " cache":"", (opt.debug & DBG_MEMSTAT_VALUE)? " memstat":"", (opt.debug & DBG_TRUST_VALUE )? " trust":"", (opt.debug & DBG_HASHING_VALUE)? " hashing":"", (opt.debug & DBG_EXTPROG_VALUE)? " extprog":"", (opt.debug & DBG_CARD_IO_VALUE)? " cardio":"", (opt.debug & DBG_ASSUAN_VALUE )? " assuan":""); } /* We need the home directory also in some other directories, so make sure that both variables are always in sync. */ static void set_homedir (const char *dir) { if (!dir) dir = ""; opt.homedir = dir; } /* We set the screen dimensions for UI purposes. Do not allow screens smaller than 80x24 for the sake of simplicity. */ static void set_screen_dimensions(void) { #ifndef HAVE_W32_SYSTEM char *str; str=getenv("COLUMNS"); if(str) opt.screen_columns=atoi(str); str=getenv("LINES"); if(str) opt.screen_lines=atoi(str); #endif if(opt.screen_columns<80 || opt.screen_columns>255) opt.screen_columns=80; if(opt.screen_lines<24 || opt.screen_lines>255) opt.screen_lines=24; } /* Helper to open a file FNAME either for reading or writing to be used with --status-file etc functions. Not generally useful but it avoids the riscos specific functions and well some Windows people might like it too. Prints an error message and returns -1 on error. On success the file descriptor is returned. */ static int open_info_file (const char *fname, int for_write, int binary) { #ifdef __riscos__ return riscos_fdopenfile (fname, for_write); #elif defined (ENABLE_SELINUX_HACKS) /* We can't allow these even when testing for a secured filename because files to be secured might not yet been secured. This is similar to the option file but in that case it is unlikely that sensitive information may be retrieved by means of error messages. */ (void)fname; (void)for_write; (void)binary; return -1; #else int fd; if (binary) binary = MY_O_BINARY; /* if (is_secured_filename (fname)) */ /* { */ /* fd = -1; */ /* gpg_err_set_errno (EPERM); */ /* } */ /* else */ /* { */ do { if (for_write) fd = open (fname, O_CREAT | O_TRUNC | O_WRONLY | binary, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); else fd = open (fname, O_RDONLY | binary); } while (fd == -1 && errno == EINTR); /* } */ if ( fd == -1) log_error ( for_write? _("can't create `%s': %s\n") : _("can't open `%s': %s\n"), fname, strerror(errno)); return fd; #endif } static void set_cmd( enum cmd_and_opt_values *ret_cmd, enum cmd_and_opt_values new_cmd ) { enum cmd_and_opt_values cmd = *ret_cmd; if( !cmd || cmd == new_cmd ) cmd = new_cmd; else if( cmd == aSign && new_cmd == aEncr ) cmd = aSignEncr; else if( cmd == aEncr && new_cmd == aSign ) cmd = aSignEncr; else if( cmd == aSign && new_cmd == aSym ) cmd = aSignSym; else if( cmd == aSym && new_cmd == aSign ) cmd = aSignSym; else if( cmd == aSym && new_cmd == aEncr ) cmd = aEncrSym; else if( cmd == aEncr && new_cmd == aSym ) cmd = aEncrSym; else if (cmd == aSignEncr && new_cmd == aSym) cmd = aSignEncrSym; else if (cmd == aSignSym && new_cmd == aEncr) cmd = aSignEncrSym; else if (cmd == aEncrSym && new_cmd == aSign) cmd = aSignEncrSym; else if( ( cmd == aSign && new_cmd == aClearsign ) || ( cmd == aClearsign && new_cmd == aSign ) ) cmd = aClearsign; else { log_error(_("conflicting commands\n")); g10_exit(2); } *ret_cmd = cmd; } static void add_group(char *string) { char *name,*value; struct groupitem *item; /* Break off the group name */ name=strsep(&string,"="); if(string==NULL) { log_error(_("no = sign found in group definition `%s'\n"),name); return; } trim_trailing_ws(name,strlen(name)); /* Does this group already exist? */ for(item=opt.grouplist;item;item=item->next) if(strcasecmp(item->name,name)==0) break; if(!item) { item=xmalloc(sizeof(struct groupitem)); item->name=name; item->next=opt.grouplist; item->values=NULL; opt.grouplist=item; } /* Break apart the values */ while ((value= strsep(&string," \t"))) { if (*value) add_to_strlist2(&item->values,value,utf8_strings); } } static void rm_group(char *name) { struct groupitem *item,*last=NULL; trim_trailing_ws(name,strlen(name)); for(item=opt.grouplist;item;last=item,item=item->next) { if(strcasecmp(item->name,name)==0) { if(last) last->next=item->next; else opt.grouplist=item->next; free_strlist(item->values); xfree(item); break; } } } /* We need to check three things. 0) The homedir. It must be x00, a directory, and owned by the user. 1) The options/gpg.conf file. Okay unless it or its containing directory is group or other writable or not owned by us. Disable exec in this case. 2) Extensions. Same as #1. Returns true if the item is unsafe. */ static int check_permissions (const char *path, int item) { #if defined(HAVE_STAT) && !defined(HAVE_DOSISH_SYSTEM) static int homedir_cache=-1; char *tmppath,*dir; struct stat statbuf,dirbuf; int homedir=0,ret=0,checkonly=0; int perm=0,own=0,enc_dir_perm=0,enc_dir_own=0; if(opt.no_perm_warn) return 0; assert(item==0 || item==1 || item==2); /* extensions may attach a path */ if(item==2 && path[0]!=DIRSEP_C) { if(strchr(path,DIRSEP_C)) tmppath=make_filename(path,NULL); else tmppath=make_filename(gnupg_libdir (),path,NULL); } else tmppath=xstrdup(path); /* If the item is located in the homedir, but isn't the homedir, don't continue if we already checked the homedir itself. This is to avoid user confusion with an extra options file warning which could be rectified if the homedir itself had proper permissions. */ if(item!=0 && homedir_cache>-1 && ascii_strncasecmp(opt.homedir,tmppath,strlen(opt.homedir))==0) { ret=homedir_cache; goto end; } /* It's okay if the file or directory doesn't exist */ if(stat(tmppath,&statbuf)!=0) { ret=0; goto end; } /* Now check the enclosing directory. Theoretically, we could walk this test up to the root directory /, but for the sake of sanity, I'm stopping at one level down. */ dir=make_dirname(tmppath); if(stat(dir,&dirbuf)!=0 || !S_ISDIR(dirbuf.st_mode)) { /* Weird error */ ret=1; goto end; } xfree(dir); /* Assume failure */ ret=1; if(item==0) { /* The homedir must be x00, a directory, and owned by the user. */ if(S_ISDIR(statbuf.st_mode)) { if(statbuf.st_uid==getuid()) { if((statbuf.st_mode & (S_IRWXG|S_IRWXO))==0) ret=0; else perm=1; } else own=1; homedir_cache=ret; } } else if(item==1 || item==2) { /* The options or extension file. Okay unless it or its containing directory is group or other writable or not owned by us or root. */ if(S_ISREG(statbuf.st_mode)) { if(statbuf.st_uid==getuid() || statbuf.st_uid==0) { if((statbuf.st_mode & (S_IWGRP|S_IWOTH))==0) { /* it's not writable, so make sure the enclosing directory is also not writable */ if(dirbuf.st_uid==getuid() || dirbuf.st_uid==0) { if((dirbuf.st_mode & (S_IWGRP|S_IWOTH))==0) ret=0; else enc_dir_perm=1; } else enc_dir_own=1; } else { /* it's writable, so the enclosing directory had better not let people get to it. */ if(dirbuf.st_uid==getuid() || dirbuf.st_uid==0) { if((dirbuf.st_mode & (S_IRWXG|S_IRWXO))==0) ret=0; else perm=enc_dir_perm=1; /* unclear which one to fix! */ } else enc_dir_own=1; } } else own=1; } } else BUG(); if(!checkonly) { if(own) { if(item==0) log_info(_("WARNING: unsafe ownership on" " homedir `%s'\n"),tmppath); else if(item==1) log_info(_("WARNING: unsafe ownership on" " configuration file `%s'\n"),tmppath); else log_info(_("WARNING: unsafe ownership on" " extension `%s'\n"),tmppath); } if(perm) { if(item==0) log_info(_("WARNING: unsafe permissions on" " homedir `%s'\n"),tmppath); else if(item==1) log_info(_("WARNING: unsafe permissions on" " configuration file `%s'\n"),tmppath); else log_info(_("WARNING: unsafe permissions on" " extension `%s'\n"),tmppath); } if(enc_dir_own) { if(item==0) log_info(_("WARNING: unsafe enclosing directory ownership on" " homedir `%s'\n"),tmppath); else if(item==1) log_info(_("WARNING: unsafe enclosing directory ownership on" " configuration file `%s'\n"),tmppath); else log_info(_("WARNING: unsafe enclosing directory ownership on" " extension `%s'\n"),tmppath); } if(enc_dir_perm) { if(item==0) log_info(_("WARNING: unsafe enclosing directory permissions on" " homedir `%s'\n"),tmppath); else if(item==1) log_info(_("WARNING: unsafe enclosing directory permissions on" " configuration file `%s'\n"),tmppath); else log_info(_("WARNING: unsafe enclosing directory permissions on" " extension `%s'\n"),tmppath); } } end: xfree(tmppath); if(homedir) homedir_cache=ret; return ret; #else /*!(HAVE_STAT && !HAVE_DOSISH_SYSTEM)*/ (void)path; (void)item; return 0; #endif /*!(HAVE_STAT && !HAVE_DOSISH_SYSTEM)*/ } /* Print the OpenPGP defined algo numbers. */ static void print_algo_numbers(int (*checker)(int)) { int i,first=1; for(i=0;i<=110;i++) { if(!checker(i)) { if(first) first=0; else es_printf (";"); es_printf ("%d",i); } } } static void print_algo_names(int (*checker)(int),const char *(*mapper)(int)) { int i,first=1; for(i=0;i<=110;i++) { if(!checker(i)) { if(first) first=0; else es_printf (";"); es_printf ("%s",mapper(i)); } } } /* In the future, we can do all sorts of interesting configuration output here. For now, just give "group" as the Enigmail folks need it, and pubkey, cipher, hash, and compress as they may be useful for frontends. */ static void list_config(char *items) { int show_all=(items==NULL); char *name=NULL; if(!opt.with_colons) return; while(show_all || (name=strsep(&items," "))) { int any=0; if(show_all || ascii_strcasecmp(name,"group")==0) { struct groupitem *iter; for(iter=opt.grouplist;iter;iter=iter->next) { strlist_t sl; es_fprintf (es_stdout, "cfg:group:"); es_write_sanitized (es_stdout, iter->name, strlen(iter->name), ":", NULL); es_putc (':', es_stdout); for(sl=iter->values;sl;sl=sl->next) { print_sanitized_string2 (stdout, sl->d, ':',';'); if(sl->next) es_printf(";"); } es_printf("\n"); } any=1; } if(show_all || ascii_strcasecmp(name,"version")==0) { es_printf("cfg:version:"); es_write_sanitized (es_stdout, VERSION, strlen(VERSION), ":", NULL); es_printf ("\n"); any=1; } if(show_all || ascii_strcasecmp(name,"pubkey")==0) { es_printf ("cfg:pubkey:"); print_algo_numbers (openpgp_pk_test_algo); es_printf ("\n"); any=1; } if(show_all || ascii_strcasecmp(name,"cipher")==0) { es_printf ("cfg:cipher:"); print_algo_numbers(openpgp_cipher_test_algo); es_printf ("\n"); any=1; } if (show_all || !ascii_strcasecmp (name,"ciphername")) { es_printf ("cfg:ciphername:"); print_algo_names (openpgp_cipher_test_algo,openpgp_cipher_algo_name); es_printf ("\n"); any = 1; } if(show_all || ascii_strcasecmp(name,"digest")==0 || ascii_strcasecmp(name,"hash")==0) { es_printf ("cfg:digest:"); print_algo_numbers(openpgp_md_test_algo); es_printf ("\n"); any=1; } if (show_all || !ascii_strcasecmp(name,"digestname") || !ascii_strcasecmp(name,"hashname")) { es_printf ("cfg:digestname:"); print_algo_names (openpgp_md_test_algo, gcry_md_algo_name); es_printf ("\n"); any=1; } if(show_all || ascii_strcasecmp(name,"compress")==0) { es_printf ("cfg:compress:"); print_algo_numbers(check_compress_algo); es_printf ("\n"); any=1; } if(show_all || ascii_strcasecmp(name,"ccid-reader-id")==0) { #if defined(ENABLE_CARD_SUPPORT) && defined(HAVE_LIBUSB) \ && GNUPG_MAJOR_VERSION == 1 char *p, *p2, *list = ccid_get_reader_list (); for (p=list; p && (p2 = strchr (p, '\n')); p = p2+1) { *p2 = 0; es_printf ("cfg:ccid-reader-id:%s\n", p); } free (list); #endif any=1; } if(show_all) break; if(!any) log_error(_("unknown configuration item `%s'\n"),name); } } /* List options and default values in the GPG Conf format. This is a new tool distributed with gnupg 1.9.x but we also want some limited support in older gpg versions. The output is the name of the configuration file and a list of options available for editing by gpgconf. */ static void gpgconf_list (const char *configfile) { char *configfile_esc = percent_escape (configfile, NULL); es_printf ("gpgconf-gpg.conf:%lu:\"%s\n", GC_OPT_FLAG_DEFAULT, configfile_esc ? configfile_esc : "/dev/null"); es_printf ("verbose:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("quiet:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("keyserver:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("reader-port:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("default-key:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("encrypt-to:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("try-secret-key:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("auto-key-locate:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("log-file:%lu:\n", GC_OPT_FLAG_NONE); es_printf ("debug-level:%lu:\"none:\n", GC_OPT_FLAG_DEFAULT); es_printf ("group:%lu:\n", GC_OPT_FLAG_NONE); /* The next one is an info only item and should match the macros at the top of keygen.c */ es_printf ("default_pubkey_algo:%lu:\"%s:\n", GC_OPT_FLAG_DEFAULT, "RSA-2048"); xfree (configfile_esc); } static int parse_subpacket_list(char *list) { char *tok; byte subpackets[128],i; int count=0; if(!list) { /* No arguments means all subpackets */ memset(subpackets+1,1,sizeof(subpackets)-1); count=127; } else { memset(subpackets,0,sizeof(subpackets)); /* Merge with earlier copy */ if(opt.show_subpackets) { byte *in; for(in=opt.show_subpackets;*in;in++) { if(*in>127 || *in<1) BUG(); if(!subpackets[*in]) count++; subpackets[*in]=1; } } while((tok=strsep(&list," ,"))) { if(!*tok) continue; i=atoi(tok); if(i>127 || i<1) return 0; if(!subpackets[i]) count++; subpackets[i]=1; } } xfree(opt.show_subpackets); opt.show_subpackets=xmalloc(count+1); opt.show_subpackets[count--]=0; for(i=1;i<128 && count>=0;i++) if(subpackets[i]) opt.show_subpackets[count--]=i; return 1; } static int parse_list_options(char *str) { char *subpackets=""; /* something that isn't NULL */ struct parse_options lopts[]= { {"show-photos",LIST_SHOW_PHOTOS,NULL, N_("display photo IDs during key listings")}, {"show-policy-urls",LIST_SHOW_POLICY_URLS,NULL, N_("show policy URLs during signature listings")}, {"show-notations",LIST_SHOW_NOTATIONS,NULL, N_("show all notations during signature listings")}, {"show-std-notations",LIST_SHOW_STD_NOTATIONS,NULL, N_("show IETF standard notations during signature listings")}, {"show-standard-notations",LIST_SHOW_STD_NOTATIONS,NULL, NULL}, {"show-user-notations",LIST_SHOW_USER_NOTATIONS,NULL, N_("show user-supplied notations during signature listings")}, {"show-keyserver-urls",LIST_SHOW_KEYSERVER_URLS,NULL, N_("show preferred keyserver URLs during signature listings")}, {"show-uid-validity",LIST_SHOW_UID_VALIDITY,NULL, N_("show user ID validity during key listings")}, {"show-unusable-uids",LIST_SHOW_UNUSABLE_UIDS,NULL, N_("show revoked and expired user IDs in key listings")}, {"show-unusable-subkeys",LIST_SHOW_UNUSABLE_SUBKEYS,NULL, N_("show revoked and expired subkeys in key listings")}, {"show-keyring",LIST_SHOW_KEYRING,NULL, N_("show the keyring name in key listings")}, {"show-sig-expire",LIST_SHOW_SIG_EXPIRE,NULL, N_("show expiration dates during signature listings")}, {"show-sig-subpackets",LIST_SHOW_SIG_SUBPACKETS,NULL, NULL}, {NULL,0,NULL,NULL} }; /* C99 allows for non-constant initializers, but we'd like to compile everywhere, so fill in the show-sig-subpackets argument here. Note that if the parse_options array changes, we'll have to change the subscript here. */ lopts[12].value=&subpackets; if(parse_options(str,&opt.list_options,lopts,1)) { if(opt.list_options&LIST_SHOW_SIG_SUBPACKETS) { /* Unset so users can pass multiple lists in. */ opt.list_options&=~LIST_SHOW_SIG_SUBPACKETS; if(!parse_subpacket_list(subpackets)) return 0; } else if(subpackets==NULL && opt.show_subpackets) { /* User did 'no-show-subpackets' */ xfree(opt.show_subpackets); opt.show_subpackets=NULL; } return 1; } else return 0; } /* Collapses argc/argv into a single string that must be freed */ static char * collapse_args(int argc,char *argv[]) { char *str=NULL; int i,first=1,len=0; for(i=0;iflags=2; break; case oShowKeyring: deprecated_warning(configname,configlineno,"--show-keyring", "--list-options ","show-keyring"); opt.list_options|=LIST_SHOW_KEYRING; break; case oDebug: opt.debug |= pargs.r.ret_ulong; break; case oDebugAll: opt.debug = ~0; break; case oDebugLevel: debug_level = pargs.r.ret_str; break; case oStatusFD: set_status_fd ( translate_sys2libc_fd_int (pargs.r.ret_int, 1) ); break; case oStatusFile: set_status_fd ( open_info_file (pargs.r.ret_str, 1, 0) ); break; case oAttributeFD: set_attrib_fd ( translate_sys2libc_fd_int (pargs.r.ret_int, 1) ); break; case oAttributeFile: set_attrib_fd ( open_info_file (pargs.r.ret_str, 1, 1) ); break; case oLoggerFD: log_set_fd (translate_sys2libc_fd_int (pargs.r.ret_int, 1)); break; case oLoggerFile: logfile = pargs.r.ret_str; break; case oWithFingerprint: opt.with_fingerprint = 1; opt.fingerprint++; break; case oFingerprint: opt.fingerprint++; fpr_maybe_cmd = 1; break; case oWithKeygrip: opt.with_keygrip = 1; break; case oSecretKeyring: /* Ignore this old option. */ break; case oOptions: /* config files may not be nested (silently ignore them) */ if( !configfp ) { xfree(configname); configname = xstrdup(pargs.r.ret_str); goto next_pass; } break; case oNoArmor: opt.no_armor=1; opt.armor=0; break; case oNoDefKeyring: default_keyring = 0; break; case oNoGreeting: nogreeting = 1; break; case oNoVerbose: opt.verbose = 0; gcry_control (GCRYCTL_SET_VERBOSITY, (int)opt.verbose); opt.list_sigs=0; break; case oQuickRandom: gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); break; case oEmitVersion: opt.no_version=0; break; case oNoEmitVersion: opt.no_version=1; break; case oCompletesNeeded: opt.completes_needed = pargs.r.ret_int; break; case oMarginalsNeeded: opt.marginals_needed = pargs.r.ret_int; break; case oMaxCertDepth: opt.max_cert_depth = pargs.r.ret_int; break; case oTrustDBName: trustdb_name = pargs.r.ret_str; break; case oDefaultKey: opt.def_secret_key = pargs.r.ret_str; break; case oDefRecipient: if( *pargs.r.ret_str ) opt.def_recipient = make_username(pargs.r.ret_str); break; case oDefRecipientSelf: xfree(opt.def_recipient); opt.def_recipient = NULL; opt.def_recipient_self = 1; break; case oNoDefRecipient: xfree(opt.def_recipient); opt.def_recipient = NULL; opt.def_recipient_self = 0; break; case oNoOptions: opt.no_homedir_creation = 1; break; /* no-options */ case oHomedir: break; case oNoBatch: opt.batch = 0; break; case oWithKeyData: opt.with_key_data=1; /*FALLTHRU*/ case oWithColons: opt.with_colons=':'; break; case oWithSigCheck: opt.check_sigs = 1; /*FALLTHRU*/ case oWithSigList: opt.list_sigs = 1; break; case oSkipVerify: opt.skip_verify=1; break; case oSkipHiddenRecipients: opt.skip_hidden_recipients = 1; break; case oNoSkipHiddenRecipients: opt.skip_hidden_recipients = 0; break; case oCompressKeys: opt.compress_keys = 1; break; case aListSecretKeys: set_cmd( &cmd, aListSecretKeys); break; /* There are many programs (like mutt) that call gpg with --always-trust so keep this option around for a long time. */ case oAlwaysTrust: opt.trust_model=TM_ALWAYS; break; case oTrustModel: parse_trust_model(pargs.r.ret_str); break; case oForceOwnertrust: log_info(_("NOTE: %s is not for normal use!\n"), "--force-ownertrust"); opt.force_ownertrust=string_to_trust_value(pargs.r.ret_str); if(opt.force_ownertrust==-1) { log_error("invalid ownertrust `%s'\n",pargs.r.ret_str); opt.force_ownertrust=0; } break; case oLoadExtension: /* Dummy so that gpg 1.4 conf files can work. Should eventually be removed. */ break; case oRFC1991: opt.compliance = CO_RFC1991; opt.force_v4_certs = 0; opt.escape_from = 1; break; case oOpenPGP: case oRFC4880: /* This is effectively the same as RFC2440, but with "--enable-dsa2 --no-rfc2440-text --escape-from-lines --require-cross-certification". */ opt.compliance = CO_RFC4880; opt.flags.dsa2 = 1; opt.flags.require_cross_cert = 1; opt.rfc2440_text = 0; opt.allow_non_selfsigned_uid = 1; opt.allow_freeform_uid = 1; opt.pgp2_workarounds = 0; opt.escape_from = 1; opt.force_v3_sigs = 0; opt.compress_keys = 0; /* not mandated, but we do it */ opt.compress_sigs = 0; /* ditto. */ opt.not_dash_escaped = 0; opt.def_cipher_algo = 0; opt.def_digest_algo = 0; opt.cert_digest_algo = 0; opt.compress_algo = -1; opt.s2k_mode = 3; /* iterated+salted */ opt.s2k_digest_algo = DIGEST_ALGO_SHA1; opt.s2k_cipher_algo = CIPHER_ALGO_3DES; break; case oRFC2440: opt.compliance = CO_RFC2440; opt.flags.dsa2 = 0; opt.rfc2440_text = 1; opt.allow_non_selfsigned_uid = 1; opt.allow_freeform_uid = 1; opt.pgp2_workarounds = 0; opt.escape_from = 0; opt.force_v3_sigs = 0; opt.compress_keys = 0; /* not mandated, but we do it */ opt.compress_sigs = 0; /* ditto. */ opt.not_dash_escaped = 0; opt.def_cipher_algo = 0; opt.def_digest_algo = 0; opt.cert_digest_algo = 0; opt.compress_algo = -1; opt.s2k_mode = 3; /* iterated+salted */ opt.s2k_digest_algo = DIGEST_ALGO_SHA1; opt.s2k_cipher_algo = CIPHER_ALGO_3DES; break; case oPGP2: opt.compliance = CO_PGP2; break; case oPGP6: opt.compliance = CO_PGP6; break; case oPGP7: opt.compliance = CO_PGP7; break; case oPGP8: opt.compliance = CO_PGP8; break; case oGnuPG: opt.compliance = CO_GNUPG; break; case oCompressSigs: opt.compress_sigs = 1; break; case oRFC2440Text: opt.rfc2440_text=1; break; case oNoRFC2440Text: opt.rfc2440_text=0; break; case oSetFilename: if(utf8_strings) opt.set_filename = pargs.r.ret_str; else opt.set_filename = native_to_utf8(pargs.r.ret_str); break; case oForYourEyesOnly: eyes_only = 1; break; case oNoForYourEyesOnly: eyes_only = 0; break; case oSetPolicyURL: add_policy_url(pargs.r.ret_str,0); add_policy_url(pargs.r.ret_str,1); break; case oSigPolicyURL: add_policy_url(pargs.r.ret_str,0); break; case oCertPolicyURL: add_policy_url(pargs.r.ret_str,1); break; case oShowPolicyURL: deprecated_warning(configname,configlineno,"--show-policy-url", "--list-options ","show-policy-urls"); deprecated_warning(configname,configlineno,"--show-policy-url", "--verify-options ","show-policy-urls"); opt.list_options|=LIST_SHOW_POLICY_URLS; opt.verify_options|=VERIFY_SHOW_POLICY_URLS; break; case oNoShowPolicyURL: deprecated_warning(configname,configlineno,"--no-show-policy-url", "--list-options ","no-show-policy-urls"); deprecated_warning(configname,configlineno,"--no-show-policy-url", "--verify-options ","no-show-policy-urls"); opt.list_options&=~LIST_SHOW_POLICY_URLS; opt.verify_options&=~VERIFY_SHOW_POLICY_URLS; break; case oSigKeyserverURL: add_keyserver_url(pargs.r.ret_str,0); break; case oUseEmbeddedFilename: opt.flags.use_embedded_filename=1; break; case oNoUseEmbeddedFilename: opt.flags.use_embedded_filename=0; break; case oComment: if(pargs.r.ret_str[0]) append_to_strlist(&opt.comments,pargs.r.ret_str); break; case oDefaultComment: deprecated_warning(configname,configlineno, "--default-comment","--no-comments",""); /* fall through */ case oNoComments: free_strlist(opt.comments); opt.comments=NULL; break; case oThrowKeyids: opt.throw_keyid = 1; break; case oNoThrowKeyids: opt.throw_keyid = 0; break; case oShowPhotos: deprecated_warning(configname,configlineno,"--show-photos", "--list-options ","show-photos"); deprecated_warning(configname,configlineno,"--show-photos", "--verify-options ","show-photos"); opt.list_options|=LIST_SHOW_PHOTOS; opt.verify_options|=VERIFY_SHOW_PHOTOS; break; case oNoShowPhotos: deprecated_warning(configname,configlineno,"--no-show-photos", "--list-options ","no-show-photos"); deprecated_warning(configname,configlineno,"--no-show-photos", "--verify-options ","no-show-photos"); opt.list_options&=~LIST_SHOW_PHOTOS; opt.verify_options&=~VERIFY_SHOW_PHOTOS; break; case oPhotoViewer: opt.photo_viewer = pargs.r.ret_str; break; case oForceV3Sigs: opt.force_v3_sigs = 1; break; case oNoForceV3Sigs: opt.force_v3_sigs = 0; break; case oForceV4Certs: opt.force_v4_certs = 1; break; case oNoForceV4Certs: opt.force_v4_certs = 0; break; case oForceMDC: opt.force_mdc = 1; break; case oNoForceMDC: opt.force_mdc = 0; break; case oDisableMDC: opt.disable_mdc = 1; break; case oNoDisableMDC: opt.disable_mdc = 0; break; case oS2KMode: opt.s2k_mode = pargs.r.ret_int; break; case oS2KDigest: s2k_digest_string = xstrdup(pargs.r.ret_str); break; case oS2KCipher: s2k_cipher_string = xstrdup(pargs.r.ret_str); break; case oS2KCount: if (pargs.r.ret_int) opt.s2k_count = encode_s2k_iterations (pargs.r.ret_int); else opt.s2k_count = 0; /* Auto-calibrate when needed. */ break; case oNoEncryptTo: opt.no_encrypt_to = 1; break; case oEncryptTo: /* store the recipient in the second list */ sl = add_to_strlist2( &remusr, pargs.r.ret_str, utf8_strings ); sl->flags = 1; break; case oHiddenEncryptTo: /* store the recipient in the second list */ sl = add_to_strlist2( &remusr, pargs.r.ret_str, utf8_strings ); sl->flags = 1|2; break; case oRecipient: /* store the recipient */ add_to_strlist2( &remusr, pargs.r.ret_str, utf8_strings ); any_explicit_recipient = 1; break; case oHiddenRecipient: /* store the recipient with a flag */ sl = add_to_strlist2( &remusr, pargs.r.ret_str, utf8_strings ); sl->flags = 2; any_explicit_recipient = 1; break; case oTrySecretKey: add_to_strlist2 (&opt.secret_keys_to_try, pargs.r.ret_str, utf8_strings); break; case oTextmodeShort: opt.textmode = 2; break; case oTextmode: opt.textmode=1; break; case oNoTextmode: opt.textmode=0; break; case oExpert: opt.expert = 1; break; case oNoExpert: opt.expert = 0; break; case oDefSigExpire: if(*pargs.r.ret_str!='\0') { if(parse_expire_string(pargs.r.ret_str)==(u32)-1) log_error(_("`%s' is not a valid signature expiration\n"), pargs.r.ret_str); else opt.def_sig_expire=pargs.r.ret_str; } break; case oAskSigExpire: opt.ask_sig_expire = 1; break; case oNoAskSigExpire: opt.ask_sig_expire = 0; break; case oDefCertExpire: if(*pargs.r.ret_str!='\0') { if(parse_expire_string(pargs.r.ret_str)==(u32)-1) log_error(_("`%s' is not a valid signature expiration\n"), pargs.r.ret_str); else opt.def_cert_expire=pargs.r.ret_str; } break; case oAskCertExpire: opt.ask_cert_expire = 1; break; case oNoAskCertExpire: opt.ask_cert_expire = 0; break; case oDefCertLevel: opt.def_cert_level=pargs.r.ret_int; break; case oMinCertLevel: opt.min_cert_level=pargs.r.ret_int; break; case oAskCertLevel: opt.ask_cert_level = 1; break; case oNoAskCertLevel: opt.ask_cert_level = 0; break; case oLocalUser: /* store the local users */ add_to_strlist2( &locusr, pargs.r.ret_str, utf8_strings ); break; case oCompress: /* this is the -z command line option */ opt.compress_level = opt.bz2_compress_level = pargs.r.ret_int; break; case oCompressLevel: opt.compress_level = pargs.r.ret_int; break; case oBZ2CompressLevel: opt.bz2_compress_level = pargs.r.ret_int; break; case oBZ2DecompressLowmem: opt.bz2_decompress_lowmem=1; break; case oPassphrase: set_passphrase_from_string(pargs.r.ret_str); break; case oPassphraseFD: pwfd = translate_sys2libc_fd_int (pargs.r.ret_int, 0); break; case oPassphraseFile: pwfd = open_info_file (pargs.r.ret_str, 0, 1); break; case oPassphraseRepeat: opt.passphrase_repeat=pargs.r.ret_int; break; case oCommandFD: opt.command_fd = translate_sys2libc_fd_int (pargs.r.ret_int, 0); break; case oCommandFile: opt.command_fd = open_info_file (pargs.r.ret_str, 0, 1); break; case oCipherAlgo: def_cipher_string = xstrdup(pargs.r.ret_str); break; case oDigestAlgo: def_digest_string = xstrdup(pargs.r.ret_str); break; case oCompressAlgo: /* If it is all digits, stick a Z in front of it for later. This is for backwards compatibility with versions that took the compress algorithm number. */ { char *pt=pargs.r.ret_str; while(*pt) { if (!isascii (*pt) || !isdigit (*pt)) break; pt++; } if(*pt=='\0') { compress_algo_string=xmalloc(strlen(pargs.r.ret_str)+2); strcpy(compress_algo_string,"Z"); strcat(compress_algo_string,pargs.r.ret_str); } else compress_algo_string = xstrdup(pargs.r.ret_str); } break; case oCertDigestAlgo: cert_digest_string = xstrdup(pargs.r.ret_str); break; case oNoSecmemWarn: gcry_control (GCRYCTL_DISABLE_SECMEM_WARN); break; case oRequireSecmem: require_secmem=1; break; case oNoRequireSecmem: require_secmem=0; break; case oNoPermissionWarn: opt.no_perm_warn=1; break; case oNoMDCWarn: opt.no_mdc_warn=1; break; case oDisplayCharset: if( set_native_charset( pargs.r.ret_str ) ) log_error(_("`%s' is not a valid character set\n"), pargs.r.ret_str); break; case oNotDashEscaped: opt.not_dash_escaped = 1; break; case oEscapeFrom: opt.escape_from = 1; break; case oNoEscapeFrom: opt.escape_from = 0; break; case oLockOnce: opt.lock_once = 1; break; case oLockNever: dotlock_disable (); break; case oLockMultiple: #ifndef __riscos__ opt.lock_once = 0; #else /* __riscos__ */ riscos_not_implemented("lock-multiple"); #endif /* __riscos__ */ break; case oKeyServer: { keyserver_spec_t keyserver; keyserver = parse_keyserver_uri (pargs.r.ret_str,0, configname,configlineno); if (!keyserver) log_error (_("could not parse keyserver URL\n")); else { keyserver->next = opt.keyserver; opt.keyserver = keyserver; } } break; case oKeyServerOptions: if(!parse_keyserver_options(pargs.r.ret_str)) { if(configname) log_error(_("%s:%d: invalid keyserver options\n"), configname,configlineno); else log_error(_("invalid keyserver options\n")); } break; case oImportOptions: if(!parse_import_options(pargs.r.ret_str,&opt.import_options,1)) { if(configname) log_error(_("%s:%d: invalid import options\n"), configname,configlineno); else log_error(_("invalid import options\n")); } break; case oExportOptions: if(!parse_export_options(pargs.r.ret_str,&opt.export_options,1)) { if(configname) log_error(_("%s:%d: invalid export options\n"), configname,configlineno); else log_error(_("invalid export options\n")); } break; case oListOptions: if(!parse_list_options(pargs.r.ret_str)) { if(configname) log_error(_("%s:%d: invalid list options\n"), configname,configlineno); else log_error(_("invalid list options\n")); } break; case oVerifyOptions: { struct parse_options vopts[]= { {"show-photos",VERIFY_SHOW_PHOTOS,NULL, N_("display photo IDs during signature verification")}, {"show-policy-urls",VERIFY_SHOW_POLICY_URLS,NULL, N_("show policy URLs during signature verification")}, {"show-notations",VERIFY_SHOW_NOTATIONS,NULL, N_("show all notations during signature verification")}, {"show-std-notations",VERIFY_SHOW_STD_NOTATIONS,NULL, N_("show IETF standard notations during signature verification")}, {"show-standard-notations",VERIFY_SHOW_STD_NOTATIONS,NULL, NULL}, {"show-user-notations",VERIFY_SHOW_USER_NOTATIONS,NULL, N_("show user-supplied notations during signature verification")}, {"show-keyserver-urls",VERIFY_SHOW_KEYSERVER_URLS,NULL, N_("show preferred keyserver URLs during signature verification")}, {"show-uid-validity",VERIFY_SHOW_UID_VALIDITY,NULL, N_("show user ID validity during signature verification")}, {"show-unusable-uids",VERIFY_SHOW_UNUSABLE_UIDS,NULL, N_("show revoked and expired user IDs in signature verification")}, {"show-primary-uid-only",VERIFY_SHOW_PRIMARY_UID_ONLY,NULL, N_("show only the primary user ID in signature verification")}, {"pka-lookups",VERIFY_PKA_LOOKUPS,NULL, N_("validate signatures with PKA data")}, {"pka-trust-increase",VERIFY_PKA_TRUST_INCREASE,NULL, N_("elevate the trust of signatures with valid PKA data")}, {NULL,0,NULL,NULL} }; if(!parse_options(pargs.r.ret_str,&opt.verify_options,vopts,1)) { if(configname) log_error(_("%s:%d: invalid verify options\n"), configname,configlineno); else log_error(_("invalid verify options\n")); } } break; case oTempDir: opt.temp_dir=pargs.r.ret_str; break; case oExecPath: if(set_exec_path(pargs.r.ret_str)) log_error(_("unable to set exec-path to %s\n"),pargs.r.ret_str); else opt.exec_path_set=1; break; case oSetNotation: add_notation_data( pargs.r.ret_str, 0 ); add_notation_data( pargs.r.ret_str, 1 ); break; case oSigNotation: add_notation_data( pargs.r.ret_str, 0 ); break; case oCertNotation: add_notation_data( pargs.r.ret_str, 1 ); break; case oShowNotation: deprecated_warning(configname,configlineno,"--show-notation", "--list-options ","show-notations"); deprecated_warning(configname,configlineno,"--show-notation", "--verify-options ","show-notations"); opt.list_options|=LIST_SHOW_NOTATIONS; opt.verify_options|=VERIFY_SHOW_NOTATIONS; break; case oNoShowNotation: deprecated_warning(configname,configlineno,"--no-show-notation", "--list-options ","no-show-notations"); deprecated_warning(configname,configlineno,"--no-show-notation", "--verify-options ","no-show-notations"); opt.list_options&=~LIST_SHOW_NOTATIONS; opt.verify_options&=~VERIFY_SHOW_NOTATIONS; break; case oUtf8Strings: utf8_strings = 1; break; case oNoUtf8Strings: utf8_strings = 0; break; case oDisableCipherAlgo: { int algo = string_to_cipher_algo (pargs.r.ret_str); gcry_cipher_ctl (NULL, GCRYCTL_DISABLE_ALGO, &algo, sizeof algo); } break; case oDisablePubkeyAlgo: { int algo = gcry_pk_map_name (pargs.r.ret_str); gcry_pk_ctl (GCRYCTL_DISABLE_ALGO, &algo, sizeof algo); } break; case oNoSigCache: opt.no_sig_cache = 1; break; case oNoSigCreateCheck: opt.no_sig_create_check = 1; break; case oAllowNonSelfsignedUID: opt.allow_non_selfsigned_uid = 1; break; case oNoAllowNonSelfsignedUID: opt.allow_non_selfsigned_uid=0; break; case oAllowFreeformUID: opt.allow_freeform_uid = 1; break; case oNoAllowFreeformUID: opt.allow_freeform_uid = 0; break; case oNoLiteral: opt.no_literal = 1; break; case oSetFilesize: opt.set_filesize = pargs.r.ret_ulong; break; case oHonorHttpProxy: add_to_strlist(&opt.keyserver_options.other,"http-proxy"); deprecated_warning(configname,configlineno, "--honor-http-proxy", "--keyserver-options ","http-proxy"); break; case oFastListMode: opt.fast_list_mode = 1; break; case oFixedListMode: /* Dummy */ break; case oListOnly: opt.list_only=1; break; case oIgnoreTimeConflict: opt.ignore_time_conflict = 1; break; case oIgnoreValidFrom: opt.ignore_valid_from = 1; break; case oIgnoreCrcError: opt.ignore_crc_error = 1; break; case oIgnoreMDCError: opt.ignore_mdc_error = 1; break; case oNoRandomSeedFile: use_random_seed = 0; break; case oAutoKeyRetrieve: case oNoAutoKeyRetrieve: if(pargs.r_opt==oAutoKeyRetrieve) opt.keyserver_options.options|=KEYSERVER_AUTO_KEY_RETRIEVE; else opt.keyserver_options.options&=~KEYSERVER_AUTO_KEY_RETRIEVE; deprecated_warning(configname,configlineno, pargs.r_opt==oAutoKeyRetrieve?"--auto-key-retrieve": "--no-auto-key-retrieve","--keyserver-options ", pargs.r_opt==oAutoKeyRetrieve?"auto-key-retrieve": "no-auto-key-retrieve"); break; case oShowSessionKey: opt.show_session_key = 1; break; case oOverrideSessionKey: opt.override_session_key = pargs.r.ret_str; break; case oMergeOnly: deprecated_warning(configname,configlineno,"--merge-only", "--import-options ","merge-only"); opt.import_options|=IMPORT_MERGE_ONLY; break; case oAllowSecretKeyImport: /* obsolete */ break; case oTryAllSecrets: opt.try_all_secrets = 1; break; case oTrustedKey: register_trusted_key( pargs.r.ret_str ); break; case oEnableSpecialFilenames: iobuf_enable_special_filenames (1); break; case oNoExpensiveTrustChecks: opt.no_expensive_trust_checks=1; break; case oAutoCheckTrustDB: opt.no_auto_check_trustdb=0; break; case oNoAutoCheckTrustDB: opt.no_auto_check_trustdb=1; break; case oPreservePermissions: opt.preserve_permissions=1; break; case oDefaultPreferenceList: opt.def_preference_list = pargs.r.ret_str; break; case oDefaultKeyserverURL: { keyserver_spec_t keyserver; keyserver = parse_keyserver_uri (pargs.r.ret_str,1, configname,configlineno); if (!keyserver) log_error (_("could not parse keyserver URL\n")); else free_keyserver_spec (keyserver); opt.def_keyserver_url = pargs.r.ret_str; } break; case oPersonalCipherPreferences: pers_cipher_list=pargs.r.ret_str; break; case oPersonalDigestPreferences: pers_digest_list=pargs.r.ret_str; break; case oPersonalCompressPreferences: pers_compress_list=pargs.r.ret_str; break; case oAgentProgram: opt.agent_program = pargs.r.ret_str; break; case oDisplay: set_opt_session_env ("DISPLAY", pargs.r.ret_str); break; case oTTYname: set_opt_session_env ("GPG_TTY", pargs.r.ret_str); break; case oTTYtype: set_opt_session_env ("TERM", pargs.r.ret_str); break; case oXauthority: set_opt_session_env ("XAUTHORITY", pargs.r.ret_str); break; case oLCctype: opt.lc_ctype = pargs.r.ret_str; break; case oLCmessages: opt.lc_messages = pargs.r.ret_str; break; case oGroup: add_group(pargs.r.ret_str); break; case oUnGroup: rm_group(pargs.r.ret_str); break; case oNoGroups: while(opt.grouplist) { struct groupitem *iter=opt.grouplist; free_strlist(iter->values); opt.grouplist=opt.grouplist->next; xfree(iter); } break; case oStrict: case oNoStrict: /* Not used */ break; case oMangleDosFilenames: opt.mangle_dos_filenames = 1; break; case oNoMangleDosFilenames: opt.mangle_dos_filenames = 0; break; case oEnableProgressFilter: opt.enable_progress_filter = 1; break; case oMultifile: multifile=1; break; case oKeyidFormat: if(ascii_strcasecmp(pargs.r.ret_str,"short")==0) opt.keyid_format=KF_SHORT; else if(ascii_strcasecmp(pargs.r.ret_str,"long")==0) opt.keyid_format=KF_LONG; else if(ascii_strcasecmp(pargs.r.ret_str,"0xshort")==0) opt.keyid_format=KF_0xSHORT; else if(ascii_strcasecmp(pargs.r.ret_str,"0xlong")==0) opt.keyid_format=KF_0xLONG; else log_error("unknown keyid-format `%s'\n",pargs.r.ret_str); break; case oExitOnStatusWriteError: opt.exit_on_status_write_error = 1; break; case oLimitCardInsertTries: opt.limit_card_insert_tries = pargs.r.ret_int; break; case oRequireCrossCert: opt.flags.require_cross_cert=1; break; case oNoRequireCrossCert: opt.flags.require_cross_cert=0; break; case oAutoKeyLocate: if(!parse_auto_key_locate(pargs.r.ret_str)) { if(configname) log_error(_("%s:%d: invalid auto-key-locate list\n"), configname,configlineno); else log_error(_("invalid auto-key-locate list\n")); } break; case oNoAutoKeyLocate: release_akl(); break; case oEnableDSA2: opt.flags.dsa2=1; break; case oDisableDSA2: opt.flags.dsa2=0; break; case oAllowMultisigVerification: case oAllowMultipleMessages: opt.flags.allow_multiple_messages=1; break; case oNoAllowMultipleMessages: opt.flags.allow_multiple_messages=0; break; case oFakedSystemTime: { time_t faked_time = isotime2epoch (pargs.r.ret_str); if (faked_time == (time_t)(-1)) faked_time = (time_t)strtoul (pargs.r.ret_str, NULL, 10); gnupg_set_time (faked_time, 0); } break; case oNoop: break; default: pargs.err = configfp? ARGPARSE_PRINT_WARNING:ARGPARSE_PRINT_ERROR; break; } } if (configfp) { fclose( configfp ); configfp = NULL; /* Remember the first config file name. */ if (!save_configname) save_configname = configname; else xfree(configname); configname = NULL; goto next_pass; } xfree(configname); configname = NULL; if (log_get_errorcount (0)) g10_exit(2); /* The command --gpgconf-list is pretty simple and may be called directly after the option parsing. */ if (cmd == aGPGConfList) { gpgconf_list (save_configname ? save_configname : default_configname); g10_exit (0); } xfree (save_configname); xfree (default_configname); if( nogreeting ) greeting = 0; if( greeting ) { es_fprintf (es_stderr, "%s %s; %s\n", strusage(11), strusage(13), strusage(14) ); es_fprintf (es_stderr, "%s\n", strusage(15) ); } #ifdef IS_DEVELOPMENT_VERSION if (!opt.batch) { const char *s; if((s=strusage(25))) log_info("%s\n",s); if((s=strusage(26))) log_info("%s\n",s); if((s=strusage(27))) log_info("%s\n",s); } #endif /* FIXME: We should use logging to a file only in server mode; however we have not yet implemetyed that. Thus we try to get away with --batch as indication for logging to file required. */ if (logfile && opt.batch) { log_set_file (logfile); log_set_prefix (NULL, 1|2|4); } /* Older Libgcrypts fail with an assertion during DSA key generation. Better disable DSA2 entirely. */ if (opt.flags.dsa2 && !gcry_check_version ("1.4.0") ) { log_info ("WARNING: " "DSA2 is only available with Libgcrypt 1.4 and later\n"); opt.flags.dsa2 = 0; } if (opt.verbose > 2) log_info ("using character set `%s'\n", get_native_charset ()); if( may_coredump && !opt.quiet ) log_info(_("WARNING: program may create a core file!\n")); if (eyes_only) { if (opt.set_filename) log_info(_("WARNING: %s overrides %s\n"), "--for-your-eyes-only","--set-filename"); opt.set_filename="_CONSOLE"; } if (opt.no_literal) { log_info(_("NOTE: %s is not for normal use!\n"), "--no-literal"); if (opt.textmode) log_error(_("%s not allowed with %s!\n"), "--textmode", "--no-literal" ); if (opt.set_filename) log_error(_("%s makes no sense with %s!\n"), eyes_only?"--for-your-eyes-only":"--set-filename", "--no-literal" ); } if (opt.set_filesize) log_info(_("NOTE: %s is not for normal use!\n"), "--set-filesize"); if( opt.batch ) tty_batchmode( 1 ); if (gnupg_faked_time_p ()) { gnupg_isotime_t tbuf; log_info (_("WARNING: running with faked system time: ")); gnupg_get_isotime (tbuf); dump_isotime (tbuf); log_printf ("\n"); } gcry_control (GCRYCTL_RESUME_SECMEM_WARN); if(require_secmem && !got_secmem) { log_info(_("will not run with insecure memory due to %s\n"), "--require-secmem"); g10_exit(2); } set_debug (debug_level); /* Do these after the switch(), so they can override settings. */ if(PGP2) { int unusable=0; if(cmd==aSign && !detached_sig) { log_info(_("you can only make detached or clear signatures " "while in --pgp2 mode\n")); unusable=1; } else if(cmd==aSignEncr || cmd==aSignSym) { log_info(_("you can't sign and encrypt at the " "same time while in --pgp2 mode\n")); unusable=1; } else if(argc==0 && (cmd==aSign || cmd==aEncr || cmd==aSym)) { log_info(_("you must use files (and not a pipe) when " "working with --pgp2 enabled.\n")); unusable=1; } else if(cmd==aEncr || cmd==aSym) { /* Everything else should work without IDEA (except using a secret key encrypted with IDEA and setting an IDEA preference, but those have their own error messages). */ if (openpgp_cipher_test_algo(CIPHER_ALGO_IDEA)) { log_info(_("encrypting a message in --pgp2 mode requires " "the IDEA cipher\n")); idea_cipher_warn(1); unusable=1; } else if(cmd==aSym) { /* This only sets IDEA for symmetric encryption since it is set via select_algo_from_prefs for pk encryption. */ xfree(def_cipher_string); def_cipher_string = xstrdup("idea"); } /* PGP2 can't handle the output from the textmode filter, so we disable it for anything that could create a literal packet (only encryption and symmetric encryption, since we disable signing above). */ if(!unusable) opt.textmode=0; } if(unusable) compliance_failure(); else { opt.force_v4_certs = 0; opt.escape_from = 1; opt.force_v3_sigs = 1; opt.pgp2_workarounds = 1; opt.ask_sig_expire = 0; opt.ask_cert_expire = 0; xfree(def_digest_string); def_digest_string = xstrdup("md5"); xfree(s2k_digest_string); s2k_digest_string = xstrdup("md5"); opt.compress_algo = COMPRESS_ALGO_ZIP; } } else if(PGP6) { opt.disable_mdc=1; opt.escape_from=1; opt.force_v3_sigs=1; opt.ask_sig_expire=0; } else if(PGP7) { opt.escape_from=1; opt.force_v3_sigs=1; opt.ask_sig_expire=0; } else if(PGP8) { opt.escape_from=1; } if( def_cipher_string ) { opt.def_cipher_algo = string_to_cipher_algo (def_cipher_string); if(opt.def_cipher_algo==0 && (ascii_strcasecmp(def_cipher_string,"idea")==0 || ascii_strcasecmp(def_cipher_string,"s1")==0)) idea_cipher_warn(1); xfree(def_cipher_string); def_cipher_string = NULL; if ( openpgp_cipher_test_algo (opt.def_cipher_algo) ) log_error(_("selected cipher algorithm is invalid\n")); } if( def_digest_string ) { opt.def_digest_algo = string_to_digest_algo (def_digest_string); xfree(def_digest_string); def_digest_string = NULL; if ( openpgp_md_test_algo (opt.def_digest_algo) ) log_error(_("selected digest algorithm is invalid\n")); } if( compress_algo_string ) { opt.compress_algo = string_to_compress_algo(compress_algo_string); xfree(compress_algo_string); compress_algo_string = NULL; if( check_compress_algo(opt.compress_algo) ) log_error(_("selected compression algorithm is invalid\n")); } if( cert_digest_string ) { opt.cert_digest_algo = string_to_digest_algo (cert_digest_string); xfree(cert_digest_string); cert_digest_string = NULL; if (openpgp_md_test_algo(opt.cert_digest_algo)) log_error(_("selected certification digest algorithm is invalid\n")); } if( s2k_cipher_string ) { opt.s2k_cipher_algo = string_to_cipher_algo (s2k_cipher_string); xfree(s2k_cipher_string); s2k_cipher_string = NULL; if (openpgp_cipher_test_algo (opt.s2k_cipher_algo)) log_error(_("selected cipher algorithm is invalid\n")); } if( s2k_digest_string ) { opt.s2k_digest_algo = string_to_digest_algo (s2k_digest_string); xfree(s2k_digest_string); s2k_digest_string = NULL; if (openpgp_md_test_algo(opt.s2k_digest_algo)) log_error(_("selected digest algorithm is invalid\n")); } if( opt.completes_needed < 1 ) log_error(_("completes-needed must be greater than 0\n")); if( opt.marginals_needed < 2 ) log_error(_("marginals-needed must be greater than 1\n")); if( opt.max_cert_depth < 1 || opt.max_cert_depth > 255 ) log_error(_("max-cert-depth must be in the range from 1 to 255\n")); if(opt.def_cert_level<0 || opt.def_cert_level>3) log_error(_("invalid default-cert-level; must be 0, 1, 2, or 3\n")); if( opt.min_cert_level < 1 || opt.min_cert_level > 3 ) log_error(_("invalid min-cert-level; must be 1, 2, or 3\n")); switch( opt.s2k_mode ) { case 0: log_info(_("NOTE: simple S2K mode (0) is strongly discouraged\n")); break; case 1: case 3: break; default: log_error(_("invalid S2K mode; must be 0, 1 or 3\n")); } /* This isn't actually needed, but does serve to error out if the string is invalid. */ if(opt.def_preference_list && keygen_set_std_prefs(opt.def_preference_list,0)) log_error(_("invalid default preferences\n")); if(pers_cipher_list && keygen_set_std_prefs(pers_cipher_list,PREFTYPE_SYM)) log_error(_("invalid personal cipher preferences\n")); if(pers_digest_list && keygen_set_std_prefs(pers_digest_list,PREFTYPE_HASH)) log_error(_("invalid personal digest preferences\n")); if(pers_compress_list && keygen_set_std_prefs(pers_compress_list,PREFTYPE_ZIP)) log_error(_("invalid personal compress preferences\n")); /* We don't support all possible commands with multifile yet */ if(multifile) { char *cmdname; switch(cmd) { case aSign: cmdname="--sign"; break; case aClearsign: cmdname="--clearsign"; break; case aDetachedSign: cmdname="--detach-sign"; break; case aSym: cmdname="--symmetric"; break; case aEncrSym: cmdname="--symmetric --encrypt"; break; case aStore: cmdname="--store"; break; default: cmdname=NULL; break; } if(cmdname) log_error(_("%s does not yet work with %s\n"),cmdname,"--multifile"); } if( log_get_errorcount(0) ) g10_exit(2); if(opt.compress_level==0) opt.compress_algo=COMPRESS_ALGO_NONE; /* Check our chosen algorithms against the list of legal algorithms. */ if(!GNUPG) { const char *badalg=NULL; preftype_t badtype=PREFTYPE_NONE; if(opt.def_cipher_algo && !algo_available(PREFTYPE_SYM,opt.def_cipher_algo,NULL)) { badalg = openpgp_cipher_algo_name (opt.def_cipher_algo); badtype = PREFTYPE_SYM; } else if(opt.def_digest_algo && !algo_available(PREFTYPE_HASH,opt.def_digest_algo,NULL)) { badalg = gcry_md_algo_name (opt.def_digest_algo); badtype = PREFTYPE_HASH; } else if(opt.cert_digest_algo && !algo_available(PREFTYPE_HASH,opt.cert_digest_algo,NULL)) { badalg = gcry_md_algo_name (opt.cert_digest_algo); badtype = PREFTYPE_HASH; } else if(opt.compress_algo!=-1 && !algo_available(PREFTYPE_ZIP,opt.compress_algo,NULL)) { badalg = compress_algo_to_string(opt.compress_algo); badtype = PREFTYPE_ZIP; } if(badalg) { switch(badtype) { case PREFTYPE_SYM: log_info(_("you may not use cipher algorithm `%s'" " while in %s mode\n"), badalg,compliance_option_string()); break; case PREFTYPE_HASH: log_info(_("you may not use digest algorithm `%s'" " while in %s mode\n"), badalg,compliance_option_string()); break; case PREFTYPE_ZIP: log_info(_("you may not use compression algorithm `%s'" " while in %s mode\n"), badalg,compliance_option_string()); break; default: BUG(); } compliance_failure(); } } /* Set the random seed file. */ if( use_random_seed ) { char *p = make_filename(opt.homedir, "random_seed", NULL ); gcry_control (GCRYCTL_SET_RANDOM_SEED_FILE, p); if (!access (p, F_OK)) register_secured_file (p); xfree(p); } /* If there is no command but the --fingerprint is given, default to the --list-keys command. */ if (!cmd && fpr_maybe_cmd) { set_cmd (&cmd, aListKeys); } if( opt.verbose > 1 ) set_packet_list_mode(1); /* Add the keyrings, but not for some special commands. Also avoid adding the secret keyring for a couple of commands to avoid unneeded access in case the secrings are stored on a floppy. We always need to add the keyrings if we are running under SELinux, this is so that the rings are added to the list of secured files. */ if( ALWAYS_ADD_KEYRINGS || (cmd != aDeArmor && cmd != aEnArmor && cmd != aGPGConfTest) ) { if (!nrings || default_keyring) /* Add default ring. */ keydb_add_resource ("pubring" EXTSEP_S "gpg", 4); for (sl = nrings; sl; sl = sl->next ) keydb_add_resource (sl->d, sl->flags); } FREE_STRLIST(nrings); if (cmd == aGPGConfTest) g10_exit(0); if( pwfd != -1 ) /* Read the passphrase now. */ read_passphrase_from_fd( pwfd ); fname = argc? *argv : NULL; if(fname && utf8_strings) opt.flags.utf8_filename=1; ctrl = xcalloc (1, sizeof *ctrl); gpg_init_default_ctrl (ctrl); switch( cmd ) { case aPrimegen: case aPrintMD: case aPrintMDs: case aGenRandom: case aDeArmor: case aEnArmor: break; case aFixTrustDB: case aExportOwnerTrust: rc = setup_trustdb( 0, trustdb_name ); break; case aListTrustDB: rc = setup_trustdb( argc? 1:0, trustdb_name ); break; default: rc = setup_trustdb(1, trustdb_name ); break; } if( rc ) log_error(_("failed to initialize the TrustDB: %s\n"), g10_errstr(rc)); switch (cmd) { case aStore: case aSym: case aSign: case aSignSym: case aClearsign: if (!opt.quiet && any_explicit_recipient) log_info (_("WARNING: recipients (-r) given " "without using public key encryption\n")); break; default: break; } switch( cmd ) { case aServer: gpg_server (ctrl); break; case aStore: /* only store the file */ if( argc > 1 ) wrong_args(_("--store [filename]")); if( (rc = encrypt_store(fname)) ) log_error ("storing `%s' failed: %s\n", print_fname_stdin(fname),g10_errstr(rc) ); break; case aSym: /* encrypt the given file only with the symmetric cipher */ if( argc > 1 ) wrong_args(_("--symmetric [filename]")); if( (rc = encrypt_symmetric(fname)) ) log_error (_("symmetric encryption of `%s' failed: %s\n"), print_fname_stdin(fname),g10_errstr(rc) ); break; case aEncr: /* encrypt the given file */ if(multifile) encrypt_crypt_files (ctrl, argc, argv, remusr); else { if( argc > 1 ) wrong_args(_("--encrypt [filename]")); if( (rc = encrypt_crypt (ctrl, -1, fname, remusr, 0, NULL, -1)) ) log_error("%s: encryption failed: %s\n", print_fname_stdin(fname), g10_errstr(rc) ); } break; case aEncrSym: /* This works with PGP 8 in the sense that it acts just like a symmetric message. It doesn't work at all with 2 or 6. It might work with 7, but alas, I don't have a copy to test with right now. */ if( argc > 1 ) wrong_args(_("--symmetric --encrypt [filename]")); else if(opt.s2k_mode==0) log_error(_("you cannot use --symmetric --encrypt" " with --s2k-mode 0\n")); else if(PGP2 || PGP6 || PGP7 || RFC1991) log_error(_("you cannot use --symmetric --encrypt" " while in %s mode\n"),compliance_option_string()); else { if( (rc = encrypt_crypt (ctrl, -1, fname, remusr, 1, NULL, -1)) ) log_error("%s: encryption failed: %s\n", print_fname_stdin(fname), g10_errstr(rc) ); } break; case aSign: /* sign the given file */ sl = NULL; if( detached_sig ) { /* sign all files */ for( ; argc; argc--, argv++ ) add_to_strlist( &sl, *argv ); } else { if( argc > 1 ) wrong_args(_("--sign [filename]")); if( argc ) { sl = xmalloc_clear( sizeof *sl + strlen(fname)); strcpy(sl->d, fname); } } if( (rc = sign_file (ctrl, sl, detached_sig, locusr, 0, NULL, NULL)) ) log_error("signing failed: %s\n", g10_errstr(rc) ); free_strlist(sl); break; case aSignEncr: /* sign and encrypt the given file */ if( argc > 1 ) wrong_args(_("--sign --encrypt [filename]")); if( argc ) { sl = xmalloc_clear( sizeof *sl + strlen(fname)); strcpy(sl->d, fname); } else sl = NULL; if ((rc = sign_file (ctrl, sl, detached_sig, locusr, 1, remusr, NULL))) log_error("%s: sign+encrypt failed: %s\n", print_fname_stdin(fname), g10_errstr(rc) ); free_strlist(sl); break; case aSignEncrSym: /* sign and encrypt the given file */ if( argc > 1 ) wrong_args(_("--symmetric --sign --encrypt [filename]")); else if(opt.s2k_mode==0) log_error(_("you cannot use --symmetric --sign --encrypt" " with --s2k-mode 0\n")); else if(PGP2 || PGP6 || PGP7 || RFC1991) log_error(_("you cannot use --symmetric --sign --encrypt" " while in %s mode\n"),compliance_option_string()); else { if( argc ) { sl = xmalloc_clear( sizeof *sl + strlen(fname)); strcpy(sl->d, fname); } else sl = NULL; if ((rc = sign_file (ctrl, sl, detached_sig, locusr, 2, remusr, NULL))) log_error("%s: symmetric+sign+encrypt failed: %s\n", print_fname_stdin(fname), g10_errstr(rc) ); free_strlist(sl); } break; case aSignSym: /* sign and conventionally encrypt the given file */ if (argc > 1) wrong_args(_("--sign --symmetric [filename]")); rc = sign_symencrypt_file (fname, locusr); if (rc) log_error("%s: sign+symmetric failed: %s\n", print_fname_stdin(fname), g10_errstr(rc) ); break; case aClearsign: /* make a clearsig */ if( argc > 1 ) wrong_args(_("--clearsign [filename]")); if( (rc = clearsign_file(fname, locusr, NULL)) ) log_error("%s: clearsign failed: %s\n", print_fname_stdin(fname), g10_errstr(rc) ); break; case aVerify: if (multifile) { if ((rc = verify_files (ctrl, argc, argv))) log_error("verify files failed: %s\n", g10_errstr(rc) ); } else { if ((rc = verify_signatures (ctrl, argc, argv))) log_error("verify signatures failed: %s\n", g10_errstr(rc) ); } break; case aDecrypt: if (multifile) decrypt_messages (ctrl, argc, argv); else { if( argc > 1 ) wrong_args(_("--decrypt [filename]")); if( (rc = decrypt_message (ctrl, fname) )) log_error("decrypt_message failed: %s\n", g10_errstr(rc) ); } break; case aSignKey: if( argc != 1 ) wrong_args(_("--sign-key user-id")); /* fall through */ case aLSignKey: if( argc != 1 ) wrong_args(_("--lsign-key user-id")); /* fall through */ sl=NULL; if(cmd==aSignKey) append_to_strlist(&sl,"sign"); else if(cmd==aLSignKey) append_to_strlist(&sl,"lsign"); else BUG(); append_to_strlist( &sl, "save" ); username = make_username( fname ); keyedit_menu (ctrl, username, locusr, sl, 0, 0 ); xfree(username); free_strlist(sl); break; case aEditKey: /* Edit a key signature */ if( !argc ) wrong_args(_("--edit-key user-id [commands]")); username = make_username( fname ); if( argc > 1 ) { sl = NULL; for( argc--, argv++ ; argc; argc--, argv++ ) append_to_strlist( &sl, *argv ); keyedit_menu (ctrl, username, locusr, sl, 0, 1 ); free_strlist(sl); } else keyedit_menu (ctrl, username, locusr, NULL, 0, 1 ); xfree(username); break; case aPasswd: if (argc != 1) wrong_args (_("--passwd ")); else { username = make_username (fname); keyedit_passwd (ctrl, username); xfree (username); } break; case aDeleteKeys: case aDeleteSecretKeys: case aDeleteSecretAndPublicKeys: sl = NULL; /* I'm adding these in reverse order as add_to_strlist2 reverses them again, and it's easier to understand in the proper order :) */ for( ; argc; argc-- ) add_to_strlist2( &sl, argv[argc-1], utf8_strings ); delete_keys(sl,cmd==aDeleteSecretKeys,cmd==aDeleteSecretAndPublicKeys); free_strlist(sl); break; case aCheckKeys: opt.check_sigs = 1; case aListSigs: opt.list_sigs = 1; case aListKeys: sl = NULL; for( ; argc; argc--, argv++ ) add_to_strlist2( &sl, *argv, utf8_strings ); public_key_list (ctrl, sl, 0); free_strlist(sl); break; case aListSecretKeys: sl = NULL; for( ; argc; argc--, argv++ ) add_to_strlist2( &sl, *argv, utf8_strings ); secret_key_list (ctrl, sl); free_strlist(sl); break; case aLocateKeys: sl = NULL; for (; argc; argc--, argv++) add_to_strlist2( &sl, *argv, utf8_strings ); public_key_list (ctrl, sl, 1); free_strlist (sl); break; case aKeygen: /* generate a key */ if( opt.batch ) { if( argc > 1 ) wrong_args("--gen-key [parameterfile]"); - generate_keypair (argc? *argv : NULL, NULL, 0); + generate_keypair (ctrl, argc? *argv : NULL, NULL, 0); } else { if( argc ) wrong_args("--gen-key"); - generate_keypair (NULL, NULL, 0); + generate_keypair (ctrl, NULL, NULL, 0); } break; case aFastImport: opt.import_options |= IMPORT_FAST; case aImport: import_keys (ctrl, argc? argv:NULL, argc, NULL, opt.import_options); break; /* TODO: There are a number of command that use this same "make strlist, call function, report error, free strlist" pattern. Join them together here and avoid all that duplicated code. */ case aExport: case aSendKeys: case aRecvKeys: sl = NULL; for( ; argc; argc--, argv++ ) append_to_strlist2( &sl, *argv, utf8_strings ); if( cmd == aSendKeys ) rc = keyserver_export (ctrl, sl ); else if( cmd == aRecvKeys ) rc = keyserver_import (ctrl, sl ); else rc = export_pubkeys (ctrl, sl, opt.export_options); if(rc) { if(cmd==aSendKeys) log_error(_("keyserver send failed: %s\n"),g10_errstr(rc)); else if(cmd==aRecvKeys) log_error(_("keyserver receive failed: %s\n"),g10_errstr(rc)); else log_error(_("key export failed: %s\n"),g10_errstr(rc)); } free_strlist(sl); break; case aSearchKeys: sl = NULL; for (; argc; argc--, argv++) append_to_strlist2 (&sl, *argv, utf8_strings); rc = keyserver_search (ctrl, sl); if (rc) log_error (_("keyserver search failed: %s\n"), gpg_strerror (rc)); free_strlist (sl); break; case aRefreshKeys: sl = NULL; for( ; argc; argc--, argv++ ) append_to_strlist2( &sl, *argv, utf8_strings ); rc = keyserver_refresh (ctrl, sl); if(rc) log_error(_("keyserver refresh failed: %s\n"),g10_errstr(rc)); free_strlist(sl); break; case aFetchKeys: sl = NULL; for( ; argc; argc--, argv++ ) append_to_strlist2( &sl, *argv, utf8_strings ); rc = keyserver_fetch (ctrl, sl); if(rc) log_error("key fetch failed: %s\n",g10_errstr(rc)); free_strlist(sl); break; case aExportSecret: sl = NULL; for( ; argc; argc--, argv++ ) add_to_strlist2( &sl, *argv, utf8_strings ); export_seckeys (ctrl, sl); free_strlist(sl); break; case aExportSecretSub: sl = NULL; for( ; argc; argc--, argv++ ) add_to_strlist2( &sl, *argv, utf8_strings ); export_secsubkeys (ctrl, sl); free_strlist(sl); break; case aGenRevoke: if( argc != 1 ) wrong_args("--gen-revoke user-id"); username = make_username(*argv); gen_revoke( username ); xfree( username ); break; case aDesigRevoke: if( argc != 1 ) wrong_args("--desig-revoke user-id"); username = make_username(*argv); gen_desig_revoke( username, locusr ); xfree( username ); break; case aDeArmor: if( argc > 1 ) wrong_args("--dearmor [file]"); rc = dearmor_file( argc? *argv: NULL ); if( rc ) log_error(_("dearmoring failed: %s\n"), g10_errstr(rc)); break; case aEnArmor: if( argc > 1 ) wrong_args("--enarmor [file]"); rc = enarmor_file( argc? *argv: NULL ); if( rc ) log_error(_("enarmoring failed: %s\n"), g10_errstr(rc)); break; case aPrimegen: #if 0 /*FIXME*/ { int mode = argc < 2 ? 0 : atoi(*argv); if( mode == 1 && argc == 2 ) { mpi_print (es_stdout, generate_public_prime( atoi(argv[1]) ), 1); } else if( mode == 2 && argc == 3 ) { mpi_print (es_stdout, generate_elg_prime( 0, atoi(argv[1]), atoi(argv[2]), NULL,NULL ), 1); } else if( mode == 3 && argc == 3 ) { MPI *factors; mpi_print (es_stdout, generate_elg_prime( 1, atoi(argv[1]), atoi(argv[2]), NULL,&factors ), 1); putchar('\n'); mpi_print (es_stdout, factors[0], 1 ); /* print q */ } else if( mode == 4 && argc == 3 ) { MPI g = mpi_alloc(1); mpi_print (es_stdout, generate_elg_prime( 0, atoi(argv[1]), atoi(argv[2]), g, NULL ), 1); putchar('\n'); mpi_print (es_stdout, g, 1 ); mpi_free (g); } else wrong_args("--gen-prime mode bits [qbits] "); putchar('\n'); } #endif wrong_args("--gen-prime not yet supported "); break; case aGenRandom: { int level = argc ? atoi(*argv):0; int count = argc > 1 ? atoi(argv[1]): 0; int endless = !count; if( argc < 1 || argc > 2 || level < 0 || level > 2 || count < 0 ) wrong_args("--gen-random 0|1|2 [count]"); while( endless || count ) { byte *p; /* Wee need a multiple of 3, so that in case of armored output we get a correct string. No linefolding is done, as it is best to levae this to other tools */ size_t n = !endless && count < 99? count : 99; p = gcry_random_bytes (n, level); #ifdef HAVE_DOSISH_SYSTEM setmode ( fileno(stdout), O_BINARY ); #endif if (opt.armor) { char *tmp = make_radix64_string (p, n); fputs (tmp, stdout); xfree (tmp); if (n%3 == 1) putchar ('='); if (n%3) putchar ('='); } else { fwrite( p, n, 1, stdout ); } xfree(p); if( !endless ) count -= n; } if (opt.armor) putchar ('\n'); } break; case aPrintMD: if( argc < 1) wrong_args("--print-md algo [files]"); { int all_algos = (**argv=='*' && !(*argv)[1]); int algo = all_algos? 0 : gcry_md_map_name (*argv); if( !algo && !all_algos ) log_error(_("invalid hash algorithm `%s'\n"), *argv ); else { argc--; argv++; if( !argc ) print_mds(NULL, algo); else { for(; argc; argc--, argv++ ) print_mds(*argv, algo); } } } break; case aPrintMDs: /* old option */ if( !argc ) print_mds(NULL,0); else { for(; argc; argc--, argv++ ) print_mds(*argv,0); } break; case aListTrustDB: if( !argc ) list_trustdb(NULL); else { for( ; argc; argc--, argv++ ) list_trustdb( *argv ); } break; case aUpdateTrustDB: if( argc ) wrong_args("--update-trustdb"); update_trustdb(); break; case aCheckTrustDB: /* Old versions allowed for arguments - ignore them */ check_trustdb(); break; case aFixTrustDB: how_to_fix_the_trustdb (); break; case aListTrustPath: if( !argc ) wrong_args("--list-trust-path "); for( ; argc; argc--, argv++ ) { username = make_username( *argv ); list_trust_path( username ); xfree(username); } break; case aExportOwnerTrust: if( argc ) wrong_args("--export-ownertrust"); export_ownertrust(); break; case aImportOwnerTrust: if( argc > 1 ) wrong_args("--import-ownertrust [file]"); import_ownertrust( argc? *argv:NULL ); break; case aRebuildKeydbCaches: if (argc) wrong_args ("--rebuild-keydb-caches"); keydb_rebuild_caches (1); break; #ifdef ENABLE_CARD_SUPPORT case aCardStatus: if (argc) wrong_args ("--card-status"); card_status (es_stdout, NULL, 0); break; case aCardEdit: if (argc) { sl = NULL; for (argc--, argv++ ; argc; argc--, argv++) append_to_strlist (&sl, *argv); card_edit (ctrl, sl); free_strlist (sl); } else card_edit (ctrl, NULL); break; case aChangePIN: if (!argc) change_pin (0,1); else if (argc == 1) change_pin (atoi (*argv),1); else wrong_args ("--change-pin [no]"); break; #endif /* ENABLE_CARD_SUPPORT*/ case aListConfig: { char *str=collapse_args(argc,argv); list_config(str); xfree(str); } break; case aListPackets: opt.list_packets=2; default: if( argc > 1 ) wrong_args(_("[filename]")); /* Issue some output for the unix newbie */ if (!fname && !opt.outfile && gnupg_isatty (fileno (stdin)) && gnupg_isatty (fileno (stdout)) && gnupg_isatty (fileno (stderr))) log_info(_("Go ahead and type your message ...\n")); a = iobuf_open(fname); if (a && is_secured_file (iobuf_get_fd (a))) { iobuf_close (a); a = NULL; gpg_err_set_errno (EPERM); } if( !a ) log_error(_("can't open `%s'\n"), print_fname_stdin(fname)); else { if( !opt.no_armor ) { if( use_armor_filter( a ) ) { afx = new_armor_context (); push_armor_filter (afx, a); } } if( cmd == aListPackets ) { set_packet_list_mode(1); opt.list_packets=1; } rc = proc_packets (ctrl, NULL, a ); if( rc ) log_error("processing message failed: %s\n", g10_errstr(rc) ); iobuf_close(a); } break; } /* cleanup */ gpg_deinit_default_ctrl (ctrl); xfree (ctrl); release_armor_context (afx); FREE_STRLIST(remusr); FREE_STRLIST(locusr); g10_exit(0); return 8; /*NEVER REACHED*/ } /* Note: This function is used by signal handlers!. */ static void emergency_cleanup (void) { gcry_control (GCRYCTL_TERM_SECMEM ); } void g10_exit( int rc ) { gcry_control (GCRYCTL_UPDATE_RANDOM_SEED_FILE); if ( (opt.debug & DBG_MEMSTAT_VALUE) ) { gcry_control (GCRYCTL_DUMP_MEMORY_STATS); gcry_control (GCRYCTL_DUMP_RANDOM_STATS); } if (opt.debug) gcry_control (GCRYCTL_DUMP_SECMEM_STATS ); emergency_cleanup (); rc = rc? rc : log_get_errorcount(0)? 2 : g10_errors_seen? 1 : 0; exit (rc); } /* Pretty-print hex hashes. This assumes at least an 80-character display, but there are a few other similar assumptions in the display code. */ static void print_hex (gcry_md_hd_t md, int algo, const char *fname) { int i,n,count,indent=0; const byte *p; if (fname) indent = es_printf("%s: ",fname); if (indent>40) { printf("\n"); indent=0; } if (algo==DIGEST_ALGO_RMD160) indent += es_printf("RMD160 = "); else if (algo>0) indent += es_printf("%6s = ", gcry_md_algo_name (algo)); else algo = abs(algo); count = indent; p = gcry_md_read (md, algo); n = gcry_md_get_algo_dlen (algo); count += es_printf ("%02X",*p++); for(i=1;i79) { es_printf ("\n%*s",indent," "); count = indent; } else count += es_printf(" "); if (!(i%8)) count += es_printf(" "); } else if (n==20) { if(!(i%2)) { if(count+4>79) { es_printf ("\n%*s",indent," "); count=indent; } else count += es_printf(" "); } if (!(i%10)) count += es_printf(" "); } else { if(!(i%4)) { if (count+8>79) { es_printf ("\n%*s",indent," "); count=indent; } else count += es_printf(" "); } } count += es_printf("%02X",*p); } es_printf ("\n"); } static void print_hashline( gcry_md_hd_t md, int algo, const char *fname ) { int i, n; const byte *p; if ( fname ) { for (p = fname; *p; p++ ) { if ( *p <= 32 || *p > 127 || *p == ':' || *p == '%' ) es_printf ("%%%02X", *p ); else es_putc (*p, es_stdout); } } es_putc (':', es_stdout); es_printf ("%d:", algo); p = gcry_md_read (md, algo); n = gcry_md_get_algo_dlen (algo); for(i=0; i < n ; i++, p++ ) es_printf ("%02X", *p); es_fputs (":\n", es_stdout); } static void print_mds( const char *fname, int algo ) { FILE *fp; char buf[1024]; size_t n; gcry_md_hd_t md; if( !fname ) { fp = stdin; #ifdef HAVE_DOSISH_SYSTEM setmode ( fileno(fp) , O_BINARY ); #endif } else { fp = fopen( fname, "rb" ); if (fp && is_secured_file (fileno (fp))) { fclose (fp); fp = NULL; gpg_err_set_errno (EPERM); } } if( !fp ) { log_error("%s: %s\n", fname?fname:"[stdin]", strerror(errno) ); return; } gcry_md_open (&md, 0, 0); if( algo ) gcry_md_enable (md, algo); else { gcry_md_enable (md, GCRY_MD_MD5); gcry_md_enable (md, GCRY_MD_SHA1); gcry_md_enable (md, GCRY_MD_RMD160); if (!openpgp_md_test_algo (GCRY_MD_SHA224)) gcry_md_enable (md, GCRY_MD_SHA224); if (!openpgp_md_test_algo (GCRY_MD_SHA256)) gcry_md_enable (md, GCRY_MD_SHA256); if (!openpgp_md_test_algo (GCRY_MD_SHA384)) gcry_md_enable (md, GCRY_MD_SHA384); if (!openpgp_md_test_algo (GCRY_MD_SHA512)) gcry_md_enable (md, GCRY_MD_SHA512); } while( (n=fread( buf, 1, DIM(buf), fp )) ) gcry_md_write (md, buf, n); if( ferror(fp) ) log_error("%s: %s\n", fname?fname:"[stdin]", strerror(errno) ); else { gcry_md_final (md); if ( opt.with_colons ) { if ( algo ) print_hashline( md, algo, fname ); else { print_hashline( md, GCRY_MD_MD5, fname ); print_hashline( md, GCRY_MD_SHA1, fname ); if (!gcry_md_test_algo (GCRY_MD_RMD160)) print_hashline( md, GCRY_MD_RMD160, fname ); if (!gcry_md_test_algo (GCRY_MD_SHA224)) print_hashline (md, GCRY_MD_SHA224, fname); if (!gcry_md_test_algo (GCRY_MD_SHA256)) print_hashline( md, GCRY_MD_SHA256, fname ); if (!gcry_md_test_algo (GCRY_MD_SHA384)) print_hashline ( md, GCRY_MD_SHA384, fname ); if (!gcry_md_test_algo (GCRY_MD_SHA512)) print_hashline ( md, GCRY_MD_SHA512, fname ); } } else { if( algo ) print_hex(md,-algo,fname); else { print_hex( md, GCRY_MD_MD5, fname ); print_hex( md, GCRY_MD_SHA1, fname ); if (!gcry_md_test_algo (GCRY_MD_RMD160)) print_hex( md, GCRY_MD_RMD160, fname ); if (!gcry_md_test_algo (GCRY_MD_SHA224)) print_hex (md, GCRY_MD_SHA224, fname); if (!gcry_md_test_algo (GCRY_MD_SHA256)) print_hex( md, GCRY_MD_SHA256, fname ); if (!gcry_md_test_algo (GCRY_MD_SHA384)) print_hex( md, GCRY_MD_SHA384, fname ); if (!gcry_md_test_algo (GCRY_MD_SHA512)) print_hex( md, GCRY_MD_SHA512, fname ); } } } gcry_md_close(md); if( fp != stdin ) fclose(fp); } /**************** * Check the supplied name,value string and add it to the notation * data to be used for signatures. which==0 for sig notations, and 1 * for cert notations. */ static void add_notation_data( const char *string, int which ) { struct notation *notation; notation=string_to_notation(string,utf8_strings); if(notation) { if(which) { notation->next=opt.cert_notations; opt.cert_notations=notation; } else { notation->next=opt.sig_notations; opt.sig_notations=notation; } } } static void add_policy_url( const char *string, int which ) { unsigned int i,critical=0; strlist_t sl; if(*string=='!') { string++; critical=1; } for(i=0;iflags |= 1; } static void add_keyserver_url( const char *string, int which ) { unsigned int i,critical=0; strlist_t sl; if(*string=='!') { string++; critical=1; } for(i=0;iflags |= 1; } diff --git a/g10/keyedit.c b/g10/keyedit.c index fd42439a8..26e05a02d 100644 --- a/g10/keyedit.c +++ b/g10/keyedit.c @@ -1,5033 +1,5033 @@ /* keyedit.c - keyedit stuff * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, * 2008, 2009, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * * GnuPG is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * GnuPG is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ #include #include #include #include #include #include #include #ifdef HAVE_LIBREADLINE # define GNUPG_LIBREADLINE_H_INCLUDED # include #endif #define JNLIB_NEED_LOG_LOGV #include "gpg.h" #include "options.h" #include "packet.h" #include "status.h" #include "iobuf.h" #include "keydb.h" #include "photoid.h" #include "util.h" #include "main.h" #include "trustdb.h" #include "filter.h" #include "ttyio.h" #include "status.h" #include "i18n.h" #include "keyserver-internal.h" #include "call-agent.h" static void show_prefs (PKT_user_id * uid, PKT_signature * selfsig, int verbose); static void show_names (KBNODE keyblock, PKT_public_key * pk, unsigned int flag, int with_prefs); static void show_key_with_all_names (KBNODE keyblock, int only_marked, int with_revoker, int with_fpr, int with_subkeys, int with_prefs); static void show_key_and_fingerprint (KBNODE keyblock); static int menu_adduid (KBNODE keyblock, int photo, const char *photo_name); static void menu_deluid (KBNODE pub_keyblock); static int menu_delsig (KBNODE pub_keyblock); static int menu_clean (KBNODE keyblock, int self_only); static void menu_delkey (KBNODE pub_keyblock); static int menu_addrevoker (ctrl_t ctrl, kbnode_t pub_keyblock, int sensitive); static int menu_expire (KBNODE pub_keyblock); static int menu_backsign (KBNODE pub_keyblock); static int menu_set_primary_uid (KBNODE pub_keyblock); static int menu_set_preferences (KBNODE pub_keyblock); static int menu_set_keyserver_url (const char *url, KBNODE pub_keyblock); static int menu_set_notation (const char *string, KBNODE pub_keyblock); static int menu_select_uid (KBNODE keyblock, int idx); static int menu_select_uid_namehash (KBNODE keyblock, const char *namehash); static int menu_select_key (KBNODE keyblock, int idx); static int count_uids (KBNODE keyblock); static int count_uids_with_flag (KBNODE keyblock, unsigned flag); static int count_keys_with_flag (KBNODE keyblock, unsigned flag); static int count_selected_uids (KBNODE keyblock); static int real_uids_left (KBNODE keyblock); static int count_selected_keys (KBNODE keyblock); static int menu_revsig (KBNODE keyblock); static int menu_revuid (KBNODE keyblock); static int menu_revkey (KBNODE pub_keyblock); static int menu_revsubkey (KBNODE pub_keyblock); static int enable_disable_key (KBNODE keyblock, int disable); static void menu_showphoto (KBNODE keyblock); static int update_trust = 0; #define CONTROL_D ('D' - 'A' + 1) #define NODFLG_BADSIG (1<<0) /* Bad signature. */ #define NODFLG_NOKEY (1<<1) /* No public key. */ #define NODFLG_SIGERR (1<<2) /* Other sig error. */ #define NODFLG_MARK_A (1<<4) /* Temporary mark. */ #define NODFLG_DELSIG (1<<5) /* To be deleted. */ #define NODFLG_SELUID (1<<8) /* Indicate the selected userid. */ #define NODFLG_SELKEY (1<<9) /* Indicate the selected key. */ #define NODFLG_SELSIG (1<<10) /* Indicate a selected signature. */ struct sign_attrib { int non_exportable, non_revocable; struct revocation_reason_info *reason; byte trust_depth, trust_value; char *trust_regexp; }; /* TODO: Fix duplicated code between here and the check-sigs/list-sigs code in keylist.c. */ static int print_and_check_one_sig_colon (KBNODE keyblock, KBNODE node, int *inv_sigs, int *no_key, int *oth_err, int *is_selfsig, int print_without_key) { PKT_signature *sig = node->pkt->pkt.signature; int rc, sigrc; /* TODO: Make sure a cached sig record here still has the pk that issued it. See also keylist.c:list_keyblock_print */ switch ((rc = check_key_signature (keyblock, node, is_selfsig))) { case 0: node->flag &= ~(NODFLG_BADSIG | NODFLG_NOKEY | NODFLG_SIGERR); sigrc = '!'; break; case G10ERR_BAD_SIGN: node->flag = NODFLG_BADSIG; sigrc = '-'; if (inv_sigs) ++ * inv_sigs; break; case G10ERR_NO_PUBKEY: case G10ERR_UNU_PUBKEY: node->flag = NODFLG_NOKEY; sigrc = '?'; if (no_key) ++ * no_key; break; default: node->flag = NODFLG_SIGERR; sigrc = '%'; if (oth_err) ++ * oth_err; break; } if (sigrc != '?' || print_without_key) { printf ("sig:%c::%d:%08lX%08lX:%lu:%lu:", sigrc, sig->pubkey_algo, (ulong) sig->keyid[0], (ulong) sig->keyid[1], (ulong) sig->timestamp, (ulong) sig->expiredate); if (sig->trust_depth || sig->trust_value) printf ("%d %d", sig->trust_depth, sig->trust_value); printf (":"); if (sig->trust_regexp) es_write_sanitized (es_stdout, sig->trust_regexp, strlen (sig->trust_regexp), ":", NULL); printf ("::%02x%c\n", sig->sig_class, sig->flags.exportable ? 'x' : 'l'); if (opt.show_subpackets) print_subpackets_colon (sig); } return (sigrc == '!'); } /* * Print information about a signature, check it and return true * if the signature is okay. NODE must be a signature packet. */ static int print_and_check_one_sig (KBNODE keyblock, KBNODE node, int *inv_sigs, int *no_key, int *oth_err, int *is_selfsig, int print_without_key) { PKT_signature *sig = node->pkt->pkt.signature; int rc, sigrc; int is_rev = sig->sig_class == 0x30; /* TODO: Make sure a cached sig record here still has the pk that issued it. See also keylist.c:list_keyblock_print */ switch ((rc = check_key_signature (keyblock, node, is_selfsig))) { case 0: node->flag &= ~(NODFLG_BADSIG | NODFLG_NOKEY | NODFLG_SIGERR); sigrc = '!'; break; case G10ERR_BAD_SIGN: node->flag = NODFLG_BADSIG; sigrc = '-'; if (inv_sigs) ++ * inv_sigs; break; case G10ERR_NO_PUBKEY: case G10ERR_UNU_PUBKEY: node->flag = NODFLG_NOKEY; sigrc = '?'; if (no_key) ++ * no_key; break; default: node->flag = NODFLG_SIGERR; sigrc = '%'; if (oth_err) ++ * oth_err; break; } if (sigrc != '?' || print_without_key) { tty_printf ("%s%c%c %c%c%c%c%c%c %s %s", is_rev ? "rev" : "sig", sigrc, (sig->sig_class - 0x10 > 0 && sig->sig_class - 0x10 < 4) ? '0' + sig->sig_class - 0x10 : ' ', sig->flags.exportable ? ' ' : 'L', sig->flags.revocable ? ' ' : 'R', sig->flags.policy_url ? 'P' : ' ', sig->flags.notation ? 'N' : ' ', sig->flags.expired ? 'X' : ' ', (sig->trust_depth > 9) ? 'T' : (sig->trust_depth > 0) ? '0' + sig->trust_depth : ' ', keystr (sig->keyid), datestr_from_sig (sig)); if (opt.list_options & LIST_SHOW_SIG_EXPIRE) tty_printf (" %s", expirestr_from_sig (sig)); tty_printf (" "); if (sigrc == '%') tty_printf ("[%s] ", g10_errstr (rc)); else if (sigrc == '?') ; else if (*is_selfsig) { tty_printf (is_rev ? _("[revocation]") : _("[self-signature]")); } else { size_t n; char *p = get_user_id (sig->keyid, &n); tty_print_utf8_string2 (p, n, opt.screen_columns - keystrlen () - 26 - ((opt. list_options & LIST_SHOW_SIG_EXPIRE) ? 11 : 0)); xfree (p); } tty_printf ("\n"); if (sig->flags.policy_url && (opt.list_options & LIST_SHOW_POLICY_URLS)) show_policy_url (sig, 3, 0); if (sig->flags.notation && (opt.list_options & LIST_SHOW_NOTATIONS)) show_notation (sig, 3, 0, ((opt. list_options & LIST_SHOW_STD_NOTATIONS) ? 1 : 0) + ((opt. list_options & LIST_SHOW_USER_NOTATIONS) ? 2 : 0)); if (sig->flags.pref_ks && (opt.list_options & LIST_SHOW_KEYSERVER_URLS)) show_keyserver_url (sig, 3, 0); } return (sigrc == '!'); } /* * Check the keysigs and set the flags to indicate errors. * Returns true if error found. */ static int check_all_keysigs (KBNODE keyblock, int only_selected) { KBNODE kbctx; KBNODE node; int inv_sigs = 0; int no_key = 0; int oth_err = 0; int has_selfsig = 0; int mis_selfsig = 0; int selected = !only_selected; int anyuid = 0; for (kbctx = NULL; (node = walk_kbnode (keyblock, &kbctx, 0));) { if (node->pkt->pkttype == PKT_USER_ID) { PKT_user_id *uid = node->pkt->pkt.user_id; if (only_selected) selected = (node->flag & NODFLG_SELUID); if (selected) { tty_printf ("uid "); tty_print_utf8_string (uid->name, uid->len); tty_printf ("\n"); if (anyuid && !has_selfsig) mis_selfsig++; has_selfsig = 0; anyuid = 1; } } else if (selected && node->pkt->pkttype == PKT_SIGNATURE && ((node->pkt->pkt.signature->sig_class & ~3) == 0x10 || node->pkt->pkt.signature->sig_class == 0x30)) { int selfsig; if (print_and_check_one_sig (keyblock, node, &inv_sigs, &no_key, &oth_err, &selfsig, 0)) { if (selfsig) has_selfsig = 1; } /* Hmmm: should we update the trustdb here? */ } } if (!has_selfsig) mis_selfsig++; if (inv_sigs == 1) tty_printf (_("1 bad signature\n")); else if (inv_sigs) tty_printf (_("%d bad signatures\n"), inv_sigs); if (no_key == 1) tty_printf (_("1 signature not checked due to a missing key\n")); else if (no_key) tty_printf (_("%d signatures not checked due to missing keys\n"), no_key); if (oth_err == 1) tty_printf (_("1 signature not checked due to an error\n")); else if (oth_err) tty_printf (_("%d signatures not checked due to errors\n"), oth_err); if (mis_selfsig == 1) tty_printf (_("1 user ID without valid self-signature detected\n")); else if (mis_selfsig) tty_printf (_("%d user IDs without valid self-signatures detected\n"), mis_selfsig); return inv_sigs || no_key || oth_err || mis_selfsig; } static int sign_mk_attrib (PKT_signature * sig, void *opaque) { struct sign_attrib *attrib = opaque; byte buf[8]; if (attrib->non_exportable) { buf[0] = 0; /* not exportable */ build_sig_subpkt (sig, SIGSUBPKT_EXPORTABLE, buf, 1); } if (attrib->non_revocable) { buf[0] = 0; /* not revocable */ build_sig_subpkt (sig, SIGSUBPKT_REVOCABLE, buf, 1); } if (attrib->reason) revocation_reason_build_cb (sig, attrib->reason); if (attrib->trust_depth) { /* Not critical. If someone doesn't understand trust sigs, this can still be a valid regular signature. */ buf[0] = attrib->trust_depth; buf[1] = attrib->trust_value; build_sig_subpkt (sig, SIGSUBPKT_TRUST, buf, 2); /* Critical. If someone doesn't understands regexps, this whole sig should be invalid. Note the +1 for the length - regexps are null terminated. */ if (attrib->trust_regexp) build_sig_subpkt (sig, SIGSUBPKT_FLAG_CRITICAL | SIGSUBPKT_REGEXP, attrib->trust_regexp, strlen (attrib->trust_regexp) + 1); } return 0; } static void trustsig_prompt (byte * trust_value, byte * trust_depth, char **regexp) { char *p; *trust_value = 0; *trust_depth = 0; *regexp = NULL; /* Same string as pkclist.c:do_edit_ownertrust */ tty_printf (_ ("Please decide how far you trust this user to correctly verify" " other users' keys\n(by looking at passports, checking" " fingerprints from different sources, etc.)\n")); tty_printf ("\n"); tty_printf (_(" %d = I trust marginally\n"), 1); tty_printf (_(" %d = I trust fully\n"), 2); tty_printf ("\n"); while (*trust_value == 0) { p = cpr_get ("trustsig_prompt.trust_value", _("Your selection? ")); trim_spaces (p); cpr_kill_prompt (); /* 60 and 120 are as per RFC2440 */ if (p[0] == '1' && !p[1]) *trust_value = 60; else if (p[0] == '2' && !p[1]) *trust_value = 120; xfree (p); } tty_printf ("\n"); tty_printf (_("Please enter the depth of this trust signature.\n" "A depth greater than 1 allows the key you are signing to make\n" "trust signatures on your behalf.\n")); tty_printf ("\n"); while (*trust_depth == 0) { p = cpr_get ("trustsig_prompt.trust_depth", _("Your selection? ")); trim_spaces (p); cpr_kill_prompt (); *trust_depth = atoi (p); xfree (p); } tty_printf ("\n"); tty_printf (_("Please enter a domain to restrict this signature, " "or enter for none.\n")); tty_printf ("\n"); p = cpr_get ("trustsig_prompt.trust_regexp", _("Your selection? ")); trim_spaces (p); cpr_kill_prompt (); if (strlen (p) > 0) { char *q = p; int regexplen = 100, ind; *regexp = xmalloc (regexplen); /* Now mangle the domain the user entered into a regexp. To do this, \-escape everything that isn't alphanumeric, and attach "<[^>]+[@.]" to the front, and ">$" to the end. */ strcpy (*regexp, "<[^>]+[@.]"); ind = strlen (*regexp); while (*q) { if (!((*q >= 'A' && *q <= 'Z') || (*q >= 'a' && *q <= 'z') || (*q >= '0' && *q <= '9'))) (*regexp)[ind++] = '\\'; (*regexp)[ind++] = *q; if ((regexplen - ind) < 3) { regexplen += 100; *regexp = xrealloc (*regexp, regexplen); } q++; } (*regexp)[ind] = '\0'; strcat (*regexp, ">$"); } xfree (p); tty_printf ("\n"); } /* * Loop over all LOCUSR and and sign the uids after asking. * If no user id is marked, all user ids will be signed; * if some user_ids are marked those will be signed. */ static int sign_uids (KBNODE keyblock, strlist_t locusr, int *ret_modified, int local, int nonrevocable, int trust, int interactive) { int rc = 0; SK_LIST sk_list = NULL; SK_LIST sk_rover = NULL; PKT_public_key *pk = NULL; KBNODE node, uidnode; PKT_public_key *primary_pk = NULL; int select_all = !count_selected_uids (keyblock) || interactive; int all_v3 = 1; /* Are there any non-v3 sigs on this key already? */ if (PGP2) for (node = keyblock; node; node = node->next) if (node->pkt->pkttype == PKT_SIGNATURE && node->pkt->pkt.signature->version > 3) { all_v3 = 0; break; } /* Build a list of all signators. * * We use the CERT flag to request the primary which must always * be one which is capable of signing keys. I can't see a reason * why to sign keys using a subkey. Implementation of USAGE_CERT * is just a hack in getkey.c and does not mean that a subkey * marked as certification capable will be used. */ rc = build_sk_list (locusr, &sk_list, PUBKEY_USAGE_CERT); if (rc) goto leave; /* Loop over all signators. */ for (sk_rover = sk_list; sk_rover; sk_rover = sk_rover->next) { u32 sk_keyid[2], pk_keyid[2]; char *p, *trust_regexp = NULL; int force_v4 = 0, class = 0, selfsig = 0; u32 duration = 0, timestamp = 0; byte trust_depth = 0, trust_value = 0; if (local || nonrevocable || trust || opt.cert_policy_url || opt.cert_notations) force_v4 = 1; pk = sk_rover->pk; keyid_from_pk (pk, sk_keyid); /* Set mark A for all selected user ids. */ for (node = keyblock; node; node = node->next) { if (select_all || (node->flag & NODFLG_SELUID)) node->flag |= NODFLG_MARK_A; else node->flag &= ~NODFLG_MARK_A; } /* Reset mark for uids which are already signed. */ uidnode = NULL; for (node = keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_KEY) { primary_pk = node->pkt->pkt.public_key; keyid_from_pk (primary_pk, pk_keyid); /* Is this a self-sig? */ if (pk_keyid[0] == sk_keyid[0] && pk_keyid[1] == sk_keyid[1]) { selfsig = 1; /* Do not force a v4 sig here, otherwise it would be difficult to remake a v3 selfsig. If this is a v3->v4 promotion case, then we set force_v4 later anyway. */ force_v4 = 0; } } else if (node->pkt->pkttype == PKT_USER_ID) { uidnode = (node->flag & NODFLG_MARK_A) ? node : NULL; if (uidnode) { int yesreally = 0; char *user; user = utf8_to_native (uidnode->pkt->pkt.user_id->name, uidnode->pkt->pkt.user_id->len, 0); if (uidnode->pkt->pkt.user_id->is_revoked) { tty_printf (_("User ID \"%s\" is revoked."), user); if (selfsig) tty_printf ("\n"); else if (opt.expert) { tty_printf ("\n"); /* No, so remove the mark and continue */ if (!cpr_get_answer_is_yes ("sign_uid.revoke_okay", _("Are you sure you " "still want to sign " "it? (y/N) "))) { uidnode->flag &= ~NODFLG_MARK_A; uidnode = NULL; } else if (interactive) yesreally = 1; } else { uidnode->flag &= ~NODFLG_MARK_A; uidnode = NULL; tty_printf (_(" Unable to sign.\n")); } } else if (uidnode->pkt->pkt.user_id->is_expired) { tty_printf (_("User ID \"%s\" is expired."), user); if (selfsig) tty_printf ("\n"); else if (opt.expert) { tty_printf ("\n"); /* No, so remove the mark and continue */ if (!cpr_get_answer_is_yes ("sign_uid.expire_okay", _("Are you sure you " "still want to sign " "it? (y/N) "))) { uidnode->flag &= ~NODFLG_MARK_A; uidnode = NULL; } else if (interactive) yesreally = 1; } else { uidnode->flag &= ~NODFLG_MARK_A; uidnode = NULL; tty_printf (_(" Unable to sign.\n")); } } else if (!uidnode->pkt->pkt.user_id->created && !selfsig) { tty_printf (_("User ID \"%s\" is not self-signed."), user); if (opt.expert) { tty_printf ("\n"); /* No, so remove the mark and continue */ if (!cpr_get_answer_is_yes ("sign_uid.nosig_okay", _("Are you sure you " "still want to sign " "it? (y/N) "))) { uidnode->flag &= ~NODFLG_MARK_A; uidnode = NULL; } else if (interactive) yesreally = 1; } else { uidnode->flag &= ~NODFLG_MARK_A; uidnode = NULL; tty_printf (_(" Unable to sign.\n")); } } if (uidnode && interactive && !yesreally) { tty_printf (_("User ID \"%s\" is signable. "), user); if (!cpr_get_answer_is_yes ("sign_uid.sign_okay", _("Sign it? (y/N) "))) { uidnode->flag &= ~NODFLG_MARK_A; uidnode = NULL; } } xfree (user); } } else if (uidnode && node->pkt->pkttype == PKT_SIGNATURE && (node->pkt->pkt.signature->sig_class & ~3) == 0x10) { if (sk_keyid[0] == node->pkt->pkt.signature->keyid[0] && sk_keyid[1] == node->pkt->pkt.signature->keyid[1]) { char buf[50]; char *user; user = utf8_to_native (uidnode->pkt->pkt.user_id->name, uidnode->pkt->pkt.user_id->len, 0); /* It's a v3 self-sig. Make it into a v4 self-sig? */ if (node->pkt->pkt.signature->version < 4 && selfsig) { tty_printf (_("The self-signature on \"%s\"\n" "is a PGP 2.x-style signature.\n"), user); /* Note that the regular PGP2 warning below still applies if there are no v4 sigs on this key at all. */ if (opt.expert) if (cpr_get_answer_is_yes ("sign_uid.v4_promote_okay", _("Do you want to promote " "it to an OpenPGP self-" "signature? (y/N) "))) { force_v4 = 1; node->flag |= NODFLG_DELSIG; xfree (user); continue; } } /* Is the current signature expired? */ if (node->pkt->pkt.signature->flags.expired) { tty_printf (_("Your current signature on \"%s\"\n" "has expired.\n"), user); if (cpr_get_answer_is_yes ("sign_uid.replace_expired_okay", _("Do you want to issue a " "new signature to replace " "the expired one? (y/N) "))) { /* Mark these for later deletion. We don't want to delete them here, just in case the replacement signature doesn't happen for some reason. We only delete these after the replacement is already in place. */ node->flag |= NODFLG_DELSIG; xfree (user); continue; } } if (!node->pkt->pkt.signature->flags.exportable && !local) { /* It's a local sig, and we want to make a exportable sig. */ tty_printf (_("Your current signature on \"%s\"\n" "is a local signature.\n"), user); if (cpr_get_answer_is_yes ("sign_uid.local_promote_okay", _("Do you want to promote " "it to a full exportable " "signature? (y/N) "))) { /* Mark these for later deletion. We don't want to delete them here, just in case the replacement signature doesn't happen for some reason. We only delete these after the replacement is already in place. */ node->flag |= NODFLG_DELSIG; xfree (user); continue; } } /* Fixme: see whether there is a revocation in which * case we should allow to sign it again. */ if (!node->pkt->pkt.signature->flags.exportable && local) tty_printf (_("\"%s\" was already locally signed by key %s\n"), user, keystr_from_pk (pk)); else tty_printf (_("\"%s\" was already signed by key %s\n"), user, keystr_from_pk (pk)); if (opt.expert && cpr_get_answer_is_yes ("sign_uid.dupe_okay", _("Do you want to sign it " "again anyway? (y/N) "))) { /* Don't delete the old sig here since this is an --expert thing. */ xfree (user); continue; } snprintf (buf, sizeof buf, "%08lX%08lX", (ulong) pk->keyid[0], (ulong) pk->keyid[1]); write_status_text (STATUS_ALREADY_SIGNED, buf); uidnode->flag &= ~NODFLG_MARK_A; /* remove mark */ xfree (user); } } } /* Check whether any uids are left for signing. */ if (!count_uids_with_flag (keyblock, NODFLG_MARK_A)) { tty_printf (_("Nothing to sign with key %s\n"), keystr_from_pk (pk)); continue; } /* Ask whether we really should sign these user id(s). */ tty_printf ("\n"); show_key_with_all_names (keyblock, 1, 0, 1, 0, 0); tty_printf ("\n"); if (primary_pk->expiredate && !selfsig) { u32 now = make_timestamp (); if (primary_pk->expiredate <= now) { tty_printf (_("This key has expired!")); if (opt.expert) { tty_printf (" "); if (!cpr_get_answer_is_yes ("sign_uid.expired_okay", _("Are you sure you still " "want to sign it? (y/N) "))) continue; } else { tty_printf (_(" Unable to sign.\n")); continue; } } else { tty_printf (_("This key is due to expire on %s.\n"), expirestr_from_pk (primary_pk)); if (opt.ask_cert_expire) { char *answer = cpr_get ("sign_uid.expire", _("Do you want your signature to " "expire at the same time? (Y/n) ")); if (answer_is_yes_no_default (answer, 1)) { /* This fixes the signature timestamp we're going to make as now. This is so the expiration date is exactly correct, and not a few seconds off (due to the time it takes to answer the questions, enter the passphrase, etc). */ timestamp = now; duration = primary_pk->expiredate - now; force_v4 = 1; } cpr_kill_prompt (); xfree (answer); } } } /* Only ask for duration if we haven't already set it to match the expiration of the pk */ if (!duration && !selfsig) { if (opt.ask_cert_expire) duration = ask_expire_interval (1, opt.def_cert_expire); else duration = parse_expire_string (opt.def_cert_expire); } if (duration) force_v4 = 1; /* Is --pgp2 on, it's a v3 key, all the sigs on the key are currently v3 and we're about to sign it with a v4 sig? If so, danger! */ if (PGP2 && all_v3 && (pk->version > 3 || force_v4) && primary_pk->version <= 3) { tty_printf (_("You may not make an OpenPGP signature on a " "PGP 2.x key while in --pgp2 mode.\n")); tty_printf (_("This would make the key unusable in PGP 2.x.\n")); if (opt.expert) { if (!cpr_get_answer_is_yes ("sign_uid.v4_on_v3_okay", _("Are you sure you still " "want to sign it? (y/N) "))) continue; all_v3 = 0; } else continue; } if (selfsig) ; else { if (opt.batch || !opt.ask_cert_level) class = 0x10 + opt.def_cert_level; else { char *answer; tty_printf (_("How carefully have you verified the key you are " "about to sign actually belongs\nto the person " "named above? If you don't know what to " "answer, enter \"0\".\n")); tty_printf ("\n"); tty_printf (_(" (0) I will not answer.%s\n"), opt.def_cert_level == 0 ? " (default)" : ""); tty_printf (_(" (1) I have not checked at all.%s\n"), opt.def_cert_level == 1 ? " (default)" : ""); tty_printf (_(" (2) I have done casual checking.%s\n"), opt.def_cert_level == 2 ? " (default)" : ""); tty_printf (_(" (3) I have done very careful checking.%s\n"), opt.def_cert_level == 3 ? " (default)" : ""); tty_printf ("\n"); while (class == 0) { answer = cpr_get ("sign_uid.class", _("Your selection? " "(enter `?' for more information): ")); if (answer[0] == '\0') class = 0x10 + opt.def_cert_level; /* Default */ else if (ascii_strcasecmp (answer, "0") == 0) class = 0x10; /* Generic */ else if (ascii_strcasecmp (answer, "1") == 0) class = 0x11; /* Persona */ else if (ascii_strcasecmp (answer, "2") == 0) class = 0x12; /* Casual */ else if (ascii_strcasecmp (answer, "3") == 0) class = 0x13; /* Positive */ else tty_printf (_("Invalid selection.\n")); xfree (answer); } } if (trust) trustsig_prompt (&trust_value, &trust_depth, &trust_regexp); } p = get_user_id_native (sk_keyid); tty_printf (_("Are you sure that you want to sign this key with your\n" "key \"%s\" (%s)\n"), p, keystr_from_pk (pk)); xfree (p); if (selfsig) { tty_printf ("\n"); tty_printf (_("This will be a self-signature.\n")); if (local) { tty_printf ("\n"); tty_printf (_("WARNING: the signature will not be marked " "as non-exportable.\n")); } if (nonrevocable) { tty_printf ("\n"); tty_printf (_("WARNING: the signature will not be marked " "as non-revocable.\n")); } } else { if (local) { tty_printf ("\n"); tty_printf (_("The signature will be marked as non-exportable.\n")); } if (nonrevocable) { tty_printf ("\n"); tty_printf (_("The signature will be marked as non-revocable.\n")); } switch (class) { case 0x11: tty_printf ("\n"); tty_printf (_("I have not checked this key at all.\n")); break; case 0x12: tty_printf ("\n"); tty_printf (_("I have checked this key casually.\n")); break; case 0x13: tty_printf ("\n"); tty_printf (_("I have checked this key very carefully.\n")); break; } } tty_printf ("\n"); if (opt.batch && opt.answer_yes) ; else if (!cpr_get_answer_is_yes ("sign_uid.okay", _("Really sign? (y/N) "))) continue; /* Now we can sign the user ids. */ reloop: /* (Must use this, because we are modifing the list.) */ primary_pk = NULL; for (node = keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_KEY) primary_pk = node->pkt->pkt.public_key; else if (node->pkt->pkttype == PKT_USER_ID && (node->flag & NODFLG_MARK_A)) { PACKET *pkt; PKT_signature *sig; struct sign_attrib attrib; assert (primary_pk); memset (&attrib, 0, sizeof attrib); attrib.non_exportable = local; attrib.non_revocable = nonrevocable; attrib.trust_depth = trust_depth; attrib.trust_value = trust_value; attrib.trust_regexp = trust_regexp; node->flag &= ~NODFLG_MARK_A; /* We force creation of a v4 signature for local * signatures, otherwise we would not generate the * subpacket with v3 keys and the signature becomes * exportable. */ if (selfsig) rc = make_keysig_packet (&sig, primary_pk, node->pkt->pkt.user_id, NULL, pk, 0x13, 0, force_v4 ? 4 : 0, 0, 0, keygen_add_std_prefs, primary_pk, NULL); else rc = make_keysig_packet (&sig, primary_pk, node->pkt->pkt.user_id, NULL, pk, class, 0, force_v4 ? 4 : 0, timestamp, duration, sign_mk_attrib, &attrib, NULL); if (rc) { log_error (_("signing failed: %s\n"), g10_errstr (rc)); goto leave; } *ret_modified = 1; /* We changed the keyblock. */ update_trust = 1; pkt = xmalloc_clear (sizeof *pkt); pkt->pkttype = PKT_SIGNATURE; pkt->pkt.signature = sig; insert_kbnode (node, new_kbnode (pkt), PKT_SIGNATURE); goto reloop; } } /* Delete any sigs that got promoted */ for (node = keyblock; node; node = node->next) if (node->flag & NODFLG_DELSIG) delete_kbnode (node); } /* End loop over signators. */ leave: release_sk_list (sk_list); return rc; } /* * Change the passphrase of the primary and all secondary keys. Note * that it is common to use only one passphrase for the primary and * all subkeys. However, this is now (since GnuPG 2.1) all up to the * gpg-agent. Returns 0 on success or an error code. */ static gpg_error_t change_passphrase (ctrl_t ctrl, kbnode_t keyblock) { gpg_error_t err; kbnode_t node; PKT_public_key *pk; int any; u32 keyid[2], subid[2]; char *hexgrip = NULL; char *cache_nonce = NULL; char *passwd_nonce = NULL; node = find_kbnode (keyblock, PKT_PUBLIC_KEY); if (!node) { log_error ("Oops; public key missing!\n"); err = gpg_error (GPG_ERR_INTERNAL); goto leave; } pk = node->pkt->pkt.public_key; keyid_from_pk (pk, keyid); /* Check whether it is likely that we will be able to change the passphrase for any subkey. */ for (any = 0, node = keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_KEY || node->pkt->pkttype == PKT_PUBLIC_SUBKEY) { char *serialno; pk = node->pkt->pkt.public_key; keyid_from_pk (pk, subid); xfree (hexgrip); err = hexkeygrip_from_pk (pk, &hexgrip); if (err) goto leave; err = agent_get_keyinfo (ctrl, hexgrip, &serialno); if (!err && serialno) ; /* Key on card. */ else if (gpg_err_code (err) == GPG_ERR_NOT_FOUND) ; /* Maybe stub key. */ else if (!err) any = 1; /* Key is known. */ else log_error ("key %s: error getting keyinfo from agent: %s\n", keystr_with_sub (keyid, subid), gpg_strerror (err)); xfree (serialno); } } err = 0; if (!any) { tty_printf (_("Key has only stub or on-card key items - " "no passphrase to change.\n")); goto leave; } /* Change the passphrase for all keys. */ for (any = 0, node = keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_KEY || node->pkt->pkttype == PKT_PUBLIC_SUBKEY) { char *desc; pk = node->pkt->pkt.public_key; keyid_from_pk (pk, subid); xfree (hexgrip); err = hexkeygrip_from_pk (pk, &hexgrip); if (err) goto leave; desc = gpg_format_keydesc (pk, 0, 1); err = agent_passwd (ctrl, hexgrip, desc, &cache_nonce, &passwd_nonce); xfree (desc); if (err) log_log ((gpg_err_code (err) == GPG_ERR_CANCELED || gpg_err_code (err) == GPG_ERR_FULLY_CANCELED) ? JNLIB_LOG_INFO : JNLIB_LOG_ERROR, _("key %s: error changing passphrase: %s\n"), keystr_with_sub (keyid, subid), gpg_strerror (err)); if (gpg_err_code (err) == GPG_ERR_FULLY_CANCELED) break; } } leave: xfree (hexgrip); xfree (cache_nonce); xfree (passwd_nonce); return err; } /* * There are some keys out (due to a bug in gnupg), where the sequence * of the packets is wrong. This function fixes that. * Returns: true if the keyblock has been fixed. * * Note: This function does not work if there is more than one user ID. */ static int fix_keyblock (KBNODE keyblock) { KBNODE node, last, subkey; int fixed = 0; /* Locate key signatures of class 0x10..0x13 behind sub key packets. */ for (subkey = last = NULL, node = keyblock; node; last = node, node = node->next) { switch (node->pkt->pkttype) { case PKT_PUBLIC_SUBKEY: case PKT_SECRET_SUBKEY: if (!subkey) subkey = last; /* Actually it is the one before the subkey. */ break; case PKT_SIGNATURE: if (subkey) { PKT_signature *sig = node->pkt->pkt.signature; if (sig->sig_class >= 0x10 && sig->sig_class <= 0x13) { log_info (_("moving a key signature to the correct place\n")); last->next = node->next; node->next = subkey->next; subkey->next = node; node = last; fixed = 1; } } break; default: break; } } return fixed; } static int parse_sign_type (const char *str, int *localsig, int *nonrevokesig, int *trustsig) { const char *p = str; while (*p) { if (ascii_strncasecmp (p, "l", 1) == 0) { *localsig = 1; p++; } else if (ascii_strncasecmp (p, "nr", 2) == 0) { *nonrevokesig = 1; p += 2; } else if (ascii_strncasecmp (p, "t", 1) == 0) { *trustsig = 1; p++; } else return 0; } return 1; } /* * Menu driven key editor. If seckey_check is true, then a secret key * that matches username will be looked for. If it is false, not all * commands will be available. * * Note: to keep track of certain selections we use node->mark MARKBIT_xxxx. */ /* Need an SK for this command */ #define KEYEDIT_NEED_SK 1 /* Cannot be viewing the SK for this command */ #define KEYEDIT_NOT_SK 2 /* Must be viewing the SK for this command */ #define KEYEDIT_ONLY_SK 4 /* Match the tail of the string */ #define KEYEDIT_TAIL_MATCH 8 enum cmdids { cmdNONE = 0, cmdQUIT, cmdHELP, cmdFPR, cmdLIST, cmdSELUID, cmdCHECK, cmdSIGN, cmdREVSIG, cmdREVKEY, cmdREVUID, cmdDELSIG, cmdPRIMARY, cmdDEBUG, cmdSAVE, cmdADDUID, cmdADDPHOTO, cmdDELUID, cmdADDKEY, cmdDELKEY, cmdADDREVOKER, cmdTOGGLE, cmdSELKEY, cmdPASSWD, cmdTRUST, cmdPREF, cmdEXPIRE, cmdBACKSIGN, cmdENABLEKEY, cmdDISABLEKEY, cmdSHOWPREF, cmdSETPREF, cmdPREFKS, cmdNOTATION, cmdINVCMD, cmdSHOWPHOTO, cmdUPDTRUST, cmdCHKTRUST, cmdADDCARDKEY, cmdKEYTOCARD, cmdBKUPTOCARD, cmdCHECKBKUPKEY, cmdCLEAN, cmdMINIMIZE, cmdNOP }; static struct { const char *name; enum cmdids id; int flags; const char *desc; } cmds[] = { { "quit", cmdQUIT, 0, N_("quit this menu")}, { "q", cmdQUIT, 0, NULL}, { "save", cmdSAVE, 0, N_("save and quit")}, { "help", cmdHELP, 0, N_("show this help")}, { "?", cmdHELP, 0, NULL}, { "fpr", cmdFPR, 0, N_("show key fingerprint")}, { "list", cmdLIST, 0, N_("list key and user IDs")}, { "l", cmdLIST, 0, NULL}, { "uid", cmdSELUID, 0, N_("select user ID N")}, { "key", cmdSELKEY, 0, N_("select subkey N")}, { "check", cmdCHECK, 0, N_("check signatures")}, { "c", cmdCHECK, 0, NULL}, { "cross-certify", cmdBACKSIGN, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, NULL}, { "backsign", cmdBACKSIGN, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, NULL}, { "sign", cmdSIGN, KEYEDIT_NOT_SK | KEYEDIT_TAIL_MATCH, N_("sign selected user IDs [* see below for related commands]")}, { "s", cmdSIGN, KEYEDIT_NOT_SK, NULL}, /* "lsign" and friends will never match since "sign" comes first and it is a tail match. They are just here so they show up in the help menu. */ { "lsign", cmdNOP, 0, N_("sign selected user IDs locally")}, { "tsign", cmdNOP, 0, N_("sign selected user IDs with a trust signature")}, { "nrsign", cmdNOP, 0, N_("sign selected user IDs with a non-revocable signature")}, { "debug", cmdDEBUG, 0, NULL}, { "adduid", cmdADDUID, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, N_("add a user ID")}, { "addphoto", cmdADDPHOTO, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, N_("add a photo ID")}, { "deluid", cmdDELUID, KEYEDIT_NOT_SK, N_("delete selected user IDs")}, /* delphoto is really deluid in disguise */ { "delphoto", cmdDELUID, KEYEDIT_NOT_SK, NULL}, { "addkey", cmdADDKEY, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, N_("add a subkey")}, #ifdef ENABLE_CARD_SUPPORT { "addcardkey", cmdADDCARDKEY, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, N_("add a key to a smartcard")}, { "keytocard", cmdKEYTOCARD, KEYEDIT_NEED_SK | KEYEDIT_ONLY_SK, N_("move a key to a smartcard")}, { "bkuptocard", cmdBKUPTOCARD, KEYEDIT_NEED_SK | KEYEDIT_ONLY_SK, N_("move a backup key to a smartcard")}, { "checkbkupkey", cmdCHECKBKUPKEY, KEYEDIT_NEED_SK | KEYEDIT_ONLY_SK, NULL}, #endif /*ENABLE_CARD_SUPPORT */ { "delkey", cmdDELKEY, KEYEDIT_NOT_SK, N_("delete selected subkeys")}, { "addrevoker", cmdADDREVOKER, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, N_("add a revocation key")}, { "delsig", cmdDELSIG, KEYEDIT_NOT_SK, N_("delete signatures from the selected user IDs")}, { "expire", cmdEXPIRE, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, N_("change the expiration date for the key or selected subkeys")}, { "primary", cmdPRIMARY, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, N_("flag the selected user ID as primary")}, { "toggle", cmdTOGGLE, KEYEDIT_NEED_SK, N_("toggle between the secret and public key listings")}, { "t", cmdTOGGLE, KEYEDIT_NEED_SK, NULL}, { "pref", cmdPREF, KEYEDIT_NOT_SK, N_("list preferences (expert)")}, { "showpref", cmdSHOWPREF, KEYEDIT_NOT_SK, N_("list preferences (verbose)")}, { "setpref", cmdSETPREF, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, N_("set preference list for the selected user IDs")}, { "updpref", cmdSETPREF, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, NULL}, { "keyserver", cmdPREFKS, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, N_("set the preferred keyserver URL for the selected user IDs")}, { "notation", cmdNOTATION, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, N_("set a notation for the selected user IDs")}, { "passwd", cmdPASSWD, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, N_("change the passphrase")}, { "password", cmdPASSWD, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, NULL}, { "trust", cmdTRUST, KEYEDIT_NOT_SK, N_("change the ownertrust")}, { "revsig", cmdREVSIG, KEYEDIT_NOT_SK, N_("revoke signatures on the selected user IDs")}, { "revuid", cmdREVUID, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, N_("revoke selected user IDs")}, { "revphoto", cmdREVUID, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, NULL}, { "revkey", cmdREVKEY, KEYEDIT_NOT_SK | KEYEDIT_NEED_SK, N_("revoke key or selected subkeys")}, { "enable", cmdENABLEKEY, KEYEDIT_NOT_SK, N_("enable key")}, { "disable", cmdDISABLEKEY, KEYEDIT_NOT_SK, N_("disable key")}, { "showphoto", cmdSHOWPHOTO, 0, N_("show selected photo IDs")}, { "clean", cmdCLEAN, KEYEDIT_NOT_SK, N_("compact unusable user IDs and remove unusable signatures from key")}, { "minimize", cmdMINIMIZE, KEYEDIT_NOT_SK, N_("compact unusable user IDs and remove all signatures from key")}, { NULL, cmdNONE, 0, NULL} }; #ifdef HAVE_LIBREADLINE /* These two functions are used by readline for command completion. */ static char * command_generator (const char *text, int state) { static int list_index, len; const char *name; /* If this is a new word to complete, initialize now. This includes saving the length of TEXT for efficiency, and initializing the index variable to 0. */ if (!state) { list_index = 0; len = strlen (text); } /* Return the next partial match */ while ((name = cmds[list_index].name)) { /* Only complete commands that have help text */ if (cmds[list_index++].desc && strncmp (name, text, len) == 0) return strdup (name); } return NULL; } static char ** keyedit_completion (const char *text, int start, int end) { /* If we are at the start of a line, we try and command-complete. If not, just do nothing for now. */ (void) end; if (start == 0) return rl_completion_matches (text, command_generator); rl_attempted_completion_over = 1; return NULL; } #endif /* HAVE_LIBREADLINE */ /* Main function of the menu driven key editor. */ void keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr, strlist_t commands, int quiet, int seckey_check) { enum cmdids cmd = 0; gpg_error_t err = 0; KBNODE keyblock = NULL; KEYDB_HANDLE kdbhd = NULL; int have_seckey = 0; char *answer = NULL; int redisplay = 1; int modified = 0; int toggle; int have_commands = !!commands; if (opt.command_fd != -1) ; else if (opt.batch && !have_commands) { log_error (_("can't do this in batch mode\n")); goto leave; } #ifdef HAVE_W32_SYSTEM /* Due to Windows peculiarities we need to make sure that the trustdb stale check is done before we open another file (i.e. by searching for a key). In theory we could make sure that the files are closed after use but the open/close caches inhibits that and flushing the cache right before the stale check is not easy to implement. Thus we take the easy way out and run the stale check as early as possible. Note, that for non- W32 platforms it is run indirectly trough a call to get_validity (). */ check_trustdb_stale (); #endif /* Get the public key */ err = get_pubkey_byname (ctrl, NULL, NULL, username, &keyblock, &kdbhd, 1, 1); if (err) goto leave; if (fix_keyblock (keyblock)) modified++; if (collapse_uids (&keyblock)) modified++; reorder_keyblock (keyblock); /* We modified the keyblock, so let's make sure the flags are right. */ if (modified) merge_keys_and_selfsig (keyblock); /* See whether we have a matching secret key. */ if (seckey_check) { have_seckey = !agent_probe_any_secret_key (ctrl, keyblock); if (have_seckey && !quiet) tty_printf (_("Secret key is available.\n")); } toggle = 0; /* Main command loop. */ for (;;) { int i, arg_number, photo; const char *arg_string = ""; char *p; PKT_public_key *pk = keyblock->pkt->pkt.public_key; tty_printf ("\n"); if (redisplay && !quiet) { show_key_with_all_names (keyblock, 0, 1, 0, 1, 0); tty_printf ("\n"); redisplay = 0; } do { xfree (answer); if (have_commands) { if (commands) { answer = xstrdup (commands->d); commands = commands->next; } else if (opt.batch) { answer = xstrdup ("quit"); } else have_commands = 0; } if (!have_commands) { #ifdef HAVE_LIBREADLINE tty_enable_completion (keyedit_completion); #endif answer = cpr_get_no_help ("keyedit.prompt", "gpg> "); cpr_kill_prompt (); tty_disable_completion (); } trim_spaces (answer); } while (*answer == '#'); arg_number = 0; /* Here is the init which egcc complains about. */ photo = 0; /* Same here. */ if (!*answer) cmd = cmdLIST; else if (*answer == CONTROL_D) cmd = cmdQUIT; else if (digitp (answer)) { cmd = cmdSELUID; arg_number = atoi (answer); } else { if ((p = strchr (answer, ' '))) { *p++ = 0; trim_spaces (answer); trim_spaces (p); arg_number = atoi (p); arg_string = p; } for (i = 0; cmds[i].name; i++) { if (cmds[i].flags & KEYEDIT_TAIL_MATCH) { size_t l = strlen (cmds[i].name); size_t a = strlen (answer); if (a >= l) { if (!ascii_strcasecmp (&answer[a - l], cmds[i].name)) { answer[a - l] = '\0'; break; } } } else if (!ascii_strcasecmp (answer, cmds[i].name)) break; } if ((cmds[i].flags & KEYEDIT_NEED_SK) && !have_seckey) { tty_printf (_("Need the secret key to do this.\n")); cmd = cmdNOP; } else if (((cmds[i].flags & KEYEDIT_NOT_SK) && have_seckey && toggle) || ((cmds[i].flags & KEYEDIT_ONLY_SK) && have_seckey && !toggle)) { tty_printf (_("Please use the command \"toggle\" first.\n")); cmd = cmdNOP; } else cmd = cmds[i].id; } /* Dispatch the command. */ switch (cmd) { case cmdHELP: for (i = 0; cmds[i].name; i++) { if ((cmds[i].flags & KEYEDIT_NEED_SK) && !have_seckey) ; /* Skip those item if we do not have the secret key. */ else if (cmds[i].desc) tty_printf ("%-11s %s\n", cmds[i].name, _(cmds[i].desc)); } tty_printf ("\n"); tty_printf (_("* The `sign' command may be prefixed with an `l' for local " "signatures (lsign),\n" " a `t' for trust signatures (tsign), an `nr' for " "non-revocable signatures\n" " (nrsign), or any combination thereof (ltsign, " "tnrsign, etc.).\n")); break; case cmdLIST: redisplay = 1; break; case cmdFPR: show_key_and_fingerprint (keyblock); break; case cmdSELUID: if (strlen (arg_string) == NAMEHASH_LEN * 2) redisplay = menu_select_uid_namehash (keyblock, arg_string); else { if (*arg_string == '*' && (!arg_string[1] || spacep (arg_string + 1))) arg_number = -1; /* Select all. */ redisplay = menu_select_uid (keyblock, arg_number); } break; case cmdSELKEY: { if (*arg_string == '*' && (!arg_string[1] || spacep (arg_string + 1))) arg_number = -1; /* Select all. */ if (menu_select_key (keyblock, arg_number)) redisplay = 1; } break; case cmdCHECK: check_all_keysigs (keyblock, count_selected_uids (keyblock)); break; case cmdSIGN: { int localsig = 0, nonrevokesig = 0, trustsig = 0, interactive = 0; if (pk->flags.revoked) { tty_printf (_("Key is revoked.")); if (opt.expert) { tty_printf (" "); if (!cpr_get_answer_is_yes ("keyedit.sign_revoked.okay", _("Are you sure you still want to sign it? (y/N) "))) break; } else { tty_printf (_(" Unable to sign.\n")); break; } } if (count_uids (keyblock) > 1 && !count_selected_uids (keyblock) && !cpr_get_answer_is_yes ("keyedit.sign_all.okay", _("Really sign all user IDs?" " (y/N) "))) { if (opt.interactive) interactive = 1; else { tty_printf (_("Hint: Select the user IDs to sign\n")); have_commands = 0; break; } } /* What sort of signing are we doing? */ if (!parse_sign_type (answer, &localsig, &nonrevokesig, &trustsig)) { tty_printf (_("Unknown signature type `%s'\n"), answer); break; } sign_uids (keyblock, locusr, &modified, localsig, nonrevokesig, trustsig, interactive); } break; case cmdDEBUG: dump_kbnode (keyblock); break; case cmdTOGGLE: /* The toggle command is a leftover from old gpg versions where we worked with a secret and a public keyring. It is not necessary anymore but we keep this command for the sake of scripts using it. */ toggle = !toggle; redisplay = 1; break; case cmdADDPHOTO: if (RFC2440 || RFC1991 || PGP2) { tty_printf (_("This command is not allowed while in %s mode.\n"), compliance_option_string ()); break; } photo = 1; /* fall through */ case cmdADDUID: if (menu_adduid (keyblock, photo, arg_string)) { update_trust = 1; redisplay = 1; modified = 1; merge_keys_and_selfsig (keyblock); } break; case cmdDELUID: { int n1; if (!(n1 = count_selected_uids (keyblock))) tty_printf (_("You must select at least one user ID.\n")); else if (real_uids_left (keyblock) < 1) tty_printf (_("You can't delete the last user ID!\n")); else if (cpr_get_answer_is_yes ("keyedit.remove.uid.okay", n1 > 1 ? _("Really remove all selected user IDs? (y/N) ") : _("Really remove this user ID? (y/N) "))) { menu_deluid (keyblock); redisplay = 1; modified = 1; } } break; case cmdDELSIG: { int n1; if (!(n1 = count_selected_uids (keyblock))) tty_printf (_("You must select at least one user ID.\n")); else if (menu_delsig (keyblock)) { /* No redisplay here, because it may scroll away some * of the status output of this command. */ modified = 1; } } break; case cmdADDKEY: - if (!generate_subkeypair (keyblock)) + if (!generate_subkeypair (ctrl, keyblock)) { redisplay = 1; modified = 1; merge_keys_and_selfsig (keyblock); } break; #ifdef ENABLE_CARD_SUPPORT case cmdADDCARDKEY: if (!card_generate_subkey (keyblock)) { redisplay = 1; modified = 1; merge_keys_and_selfsig (keyblock); } break; case cmdKEYTOCARD: { KBNODE node = NULL; switch (count_selected_keys (keyblock)) { case 0: if (cpr_get_answer_is_yes ("keyedit.keytocard.use_primary", /* TRANSLATORS: Please take care: This is about moving the key and not about removing it. */ _("Really move the primary key? (y/N) "))) node = keyblock; break; case 1: for (node = keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY && node->flag & NODFLG_SELKEY) break; } break; default: tty_printf (_("You must select exactly one key.\n")); break; } if (node) { PKT_public_key *xxpk = node->pkt->pkt.public_key; if (card_store_subkey (node, xxpk ? xxpk->pubkey_usage : 0)) { redisplay = 1; /* Only the secret key has been modified; thus there is no need to set the modified flag. */ } } } break; case cmdBKUPTOCARD: case cmdCHECKBKUPKEY: log_debug ("FIXME: This needs to be changed\n"); { /* Ask for a filename, check whether this is really a backup key as generated by the card generation, parse that key and store it on card. */ KBNODE node; const char *fname; PACKET *pkt; IOBUF a; fname = arg_string; if (!*fname) { tty_printf (_("Command expects a filename argument\n")); break; } /* Open that file. */ a = iobuf_open (fname); if (a && is_secured_file (iobuf_get_fd (a))) { iobuf_close (a); a = NULL; gpg_err_set_errno (EPERM); } if (!a) { tty_printf (_("Can't open `%s': %s\n"), fname, strerror (errno)); break; } /* Parse and check that file. */ pkt = xmalloc (sizeof *pkt); init_packet (pkt); err = parse_packet (a, pkt); iobuf_close (a); iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0, (char *) fname); if (!err && pkt->pkttype != PKT_SECRET_KEY && pkt->pkttype != PKT_SECRET_SUBKEY) err = G10ERR_NO_SECKEY; if (err) { tty_printf (_("Error reading backup key from `%s': %s\n"), fname, g10_errstr (err)); free_packet (pkt); xfree (pkt); break; } node = new_kbnode (pkt); if (cmd == cmdCHECKBKUPKEY) { /* PKT_public_key *sk = node->pkt->pkt.secret_key; */ /* switch (is_secret_key_protected (sk)) */ /* { */ /* case 0: /\* Not protected. *\/ */ /* tty_printf (_("This key is not protected.\n")); */ /* break; */ /* case -1: */ /* log_error (_("unknown key protection algorithm\n")); */ /* break; */ /* default: */ /* if (sk->protect.s2k.mode == 1001) */ /* tty_printf (_("Secret parts of key" */ /* " are not available.\n")); */ /* if (sk->protect.s2k.mode == 1002) */ /* tty_printf (_("Secret parts of key" */ /* " are stored on-card.\n")); */ /* else */ /* check_secret_key (sk, 0); */ /* } */ } else /* Store it. */ { if (card_store_subkey (node, 0)) { redisplay = 1; /* FIXME:sec_modified = 1;*/ } } release_kbnode (node); } break; #endif /* ENABLE_CARD_SUPPORT */ case cmdDELKEY: { int n1; if (!(n1 = count_selected_keys (keyblock))) tty_printf (_("You must select at least one key.\n")); else if (!cpr_get_answer_is_yes ("keyedit.remove.subkey.okay", n1 > 1 ? _("Do you really want to delete the " "selected keys? (y/N) ") : _("Do you really want to delete this key? (y/N) "))) ; else { menu_delkey (keyblock); redisplay = 1; modified = 1; } } break; case cmdADDREVOKER: { int sensitive = 0; if (ascii_strcasecmp (arg_string, "sensitive") == 0) sensitive = 1; if (menu_addrevoker (ctrl, keyblock, sensitive)) { redisplay = 1; modified = 1; merge_keys_and_selfsig (keyblock); } } break; case cmdREVUID: { int n1; if (!(n1 = count_selected_uids (keyblock))) tty_printf (_("You must select at least one user ID.\n")); else if (cpr_get_answer_is_yes ("keyedit.revoke.uid.okay", n1 > 1 ? _("Really revoke all selected user IDs? (y/N) ") : _("Really revoke this user ID? (y/N) "))) { if (menu_revuid (keyblock)) { modified = 1; redisplay = 1; } } } break; case cmdREVKEY: { int n1; if (!(n1 = count_selected_keys (keyblock))) { if (cpr_get_answer_is_yes ("keyedit.revoke.subkey.okay", _("Do you really want to revoke" " the entire key? (y/N) "))) { if (menu_revkey (keyblock)) modified = 1; redisplay = 1; } } else if (cpr_get_answer_is_yes ("keyedit.revoke.subkey.okay", n1 > 1 ? _("Do you really want to revoke" " the selected subkeys? (y/N) ") : _("Do you really want to revoke" " this subkey? (y/N) "))) { if (menu_revsubkey (keyblock)) modified = 1; redisplay = 1; } if (modified) merge_keys_and_selfsig (keyblock); } break; case cmdEXPIRE: if (menu_expire (keyblock)) { merge_keys_and_selfsig (keyblock); modified = 1; redisplay = 1; } break; case cmdBACKSIGN: if (menu_backsign (keyblock)) { modified = 1; redisplay = 1; } break; case cmdPRIMARY: if (menu_set_primary_uid (keyblock)) { merge_keys_and_selfsig (keyblock); modified = 1; redisplay = 1; } break; case cmdPASSWD: change_passphrase (ctrl, keyblock); break; case cmdTRUST: if (opt.trust_model == TM_EXTERNAL) { tty_printf (_("Owner trust may not be set while " "using a user provided trust database\n")); break; } show_key_with_all_names (keyblock, 0, 0, 0, 1, 0); tty_printf ("\n"); if (edit_ownertrust (find_kbnode (keyblock, PKT_PUBLIC_KEY)->pkt->pkt. public_key, 1)) { redisplay = 1; /* No real need to set update_trust here as edit_ownertrust() calls revalidation_mark() anyway. */ update_trust = 1; } break; case cmdPREF: { int count = count_selected_uids (keyblock); assert (keyblock->pkt->pkttype == PKT_PUBLIC_KEY); show_names (keyblock, keyblock->pkt->pkt.public_key, count ? NODFLG_SELUID : 0, 1); } break; case cmdSHOWPREF: { int count = count_selected_uids (keyblock); assert (keyblock->pkt->pkttype == PKT_PUBLIC_KEY); show_names (keyblock, keyblock->pkt->pkt.public_key, count ? NODFLG_SELUID : 0, 2); } break; case cmdSETPREF: { PKT_user_id *tempuid; keygen_set_std_prefs (!*arg_string ? "default" : arg_string, 0); tempuid = keygen_get_std_prefs (); tty_printf (_("Set preference list to:\n")); show_prefs (tempuid, NULL, 1); free_user_id (tempuid); if (cpr_get_answer_is_yes ("keyedit.setpref.okay", count_selected_uids (keyblock) ? _("Really update the preferences" " for the selected user IDs? (y/N) ") : _("Really update the preferences? (y/N) "))) { if (menu_set_preferences (keyblock)) { merge_keys_and_selfsig (keyblock); modified = 1; redisplay = 1; } } } break; case cmdPREFKS: if (menu_set_keyserver_url (*arg_string ? arg_string : NULL, keyblock)) { merge_keys_and_selfsig (keyblock); modified = 1; redisplay = 1; } break; case cmdNOTATION: if (menu_set_notation (*arg_string ? arg_string : NULL, keyblock)) { merge_keys_and_selfsig (keyblock); modified = 1; redisplay = 1; } break; case cmdNOP: break; case cmdREVSIG: if (menu_revsig (keyblock)) { redisplay = 1; modified = 1; } break; case cmdENABLEKEY: case cmdDISABLEKEY: if (enable_disable_key (keyblock, cmd == cmdDISABLEKEY)) { redisplay = 1; modified = 1; } break; case cmdSHOWPHOTO: menu_showphoto (keyblock); break; case cmdCLEAN: if (menu_clean (keyblock, 0)) redisplay = modified = 1; break; case cmdMINIMIZE: if (menu_clean (keyblock, 1)) redisplay = modified = 1; break; case cmdQUIT: if (have_commands) goto leave; if (!modified) goto leave; if (!cpr_get_answer_is_yes ("keyedit.save.okay", _("Save changes? (y/N) "))) { if (cpr_enabled () || cpr_get_answer_is_yes ("keyedit.cancel.okay", _("Quit without saving? (y/N) "))) goto leave; break; } /* fall thru */ case cmdSAVE: if (modified) { err = keydb_update_keyblock (kdbhd, keyblock); if (err) { log_error (_("update failed: %s\n"), g10_errstr (err)); break; } } else tty_printf (_("Key not changed so no update needed.\n")); if (update_trust) { revalidation_mark (); update_trust = 0; } goto leave; case cmdINVCMD: default: tty_printf ("\n"); tty_printf (_("Invalid command (try \"help\")\n")); break; } } /* End of the main command loop. */ leave: release_kbnode (keyblock); keydb_release (kdbhd); xfree (answer); } /* Change the passphrase of the secret key identified by USERNAME. */ void keyedit_passwd (ctrl_t ctrl, const char *username) { gpg_error_t err; PKT_public_key *pk; kbnode_t keyblock = NULL; pk = xtrycalloc (1, sizeof *pk); if (!pk) { err = gpg_error_from_syserror (); goto leave; } err = getkey_byname (NULL, pk, username, 1, &keyblock); if (err) goto leave; err = change_passphrase (ctrl, keyblock); leave: release_kbnode (keyblock); free_public_key (pk); if (err) { log_info ("error changing the passphrase for `%s': %s\n", username, gpg_strerror (err)); write_status_error ("keyedit.passwd", err); } else write_status_text (STATUS_SUCCESS, "keyedit.passwd"); } static void tty_print_notations (int indent, PKT_signature * sig) { int first = 1; struct notation *notation, *nd; if (indent < 0) { first = 0; indent = -indent; } notation = sig_to_notation (sig); for (nd = notation; nd; nd = nd->next) { if (!first) tty_printf ("%*s", indent, ""); else first = 0; tty_print_utf8_string (nd->name, strlen (nd->name)); tty_printf ("="); tty_print_utf8_string (nd->value, strlen (nd->value)); tty_printf ("\n"); } free_notation (notation); } /* * Show preferences of a public keyblock. */ static void show_prefs (PKT_user_id * uid, PKT_signature * selfsig, int verbose) { const prefitem_t fake = { 0, 0 }; const prefitem_t *prefs; int i; if (!uid) return; if (uid->prefs) prefs = uid->prefs; else if (verbose) prefs = &fake; else return; if (verbose) { int any, des_seen = 0, sha1_seen = 0, uncomp_seen = 0; tty_printf (" "); tty_printf (_("Cipher: ")); for (i = any = 0; prefs[i].type; i++) { if (prefs[i].type == PREFTYPE_SYM) { if (any) tty_printf (", "); any = 1; /* We don't want to display strings for experimental algos */ if (!openpgp_cipher_test_algo (prefs[i].value) && prefs[i].value < 100) tty_printf ("%s", openpgp_cipher_algo_name (prefs[i].value)); else tty_printf ("[%d]", prefs[i].value); if (prefs[i].value == CIPHER_ALGO_3DES) des_seen = 1; } } if (!des_seen) { if (any) tty_printf (", "); tty_printf ("%s", openpgp_cipher_algo_name (CIPHER_ALGO_3DES)); } tty_printf ("\n "); tty_printf (_("Digest: ")); for (i = any = 0; prefs[i].type; i++) { if (prefs[i].type == PREFTYPE_HASH) { if (any) tty_printf (", "); any = 1; /* We don't want to display strings for experimental algos */ if (!gcry_md_test_algo (prefs[i].value) && prefs[i].value < 100) tty_printf ("%s", gcry_md_algo_name (prefs[i].value)); else tty_printf ("[%d]", prefs[i].value); if (prefs[i].value == DIGEST_ALGO_SHA1) sha1_seen = 1; } } if (!sha1_seen) { if (any) tty_printf (", "); tty_printf ("%s", gcry_md_algo_name (DIGEST_ALGO_SHA1)); } tty_printf ("\n "); tty_printf (_("Compression: ")); for (i = any = 0; prefs[i].type; i++) { if (prefs[i].type == PREFTYPE_ZIP) { const char *s = compress_algo_to_string (prefs[i].value); if (any) tty_printf (", "); any = 1; /* We don't want to display strings for experimental algos */ if (s && prefs[i].value < 100) tty_printf ("%s", s); else tty_printf ("[%d]", prefs[i].value); if (prefs[i].value == COMPRESS_ALGO_NONE) uncomp_seen = 1; } } if (!uncomp_seen) { if (any) tty_printf (", "); else { tty_printf ("%s", compress_algo_to_string (COMPRESS_ALGO_ZIP)); tty_printf (", "); } tty_printf ("%s", compress_algo_to_string (COMPRESS_ALGO_NONE)); } if (uid->flags.mdc || !uid->flags.ks_modify) { tty_printf ("\n "); tty_printf (_("Features: ")); any = 0; if (uid->flags.mdc) { tty_printf ("MDC"); any = 1; } if (!uid->flags.ks_modify) { if (any) tty_printf (", "); tty_printf (_("Keyserver no-modify")); } } tty_printf ("\n"); if (selfsig) { const byte *pref_ks; size_t pref_ks_len; pref_ks = parse_sig_subpkt (selfsig->hashed, SIGSUBPKT_PREF_KS, &pref_ks_len); if (pref_ks && pref_ks_len) { tty_printf (" "); tty_printf (_("Preferred keyserver: ")); tty_print_utf8_string (pref_ks, pref_ks_len); tty_printf ("\n"); } if (selfsig->flags.notation) { tty_printf (" "); tty_printf (_("Notations: ")); tty_print_notations (5 + strlen (_("Notations: ")), selfsig); } } } else { tty_printf (" "); for (i = 0; prefs[i].type; i++) { tty_printf (" %c%d", prefs[i].type == PREFTYPE_SYM ? 'S' : prefs[i].type == PREFTYPE_HASH ? 'H' : prefs[i].type == PREFTYPE_ZIP ? 'Z' : '?', prefs[i].value); } if (uid->flags.mdc) tty_printf (" [mdc]"); if (!uid->flags.ks_modify) tty_printf (" [no-ks-modify]"); tty_printf ("\n"); } } /* This is the version of show_key_with_all_names used when opt.with_colons is used. It prints all available data in a easy to parse format and does not translate utf8 */ static void show_key_with_all_names_colon (KBNODE keyblock) { KBNODE node; int i, j, ulti_hack = 0; byte pk_version = 0; PKT_public_key *primary = NULL; /* the keys */ for (node = keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_KEY || (node->pkt->pkttype == PKT_PUBLIC_SUBKEY)) { PKT_public_key *pk = node->pkt->pkt.public_key; u32 keyid[2]; if (node->pkt->pkttype == PKT_PUBLIC_KEY) { pk_version = pk->version; primary = pk; } keyid_from_pk (pk, keyid); fputs (node->pkt->pkttype == PKT_PUBLIC_KEY ? "pub:" : "sub:", stdout); if (!pk->flags.valid) putchar ('i'); else if (pk->flags.revoked) putchar ('r'); else if (pk->has_expired) putchar ('e'); else if (!(opt.fast_list_mode || opt.no_expensive_trust_checks)) { int trust = get_validity_info (pk, NULL); if (trust == 'u') ulti_hack = 1; putchar (trust); } printf (":%u:%d:%08lX%08lX:%lu:%lu::", nbits_from_pk (pk), pk->pubkey_algo, (ulong) keyid[0], (ulong) keyid[1], (ulong) pk->timestamp, (ulong) pk->expiredate); if (node->pkt->pkttype == PKT_PUBLIC_KEY && !(opt.fast_list_mode || opt.no_expensive_trust_checks)) putchar (get_ownertrust_info (pk)); putchar (':'); putchar (':'); putchar (':'); /* Print capabilities. */ if ((pk->pubkey_usage & PUBKEY_USAGE_ENC)) putchar ('e'); if ((pk->pubkey_usage & PUBKEY_USAGE_SIG)) putchar ('s'); if ((pk->pubkey_usage & PUBKEY_USAGE_CERT)) putchar ('c'); if ((pk->pubkey_usage & PUBKEY_USAGE_AUTH)) putchar ('a'); putchar ('\n'); print_fingerprint (pk, 0); print_revokers (pk); } } /* the user ids */ i = 0; for (node = keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_USER_ID) { PKT_user_id *uid = node->pkt->pkt.user_id; ++i; if (uid->attrib_data) printf ("uat:"); else printf ("uid:"); if (uid->is_revoked) printf ("r::::::::"); else if (uid->is_expired) printf ("e::::::::"); else if (opt.fast_list_mode || opt.no_expensive_trust_checks) printf ("::::::::"); else { int uid_validity; if (primary && !ulti_hack) uid_validity = get_validity_info (primary, uid); else uid_validity = 'u'; printf ("%c::::::::", uid_validity); } if (uid->attrib_data) printf ("%u %lu", uid->numattribs, uid->attrib_len); else es_write_sanitized (es_stdout, uid->name, uid->len, ":", NULL); putchar (':'); /* signature class */ putchar (':'); /* capabilities */ putchar (':'); /* preferences */ if (pk_version > 3 || uid->selfsigversion > 3) { const prefitem_t *prefs = uid->prefs; for (j = 0; prefs && prefs[j].type; j++) { if (j) putchar (' '); printf ("%c%d", prefs[j].type == PREFTYPE_SYM ? 'S' : prefs[j].type == PREFTYPE_HASH ? 'H' : prefs[j].type == PREFTYPE_ZIP ? 'Z' : '?', prefs[j].value); } if (uid->flags.mdc) printf (",mdc"); if (!uid->flags.ks_modify) printf (",no-ks-modify"); } putchar (':'); /* flags */ printf ("%d,", i); if (uid->is_primary) putchar ('p'); if (uid->is_revoked) putchar ('r'); if (uid->is_expired) putchar ('e'); if ((node->flag & NODFLG_SELUID)) putchar ('s'); if ((node->flag & NODFLG_MARK_A)) putchar ('m'); putchar (':'); putchar ('\n'); } } } static void show_names (KBNODE keyblock, PKT_public_key * pk, unsigned int flag, int with_prefs) { KBNODE node; int i = 0; for (node = keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_USER_ID && !is_deleted_kbnode (node)) { PKT_user_id *uid = node->pkt->pkt.user_id; ++i; if (!flag || (flag && (node->flag & flag))) { if (!(flag & NODFLG_MARK_A) && pk) tty_printf ("%s ", uid_trust_string_fixed (pk, uid)); if (flag & NODFLG_MARK_A) tty_printf (" "); else if (node->flag & NODFLG_SELUID) tty_printf ("(%d)* ", i); else if (uid->is_primary) tty_printf ("(%d). ", i); else tty_printf ("(%d) ", i); tty_print_utf8_string (uid->name, uid->len); tty_printf ("\n"); if (with_prefs && pk) { if (pk->version > 3 || uid->selfsigversion > 3) { PKT_signature *selfsig = NULL; KBNODE signode; for (signode = node->next; signode && signode->pkt->pkttype == PKT_SIGNATURE; signode = signode->next) { if (signode->pkt->pkt.signature-> flags.chosen_selfsig) { selfsig = signode->pkt->pkt.signature; break; } } show_prefs (uid, selfsig, with_prefs == 2); } else tty_printf (_("There are no preferences on a" " PGP 2.x-style user ID.\n")); } } } } } /* * Display the key a the user ids, if only_marked is true, do only * so for user ids with mark A flag set and dont display the index number */ static void show_key_with_all_names (KBNODE keyblock, int only_marked, int with_revoker, int with_fpr, int with_subkeys, int with_prefs) { KBNODE node; int i; int do_warn = 0; PKT_public_key *primary = NULL; if (opt.with_colons) { show_key_with_all_names_colon (keyblock); return; } /* the keys */ for (node = keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_KEY || (with_subkeys && node->pkt->pkttype == PKT_PUBLIC_SUBKEY && !is_deleted_kbnode (node))) { PKT_public_key *pk = node->pkt->pkt.public_key; const char *otrust = "err", *trust = "err"; if (node->pkt->pkttype == PKT_PUBLIC_KEY) { /* do it here, so that debug messages don't clutter the * output */ static int did_warn = 0; trust = get_validity_string (pk, NULL); otrust = get_ownertrust_string (pk); /* Show a warning once */ if (!did_warn && (get_validity (pk, NULL) & TRUST_FLAG_PENDING_CHECK)) { did_warn = 1; do_warn = 1; } primary = pk; } if (pk->flags.revoked) { char *user = get_user_id_string_native (pk->revoked.keyid); tty_printf (_("The following key was revoked on" " %s by %s key %s\n"), revokestr_from_pk (pk), gcry_pk_algo_name (pk->revoked.algo), user); xfree (user); } if (with_revoker) { if (!pk->revkey && pk->numrevkeys) BUG (); else for (i = 0; i < pk->numrevkeys; i++) { u32 r_keyid[2]; char *user; const char *algo; algo = gcry_pk_algo_name (pk->revkey[i].algid); keyid_from_fingerprint (pk->revkey[i].fpr, MAX_FINGERPRINT_LEN, r_keyid); user = get_user_id_string_native (r_keyid); tty_printf (_("This key may be revoked by %s key %s"), algo ? algo : "?", user); if (pk->revkey[i].class & 0x40) { tty_printf (" "); tty_printf (_("(sensitive)")); } tty_printf ("\n"); xfree (user); } } keyid_from_pk (pk, NULL); tty_printf ("%s%c %4u%c/%s ", node->pkt->pkttype == PKT_PUBLIC_KEY ? "pub" : node->pkt->pkttype == PKT_PUBLIC_SUBKEY ? "sub" : node->pkt->pkttype == PKT_SECRET_KEY ? "sec" : "ssb", (node->flag & NODFLG_SELKEY) ? '*' : ' ', nbits_from_pk (pk), pubkey_letter (pk->pubkey_algo), keystr (pk->keyid)); tty_printf (_("created: %s"), datestr_from_pk (pk)); tty_printf (" "); if (pk->flags.revoked) tty_printf (_("revoked: %s"), revokestr_from_pk (pk)); else if (pk->has_expired) tty_printf (_("expired: %s"), expirestr_from_pk (pk)); else tty_printf (_("expires: %s"), expirestr_from_pk (pk)); tty_printf (" "); tty_printf (_("usage: %s"), usagestr_from_pk (pk)); tty_printf ("\n"); if (pk->seckey_info && pk->seckey_info->is_protected && pk->seckey_info->s2k.mode == 1002) { tty_printf (" "); tty_printf (_("card-no: ")); if (pk->seckey_info->ivlen == 16 && !memcmp (pk->seckey_info->iv, "\xD2\x76\x00\x01\x24\x01", 6)) { /* This is an OpenPGP card. */ for (i = 8; i < 14; i++) { if (i == 10) tty_printf (" "); tty_printf ("%02X", pk->seckey_info->iv[i]); } } else { /* Unknown card: Print all. */ for (i = 0; i < pk->seckey_info->ivlen; i++) tty_printf ("%02X", pk->seckey_info->iv[i]); } tty_printf ("\n"); } if (node->pkt->pkttype == PKT_PUBLIC_KEY || node->pkt->pkttype == PKT_SECRET_KEY) { if (opt.trust_model != TM_ALWAYS) { tty_printf ("%*s", (int) keystrlen () + 13, ""); /* Ownertrust is only meaningful for the PGP or classic trust models */ if (opt.trust_model == TM_PGP || opt.trust_model == TM_CLASSIC) { int width = 14 - strlen (otrust); if (width <= 0) width = 1; tty_printf (_("trust: %s"), otrust); tty_printf ("%*s", width, ""); } tty_printf (_("validity: %s"), trust); tty_printf ("\n"); } if (node->pkt->pkttype == PKT_PUBLIC_KEY && (get_ownertrust (pk) & TRUST_FLAG_DISABLED)) { tty_printf ("*** "); tty_printf (_("This key has been disabled")); tty_printf ("\n"); } } if ((node->pkt->pkttype == PKT_PUBLIC_KEY || node->pkt->pkttype == PKT_SECRET_KEY) && with_fpr) { print_fingerprint (pk, 2); tty_printf ("\n"); } } } show_names (keyblock, primary, only_marked ? NODFLG_MARK_A : 0, with_prefs); if (do_warn) tty_printf (_("Please note that the shown key validity" " is not necessarily correct\n" "unless you restart the program.\n")); } /* Display basic key information. This function is suitable to show information on the key without any dependencies on the trustdb or any other internal GnuPG stuff. KEYBLOCK may either be a public or a secret key.*/ void show_basic_key_info (KBNODE keyblock) { KBNODE node; int i; /* The primary key */ for (node = keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_KEY || node->pkt->pkttype == PKT_SECRET_KEY) { PKT_public_key *pk = node->pkt->pkt.public_key; /* Note, we use the same format string as in other show functions to make the translation job easier. */ tty_printf ("%s %4u%c/%s ", node->pkt->pkttype == PKT_PUBLIC_KEY ? "pub" : node->pkt->pkttype == PKT_PUBLIC_SUBKEY ? "sub" : node->pkt->pkttype == PKT_SECRET_KEY ? "sec" :"ssb", nbits_from_pk (pk), pubkey_letter (pk->pubkey_algo), keystr_from_pk (pk)); tty_printf (_("created: %s"), datestr_from_pk (pk)); tty_printf (" "); tty_printf (_("expires: %s"), expirestr_from_pk (pk)); tty_printf ("\n"); print_fingerprint (pk, 3); tty_printf ("\n"); } } /* The user IDs. */ for (i = 0, node = keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_USER_ID) { PKT_user_id *uid = node->pkt->pkt.user_id; ++i; tty_printf (" "); if (uid->is_revoked) tty_printf ("[%s] ", _("revoked")); else if (uid->is_expired) tty_printf ("[%s] ", _("expired")); tty_print_utf8_string (uid->name, uid->len); tty_printf ("\n"); } } } static void show_key_and_fingerprint (KBNODE keyblock) { KBNODE node; PKT_public_key *pk = NULL; for (node = keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_KEY) { pk = node->pkt->pkt.public_key; tty_printf ("pub %4u%c/%s %s ", nbits_from_pk (pk), pubkey_letter (pk->pubkey_algo), keystr_from_pk (pk), datestr_from_pk (pk)); } else if (node->pkt->pkttype == PKT_USER_ID) { PKT_user_id *uid = node->pkt->pkt.user_id; tty_print_utf8_string (uid->name, uid->len); break; } } tty_printf ("\n"); if (pk) print_fingerprint (pk, 2); } /* Show a warning if no uids on the key have the primary uid flag set. */ static void no_primary_warning (KBNODE keyblock) { KBNODE node; int have_primary = 0, uid_count = 0; /* TODO: if we ever start behaving differently with a primary or non-primary attribute ID, we will need to check for attributes here as well. */ for (node = keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_USER_ID && node->pkt->pkt.user_id->attrib_data == NULL) { uid_count++; if (node->pkt->pkt.user_id->is_primary == 2) { have_primary = 1; break; } } } if (uid_count > 1 && !have_primary) log_info (_ ("WARNING: no user ID has been marked as primary. This command" " may\n cause a different user ID to become" " the assumed primary.\n")); } /* * Ask for a new user id, add the self-signature and update the keyblock. * Return true if there is a new user id */ static int menu_adduid (KBNODE pub_keyblock, int photo, const char *photo_name) { PKT_user_id *uid; PKT_public_key *pk = NULL; PKT_signature *sig = NULL; PACKET *pkt; KBNODE node; KBNODE pub_where = NULL; gpg_error_t err; for (node = pub_keyblock; node; pub_where = node, node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_KEY) pk = node->pkt->pkt.public_key; else if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY) break; } if (!node) /* No subkey. */ pub_where = NULL; assert (pk); if (photo) { int hasattrib = 0; for (node = pub_keyblock; node; node = node->next) if (node->pkt->pkttype == PKT_USER_ID && node->pkt->pkt.user_id->attrib_data != NULL) { hasattrib = 1; break; } /* It is legal but bad for compatibility to add a photo ID to a v3 key as it means that PGP2 will not be able to use that key anymore. Also, PGP may not expect a photo on a v3 key. Don't bother to ask this if the key already has a photo - any damage has already been done at that point. -dms */ if (pk->version == 3 && !hasattrib) { if (opt.expert) { tty_printf (_("WARNING: This is a PGP2-style key. " "Adding a photo ID may cause some versions\n" " of PGP to reject this key.\n")); if (!cpr_get_answer_is_yes ("keyedit.v3_photo.okay", _("Are you sure you still want " "to add it? (y/N) "))) return 0; } else { tty_printf (_("You may not add a photo ID to " "a PGP2-style key.\n")); return 0; } } uid = generate_photo_id (pk, photo_name); } else uid = generate_user_id (pub_keyblock); if (!uid) return 0; err = make_keysig_packet (&sig, pk, uid, NULL, pk, 0x13, 0, 0, 0, 0, keygen_add_std_prefs, pk, NULL); if (err) { log_error ("signing failed: %s\n", g10_errstr (err)); free_user_id (uid); return 0; } /* Insert/append to public keyblock */ pkt = xmalloc_clear (sizeof *pkt); pkt->pkttype = PKT_USER_ID; pkt->pkt.user_id = uid; node = new_kbnode (pkt); if (pub_where) insert_kbnode (pub_where, node, 0); else add_kbnode (pub_keyblock, node); pkt = xmalloc_clear (sizeof *pkt); pkt->pkttype = PKT_SIGNATURE; pkt->pkt.signature = copy_signature (NULL, sig); if (pub_where) insert_kbnode (node, new_kbnode (pkt), 0); else add_kbnode (pub_keyblock, new_kbnode (pkt)); return 1; } /* * Remove all selected userids from the keyring */ static void menu_deluid (KBNODE pub_keyblock) { KBNODE node; int selected = 0; for (node = pub_keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_USER_ID) { selected = node->flag & NODFLG_SELUID; if (selected) { /* Only cause a trust update if we delete a non-revoked user id */ if (!node->pkt->pkt.user_id->is_revoked) update_trust = 1; delete_kbnode (node); } } else if (selected && node->pkt->pkttype == PKT_SIGNATURE) delete_kbnode (node); else if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY) selected = 0; } commit_kbnode (&pub_keyblock); } static int menu_delsig (KBNODE pub_keyblock) { KBNODE node; PKT_user_id *uid = NULL; int changed = 0; for (node = pub_keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_USER_ID) { uid = (node->flag & NODFLG_SELUID) ? node->pkt->pkt.user_id : NULL; } else if (uid && node->pkt->pkttype == PKT_SIGNATURE) { int okay, valid, selfsig, inv_sig, no_key, other_err; tty_printf ("uid "); tty_print_utf8_string (uid->name, uid->len); tty_printf ("\n"); okay = inv_sig = no_key = other_err = 0; if (opt.with_colons) valid = print_and_check_one_sig_colon (pub_keyblock, node, &inv_sig, &no_key, &other_err, &selfsig, 1); else valid = print_and_check_one_sig (pub_keyblock, node, &inv_sig, &no_key, &other_err, &selfsig, 1); if (valid) { okay = cpr_get_answer_yes_no_quit ("keyedit.delsig.valid", _("Delete this good signature? (y/N/q)")); /* Only update trust if we delete a good signature. The other two cases do not affect trust. */ if (okay) update_trust = 1; } else if (inv_sig || other_err) okay = cpr_get_answer_yes_no_quit ("keyedit.delsig.invalid", _("Delete this invalid signature? (y/N/q)")); else if (no_key) okay = cpr_get_answer_yes_no_quit ("keyedit.delsig.unknown", _("Delete this unknown signature? (y/N/q)")); if (okay == -1) break; if (okay && selfsig && !cpr_get_answer_is_yes ("keyedit.delsig.selfsig", _("Really delete this self-signature? (y/N)"))) okay = 0; if (okay) { delete_kbnode (node); changed++; } } else if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY) uid = NULL; } if (changed) { commit_kbnode (&pub_keyblock); tty_printf (changed == 1 ? _("Deleted %d signature.\n") : _("Deleted %d signatures.\n"), changed); } else tty_printf (_("Nothing deleted.\n")); return changed; } static int menu_clean (KBNODE keyblock, int self_only) { KBNODE uidnode; int modified = 0, select_all = !count_selected_uids (keyblock); for (uidnode = keyblock->next; uidnode && uidnode->pkt->pkttype != PKT_PUBLIC_SUBKEY; uidnode = uidnode->next) { if (uidnode->pkt->pkttype == PKT_USER_ID && (uidnode->flag & NODFLG_SELUID || select_all)) { int uids = 0, sigs = 0; char *user = utf8_to_native (uidnode->pkt->pkt.user_id->name, uidnode->pkt->pkt.user_id->len, 0); clean_one_uid (keyblock, uidnode, opt.verbose, self_only, &uids, &sigs); if (uids) { const char *reason; if (uidnode->pkt->pkt.user_id->is_revoked) reason = _("revoked"); else if (uidnode->pkt->pkt.user_id->is_expired) reason = _("expired"); else reason = _("invalid"); tty_printf (_("User ID \"%s\" compacted: %s\n"), user, reason); modified = 1; } else if (sigs) { tty_printf (sigs == 1 ? _("User ID \"%s\": %d signature removed\n") : _("User ID \"%s\": %d signatures removed\n"), user, sigs); modified = 1; } else { tty_printf (self_only == 1 ? _("User ID \"%s\": already minimized\n") : _("User ID \"%s\": already clean\n"), user); } xfree (user); } } return modified; } /* * Remove some of the secondary keys */ static void menu_delkey (KBNODE pub_keyblock) { KBNODE node; int selected = 0; for (node = pub_keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY) { selected = node->flag & NODFLG_SELKEY; if (selected) delete_kbnode (node); } else if (selected && node->pkt->pkttype == PKT_SIGNATURE) delete_kbnode (node); else selected = 0; } commit_kbnode (&pub_keyblock); /* No need to set update_trust here since signing keys are no longer used to certify other keys, so there is no change in trust when revoking/removing them. */ } /* * Ask for a new revoker, create the self-signature and put it into * the keyblock. Returns true if there is a new revoker. */ static int menu_addrevoker (ctrl_t ctrl, kbnode_t pub_keyblock, int sensitive) { PKT_public_key *pk = NULL; PKT_public_key *revoker_pk = NULL; PKT_signature *sig = NULL; PACKET *pkt; struct revocation_key revkey; size_t fprlen; int rc; assert (pub_keyblock->pkt->pkttype == PKT_PUBLIC_KEY); pk = pub_keyblock->pkt->pkt.public_key; if (pk->numrevkeys == 0 && pk->version == 3) { /* It is legal but bad for compatibility to add a revoker to a v3 key as it means that PGP2 will not be able to use that key anymore. Also, PGP may not expect a revoker on a v3 key. Don't bother to ask this if the key already has a revoker - any damage has already been done at that point. -dms */ if (opt.expert) { tty_printf (_("WARNING: This is a PGP 2.x-style key. " "Adding a designated revoker may cause\n" " some versions of PGP to reject this key.\n")); if (!cpr_get_answer_is_yes ("keyedit.v3_revoker.okay", _("Are you sure you still want " "to add it? (y/N) "))) return 0; } else { tty_printf (_("You may not add a designated revoker to " "a PGP 2.x-style key.\n")); return 0; } } for (;;) { char *answer; free_public_key (revoker_pk); revoker_pk = xmalloc_clear (sizeof (*revoker_pk)); tty_printf ("\n"); answer = cpr_get_utf8 ("keyedit.add_revoker", _("Enter the user ID of the designated revoker: ")); if (answer[0] == '\0' || answer[0] == CONTROL_D) { xfree (answer); goto fail; } /* Note that I'm requesting CERT here, which usually implies primary keys only, but some casual testing shows that PGP and GnuPG both can handle a designated revocation from a subkey. */ revoker_pk->req_usage = PUBKEY_USAGE_CERT; rc = get_pubkey_byname (ctrl, NULL, revoker_pk, answer, NULL, NULL, 1, 1); if (rc) { log_error (_("key \"%s\" not found: %s\n"), answer, g10_errstr (rc)); xfree (answer); continue; } xfree (answer); fingerprint_from_pk (revoker_pk, revkey.fpr, &fprlen); if (fprlen != 20) { log_error (_("cannot appoint a PGP 2.x style key as a " "designated revoker\n")); continue; } revkey.class = 0x80; if (sensitive) revkey.class |= 0x40; revkey.algid = revoker_pk->pubkey_algo; if (cmp_public_keys (revoker_pk, pk) == 0) { /* This actually causes no harm (after all, a key that designates itself as a revoker is the same as a regular key), but it's easy enough to check. */ log_error (_("you cannot appoint a key as its own " "designated revoker\n")); continue; } keyid_from_pk (pk, NULL); /* Does this revkey already exist? */ if (!pk->revkey && pk->numrevkeys) BUG (); else { int i; for (i = 0; i < pk->numrevkeys; i++) { if (memcmp (&pk->revkey[i], &revkey, sizeof (struct revocation_key)) == 0) { char buf[50]; log_error (_("this key has already been designated " "as a revoker\n")); sprintf (buf, "%08lX%08lX", (ulong) pk->keyid[0], (ulong) pk->keyid[1]); write_status_text (STATUS_ALREADY_SIGNED, buf); break; } } if (i < pk->numrevkeys) continue; } print_pubkey_info (NULL, revoker_pk); print_fingerprint (revoker_pk, 2); tty_printf ("\n"); tty_printf (_("WARNING: appointing a key as a designated revoker " "cannot be undone!\n")); tty_printf ("\n"); if (!cpr_get_answer_is_yes ("keyedit.add_revoker.okay", _("Are you sure you want to appoint this " "key as a designated revoker? (y/N) "))) continue; free_public_key (revoker_pk); revoker_pk = NULL; break; } /* The 1F signature must be at least v4 to carry the revocation key subpacket. */ rc = make_keysig_packet (&sig, pk, NULL, NULL, pk, 0x1F, 0, 4, 0, 0, keygen_add_revkey, &revkey, NULL); if (rc) { log_error ("signing failed: %s\n", g10_errstr (rc)); goto fail; } /* Insert into public keyblock. */ pkt = xmalloc_clear (sizeof *pkt); pkt->pkttype = PKT_SIGNATURE; pkt->pkt.signature = sig; insert_kbnode (pub_keyblock, new_kbnode (pkt), PKT_SIGNATURE); return 1; fail: if (sig) free_seckey_enc (sig); free_public_key (revoker_pk); return 0; } static int menu_expire (KBNODE pub_keyblock) { int n1, signumber, rc; u32 expiredate; int mainkey = 0; PKT_public_key *main_pk, *sub_pk; PKT_user_id *uid; KBNODE node; u32 keyid[2]; n1 = count_selected_keys (pub_keyblock); if (n1 > 1) { tty_printf (_("Please select at most one subkey.\n")); return 0; } else if (n1) tty_printf (_("Changing expiration time for a subkey.\n")); else { tty_printf (_("Changing expiration time for the primary key.\n")); mainkey = 1; no_primary_warning (pub_keyblock); } expiredate = ask_expiredate (); /* Now we can actually change the self-signature(s) */ main_pk = sub_pk = NULL; uid = NULL; signumber = 0; for (node = pub_keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_KEY) { main_pk = node->pkt->pkt.public_key; keyid_from_pk (main_pk, keyid); main_pk->expiredate = expiredate; } else if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY && (node->flag & NODFLG_SELKEY)) { sub_pk = node->pkt->pkt.public_key; sub_pk->expiredate = expiredate; } else if (node->pkt->pkttype == PKT_USER_ID) uid = node->pkt->pkt.user_id; else if (main_pk && node->pkt->pkttype == PKT_SIGNATURE && (mainkey || sub_pk)) { PKT_signature *sig = node->pkt->pkt.signature; if (keyid[0] == sig->keyid[0] && keyid[1] == sig->keyid[1] && ((mainkey && uid && uid->created && (sig->sig_class & ~3) == 0x10) || (!mainkey && sig->sig_class == 0x18)) && sig->flags.chosen_selfsig) { /* This is a self-signature which is to be replaced. */ PKT_signature *newsig; PACKET *newpkt; signumber++; if ((mainkey && main_pk->version < 4) || (!mainkey && sub_pk->version < 4)) { log_info (_("You can't change the expiration date of a v3 key\n")); return 0; } if (mainkey) rc = update_keysig_packet (&newsig, sig, main_pk, uid, NULL, main_pk, keygen_add_key_expire, main_pk); else rc = update_keysig_packet (&newsig, sig, main_pk, NULL, sub_pk, main_pk, keygen_add_key_expire, sub_pk); if (rc) { log_error ("make_keysig_packet failed: %s\n", g10_errstr (rc)); return 0; } /* Replace the packet. */ newpkt = xmalloc_clear (sizeof *newpkt); newpkt->pkttype = PKT_SIGNATURE; newpkt->pkt.signature = newsig; free_packet (node->pkt); xfree (node->pkt); node->pkt = newpkt; sub_pk = NULL; } } } update_trust = 1; return 1; } static int menu_backsign (KBNODE pub_keyblock) { int rc, modified = 0; PKT_public_key *main_pk; KBNODE node; u32 timestamp; assert (pub_keyblock->pkt->pkttype == PKT_PUBLIC_KEY); merge_keys_and_selfsig (pub_keyblock); main_pk = pub_keyblock->pkt->pkt.public_key; keyid_from_pk (main_pk, NULL); /* We use the same timestamp for all backsigs so that we don't reveal information about the used machine. */ timestamp = make_timestamp (); for (node = pub_keyblock; node; node = node->next) { PKT_public_key *sub_pk = NULL; KBNODE node2, sig_pk = NULL /*,sig_sk = NULL*/; /* char *passphrase; */ /* Find a signing subkey with no backsig */ if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY) { if (node->pkt->pkt.public_key->pubkey_usage & PUBKEY_USAGE_SIG) { if (node->pkt->pkt.public_key->flags.backsig) tty_printf (_ ("signing subkey %s is already cross-certified\n"), keystr_from_pk (node->pkt->pkt.public_key)); else sub_pk = node->pkt->pkt.public_key; } else tty_printf (_("subkey %s does not sign and so does" " not need to be cross-certified\n"), keystr_from_pk (node->pkt->pkt.public_key)); } if (!sub_pk) continue; /* Find the selected selfsig on this subkey */ for (node2 = node->next; node2 && node2->pkt->pkttype == PKT_SIGNATURE; node2 = node2->next) if (node2->pkt->pkt.signature->version >= 4 && node2->pkt->pkt.signature->flags.chosen_selfsig) { sig_pk = node2; break; } if (!sig_pk) continue; /* Find the secret subkey that matches the public subkey */ log_debug ("FIXME: Check whether a secret subkey is available.\n"); /* if (!sub_sk) */ /* { */ /* tty_printf (_("no secret subkey for public subkey %s - ignoring\n"), */ /* keystr_from_pk (sub_pk)); */ /* continue; */ /* } */ /* Now we can get to work. */ rc = make_backsig (sig_pk->pkt->pkt.signature, main_pk, sub_pk, sub_pk, timestamp, NULL); if (!rc) { PKT_signature *newsig; PACKET *newpkt; rc = update_keysig_packet (&newsig, sig_pk->pkt->pkt.signature, main_pk, NULL, sub_pk, main_pk, NULL, NULL); if (!rc) { /* Put the new sig into place on the pubkey */ newpkt = xmalloc_clear (sizeof (*newpkt)); newpkt->pkttype = PKT_SIGNATURE; newpkt->pkt.signature = newsig; free_packet (sig_pk->pkt); xfree (sig_pk->pkt); sig_pk->pkt = newpkt; modified = 1; } else { log_error ("update_keysig_packet failed: %s\n", g10_errstr (rc)); break; } } else { log_error ("make_backsig failed: %s\n", g10_errstr (rc)); break; } } return modified; } static int change_primary_uid_cb (PKT_signature * sig, void *opaque) { byte buf[1]; /* first clear all primary uid flags so that we are sure none are * lingering around */ delete_sig_subpkt (sig->hashed, SIGSUBPKT_PRIMARY_UID); delete_sig_subpkt (sig->unhashed, SIGSUBPKT_PRIMARY_UID); /* if opaque is set,we want to set the primary id */ if (opaque) { buf[0] = 1; build_sig_subpkt (sig, SIGSUBPKT_PRIMARY_UID, buf, 1); } return 0; } /* * Set the primary uid flag for the selected UID. We will also reset * all other primary uid flags. For this to work with have to update * all the signature timestamps. If we would do this with the current * time, we lose quite a lot of information, so we use a a kludge to * do this: Just increment the timestamp by one second which is * sufficient to updated a signature during import. */ static int menu_set_primary_uid (KBNODE pub_keyblock) { PKT_public_key *main_pk; PKT_user_id *uid; KBNODE node; u32 keyid[2]; int selected; int attribute = 0; int modified = 0; if (count_selected_uids (pub_keyblock) != 1) { tty_printf (_("Please select exactly one user ID.\n")); return 0; } main_pk = NULL; uid = NULL; selected = 0; /* Is our selected uid an attribute packet? */ for (node = pub_keyblock; node; node = node->next) if (node->pkt->pkttype == PKT_USER_ID && node->flag & NODFLG_SELUID) attribute = (node->pkt->pkt.user_id->attrib_data != NULL); for (node = pub_keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY) break; /* No more user ids expected - ready. */ if (node->pkt->pkttype == PKT_PUBLIC_KEY) { main_pk = node->pkt->pkt.public_key; keyid_from_pk (main_pk, keyid); } else if (node->pkt->pkttype == PKT_USER_ID) { uid = node->pkt->pkt.user_id; selected = node->flag & NODFLG_SELUID; } else if (main_pk && uid && node->pkt->pkttype == PKT_SIGNATURE) { PKT_signature *sig = node->pkt->pkt.signature; if (keyid[0] == sig->keyid[0] && keyid[1] == sig->keyid[1] && (uid && (sig->sig_class & ~3) == 0x10) && attribute == (uid->attrib_data != NULL) && sig->flags.chosen_selfsig) { if (sig->version < 4) { char *user = utf8_to_native (uid->name, strlen (uid->name), 0); log_info (_("skipping v3 self-signature on user ID \"%s\"\n"), user); xfree (user); } else { /* This is a selfsignature which is to be replaced. We can just ignore v3 signatures because they are not able to carry the primary ID flag. We also ignore self-sigs on user IDs that are not of the same type that we are making primary. That is, if we are making a user ID primary, we alter user IDs. If we are making an attribute packet primary, we alter attribute packets. */ /* FIXME: We must make sure that we only have one self-signature per user ID here (not counting revocations) */ PKT_signature *newsig; PACKET *newpkt; const byte *p; int action; /* See whether this signature has the primary UID flag. */ p = parse_sig_subpkt (sig->hashed, SIGSUBPKT_PRIMARY_UID, NULL); if (!p) p = parse_sig_subpkt (sig->unhashed, SIGSUBPKT_PRIMARY_UID, NULL); if (p && *p) /* yes */ action = selected ? 0 : -1; else /* no */ action = selected ? 1 : 0; if (action) { int rc = update_keysig_packet (&newsig, sig, main_pk, uid, NULL, main_pk, change_primary_uid_cb, action > 0 ? "x" : NULL); if (rc) { log_error ("update_keysig_packet failed: %s\n", g10_errstr (rc)); return 0; } /* replace the packet */ newpkt = xmalloc_clear (sizeof *newpkt); newpkt->pkttype = PKT_SIGNATURE; newpkt->pkt.signature = newsig; free_packet (node->pkt); xfree (node->pkt); node->pkt = newpkt; modified = 1; } } } } } return modified; } /* * Set preferences to new values for the selected user IDs */ static int menu_set_preferences (KBNODE pub_keyblock) { PKT_public_key *main_pk; PKT_user_id *uid; KBNODE node; u32 keyid[2]; int selected, select_all; int modified = 0; no_primary_warning (pub_keyblock); select_all = !count_selected_uids (pub_keyblock); /* Now we can actually change the self signature(s) */ main_pk = NULL; uid = NULL; selected = 0; for (node = pub_keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY) break; /* No more user-ids expected - ready. */ if (node->pkt->pkttype == PKT_PUBLIC_KEY) { main_pk = node->pkt->pkt.public_key; keyid_from_pk (main_pk, keyid); } else if (node->pkt->pkttype == PKT_USER_ID) { uid = node->pkt->pkt.user_id; selected = select_all || (node->flag & NODFLG_SELUID); } else if (main_pk && uid && selected && node->pkt->pkttype == PKT_SIGNATURE) { PKT_signature *sig = node->pkt->pkt.signature; if (keyid[0] == sig->keyid[0] && keyid[1] == sig->keyid[1] && (uid && (sig->sig_class & ~3) == 0x10) && sig->flags.chosen_selfsig) { if (sig->version < 4) { char *user = utf8_to_native (uid->name, strlen (uid->name), 0); log_info (_("skipping v3 self-signature on user ID \"%s\"\n"), user); xfree (user); } else { /* This is a selfsignature which is to be replaced * We have to ignore v3 signatures because they are * not able to carry the preferences. */ PKT_signature *newsig; PACKET *newpkt; int rc; rc = update_keysig_packet (&newsig, sig, main_pk, uid, NULL, main_pk, keygen_upd_std_prefs, NULL); if (rc) { log_error ("update_keysig_packet failed: %s\n", g10_errstr (rc)); return 0; } /* replace the packet */ newpkt = xmalloc_clear (sizeof *newpkt); newpkt->pkttype = PKT_SIGNATURE; newpkt->pkt.signature = newsig; free_packet (node->pkt); xfree (node->pkt); node->pkt = newpkt; modified = 1; } } } } return modified; } static int menu_set_keyserver_url (const char *url, KBNODE pub_keyblock) { PKT_public_key *main_pk; PKT_user_id *uid; KBNODE node; u32 keyid[2]; int selected, select_all; int modified = 0; char *answer, *uri; no_primary_warning (pub_keyblock); if (url) answer = xstrdup (url); else { answer = cpr_get_utf8 ("keyedit.add_keyserver", _("Enter your preferred keyserver URL: ")); if (answer[0] == '\0' || answer[0] == CONTROL_D) { xfree (answer); return 0; } } if (ascii_strcasecmp (answer, "none") == 0) uri = NULL; else { struct keyserver_spec *keyserver = NULL; /* Sanity check the format */ keyserver = parse_keyserver_uri (answer, 1, NULL, 0); xfree (answer); if (!keyserver) { log_info (_("could not parse keyserver URL\n")); return 0; } uri = xstrdup (keyserver->uri); free_keyserver_spec (keyserver); } select_all = !count_selected_uids (pub_keyblock); /* Now we can actually change the self signature(s) */ main_pk = NULL; uid = NULL; selected = 0; for (node = pub_keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY) break; /* ready */ if (node->pkt->pkttype == PKT_PUBLIC_KEY) { main_pk = node->pkt->pkt.public_key; keyid_from_pk (main_pk, keyid); } else if (node->pkt->pkttype == PKT_USER_ID) { uid = node->pkt->pkt.user_id; selected = select_all || (node->flag & NODFLG_SELUID); } else if (main_pk && uid && selected && node->pkt->pkttype == PKT_SIGNATURE) { PKT_signature *sig = node->pkt->pkt.signature; if (keyid[0] == sig->keyid[0] && keyid[1] == sig->keyid[1] && (uid && (sig->sig_class & ~3) == 0x10) && sig->flags.chosen_selfsig) { char *user = utf8_to_native (uid->name, strlen (uid->name), 0); if (sig->version < 4) log_info (_("skipping v3 self-signature on user ID \"%s\"\n"), user); else { /* This is a selfsignature which is to be replaced * We have to ignore v3 signatures because they are * not able to carry the subpacket. */ PKT_signature *newsig; PACKET *newpkt; int rc; const byte *p; size_t plen; p = parse_sig_subpkt (sig->hashed, SIGSUBPKT_PREF_KS, &plen); if (p && plen) { tty_printf ("Current preferred keyserver for user" " ID \"%s\": ", user); tty_print_utf8_string (p, plen); tty_printf ("\n"); if (!cpr_get_answer_is_yes ("keyedit.confirm_keyserver", uri ? _("Are you sure you want to replace it? (y/N) ") : _("Are you sure you want to delete it? (y/N) "))) continue; } else if (uri == NULL) { /* There is no current keyserver URL, so there is no point in trying to un-set it. */ continue; } rc = update_keysig_packet (&newsig, sig, main_pk, uid, NULL, main_pk, keygen_add_keyserver_url, uri); if (rc) { log_error ("update_keysig_packet failed: %s\n", g10_errstr (rc)); xfree (uri); return 0; } /* replace the packet */ newpkt = xmalloc_clear (sizeof *newpkt); newpkt->pkttype = PKT_SIGNATURE; newpkt->pkt.signature = newsig; free_packet (node->pkt); xfree (node->pkt); node->pkt = newpkt; modified = 1; } xfree (user); } } } xfree (uri); return modified; } static int menu_set_notation (const char *string, KBNODE pub_keyblock) { PKT_public_key *main_pk; PKT_user_id *uid; KBNODE node; u32 keyid[2]; int selected, select_all; int modified = 0; char *answer; struct notation *notation; no_primary_warning (pub_keyblock); if (string) answer = xstrdup (string); else { answer = cpr_get_utf8 ("keyedit.add_notation", _("Enter the notation: ")); if (answer[0] == '\0' || answer[0] == CONTROL_D) { xfree (answer); return 0; } } if (!ascii_strcasecmp (answer, "none") || !ascii_strcasecmp (answer, "-")) notation = NULL; /* Delete them all. */ else { notation = string_to_notation (answer, 0); if (!notation) { xfree (answer); return 0; } } xfree (answer); select_all = !count_selected_uids (pub_keyblock); /* Now we can actually change the self signature(s) */ main_pk = NULL; uid = NULL; selected = 0; for (node = pub_keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY) break; /* ready */ if (node->pkt->pkttype == PKT_PUBLIC_KEY) { main_pk = node->pkt->pkt.public_key; keyid_from_pk (main_pk, keyid); } else if (node->pkt->pkttype == PKT_USER_ID) { uid = node->pkt->pkt.user_id; selected = select_all || (node->flag & NODFLG_SELUID); } else if (main_pk && uid && selected && node->pkt->pkttype == PKT_SIGNATURE) { PKT_signature *sig = node->pkt->pkt.signature; if (keyid[0] == sig->keyid[0] && keyid[1] == sig->keyid[1] && (uid && (sig->sig_class & ~3) == 0x10) && sig->flags.chosen_selfsig) { char *user = utf8_to_native (uid->name, strlen (uid->name), 0); if (sig->version < 4) log_info (_("skipping v3 self-signature on user ID \"%s\"\n"), user); else { PKT_signature *newsig; PACKET *newpkt; int rc, skip = 0, addonly = 1; if (sig->flags.notation) { tty_printf ("Current notations for user ID \"%s\":\n", user); tty_print_notations (-9, sig); } else { tty_printf ("No notations on user ID \"%s\"\n", user); if (notation == NULL) { /* There are no current notations, so there is no point in trying to un-set them. */ continue; } } if (notation) { struct notation *n; int deleting = 0; notation->next = sig_to_notation (sig); for (n = notation->next; n; n = n->next) if (strcmp (n->name, notation->name) == 0) { if (notation->value) { if (strcmp (n->value, notation->value) == 0) { if (notation->flags.ignore) { /* Value match with a delete flag. */ n->flags.ignore = 1; deleting = 1; } else { /* Adding the same notation twice, so don't add it at all. */ skip = 1; tty_printf ("Skipping notation:" " %s=%s\n", notation->name, notation->value); break; } } } else { /* No value, so it means delete. */ n->flags.ignore = 1; deleting = 1; } if (n->flags.ignore) { tty_printf ("Removing notation: %s=%s\n", n->name, n->value); addonly = 0; } } if (!notation->flags.ignore && !skip) tty_printf ("Adding notation: %s=%s\n", notation->name, notation->value); /* We tried to delete, but had no matches. */ if (notation->flags.ignore && !deleting) continue; } else { tty_printf ("Removing all notations\n"); addonly = 0; } if (skip || (!addonly && !cpr_get_answer_is_yes ("keyedit.confirm_notation", _("Proceed? (y/N) ")))) continue; rc = update_keysig_packet (&newsig, sig, main_pk, uid, NULL, main_pk, keygen_add_notations, notation); if (rc) { log_error ("update_keysig_packet failed: %s\n", g10_errstr (rc)); free_notation (notation); xfree (user); return 0; } /* replace the packet */ newpkt = xmalloc_clear (sizeof *newpkt); newpkt->pkttype = PKT_SIGNATURE; newpkt->pkt.signature = newsig; free_packet (node->pkt); xfree (node->pkt); node->pkt = newpkt; modified = 1; if (notation) { /* Snip off the notation list from the sig */ free_notation (notation->next); notation->next = NULL; } xfree (user); } } } } free_notation (notation); return modified; } /* * Select one user id or remove all selection if IDX is 0 or select * all if IDX is -1. Returns: True if the selection changed. */ static int menu_select_uid (KBNODE keyblock, int idx) { KBNODE node; int i; if (idx == -1) /* Select all. */ { for (node = keyblock; node; node = node->next) if (node->pkt->pkttype == PKT_USER_ID) node->flag |= NODFLG_SELUID; return 1; } else if (idx) /* Toggle. */ { for (i = 0, node = keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_USER_ID) if (++i == idx) break; } if (!node) { tty_printf (_("No user ID with index %d\n"), idx); return 0; } for (i = 0, node = keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_USER_ID) { if (++i == idx) { if ((node->flag & NODFLG_SELUID)) node->flag &= ~NODFLG_SELUID; else node->flag |= NODFLG_SELUID; } } } } else /* Unselect all */ { for (node = keyblock; node; node = node->next) if (node->pkt->pkttype == PKT_USER_ID) node->flag &= ~NODFLG_SELUID; } return 1; } /* Search in the keyblock for a uid that matches namehash */ static int menu_select_uid_namehash (KBNODE keyblock, const char *namehash) { byte hash[NAMEHASH_LEN]; KBNODE node; int i; assert (strlen (namehash) == NAMEHASH_LEN * 2); for (i = 0; i < NAMEHASH_LEN; i++) hash[i] = hextobyte (&namehash[i * 2]); for (node = keyblock->next; node; node = node->next) { if (node->pkt->pkttype == PKT_USER_ID) { namehash_from_uid (node->pkt->pkt.user_id); if (memcmp (node->pkt->pkt.user_id->namehash, hash, NAMEHASH_LEN) == 0) { if (node->flag & NODFLG_SELUID) node->flag &= ~NODFLG_SELUID; else node->flag |= NODFLG_SELUID; break; } } } if (!node) { tty_printf (_("No user ID with hash %s\n"), namehash); return 0; } return 1; } /* * Select secondary keys * Returns: True if the selection changed. */ static int menu_select_key (KBNODE keyblock, int idx) { KBNODE node; int i; if (idx == -1) /* Select all. */ { for (node = keyblock; node; node = node->next) if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY || node->pkt->pkttype == PKT_SECRET_SUBKEY) node->flag |= NODFLG_SELKEY; } else if (idx) /* Toggle selection. */ { for (i = 0, node = keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY || node->pkt->pkttype == PKT_SECRET_SUBKEY) if (++i == idx) break; } if (!node) { tty_printf (_("No subkey with index %d\n"), idx); return 0; } for (i = 0, node = keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY || node->pkt->pkttype == PKT_SECRET_SUBKEY) if (++i == idx) { if ((node->flag & NODFLG_SELKEY)) node->flag &= ~NODFLG_SELKEY; else node->flag |= NODFLG_SELKEY; } } } else /* Unselect all. */ { for (node = keyblock; node; node = node->next) if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY || node->pkt->pkttype == PKT_SECRET_SUBKEY) node->flag &= ~NODFLG_SELKEY; } return 1; } static int count_uids_with_flag (KBNODE keyblock, unsigned flag) { KBNODE node; int i = 0; for (node = keyblock; node; node = node->next) if (node->pkt->pkttype == PKT_USER_ID && (node->flag & flag)) i++; return i; } static int count_keys_with_flag (KBNODE keyblock, unsigned flag) { KBNODE node; int i = 0; for (node = keyblock; node; node = node->next) if ((node->pkt->pkttype == PKT_PUBLIC_SUBKEY || node->pkt->pkttype == PKT_SECRET_SUBKEY) && (node->flag & flag)) i++; return i; } static int count_uids (KBNODE keyblock) { KBNODE node; int i = 0; for (node = keyblock; node; node = node->next) if (node->pkt->pkttype == PKT_USER_ID) i++; return i; } /* * Returns true if there is at least one selected user id */ static int count_selected_uids (KBNODE keyblock) { return count_uids_with_flag (keyblock, NODFLG_SELUID); } static int count_selected_keys (KBNODE keyblock) { return count_keys_with_flag (keyblock, NODFLG_SELKEY); } /* Returns how many real (i.e. not attribute) uids are unmarked. */ static int real_uids_left (KBNODE keyblock) { KBNODE node; int real = 0; for (node = keyblock; node; node = node->next) if (node->pkt->pkttype == PKT_USER_ID && !(node->flag & NODFLG_SELUID) && !node->pkt->pkt.user_id->attrib_data) real++; return real; } /* * Ask whether the signature should be revoked. If the user commits this, * flag bit MARK_A is set on the signature and the user ID. */ static void ask_revoke_sig (KBNODE keyblock, KBNODE node) { int doit = 0; PKT_user_id *uid; PKT_signature *sig = node->pkt->pkt.signature; KBNODE unode = find_prev_kbnode (keyblock, node, PKT_USER_ID); if (!unode) { log_error ("Oops: no user ID for signature\n"); return; } uid = unode->pkt->pkt.user_id; if (opt.with_colons) { if (uid->attrib_data) printf ("uat:::::::::%u %lu", uid->numattribs, uid->attrib_len); else { printf ("uid:::::::::"); es_write_sanitized (es_stdout, uid->name, uid->len, ":", NULL); } printf ("\n"); print_and_check_one_sig_colon (keyblock, node, NULL, NULL, NULL, NULL, 1); } else { char *p = utf8_to_native (unode->pkt->pkt.user_id->name, unode->pkt->pkt.user_id->len, 0); tty_printf (_("user ID: \"%s\"\n"), p); xfree (p); tty_printf (_("signed by your key %s on %s%s%s\n"), keystr (sig->keyid), datestr_from_sig (sig), sig->flags.exportable ? "" : _(" (non-exportable)"), ""); } if (sig->flags.expired) { tty_printf (_("This signature expired on %s.\n"), expirestr_from_sig (sig)); /* Use a different question so we can have different help text */ doit = cpr_get_answer_is_yes ("ask_revoke_sig.expired", _("Are you sure you still want to revoke it? (y/N) ")); } else doit = cpr_get_answer_is_yes ("ask_revoke_sig.one", _("Create a revocation certificate for this signature? (y/N) ")); if (doit) { node->flag |= NODFLG_MARK_A; unode->flag |= NODFLG_MARK_A; } } /* * Display all user ids of the current public key together with signatures * done by one of our keys. Then walk over all this sigs and ask the user * whether he wants to revoke this signature. * Return: True when the keyblock has changed. */ static int menu_revsig (KBNODE keyblock) { PKT_signature *sig; PKT_public_key *primary_pk; KBNODE node; int changed = 0; int rc, any, skip = 1, all = !count_selected_uids (keyblock); struct revocation_reason_info *reason = NULL; assert (keyblock->pkt->pkttype == PKT_PUBLIC_KEY); /* First check whether we have any signatures at all. */ any = 0; for (node = keyblock; node; node = node->next) { node->flag &= ~(NODFLG_SELSIG | NODFLG_MARK_A); if (node->pkt->pkttype == PKT_USER_ID) { if (node->flag & NODFLG_SELUID || all) skip = 0; else skip = 1; } else if (!skip && node->pkt->pkttype == PKT_SIGNATURE && ((sig = node->pkt->pkt.signature), have_secret_key_with_kid (sig->keyid))) { if ((sig->sig_class & ~3) == 0x10) { any = 1; break; } } } if (!any) { tty_printf (_("Not signed by you.\n")); return 0; } /* FIXME: detect duplicates here */ tty_printf (_("You have signed these user IDs on key %s:\n"), keystr_from_pk (keyblock->pkt->pkt.public_key)); for (node = keyblock; node; node = node->next) { node->flag &= ~(NODFLG_SELSIG | NODFLG_MARK_A); if (node->pkt->pkttype == PKT_USER_ID) { if (node->flag & NODFLG_SELUID || all) { PKT_user_id *uid = node->pkt->pkt.user_id; /* Hmmm: Should we show only UIDs with a signature? */ tty_printf (" "); tty_print_utf8_string (uid->name, uid->len); tty_printf ("\n"); skip = 0; } else skip = 1; } else if (!skip && node->pkt->pkttype == PKT_SIGNATURE && ((sig = node->pkt->pkt.signature), have_secret_key_with_kid (sig->keyid))) { if ((sig->sig_class & ~3) == 0x10) { tty_printf (" "); tty_printf (_("signed by your key %s on %s%s%s\n"), keystr (sig->keyid), datestr_from_sig (sig), sig->flags.exportable ? "" : _(" (non-exportable)"), sig->flags.revocable ? "" : _(" (non-revocable)")); if (sig->flags.revocable) node->flag |= NODFLG_SELSIG; } else if (sig->sig_class == 0x30) { tty_printf (" "); tty_printf (_("revoked by your key %s on %s\n"), keystr (sig->keyid), datestr_from_sig (sig)); } } } tty_printf ("\n"); /* ask */ for (node = keyblock; node; node = node->next) { if (!(node->flag & NODFLG_SELSIG)) continue; ask_revoke_sig (keyblock, node); } /* present selected */ any = 0; for (node = keyblock; node; node = node->next) { if (!(node->flag & NODFLG_MARK_A)) continue; if (!any) { any = 1; tty_printf (_("You are about to revoke these signatures:\n")); } if (node->pkt->pkttype == PKT_USER_ID) { PKT_user_id *uid = node->pkt->pkt.user_id; tty_printf (" "); tty_print_utf8_string (uid->name, uid->len); tty_printf ("\n"); } else if (node->pkt->pkttype == PKT_SIGNATURE) { sig = node->pkt->pkt.signature; tty_printf (" "); tty_printf (_("signed by your key %s on %s%s%s\n"), keystr (sig->keyid), datestr_from_sig (sig), "", sig->flags.exportable ? "" : _(" (non-exportable)")); } } if (!any) return 0; /* none selected */ if (!cpr_get_answer_is_yes ("ask_revoke_sig.okay", _("Really create the revocation certificates? (y/N) "))) return 0; /* forget it */ reason = ask_revocation_reason (0, 1, 0); if (!reason) { /* user decided to cancel */ return 0; } /* now we can sign the user ids */ reloop: /* (must use this, because we are modifing the list) */ primary_pk = keyblock->pkt->pkt.public_key; for (node = keyblock; node; node = node->next) { KBNODE unode; PACKET *pkt; struct sign_attrib attrib; PKT_public_key *signerkey; if (!(node->flag & NODFLG_MARK_A) || node->pkt->pkttype != PKT_SIGNATURE) continue; unode = find_prev_kbnode (keyblock, node, PKT_USER_ID); assert (unode); /* we already checked this */ memset (&attrib, 0, sizeof attrib); attrib.reason = reason; attrib.non_exportable = !node->pkt->pkt.signature->flags.exportable; node->flag &= ~NODFLG_MARK_A; signerkey = xmalloc_secure_clear (sizeof *signerkey); if (get_seckey (signerkey, node->pkt->pkt.signature->keyid)) { log_info (_("no secret key\n")); free_public_key (signerkey); continue; } rc = make_keysig_packet (&sig, primary_pk, unode->pkt->pkt.user_id, NULL, signerkey, 0x30, 0, 0, 0, 0, sign_mk_attrib, &attrib, NULL); free_public_key (signerkey); if (rc) { log_error (_("signing failed: %s\n"), g10_errstr (rc)); release_revocation_reason_info (reason); return changed; } changed = 1; /* we changed the keyblock */ update_trust = 1; /* Are we revoking our own uid? */ if (primary_pk->keyid[0] == sig->keyid[0] && primary_pk->keyid[1] == sig->keyid[1]) unode->pkt->pkt.user_id->is_revoked = 1; pkt = xmalloc_clear (sizeof *pkt); pkt->pkttype = PKT_SIGNATURE; pkt->pkt.signature = sig; insert_kbnode (unode, new_kbnode (pkt), 0); goto reloop; } release_revocation_reason_info (reason); return changed; } /* Revoke a user ID (i.e. revoke a user ID selfsig). Return true if keyblock changed. */ static int menu_revuid (KBNODE pub_keyblock) { PKT_public_key *pk = pub_keyblock->pkt->pkt.public_key; KBNODE node; int changed = 0; int rc; struct revocation_reason_info *reason = NULL; /* Note that this is correct as per the RFCs, but nevertheless somewhat meaningless in the real world. 1991 did define the 0x30 sig class, but PGP 2.x did not actually implement it, so it would probably be safe to use v4 revocations everywhere. -ds */ for (node = pub_keyblock; node; node = node->next) if (pk->version > 3 || (node->pkt->pkttype == PKT_USER_ID && node->pkt->pkt.user_id->selfsigversion > 3)) { if ((reason = ask_revocation_reason (0, 1, 4))) break; else goto leave; } reloop: /* (better this way because we are modifing the keyring) */ for (node = pub_keyblock; node; node = node->next) if (node->pkt->pkttype == PKT_USER_ID && (node->flag & NODFLG_SELUID)) { PKT_user_id *uid = node->pkt->pkt.user_id; if (uid->is_revoked) { char *user = utf8_to_native (uid->name, uid->len, 0); log_info (_("user ID \"%s\" is already revoked\n"), user); xfree (user); } else { PACKET *pkt; PKT_signature *sig; struct sign_attrib attrib; u32 timestamp = make_timestamp (); if (uid->created >= timestamp) { /* Okay, this is a problem. The user ID selfsig was created in the future, so we need to warn the user and set our revocation timestamp one second after that so everything comes out clean. */ log_info (_("WARNING: a user ID signature is dated %d" " seconds in the future\n"), uid->created - timestamp); timestamp = uid->created + 1; } memset (&attrib, 0, sizeof attrib); attrib.reason = reason; node->flag &= ~NODFLG_SELUID; rc = make_keysig_packet (&sig, pk, uid, NULL, pk, 0x30, 0, (reason == NULL) ? 3 : 0, timestamp, 0, sign_mk_attrib, &attrib, NULL); if (rc) { log_error (_("signing failed: %s\n"), g10_errstr (rc)); goto leave; } else { pkt = xmalloc_clear (sizeof *pkt); pkt->pkttype = PKT_SIGNATURE; pkt->pkt.signature = sig; insert_kbnode (node, new_kbnode (pkt), 0); /* If the trustdb has an entry for this key+uid then the trustdb needs an update. */ if (!update_trust && (get_validity (pk, uid) & TRUST_MASK) >= TRUST_UNDEFINED) update_trust = 1; changed = 1; node->pkt->pkt.user_id->is_revoked = 1; goto reloop; } } } if (changed) commit_kbnode (&pub_keyblock); leave: release_revocation_reason_info (reason); return changed; } /* * Revoke the whole key. */ static int menu_revkey (KBNODE pub_keyblock) { PKT_public_key *pk = pub_keyblock->pkt->pkt.public_key; int rc, changed = 0; struct revocation_reason_info *reason; PACKET *pkt; PKT_signature *sig; if (pk->flags.revoked) { tty_printf (_("Key %s is already revoked.\n"), keystr_from_pk (pk)); return 0; } reason = ask_revocation_reason (1, 0, 0); /* user decided to cancel */ if (!reason) return 0; rc = make_keysig_packet (&sig, pk, NULL, NULL, pk, 0x20, 0, opt.force_v4_certs ? 4 : 0, 0, 0, revocation_reason_build_cb, reason, NULL); if (rc) { log_error (_("signing failed: %s\n"), g10_errstr (rc)); goto scram; } changed = 1; /* we changed the keyblock */ pkt = xmalloc_clear (sizeof *pkt); pkt->pkttype = PKT_SIGNATURE; pkt->pkt.signature = sig; insert_kbnode (pub_keyblock, new_kbnode (pkt), 0); commit_kbnode (&pub_keyblock); update_trust = 1; scram: release_revocation_reason_info (reason); return changed; } static int menu_revsubkey (KBNODE pub_keyblock) { PKT_public_key *mainpk; KBNODE node; int changed = 0; int rc; struct revocation_reason_info *reason = NULL; reason = ask_revocation_reason (1, 0, 0); if (!reason) return 0; /* User decided to cancel. */ reloop: /* (better this way because we are modifing the keyring) */ mainpk = pub_keyblock->pkt->pkt.public_key; for (node = pub_keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY && (node->flag & NODFLG_SELKEY)) { PACKET *pkt; PKT_signature *sig; PKT_public_key *subpk = node->pkt->pkt.public_key; struct sign_attrib attrib; if (subpk->flags.revoked) { tty_printf (_("Subkey %s is already revoked.\n"), keystr_from_pk (subpk)); continue; } memset (&attrib, 0, sizeof attrib); attrib.reason = reason; node->flag &= ~NODFLG_SELKEY; rc = make_keysig_packet (&sig, mainpk, NULL, subpk, mainpk, 0x28, 0, 0, 0, 0, sign_mk_attrib, &attrib, NULL); if (rc) { log_error (_("signing failed: %s\n"), g10_errstr (rc)); release_revocation_reason_info (reason); return changed; } changed = 1; /* we changed the keyblock */ pkt = xmalloc_clear (sizeof *pkt); pkt->pkttype = PKT_SIGNATURE; pkt->pkt.signature = sig; insert_kbnode (node, new_kbnode (pkt), 0); goto reloop; } } commit_kbnode (&pub_keyblock); /* No need to set update_trust here since signing keys no longer are used to certify other keys, so there is no change in trust when revoking/removing them */ release_revocation_reason_info (reason); return changed; } /* Note that update_ownertrust is going to mark the trustdb dirty when enabling or disabling a key. This is arguably sub-optimal as disabled keys are still counted in the web of trust, but perhaps not worth adding extra complexity to change. -ds */ static int enable_disable_key (KBNODE keyblock, int disable) { PKT_public_key *pk = find_kbnode (keyblock, PKT_PUBLIC_KEY)->pkt->pkt.public_key; unsigned int trust, newtrust; trust = newtrust = get_ownertrust (pk); newtrust &= ~TRUST_FLAG_DISABLED; if (disable) newtrust |= TRUST_FLAG_DISABLED; if (trust == newtrust) return 0; /* already in that state */ update_ownertrust (pk, newtrust); return 0; } static void menu_showphoto (KBNODE keyblock) { KBNODE node; int select_all = !count_selected_uids (keyblock); int count = 0; PKT_public_key *pk = NULL; /* Look for the public key first. We have to be really, really, explicit as to which photo this is, and what key it is a UID on since people may want to sign it. */ for (node = keyblock; node; node = node->next) { if (node->pkt->pkttype == PKT_PUBLIC_KEY) pk = node->pkt->pkt.public_key; else if (node->pkt->pkttype == PKT_USER_ID) { PKT_user_id *uid = node->pkt->pkt.user_id; count++; if ((select_all || (node->flag & NODFLG_SELUID)) && uid->attribs != NULL) { int i; for (i = 0; i < uid->numattribs; i++) { byte type; u32 size; if (uid->attribs[i].type == ATTRIB_IMAGE && parse_image_header (&uid->attribs[i], &type, &size)) { tty_printf (_("Displaying %s photo ID of size %ld for " "key %s (uid %d)\n"), image_type_to_string (type, 1), (ulong) size, keystr_from_pk (pk), count); show_photos (&uid->attribs[i], 1, pk, uid); } } } } } } diff --git a/g10/keygen.c b/g10/keygen.c index a5650a8bf..55048b163 100644 --- a/g10/keygen.c +++ b/g10/keygen.c @@ -1,4190 +1,4360 @@ /* keygen.c - generate a key pair * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 * 2007, 2009, 2010, 2011 Free Software Foundation, Inc. * * This file is part of GnuPG. * * GnuPG is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * GnuPG is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ #include #include #include #include #include #include #include #include #include #include #include "gpg.h" #include "util.h" #include "main.h" #include "packet.h" #include "cipher.h" #include "ttyio.h" #include "options.h" #include "keydb.h" #include "trustdb.h" #include "status.h" #include "i18n.h" #include "keyserver-internal.h" #include "call-agent.h" #include "pkglue.h" /* The default algorithms. If you change them remember to change them also in gpg.c:gpgconf_list. You should also check that the value is inside the bounds enforced by ask_keysize and gen_xxx. */ #define DEFAULT_STD_ALGO GCRY_PK_RSA #define DEFAULT_STD_KEYSIZE 2048 /* Flag bits used during key generation. */ #define KEYGEN_FLAG_NO_PROTECTION 1 #define KEYGEN_FLAG_TRANSIENT_KEY 2 /* Maximum number of supported algorithm preferences. */ #define MAX_PREFS 30 enum para_name { pKEYTYPE, pKEYLENGTH, pKEYUSAGE, pSUBKEYTYPE, pSUBKEYLENGTH, pSUBKEYUSAGE, pAUTHKEYTYPE, pNAMEREAL, pNAMEEMAIL, pNAMECOMMENT, pPREFERENCES, pREVOKER, pUSERID, pCREATIONDATE, pKEYCREATIONDATE, /* Same in seconds since epoch. */ pEXPIREDATE, pKEYEXPIRE, /* in n seconds */ pSUBKEYEXPIRE, /* in n seconds */ pPASSPHRASE, pPASSPHRASE_DEK, pPASSPHRASE_S2K, pSERIALNO, pCARDBACKUPKEY, pHANDLE, pKEYSERVER }; struct para_data_s { struct para_data_s *next; int lnr; enum para_name key; union { DEK *dek; STRING2KEY *s2k; u32 expire; u32 creation; unsigned int usage; struct revocation_key revkey; char value[1]; } u; }; struct output_control_s { int lnr; int dryrun; int ask_passphrase; unsigned int keygen_flags; int use_files; struct { char *fname; char *newfname; IOBUF stream; armor_filter_context_t *afx; } pub; }; struct opaque_data_usage_and_pk { unsigned int usage; PKT_public_key *pk; }; static int prefs_initialized = 0; static byte sym_prefs[MAX_PREFS]; static int nsym_prefs; static byte hash_prefs[MAX_PREFS]; static int nhash_prefs; static byte zip_prefs[MAX_PREFS]; static int nzip_prefs; static int mdc_available,ks_modify; static void do_generate_keypair( struct para_data_s *para, struct output_control_s *outctrl, int card ); static int write_keyblock (iobuf_t out, kbnode_t node); static gpg_error_t gen_card_key (int algo, int keyno, int is_primary, kbnode_t pub_root, u32 *timestamp, u32 expireval); static int gen_card_key_with_backup (int algo, int keyno, int is_primary, kbnode_t pub_root, u32 timestamp, u32 expireval, struct para_data_s *para); static void print_status_key_created (int letter, PKT_public_key *pk, const char *handle) { byte array[MAX_FINGERPRINT_LEN], *s; char *buf, *p; size_t i, n; if (!handle) handle = ""; buf = xmalloc (MAX_FINGERPRINT_LEN*2+31 + strlen (handle) + 1); p = buf; if (letter || pk) { *p++ = letter; *p++ = ' '; fingerprint_from_pk (pk, array, &n); s = array; for (i=0; i < n ; i++, s++, p += 2) sprintf (p, "%02X", *s); } if (*handle) { *p++ = ' '; for (i=0; handle[i] && i < 100; i++) *p++ = isspace ((unsigned int)handle[i])? '_':handle[i]; } *p = 0; write_status_text ((letter || pk)?STATUS_KEY_CREATED:STATUS_KEY_NOT_CREATED, buf); xfree (buf); } static void print_status_key_not_created (const char *handle) { print_status_key_created (0, NULL, handle); } static void write_uid( KBNODE root, const char *s ) { PACKET *pkt = xmalloc_clear(sizeof *pkt ); size_t n = strlen(s); pkt->pkttype = PKT_USER_ID; pkt->pkt.user_id = xmalloc_clear( sizeof *pkt->pkt.user_id + n - 1 ); pkt->pkt.user_id->len = n; pkt->pkt.user_id->ref = 1; strcpy(pkt->pkt.user_id->name, s); add_kbnode( root, new_kbnode( pkt ) ); } static void do_add_key_flags (PKT_signature *sig, unsigned int use) { byte buf[1]; buf[0] = 0; /* The spec says that all primary keys MUST be able to certify. */ if(sig->sig_class!=0x18) buf[0] |= 0x01; if (use & PUBKEY_USAGE_SIG) buf[0] |= 0x02; if (use & PUBKEY_USAGE_ENC) buf[0] |= 0x04 | 0x08; if (use & PUBKEY_USAGE_AUTH) buf[0] |= 0x20; if (!buf[0]) return; build_sig_subpkt (sig, SIGSUBPKT_KEY_FLAGS, buf, 1); } int keygen_add_key_expire (PKT_signature *sig, void *opaque) { PKT_public_key *pk = opaque; byte buf[8]; u32 u; if (pk->expiredate) { if (pk->expiredate > pk->timestamp) u = pk->expiredate - pk->timestamp; else u = 1; buf[0] = (u >> 24) & 0xff; buf[1] = (u >> 16) & 0xff; buf[2] = (u >> 8) & 0xff; buf[3] = u & 0xff; build_sig_subpkt (sig, SIGSUBPKT_KEY_EXPIRE, buf, 4); } else { /* Make sure we don't leave a key expiration subpacket lying around */ delete_sig_subpkt (sig->hashed, SIGSUBPKT_KEY_EXPIRE); } return 0; } static int keygen_add_key_flags_and_expire (PKT_signature *sig, void *opaque) { struct opaque_data_usage_and_pk *oduap = opaque; do_add_key_flags (sig, oduap->usage); return keygen_add_key_expire (sig, oduap->pk); } static int set_one_pref (int val, int type, const char *item, byte *buf, int *nbuf) { int i; for (i=0; i < *nbuf; i++ ) if (buf[i] == val) { log_info (_("preference `%s' duplicated\n"), item); return -1; } if (*nbuf >= MAX_PREFS) { if(type==1) log_info(_("too many cipher preferences\n")); else if(type==2) log_info(_("too many digest preferences\n")); else if(type==3) log_info(_("too many compression preferences\n")); else BUG(); return -1; } buf[(*nbuf)++] = val; return 0; } /* * Parse the supplied string and use it to set the standard * preferences. The string may be in a form like the one printed by * "pref" (something like: "S10 S3 H3 H2 Z2 Z1") or the actual * cipher/hash/compress names. Use NULL to set the default * preferences. Returns: 0 = okay */ int keygen_set_std_prefs (const char *string,int personal) { byte sym[MAX_PREFS], hash[MAX_PREFS], zip[MAX_PREFS]; int nsym=0, nhash=0, nzip=0, val, rc=0; int mdc=1, modify=0; /* mdc defaults on, modify defaults off. */ char dummy_string[20*4+1]; /* Enough for 20 items. */ if (!string || !ascii_strcasecmp (string, "default")) { if (opt.def_preference_list) string=opt.def_preference_list; else { int any_compress = 0; dummy_string[0]='\0'; /* The rationale why we use the order AES256,192,128 is for compatibility reasons with PGP. If gpg would define AES128 first, we would get the somewhat confusing situation: gpg -r pgpkey -r gpgkey ---gives--> AES256 gpg -r gpgkey -r pgpkey ---gives--> AES Note that by using --personal-cipher-preferences it is possible to prefer AES128. */ /* Make sure we do not add more than 15 items here, as we could overflow the size of dummy_string. We currently have at most 12. */ if ( !openpgp_cipher_test_algo (CIPHER_ALGO_AES256) ) strcat(dummy_string,"S9 "); if ( !openpgp_cipher_test_algo (CIPHER_ALGO_AES192) ) strcat(dummy_string,"S8 "); if ( !openpgp_cipher_test_algo (CIPHER_ALGO_AES) ) strcat(dummy_string,"S7 "); if ( !openpgp_cipher_test_algo (CIPHER_ALGO_CAST5) ) strcat(dummy_string,"S3 "); strcat(dummy_string,"S2 "); /* 3DES */ /* If we have it, IDEA goes *after* 3DES so it won't be used unless we're encrypting along with a V3 key. Ideally, we would only put the S1 preference in if the key was RSA and <=2048 bits, as that is what won't break PGP2, but that is difficult with the current code, and not really worth checking as a non-RSA <=2048 bit key wouldn't be usable by PGP2 anyway. -dms */ if ( !openpgp_cipher_test_algo (CIPHER_ALGO_IDEA) ) strcat(dummy_string,"S1 "); /* The default hash algo order is: SHA-256, SHA-1, SHA-384, SHA-512, SHA-224. Ordering SHA-1 before SHA-384 might be viewed as a bit strange; it is done because we expect that soon enough SHA-3 will be available and at that point there should be no more need for SHA-384 etc. Anyway this order is just a default and can easily be changed by a config option. */ if (!openpgp_md_test_algo (DIGEST_ALGO_SHA256)) strcat (dummy_string, "H8 "); strcat (dummy_string, "H2 "); /* SHA-1 */ if (!openpgp_md_test_algo (DIGEST_ALGO_SHA384)) strcat (dummy_string, "H9 "); if (!openpgp_md_test_algo (DIGEST_ALGO_SHA512)) strcat (dummy_string, "H10 "); if (!openpgp_md_test_algo (DIGEST_ALGO_SHA224)) strcat (dummy_string, "H11 "); if(!check_compress_algo(COMPRESS_ALGO_ZLIB)) { strcat(dummy_string,"Z2 "); any_compress = 1; } if(!check_compress_algo(COMPRESS_ALGO_BZIP2)) { strcat(dummy_string,"Z3 "); any_compress = 1; } if(!check_compress_algo(COMPRESS_ALGO_ZIP)) { strcat(dummy_string,"Z1 "); any_compress = 1; } /* In case we have no compress algo at all, declare that we prefer no compresssion. */ if (!any_compress) strcat(dummy_string,"Z0 "); /* Remove the trailing space. */ if (*dummy_string && dummy_string[strlen (dummy_string)-1] == ' ') dummy_string[strlen (dummy_string)-1] = 0; string=dummy_string; } } else if (!ascii_strcasecmp (string, "none")) string = ""; if(strlen(string)) { char *tok,*prefstring; prefstring=xstrdup(string); /* need a writable string! */ while((tok=strsep(&prefstring," ,"))) { if((val=string_to_cipher_algo (tok))) { if(set_one_pref(val,1,tok,sym,&nsym)) rc=-1; } else if((val=string_to_digest_algo (tok))) { if(set_one_pref(val,2,tok,hash,&nhash)) rc=-1; } else if((val=string_to_compress_algo(tok))>-1) { if(set_one_pref(val,3,tok,zip,&nzip)) rc=-1; } else if (ascii_strcasecmp(tok,"mdc")==0) mdc=1; else if (ascii_strcasecmp(tok,"no-mdc")==0) mdc=0; else if (ascii_strcasecmp(tok,"ks-modify")==0) modify=1; else if (ascii_strcasecmp(tok,"no-ks-modify")==0) modify=0; else { log_info (_("invalid item `%s' in preference string\n"),tok); /* Complain if IDEA is not available. */ if(ascii_strcasecmp(tok,"s1")==0 || ascii_strcasecmp(tok,"idea")==0) idea_cipher_warn(1); rc=-1; } } xfree(prefstring); } if(!rc) { if(personal) { if(personal==PREFTYPE_SYM) { xfree(opt.personal_cipher_prefs); if(nsym==0) opt.personal_cipher_prefs=NULL; else { int i; opt.personal_cipher_prefs= xmalloc(sizeof(prefitem_t *)*(nsym+1)); for (i=0; iref=1; uid->prefs=xmalloc((sizeof(prefitem_t *)* (nsym_prefs+nhash_prefs+nzip_prefs+1))); for(i=0;iprefs[j].type=PREFTYPE_SYM; uid->prefs[j].value=sym_prefs[i]; } for(i=0;iprefs[j].type=PREFTYPE_HASH; uid->prefs[j].value=hash_prefs[i]; } for(i=0;iprefs[j].type=PREFTYPE_ZIP; uid->prefs[j].value=zip_prefs[i]; } uid->prefs[j].type=PREFTYPE_NONE; uid->prefs[j].value=0; uid->flags.mdc=mdc_available; uid->flags.ks_modify=ks_modify; return uid; } static void add_feature_mdc (PKT_signature *sig,int enabled) { const byte *s; size_t n; int i; char *buf; s = parse_sig_subpkt (sig->hashed, SIGSUBPKT_FEATURES, &n ); /* Already set or cleared */ if (s && n && ((enabled && (s[0] & 0x01)) || (!enabled && !(s[0] & 0x01)))) return; if (!s || !n) { /* create a new one */ n = 1; buf = xmalloc_clear (n); } else { buf = xmalloc (n); memcpy (buf, s, n); } if(enabled) buf[0] |= 0x01; /* MDC feature */ else buf[0] &= ~0x01; /* Are there any bits set? */ for(i=0;ihashed, SIGSUBPKT_FEATURES); else build_sig_subpkt (sig, SIGSUBPKT_FEATURES, buf, n); xfree (buf); } static void add_keyserver_modify (PKT_signature *sig,int enabled) { const byte *s; size_t n; int i; char *buf; /* The keyserver modify flag is a negative flag (i.e. no-modify) */ enabled=!enabled; s = parse_sig_subpkt (sig->hashed, SIGSUBPKT_KS_FLAGS, &n ); /* Already set or cleared */ if (s && n && ((enabled && (s[0] & 0x80)) || (!enabled && !(s[0] & 0x80)))) return; if (!s || !n) { /* create a new one */ n = 1; buf = xmalloc_clear (n); } else { buf = xmalloc (n); memcpy (buf, s, n); } if(enabled) buf[0] |= 0x80; /* no-modify flag */ else buf[0] &= ~0x80; /* Are there any bits set? */ for(i=0;ihashed, SIGSUBPKT_KS_FLAGS); else build_sig_subpkt (sig, SIGSUBPKT_KS_FLAGS, buf, n); xfree (buf); } int keygen_upd_std_prefs (PKT_signature *sig, void *opaque) { (void)opaque; if (!prefs_initialized) keygen_set_std_prefs (NULL, 0); if (nsym_prefs) build_sig_subpkt (sig, SIGSUBPKT_PREF_SYM, sym_prefs, nsym_prefs); else { delete_sig_subpkt (sig->hashed, SIGSUBPKT_PREF_SYM); delete_sig_subpkt (sig->unhashed, SIGSUBPKT_PREF_SYM); } if (nhash_prefs) build_sig_subpkt (sig, SIGSUBPKT_PREF_HASH, hash_prefs, nhash_prefs); else { delete_sig_subpkt (sig->hashed, SIGSUBPKT_PREF_HASH); delete_sig_subpkt (sig->unhashed, SIGSUBPKT_PREF_HASH); } if (nzip_prefs) build_sig_subpkt (sig, SIGSUBPKT_PREF_COMPR, zip_prefs, nzip_prefs); else { delete_sig_subpkt (sig->hashed, SIGSUBPKT_PREF_COMPR); delete_sig_subpkt (sig->unhashed, SIGSUBPKT_PREF_COMPR); } /* Make sure that the MDC feature flag is set if needed. */ add_feature_mdc (sig,mdc_available); add_keyserver_modify (sig,ks_modify); keygen_add_keyserver_url(sig,NULL); return 0; } /**************** * Add preference to the self signature packet. * This is only called for packets with version > 3. */ int keygen_add_std_prefs (PKT_signature *sig, void *opaque) { PKT_public_key *pk = opaque; do_add_key_flags (sig, pk->pubkey_usage); keygen_add_key_expire (sig, opaque ); keygen_upd_std_prefs (sig, opaque); keygen_add_keyserver_url (sig,NULL); return 0; } int keygen_add_keyserver_url(PKT_signature *sig, void *opaque) { const char *url=opaque; if(!url) url=opt.def_keyserver_url; if(url) build_sig_subpkt(sig,SIGSUBPKT_PREF_KS,url,strlen(url)); else delete_sig_subpkt (sig->hashed,SIGSUBPKT_PREF_KS); return 0; } int keygen_add_notations(PKT_signature *sig,void *opaque) { struct notation *notation; /* We always start clean */ delete_sig_subpkt(sig->hashed,SIGSUBPKT_NOTATION); delete_sig_subpkt(sig->unhashed,SIGSUBPKT_NOTATION); sig->flags.notation=0; for(notation=opaque;notation;notation=notation->next) if(!notation->flags.ignore) { unsigned char *buf; unsigned int n1,n2; n1=strlen(notation->name); if(notation->altvalue) n2=strlen(notation->altvalue); else if(notation->bdat) n2=notation->blen; else n2=strlen(notation->value); buf = xmalloc( 8 + n1 + n2 ); /* human readable or not */ buf[0] = notation->bdat?0:0x80; buf[1] = buf[2] = buf[3] = 0; buf[4] = n1 >> 8; buf[5] = n1; buf[6] = n2 >> 8; buf[7] = n2; memcpy(buf+8, notation->name, n1 ); if(notation->altvalue) memcpy(buf+8+n1, notation->altvalue, n2 ); else if(notation->bdat) memcpy(buf+8+n1, notation->bdat, n2 ); else memcpy(buf+8+n1, notation->value, n2 ); build_sig_subpkt( sig, SIGSUBPKT_NOTATION | (notation->flags.critical?SIGSUBPKT_FLAG_CRITICAL:0), buf, 8+n1+n2 ); xfree(buf); } return 0; } int keygen_add_revkey (PKT_signature *sig, void *opaque) { struct revocation_key *revkey = opaque; byte buf[2+MAX_FINGERPRINT_LEN]; buf[0] = revkey->class; buf[1] = revkey->algid; memcpy (&buf[2], revkey->fpr, MAX_FINGERPRINT_LEN); build_sig_subpkt (sig, SIGSUBPKT_REV_KEY, buf, 2+MAX_FINGERPRINT_LEN); /* All sigs with revocation keys set are nonrevocable. */ sig->flags.revocable = 0; buf[0] = 0; build_sig_subpkt (sig, SIGSUBPKT_REVOCABLE, buf, 1); parse_revkeys (sig); return 0; } /* Create a back-signature. If TIMESTAMP is not NULL, use it for the signature creation time. */ gpg_error_t make_backsig (PKT_signature *sig, PKT_public_key *pk, PKT_public_key *sub_pk, PKT_public_key *sub_psk, u32 timestamp, const char *cache_nonce) { gpg_error_t err; PKT_signature *backsig; cache_public_key (sub_pk); err = make_keysig_packet (&backsig, pk, NULL, sub_pk, sub_psk, 0x19, 0, 0, timestamp, 0, NULL, NULL, cache_nonce); if (err) log_error ("make_keysig_packet failed for backsig: %s\n", g10_errstr(err)); else { /* Get it into a binary packed form. */ IOBUF backsig_out = iobuf_temp(); PACKET backsig_pkt; init_packet (&backsig_pkt); backsig_pkt.pkttype = PKT_SIGNATURE; backsig_pkt.pkt.signature = backsig; err = build_packet (backsig_out, &backsig_pkt); free_packet (&backsig_pkt); if (err) log_error ("build_packet failed for backsig: %s\n", g10_errstr(err)); else { size_t pktlen = 0; byte *buf = iobuf_get_temp_buffer (backsig_out); /* Remove the packet header. */ if(buf[0]&0x40) { if (buf[1] < 192) { pktlen = buf[1]; buf += 2; } else if(buf[1] < 224) { pktlen = (buf[1]-192)*256; pktlen += buf[2]+192; buf += 3; } else if (buf[1] == 255) { pktlen = buf[2] << 24; pktlen |= buf[3] << 16; pktlen |= buf[4] << 8; pktlen |= buf[5]; buf += 6; } else BUG (); } else { int mark = 1; switch (buf[0]&3) { case 3: BUG (); break; case 2: pktlen = buf[mark++] << 24; pktlen |= buf[mark++] << 16; case 1: pktlen |= buf[mark++] << 8; case 0: pktlen |= buf[mark++]; } buf += mark; } /* Now make the binary blob into a subpacket. */ build_sig_subpkt (sig, SIGSUBPKT_SIGNATURE, buf, pktlen); iobuf_close (backsig_out); } } return err; } /* Write a direct key signature to the first key in ROOT using the key PSK. REVKEY is describes the direct key signature and TIMESTAMP is the timestamp to set on the signature. */ static gpg_error_t write_direct_sig (KBNODE root, PKT_public_key *psk, struct revocation_key *revkey, u32 timestamp, const char *cache_nonce) { gpg_error_t err; PACKET *pkt; PKT_signature *sig; KBNODE node; PKT_public_key *pk; if (opt.verbose) log_info (_("writing direct signature\n")); /* Get the pk packet from the pub_tree. */ node = find_kbnode (root, PKT_PUBLIC_KEY); if (!node) BUG (); pk = node->pkt->pkt.public_key; /* We have to cache the key, so that the verification of the signature creation is able to retrieve the public key. */ cache_public_key (pk); /* Make the signature. */ err = make_keysig_packet (&sig, pk, NULL,NULL, psk, 0x1F, 0, 0, timestamp, 0, keygen_add_revkey, revkey, cache_nonce); if (err) { log_error ("make_keysig_packet failed: %s\n", g10_errstr (err) ); return err; } pkt = xmalloc_clear (sizeof *pkt); pkt->pkttype = PKT_SIGNATURE; pkt->pkt.signature = sig; add_kbnode (root, new_kbnode (pkt)); return err; } /* Write a self-signature to the first user id in ROOT using the key PSK. USE and TIMESTAMP give the extra data we need for the signature. */ static gpg_error_t write_selfsigs (KBNODE root, PKT_public_key *psk, unsigned int use, u32 timestamp, const char *cache_nonce) { gpg_error_t err; PACKET *pkt; PKT_signature *sig; PKT_user_id *uid; KBNODE node; PKT_public_key *pk; if (opt.verbose) log_info (_("writing self signature\n")); /* Get the uid packet from the list. */ node = find_kbnode (root, PKT_USER_ID); if (!node) BUG(); /* No user id packet in tree. */ uid = node->pkt->pkt.user_id; /* Get the pk packet from the pub_tree. */ node = find_kbnode (root, PKT_PUBLIC_KEY); if (!node) BUG(); pk = node->pkt->pkt.public_key; /* The usage has not yet been set - do it now. */ pk->pubkey_usage = use; /* We have to cache the key, so that the verification of the signature creation is able to retrieve the public key. */ cache_public_key (pk); /* Make the signature. */ err = make_keysig_packet (&sig, pk, uid, NULL, psk, 0x13, 0, 0, timestamp, 0, keygen_add_std_prefs, pk, cache_nonce); if (err) { log_error ("make_keysig_packet failed: %s\n", g10_errstr (err)); return err; } pkt = xmalloc_clear (sizeof *pkt); pkt->pkttype = PKT_SIGNATURE; pkt->pkt.signature = sig; add_kbnode (root, new_kbnode (pkt)); return err; } /* Write the key binding signature. If TIMESTAMP is not NULL use the signature creation time. PRI_PSK is the key use for signing. SUB_PSK is a key used to create a back-signature; that one is only used if USE has the PUBKEY_USAGE_SIG capability. */ static int write_keybinding (KBNODE root, PKT_public_key *pri_psk, PKT_public_key *sub_psk, unsigned int use, u32 timestamp, const char *cache_nonce) { gpg_error_t err; PACKET *pkt; PKT_signature *sig; KBNODE node; PKT_public_key *pri_pk, *sub_pk; struct opaque_data_usage_and_pk oduap; if (opt.verbose) log_info(_("writing key binding signature\n")); /* Get the primary pk packet from the tree. */ node = find_kbnode (root, PKT_PUBLIC_KEY); if (!node) BUG(); pri_pk = node->pkt->pkt.public_key; /* We have to cache the key, so that the verification of the * signature creation is able to retrieve the public key. */ cache_public_key (pri_pk); /* Find the last subkey. */ sub_pk = NULL; for (node = root; node; node = node->next ) { if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY) sub_pk = node->pkt->pkt.public_key; } if (!sub_pk) BUG(); /* Make the signature. */ oduap.usage = use; oduap.pk = sub_pk; err = make_keysig_packet (&sig, pri_pk, NULL, sub_pk, pri_psk, 0x18, 0, 0, timestamp, 0, keygen_add_key_flags_and_expire, &oduap, cache_nonce); if (err) { log_error ("make_keysig_packet failed: %s\n", g10_errstr (err)); return err; } /* Make a backsig. */ if (use & PUBKEY_USAGE_SIG) { err = make_backsig (sig, pri_pk, sub_pk, sub_psk, timestamp, cache_nonce); if (err) return err; } pkt = xmalloc_clear ( sizeof *pkt ); pkt->pkttype = PKT_SIGNATURE; pkt->pkt.signature = sig; add_kbnode (root, new_kbnode (pkt) ); return err; } /* Map the Libgcrypt ECC curve NAME to an OID. If R_NBITS is not NULL store the bit size of the curve there. Returns NULL for unknown curve names. */ const char * gpg_curve_to_oid (const char *name, unsigned int *r_nbits) { unsigned int nbits = 0; const char *oidstr; if (!name) oidstr = NULL; else if (!strcmp (name, "NIST P-256")) { oidstr = "1.2.840.10045.3.1.7"; nbits = 256; } else if (!strcmp (name, "NIST P-384")) { oidstr = "1.3.132.0.34"; nbits = 384; } else if (!strcmp (name, "NIST P-521")) { oidstr = "1.3.132.0.35"; nbits = 521; } else oidstr = NULL; if (r_nbits) *r_nbits = nbits; return oidstr; } static gpg_error_t ecckey_from_sexp (gcry_mpi_t *array, gcry_sexp_t sexp, int algo) { gpg_error_t err; gcry_sexp_t list, l2; char *curve; int i; const char *oidstr; unsigned int nbits; array[0] = NULL; array[1] = NULL; array[2] = NULL; list = gcry_sexp_find_token (sexp, "public-key", 0); if (!list) return gpg_error (GPG_ERR_INV_OBJ); l2 = gcry_sexp_cadr (list); gcry_sexp_release (list); list = l2; if (!list) return gpg_error (GPG_ERR_NO_OBJ); l2 = gcry_sexp_find_token (list, "curve", 0); if (!l2) { err = gpg_error (GPG_ERR_NO_OBJ); goto leave; } curve = gcry_sexp_nth_string (l2, 1); if (!curve) { err = gpg_error (GPG_ERR_NO_OBJ); goto leave; } gcry_sexp_release (l2); oidstr = gpg_curve_to_oid (curve, &nbits); if (!oidstr) { /* That can't happen because we used one of the curves gpg_curve_to_oid knows about. */ err = gpg_error (GPG_ERR_INV_OBJ); goto leave; } err = openpgp_oid_from_str (oidstr, &array[0]); if (err) goto leave; l2 = gcry_sexp_find_token (list, "q", 0); if (!l2) { err = gpg_error (GPG_ERR_NO_OBJ); goto leave; } array[1] = gcry_sexp_nth_mpi (l2, 1, GCRYMPI_FMT_USG); gcry_sexp_release (l2); if (!array[1]) { err = gpg_error (GPG_ERR_INV_OBJ); goto leave; } gcry_sexp_release (list); if (algo == PUBKEY_ALGO_ECDH) { array[2] = pk_ecdh_default_params (nbits); if (!array[2]) { err = gpg_error_from_syserror (); goto leave; } } leave: if (err) { for (i=0; i < 3; i++) { gcry_mpi_release (array[i]); array[i] = NULL; } } return 0; } /* Extract key parameters from SEXP and store them in ARRAY. ELEMS is a string where each character denotes a parameter name. TOPNAME is the name of the top element above the elements. */ static int key_from_sexp (gcry_mpi_t *array, gcry_sexp_t sexp, const char *topname, const char *elems) { gcry_sexp_t list, l2; const char *s; int i, idx; int rc = 0; list = gcry_sexp_find_token (sexp, topname, 0); if (!list) return gpg_error (GPG_ERR_INV_OBJ); l2 = gcry_sexp_cadr (list); gcry_sexp_release (list); list = l2; if (!list) return gpg_error (GPG_ERR_NO_OBJ); for (idx=0,s=elems; *s; s++, idx++) { l2 = gcry_sexp_find_token (list, s, 1); if (!l2) { rc = gpg_error (GPG_ERR_NO_OBJ); /* required parameter not found */ goto leave; } array[idx] = gcry_sexp_nth_mpi (l2, 1, GCRYMPI_FMT_USG); gcry_sexp_release (l2); if (!array[idx]) { rc = gpg_error (GPG_ERR_INV_OBJ); /* required parameter invalid */ goto leave; } } gcry_sexp_release (list); leave: if (rc) { for (i=0; itimestamp = timestamp; + pk->version = 4; + if (expireval) + pk->expiredate = pk->timestamp + expireval; + pk->pubkey_algo = algo; + + if (algo == PUBKEY_ALGO_ECDSA || algo == PUBKEY_ALGO_ECDH) + err = ecckey_from_sexp (pk->pkey, s_key, algo); + else + err = key_from_sexp (pk->pkey, s_key, "public-key", algoelem); + if (err) + { + log_error ("key_from_sexp failed: %s\n", gpg_strerror (err) ); + gcry_sexp_release (s_key); + free_public_key (pk); + return err; + } + gcry_sexp_release (s_key); + + pkt = xtrycalloc (1, sizeof *pkt); + if (!pkt) + { + err = gpg_error_from_syserror (); + free_public_key (pk); + return err; + } + + pkt->pkttype = is_subkey ? PKT_PUBLIC_SUBKEY : PKT_PUBLIC_KEY; + pkt->pkt.public_key = pk; + add_kbnode (pub_root, new_kbnode (pkt)); + + return 0; +} + + /* Common code for the key generation fucntion gen_xxx. */ static int common_gen (const char *keyparms, int algo, const char *algoelem, kbnode_t pub_root, u32 timestamp, u32 expireval, int is_subkey, int keygen_flags, char **cache_nonce_addr) { int err; PACKET *pkt; PKT_public_key *pk; gcry_sexp_t s_key; err = agent_genkey (NULL, cache_nonce_addr, keyparms, !!(keygen_flags & KEYGEN_FLAG_NO_PROTECTION), &s_key); if (err) { log_error ("agent_genkey failed: %s\n", gpg_strerror (err) ); return err; } pk = xtrycalloc (1, sizeof *pk); if (!pk) { err = gpg_error_from_syserror (); gcry_sexp_release (s_key); return err; } pk->timestamp = timestamp; pk->version = 4; if (expireval) pk->expiredate = pk->timestamp + expireval; pk->pubkey_algo = algo; if (algo == PUBKEY_ALGO_ECDSA || algo == PUBKEY_ALGO_ECDH) err = ecckey_from_sexp (pk->pkey, s_key, algo); else err = key_from_sexp (pk->pkey, s_key, "public-key", algoelem); if (err) { log_error ("key_from_sexp failed: %s\n", gpg_strerror (err) ); gcry_sexp_release (s_key); free_public_key (pk); return err; } gcry_sexp_release (s_key); pkt = xtrycalloc (1, sizeof *pkt); if (!pkt) { err = gpg_error_from_syserror (); free_public_key (pk); return err; } pkt->pkttype = is_subkey ? PKT_PUBLIC_SUBKEY : PKT_PUBLIC_KEY; pkt->pkt.public_key = pk; add_kbnode (pub_root, new_kbnode (pkt)); return 0; } /* * Generate an Elgamal key. */ static int gen_elg (int algo, unsigned int nbits, KBNODE pub_root, u32 timestamp, u32 expireval, int is_subkey, int keygen_flags, char **cache_nonce_addr) { int err; char *keyparms; char nbitsstr[35]; assert (is_ELGAMAL (algo)); if (nbits < 512) { nbits = 1024; log_info (_("keysize invalid; using %u bits\n"), nbits ); } if ((nbits % 32)) { nbits = ((nbits + 31) / 32) * 32; log_info (_("keysize rounded up to %u bits\n"), nbits ); } /* Note that we use transient-key only if no-protection has also been enabled. */ snprintf (nbitsstr, sizeof nbitsstr, "%u", nbits); keyparms = xtryasprintf ("(genkey(%s(nbits %zu:%s)%s))", algo == GCRY_PK_ELG_E ? "openpgp-elg" : algo == GCRY_PK_ELG ? "elg" : "x-oops" , strlen (nbitsstr), nbitsstr, ((keygen_flags & KEYGEN_FLAG_TRANSIENT_KEY) && (keygen_flags & KEYGEN_FLAG_NO_PROTECTION))? "(transient-key)" : "" ); if (!keyparms) err = gpg_error_from_syserror (); else { err = common_gen (keyparms, algo, "pgy", pub_root, timestamp, expireval, is_subkey, keygen_flags, cache_nonce_addr); xfree (keyparms); } return err; } /* * Generate an DSA key */ static gpg_error_t gen_dsa (unsigned int nbits, KBNODE pub_root, u32 timestamp, u32 expireval, int is_subkey, int keygen_flags, char **cache_nonce_addr) { int err; unsigned int qbits; char *keyparms; char nbitsstr[35]; char qbitsstr[35]; if ( nbits < 512) { nbits = 1024; log_info(_("keysize invalid; using %u bits\n"), nbits ); } else if ( nbits > 3072 ) { nbits = 3072; log_info(_("keysize invalid; using %u bits\n"), nbits ); } if( (nbits % 64) ) { nbits = ((nbits + 63) / 64) * 64; log_info(_("keysize rounded up to %u bits\n"), nbits ); } /* To comply with FIPS rules we round up to the next value unless in expert mode. */ if (!opt.expert && nbits > 1024 && (nbits % 1024)) { nbits = ((nbits + 1023) / 1024) * 1024; log_info(_("keysize rounded up to %u bits\n"), nbits ); } /* Figure out a q size based on the key size. FIPS 180-3 says: L = 1024, N = 160 L = 2048, N = 224 L = 2048, N = 256 L = 3072, N = 256 2048/256 is an odd pair since there is also a 2048/224 and 3072/256. Matching sizes is not a very exact science. We'll do 256 qbits for nbits over 2047, 224 for nbits over 1024 but less than 2048, and 160 for 1024 (DSA1). */ if (nbits > 2047) qbits = 256; else if ( nbits > 1024) qbits = 224; else qbits = 160; if (qbits != 160 ) log_info (_("WARNING: some OpenPGP programs can't" " handle a DSA key with this digest size\n")); snprintf (nbitsstr, sizeof nbitsstr, "%u", nbits); snprintf (qbitsstr, sizeof qbitsstr, "%u", qbits); keyparms = xtryasprintf ("(genkey(dsa(nbits %zu:%s)(qbits %zu:%s)%s))", strlen (nbitsstr), nbitsstr, strlen (qbitsstr), qbitsstr, ((keygen_flags & KEYGEN_FLAG_TRANSIENT_KEY) && (keygen_flags & KEYGEN_FLAG_NO_PROTECTION))? "(transient-key)" : "" ); if (!keyparms) err = gpg_error_from_syserror (); else { err = common_gen (keyparms, PUBKEY_ALGO_DSA, "pqgy", pub_root, timestamp, expireval, is_subkey, keygen_flags, cache_nonce_addr); xfree (keyparms); } return err; } /* * Generate an ECC key */ static gpg_error_t gen_ecc (int algo, unsigned int nbits, kbnode_t pub_root, u32 timestamp, u32 expireval, int is_subkey, int keygen_flags, char **cache_nonce_addr) { gpg_error_t err; const char *curve; char *keyparms; assert (algo == PUBKEY_ALGO_ECDSA || algo == PUBKEY_ALGO_ECDH); /* For now we may only use one of the 3 NIST curves. See also gpg_curve_to_oid. */ if (nbits <= 256) curve = "NIST P-256"; else if (nbits <= 384) curve = "NIST P-384"; else curve = "NIST P-521"; keyparms = xtryasprintf ("(genkey(%s(curve %zu:%s)%s))", algo == PUBKEY_ALGO_ECDSA ? "ecdsa" : "ecdh", strlen (curve), curve, ((keygen_flags & KEYGEN_FLAG_TRANSIENT_KEY) && (keygen_flags & KEYGEN_FLAG_NO_PROTECTION))? "(transient-key)" : "" ); if (!keyparms) err = gpg_error_from_syserror (); else { err = common_gen (keyparms, algo, "", pub_root, timestamp, expireval, is_subkey, keygen_flags, cache_nonce_addr); xfree (keyparms); } return err; } /* * Generate an RSA key. */ static int gen_rsa (int algo, unsigned int nbits, KBNODE pub_root, u32 timestamp, u32 expireval, int is_subkey, int keygen_flags, char **cache_nonce_addr) { int err; char *keyparms; char nbitsstr[35]; assert (is_RSA(algo)); if (!nbits) nbits = DEFAULT_STD_KEYSIZE; if (nbits < 1024) { nbits = 1024; log_info (_("keysize invalid; using %u bits\n"), nbits ); } if ((nbits % 32)) { nbits = ((nbits + 31) / 32) * 32; log_info (_("keysize rounded up to %u bits\n"), nbits ); } snprintf (nbitsstr, sizeof nbitsstr, "%u", nbits); keyparms = xtryasprintf ("(genkey(rsa(nbits %zu:%s)%s))", strlen (nbitsstr), nbitsstr, ((keygen_flags & KEYGEN_FLAG_TRANSIENT_KEY) && (keygen_flags & KEYGEN_FLAG_NO_PROTECTION))? "(transient-key)" : "" ); if (!keyparms) err = gpg_error_from_syserror (); else { err = common_gen (keyparms, algo, "ne", pub_root, timestamp, expireval, is_subkey, keygen_flags, cache_nonce_addr); xfree (keyparms); } return err; } /**************** * check valid days: * return 0 on error or the multiplier */ static int check_valid_days( const char *s ) { if( !digitp(s) ) return 0; for( s++; *s; s++) if( !digitp(s) ) break; if( !*s ) return 1; if( s[1] ) return 0; /* e.g. "2323wc" */ if( *s == 'd' || *s == 'D' ) return 1; if( *s == 'w' || *s == 'W' ) return 7; if( *s == 'm' || *s == 'M' ) return 30; if( *s == 'y' || *s == 'Y' ) return 365; return 0; } static void print_key_flags(int flags) { if(flags&PUBKEY_USAGE_SIG) tty_printf("%s ",_("Sign")); if(flags&PUBKEY_USAGE_CERT) tty_printf("%s ",_("Certify")); if(flags&PUBKEY_USAGE_ENC) tty_printf("%s ",_("Encrypt")); if(flags&PUBKEY_USAGE_AUTH) tty_printf("%s ",_("Authenticate")); } /* Returns the key flags */ static unsigned int ask_key_flags(int algo,int subkey) { /* TRANSLATORS: Please use only plain ASCII characters for the translation. If this is not possible use single digits. The string needs to 8 bytes long. Here is a description of the functions: s = Toggle signing capability e = Toggle encryption capability a = Toggle authentication capability q = Finish */ const char *togglers=_("SsEeAaQq"); char *answer=NULL; unsigned int current=0; unsigned int possible=openpgp_pk_algo_usage(algo); if ( strlen(togglers) != 8 ) { tty_printf ("NOTE: Bad translation at %s:%d. " "Please report.\n", __FILE__, __LINE__); togglers = "11223300"; } /* Only primary keys may certify. */ if(subkey) possible&=~PUBKEY_USAGE_CERT; /* Preload the current set with the possible set, minus authentication, since nobody really uses auth yet. */ current=possible&~PUBKEY_USAGE_AUTH; for(;;) { tty_printf("\n"); tty_printf(_("Possible actions for a %s key: "), openpgp_pk_algo_name (algo)); print_key_flags(possible); tty_printf("\n"); tty_printf(_("Current allowed actions: ")); print_key_flags(current); tty_printf("\n\n"); if(possible&PUBKEY_USAGE_SIG) tty_printf(_(" (%c) Toggle the sign capability\n"), togglers[0]); if(possible&PUBKEY_USAGE_ENC) tty_printf(_(" (%c) Toggle the encrypt capability\n"), togglers[2]); if(possible&PUBKEY_USAGE_AUTH) tty_printf(_(" (%c) Toggle the authenticate capability\n"), togglers[4]); tty_printf(_(" (%c) Finished\n"),togglers[6]); tty_printf("\n"); xfree(answer); answer = cpr_get("keygen.flags",_("Your selection? ")); cpr_kill_prompt(); if(strlen(answer)>1) tty_printf(_("Invalid selection.\n")); else if(*answer=='\0' || *answer==togglers[6] || *answer==togglers[7]) break; else if((*answer==togglers[0] || *answer==togglers[1]) && possible&PUBKEY_USAGE_SIG) { if(current&PUBKEY_USAGE_SIG) current&=~PUBKEY_USAGE_SIG; else current|=PUBKEY_USAGE_SIG; } else if((*answer==togglers[2] || *answer==togglers[3]) && possible&PUBKEY_USAGE_ENC) { if(current&PUBKEY_USAGE_ENC) current&=~PUBKEY_USAGE_ENC; else current|=PUBKEY_USAGE_ENC; } else if((*answer==togglers[4] || *answer==togglers[5]) && possible&PUBKEY_USAGE_AUTH) { if(current&PUBKEY_USAGE_AUTH) current&=~PUBKEY_USAGE_AUTH; else current|=PUBKEY_USAGE_AUTH; } else tty_printf(_("Invalid selection.\n")); } xfree(answer); return current; } +/* Check whether we have a key for the key with HEXGRIP. Returns 0 if + there is no such key or the OpenPGP algo number for the key. */ +static int +check_keygrip (ctrl_t ctrl, const char *hexgrip) +{ + gpg_error_t err; + unsigned char *public; + size_t publiclen; + int algo; + + if (hexgrip[0] == '&') + hexgrip++; + + err = agent_readkey (ctrl, 0, hexgrip, &public); + if (err) + return 0; + publiclen = gcry_sexp_canon_len (public, 0, NULL, NULL); + + get_pk_algo_from_canon_sexp (public, publiclen, &algo); + xfree (public); + + switch (algo) + { + case GCRY_PK_RSA: return PUBKEY_ALGO_RSA; + case GCRY_PK_DSA: return PUBKEY_ALGO_DSA; + case GCRY_PK_ELG_E: return PUBKEY_ALGO_ELGAMAL_E; + case GCRY_PK_ECDH: return PUBKEY_ALGO_ECDH; + case GCRY_PK_ECDSA: return PUBKEY_ALGO_ECDSA; + default: return 0; + } +} + + + /* Ask for an algorithm. The function returns the algorithm id to * create. If ADDMODE is false the function won't show an option to * create the primary and subkey combined and won't set R_USAGE * either. If a combined algorithm has been selected, the subkey - * algorithm is stored at R_SUBKEY_ALGO. */ + * algorithm is stored at R_SUBKEY_ALGO. If R_KEYGRIP is given, the + * user has the choice to enter the keygrip of an existing key. That + * keygrip is then stored at this address. The caller needs to free + * it. */ static int -ask_algo (int addmode, int *r_subkey_algo, unsigned int *r_usage) +ask_algo (ctrl_t ctrl, int addmode, int *r_subkey_algo, unsigned int *r_usage, + char **r_keygrip) { + char *keygrip = NULL; char *answer; int algo; int dummy_algo; if (!r_subkey_algo) r_subkey_algo = &dummy_algo; tty_printf (_("Please select what kind of key you want:\n")); if (!addmode) tty_printf (_(" (%d) RSA and RSA (default)\n"), 1 ); if (!addmode) tty_printf (_(" (%d) DSA and Elgamal\n"), 2 ); tty_printf (_(" (%d) DSA (sign only)\n"), 3 ); tty_printf (_(" (%d) RSA (sign only)\n"), 4 ); if (addmode) { tty_printf (_(" (%d) Elgamal (encrypt only)\n"), 5 ); tty_printf (_(" (%d) RSA (encrypt only)\n"), 6 ); } if (opt.expert) { tty_printf (_(" (%d) DSA (set your own capabilities)\n"), 7 ); tty_printf (_(" (%d) RSA (set your own capabilities)\n"), 8 ); } if (opt.expert && !addmode) tty_printf (_(" (%d) ECDSA and ECDH\n"), 9 ); if (opt.expert) tty_printf (_(" (%d) ECDSA (sign only)\n"), 10 ); if (opt.expert) tty_printf (_(" (%d) ECDSA (set your own capabilities)\n"), 11 ); if (opt.expert && addmode) tty_printf (_(" (%d) ECDH (encrypt only)\n"), 12 ); + if (opt.expert && r_keygrip) + tty_printf (_(" (%d) Existing key\n"), 13 ); + for (;;) { *r_usage = 0; *r_subkey_algo = 0; answer = cpr_get ("keygen.algo", _("Your selection? ")); cpr_kill_prompt (); algo = *answer? atoi (answer) : 1; xfree(answer); + answer = NULL; if (algo == 1 && !addmode) { algo = PUBKEY_ALGO_RSA; *r_subkey_algo = PUBKEY_ALGO_RSA; break; } else if (algo == 2 && !addmode) { algo = PUBKEY_ALGO_DSA; *r_subkey_algo = PUBKEY_ALGO_ELGAMAL_E; break; } else if (algo == 3) { algo = PUBKEY_ALGO_DSA; *r_usage = PUBKEY_USAGE_SIG; break; } else if (algo == 4) { algo = PUBKEY_ALGO_RSA; *r_usage = PUBKEY_USAGE_SIG; break; } else if (algo == 5 && addmode) { algo = PUBKEY_ALGO_ELGAMAL_E; *r_usage = PUBKEY_USAGE_ENC; break; } else if (algo == 6 && addmode) { algo = PUBKEY_ALGO_RSA; *r_usage = PUBKEY_USAGE_ENC; break; } else if (algo == 7 && opt.expert) { algo = PUBKEY_ALGO_DSA; *r_usage = ask_key_flags (algo, addmode); break; } else if (algo == 8 && opt.expert) { algo = PUBKEY_ALGO_RSA; *r_usage = ask_key_flags (algo, addmode); break; } else if (algo == 9 && opt.expert && !addmode) { algo = PUBKEY_ALGO_ECDSA; *r_subkey_algo = PUBKEY_ALGO_ECDH; break; } else if (algo == 10 && opt.expert) { algo = PUBKEY_ALGO_ECDSA; *r_usage = PUBKEY_USAGE_SIG; break; } else if (algo == 11 && opt.expert) { algo = PUBKEY_ALGO_ECDSA; *r_usage = ask_key_flags (algo, addmode); break; } else if (algo == 12 && opt.expert && addmode) { algo = PUBKEY_ALGO_ECDH; *r_usage = PUBKEY_USAGE_ENC; break; } + else if (algo == 13 && opt.expert && r_keygrip) + { + for (;;) + { + xfree (answer); + answer = tty_get (_("Enter the keygrip: ")); + tty_kill_prompt (); + trim_spaces (answer); + if (!*answer) + { + xfree (answer); + answer = NULL; + continue; + } + + if (strlen (answer) != 40 && + !(answer[0] == '&' && strlen (answer+1) == 40)) + tty_printf + (_("Not a valid keygrip (expecting 40 hex digits)\n")); + else if (!(algo = check_keygrip (ctrl, answer)) ) + tty_printf (_("No key with this keygrip\n")); + else + break; /* Okay. */ + } + xfree (keygrip); + keygrip = answer; + answer = NULL; + *r_usage = ask_key_flags (algo, addmode); + break; + } else tty_printf (_("Invalid selection.\n")); } + if (r_keygrip) + *r_keygrip = keygrip; return algo; } /* Ask for the key size. ALGO is the algorithm. If PRIMARY_KEYSIZE is not 0, the function asks for the size of the encryption subkey. */ static unsigned ask_keysize (int algo, unsigned int primary_keysize) { unsigned int nbits, min, def = DEFAULT_STD_KEYSIZE, max=4096; int for_subkey = !!primary_keysize; int autocomp = 0; if(opt.expert) min=512; else min=1024; if (primary_keysize && !opt.expert) { /* Deduce the subkey size from the primary key size. */ if (algo == PUBKEY_ALGO_DSA && primary_keysize > 3072) nbits = 3072; /* For performance reasons we don't support more than 3072 bit DSA. However we won't see this case anyway because DSA can't be used as an encryption subkey ;-). */ else nbits = primary_keysize; autocomp = 1; goto leave; } switch(algo) { case PUBKEY_ALGO_DSA: def=2048; max=3072; break; case PUBKEY_ALGO_ECDSA: case PUBKEY_ALGO_ECDH: min=256; def=256; max=521; break; case PUBKEY_ALGO_RSA: min=1024; break; } tty_printf(_("%s keys may be between %u and %u bits long.\n"), openpgp_pk_algo_name (algo), min, max); for (;;) { char *prompt, *answer; if (for_subkey) prompt = xasprintf (_("What keysize do you want " "for the subkey? (%u) "), def); else prompt = xasprintf (_("What keysize do you want? (%u) "), def); answer = cpr_get ("keygen.size", prompt); cpr_kill_prompt (); nbits = *answer? atoi (answer): def; xfree(prompt); xfree(answer); if(nbitsmax) tty_printf(_("%s keysizes must be in the range %u-%u\n"), openpgp_pk_algo_name (algo), min, max); else break; } tty_printf (_("Requested keysize is %u bits\n"), nbits); leave: if (algo == PUBKEY_ALGO_DSA && (nbits % 64)) { nbits = ((nbits + 63) / 64) * 64; if (!autocomp) tty_printf (_("rounded up to %u bits\n"), nbits); } else if (algo == PUBKEY_ALGO_ECDH || algo == PUBKEY_ALGO_ECDSA) { if (nbits != 256 && nbits != 384 && nbits != 521) { if (nbits < 256) nbits = 256; else if (nbits < 384) nbits = 384; else nbits = 521; if (!autocomp) tty_printf (_("rounded to %u bits\n"), nbits); } } else if ((nbits % 32)) { nbits = ((nbits + 31) / 32) * 32; if (!autocomp) tty_printf (_("rounded up to %u bits\n"), nbits ); } return nbits; } /**************** * Parse an expire string and return its value in seconds. * Returns (u32)-1 on error. * This isn't perfect since scan_isodatestr returns unix time, and * OpenPGP actually allows a 32-bit time *plus* a 32-bit offset. * Because of this, we only permit setting expirations up to 2106, but * OpenPGP could theoretically allow up to 2242. I think we'll all * just cope for the next few years until we get a 64-bit time_t or * similar. */ u32 parse_expire_string( const char *string ) { int mult; u32 seconds; u32 abs_date = 0; u32 curtime = make_timestamp (); time_t tt; if (!*string) seconds = 0; else if (!strncmp (string, "seconds=", 8)) seconds = atoi (string+8); else if ((abs_date = scan_isodatestr(string)) && (abs_date+86400/2) > curtime) seconds = (abs_date+86400/2) - curtime; else if ((tt = isotime2epoch (string)) != (time_t)(-1)) seconds = (u32)tt - curtime; else if ((mult = check_valid_days (string))) seconds = atoi (string) * 86400L * mult; else seconds = (u32)(-1); return seconds; } /* Parsean Creation-Date string which is either "1986-04-26" or "19860426T042640". Returns 0 on error. */ static u32 parse_creation_string (const char *string) { u32 seconds; if (!*string) seconds = 0; else if ( !strncmp (string, "seconds=", 8) ) seconds = atoi (string+8); else if ( !(seconds = scan_isodatestr (string))) { time_t tmp = isotime2epoch (string); seconds = (tmp == (time_t)(-1))? 0 : tmp; } return seconds; } /* object == 0 for a key, and 1 for a sig */ u32 ask_expire_interval(int object,const char *def_expire) { u32 interval; char *answer; switch(object) { case 0: if(def_expire) BUG(); tty_printf(_("Please specify how long the key should be valid.\n" " 0 = key does not expire\n" " = key expires in n days\n" " w = key expires in n weeks\n" " m = key expires in n months\n" " y = key expires in n years\n")); break; case 1: if(!def_expire) BUG(); tty_printf(_("Please specify how long the signature should be valid.\n" " 0 = signature does not expire\n" " = signature expires in n days\n" " w = signature expires in n weeks\n" " m = signature expires in n months\n" " y = signature expires in n years\n")); break; default: BUG(); } /* Note: The elgamal subkey for DSA has no expiration date because * it must be signed with the DSA key and this one has the expiration * date */ answer = NULL; for(;;) { u32 curtime=make_timestamp(); xfree(answer); if(object==0) answer = cpr_get("keygen.valid",_("Key is valid for? (0) ")); else { char *prompt; #define PROMPTSTRING _("Signature is valid for? (%s) ") /* This will actually end up larger than necessary because of the 2 bytes for '%s' */ prompt=xmalloc(strlen(PROMPTSTRING)+strlen(def_expire)+1); sprintf(prompt,PROMPTSTRING,def_expire); #undef PROMPTSTRING answer = cpr_get("siggen.valid",prompt); xfree(prompt); if(*answer=='\0') answer=xstrdup(def_expire); } cpr_kill_prompt(); trim_spaces(answer); interval = parse_expire_string( answer ); if( interval == (u32)-1 ) { tty_printf(_("invalid value\n")); continue; } if( !interval ) { tty_printf((object==0) ? _("Key does not expire at all\n") : _("Signature does not expire at all\n")); } else { tty_printf(object==0 ? _("Key expires at %s\n") : _("Signature expires at %s\n"), asctimestamp((ulong)(curtime + interval) ) ); #if SIZEOF_TIME_T <= 4 && !defined (HAVE_UNSIGNED_TIME_T) if ( (time_t)((ulong)(curtime+interval)) < 0 ) tty_printf (_("Your system can't display dates beyond 2038.\n" "However, it will be correctly handled up to" " 2106.\n")); else #endif /*SIZEOF_TIME_T*/ if ( (time_t)((unsigned long)(curtime+interval)) < curtime ) { tty_printf (_("invalid value\n")); continue; } } if( cpr_enabled() || cpr_get_answer_is_yes("keygen.valid.okay", _("Is this correct? (y/N) ")) ) break; } xfree(answer); return interval; } u32 ask_expiredate() { u32 x = ask_expire_interval(0,NULL); return x? make_timestamp() + x : 0; } static PKT_user_id * uid_from_string (const char *string) { size_t n; PKT_user_id *uid; n = strlen (string); uid = xmalloc_clear (sizeof *uid + n); uid->len = n; strcpy (uid->name, string); uid->ref = 1; return uid; } /* Ask for a user ID. With a MODE of 1 an extra help prompt is printed for use during a new key creation. If KEYBLOCK is not NULL the function prevents the creation of an already existing user ID. */ static char * ask_user_id (int mode, KBNODE keyblock) { char *answer; char *aname, *acomment, *amail, *uid; if ( !mode ) { /* TRANSLATORS: This is the new string telling the user what gpg is now going to do (i.e. ask for the parts of the user ID). Note that if you do not tyranslated this string, a different string will be used used, which might still have a correct transaltion. */ const char *s1 = N_("\n" "GnuPG needs to construct a user ID to identify your key.\n" "\n"); const char *s2 = _(s1); if (!strcmp (s1, s2)) { /* There is no translation for the string thus we to use the old info text. gettext has no way to tell whether a translation is actually available, thus we need to to compare again. */ /* TRANSLATORS: This string is in general not anymore used but you should keep your existing translation. In case the new string is not translated this old string will be used. */ const char *s3 = N_("\n" "You need a user ID to identify your key; " "the software constructs the user ID\n" "from the Real Name, Comment and Email Address in this form:\n" " \"Heinrich Heine (Der Dichter) \"\n\n"); const char *s4 = _(s3); if (strcmp (s3, s4)) s2 = s3; /* A translation exists - use it. */ } tty_printf ("%s", s2) ; } uid = aname = acomment = amail = NULL; for(;;) { char *p; int fail=0; if( !aname ) { for(;;) { xfree(aname); aname = cpr_get("keygen.name",_("Real name: ")); trim_spaces(aname); cpr_kill_prompt(); if( opt.allow_freeform_uid ) break; if( strpbrk( aname, "<>" ) ) tty_printf(_("Invalid character in name\n")); else if( digitp(aname) ) tty_printf(_("Name may not start with a digit\n")); else if( strlen(aname) < 5 ) tty_printf(_("Name must be at least 5 characters long\n")); else break; } } if( !amail ) { for(;;) { xfree(amail); amail = cpr_get("keygen.email",_("Email address: ")); trim_spaces(amail); cpr_kill_prompt(); if( !*amail || opt.allow_freeform_uid ) break; /* no email address is okay */ else if ( !is_valid_mailbox (amail) ) tty_printf(_("Not a valid email address\n")); else break; } } if( !acomment ) { for(;;) { xfree(acomment); acomment = cpr_get("keygen.comment",_("Comment: ")); trim_spaces(acomment); cpr_kill_prompt(); if( !*acomment ) break; /* no comment is okay */ else if( strpbrk( acomment, "()" ) ) tty_printf(_("Invalid character in comment\n")); else break; } } xfree(uid); uid = p = xmalloc(strlen(aname)+strlen(amail)+strlen(acomment)+12+10); p = stpcpy(p, aname ); if( *acomment ) p = stpcpy(stpcpy(stpcpy(p," ("), acomment),")"); if( *amail ) p = stpcpy(stpcpy(stpcpy(p," <"), amail),">"); /* Append a warning if the RNG is switched into fake mode. */ if ( random_is_faked () ) strcpy(p, " (insecure!)" ); /* print a note in case that UTF8 mapping has to be done */ for(p=uid; *p; p++ ) { if( *p & 0x80 ) { tty_printf(_("You are using the `%s' character set.\n"), get_native_charset() ); break; } } tty_printf(_("You selected this USER-ID:\n \"%s\"\n\n"), uid); if( !*amail && !opt.allow_freeform_uid && (strchr( aname, '@' ) || strchr( acomment, '@'))) { fail = 1; tty_printf(_("Please don't put the email address " "into the real name or the comment\n") ); } if (!fail && keyblock) { PKT_user_id *uidpkt = uid_from_string (uid); KBNODE node; for (node=keyblock; node && !fail; node=node->next) if (!is_deleted_kbnode (node) && node->pkt->pkttype == PKT_USER_ID && !cmp_user_ids (uidpkt, node->pkt->pkt.user_id)) fail = 1; if (fail) tty_printf (_("Such a user ID already exists on this key!\n")); free_user_id (uidpkt); } for(;;) { /* TRANSLATORS: These are the allowed answers in lower and uppercase. Below you will find the matching string which should be translated accordingly and the letter changed to match the one in the answer string. n = Change name c = Change comment e = Change email o = Okay (ready, continue) q = Quit */ const char *ansstr = _("NnCcEeOoQq"); if( strlen(ansstr) != 10 ) BUG(); if( cpr_enabled() ) { answer = xstrdup (ansstr + (fail?8:6)); answer[1] = 0; } else { answer = cpr_get("keygen.userid.cmd", fail? _("Change (N)ame, (C)omment, (E)mail or (Q)uit? ") : _("Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? ")); cpr_kill_prompt(); } if( strlen(answer) > 1 ) ; else if( *answer == ansstr[0] || *answer == ansstr[1] ) { xfree(aname); aname = NULL; break; } else if( *answer == ansstr[2] || *answer == ansstr[3] ) { xfree(acomment); acomment = NULL; break; } else if( *answer == ansstr[4] || *answer == ansstr[5] ) { xfree(amail); amail = NULL; break; } else if( *answer == ansstr[6] || *answer == ansstr[7] ) { if( fail ) { tty_printf(_("Please correct the error first\n")); } else { xfree(aname); aname = NULL; xfree(acomment); acomment = NULL; xfree(amail); amail = NULL; break; } } else if( *answer == ansstr[8] || *answer == ansstr[9] ) { xfree(aname); aname = NULL; xfree(acomment); acomment = NULL; xfree(amail); amail = NULL; xfree(uid); uid = NULL; break; } xfree(answer); } xfree(answer); if( !amail && !acomment && !amail ) break; xfree(uid); uid = NULL; } if( uid ) { char *p = native_to_utf8( uid ); xfree( uid ); uid = p; } return uid; } /* MODE 0 - standard 1 - Ask for passphrase of the card backup key. */ static DEK * do_ask_passphrase (STRING2KEY **ret_s2k, int mode, int *r_canceled) { DEK *dek = NULL; STRING2KEY *s2k; const char *errtext = NULL; const char *custdesc = NULL; tty_printf(_("You need a Passphrase to protect your secret key.\n\n") ); if (mode == 1) custdesc = _("Please enter a passphrase to protect the off-card " "backup of the new encryption key."); s2k = xmalloc_secure( sizeof *s2k ); for(;;) { s2k->mode = opt.s2k_mode; s2k->hash_algo = S2K_DIGEST_ALGO; dek = passphrase_to_dek_ext (NULL, 0, opt.s2k_cipher_algo, s2k, 2, errtext, custdesc, NULL, r_canceled); if (!dek && *r_canceled) { xfree(dek); dek = NULL; xfree(s2k); s2k = NULL; break; } else if( !dek ) { errtext = N_("passphrase not correctly repeated; try again"); tty_printf(_("%s.\n"), _(errtext)); } else if( !dek->keylen ) { xfree(dek); dek = NULL; xfree(s2k); s2k = NULL; tty_printf(_( "You don't want a passphrase - this is probably a *bad* idea!\n" "I will do it anyway. You can change your passphrase at any time,\n" "using this program with the option \"--edit-key\".\n\n")); break; } else break; /* okay */ } *ret_s2k = s2k; return dek; } /* Basic key generation. Here we divert to the actual generation routines based on the requested algorithm. */ static int do_create (int algo, unsigned int nbits, KBNODE pub_root, u32 timestamp, u32 expiredate, int is_subkey, int keygen_flags, char **cache_nonce_addr) { gpg_error_t err; /* Fixme: The entropy collecting message should be moved to a libgcrypt progress handler. */ if (!opt.batch) tty_printf (_( "We need to generate a lot of random bytes. It is a good idea to perform\n" "some other action (type on the keyboard, move the mouse, utilize the\n" "disks) during the prime generation; this gives the random number\n" "generator a better chance to gain enough entropy.\n") ); if (algo == PUBKEY_ALGO_ELGAMAL_E) err = gen_elg (algo, nbits, pub_root, timestamp, expiredate, is_subkey, keygen_flags, cache_nonce_addr); else if (algo == PUBKEY_ALGO_DSA) err = gen_dsa (nbits, pub_root, timestamp, expiredate, is_subkey, keygen_flags, cache_nonce_addr); else if (algo == PUBKEY_ALGO_ECDSA || algo == PUBKEY_ALGO_ECDH) err = gen_ecc (algo, nbits, pub_root, timestamp, expiredate, is_subkey, keygen_flags, cache_nonce_addr); else if (algo == PUBKEY_ALGO_RSA) err = gen_rsa (algo, nbits, pub_root, timestamp, expiredate, is_subkey, keygen_flags, cache_nonce_addr); else BUG(); return err; } /* Generate a new user id packet or return NULL if canceled. If KEYBLOCK is not NULL the function prevents the creation of an already existing user ID. */ PKT_user_id * generate_user_id (KBNODE keyblock) { char *p; p = ask_user_id (1, keyblock); if (!p) return NULL; /* Canceled. */ return uid_from_string (p); } static void release_parameter_list (struct para_data_s *r) { struct para_data_s *r2; for (; r ; r = r2) { r2 = r->next; if (r->key == pPASSPHRASE_DEK) xfree (r->u.dek); else if (r->key == pPASSPHRASE_S2K ) xfree (r->u.s2k); xfree (r); } } static struct para_data_s * get_parameter( struct para_data_s *para, enum para_name key ) { struct para_data_s *r; for( r = para; r && r->key != key; r = r->next ) ; return r; } static const char * get_parameter_value( struct para_data_s *para, enum para_name key ) { struct para_data_s *r = get_parameter( para, key ); return (r && *r->u.value)? r->u.value : NULL; } static int get_parameter_algo( struct para_data_s *para, enum para_name key, int *r_default) { int i; struct para_data_s *r = get_parameter( para, key ); if (r_default) *r_default = 0; if (!r) return -1; if (!ascii_strcasecmp (r->u.value, "default")) { /* Note: If you change this default algo, remember to change it also in gpg.c:gpgconf_list. */ i = DEFAULT_STD_ALGO; if (r_default) *r_default = 1; } else if (digitp (r->u.value)) i = atoi( r->u.value ); else if (!strcmp (r->u.value, "ELG-E") || !strcmp (r->u.value, "ELG")) i = GCRY_PK_ELG_E; else i = map_pk_gcry_to_openpgp (gcry_pk_map_name (r->u.value)); if (i == PUBKEY_ALGO_RSA_E || i == PUBKEY_ALGO_RSA_S) i = 0; /* we don't want to allow generation of these algorithms */ return i; } /* * Parse the usage parameter and set the keyflags. Returns -1 on * error, 0 for no usage given or 1 for usage available. */ static int parse_parameter_usage (const char *fname, struct para_data_s *para, enum para_name key) { struct para_data_s *r = get_parameter( para, key ); char *p, *pn; unsigned int use; if( !r ) return 0; /* none (this is an optional parameter)*/ use = 0; pn = r->u.value; while ( (p = strsep (&pn, " \t,")) ) { if ( !*p) ; else if ( !ascii_strcasecmp (p, "sign") ) use |= PUBKEY_USAGE_SIG; else if ( !ascii_strcasecmp (p, "encrypt") ) use |= PUBKEY_USAGE_ENC; else if ( !ascii_strcasecmp (p, "auth") ) use |= PUBKEY_USAGE_AUTH; else { log_error("%s:%d: invalid usage list\n", fname, r->lnr ); return -1; /* error */ } } r->u.usage = use; return 1; } static int parse_revocation_key (const char *fname, struct para_data_s *para, enum para_name key) { struct para_data_s *r = get_parameter( para, key ); struct revocation_key revkey; char *pn; int i; if( !r ) return 0; /* none (this is an optional parameter) */ pn = r->u.value; revkey.class=0x80; revkey.algid=atoi(pn); if(!revkey.algid) goto fail; /* Skip to the fpr */ while(*pn && *pn!=':') pn++; if(*pn!=':') goto fail; pn++; for(i=0;iu.revkey,&revkey,sizeof(struct revocation_key)); return 0; fail: log_error("%s:%d: invalid revocation key\n", fname, r->lnr ); return -1; /* error */ } static u32 get_parameter_u32( struct para_data_s *para, enum para_name key ) { struct para_data_s *r = get_parameter( para, key ); if( !r ) return 0; if( r->key == pKEYCREATIONDATE ) return r->u.creation; if( r->key == pKEYEXPIRE || r->key == pSUBKEYEXPIRE ) return r->u.expire; if( r->key == pKEYUSAGE || r->key == pSUBKEYUSAGE ) return r->u.usage; return (unsigned int)strtoul( r->u.value, NULL, 10 ); } static unsigned int get_parameter_uint( struct para_data_s *para, enum para_name key ) { return get_parameter_u32( para, key ); } static struct revocation_key * get_parameter_revkey( struct para_data_s *para, enum para_name key ) { struct para_data_s *r = get_parameter( para, key ); return r? &r->u.revkey : NULL; } static int proc_parameter_file( struct para_data_s *para, const char *fname, struct output_control_s *outctrl, int card ) { struct para_data_s *r; const char *s1, *s2, *s3; size_t n; char *p; int is_default = 0; int have_user_id = 0; int err, algo; /* Check that we have all required parameters. */ r = get_parameter( para, pKEYTYPE ); if(r) { algo = get_parameter_algo (para, pKEYTYPE, &is_default); if (openpgp_pk_test_algo2 (algo, PUBKEY_USAGE_SIG)) { log_error ("%s:%d: invalid algorithm\n", fname, r->lnr ); return -1; } } else { log_error ("%s: no Key-Type specified\n",fname); return -1; } err = parse_parameter_usage (fname, para, pKEYUSAGE); if (!err) { /* Default to algo capabilities if key-usage is not provided and no default algorithm has been requested. */ r = xmalloc_clear(sizeof(*r)); r->key = pKEYUSAGE; r->u.usage = (is_default ? (PUBKEY_USAGE_CERT | PUBKEY_USAGE_SIG) : openpgp_pk_algo_usage(algo)); r->next = para; para = r; } else if (err == -1) return -1; else { r = get_parameter (para, pKEYUSAGE); if (r && (r->u.usage & ~openpgp_pk_algo_usage (algo))) { log_error ("%s:%d: specified Key-Usage not allowed for algo %d\n", fname, r->lnr, algo); return -1; } } is_default = 0; r = get_parameter( para, pSUBKEYTYPE ); if(r) { algo = get_parameter_algo (para, pSUBKEYTYPE, &is_default); if (openpgp_pk_test_algo (algo)) { log_error ("%s:%d: invalid algorithm\n", fname, r->lnr ); return -1; } err = parse_parameter_usage (fname, para, pSUBKEYUSAGE); if (!err) { /* Default to algo capabilities if subkey-usage is not provided */ r = xmalloc_clear (sizeof(*r)); r->key = pSUBKEYUSAGE; r->u.usage = (is_default ? PUBKEY_USAGE_ENC : openpgp_pk_algo_usage (algo)); r->next = para; para = r; } else if (err == -1) return -1; else { r = get_parameter (para, pSUBKEYUSAGE); if (r && (r->u.usage & ~openpgp_pk_algo_usage (algo))) { log_error ("%s:%d: specified Subkey-Usage not allowed" " for algo %d\n", fname, r->lnr, algo); return -1; } } } if( get_parameter_value( para, pUSERID ) ) have_user_id=1; else { /* create the formatted user ID */ s1 = get_parameter_value( para, pNAMEREAL ); s2 = get_parameter_value( para, pNAMECOMMENT ); s3 = get_parameter_value( para, pNAMEEMAIL ); if( s1 || s2 || s3 ) { n = (s1?strlen(s1):0) + (s2?strlen(s2):0) + (s3?strlen(s3):0); r = xmalloc_clear( sizeof *r + n + 20 ); r->key = pUSERID; p = r->u.value; if( s1 ) p = stpcpy(p, s1 ); if( s2 ) p = stpcpy(stpcpy(stpcpy(p," ("), s2 ),")"); if( s3 ) p = stpcpy(stpcpy(stpcpy(p," <"), s3 ),">"); r->next = para; para = r; have_user_id=1; } } if(!have_user_id) { log_error("%s: no User-ID specified\n",fname); return -1; } /* Set preferences, if any. */ keygen_set_std_prefs(get_parameter_value( para, pPREFERENCES ), 0); /* Set keyserver, if any. */ s1=get_parameter_value( para, pKEYSERVER ); if(s1) { struct keyserver_spec *spec; spec=parse_keyserver_uri(s1,1,NULL,0); if(spec) { free_keyserver_spec(spec); opt.def_keyserver_url=s1; } else { log_error("%s:%d: invalid keyserver url\n", fname, r->lnr ); return -1; } } /* Set revoker, if any. */ if (parse_revocation_key (fname, para, pREVOKER)) return -1; /* Make DEK and S2K from the Passphrase. */ if (outctrl->ask_passphrase) { /* %ask-passphrase is active - ignore pPASSPRASE and ask. This feature is required so that GUIs are able to do a key creation but have gpg-agent ask for the passphrase. */ int canceled = 0; STRING2KEY *s2k; DEK *dek; dek = do_ask_passphrase (&s2k, 0, &canceled); if (dek) { r = xmalloc_clear( sizeof *r ); r->key = pPASSPHRASE_DEK; r->u.dek = dek; r->next = para; para = r; r = xmalloc_clear( sizeof *r ); r->key = pPASSPHRASE_S2K; r->u.s2k = s2k; r->next = para; para = r; } if (canceled) { log_error ("%s:%d: key generation canceled\n", fname, r->lnr ); return -1; } } else { r = get_parameter( para, pPASSPHRASE ); if ( r && *r->u.value ) { /* We have a plain text passphrase - create a DEK from it. * It is a little bit ridiculous to keep it in secure memory * but because we do this always, why not here. */ STRING2KEY *s2k; DEK *dek; s2k = xmalloc_secure ( sizeof *s2k ); s2k->mode = opt.s2k_mode; s2k->hash_algo = S2K_DIGEST_ALGO; set_next_passphrase ( r->u.value ); dek = passphrase_to_dek (NULL, 0, opt.s2k_cipher_algo, s2k, 2, NULL, NULL); set_next_passphrase (NULL ); assert (dek); memset (r->u.value, 0, strlen(r->u.value)); r = xmalloc_clear (sizeof *r); r->key = pPASSPHRASE_S2K; r->u.s2k = s2k; r->next = para; para = r; r = xmalloc_clear (sizeof *r); r->key = pPASSPHRASE_DEK; r->u.dek = dek; r->next = para; para = r; } } /* Make KEYCREATIONDATE from Creation-Date. */ r = get_parameter (para, pCREATIONDATE); if (r && *r->u.value) { u32 seconds; seconds = parse_creation_string (r->u.value); if (!seconds) { log_error ("%s:%d: invalid creation date\n", fname, r->lnr ); return -1; } r->u.creation = seconds; r->key = pKEYCREATIONDATE; /* Change that entry. */ } /* Make KEYEXPIRE from Expire-Date. */ r = get_parameter( para, pEXPIREDATE ); if( r && *r->u.value ) { u32 seconds; seconds = parse_expire_string( r->u.value ); if( seconds == (u32)-1 ) { log_error("%s:%d: invalid expire date\n", fname, r->lnr ); return -1; } r->u.expire = seconds; r->key = pKEYEXPIRE; /* change hat entry */ /* also set it for the subkey */ r = xmalloc_clear( sizeof *r + 20 ); r->key = pSUBKEYEXPIRE; r->u.expire = seconds; r->next = para; para = r; } do_generate_keypair( para, outctrl, card ); return 0; } /**************** * Kludge to allow non interactive key generation controlled * by a parameter file. * Note, that string parameters are expected to be in UTF-8 */ static void read_parameter_file( const char *fname ) { static struct { const char *name; enum para_name key; } keywords[] = { { "Key-Type", pKEYTYPE}, { "Key-Length", pKEYLENGTH }, { "Key-Usage", pKEYUSAGE }, { "Subkey-Type", pSUBKEYTYPE }, { "Subkey-Length", pSUBKEYLENGTH }, { "Subkey-Usage", pSUBKEYUSAGE }, { "Name-Real", pNAMEREAL }, { "Name-Email", pNAMEEMAIL }, { "Name-Comment", pNAMECOMMENT }, { "Expire-Date", pEXPIREDATE }, { "Creation-Date", pCREATIONDATE }, { "Passphrase", pPASSPHRASE }, { "Preferences", pPREFERENCES }, { "Revoker", pREVOKER }, { "Handle", pHANDLE }, { "Keyserver", pKEYSERVER }, { NULL, 0 } }; IOBUF fp; byte *line; unsigned int maxlen, nline; char *p; int lnr; const char *err = NULL; struct para_data_s *para, *r; int i; struct output_control_s outctrl; memset( &outctrl, 0, sizeof( outctrl ) ); outctrl.pub.afx = new_armor_context (); if( !fname || !*fname) fname = "-"; fp = iobuf_open (fname); if (fp && is_secured_file (iobuf_get_fd (fp))) { iobuf_close (fp); fp = NULL; gpg_err_set_errno (EPERM); } if (!fp) { log_error (_("can't open `%s': %s\n"), fname, strerror(errno) ); return; } iobuf_ioctl (fp, IOBUF_IOCTL_NO_CACHE, 1, NULL); lnr = 0; err = NULL; para = NULL; maxlen = 1024; line = NULL; while ( iobuf_read_line (fp, &line, &nline, &maxlen) ) { char *keyword, *value; lnr++; if( !maxlen ) { err = "line too long"; break; } for( p = line; isspace(*(byte*)p); p++ ) ; if( !*p || *p == '#' ) continue; keyword = p; if( *keyword == '%' ) { for( ; !isspace(*(byte*)p); p++ ) ; if( *p ) *p++ = 0; for( ; isspace(*(byte*)p); p++ ) ; value = p; trim_trailing_ws( value, strlen(value) ); if( !ascii_strcasecmp( keyword, "%echo" ) ) log_info("%s\n", value ); else if( !ascii_strcasecmp( keyword, "%dry-run" ) ) outctrl.dryrun = 1; else if( !ascii_strcasecmp( keyword, "%ask-passphrase" ) ) outctrl.ask_passphrase = 1; else if( !ascii_strcasecmp( keyword, "%no-ask-passphrase" ) ) outctrl.ask_passphrase = 0; else if( !ascii_strcasecmp( keyword, "%no-protection" ) ) outctrl.keygen_flags |= KEYGEN_FLAG_NO_PROTECTION; else if( !ascii_strcasecmp( keyword, "%transient-key" ) ) outctrl.keygen_flags |= KEYGEN_FLAG_TRANSIENT_KEY; else if( !ascii_strcasecmp( keyword, "%commit" ) ) { outctrl.lnr = lnr; if (proc_parameter_file( para, fname, &outctrl, 0 )) print_status_key_not_created (get_parameter_value (para, pHANDLE)); release_parameter_list( para ); para = NULL; } else if( !ascii_strcasecmp( keyword, "%pubring" ) ) { if( outctrl.pub.fname && !strcmp( outctrl.pub.fname, value ) ) ; /* still the same file - ignore it */ else { xfree( outctrl.pub.newfname ); outctrl.pub.newfname = xstrdup( value ); outctrl.use_files = 1; } } else if( !ascii_strcasecmp( keyword, "%secring" ) ) { /* Ignore this command. */ } else log_info("skipping control `%s' (%s)\n", keyword, value ); continue; } if( !(p = strchr( p, ':' )) || p == keyword ) { err = "missing colon"; break; } if( *p ) *p++ = 0; for( ; isspace(*(byte*)p); p++ ) ; if( !*p ) { err = "missing argument"; break; } value = p; trim_trailing_ws( value, strlen(value) ); for(i=0; keywords[i].name; i++ ) { if( !ascii_strcasecmp( keywords[i].name, keyword ) ) break; } if( !keywords[i].name ) { err = "unknown keyword"; break; } if( keywords[i].key != pKEYTYPE && !para ) { err = "parameter block does not start with \"Key-Type\""; break; } if( keywords[i].key == pKEYTYPE && para ) { outctrl.lnr = lnr; if (proc_parameter_file( para, fname, &outctrl, 0 )) print_status_key_not_created (get_parameter_value (para, pHANDLE)); release_parameter_list( para ); para = NULL; } else { for( r = para; r; r = r->next ) { if( r->key == keywords[i].key ) break; } if( r ) { err = "duplicate keyword"; break; } } r = xmalloc_clear( sizeof *r + strlen( value ) ); r->lnr = lnr; r->key = keywords[i].key; strcpy( r->u.value, value ); r->next = para; para = r; } if( err ) log_error("%s:%d: %s\n", fname, lnr, err ); else if( iobuf_error (fp) ) { log_error("%s:%d: read error\n", fname, lnr); } else if( para ) { outctrl.lnr = lnr; if (proc_parameter_file( para, fname, &outctrl, 0 )) print_status_key_not_created (get_parameter_value (para, pHANDLE)); } if( outctrl.use_files ) { /* close open streams */ iobuf_close( outctrl.pub.stream ); /* Must invalidate that ugly cache to actually close it. */ if (outctrl.pub.fname) iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0, (char*)outctrl.pub.fname); xfree( outctrl.pub.fname ); xfree( outctrl.pub.newfname ); } release_parameter_list( para ); iobuf_close (fp); release_armor_context (outctrl.pub.afx); } /* * Generate a keypair (fname is only used in batch mode) If * CARD_SERIALNO is not NULL the function will create the keys on an * OpenPGP Card. If CARD_BACKUP_KEY has been set and CARD_SERIALNO is * NOT NULL, the encryption key for the card is generated on the host, * imported to the card and a backup file created by gpg-agent. */ void -generate_keypair (const char *fname, const char *card_serialno, +generate_keypair (ctrl_t ctrl, const char *fname, const char *card_serialno, int card_backup_key) { unsigned int nbits; char *uid = NULL; int algo; unsigned int use; int both = 0; u32 expire; struct para_data_s *para = NULL; struct para_data_s *r; struct output_control_s outctrl; memset( &outctrl, 0, sizeof( outctrl ) ); if (opt.batch && card_serialno) { /* We don't yet support unattended key generation. */ log_error (_("can't do this in batch mode\n")); return; } if (opt.batch) { read_parameter_file( fname ); return; } if (card_serialno) { #ifdef ENABLE_CARD_SUPPORT r = xcalloc (1, sizeof *r + strlen (card_serialno) ); r->key = pSERIALNO; strcpy( r->u.value, card_serialno); r->next = para; para = r; algo = PUBKEY_ALGO_RSA; r = xcalloc (1, sizeof *r + 20 ); r->key = pKEYTYPE; sprintf( r->u.value, "%d", algo ); r->next = para; para = r; r = xcalloc (1, sizeof *r + 20 ); r->key = pKEYUSAGE; strcpy (r->u.value, "sign"); r->next = para; para = r; r = xcalloc (1, sizeof *r + 20 ); r->key = pSUBKEYTYPE; sprintf( r->u.value, "%d", algo ); r->next = para; para = r; r = xcalloc (1, sizeof *r + 20 ); r->key = pSUBKEYUSAGE; strcpy (r->u.value, "encrypt"); r->next = para; para = r; r = xcalloc (1, sizeof *r + 20 ); r->key = pAUTHKEYTYPE; sprintf( r->u.value, "%d", algo ); r->next = para; para = r; if (card_backup_key) { r = xcalloc (1, sizeof *r + 1); r->key = pCARDBACKUPKEY; strcpy (r->u.value, "1"); r->next = para; para = r; } #endif /*ENABLE_CARD_SUPPORT*/ } else { int subkey_algo; - algo = ask_algo (0, &subkey_algo, &use); + /* Fixme: To support creating a primary key by keygrip we better + also define the keyword for the parameter file. Note that + the subkey case will never be asserted if a keygrip has been + given. */ + algo = ask_algo (ctrl, 0, &subkey_algo, &use, NULL); if (subkey_algo) { /* Create primary and subkey at once. */ both = 1; r = xmalloc_clear( sizeof *r + 20 ); r->key = pKEYTYPE; sprintf( r->u.value, "%d", algo ); r->next = para; para = r; nbits = ask_keysize (algo, 0); r = xmalloc_clear( sizeof *r + 20 ); r->key = pKEYLENGTH; sprintf( r->u.value, "%u", nbits); r->next = para; para = r; r = xmalloc_clear( sizeof *r + 20 ); r->key = pKEYUSAGE; strcpy( r->u.value, "sign" ); r->next = para; para = r; r = xmalloc_clear( sizeof *r + 20 ); r->key = pSUBKEYTYPE; sprintf( r->u.value, "%d", subkey_algo); r->next = para; para = r; r = xmalloc_clear( sizeof *r + 20 ); r->key = pSUBKEYUSAGE; strcpy( r->u.value, "encrypt" ); r->next = para; para = r; } else { r = xmalloc_clear( sizeof *r + 20 ); r->key = pKEYTYPE; sprintf( r->u.value, "%d", algo ); r->next = para; para = r; if (use) { r = xmalloc_clear( sizeof *r + 25 ); r->key = pKEYUSAGE; sprintf( r->u.value, "%s%s%s", (use & PUBKEY_USAGE_SIG)? "sign ":"", (use & PUBKEY_USAGE_ENC)? "encrypt ":"", (use & PUBKEY_USAGE_AUTH)? "auth":"" ); r->next = para; para = r; } nbits = 0; } nbits = ask_keysize (both? subkey_algo : algo, nbits); r = xmalloc_clear( sizeof *r + 20 ); r->key = both? pSUBKEYLENGTH : pKEYLENGTH; sprintf( r->u.value, "%u", nbits); r->next = para; para = r; } expire = ask_expire_interval(0,NULL); r = xmalloc_clear( sizeof *r + 20 ); r->key = pKEYEXPIRE; r->u.expire = expire; r->next = para; para = r; r = xmalloc_clear( sizeof *r + 20 ); r->key = pSUBKEYEXPIRE; r->u.expire = expire; r->next = para; para = r; uid = ask_user_id (0, NULL); if( !uid ) { log_error(_("Key generation canceled.\n")); release_parameter_list( para ); return; } r = xmalloc_clear( sizeof *r + strlen(uid) ); r->key = pUSERID; strcpy( r->u.value, uid ); r->next = para; para = r; proc_parameter_file( para, "[internal]", &outctrl, !!card_serialno); release_parameter_list( para ); } #if 0 /* not required */ /* Generate a raw key and return it as a secret key packet. The function will ask for the passphrase and return a protected as well as an unprotected copy of a new secret key packet. 0 is returned on success and the caller must then free the returned values. */ static int generate_raw_key (int algo, unsigned int nbits, u32 created_at, PKT_secret_key **r_sk_unprotected, PKT_secret_key **r_sk_protected) { int rc; DEK *dek = NULL; STRING2KEY *s2k = NULL; PKT_secret_key *sk = NULL; int i; size_t nskey, npkey; gcry_sexp_t s_parms, s_key; int canceled; npkey = pubkey_get_npkey (algo); nskey = pubkey_get_nskey (algo); assert (nskey <= PUBKEY_MAX_NSKEY && npkey < nskey); if (nbits < 512) { nbits = 512; log_info (_("keysize invalid; using %u bits\n"), nbits ); } if ((nbits % 32)) { nbits = ((nbits + 31) / 32) * 32; log_info(_("keysize rounded up to %u bits\n"), nbits ); } dek = do_ask_passphrase (&s2k, 1, &canceled); if (canceled) { rc = gpg_error (GPG_ERR_CANCELED); goto leave; } sk = xmalloc_clear (sizeof *sk); sk->timestamp = created_at; sk->version = 4; sk->pubkey_algo = algo; if ( !is_RSA (algo) ) { log_error ("only RSA is supported for offline generated keys\n"); rc = gpg_error (GPG_ERR_NOT_IMPLEMENTED); goto leave; } rc = gcry_sexp_build (&s_parms, NULL, "(genkey(rsa(nbits %d)))", (int)nbits); if (rc) log_bug ("gcry_sexp_build failed: %s\n", gpg_strerror (rc)); rc = gcry_pk_genkey (&s_key, s_parms); gcry_sexp_release (s_parms); if (rc) { log_error ("gcry_pk_genkey failed: %s\n", gpg_strerror (rc) ); goto leave; } rc = key_from_sexp (sk->skey, s_key, "private-key", "nedpqu"); gcry_sexp_release (s_key); if (rc) { log_error ("key_from_sexp failed: %s\n", gpg_strerror (rc) ); goto leave; } for (i=npkey; i < nskey; i++) sk->csum += checksum_mpi (sk->skey[i]); if (r_sk_unprotected) *r_sk_unprotected = copy_secret_key (NULL, sk); rc = genhelp_protect (dek, s2k, sk); if (rc) goto leave; if (r_sk_protected) { *r_sk_protected = sk; sk = NULL; } leave: if (sk) free_secret_key (sk); xfree (dek); xfree (s2k); return rc; } #endif /* ENABLE_CARD_SUPPORT */ /* Create and delete a dummy packet to start off a list of kbnodes. */ static void start_tree(KBNODE *tree) { PACKET *pkt; pkt=xmalloc_clear(sizeof(*pkt)); pkt->pkttype=PKT_NONE; *tree=new_kbnode(pkt); delete_kbnode(*tree); } static void do_generate_keypair (struct para_data_s *para, struct output_control_s *outctrl, int card) { gpg_error_t err; KBNODE pub_root = NULL; const char *s; PKT_public_key *pri_psk = NULL; PKT_public_key *sub_psk = NULL; struct revocation_key *revkey; int did_sub = 0; u32 timestamp; char *cache_nonce = NULL; if (outctrl->dryrun) { log_info("dry-run mode - key generation skipped\n"); return; } if ( outctrl->use_files ) { if ( outctrl->pub.newfname ) { iobuf_close(outctrl->pub.stream); outctrl->pub.stream = NULL; if (outctrl->pub.fname) iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0, (char*)outctrl->pub.fname); xfree( outctrl->pub.fname ); outctrl->pub.fname = outctrl->pub.newfname; outctrl->pub.newfname = NULL; if (is_secured_filename (outctrl->pub.fname) ) { outctrl->pub.stream = NULL; gpg_err_set_errno (EPERM); } else outctrl->pub.stream = iobuf_create( outctrl->pub.fname ); if (!outctrl->pub.stream) { log_error(_("can't create `%s': %s\n"), outctrl->pub.newfname, strerror(errno) ); return; } if (opt.armor) { outctrl->pub.afx->what = 1; push_armor_filter (outctrl->pub.afx, outctrl->pub.stream); } } assert( outctrl->pub.stream ); if (opt.verbose) log_info (_("writing public key to `%s'\n"), outctrl->pub.fname ); } /* We create the packets as a tree of kbnodes. Because the structure we create is known in advance we simply generate a linked list. The first packet is a dummy packet which we flag as deleted. The very first packet must always be a KEY packet. */ start_tree (&pub_root); timestamp = get_parameter_u32 (para, pKEYCREATIONDATE); if (!timestamp) timestamp = make_timestamp (); /* Note that, depending on the backend (i.e. the used scdaemon version), the card key generation may update TIMESTAMP for each key. Thus we need to pass TIMESTAMP to all signing function to make sure that the binding signature is done using the timestamp of the corresponding (sub)key and not that of the primary key. An alternative implementation could tell the signing function the node of the subkey but that is more work than just to pass the current timestamp. */ if (!card) err = do_create (get_parameter_algo( para, pKEYTYPE, NULL ), get_parameter_uint( para, pKEYLENGTH ), pub_root, timestamp, get_parameter_u32( para, pKEYEXPIRE ), 0, outctrl->keygen_flags, &cache_nonce); else err = gen_card_key (PUBKEY_ALGO_RSA, 1, 1, pub_root, ×tamp, get_parameter_u32 (para, pKEYEXPIRE)); /* Get the pointer to the generated public key packet. */ if (!err) { pri_psk = pub_root->next->pkt->pkt.public_key; assert (pri_psk); } if (!err && (revkey = get_parameter_revkey (para, pREVOKER))) err = write_direct_sig (pub_root, pri_psk, revkey, timestamp, cache_nonce); if (!err && (s = get_parameter_value (para, pUSERID))) { write_uid (pub_root, s ); err = write_selfsigs (pub_root, pri_psk, get_parameter_uint (para, pKEYUSAGE), timestamp, cache_nonce); } /* Write the auth key to the card before the encryption key. This is a partial workaround for a PGP bug (as of this writing, all versions including 8.1), that causes it to try and encrypt to the most recent subkey regardless of whether that subkey is actually an encryption type. In this case, the auth key is an RSA key so it succeeds. */ if (!err && card && get_parameter (para, pAUTHKEYTYPE)) { err = gen_card_key (PUBKEY_ALGO_RSA, 3, 0, pub_root, ×tamp, get_parameter_u32 (para, pKEYEXPIRE)); if (!err) err = write_keybinding (pub_root, pri_psk, NULL, PUBKEY_USAGE_AUTH, timestamp, cache_nonce); } if (!err && get_parameter (para, pSUBKEYTYPE)) { sub_psk = NULL; if (!card) { err = do_create (get_parameter_algo (para, pSUBKEYTYPE, NULL), get_parameter_uint (para, pSUBKEYLENGTH), pub_root, timestamp, get_parameter_u32 (para, pSUBKEYEXPIRE), 1, outctrl->keygen_flags, &cache_nonce); /* Get the pointer to the generated public subkey packet. */ if (!err) { kbnode_t node; for (node = pub_root; node; node = node->next) if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY) sub_psk = node->pkt->pkt.public_key; assert (sub_psk); } } else { if ((s = get_parameter_value (para, pCARDBACKUPKEY))) { /* A backup of the encryption key has been requested. Generate the key in software and import it then to the card. Write a backup file. */ err = gen_card_key_with_backup (PUBKEY_ALGO_RSA, 2, 0, pub_root, timestamp, get_parameter_u32 (para, pKEYEXPIRE), para); } else { err = gen_card_key (PUBKEY_ALGO_RSA, 2, 0, pub_root, ×tamp, get_parameter_u32 (para, pKEYEXPIRE)); } } if (!err) err = write_keybinding (pub_root, pri_psk, sub_psk, get_parameter_uint (para, pSUBKEYUSAGE), timestamp, cache_nonce); did_sub = 1; } if (!err && outctrl->use_files) /* Direct write to specified files. */ { err = write_keyblock (outctrl->pub.stream, pub_root); if (err) log_error ("can't write public key: %s\n", g10_errstr (err)); } else if (!err) /* Write to the standard keyrings. */ { KEYDB_HANDLE pub_hd = keydb_new (); err = keydb_locate_writable (pub_hd, NULL); if (err) log_error (_("no writable public keyring found: %s\n"), g10_errstr (err)); if (!err && opt.verbose) { log_info (_("writing public key to `%s'\n"), keydb_get_resource_name (pub_hd)); } if (!err) { err = keydb_insert_keyblock (pub_hd, pub_root); if (err) log_error (_("error writing public keyring `%s': %s\n"), keydb_get_resource_name (pub_hd), g10_errstr(err)); } keydb_release (pub_hd); if (!err) { int no_enc_rsa; PKT_public_key *pk; no_enc_rsa = ((get_parameter_algo (para, pKEYTYPE, NULL) == PUBKEY_ALGO_RSA) && get_parameter_uint (para, pKEYUSAGE) && !((get_parameter_uint (para, pKEYUSAGE) & PUBKEY_USAGE_ENC)) ); pk = find_kbnode (pub_root, PKT_PUBLIC_KEY)->pkt->pkt.public_key; keyid_from_pk (pk, pk->main_keyid); register_trusted_keyid (pk->main_keyid); update_ownertrust (pk, ((get_ownertrust (pk) & ~TRUST_MASK) | TRUST_ULTIMATE )); if (!opt.batch) { tty_printf (_("public and secret key created and signed.\n") ); tty_printf ("\n"); list_keyblock (pub_root, 0, 1, NULL); } if (!opt.batch && (get_parameter_algo (para, pKEYTYPE, NULL) == PUBKEY_ALGO_DSA || no_enc_rsa ) && !get_parameter (para, pSUBKEYTYPE) ) { tty_printf(_("Note that this key cannot be used for " "encryption. You may want to use\n" "the command \"--edit-key\" to generate a " "subkey for this purpose.\n") ); } } } if (err) { if (opt.batch) log_error ("key generation failed: %s\n", g10_errstr(err) ); else tty_printf (_("Key generation failed: %s\n"), g10_errstr(err) ); write_status_error (card? "card_key_generate":"key_generate", err); print_status_key_not_created ( get_parameter_value (para, pHANDLE) ); } else { PKT_public_key *pk = find_kbnode (pub_root, PKT_PUBLIC_KEY)->pkt->pkt.public_key; print_status_key_created (did_sub? 'B':'P', pk, get_parameter_value (para, pHANDLE)); } release_kbnode (pub_root); xfree (cache_nonce); } /* Add a new subkey to an existing key. Returns 0 if a new key has been generated and put into the keyblocks. */ gpg_error_t -generate_subkeypair (KBNODE keyblock) +generate_subkeypair (ctrl_t ctrl, kbnode_t keyblock) { gpg_error_t err = 0; kbnode_t node; PKT_public_key *pri_psk = NULL; PKT_public_key *sub_psk = NULL; int algo; unsigned int use; u32 expire; unsigned int nbits; u32 cur_time; char *hexgrip = NULL; char *serialno = NULL; /* Break out the primary key. */ node = find_kbnode (keyblock, PKT_PUBLIC_KEY); if (!node) { log_error ("Oops; primary key missing in keyblock!\n"); err = gpg_error (GPG_ERR_BUG); goto leave; } pri_psk = node->pkt->pkt.public_key; cur_time = make_timestamp (); if (pri_psk->timestamp > cur_time) { ulong d = pri_psk->timestamp - cur_time; log_info ( d==1 ? _("key has been created %lu second " "in future (time warp or clock problem)\n") : _("key has been created %lu seconds " "in future (time warp or clock problem)\n"), d ); if (!opt.ignore_time_conflict) { err = gpg_error (GPG_ERR_TIME_CONFLICT); goto leave; } } if (pri_psk->version < 4) { log_info (_("NOTE: creating subkeys for v3 keys " "is not OpenPGP compliant\n")); err = gpg_error (GPG_ERR_CONFLICT); goto leave; } err = hexkeygrip_from_pk (pri_psk, &hexgrip); if (err) goto leave; if (agent_get_keyinfo (NULL, hexgrip, &serialno)) { tty_printf (_("Secret parts of primary key are not available.\n")); goto leave; } if (serialno) tty_printf (_("Secret parts of primary key are stored on-card.\n")); - algo = ask_algo (1, NULL, &use); + xfree (hexgrip); + hexgrip = NULL; + algo = ask_algo (ctrl, 1, NULL, &use, &hexgrip); assert (algo); - nbits = ask_keysize (algo, 0); + nbits = hexgrip? 0 : ask_keysize (algo, 0); expire = ask_expire_interval (0, NULL); if (!cpr_enabled() && !cpr_get_answer_is_yes("keygen.sub.okay", _("Really create? (y/N) "))) { err = gpg_error (GPG_ERR_CANCELED); goto leave; } - err = do_create (algo, nbits, keyblock, cur_time, expire, 1, 0, NULL); + if (hexgrip) + err = do_create_from_keygrip (ctrl, algo, hexgrip, + keyblock, cur_time, expire, 1); + else + err = do_create (algo, nbits, keyblock, cur_time, expire, 1, 0, NULL); if (err) goto leave; /* Get the pointer to the generated public subkey packet. */ for (node = keyblock; node; node = node->next) if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY) sub_psk = node->pkt->pkt.public_key; /* Write the binding signature. */ err = write_keybinding (keyblock, pri_psk, sub_psk, use, cur_time, NULL); if (err) goto leave; write_status_text (STATUS_KEY_CREATED, "S"); leave: xfree (hexgrip); xfree (serialno); if (err) log_error (_("Key generation failed: %s\n"), g10_errstr (err) ); return err; } #ifdef ENABLE_CARD_SUPPORT /* Generate a subkey on a card. */ gpg_error_t generate_card_subkeypair (kbnode_t pub_keyblock, int keyno, const char *serialno) { gpg_error_t err = 0; kbnode_t node; PKT_public_key *pri_pk = NULL; int algo; unsigned int use; u32 expire; u32 cur_time; struct para_data_s *para = NULL; assert (keyno >= 1 && keyno <= 3); para = xtrycalloc (1, sizeof *para + strlen (serialno) ); if (!para) { err = gpg_error_from_syserror (); goto leave; } para->key = pSERIALNO; strcpy (para->u.value, serialno); /* Break out the primary secret key */ node = find_kbnode (pub_keyblock, PKT_PUBLIC_KEY); if (!node) { log_error ("Oops; publkic key lost!\n"); err = gpg_error (GPG_ERR_INTERNAL); goto leave; } pri_pk = node->pkt->pkt.public_key; cur_time = make_timestamp(); if (pri_pk->timestamp > cur_time) { ulong d = pri_pk->timestamp - cur_time; log_info (d==1 ? _("key has been created %lu second " "in future (time warp or clock problem)\n") : _("key has been created %lu seconds " "in future (time warp or clock problem)\n"), d ); if (!opt.ignore_time_conflict) { err = gpg_error (GPG_ERR_TIME_CONFLICT); goto leave; } } if (pri_pk->version < 4) { log_info (_("NOTE: creating subkeys for v3 keys " "is not OpenPGP compliant\n")); err = gpg_error (GPG_ERR_NOT_SUPPORTED); goto leave; } algo = PUBKEY_ALGO_RSA; expire = ask_expire_interval (0, NULL); if (keyno == 1) use = PUBKEY_USAGE_SIG; else if (keyno == 2) use = PUBKEY_USAGE_ENC; else use = PUBKEY_USAGE_AUTH; if (!cpr_enabled() && !cpr_get_answer_is_yes("keygen.cardsub.okay", _("Really create? (y/N) "))) { err = gpg_error (GPG_ERR_CANCELED); goto leave; } /* Note, that depending on the backend, the card key generation may update CUR_TIME. */ err = gen_card_key (algo, keyno, 0, pub_keyblock, &cur_time, expire); /* Get the pointer to the generated public subkey packet. */ if (!err) { PKT_public_key *sub_pk = NULL; for (node = pub_keyblock; node; node = node->next) if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY) sub_pk = node->pkt->pkt.public_key; assert (sub_pk); err = write_keybinding (pub_keyblock, pri_pk, sub_pk, use, cur_time, NULL); } leave: if (err) log_error (_("Key generation failed: %s\n"), g10_errstr(err) ); else write_status_text (STATUS_KEY_CREATED, "S"); release_parameter_list (para); return err; } #endif /* !ENABLE_CARD_SUPPORT */ /* * Write a keyblock to an output stream */ static int write_keyblock( IOBUF out, KBNODE node ) { for( ; node ; node = node->next ) { if(!is_deleted_kbnode(node)) { int rc = build_packet( out, node->pkt ); if( rc ) { log_error("build_packet(%d) failed: %s\n", node->pkt->pkttype, g10_errstr(rc) ); return rc; } } } return 0; } /* Note that timestamp is an in/out arg. */ static gpg_error_t gen_card_key (int algo, int keyno, int is_primary, kbnode_t pub_root, u32 *timestamp, u32 expireval) { #ifdef ENABLE_CARD_SUPPORT gpg_error_t err; struct agent_card_genkey_s info; PACKET *pkt; PKT_public_key *pk; if (algo != PUBKEY_ALGO_RSA) return gpg_error (GPG_ERR_PUBKEY_ALGO); pk = xtrycalloc (1, sizeof *pk ); if (!pk) return gpg_error_from_syserror (); pkt = xtrycalloc (1, sizeof *pkt); if (!pkt) { xfree (pk); return gpg_error_from_syserror (); } /* Note: SCD knows the serialnumber, thus there is no point in passing it. */ err = agent_scd_genkey (&info, keyno, 1, NULL, *timestamp); /* The code below is not used because we force creation of * the a card key (3rd arg). * if (gpg_err_code (rc) == GPG_ERR_EEXIST) * { * tty_printf ("\n"); * log_error ("WARNING: key does already exists!\n"); * tty_printf ("\n"); * if ( cpr_get_answer_is_yes( "keygen.card.replace_key", * _("Replace existing key? "))) * rc = agent_scd_genkey (&info, keyno, 1); * } */ if (!err && (!info.n || !info.e)) { log_error ("communication error with SCD\n"); gcry_mpi_release (info.n); gcry_mpi_release (info.e); err = gpg_error (GPG_ERR_GENERAL); } if (err) { log_error ("key generation failed: %s\n", gpg_strerror (err)); xfree (pkt); xfree (pk); return err; } if (*timestamp != info.created_at) log_info ("NOTE: the key does not use the suggested creation date\n"); *timestamp = info.created_at; pk->timestamp = info.created_at; pk->version = 4; if (expireval) pk->expiredate = pk->timestamp + expireval; pk->pubkey_algo = algo; pk->pkey[0] = info.n; pk->pkey[1] = info.e; pkt->pkttype = is_primary ? PKT_PUBLIC_KEY : PKT_PUBLIC_SUBKEY; pkt->pkt.public_key = pk; add_kbnode (pub_root, new_kbnode (pkt)); return 0; #else return gpg_error (GPG_ERR_NOT_SUPPORTED); #endif /*!ENABLE_CARD_SUPPORT*/ } static int gen_card_key_with_backup (int algo, int keyno, int is_primary, KBNODE pub_root, u32 timestamp, u32 expireval, struct para_data_s *para) { #if 0 /* FIXME: Move this to gpg-agent. */ int rc; const char *s; PACKET *pkt; PKT_secret_key *sk, *sk_unprotected = NULL, *sk_protected = NULL; PKT_public_key *pk; size_t n; int i; unsigned int nbits; /* Get the size of the key directly from the card. */ { struct agent_card_info_s info; memset (&info, 0, sizeof info); if (!agent_scd_getattr ("KEY-ATTR", &info) && info.key_attr[1].algo) nbits = info.key_attr[1].nbits; else nbits = 1024; /* All pre-v2.0 cards. */ agent_release_card_info (&info); } /* Create a key of this size in memory. */ rc = generate_raw_key (algo, nbits, timestamp, &sk_unprotected, &sk_protected); if (rc) return rc; /* Store the key to the card. */ rc = save_unprotected_key_to_card (sk_unprotected, keyno); if (rc) { log_error (_("storing key onto card failed: %s\n"), g10_errstr (rc)); free_secret_key (sk_unprotected); free_secret_key (sk_protected); write_status_errcode ("save_key_to_card", rc); return rc; } /* Get rid of the secret key parameters and store the serial numer. */ sk = sk_unprotected; n = pubkey_get_nskey (sk->pubkey_algo); for (i=pubkey_get_npkey (sk->pubkey_algo); i < n; i++) { gcry_mpi_release (sk->skey[i]); sk->skey[i] = NULL; } i = pubkey_get_npkey (sk->pubkey_algo); sk->skey[i] = gcry_mpi_set_opaque (NULL, xstrdup ("dummydata"), 10*8); sk->is_protected = 1; sk->protect.s2k.mode = 1002; s = get_parameter_value (para, pSERIALNO); assert (s); for (sk->protect.ivlen=0; sk->protect.ivlen < 16 && *s && s[1]; sk->protect.ivlen++, s += 2) sk->protect.iv[sk->protect.ivlen] = xtoi_2 (s); /* Now write the *protected* secret key to the file. */ { char name_buffer[50]; char *fname; IOBUF fp; mode_t oldmask; keyid_from_sk (sk, NULL); snprintf (name_buffer, sizeof name_buffer, "sk_%08lX%08lX.gpg", (ulong)sk->keyid[0], (ulong)sk->keyid[1]); fname = make_filename (backup_dir, name_buffer, NULL); oldmask = umask (077); if (is_secured_filename (fname)) { fp = NULL; gpg_err_set_errno (EPERM); } else fp = iobuf_create (fname); umask (oldmask); if (!fp) { rc = gpg_error_from_syserror (); log_error (_("can't create backup file `%s': %s\n"), fname, strerror(errno) ); xfree (fname); free_secret_key (sk_unprotected); free_secret_key (sk_protected); return rc; } pkt = xcalloc (1, sizeof *pkt); pkt->pkttype = PKT_SECRET_KEY; pkt->pkt.secret_key = sk_protected; sk_protected = NULL; rc = build_packet (fp, pkt); if (rc) { log_error("build packet failed: %s\n", g10_errstr(rc) ); iobuf_cancel (fp); } else { unsigned char array[MAX_FINGERPRINT_LEN]; char *fprbuf, *p; iobuf_close (fp); iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0, (char*)fname); log_info (_("NOTE: backup of card key saved to `%s'\n"), fname); fingerprint_from_sk (sk, array, &n); p = fprbuf = xmalloc (MAX_FINGERPRINT_LEN*2 + 1 + 1); for (i=0; i < n ; i++, p += 2) sprintf (p, "%02X", array[i]); *p++ = ' '; *p = 0; write_status_text_and_buffer (STATUS_BACKUP_KEY_CREATED, fprbuf, fname, strlen (fname), 0); xfree (fprbuf); } free_packet (pkt); xfree (pkt); xfree (fname); if (rc) { free_secret_key (sk_unprotected); return rc; } } /* Create the public key from the secret key. */ pk = xcalloc (1, sizeof *pk ); pk->timestamp = sk->timestamp; pk->version = sk->version; if (expireval) pk->expiredate = sk->expiredate = sk->timestamp + expireval; pk->pubkey_algo = sk->pubkey_algo; n = pubkey_get_npkey (sk->pubkey_algo); for (i=0; i < n; i++) pk->pkey[i] = mpi_copy (sk->skey[i]); /* Build packets and add them to the node lists. */ pkt = xcalloc (1,sizeof *pkt); pkt->pkttype = is_primary ? PKT_PUBLIC_KEY : PKT_PUBLIC_SUBKEY; pkt->pkt.public_key = pk; add_kbnode(pub_root, new_kbnode( pkt )); pkt = xcalloc (1,sizeof *pkt); pkt->pkttype = is_primary ? PKT_SECRET_KEY : PKT_SECRET_SUBKEY; pkt->pkt.secret_key = sk; add_kbnode(sec_root, new_kbnode( pkt )); return 0; #else return gpg_error (GPG_ERR_NOT_SUPPORTED); #endif /*!ENABLE_CARD_SUPPORT*/ } #if 0 int save_unprotected_key_to_card (PKT_public_key *sk, int keyno) { int rc; unsigned char *rsa_n = NULL; unsigned char *rsa_e = NULL; unsigned char *rsa_p = NULL; unsigned char *rsa_q = NULL; size_t rsa_n_len, rsa_e_len, rsa_p_len, rsa_q_len; unsigned char *sexp = NULL; unsigned char *p; char numbuf[55], numbuf2[50]; assert (is_RSA (sk->pubkey_algo)); assert (!sk->is_protected); /* Copy the parameters into straight buffers. */ gcry_mpi_aprint (GCRYMPI_FMT_USG, &rsa_n, &rsa_n_len, sk->skey[0]); gcry_mpi_aprint (GCRYMPI_FMT_USG, &rsa_e, &rsa_e_len, sk->skey[1]); gcry_mpi_aprint (GCRYMPI_FMT_USG, &rsa_p, &rsa_p_len, sk->skey[3]); gcry_mpi_aprint (GCRYMPI_FMT_USG, &rsa_q, &rsa_q_len, sk->skey[4]); if (!rsa_n || !rsa_e || !rsa_p || !rsa_q) { rc = G10ERR_INV_ARG; goto leave; } /* Put the key into an S-expression. */ sexp = p = xmalloc_secure (30 + rsa_n_len + rsa_e_len + rsa_p_len + rsa_q_len + 4*sizeof (numbuf) + 25 + sizeof(numbuf) + 20); p = stpcpy (p,"(11:private-key(3:rsa(1:n"); sprintf (numbuf, "%u:", (unsigned int)rsa_n_len); p = stpcpy (p, numbuf); memcpy (p, rsa_n, rsa_n_len); p += rsa_n_len; sprintf (numbuf, ")(1:e%u:", (unsigned int)rsa_e_len); p = stpcpy (p, numbuf); memcpy (p, rsa_e, rsa_e_len); p += rsa_e_len; sprintf (numbuf, ")(1:p%u:", (unsigned int)rsa_p_len); p = stpcpy (p, numbuf); memcpy (p, rsa_p, rsa_p_len); p += rsa_p_len; sprintf (numbuf, ")(1:q%u:", (unsigned int)rsa_q_len); p = stpcpy (p, numbuf); memcpy (p, rsa_q, rsa_q_len); p += rsa_q_len; p = stpcpy (p,"))(10:created-at"); sprintf (numbuf2, "%lu", (unsigned long)sk->timestamp); sprintf (numbuf, "%lu:", (unsigned long)strlen (numbuf2)); p = stpcpy (stpcpy (stpcpy (p, numbuf), numbuf2), "))"); /* Fixme: Unfortunately we don't have the serialnumber available - thus we can't pass it down to the agent. */ rc = agent_scd_writekey (keyno, NULL, sexp, p - sexp); leave: xfree (sexp); xfree (rsa_n); xfree (rsa_e); xfree (rsa_p); xfree (rsa_q); return rc; } #endif /*ENABLE_CARD_SUPPORT*/ diff --git a/g10/main.h b/g10/main.h index 9548731fc..7088abec9 100644 --- a/g10/main.h +++ b/g10/main.h @@ -1,374 +1,374 @@ /* main.h * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, * 2008, 2009, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * * GnuPG is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * GnuPG is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ #ifndef G10_MAIN_H #define G10_MAIN_H #include "types.h" #include "iobuf.h" #include "cipher.h" #include "keydb.h" #include "util.h" /* It could be argued that the default cipher should be 3DES rather than CAST5, and the default compression should be 0 (i.e. uncompressed) rather than 1 (zip). However, the real world issues of speed and size come into play here. */ #define DEFAULT_CIPHER_ALGO CIPHER_ALGO_CAST5 #define DEFAULT_DIGEST_ALGO DIGEST_ALGO_SHA1 #define DEFAULT_S2K_DIGEST_ALGO DIGEST_ALGO_SHA1 #ifdef HAVE_ZIP # define DEFAULT_COMPRESS_ALGO COMPRESS_ALGO_ZIP #else # define DEFAULT_COMPRESS_ALGO COMPRESS_ALGO_NONE #endif #define S2K_DIGEST_ALGO (opt.s2k_digest_algo?opt.s2k_digest_algo:DEFAULT_S2K_DIGEST_ALGO) typedef struct { int header_okay; PK_LIST pk_list; DEK *symkey_dek; STRING2KEY *symkey_s2k; cipher_filter_context_t cfx; } encrypt_filter_context_t; struct groupitem { char *name; strlist_t values; struct groupitem *next; }; /*-- gpg.c --*/ extern int g10_errors_seen; #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 ) void g10_exit(int rc) __attribute__ ((noreturn)); #else void g10_exit(int rc); #endif void print_pubkey_algo_note( int algo ); void print_cipher_algo_note( int algo ); void print_digest_algo_note( int algo ); /*-- armor.c --*/ char *make_radix64_string( const byte *data, size_t len ); /*-- misc.c --*/ void trap_unaligned(void); int disable_core_dumps(void); void register_secured_file (const char *fname); void unregister_secured_file (const char *fname); int is_secured_file (int fd); int is_secured_filename (const char *fname); u16 checksum_u16( unsigned n ); u16 checksum( byte *p, unsigned n ); u16 checksum_mpi( gcry_mpi_t a ); u32 buffer_to_u32( const byte *buffer ); const byte *get_session_marker( size_t *rlen ); int map_cipher_openpgp_to_gcry (int algo); #define openpgp_cipher_open(_a,_b,_c,_d) \ gcry_cipher_open((_a),map_cipher_openpgp_to_gcry((_b)),(_c),(_d)) #define openpgp_cipher_get_algo_keylen(_a) \ gcry_cipher_get_algo_keylen(map_cipher_openpgp_to_gcry((_a))) #define openpgp_cipher_get_algo_blklen(_a) \ gcry_cipher_get_algo_blklen(map_cipher_openpgp_to_gcry((_a))) int openpgp_cipher_blocklen (int algo); int openpgp_cipher_test_algo( int algo ); const char *openpgp_cipher_algo_name (int algo); int map_pk_openpgp_to_gcry (int algo); int map_pk_gcry_to_openpgp (enum gcry_pk_algos algo); int openpgp_pk_test_algo( int algo ); int openpgp_pk_test_algo2 ( int algo, unsigned int use ); int openpgp_pk_algo_usage ( int algo ); int openpgp_md_test_algo( int algo ); const char *openpgp_pk_algo_name (int algo); const char *openpgp_md_algo_name (int algo); #ifdef USE_IDEA void idea_cipher_warn( int show ); #else #define idea_cipher_warn(a) do { } while (0) #endif struct expando_args { PKT_public_key *pk; PKT_public_key *pksk; byte imagetype; int validity_info; const char *validity_string; }; char *pct_expando(const char *string,struct expando_args *args); void deprecated_warning(const char *configname,unsigned int configlineno, const char *option,const char *repl1,const char *repl2); void deprecated_command (const char *name); void obsolete_option (const char *configname, unsigned int configlineno, const char *name); int string_to_cipher_algo (const char *string); int string_to_digest_algo (const char *string); const char *compress_algo_to_string(int algo); int string_to_compress_algo(const char *string); int check_compress_algo(int algo); int default_cipher_algo(void); int default_compress_algo(void); const char *compliance_option_string(void); void compliance_failure(void); struct parse_options { char *name; unsigned int bit; char **value; char *help; }; char *optsep(char **stringp); char *argsplit(char *string); int parse_options(char *str,unsigned int *options, struct parse_options *opts,int noisy); int has_invalid_email_chars (const char *s); int is_valid_mailbox (const char *name); const char *get_libexecdir (void); int path_access(const char *file,int mode); int pubkey_get_npkey( int algo ); int pubkey_get_nskey( int algo ); int pubkey_get_nsig( int algo ); int pubkey_get_nenc( int algo ); /* Temporary helpers. */ unsigned int pubkey_nbits( int algo, gcry_mpi_t *pkey ); int mpi_print (estream_t stream, gcry_mpi_t a, int mode); unsigned int ecdsa_qbits_from_Q (unsigned int qbits); /*-- status.c --*/ void set_status_fd ( int fd ); int is_status_enabled ( void ); void write_status ( int no ); void write_status_error (const char *where, gpg_error_t err); void write_status_errcode (const char *where, int errcode); void write_status_text ( int no, const char *text ); void write_status_buffer ( int no, const char *buffer, size_t len, int wrap ); void write_status_text_and_buffer ( int no, const char *text, const char *buffer, size_t len, int wrap ); void write_status_begin_signing (gcry_md_hd_t md); int cpr_enabled(void); char *cpr_get( const char *keyword, const char *prompt ); char *cpr_get_no_help( const char *keyword, const char *prompt ); char *cpr_get_utf8( const char *keyword, const char *prompt ); char *cpr_get_hidden( const char *keyword, const char *prompt ); void cpr_kill_prompt(void); int cpr_get_answer_is_yes( const char *keyword, const char *prompt ); int cpr_get_answer_yes_no_quit( const char *keyword, const char *prompt ); int cpr_get_answer_okay_cancel (const char *keyword, const char *prompt, int def_answer); /*-- helptext.c --*/ void display_online_help( const char *keyword ); /*-- encode.c --*/ int setup_symkey (STRING2KEY **symkey_s2k,DEK **symkey_dek); int encrypt_symmetric (const char *filename ); int encrypt_store (const char *filename ); int encrypt_crypt (ctrl_t ctrl, int filefd, const char *filename, strlist_t remusr, int use_symkey, pk_list_t provided_keys, int outputfd); void encrypt_crypt_files (ctrl_t ctrl, int nfiles, char **files, strlist_t remusr); int encrypt_filter (void *opaque, int control, iobuf_t a, byte *buf, size_t *ret_len); /*-- sign.c --*/ int complete_sig (PKT_signature *sig, PKT_public_key *pksk, gcry_md_hd_t md, const char *cache_nonce); int sign_file (ctrl_t ctrl, strlist_t filenames, int detached, strlist_t locusr, int do_encrypt, strlist_t remusr, const char *outfile ); int clearsign_file( const char *fname, strlist_t locusr, const char *outfile ); int sign_symencrypt_file (const char *fname, strlist_t locusr); /*-- sig-check.c --*/ int check_revocation_keys (PKT_public_key *pk, PKT_signature *sig); int check_backsig(PKT_public_key *main_pk,PKT_public_key *sub_pk, PKT_signature *backsig); int check_key_signature( KBNODE root, KBNODE node, int *is_selfsig ); int check_key_signature2( KBNODE root, KBNODE node, PKT_public_key *check_pk, PKT_public_key *ret_pk, int *is_selfsig, u32 *r_expiredate, int *r_expired ); /*-- delkey.c --*/ int delete_keys( strlist_t names, int secret, int allow_both ); /*-- keyedit.c --*/ void keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr, strlist_t commands, int quiet, int seckey_check ); void keyedit_passwd (ctrl_t ctrl, const char *username); void show_basic_key_info (KBNODE keyblock); /*-- keygen.c --*/ const char *gpg_curve_to_oid (const char *name, unsigned int *r_nbits); u32 parse_expire_string(const char *string); u32 ask_expire_interval(int object,const char *def_expire); u32 ask_expiredate(void); -void generate_keypair (const char *fname, const char *card_serialno, - int card_backup_key); +void generate_keypair (ctrl_t ctrl, const char *fname, + const char *card_serialno, int card_backup_key); int keygen_set_std_prefs (const char *string,int personal); PKT_user_id *keygen_get_std_prefs (void); int keygen_add_key_expire( PKT_signature *sig, void *opaque ); int keygen_add_std_prefs( PKT_signature *sig, void *opaque ); int keygen_upd_std_prefs( PKT_signature *sig, void *opaque ); int keygen_add_keyserver_url(PKT_signature *sig, void *opaque); int keygen_add_notations(PKT_signature *sig,void *opaque); int keygen_add_revkey(PKT_signature *sig, void *opaque); gpg_error_t make_backsig (PKT_signature *sig, PKT_public_key *pk, PKT_public_key *sub_pk, PKT_public_key *sub_psk, u32 timestamp, const char *cache_nonce); -gpg_error_t generate_subkeypair (kbnode_t pub_keyblock); +gpg_error_t generate_subkeypair (ctrl_t ctrl, kbnode_t pub_keyblock); #ifdef ENABLE_CARD_SUPPORT gpg_error_t generate_card_subkeypair (kbnode_t pub_keyblock, int keyno, const char *serialno); int save_unprotected_key_to_card (PKT_public_key *sk, int keyno); #endif /*-- openfile.c --*/ int overwrite_filep( const char *fname ); char *make_outfile_name( const char *iname ); char *ask_outfile_name( const char *name, size_t namelen ); int open_outfile (int inp_fd, const char *iname, int mode, iobuf_t *a); iobuf_t open_sigfile( const char *iname, progress_filter_context_t *pfx ); void try_make_homedir( const char *fname ); /*-- seskey.c --*/ void make_session_key( DEK *dek ); gcry_mpi_t encode_session_key( int openpgp_pk_algo, DEK *dek, unsigned nbits ); gcry_mpi_t encode_md_value (PKT_public_key *pk, gcry_md_hd_t md, int hash_algo ); /*-- import.c --*/ int parse_import_options(char *str,unsigned int *options,int noisy); void import_keys (ctrl_t ctrl, char **fnames, int nnames, void *stats_hd, unsigned int options); int import_keys_stream (ctrl_t ctrl, iobuf_t inp, void *stats_hd, unsigned char **fpr, size_t *fpr_len, unsigned int options); int import_keys_es_stream (ctrl_t ctrl, estream_t fp, void *stats_handle, unsigned char **fpr, size_t *fpr_len, unsigned int options); void *import_new_stats_handle (void); void import_release_stats_handle (void *p); void import_print_stats (void *hd); int collapse_uids( KBNODE *keyblock ); /*-- export.c --*/ int parse_export_options(char *str,unsigned int *options,int noisy); int export_pubkeys (ctrl_t ctrl, strlist_t users, unsigned int options ); int export_pubkeys_stream (ctrl_t ctrl, iobuf_t out, strlist_t users, kbnode_t *keyblock_out, unsigned int options ); gpg_error_t export_pubkey_buffer (ctrl_t ctrl, const char *keyspec, unsigned int options, kbnode_t *r_keyblock, void **r_data, size_t *r_datalen); int export_seckeys (ctrl_t ctrl, strlist_t users); int export_secsubkeys (ctrl_t ctrl, strlist_t users); /*-- dearmor.c --*/ int dearmor_file( const char *fname ); int enarmor_file( const char *fname ); /*-- revoke.c --*/ struct revocation_reason_info; int gen_revoke( const char *uname ); int gen_desig_revoke( const char *uname, strlist_t locusr); int revocation_reason_build_cb( PKT_signature *sig, void *opaque ); struct revocation_reason_info * ask_revocation_reason( int key_rev, int cert_rev, int hint ); void release_revocation_reason_info( struct revocation_reason_info *reason ); /*-- keylist.c --*/ void public_key_list (ctrl_t ctrl, strlist_t list, int locate_mode ); void secret_key_list (ctrl_t ctrl, strlist_t list ); void print_subpackets_colon(PKT_signature *sig); void reorder_keyblock (KBNODE keyblock); void list_keyblock( KBNODE keyblock, int secret, int fpr, void *opaque ); void print_fingerprint (PKT_public_key *pk, int mode); void print_revokers(PKT_public_key *pk); void show_policy_url(PKT_signature *sig,int indent,int mode); void show_keyserver_url(PKT_signature *sig,int indent,int mode); void show_notation(PKT_signature *sig,int indent,int mode,int which); void dump_attribs (const PKT_user_id *uid, PKT_public_key *pk); void set_attrib_fd(int fd); void print_seckey_info (PKT_public_key *pk); void print_pubkey_info (estream_t fp, PKT_public_key *pk); void print_card_key_info (estream_t fp, KBNODE keyblock); /*-- verify.c --*/ void print_file_status( int status, const char *name, int what ); int verify_signatures (ctrl_t ctrl, int nfiles, char **files ); int verify_files (ctrl_t ctrl, int nfiles, char **files ); int gpg_verify (ctrl_t ctrl, int sig_fd, int data_fd, estream_t out_fp); /*-- decrypt.c --*/ int decrypt_message (ctrl_t ctrl, const char *filename ); gpg_error_t decrypt_message_fd (ctrl_t ctrl, int input_fd, int output_fd); void decrypt_messages (ctrl_t ctrl, int nfiles, char *files[]); /*-- plaintext.c --*/ int hash_datafiles( gcry_md_hd_t md, gcry_md_hd_t md2, strlist_t files, const char *sigfilename, int textmode ); int hash_datafile_by_fd ( gcry_md_hd_t md, gcry_md_hd_t md2, int data_fd, int textmode ); PKT_plaintext *setup_plaintext_name(const char *filename,IOBUF iobuf); /*-- signal.c --*/ void init_signals(void); void block_all_signals(void); void unblock_all_signals(void); /*-- server.c --*/ int gpg_server (ctrl_t); #ifdef ENABLE_CARD_SUPPORT /*-- card-util.c --*/ void change_pin (int no, int allow_admin); void card_status (estream_t fp, char *serialno, size_t serialnobuflen); void card_edit (ctrl_t ctrl, strlist_t commands); gpg_error_t card_generate_subkey (KBNODE pub_keyblock); int card_store_subkey (KBNODE node, int use); #endif #define S2K_DECODE_COUNT(_val) ((16ul + ((_val) & 15)) << (((_val) >> 4) + 6)) #endif /*G10_MAIN_H*/