From ed9f9969e378fd2d15a875a5e100b87bddd1a75a Mon Sep 17 00:00:00 2001 From: Karl-Heinz Zimmer Date: Fri, 8 Mar 2002 15:44:09 +0000 Subject: [PATCH] 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. --- gpgmeplug/cryptplug.h | 8 +++++ gpgmeplug/gpgmeplug.c | 73 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 66 insertions(+), 15 deletions(-) diff --git a/gpgmeplug/cryptplug.h b/gpgmeplug/cryptplug.h index ba346de..ce2e75a 100644 --- a/gpgmeplug/cryptplug.h +++ b/gpgmeplug/cryptplug.h @@ -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 diff --git a/gpgmeplug/gpgmeplug.c b/gpgmeplug/gpgmeplug.c index 389092f..f9e17ac 100644 --- a/gpgmeplug/gpgmeplug.c +++ b/gpgmeplug/gpgmeplug.c @@ -1091,8 +1091,8 @@ bool storeCertificatesFromMessage( const char* ciphertext ){ return true; } -/* returns address if address doesn't contain a part - * else it returns a new string xxx and frees address +/* returns address if address doesn't contain a part + * else it returns a new string xxx and frees address */ static char* parseAddress( char* address ) { @@ -1138,15 +1138,15 @@ static char* nextAddress( const char** address ) int found = 0; if( *address == NULL ) return NULL; while( **address ) { - + switch( **address ) { case '\\': /* escaped character */ ++(*address); break; case '"': if( comment == 0 ) { - if( quote > 0 ) --quote; - else ++quote; + if( quote > 0 ) --quote; + else ++quote; } break; case '(': /* comment start */ @@ -1154,11 +1154,11 @@ static char* nextAddress( const char** address ) break; case ')': /* comment end */ if( quote == 0 ) --comment; - break; + break; case '\0': - case ',': /* delimiter */ + case '\1': /* delimiter */ if( quote == 0 && comment == 0 ) { - found = 1; + found = 1; } break; } @@ -1173,14 +1173,53 @@ static char* nextAddress( const char** address ) result = malloc( len*sizeof(char)+1 ); strncpy( result, start, len ); result[len] = '\0'; - } + } } return parseAddress(result); } -bool encryptMessage( const char* cleartext, +/* + 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,11 +1253,15 @@ 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 ) { - gpgme_recipients_add_name (rset, 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); } -- 2.26.2