From: Karl-Heinz Zimmer Date: Sat, 27 Apr 2002 05:32:39 +0000 (+0000) Subject: allow checking of Opaque Signed message data X-Git-Tag: gpgme-1.2.0@1385~1009 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a9a0c6df0e64fbafb05e1fe6d6546046e47799b5;p=gpgme.git allow checking of Opaque Signed message data --- diff --git a/trunk/gpgmeplug/cryptplug.h b/trunk/gpgmeplug/cryptplug.h index c3a0979..72cfdf4 100644 --- a/trunk/gpgmeplug/cryptplug.h +++ b/trunk/gpgmeplug/cryptplug.h @@ -1449,9 +1449,18 @@ struct SignatureMetaData { /*! \ingroup groupSignAct \brief Checks whether the signature of a message is - valid. \c ciphertext specifies the signed message - as it was received by the MUA, \c signaturetext is the - signature itself. + valid. + + \c cleartext must never be 0 but be a valid pointer. + + If \c *cleartext > 0 then **cleartext specifies the message text + that was signed and \c signaturetext is the signature itself. + + If \c *cleartext == 0 is an empty string then \c signaturetext is + supposed to contain an opaque signed message part. After checking the + data and verifying the signature the cleartext of the message will be + returned in \c cleartext. The user must free the respective memory + ocupied by *cleartext. Depending on the configuration, MUAs might not need to use this. If \c sigmeta is non-null, the @@ -1459,7 +1468,7 @@ struct SignatureMetaData { contain meta information about the signature after the function call. */ -bool checkMessageSignature( const char* ciphertext, +bool checkMessageSignature( char** cleartext, const char* signaturetext, bool signatureIsBinary, int signatureLen, diff --git a/trunk/gpgmeplug/gpgmeplug.c b/trunk/gpgmeplug/gpgmeplug.c index 7c3c25e..12cf200 100644 --- a/trunk/gpgmeplug/gpgmeplug.c +++ b/trunk/gpgmeplug/gpgmeplug.c @@ -81,6 +81,7 @@ #define GPGMEPLUG_SIGN_FLAT_POSTFIX "" #define __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY false #endif +#define __GPGMEPLUG_ERROR_CLEARTEXT_IS_ZERO "Error: Cannot run checkMessageSignature() with cleartext == 0" /* definitions for encoding */ #ifndef GPGMEPLUG_ENC_MAKE_MIME_OBJECT #define GPGMEPLUG_ENC_INCLUDE_CLEARTEXT false @@ -1028,7 +1029,7 @@ sig_status_to_string( GpgmeSigStat status ) } -bool checkMessageSignature( const char* ciphertext, +bool checkMessageSignature( char** cleartext, const char* signaturetext, bool signatureIsBinary, int signatureLen, @@ -1037,20 +1038,39 @@ bool checkMessageSignature( const char* ciphertext, GpgmeCtx ctx; GpgmeSigStat status; GpgmeData datapart, sigpart; + char* rClear = 0; + size_t clearLen; GpgmeError err; GpgmeKey key; time_t created; int sig_idx = 0; const char* statusStr; const char* fpr; + bool isOpaqueSigned; + + if( !cleartext ) { + if( sigmeta ) { + sigmeta->status = malloc( strlen( __GPGMEPLUG_ERROR_CLEARTEXT_IS_ZERO ) + 1 ); + if( sigmeta->status ) { + strcpy( sigmeta->status, __GPGMEPLUG_ERROR_CLEARTEXT_IS_ZERO ); + sigmeta->status[ strlen( __GPGMEPLUG_ERROR_CLEARTEXT_IS_ZERO ) ] = '\0'; + } + } + return false; + } + + isOpaqueSigned = !*cleartext; gpgme_new( &ctx ); gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL); gpgme_set_armor (ctx, signatureIsBinary ? 0 : 1); /* gpgme_set_textmode (ctx, signatureIsBinary ? 0 : 1); */ - gpgme_data_new_from_mem( &datapart, ciphertext, - strlen( ciphertext ), 1 ); + if( isOpaqueSigned ) + gpgme_data_new( &datapart ); + else + gpgme_data_new_from_mem( &datapart, *cleartext, + strlen( *cleartext ), 1 ); gpgme_data_new_from_mem( &sigpart, signaturetext, @@ -1060,7 +1080,20 @@ bool checkMessageSignature( const char* ciphertext, 1 ); gpgme_op_verify( ctx, sigpart, datapart, &status ); - gpgme_data_release( datapart ); + + if( isOpaqueSigned ) { + rClear = gpgme_data_release_and_get_mem( datapart, &clearLen ); + *cleartext = malloc( clearLen + 1 ); + if( *cleartext ) { + if( clearLen ) + strncpy(*cleartext, rClear, clearLen ); + (*cleartext)[clearLen] = '\0'; + } + free( rClear ); + } + else + gpgme_data_release( datapart ); + gpgme_data_release( sigpart ); /* Provide information in the sigmeta struct */