iaik.smime
Class PKCS10Content

java.lang.Object
  extended by iaik.smime.PKCS10Content

public class PKCS10Content
extends java.lang.Object

This class can be used to create S/MIME application/pkcs10 emails in combination with the javax.mail package.

S/MIMEv2 (Secure/Multipurpose Internet Mail Extensions) specifies the application/pkcs10 type for providing a format for sending a PKCS#10 certification request to a certification authority.

When using this class for creating a application/pkcs10 message, first use the class iaik.pkcs.pkcs10.CertificateRequest of IAIK-JCE for creating the request, and subsequently incorporate it into the PKCS#10 message by means of the setCertRequest method, e.g.:

 // create or load a PKCS#10 request:
 CertificateRequest request = ...;
 // create a new PKCS10Content:
 PKCS10Content pkcs10 = new PKCS10Content();
 // set the request:
 pkcs10.setCertRequest(request);
 // prepare for sending and send:
 MimeMessage msg = new MimeMessage(session);
  ...
 // set the content
 msg.setContent(pkcs10, pkcs10.getContentType());
 // let the PKCS10Content update some message headers
 pkcs10.setHeaders(msg);
 Transport.send(msg);
 

For more information about the JavaMail architecture, and how to handling MIME messages, consult the JavaMail specification.

For using the IAIK-CMS S/MIME library, you also will need the following packages:

The JAF assignment between MIME-types and content handlers is done by means of a RFC 1524 mailcap file which is included in the IAIK-CMS distribution. It defines the following classes as content handlers for the corresponding MIME types:
 #
 # IAIK 'mailcap' file entries
 #
 multipart/signed;;               x-java-content-handler=iaik.smime.signed_content
 application/x-pkcs7-signature;;  x-java-content-handler=iaik.smime.signed_content
 application/x-pkcs7-mime;;       x-java-content-handler=iaik.smime.encrypted_content
 application/x-pkcs10;;           x-java-content-handler=iaik.smime.pkcs10_content
 application/pkcs7-signature;;    x-java-content-handler=iaik.smime.signed_content
 application/pkcs7-mime;;         x-java-content-handler=iaik.smime.encrypted_content
 application/pkcs10;;             x-java-content-handler=iaik.smime.pkcs10_content
 
The content handlers are registered by copying the mailcap file into the lib directory of your JDK (/lib). Alternatively you may register the IAIK-S/MIME mailcap file dynamically by using the default command map:
 String mailcapFileName = ...;
 MailcapCommandMap mc = new MailcapCommandMap(mailcapFileName);
 CommandMap.setDefaultCommandMap(mc);
 
Or you may add the IAIK mailcap entries to the default mailcap command map, e.g.:
 MailcapCommandMap mc = (MailcapCommandMap)CommandMap.getDefaultCommandMap();
 mc.addMailcap("multipart/signed;; x-java-content-handler=iaik.smime.signed_content");
 mc.addMailcap("application/x-pkcs7-signature;; x-java-content-handler=iaik.smime.signed_content");
 mc.addMailcap("application/x-pkcs7-mime;; x-java-content-handler=iaik.smime.encrypted_content");
 mc.addMailcap("application/pkcs7-signature;; x-java-content-handler=iaik.smime.signed_content");
 mc.addMailcap("application/pkcs7-mime;; x-java-content-handler=iaik.smime.encrypted_content");
 mc.addMailcap("application/x-pkcs10;; x-java-content-handler=iaik.smime.pkcs10_content");
 mc.addMailcap("application/pkcs10;; x-java-content-handler=iaik.smime.pkcs10_content");
 CommandMap.setDefaultCommandMap(mc);
 
For a more detailed description of mailcap handling consult the Javadoc of the Activation Framework.

When creating a new PKCS10Content to be sent per default the new S/MIME content type application/pkcs10 is used. For using the old type (application/x-pkcs10) call the static useNewContentTypes method of the SMimeParameters class before creating a new PKCS10Content object, e.g.:

 //switch to old content types
 SMimeParameters.useNewContentTypes(false);
 //create a PKCS10Content
 PKCS10Content pkcs10 = new PKCS10Content();
 ...
 


Constructor Summary
PKCS10Content()
          Creates a new PKCS10Content object.
PKCS10Content(javax.activation.DataSource dataSource)
          Constructs a PKCS10Content object from the given data source.
 
Method Summary
 CertificateRequest getCertRequest()
          Returns the PKCS#10 request sent with this message.
 java.lang.String getContentType()
          Returns the ContentType and any attached parameters of this PKCS10 content.
 void setCertRequest(CertificateRequest request)
          Sets the PKCS#10 request for this PKCS10Content.
 void setHeaders(javax.mail.Part part)
          Sets additional headers of the message containing this PKCS10Content.
 void writeTo(java.io.OutputStream os)
          Writes this PKCS10Content DER encoded to the given output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PKCS10Content

public PKCS10Content()
Creates a new PKCS10Content object.

Use the setCertRequest method for specifying a certificate request, e.g.:

 // create or load a PKCS#10 request:
 CertificateRequest request = ...;
 // create a new PKCS10Content:
 PKCS10Content pkcs10 = new PKCS10Content();
 // set the request:
 pkcs10.setCertRequest(request);
 // prepare for sending and send:
 MimeMessage msg = new MimeMessage(session);
  ...
 // set the content
 msg.setContent(pkcs10, pkcs10.getContentType());
 // let the PKCS10Content update some message headers
 pkcs10.setHeaders(msg);
 Transport.send(msg);
 


PKCS10Content

public PKCS10Content(javax.activation.DataSource dataSource)
              throws java.io.IOException
Constructs a PKCS10Content object from the given data source. The given data source is expected to supply an DER encoded PKCS#10 certificate request. During a mail session this constructor usually will not be called directly. Rather it is called by a proper data content handler pkcs10_content supplying the data source.

For more information on data handling using the javax.activation.DataSource for "MIME type based" data access, see the JavaBeans Activation Framework (JAF) sepecification.

Parameters:
dataSource - the DataSource supplying the request
Throws:
java.io.IOException - if an I/O error occurs during reading the object
Method Detail

getContentType

public java.lang.String getContentType()
Returns the ContentType and any attached parameters of this PKCS10 content. This method shall be used when setting an PKCS10Content object as the content of a Message:
 MimeMessage msg = ...;
 PKCS10Content pkcs10 = new PKCS10Content();
 ...
 msg.setContent(pkcs10, pkcs10.getContentType());
 ...
 

Returns:
the content type of this PKCS10 content

setCertRequest

public void setCertRequest(CertificateRequest request)
Sets the PKCS#10 request for this PKCS10Content.

Parameters:
request - the PKCS#10 certificate request to be sent

getCertRequest

public CertificateRequest getCertRequest()
Returns the PKCS#10 request sent with this message.

Returns:
request the PKCS#10 certificate request

setHeaders

public void setHeaders(javax.mail.Part part)
Sets additional headers of the message containing this PKCS10Content. Till now I found no way how to set the required header for the message which contains this PKCS10Content. This method adds one header with one parameter to the specified message:
 Content-Disposition: attachment";
     filename="smime.p10"
 Content-Transfer-Encoding: base64
 

Parameters:
part - the Part to which to add the headers

writeTo

public void writeTo(java.io.OutputStream os)
             throws java.io.IOException,
                    javax.mail.MessagingException
Writes this PKCS10Content DER encoded to the given output stream.

Throws:
java.io.IOException - if an error occurs writing to the stream
javax.mail.MessagingException - if an error occurs when fetching the data to be written

This Javadoc may contain text parts from text parts from IETF Internet Standard specifications (see copyright note).

IAIK-CMS 6.0, (c) 2002 IAIK, (c) 2003, 2023 SIC