public class PKCS10Content
extends java.lang.Object
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 Jakarta Mail architecture, and how to handling MIME messages, consult the Jakarta Mail Specification/<.
For using the IAIK-CMS S/MIME library, you also will need the following packages:
iaik_jce(_full).jar
(IAIK-JCE Core Crypto Library).
iaik_eccelerate.jar
(IAIK ECC Library; if you want to use Elliptic Curve Cryptography).
# # 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_contentThe content handlers are registered by copying the mailcap file into the lib directory of your JDK (<JDK-HOME>/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 and Description |
---|
PKCS10Content()
Creates a new PKCS10Content object.
|
PKCS10Content(jakarta.activation.DataSource dataSource)
Constructs a PKCS10Content object from the given data source.
|
Modifier and Type | Method and Description |
---|---|
iaik.pkcs.pkcs10.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(iaik.pkcs.pkcs10.CertificateRequest request)
Sets the PKCS#10 request for this PKCS10Content.
|
void |
setHeaders(jakarta.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.
|
public PKCS10Content()
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);
public PKCS10Content(jakarta.activation.DataSource dataSource) throws java.io.IOException
pkcs10_content
supplying the data
source.
For more information on data handling using the
jakarta.activation.DataSource
for "MIME type based" data
access, see the
JavaBeans Activation Framework (JAF) sepecification.
dataSource
- the DataSource supplying the requestjava.io.IOException
- if an I/O error occurs during reading the objectpublic java.lang.String getContentType()
MimeMessage msg = ...; PKCS10Content pkcs10 = new PKCS10Content(); ... msg.setContent(pkcs10, pkcs10.getContentType()); ...
public void setCertRequest(iaik.pkcs.pkcs10.CertificateRequest request)
request
- the PKCS#10 certificate request to be sentpublic iaik.pkcs.pkcs10.CertificateRequest getCertRequest()
public void setHeaders(jakarta.mail.Part part)
Content-Disposition: attachment"; filename="smime.p10" Content-Transfer-Encoding: base64
part
- the Part to which to add the headerspublic void writeTo(java.io.OutputStream os) throws java.io.IOException, jakarta.mail.MessagingException
os
- the output streamjava.io.IOException
- if an error occurs writing to the streamjakarta.mail.MessagingException
- if an error occurs when fetching the data to be written