diff options
| -rw-r--r-- | gpgmeplug/cryptplug.h | 15 | ||||
| -rw-r--r-- | gpgmeplug/gpgme-openpgp.c | 2 | ||||
| -rw-r--r-- | gpgmeplug/gpgme-smime.c | 2 | ||||
| -rw-r--r-- | gpgmeplug/gpgmeplug.c | 58 | 
4 files changed, 52 insertions, 25 deletions
diff --git a/gpgmeplug/cryptplug.h b/gpgmeplug/cryptplug.h index e3aea6ca..c390b6e6 100644 --- a/gpgmeplug/cryptplug.h +++ b/gpgmeplug/cryptplug.h @@ -1386,7 +1386,12 @@ struct StructuringInfo {  /*! \ingroup groupSignAct     \brief Signs a message \c cleartext and returns            in \c *ciphertext the signature data bloc that -          is to be added to the message. +          is to be added to the message. The length returned +          in \c *cipherLen tells you the size (==amount of bytes) +          of the ciphertext, if the structuring information +          would return with contentTEncCode set to "base64" +          the ciphertext might contain a char 0x00 +          and has to be converted into base64 before sending.     The signature role is specified by \c certificate.     If \c certificate is \c NULL, the default certificate is used. @@ -1416,6 +1421,7 @@ struct StructuringInfo {  */  bool signMessage( const char*  cleartext,                    const char** ciphertext, +                  const size_t* cipherLen,                    const char*  certificate,                    struct StructuringInfo* structuring ); @@ -1477,6 +1483,12 @@ bool findCertificates( const char* addressee, char** certificates );            \c cleartext according to the \c addressee and            the current settings (algorithm, etc.) and            returns the encoded data bloc in \c *ciphertext. +          The length returned in \c *cipherLen tells you the +          size (==amount of bytes) of the ciphertext, if the +          structuring information would return with +          contentTEncCode set to "base64" the ciphertext +          might contain a char 0x00 and has to be converted +          into base64 before sending.     If the message could be encrypted, the function returns            \c true, otherwise @@ -1501,6 +1513,7 @@ bool findCertificates( const char* addressee, char** certificates );  */  bool encryptMessage( const char*  cleartext,                       const char** ciphertext, +                     const size_t* cipherLen,                       const char*  addressee,                       struct StructuringInfo* structuring ); diff --git a/gpgmeplug/gpgme-openpgp.c b/gpgmeplug/gpgme-openpgp.c index dce22bea..042a11dc 100644 --- a/gpgmeplug/gpgme-openpgp.c +++ b/gpgmeplug/gpgme-openpgp.c @@ -16,6 +16,7 @@  #define GPGMEPLUG_SIGN_FLAT_PREFIX       ""  #define GPGMEPLUG_SIGN_FLAT_SEPARATOR    ""  #define GPGMEPLUG_SIGN_FLAT_POSTFIX      "" +#define __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY true  #define GPGMEPLUG_ENC_INCLUDE_CLEARTEXT  false  #define GPGMEPLUG_ENC_MAKE_MIME_OBJECT   true @@ -33,5 +34,6 @@  #define GPGMEPLUG_ENC_FLAT_PREFIX        ""  #define GPGMEPLUG_ENC_FLAT_SEPARATOR     ""  #define GPGMEPLUG_ENC_FLAT_POSTFIX       "" +#define __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY false  #include "gpgmeplug.c" diff --git a/gpgmeplug/gpgme-smime.c b/gpgmeplug/gpgme-smime.c index 088c8d53..70fff085 100644 --- a/gpgmeplug/gpgme-smime.c +++ b/gpgmeplug/gpgme-smime.c @@ -16,6 +16,7 @@  #define GPGMEPLUG_SIGN_FLAT_PREFIX       ""  #define GPGMEPLUG_SIGN_FLAT_SEPARATOR    ""  #define GPGMEPLUG_SIGN_FLAT_POSTFIX      "" +#define __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY true  #define GPGMEPLUG_ENC_INCLUDE_CLEARTEXT  false  #define GPGMEPLUG_ENC_MAKE_MIME_OBJECT   true @@ -33,5 +34,6 @@  #define GPGMEPLUG_ENC_FLAT_PREFIX        ""  #define GPGMEPLUG_ENC_FLAT_SEPARATOR     ""  #define GPGMEPLUG_ENC_FLAT_POSTFIX       "" +#define __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY true  #include "gpgmeplug.c" diff --git a/gpgmeplug/gpgmeplug.c b/gpgmeplug/gpgmeplug.c index 5b856e8c..333ddf81 100644 --- a/gpgmeplug/gpgmeplug.c +++ b/gpgmeplug/gpgmeplug.c @@ -79,6 +79,7 @@  #define GPGMEPLUG_SIGN_FLAT_PREFIX       ""  #define GPGMEPLUG_SIGN_FLAT_SEPARATOR    ""  #define GPGMEPLUG_SIGN_FLAT_POSTFIX      "" +#define __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY false  #endif  // definitions for encoding  #ifndef GPGMEPLUG_ENC_MAKE_MIME_OBJECT @@ -98,6 +99,7 @@  #define GPGMEPLUG_ENC_FLAT_PREFIX        ""  #define GPGMEPLUG_ENC_FLAT_SEPARATOR     ""  #define GPGMEPLUG_ENC_FLAT_POSTFIX       "" +#define __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY false  #endif  // Note: The following specification will result in  //       function encryptAndSignMessage() producing @@ -860,15 +862,15 @@ void storeNewCharPtr( char** dest, const char* src )  bool signMessage( const char*  cleartext,                    const char** ciphertext, +                  const size_t* cipherLen,                    const char*  certificate,                    struct StructuringInfo* structuring )  {    GpgmeCtx ctx;    GpgmeError err;    GpgmeData data,  sig; -  size_t rSLen = 0; -  char*  rSig  = 0; -  bool   bOk   = false; +  char* rSig  = 0; +  bool  bOk   = false;    int sendCerts = 1;    init_StructuringInfo( structuring ); @@ -879,8 +881,8 @@ bool signMessage( const char*  cleartext,    err = gpgme_new (&ctx);    gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL); -  gpgme_set_armor (ctx, 1); -  gpgme_set_textmode (ctx, 1); +  gpgme_set_armor (ctx, __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY ? 0 : 1); +//  gpgme_set_textmode (ctx, 1);    switch ( config.sendCertificates ) {      case SendCert_undef: @@ -912,16 +914,20 @@ bool signMessage( const char*  cleartext,    err = gpgme_op_sign (ctx, data, sig, GPGME_SIG_MODE_DETACH );    if (!err) { -    rSig  = gpgme_data_release_and_get_mem( sig,  &rSLen ); -    *ciphertext = malloc( rSLen + 1 ); -    if( *ciphertext ) { -      if( rSLen ) { -        bOk = true; -        strncpy((char*)*ciphertext, rSig, rSLen ); +    if( __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY ) +      *ciphertext = gpgme_data_release_and_get_mem( sig, (size_t*)cipherLen ); +    else { +      rSig = gpgme_data_release_and_get_mem( sig, (size_t*)cipherLen ); +      *ciphertext = malloc( *cipherLen + 1 ); +      if( *ciphertext ) { +        if( *cipherLen ) { +          bOk = true; +          strncpy((char*)*ciphertext, rSig, *cipherLen ); +        } +        ((char*)(*ciphertext))[*cipherLen] = '\0';        } -      ((char*)(*ciphertext))[rSLen] = '\0'; +      free( rSig );      } -    free( rSig );    }    else {      gpgme_data_release( sig ); @@ -1238,6 +1244,7 @@ bool findCertificates( const char* addressee, char** certificates )  bool encryptMessage( const char*  cleartext,                       const char** ciphertext, +                     const size_t* cipherLen,                       const char*  certificate,                       struct StructuringInfo* structuring )  { @@ -1245,7 +1252,6 @@ bool encryptMessage( const char*  cleartext,    GpgmeError err;    GpgmeData gCiphertext, gPlaintext;    GpgmeRecipients rset; -  size_t rCLen = 0;    char*  rCiph = 0;    bool   bOk   = false; @@ -1254,8 +1260,8 @@ bool encryptMessage( const char*  cleartext,    gpgme_new (&ctx);    gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL); -  gpgme_set_armor (ctx, 1); -  gpgme_set_textmode (ctx, 1); +  gpgme_set_armor (ctx, __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY ? 0 : 1); +//  gpgme_set_textmode (ctx, 1);    gpgme_data_new_from_mem (&gPlaintext, cleartext,                              1+strlen( cleartext ), 1 ); @@ -1308,16 +1314,20 @@ bool encryptMessage( const char*  cleartext,    gpgme_data_release (gPlaintext);    if( !err ) { -    rCiph = gpgme_data_release_and_get_mem( gCiphertext,  &rCLen ); -    *ciphertext = malloc( rCLen + 1 ); -    if( *ciphertext ) { -      if( rCLen ) { -        bOk = true; -        strncpy((char*)*ciphertext, rCiph, rCLen ); +    if( __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY ) +      *ciphertext = gpgme_data_release_and_get_mem( gCiphertext, (size_t*)cipherLen ); +    else { +      rCiph = gpgme_data_release_and_get_mem( gCiphertext, (size_t*)cipherLen ); +      *ciphertext = malloc( *cipherLen + 1 ); +      if( *ciphertext ) { +        if( *cipherLen ) { +          bOk = true; +          strncpy((char*)*ciphertext, rCiph, *cipherLen ); +        } +        ((char*)(*ciphertext))[*cipherLen] = 0;        } -      ((char*)(*ciphertext))[rCLen] = 0; +      free( rCiph );      } -    free( rCiph );    }    else {      gpgme_data_release ( gCiphertext );  | 
