New feature: Ask user which certificate is to be taken when more than one found by the crypto plug-in for a single recipient. - NOTE: This code is not working correctly (yet) so we allways get some *all* keys that are stored by gpg instead of the right key information.

This commit is contained in:
Karl-Heinz Zimmer 2002-03-08 15:44:09 +00:00
parent af75bafc1b
commit ed9f9969e3
2 changed files with 66 additions and 15 deletions

View File

@ -1453,6 +1453,14 @@ bool checkMessageSignature( const char* ciphertext,
bool storeCertificatesFromMessage( const char* ciphertext );
/*! \ingroup groupCryptAct
\brief Find all certificate for a given addressee.
NOTE: The \c certificate parameter must point to an allready allocated
block of memory which is large enough to hold the complete list.
*/
bool findCertificates( const char* addressee, char** certificates );
/*! \ingroup groupCryptAct
\brief Encrypts an email message in
\c cleartext according to the \c addressee and

View File

@ -1156,7 +1156,7 @@ static char* nextAddress( const char** address )
if( quote == 0 ) --comment;
break;
case '\0':
case ',': /* delimiter */
case '\1': /* delimiter */
if( quote == 0 && comment == 0 ) {
found = 1;
}
@ -1178,9 +1178,48 @@ static char* nextAddress( const char** address )
return parseAddress(result);
}
/*
Find all certificate for a given addressee and return them in a
'\1' separated list.
NOTE: The certificate parameter must point to an allready allocated
block of memory which is large enough to hold the complete list.
*/
bool findCertificates( const char* addressee, char** certificates )
{
GpgmeCtx ctx;
GpgmeError err;
GpgmeKey rKey;
const char *s;
const char *s2;
bool bOk = false;
gpgme_new (&ctx);
gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL);
err = gpgme_op_keylist_start(ctx, addressee, 0);
while( GPGME_No_Error == err ) {
err = gpgme_op_keylist_next(ctx, &rKey);
if( GPGME_No_Error == err ) {
bOk = true;
s = gpgme_key_get_string_attr (rKey, GPGME_ATTR_USERID, NULL, 0);
if( s ) {
s2 = gpgme_key_get_string_attr (rKey, GPGME_ATTR_FPR, NULL, 0);
if( s2 ) {
strcat( *certificates, s );
strcat( *certificates, "(" );
strcat( *certificates, s2 );
strcat( *certificates, ")\1" );
}
}
}
}
gpgme_op_keylist_end( ctx );
return bOk;
}
bool encryptMessage( const char* cleartext,
const char** ciphertext,
const char* addressee,
const char* certificate,
struct StructuringInfo* structuring )
{
GpgmeCtx ctx;
@ -1205,7 +1244,7 @@ bool encryptMessage( const char* cleartext,
gpgme_recipients_new (&rset);
/*
if( GPGMEPLUG_PROTOCOL == GPGME_PROTOCOL_CMS )
{
gpgme_recipients_add_name_with_validity (rset,
@ -1214,10 +1253,14 @@ bool encryptMessage( const char* cleartext,
fputs( "\nGPGSMPLUG encryptMessage() using test key of Aegypten Project\n", stderr );
}
else
*/
{
const char* p = addressee;
const char* p = certificate;
char* tok;
while( (tok = nextAddress( &p ) ) != 0 ) {
if( GPGMEPLUG_PROTOCOL == GPGME_PROTOCOL_CMS )
gpgme_recipients_add_name_with_validity (rset, tok, GPGME_VALIDITY_FULL );
else
gpgme_recipients_add_name (rset, tok);
fprintf( stderr, "\nGPGMEPLUG encryptMessage() using addressee %s\n", tok );
free(tok);