org.webdocwf.util.smime.activation
Class CMSSignedDataSource

java.lang.Object
  |
  +--org.webdocwf.util.smime.activation.CMSSignedDataSource
All Implemented Interfaces:
javax.activation.DataSource

public class CMSSignedDataSource
extends java.lang.Object
implements javax.activation.DataSource

CMSSignedDataSource represents implementation of DataSource interfaces. It is used within MimeMessage as a source of data. Also, object of this class is used to create DER encoded Cryptographic Message Syntax (CMS) object represented in ASN.1 notation according to RFC2630. This object (CMS) is used as the source of data for MimeMessage in the process of sending signed message.


Constructor Summary
CMSSignedDataSource(byte[] message0, boolean externalSignature0)
          Constructs CMS object for signing with Mime Message in form of byte array and with given value for type of CMSSignedDataSource (type of signing).
CMSSignedDataSource(javax.mail.internet.MimeMessage message0, boolean externalSignature0)
          Constructs CMS object for signing with Mime Message in form of instance of MimeMessage class and with given value for type of CMSSignedDataSource (type of signing).
 
Method Summary
 void addCertificate(java.security.cert.X509Certificate cert0)
          Adds the Certificate
 void addSigner(java.security.KeyStore pfx0, boolean includingCert0, boolean includingSignAttrib0, java.lang.String signingAlg0)
          Adds Signer.
 void addSigner(java.security.cert.X509Certificate[] chain0, java.security.PrivateKey privKey0, boolean includingCert0, boolean includingSignAttrib0, java.lang.String signingAlg0)
          Adds Signer.
 byte[] getBASE64CMSSignedObject()
          Returns complete DER encoded CMS Signed Object with BASE64 encoding
 byte[] getCMSSignedObject()
          Returns complete DER encoded CMS Signed Object
 java.lang.String getContentType()
          Implements getContentType method from DataSource interface
 java.io.InputStream getInputStream()
          Implements getInputStream method from DataSource interface
 java.lang.String getName()
          Implements getName method from DataSource interface
 java.io.OutputStream getOutputStream()
          Implements getOutputStream method from DataSource interface.
 void setCapabilities(java.lang.String type0, int par10, int par20, int par30, int par40, int par50)
          Sets Capabilities Attributes (method is optional, but if exists, must be performed before addSigner method).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CMSSignedDataSource

public CMSSignedDataSource(byte[] message0,
                           boolean externalSignature0)
                    throws SMIMEException
Constructs CMS object for signing with Mime Message in form of byte array and with given value for type of CMSSignedDataSource (type of signing). Type can be external or internal signing.
Parameters:
message0 - message for encryption
externalSignature0 - true = external signing, false = internal signing
Throws:
SMIMEException - in case of failure in MimeMessageConvertor class which performes transformation from MimeMessage object to byte array. Also, it can be caused by problems in construction or work with some inner objects instantiated from classes that belong to org.webdocwf.util.smime.der or org.webdocwf.util.smime.cms packages used in other CMSEnvelopedObject constructor.

CMSSignedDataSource

public CMSSignedDataSource(javax.mail.internet.MimeMessage message0,
                           boolean externalSignature0)
                    throws SMIMEException
Constructs CMS object for signing with Mime Message in form of instance of MimeMessage class and with given value for type of CMSSignedDataSource (type of signing). Type can be external or internal signing.
Parameters:
message0 - message for encryption
externalSignature0 - true = external signing, false = internal signing
Throws:
SMIMEException - caused by problems in construction or work with some inner objects instantiated from classes that belong to org.webdocwf.util.smime.der or org.webdocwf.util.smime.cms packages used in other CMSEnvelopedObject constructor.
Method Detail

setCapabilities

public void setCapabilities(java.lang.String type0,
                            int par10,
                            int par20,
                            int par30,
                            int par40,
                            int par50)
                     throws SMIMEException
Sets Capabilities Attributes (method is optional, but if exists, must be performed before addSigner method). Depending on parameter type0, other five parameters make order in specific group of algorithms. Groups of algorithms with positions of specific algorithms are:
(SIGNATURE, MD2 with RSA, MD5 with RSA, SHA1 with RSA, SHA1 with DSA, Unused field)
(SYMMETRIC, RC2 40 bits, RC2 64 bits, RC2 128 bits, DES, DES_EDE3)
(ENCIPHER, RSA, Unused field, Unused field, Unused field, Unused field)

For example, if we wish to set Capabilities Attributes for symmetric algorithms in order: RC2 64 bits, RC2 40 bits and DES, encipher algorithm RSA (only possible in this version), and signature algorithms in order: SHA1 with RSA, MD5 with RSA and MD2 with RSA, we should make following lines of code

setCapabilities ("SYMMETRIC", 2, 1, 0, 3, 0)
setCapabilities ("ENCIPHER", 1, 0, 0, 0, 0)
setCapabilities ("SIGNATURE", 3, 2, 1, 0, 0)

0 means exclusion of algorithm from the specified position in the method. It is free to decide which algorithm will be included, or which group of algorithm will be included in Capabilities Attributes. If no groups are added, capabilities attributes won't be added to Signed Attributes. If two or more signers will sign the message, and their capabilities are different, this method should be performed before every signing if we wish to specify Capabilities Attributes for all particular signers. If type0 parameter is set as:
setCapabilities ("DEFAULT", 0, 0, 0, 0, 0)
it is equivalent to:
setCapabilities ("SYMMETRIC", 1, 0, 0, 0, 0)
setCapabilities ("ENCIPHER", 0, 0, 1, 0, 0)
setCapabilities ("SIGNATURE", 1, 0, 0, 0, 0)
Parameters:
type0 - sets group of algorithms for capabilities attributes. It can be set with values: SIGNATURE, SYMMETRIC, ENCIPHER or DEFAULT.
par10 - sets order in group of parameters, or exclude some algorithms from capabilities atributes. Can take values 1, 2, 3, 4 or 5 and 0 for exclusion of the particular algorithm.
par20 - same as for par10
par30 - same as for par10
par40 - same as for par10
par50 - same as for par10
Throws:
SMIMEException - if method is performed more than three times for one signer, or in case of wrong values of parameters.

addSigner

public void addSigner(java.security.KeyStore pfx0,
                      boolean includingCert0,
                      boolean includingSignAttrib0,
                      java.lang.String signingAlg0)
               throws SMIMEException
Adds Signer. This method must be performed at least once.
Parameters:
pfx0 - contains information from signer's .pfx or .p12 file
includingCert0 - true = automatically including all certificates from pfx0 false = no certificate will be added
includingSignAttrib0 - true = signed attributes will be included, false = signed attributes will not be included
signingAlg0 - used for signing (can be SHA1_WITH_RSA, MD2_WITH_RSA, MD5_WITH_RSA or SHA1_WITH_DSA)
Throws:
SMIMEException - in case of wrong type of digest algorithm, or in case of problems with manipulation with .pfx or .p12 file in PFXUtils class. Also, it can be caused by problems in construction or work with some inner objects from org.webdocwf.util.smime.der or org.webdocwf.util.smime.cms package.

addSigner

public void addSigner(java.security.cert.X509Certificate[] chain0,
                      java.security.PrivateKey privKey0,
                      boolean includingCert0,
                      boolean includingSignAttrib0,
                      java.lang.String signingAlg0)
               throws SMIMEException
Adds Signer. This method must be performed at least once.
Parameters:
chain0 - signer's certificates chain. First certificate in chain must be owner's.
privKey0 - signer's private key (DSA or RSA depend on type of signing)
includingCert0 - true = automatically including all certificates from pfx0 false = no certificate will be added
includingSignAttrib0 - true = signed attributes will be included, false = signed attributes will not be included
signingAlg0 - used for signing (can be SHA1_WITH_RSA, MD2_WITH_RSA, MD5_WITH_RSA or SHA1_WITH_DSA)
Throws:
SMIMEException - in case of wrong type of digest algorithm. Also, it can be caused by problems in construction or work with some inner objects from org.webdocwf.util.smime.der or org.webdocwf.util.smime.cms package.

addCertificate

public void addCertificate(java.security.cert.X509Certificate cert0)
                    throws SMIMEException
Adds the Certificate
Parameters:
cert0 - X509 certificate
Throws:
SMIMEException - thrown in inner object which is instance of the class org.webdocwf.util.smime.cms.Certificates.

getCMSSignedObject

public byte[] getCMSSignedObject()
                          throws SMIMEException
Returns complete DER encoded CMS Signed Object
Returns:
DER encoded CMS Signed Object represented as byte array
Throws:
SMIMEException - caused by problems in construction or dealing with some inner objects instantiated from classes that belong to org.webdocwf.util.smime.der or org.webdocwf.util.smime.cms packages.

getBASE64CMSSignedObject

public byte[] getBASE64CMSSignedObject()
                                throws SMIMEException
Returns complete DER encoded CMS Signed Object with BASE64 encoding
Returns:
DER encoded CMS Signed Object represented as byte array with performed BASE64 encoding.
Throws:
SMIMEException - in case of failure in Base64 encoding performed on the generated SMIME message byte array by method ofMimeAssist class. Also, it can be caused by problems in construction or work with some inner objects instantiated from classes that belong to org.webdocwf.util.smime.der or org.webdocwf.util.smime.cms packages used in getCMSSignedDataSource() method.

getContentType

public java.lang.String getContentType()
Implements getContentType method from DataSource interface
Specified by:
getContentType in interface javax.activation.DataSource
Returns:
Content-Type for MIME message header field

getInputStream

public java.io.InputStream getInputStream()
                                   throws SMIMEIOException
Implements getInputStream method from DataSource interface
Specified by:
getInputStream in interface javax.activation.DataSource
Returns:
CMS signed object
Throws:
SMIMEIOException - thrown as result of SMIMEException

getName

public java.lang.String getName()
Implements getName method from DataSource interface
Specified by:
getName in interface javax.activation.DataSource
Returns:
Name: SignedDataContentInfo

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Implements getOutputStream method from DataSource interface. This method is not in use.
Specified by:
getOutputStream in interface javax.activation.DataSource
Returns:
nothing
Throws:
java.io.IOException - is always thrown when this method is used.


Copyright © 2002-2002 Together Teamlösungen. All Rights Reserved.