sipxtacklib  Version 3.3
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
SmimeBody Class Reference

class to contain an PKCS7 (S/MIME) body More...

#include <SmimeBody.h>

Inheritance diagram for SmimeBody:
Inheritance graph
[legend]
Collaboration diagram for SmimeBody:
Collaboration graph
[legend]

Public Types

enum  ContentEncoding {
  SMIME_ENODING_UNKNOWN = 0,
  SMIME_ENODING_BINARY,
  SMIME_ENODING_BASE64
}
 
- Public Types inherited from HttpBody
enum  BodyClassTypes {
  UNKNOWN_BODY_CLASS = 0,
  HTTP_BODY_CLASS,
  SMIME_BODY_CLASS,
  SDP_BODY_CLASS,
  PIDF_BODY_CLASS,
  DIALOG_EVENT_BODY_CLASS
}
 

Public Member Functions

 SmimeBody ()
 default constructor More...
 
 SmimeBody (const char *bytes, int length, const char *contentEncodingValueString)
 Construct an SmimeBody from a bunch of bytes. More...
 
 SmimeBody (const SmimeBody &rSmimeBody)
 Copy constructor. More...
 
virtual ~SmimeBody ()
 Destructor. More...
 
SmimeBodyoperator= (const SmimeBody &rhs)
 Assignment operator. More...
 
UtlBoolean decrypt (const char *derPkcs12, int derPkcs12Length, const char *pkcs12password, const char *certDbPassword, const char *signerCertDER, int signerCertDERLength, ISmimeNotifySink *pSink=NULL)
 Decrypt this body using the given private key and cert. contained in the pkcs12 package. More...
 
UtlBoolean encrypt (HttpBody *bodyToEncrypt, int numRecipients, const char *derPublicKeyCerts[], int derPubliceKeyCertLengths[], const char *szMyCertNickname, const char *szCertDbPassword, ISmimeNotifySink *pSink=NULL)
 Encrypt the given body for the given list of recipients. More...
 
const HttpBodygetDecryptedBody () const
 Gets the decrypted form of this body if available. More...
 
UtlBoolean isDecrypted () const
 Query if this body has been decrypted. More...
 
- Public Member Functions inherited from HttpBody
 HttpBody (const char *bytes=NULL, int length=-1, const char *contentType=NULL)
 
 HttpBody (const char *contentType)
 
 HttpBody (const HttpBody &rHttpBody)
 
virtual ~HttpBody ()
 
HttpBodyoperator= (const HttpBody &rhs)
 
void appendBodyPart (const HttpBody &body, const UtlDList &parameters)
 Append a multipart body part to an existing multiparty body. More...
 
virtual int getLength () const
 
virtual void getBytes (const char **bytes, int *length) const
 
virtual void getBytes (UtlString *bytes, int *length) const
 
virtual const char * getBytes () const
 
UtlBoolean getMultipartBytes (int partIndex, const char **bytes, int *length, int *start) const
 
const MimeBodyPartgetMultipart (int partIndex) const
 
int getMultipartCount () const
 
BodyClassTypes getClassType () const
 
const char * getMultipartBoundary () const
 Get the multipart boundary string. More...
 
const char * getContentType () const
 Get the content type string. More...
 
UtlBoolean isMultipart () const
 

Static Public Member Functions

static UtlBoolean nssSmimeEncrypt (int numRecipientCerts, const char *derPublicKeyCerts[], int derPublicKeyCertLengths[], const char *szMyCertNickname, const char *szCertDbPassword, const char *dataToEncrypt, int dataToEncryptLength, UtlBoolean encryptedDataInBase64Format, UtlString &encryptedData, ISmimeNotifySink *pSmimeSink)
 
static UtlBoolean nssSmimeDecrypt (const char *derPkcs12, int derPkcs12Length, const char *pkcs12Password, const char *certDbPassword, const char *signerCertDER, int signerCertDERLength, UtlBoolean dataIsInBase64Format, const char *dataToDecrypt, int dataToDecryptLength, UtlString &decryptedData, ISmimeNotifySink *pSmimeSink)
 
static UtlBoolean opensslSmimeEncrypt (int numRecipientCerts, const char *derPublicKeyCerts[], int derPublicKeyCertLengths[], const char *dataToEncrypt, int dataToEncryptLength, UtlBoolean encryptedDataInBase64Format, UtlString &encryptedData)
 
static UtlBoolean opensslSmimeDecrypt (const char *derPkcs12, int derPkcs12Length, const char *pkcs12Password, UtlBoolean dataIsInBase64Format, const char *dataToDecrypt, int dataToDecryptLength, UtlString &decryptedData)
 
static UtlBoolean convertPemToDer (UtlString &pemData, UtlString &derData)
 Utility to convert PEM format data to DER format. More...
 
static bool importPKCS12Object (const char *derPkcs12, int derPkcs12Length, const char *pkcs12Password, const char *certDbLocation, const char *certDbPassword)
 
- Static Public Member Functions inherited from HttpBody
static HttpBodycopyBody (const HttpBody &sourceBody)
 Copy the source HttpBody using the correct derived class constructor. More...
 
static HttpBodycreateBody (const char *bodyBytes, int bodyBytesLength, const char *contentType, const char *contentEncoding)
 Pseudo body factory. More...
 

Protected Attributes

HttpBodympDecryptedBody
 
enum ContentEncoding mContentEncoding
 
- Protected Attributes inherited from HttpBody
int bodyLength
 
UtlString mBody
 
UtlString mMultipartBoundary
 
int mBodyPartCount
 
MimeBodyPartmpBodyParts [MAX_HTTP_BODY_PARTS]
 
BodyClassTypes mClassType
 

Detailed Description

class to contain an PKCS7 (S/MIME) body

This class can be used to create an encrypted S/MIME body as well as to decrypt an encrypted body.

Member Enumeration Documentation

Enumerator
SMIME_ENODING_UNKNOWN 
SMIME_ENODING_BINARY 
SMIME_ENODING_BASE64 

Constructor & Destructor Documentation

SmimeBody ( )

default constructor

SmimeBody ( const char *  bytes,
int  length,
const char *  contentEncodingValueString 
)

Construct an SmimeBody from a bunch of bytes.

SmimeBody ( const SmimeBody rSmimeBody)

Copy constructor.

~SmimeBody ( )
virtual

Destructor.

Member Function Documentation

SmimeBody & operator= ( const SmimeBody rhs)

Assignment operator.

UtlBoolean decrypt ( const char *  derPkcs12,
int  derPkcs12Length,
const char *  pkcs12password,
const char *  certDbPassword,
const char *  signerCertDER,
int  signerCertDERLength,
ISmimeNotifySink pSink = NULL 
)

Decrypt this body using the given private key and cert. contained in the pkcs12 package.

Decrypts this body using the derPkcs12PrivateKey.

Parameters
derPkcs12- DER format pkcs12 container for the private key and public key/Certificate for a recipent who is allowed to decrypt this pkcs7 (S/MIME) encapsulated body.
derPkcs12Length- length in bytes of derPkcs12PrivateKey
pkcs12Password- symetric key (password) used to protect (encrypt) the derPkcs12PrivateKey (the private key is contained in a pkcs12 in an encrypted format to protect it from theft). Must be NULL terminated string.
UtlBoolean encrypt ( HttpBody bodyToEncrypt,
int  numRecipients,
const char *  derPublicKeyCerts[],
int  derPubliceKeyCertLengths[],
const char *  szMyCertNickname,
const char *  szCertDbPassword,
ISmimeNotifySink pSink = NULL 
)

Encrypt the given body for the given list of recipients.

Parameters
bodyToEncrypt- Body to encrypt, note bodyToEncrypt will be attached to and deleted with this SmimeBody. bodyToEncrypt can be retrieved after invoking decrypt using the getDecyptedBody method.
numRecipients- number of recipients for which bodyToEncrypt will be encrypted. For each recipient an element in derPublicKeyCerts and derPubliceKeyCertLengths must be given.
derPublicKeyCerts- array containing a DER format certificate (containing the public key) for each recipient.
derPubliceKeyCertLengths- length in bytes of the corresponding element in derPublicKeyCerts.
UtlBoolean nssSmimeEncrypt ( int  numRecipientCerts,
const char *  derPublicKeyCerts[],
int  derPublicKeyCertLengths[],
const char *  szMyCertNickname,
const char *  szCertDbPassword,
const char *  dataToEncrypt,
int  dataToEncryptLength,
UtlBoolean  encryptedDataInBase64Format,
UtlString &  encryptedData,
ISmimeNotifySink pSmimeSink 
)
static

Encrypts the given data for the recipients represented by the array of certificates containing the public keys.

Parameters
numRecipientCertsthe number of recipient certificates in the derPublicKeyCerts array.
derPublicKeyCerts- array containing DER format certificates.
derPublicKeyCertLengths- array containing the length of the corresponding certificate DER data.
dataToEncrypt- raw data to encrypt using PKCS7 S/MIME format
dataToEncryptLengthlength in bytes of dataToEncrypt
encryptedDataInBase64Format- TRUE: output encrypted data in base64 format, FALSE: output data in raw binary format. Typically for SIP one should send in binary format.
encryptedData- string containing the encrypted result.
UtlBoolean nssSmimeDecrypt ( const char *  derPkcs12,
int  derPkcs12Length,
const char *  pkcs12Password,
const char *  certDbPassword,
const char *  signerCertDER,
int  signerCertDERLength,
UtlBoolean  dataIsInBase64Format,
const char *  dataToDecrypt,
int  dataToDecryptLength,
UtlString &  decryptedData,
ISmimeNotifySink pSmimeSink 
)
static

Decrypts this body using the derPkcs12PrivateKey.

Parameters
derPkcs12- DER format pkcs12 container for the private key and public key/Certificate for a recipent who is allowed to decrypt this pkcs7 (S/MIME) encapsulated body.
derPkcs12Length- length in bytes of derPkcs12PrivateKey
pkcs12Password- symetric key (password) used to protect (encrypt) the derPkcs12PrivateKey (the private key is contained in a pkcs12 in an encrypted format to protect it from theft). Must be NULL terminated string.
dataIsInBase64Format- TRUE: encrypted data is in base64 format, FALSE: encrypted data is in binary format.
dataToDecrypt- raw data to be decrypted. Must be in binary or base64 format. Does NOT need to be NULL terminated.
dataToDecryptLength- length of the data in dataToDecrypt to be decrypted.
decryptedData- string to contain the resulting decrypted data.
static UtlBoolean opensslSmimeEncrypt ( int  numRecipientCerts,
const char *  derPublicKeyCerts[],
int  derPublicKeyCertLengths[],
const char *  dataToEncrypt,
int  dataToEncryptLength,
UtlBoolean  encryptedDataInBase64Format,
UtlString &  encryptedData 
)
static

Encrypts the given data for the recipients represented by the array of certificates containing the public keys.

Parameters
numRecipientCertsthe number of recipient certificates in the derPublicKeyCerts array.
derPublicKeyCerts- array containing DER format certificates.
derPublicKeyCertLengths- array containing the length of the corresponding certificate DER data.
dataToEncrypt- raw data to encrypt using PKCS7 S/MIME format
dataToEncryptLengthlength in bytes of dataToEncrypt
encryptedDataInBase64Format- TRUE: output encrypted data in base64 format, FALSE: output data in raw binary format. Typically for SIP one should send in binary format.
encryptedData- string containing the encrypted result.
UtlBoolean opensslSmimeDecrypt ( const char *  derPkcs12,
int  derPkcs12Length,
const char *  pkcs12Password,
UtlBoolean  dataIsInBase64Format,
const char *  dataToDecrypt,
int  dataToDecryptLength,
UtlString &  decryptedData 
)
static

Decrypts this body using the derPkcs12PrivateKey.

Parameters
derPkcs12- DER format pkcs12 container for the private key and public key/Certificate for a recipent who is allowed to decrypt this pkcs7 (S/MIME) encapsulated body.
derPkcs12Length- length in bytes of derPkcs12PrivateKey
pkcs12Password- symetric key (password) used to protect (encrypt) the derPkcs12PrivateKey (the private key is contained in a pkcs12 in an encrypted format to protect it from theft). Must be NULL terminated string.
dataIsInBase64Format- TRUE: encrypted data is in base64 format, FALSE: encrypted data is in binary format.
dataToDecrypt- raw data to be decrypted. Must be in binary or base64 format. Does NOT need to be NULL terminated.
dataToDecryptLength- length of the data in dataToDecrypt to be decrypted.
decryptedData- string to contain the resulting decrypted data.
UtlBoolean convertPemToDer ( UtlString &  pemData,
UtlString &  derData 
)
static

Utility to convert PEM format data to DER format.

bool importPKCS12Object ( const char *  derPkcs12,
int  derPkcs12Length,
const char *  pkcs12Password,
const char *  certDbLocation,
const char *  certDbPassword 
)
static
const HttpBody * getDecryptedBody ( ) const

Gets the decrypted form of this body if available.

UtlBoolean isDecrypted ( ) const

Query if this body has been decrypted.

Member Data Documentation

HttpBody* mpDecryptedBody
protected
enum ContentEncoding mContentEncoding
protected

sipXtackLib home page