mirror of
git://git.gnupg.org/gnupg.git
synced 2025-02-07 17:33:02 +01:00
Re-indent and changed return type.
This commit is contained in:
parent
a1412b05de
commit
ac823ac671
@ -358,7 +358,7 @@ keyserver_import_ldap (const char *name)
|
|||||||
/* Stub:
|
/* Stub:
|
||||||
* No encryption here but mainproc links to these functions.
|
* No encryption here but mainproc links to these functions.
|
||||||
*/
|
*/
|
||||||
int
|
gpg_error_t
|
||||||
get_session_key (PKT_pubkey_enc *k, DEK *dek)
|
get_session_key (PKT_pubkey_enc *k, DEK *dek)
|
||||||
{
|
{
|
||||||
(void)k;
|
(void)k;
|
||||||
@ -367,7 +367,7 @@ get_session_key (PKT_pubkey_enc *k, DEK *dek)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Stub: */
|
/* Stub: */
|
||||||
int
|
gpg_error_t
|
||||||
get_override_session_key (DEK *dek, const char *string)
|
get_override_session_key (DEK *dek, const char *string)
|
||||||
{
|
{
|
||||||
(void)dek;
|
(void)dek;
|
||||||
|
@ -480,8 +480,8 @@ int signature_check2( PKT_signature *sig, gcry_md_hd_t digest, u32 *r_expiredate
|
|||||||
int is_secret_key_protected (PKT_public_key *pk);
|
int is_secret_key_protected (PKT_public_key *pk);
|
||||||
|
|
||||||
/*-- pubkey-enc.c --*/
|
/*-- pubkey-enc.c --*/
|
||||||
int get_session_key( PKT_pubkey_enc *k, DEK *dek );
|
gpg_error_t get_session_key (PKT_pubkey_enc *k, DEK *dek);
|
||||||
int get_override_session_key( DEK *dek, const char *string );
|
gpg_error_t get_override_session_key (DEK *dek, const char *string);
|
||||||
|
|
||||||
/*-- compress.c --*/
|
/*-- compress.c --*/
|
||||||
int handle_compressed( void *ctx, PKT_compressed *cd,
|
int handle_compressed( void *ctx, PKT_compressed *cd,
|
||||||
|
147
g10/pubkey-enc.c
147
g10/pubkey-enc.c
@ -1,6 +1,6 @@
|
|||||||
/* pubkey-enc.c - public key encoded packet handling
|
/* pubkey-enc.c - Process a public key encoded packet.
|
||||||
* Copyright (C) 1998, 1999, 2000, 2001, 2002,
|
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2006, 2009,
|
||||||
* 2006, 2009 Free Software Foundation, Inc.
|
* 2010 Free Software Foundation, Inc.
|
||||||
*
|
*
|
||||||
* This file is part of GnuPG.
|
* This file is part of GnuPG.
|
||||||
*
|
*
|
||||||
@ -38,23 +38,25 @@
|
|||||||
#include "call-agent.h"
|
#include "call-agent.h"
|
||||||
|
|
||||||
|
|
||||||
static int get_it( PKT_pubkey_enc *k,
|
static gpg_error_t get_it (PKT_pubkey_enc *k,
|
||||||
DEK *dek, PKT_secret_key *sk, u32 *keyid);
|
DEK *dek, PKT_secret_key *sk, u32 *keyid);
|
||||||
|
|
||||||
|
|
||||||
/* check that the given algo is mentioned in one of the valid user IDs */
|
/* Check that the given algo is mentioned in one of the valid user-ids. */
|
||||||
static int
|
static int
|
||||||
is_algo_in_prefs ( KBNODE keyblock, preftype_t type, int algo )
|
is_algo_in_prefs (kbnode_t keyblock, preftype_t type, int algo)
|
||||||
{
|
{
|
||||||
KBNODE k;
|
kbnode_t k;
|
||||||
|
|
||||||
for (k=keyblock; k; k=k->next) {
|
for (k = keyblock; k; k = k->next)
|
||||||
if (k->pkt->pkttype == PKT_USER_ID) {
|
{
|
||||||
|
if (k->pkt->pkttype == PKT_USER_ID)
|
||||||
|
{
|
||||||
PKT_user_id *uid = k->pkt->pkt.user_id;
|
PKT_user_id *uid = k->pkt->pkt.user_id;
|
||||||
prefitem_t *prefs = uid->prefs;
|
prefitem_t *prefs = uid->prefs;
|
||||||
|
|
||||||
if (uid->created && prefs &&
|
if (uid->created && prefs && !uid->is_revoked && !uid->is_expired)
|
||||||
!uid->is_revoked && !uid->is_expired ) {
|
{
|
||||||
for (; prefs->type; prefs++)
|
for (; prefs->type; prefs++)
|
||||||
if (prefs->type == type && prefs->value == algo)
|
if (prefs->type == type && prefs->value == algo)
|
||||||
return 1;
|
return 1;
|
||||||
@ -65,11 +67,11 @@ is_algo_in_prefs ( KBNODE keyblock, preftype_t type, int algo )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************
|
/*
|
||||||
* Get the session key from a pubkey enc packet and return
|
* Get the session key from a pubkey enc packet and return it in DEK,
|
||||||
* it in DEK, which should have been allocated in secure memory.
|
* which should have been allocated in secure memory by the caller.
|
||||||
*/
|
*/
|
||||||
int
|
gpg_error_t
|
||||||
get_session_key (PKT_pubkey_enc * k, DEK * dek)
|
get_session_key (PKT_pubkey_enc * k, DEK * dek)
|
||||||
{
|
{
|
||||||
PKT_secret_key *sk = NULL;
|
PKT_secret_key *sk = NULL;
|
||||||
@ -79,25 +81,29 @@ get_session_key( PKT_pubkey_enc *k, DEK *dek )
|
|||||||
if (rc)
|
if (rc)
|
||||||
goto leave;
|
goto leave;
|
||||||
|
|
||||||
if( (k->keyid[0] || k->keyid[1]) && !opt.try_all_secrets ) {
|
if ((k->keyid[0] || k->keyid[1]) && !opt.try_all_secrets)
|
||||||
|
{
|
||||||
sk = xmalloc_clear (sizeof *sk);
|
sk = xmalloc_clear (sizeof *sk);
|
||||||
sk->pubkey_algo = k->pubkey_algo; /* we want a pubkey with this algo*/
|
sk->pubkey_algo = k->pubkey_algo; /* We want a pubkey with this algo */
|
||||||
if (!(rc = get_seckey (sk, k->keyid)))
|
if (!(rc = get_seckey (sk, k->keyid)))
|
||||||
rc = get_it (k, dek, sk, k->keyid);
|
rc = get_it (k, dek, sk, k->keyid);
|
||||||
}
|
}
|
||||||
else if (opt.skip_hidden_recipients)
|
else if (opt.skip_hidden_recipients)
|
||||||
rc = gpg_error (GPG_ERR_NO_SECKEY);
|
rc = gpg_error (GPG_ERR_NO_SECKEY);
|
||||||
else { /* anonymous receiver: Try all available secret keys */
|
else /* Anonymous receiver: Try all available secret keys. */
|
||||||
|
{
|
||||||
void *enum_context = NULL;
|
void *enum_context = NULL;
|
||||||
u32 keyid[2];
|
u32 keyid[2];
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
for(;;) {
|
for (;;)
|
||||||
|
{
|
||||||
if (sk)
|
if (sk)
|
||||||
free_secret_key (sk);
|
free_secret_key (sk);
|
||||||
sk = xmalloc_clear (sizeof *sk);
|
sk = xmalloc_clear (sizeof *sk);
|
||||||
rc = enum_secret_keys (&enum_context, sk, 1, 0);
|
rc = enum_secret_keys (&enum_context, sk, 1, 0);
|
||||||
if( rc ) {
|
if (rc)
|
||||||
|
{
|
||||||
rc = G10ERR_NO_SECKEY;
|
rc = G10ERR_NO_SECKEY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -120,15 +126,14 @@ get_session_key( PKT_pubkey_enc *k, DEK *dek )
|
|||||||
/* if( !rc ) */
|
/* if( !rc ) */
|
||||||
{
|
{
|
||||||
rc = get_it (k, dek, sk, keyid);
|
rc = get_it (k, dek, sk, keyid);
|
||||||
/* Successfully checked the secret key (either it was
|
/* Successfully checked the secret key (either it was a
|
||||||
a card, had no passphrase, or had the right
|
card, had no passphrase, or had the right passphrase)
|
||||||
passphrase) but couldn't decrypt the session key,
|
but couldn't decrypt the session key, so thus that key
|
||||||
so thus that key is not the anonymous recipient.
|
is not the anonymous recipient. Move the next
|
||||||
Move the next passphrase into last for the next
|
passphrase into last for the next round. We only do
|
||||||
round. We only do this if the secret key was
|
this if the secret key was successfully checked as in
|
||||||
successfully checked as in the normal case,
|
the normal case, check_secret_key handles this for us
|
||||||
check_secret_key handles this for us via
|
via passphrase_to_dek. */
|
||||||
passphrase_to_dek */
|
|
||||||
if (rc)
|
if (rc)
|
||||||
next_to_last_passphrase ();
|
next_to_last_passphrase ();
|
||||||
}
|
}
|
||||||
@ -149,7 +154,7 @@ get_session_key( PKT_pubkey_enc *k, DEK *dek )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static gpg_error_t
|
||||||
get_it (PKT_pubkey_enc *enc, DEK *dek, PKT_secret_key *sk, u32 *keyid)
|
get_it (PKT_pubkey_enc *enc, DEK *dek, PKT_secret_key *sk, u32 *keyid)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
@ -170,9 +175,11 @@ get_it( PKT_pubkey_enc *enc, DEK *dek, PKT_secret_key *sk, u32 *keyid )
|
|||||||
unsigned char *indata = NULL;
|
unsigned char *indata = NULL;
|
||||||
size_t indatalen;
|
size_t indatalen;
|
||||||
|
|
||||||
snbuf = serialno_and_fpr_from_sk (sk->protect.iv, sk->protect.ivlen, sk);
|
snbuf =
|
||||||
|
serialno_and_fpr_from_sk (sk->protect.iv, sk->protect.ivlen, sk);
|
||||||
|
|
||||||
if (gcry_mpi_aprint (GCRYMPI_FMT_USG, &indata, &indatalen, enc->data[0]))
|
if (gcry_mpi_aprint
|
||||||
|
(GCRYMPI_FMT_USG, &indata, &indatalen, enc->data[0]))
|
||||||
BUG ();
|
BUG ();
|
||||||
|
|
||||||
rc = agent_scd_pkdecrypt (snbuf, indata, indatalen, &rbuf, &rbuflen);
|
rc = agent_scd_pkdecrypt (snbuf, indata, indatalen, &rbuf, &rbuflen);
|
||||||
@ -196,7 +203,8 @@ get_it( PKT_pubkey_enc *enc, DEK *dek, PKT_secret_key *sk, u32 *keyid )
|
|||||||
goto leave;
|
goto leave;
|
||||||
if (gcry_mpi_aprint (GCRYMPI_FMT_USG, &frame, &nframe, plain_dek))
|
if (gcry_mpi_aprint (GCRYMPI_FMT_USG, &frame, &nframe, plain_dek))
|
||||||
BUG ();
|
BUG ();
|
||||||
gcry_mpi_release (plain_dek); plain_dek = NULL;
|
gcry_mpi_release (plain_dek);
|
||||||
|
plain_dek = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now get the DEK (data encryption key) from the frame
|
/* Now get the DEK (data encryption key) from the frame
|
||||||
@ -222,60 +230,77 @@ get_it( PKT_pubkey_enc *enc, DEK *dek, PKT_secret_key *sk, u32 *keyid )
|
|||||||
if (!card)
|
if (!card)
|
||||||
{
|
{
|
||||||
if (n + 7 > nframe)
|
if (n + 7 > nframe)
|
||||||
{ rc = G10ERR_WRONG_SECKEY; goto leave; }
|
{
|
||||||
if( frame[n] == 1 && frame[nframe-1] == 2 ) {
|
rc = G10ERR_WRONG_SECKEY;
|
||||||
|
goto leave;
|
||||||
|
}
|
||||||
|
if (frame[n] == 1 && frame[nframe - 1] == 2)
|
||||||
|
{
|
||||||
log_info (_("old encoding of the DEK is not supported\n"));
|
log_info (_("old encoding of the DEK is not supported\n"));
|
||||||
rc = G10ERR_CIPHER_ALGO;
|
rc = G10ERR_CIPHER_ALGO;
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
if( frame[n] != 2 ) /* somethink is wrong */
|
if (frame[n] != 2) /* Somethink is wrong. */
|
||||||
{ rc = G10ERR_WRONG_SECKEY; goto leave; }
|
{
|
||||||
for(n++; n < nframe && frame[n]; n++ ) /* skip the random bytes */
|
rc = G10ERR_WRONG_SECKEY;
|
||||||
|
goto leave;
|
||||||
|
}
|
||||||
|
for (n++; n < nframe && frame[n]; n++) /* Skip the random bytes. */
|
||||||
;
|
;
|
||||||
n++; /* and the zero byte */
|
n++; /* Skip the zero byte. */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n + 4 > nframe)
|
if (n + 4 > nframe)
|
||||||
{ rc = G10ERR_WRONG_SECKEY; goto leave; }
|
{
|
||||||
|
rc = G10ERR_WRONG_SECKEY;
|
||||||
|
goto leave;
|
||||||
|
}
|
||||||
|
|
||||||
dek->keylen = nframe - (n + 1) - 2;
|
dek->keylen = nframe - (n + 1) - 2;
|
||||||
dek->algo = frame[n++];
|
dek->algo = frame[n++];
|
||||||
if (dek->algo == CIPHER_ALGO_IDEA)
|
if (dek->algo == CIPHER_ALGO_IDEA)
|
||||||
write_status (STATUS_RSA_OR_IDEA);
|
write_status (STATUS_RSA_OR_IDEA);
|
||||||
rc = openpgp_cipher_test_algo (dek->algo);
|
rc = openpgp_cipher_test_algo (dek->algo);
|
||||||
if( rc ) {
|
if (rc)
|
||||||
if( !opt.quiet && gpg_err_code (rc) == GPG_ERR_CIPHER_ALGO ) {
|
{
|
||||||
|
if (!opt.quiet && gpg_err_code (rc) == GPG_ERR_CIPHER_ALGO)
|
||||||
|
{
|
||||||
log_info (_("cipher algorithm %d%s is unknown or disabled\n"),
|
log_info (_("cipher algorithm %d%s is unknown or disabled\n"),
|
||||||
dek->algo, dek->algo == CIPHER_ALGO_IDEA? " (IDEA)":"");
|
dek->algo,
|
||||||
|
dek->algo == CIPHER_ALGO_IDEA ? " (IDEA)" : "");
|
||||||
if (dek->algo == CIPHER_ALGO_IDEA)
|
if (dek->algo == CIPHER_ALGO_IDEA)
|
||||||
idea_cipher_warn (0);
|
idea_cipher_warn (0);
|
||||||
}
|
}
|
||||||
dek->algo = 0;
|
dek->algo = 0;
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
if ( dek->keylen != openpgp_cipher_get_algo_keylen (dek->algo) ) {
|
if (dek->keylen != openpgp_cipher_get_algo_keylen (dek->algo))
|
||||||
|
{
|
||||||
rc = GPG_ERR_WRONG_SECKEY;
|
rc = GPG_ERR_WRONG_SECKEY;
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copy the key to DEK and compare the checksum */
|
/* Copy the key to DEK and compare the checksum. */
|
||||||
csum = frame[nframe - 2] << 8;
|
csum = frame[nframe - 2] << 8;
|
||||||
csum |= frame[nframe - 1];
|
csum |= frame[nframe - 1];
|
||||||
memcpy (dek->key, frame + n, dek->keylen);
|
memcpy (dek->key, frame + n, dek->keylen);
|
||||||
for (csum2 = 0, n = 0; n < dek->keylen; n++)
|
for (csum2 = 0, n = 0; n < dek->keylen; n++)
|
||||||
csum2 += dek->key[n];
|
csum2 += dek->key[n];
|
||||||
if( csum != csum2 ) {
|
if (csum != csum2)
|
||||||
|
{
|
||||||
rc = G10ERR_WRONG_SECKEY;
|
rc = G10ERR_WRONG_SECKEY;
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
if (DBG_CIPHER)
|
if (DBG_CIPHER)
|
||||||
log_printhex ("DEK is:", dek->key, dek->keylen);
|
log_printhex ("DEK is:", dek->key, dek->keylen);
|
||||||
/* check that the algo is in the preferences and whether it has expired */
|
|
||||||
|
/* Check that the algo is in the preferences and whether it has expired. */
|
||||||
{
|
{
|
||||||
PKT_public_key *pk = NULL;
|
PKT_public_key *pk = NULL;
|
||||||
KBNODE pkb = get_pubkeyblock (keyid);
|
KBNODE pkb = get_pubkeyblock (keyid);
|
||||||
|
|
||||||
if( !pkb ) {
|
if (!pkb)
|
||||||
|
{
|
||||||
rc = -1;
|
rc = -1;
|
||||||
log_error ("oops: public key not found for preference check\n");
|
log_error ("oops: public key not found for preference check\n");
|
||||||
}
|
}
|
||||||
@ -285,16 +310,20 @@ get_it( PKT_pubkey_enc *enc, DEK *dek, PKT_secret_key *sk, u32 *keyid )
|
|||||||
&& !is_algo_in_prefs (pkb, PREFTYPE_SYM, dek->algo))
|
&& !is_algo_in_prefs (pkb, PREFTYPE_SYM, dek->algo))
|
||||||
log_info (_("WARNING: cipher algorithm %s not found in recipient"
|
log_info (_("WARNING: cipher algorithm %s not found in recipient"
|
||||||
" preferences\n"), openpgp_cipher_algo_name (dek->algo));
|
" preferences\n"), openpgp_cipher_algo_name (dek->algo));
|
||||||
if (!rc) {
|
if (!rc)
|
||||||
|
{
|
||||||
KBNODE k;
|
KBNODE k;
|
||||||
|
|
||||||
for (k=pkb; k; k = k->next) {
|
for (k = pkb; k; k = k->next)
|
||||||
|
{
|
||||||
if (k->pkt->pkttype == PKT_PUBLIC_KEY
|
if (k->pkt->pkttype == PKT_PUBLIC_KEY
|
||||||
|| k->pkt->pkttype == PKT_PUBLIC_SUBKEY){
|
|| k->pkt->pkttype == PKT_PUBLIC_SUBKEY)
|
||||||
|
{
|
||||||
u32 aki[2];
|
u32 aki[2];
|
||||||
keyid_from_pk (k->pkt->pkt.public_key, aki);
|
keyid_from_pk (k->pkt->pkt.public_key, aki);
|
||||||
|
|
||||||
if (aki[0]==keyid[0] && aki[1]==keyid[1]) {
|
if (aki[0] == keyid[0] && aki[1] == keyid[1])
|
||||||
|
{
|
||||||
pk = k->pkt->pkt.public_key;
|
pk = k->pkt->pkt.public_key;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -302,13 +331,15 @@ get_it( PKT_pubkey_enc *enc, DEK *dek, PKT_secret_key *sk, u32 *keyid )
|
|||||||
}
|
}
|
||||||
if (!pk)
|
if (!pk)
|
||||||
BUG ();
|
BUG ();
|
||||||
if ( pk->expiredate && pk->expiredate <= make_timestamp() ) {
|
if (pk->expiredate && pk->expiredate <= make_timestamp ())
|
||||||
|
{
|
||||||
log_info (_("NOTE: secret key %s expired at %s\n"),
|
log_info (_("NOTE: secret key %s expired at %s\n"),
|
||||||
keystr (keyid), asctimestamp (pk->expiredate));
|
keystr (keyid), asctimestamp (pk->expiredate));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( pk && pk->is_revoked ) {
|
if (pk && pk->is_revoked)
|
||||||
|
{
|
||||||
log_info (_("NOTE: key has been revoked"));
|
log_info (_("NOTE: key has been revoked"));
|
||||||
log_printf ("\n");
|
log_printf ("\n");
|
||||||
show_revocation_reason (pk, 1);
|
show_revocation_reason (pk, 1);
|
||||||
@ -326,12 +357,12 @@ get_it( PKT_pubkey_enc *enc, DEK *dek, PKT_secret_key *sk, u32 *keyid )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************
|
/*
|
||||||
* Get the session key from the given string.
|
* Get the session key from the given string.
|
||||||
* String is supposed to be formatted as this:
|
* String is supposed to be formatted as this:
|
||||||
* <algo-id>:<even-number-of-hex-digits>
|
* <algo-id>:<even-number-of-hex-digits>
|
||||||
*/
|
*/
|
||||||
int
|
gpg_error_t
|
||||||
get_override_session_key (DEK *dek, const char *string)
|
get_override_session_key (DEK *dek, const char *string)
|
||||||
{
|
{
|
||||||
const char *s;
|
const char *s;
|
||||||
@ -345,7 +376,8 @@ get_override_session_key( DEK *dek, const char *string )
|
|||||||
if (!(s = strchr (string, ':')))
|
if (!(s = strchr (string, ':')))
|
||||||
return G10ERR_BAD_KEY;
|
return G10ERR_BAD_KEY;
|
||||||
s++;
|
s++;
|
||||||
for(i=0; i < DIM(dek->key) && *s; i++, s +=2 ) {
|
for (i = 0; i < DIM (dek->key) && *s; i++, s += 2)
|
||||||
|
{
|
||||||
int c = hextobyte (s);
|
int c = hextobyte (s);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
return G10ERR_BAD_KEY;
|
return G10ERR_BAD_KEY;
|
||||||
@ -356,4 +388,3 @@ get_override_session_key( DEK *dek, const char *string )
|
|||||||
dek->keylen = i;
|
dek->keylen = i;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user