certmanager/lib

#include <cryptplugwrapper.h>

Public Member Functions

 StructuringInfoWrapper (CryptPlugWrapper *wrapper)
 
void reset ()
 

Public Attributes

CryptPlug::StructuringInfo data
 

Detailed Description

This class provides C++ access to the StructuringInfo helper struct that is specified in cryptplug.h to hold information returned by signing and by encrypting functions.

Use this information to compose a MIME object containing signed and/or encrypted content (or to build a text frame around your flat non-MIME message body, resp.)

Note
This class is different from the respective cryptplug.h class because this one takes care for freeing the char** members' memory automatically. You must not call the free function for any of it's members - just ignore the advise given in the cryptplug.h documentation!

If value returned in makeMimeObject is TRUE the text strings returned in contentTypeMain and contentDispMain and contentTEncMain (and, if required, content[..]Version and bodyTextVersion and content[..]Sig) should be used to compose a respective MIME object.
If FALSE the texts returned in flatTextPrefix and flatTextSeparator and flatTextPostfix are to be used instead.
Always either the content[..] and bodyTextVersion parameters or the flatText[..] parameters are holding valid data - never both of them may be used simultaneously as plugins will just ignore the parameters not matching their makeMimeObject setting.

When creating your MIME object please observe these common rules:

  • Parameters named contentType[..] and contentDisp[..] and contentTEnc[..] will return the values for the respective MIME headers 'Content-Type' and 'Content-Disposition' and 'Content-Transfer-Encoding'. The following applies to these parameters:
  • The relevant MIME part may only be created if the respective contentType[..] parameter is holding a non-zero-length string. If the contentType[..] parameter value is invalid or holding an empty string the respective contentDisp[..] and contentTEnc[..] parameters should be ignored.
  • If the respective contentDisp[..] or contentTEnc[..] parameter is NULL or holding a zero-length string it is up to you whether you want to add the relevant MIME header yourself, but since it in in the responsibility of the plugin implementors to provide you with all necessary 'Content-[..]' header information you should not need to define them if they are not returned by the signing or encrypting function - otherwise this may be considered as a bug in the plugin and you could report the missing MIME header information to the address returned by the bugURL() function.

If makeMultiMime returns FALSE the contentTypeMain returned must not be altered but used to specify a single part mime object holding the code bloc, e.g. this is used for 'enveloped-data' single part MIME objects. In this case you should ignore both the content[..]Version and content[..]Code parameters.

If makeMultiMime returns TRUE also the following rules apply:

  • If includeCleartext is TRUE you should include the cleartext as first part of our multipart MIME object, typically this is TRUE when signing mails but FALSE when encrypting.
  • The contentTypeMain returned typically starts with "multipart/" while providing a "protocol" and a "micalg" parameter: just add an appropriate "; boundary=[your \c boundary \c string]" to get the complete Content-Type value to be used for the MIME object embedding both the signed part and the signature part (or - in case of encrypting - the version part and the code part, resp.).
  • If contentTypeVersion is holding a non-zero-length string an additional MIME part must added immediately before the code part, this version part's MIME headers must have the unaltered values of contentTypeVersion and (if they are holding non-zero-length strings) contentDispVersion and contentTEncVersion, the unaltered contents of bodyTextVersion must be it's body.
  • The value returned in contentTypeCode is specifying the complete Content-Type to be used for this multipart MIME object's signature part (or - in case of encrypting - for the code part following after the version part, resp.), you should not add/change/remove anything here but just use it's unaltered value for specifying the Content-Type header of the respective MIME part.
  • The same applies to the contentDispCode value: just use it's unaltered value to specify the Content-Disposition header entry of the respective MIME part.
  • The same applies to the contentTEncCode value: just use it's unaltered value to specify the Content-Transfer-Encoding header of the respective MIME part.

If value returned in makeMimeObject is FALSE the text strings returned in flatTextPrefix and flatTextPostfix should be used to build a frame around the cleartext and the code bloc holding the signature (or - in case of encrypting - the encoded data bloc, resp.).
If includeCleartext is TRUE this frame should also include the cleartext as first bloc, this bloc should be divided from the code bloc by the contents of flatTextSeparator - typically this is used for signing but not when encrypting.
If includeCleartext is FALSE you should ignore both the cleartext and the flatTextSeparator parameter.

How to use StructuringInfoWrapper data in your program:

  • To compose a signed message please act as described below.
  • For constructing an encrypted message just replace the signMessage() call by the respective encryptMessage() call and then proceed exactly the same way.
  • In any case make sure to free your ciphertext when you are done with processing the data returned by the signing (or encrypting, resp.) function.
    char* ciphertext;
    StructuringInfoWrapper structInf;

    if( ! signMessage( cleartext, &ciphertext, certificate,
                      structInf ) ) {

        myErrorDialog( "Error: could not sign the message!" );

    } else {
      if( structInf.data.makeMimeObject ) {

        // Build the main MIME object.
        // This is done by
        // using the header values returned in
        // structInf.data.contentTypeMain and in
        // structInf.data.contentDispMain and in
        // structInf.data.contentTEncMain.
        ..

        if( ! structInf.data.makeMultiMime ) {

          // Build the main MIME object's body.
          // This is done by
          // using the code bloc returned in
          // ciphertext.
          ..

        } else {

          // Build the encapsulated MIME parts.
          if( structInf.data.includeCleartext ) {

            // Build a MIME part holding the cleartext.
            // This is done by
            // using the original cleartext's headers and by
            // taking it's original body text.
            ..

          }
          if(    structInf.data.contentTypeVersion
              && 0 < strlen( structInf.data.contentTypeVersion ) ) {

            // Build a MIME part holding the version information.
            // This is done by
            // using the header values returned in
            // structInf.data.contentTypeVersion and
            // structInf.data.contentDispVersion and
            // structInf.data.contentTEncVersion and by
            // taking the body contents returned in
            // structInf.data.bodyTextVersion.
            ..

          }
          if(    structInf.data.contentTypeCode
              && 0 < strlen( structInf.data.contentTypeCode ) ) {

            // Build a MIME part holding the code information.
            // This is done by
            // using the header values returned in
            // structInf.data.contentTypeCode and
            // structInf.data.contentDispCode and
            // structInf.data.contentTEncCode and by
            // taking the body contents returned in
            // ciphertext.
            ..

          } else {

            // Plugin error!
            myErrorDialog( "Error: Cryptography plugin returned a main"
                          "Content-Type=Multipart/.. but did not "
                          "specify the code bloc's Content-Type header."
                          "\nYou may report this bug:"
                          "\n" + cryptplug.bugURL() );
          }
        }
      } else  {

        // Build a plain message body
        // based on the values returned in structInf.
        // Note: We do _not_ insert line breaks between the parts since
        //       it is the plugin job to provide us with ready-to-use
        //       texts containing all necessary line breaks.
        strcpy( myMessageBody, structInf.data.plainTextPrefix );
        if( structInf.data.includeCleartext ) {
          strcat( myMessageBody, cleartext );
          strcat( myMessageBody, structInf.data.plainTextSeparator );
        }
        strcat( myMessageBody, *ciphertext );
        strcat( myMessageBody, structInf.data.plainTextPostfix );
      }

      // free the memory that was allocated
      // for the ciphertext
      free( ciphertext );
    }
See also
signMessage, encryptMessage, encryptAndSignMessage

Definition at line 435 of file cryptplugwrapper.h.


The documentation for this class was generated from the following files: