2
* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4
* This file is part of GnuPG.
6
* GnuPG is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* GnuPG is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
39
release_sk_list( SK_LIST sk_list )
43
for( ; sk_list; sk_list = sk_rover ) {
44
sk_rover = sk_list->next;
45
free_secret_key( sk_list->sk );
53
key_present_in_sk_list(SK_LIST sk_list, PKT_secret_key *sk)
55
for (; sk_list; sk_list = sk_list->next) {
56
if ( !cmp_secret_keys(sk_list->sk, sk) )
63
is_duplicated_entry (STRLIST list, STRLIST item)
65
for(; list && list != item; list = list->next) {
66
if ( !strcmp (list->d, item->d) )
74
build_sk_list( STRLIST locusr, SK_LIST *ret_sk_list,
75
int unlock, unsigned int use )
77
SK_LIST sk_list = NULL;
80
if( !locusr ) { /* use the default one */
83
sk = xcalloc (1, sizeof *sk );
85
if( (rc = get_seckey_byname( sk, NULL, unlock )) ) {
86
free_secret_key( sk ); sk = NULL;
87
log_error("no default secret key: %s\n", gpg_strerror (rc) );
89
else if( !(rc=openpgp_pk_test_algo (sk->pubkey_algo, use)) ) {
92
if( sk->version == 4 && (use & PUBKEY_USAGE_SIG)
93
&& sk->pubkey_algo == PUBKEY_ALGO_ELGAMAL_E ) {
94
log_info("this is a PGP generated "
95
"ElGamal key which is NOT secure for signatures!\n");
96
free_secret_key( sk ); sk = NULL;
99
r = xmalloc ( sizeof *r );
100
r->sk = sk; sk = NULL;
107
free_secret_key( sk ); sk = NULL;
108
log_error("invalid default secret key: %s\n", gpg_strerror (rc) );
112
STRLIST locusr_orig = locusr;
113
for(; locusr; locusr = locusr->next ) {
117
/* Do an early check agains duplicated entries. However this
118
* won't catch all duplicates because the user IDs may be
119
* specified in different ways.
121
if ( is_duplicated_entry ( locusr_orig, locusr ) ) {
122
log_error(_("skipped `%s': duplicated\n"), locusr->d );
125
sk = xcalloc (1, sizeof *sk );
127
if( (rc = get_seckey_byname( sk, locusr->d, 0 )) ) {
128
free_secret_key( sk ); sk = NULL;
129
log_error(_("skipped `%s': %s\n"), locusr->d, gpg_strerror (rc) );
131
else if ( key_present_in_sk_list(sk_list, sk) == 0) {
132
free_secret_key(sk); sk = NULL;
133
log_info(_("skipped: secret key already present\n"));
135
else if ( unlock && (rc = check_secret_key( sk, 0 )) ) {
136
free_secret_key( sk ); sk = NULL;
137
log_error(_("skipped `%s': %s\n"), locusr->d, gpg_strerror (rc) );
139
else if( !(rc=openpgp_pk_test_algo (sk->pubkey_algo, use)) ) {
142
if( sk->version == 4 && (use & PUBKEY_USAGE_SIG)
143
&& sk->pubkey_algo == PUBKEY_ALGO_ELGAMAL_E ) {
144
log_info(_("skipped `%s': this is a PGP generated "
145
"ElGamal key which is not secure for signatures!\n"),
147
free_secret_key( sk ); sk = NULL;
150
r = xmalloc ( sizeof *r );
151
r->sk = sk; sk = NULL;
158
free_secret_key( sk ); sk = NULL;
159
log_error("skipped `%s': %s\n", locusr->d, gpg_strerror (rc) );
165
if( !rc && !sk_list ) {
166
log_error("no valid signators\n");
167
rc = GPG_ERR_NO_USER_ID;
171
release_sk_list( sk_list );
173
*ret_sk_list = sk_list;