|
From: <kc...@us...> - 2003-07-17 08:08:17
|
Update of /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/packaging
In directory sc8-pr-cvs1:/tmp/cvs-serv19796/src/hk/hku/cecid/phoenix/message/packaging
Modified Files:
Tag: b0931
EbxmlMessage.java
Log Message:
modified s/mime encryption/decryption calling mechanism to suit ebmail usage
Index: EbxmlMessage.java
===================================================================
RCS file: /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/packaging/EbxmlMessage.java,v
retrieving revision 1.24.2.4
retrieving revision 1.24.2.5
diff -C2 -d -r1.24.2.4 -r1.24.2.5
*** EbxmlMessage.java 6 May 2003 06:16:52 -0000 1.24.2.4
--- EbxmlMessage.java 17 Jul 2003 08:08:13 -0000 1.24.2.5
***************
*** 72,80 ****
--- 72,88 ----
import hk.hku.cecid.phoenix.message.packaging.validation.SOAPValidationException;
import hk.hku.cecid.phoenix.message.packaging.validation.EbxmlValidationException;
+ import hk.hku.cecid.phoenix.message.transport.Mail;
import hk.hku.cecid.phoenix.pki.CertResolver;
+ import hk.hku.cecid.phoenix.pki.CompositeKeyStore;
+ import hk.hku.cecid.phoenix.pki.SMIMEException;
+ import hk.hku.cecid.phoenix.pki.SMIMEEncrypter;
import java.io.*;
+ import java.security.cert.Certificate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.HashMap;
+ import java.util.Properties;
+ import javax.mail.*;
+ import javax.mail.internet.*;
import javax.xml.soap.*;
import javax.activation.DataHandler;
***************
*** 157,160 ****
--- 165,173 ----
private String filename;
+ private boolean encryption;
+
+ private Certificate encryptionCert;
+
+
/** Constructs an <code>EbxmlMessage</code> using the default JAXM
<code>MessageFactory</code> implementation
***************
*** 899,902 ****
--- 912,956 ----
/**
+ * Encrypts this ebxml message using s/mime. The actual encryption would
+ * be done when writeTo() is called
+ * @param alias
+ * @param password
+ * @param keyStoreLocation
+ */
+ public void SMIMEEncrypt(String alias, char[] password,
+ String keyStoreLocation)
+ throws SMIMEException {
+ CompositeKeyStore compositeKs = new CompositeKeyStore();
+ compositeKs.addKeyStoreFile(keyStoreLocation , null, password);
+ try {
+ encryptionCert = compositeKs.getCertificate(alias);
+ encryption = true;
+ }
+ catch (Exception e) {
+ throw new SMIMEException("Cannot resolve encryption certificate");
+ }
+ }
+
+ /**
+ * Encrypts this ebxml message using s/mime. The actual encryption would
+ * be done when writeTo() is called
+ * @param c
+ */
+ public void SMIMEEncrypt(CertResolver c) throws SMIMEException {
+ Certificate[] certs = c.resolve(this);
+ if (certs != null && certs.length > 0) {
+ encryptionCert = certs[0];
+ encryption = true;
+ }
+ else {
+ throw new SMIMEException("Cannot resolve encryption certificate");
+ }
+ }
+
+ public boolean isSMIMEEncrypted() {
+ return encryption;
+ }
+
+ /**
* Add an ebXML message payload container.
*
***************
*** 1013,1017 ****
public void writeTo(OutputStream out)
throws IOException, SOAPException {
! soapMessage.writeTo(out);
}
--- 1067,1112 ----
public void writeTo(OutputStream out)
throws IOException, SOAPException {
! if (!encryption || encryptionCert == null) {
! soapMessage.writeTo(out);
! }
! else {
! try {
! final boolean hasAttachments =
! soapMessage.getAttachments().hasNext();
! final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
! soapMessage.writeTo(bytes);
! final String[] contentType = soapMessage.getMimeHeaders().
! getHeader(Constants.CONTENT_TYPE);
! String type = contentType[0];
! final AttachmentDataSource content =
! new AttachmentDataSource(bytes.toByteArray(), type);
! final Session session = Session.getInstance(new Properties());
! MimeMessage mimeMessage = new MimeMessage(session);
! MimeMultipart multipart = null;
! if (hasAttachments) {
! multipart = new MimeMultipart(content);
! }
! else {
! mimeMessage.setDataHandler(new DataHandler(content));
! mimeMessage.setHeader(Constants.CONTENT_TRANSFER_ENCODING,
! Mail.MAIL_TRANSFER_ENCODING);
! }
!
! if (multipart != null) {
! mimeMessage.setContent(multipart);
! }
!
! mimeMessage.saveChanges();
!
! mimeMessage = SMIMEEncrypter.getInstance().
! createEncryptedMimeMessage(encryptionCert, mimeMessage,
! session);
!
! mimeMessage.writeTo(out);
! }
! catch (Exception e) {
! throw new SOAPException(e.getMessage());
! }
! }
}
|