git-svn-id: http://locode01.ad.dom/svn/WEBMIP/trunk@50874 248e525c-4dfb-0310-94bc-949c084e9493

This commit is contained in:
andrew.gilmore
2012-03-19 11:57:19 +00:00
parent 2a0f4900c3
commit 0e9ca75d77
1587 changed files with 500863 additions and 0 deletions

View File

@@ -0,0 +1,119 @@
<?xml version = '1.0' encoding = 'UTF-8'?>
<jpr:project xmlns:jpr="http://xmlns.oracle.com/ide/project">
<hash n="component-versions">
<value n="oracle.adfdt.controller.jsf.addin.JSFProjectMigrator" v="10.1.3.5.0"/>
<value n="oracle.adfdt.controller.struts.addin.StrutsProjectMigrator" v="10.1.3.5.0"/>
<value n="oracle.bm.commonIde.ProjectUpgrader" v="10.1.3.5.0"/>
<value n="oracle.ide.model.Project" v="10.1.3.5.0"/>
<value n="oracle.ide.model.ResourcePathsMigrator" v="10.1.3.5.0"/>
<value n="oracle.jdeveloper.dbmodeler.migration.ProjectMigratorHelper" v="10.1.3.5.0"/>
<value n="oracle.jdeveloper.ejb.EjbMigrator" v="10.1.3.5.0"/>
<value n="oracle.jdeveloper.offlinedb.migration.OfflineDBProjectMigrator" v="10.1.3.5.0"/>
<value n="oracle.jdevimpl.jsp.JsfLibraryMigrator" v="10.1.3.5.0"/>
<value n="oracle.jdevimpl.jsp.JspMigrator" v="10.1.3.1.0"/>
<value n="oracle.jdevimpl.runner.RunConfigurationsMigrator" v="10.1.3.5.0"/>
<value n="oracle.jdevimpl.webservices.WebServicesMigratorHelper" v="10.1.3.5.0"/>
<value n="oracle.toplink.addin.migration.TopLinkProjectMigrator" v="10.1.3.1.0"/>
</hash>
<list n="contentSets">
<string v="oracle.jdeveloper.model.PathsConfiguration/javaContentSet"/>
<string v="oracle.ide.model.ResourcePaths/resourcesContentSet"/>
<string v="oracle.jdeveloper.offlinedb.model.OfflineDBProjectSettings/offlineDBContentSet"/>
<string v="oracle.jdeveloper.model.J2eeSettings/webContentSet"/>
<string v="oracle.toplink.addin.TopLinkProjectSettings/toplinkContentSet"/>
<string v="oracle.bm.commonIde.data.project.ModelerProjectSettings/modelersContentSet"/>
</list>
<value n="defaultPackage" v="smime"/>
<hash n="oracle.bm.commonIde.data.project.ModelerProjectSettings">
<hash n="modelersContentSet">
<list n="url-path">
<url path="model/"/>
</list>
</hash>
</hash>
<hash n="oracle.ide.model.ResourcePaths">
<hash n="resourcesContentSet">
<list n="pattern-filters">
<string v="+*"/>
</list>
<list n="url-path">
<url path="."/>
</list>
</hash>
</hash>
<hash n="oracle.jdeveloper.compiler.OjcConfiguration">
<value n="internalEncoding" v="Cp1252"/>
<value n="source" v="1.4"/>
<value n="target" v="1.4"/>
</hash>
<hash n="oracle.jdeveloper.model.J2eeSettings">
<value n="j2eeWebAppName" v="EFT-SMIME-webapp"/>
<value n="j2eeWebContextRoot" v="EFT-SMIME-context-root"/>
<hash n="webContentSet">
<list n="url-path">
<url path="public_html/"/>
</list>
</hash>
</hash>
<hash n="oracle.jdeveloper.model.PathsConfiguration">
<hash n="javaContentSet">
<list n="pattern-filters">
<string v="+**"/>
</list>
<list n="url-path">
<url path="src/"/>
</list>
</hash>
</hash>
<hash n="oracle.jdeveloper.offlinedb.model.OfflineDBProjectSettings">
<hash n="offlineDBContentSet">
<list n="pattern-filters">
<string v="+**"/>
</list>
<list n="url-path">
<url path="database/"/>
</list>
</hash>
</hash>
<hash n="oracle.jdeveloper.runner.RunConfigurations">
<hash n="runConfigurationDefinitions">
<hash n="Default">
<value n="custom" v="false"/>
<value n="name" v="Default"/>
</hash>
</hash>
<list n="runConfigurationList">
<string v="Default"/>
</list>
</hash>
<hash n="oracle.jdevimpl.config.JProjectLibraries">
<list n="exportedReferences">
<hash>
<url n="id" path="../../../../../../oracle/jdev10/jdev/system/oracle.jdeveloper.10.1.3.43.6/SMIME.library"/>
<value n="isJDK" v="false"/>
</hash>
</list>
<hash n="internalDefinitions">
<list n="libraryDefinitions"/>
</hash>
<list n="libraryReferences">
<hash>
<url n="id" path="../../../../../../oracle/jdev10/jdev/system/oracle.jdeveloper.10.1.3.43.6/SMIME.library"/>
<value n="isJDK" v="false"/>
</hash>
</list>
</hash>
<hash n="oracle.jdevimpl.config.JProjectPaths">
<url n="outputDirectory" path="classes/"/>
</hash>
<hash n="oracle.toplink.addin.TopLinkProjectSettings">
<hash n="toplinkContentSet">
<list n="pattern-filters">
<string v="+**"/>
</list>
<list n="url-path">
<url path="toplink/"/>
</list>
</hash>
</hash>
</jpr:project>

Binary file not shown.

View File

@@ -0,0 +1,408 @@
import java.io.FileInputStream;
import java.io.InputStream;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.Security;
import java.security.cert.CertStore;
import java.security.cert.CollectionCertStoreParameters;
import java.security.cert.X509Certificate;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.sql.Connection;
//import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Properties;
import javax.activation.CommandMap;
import javax.activation.DataHandler;
import javax.activation.MailcapCommandMap;
import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.util.ByteArrayDataSource;
import oracle.sql.BLOB;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.cms.AttributeTable;
import org.bouncycastle.asn1.smime.SMIMECapabilitiesAttribute;
import org.bouncycastle.asn1.smime.SMIMECapability;
import org.bouncycastle.asn1.smime.SMIMECapabilityVector;
import org.bouncycastle.mail.smime.SMIMESignedGenerator;
public class am_smime
{
static
{
Security.insertProviderAt(new org.bouncycastle.jce.provider.BouncyCastleProvider(), 2);
}
//
// certificate serial number seed.
//
static int serialNo = 1;
//
// Javamail authenticator instance
//
private static Authenticator authenticator = null;
//
// Database connection global
//
private static Connection conn = null;
//
// Default connection settings
//
private static String username = "eft_nom";
private static String password = "eft_nom";
private static String connection = "jdbc:oracle:thin:@loordv01:1521:dev10g";
//
private static String mslo_id = null;
//
// Main Method
//
public static void main(String[] args) throws Exception
{
am_smime smime_msg = new am_smime();
//
// check for parameters
//
if (args.length >= 1) {
mslo_id = args[0];
username = args[1];
password = args[2];
connection = args[3];
}
//
// call the main routine
//
sendmsg( mslo_id
);
}
public static String Sysdate() {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.Ms");
Date sysdate = new Date();
return dateFormat.format(sysdate);
}
public static void sendmsg( String mslo_id
) throws Exception {
//
// get a JDBC connection
//
try {
conn = getConnection();
System.out.println("am_smime: " + "connection opened" + ": " + Sysdate());
} catch(SQLException ex){
ex.printStackTrace();
}
//
// Initialise defaults - if no details passed, will still send a message in dev
//
String mailFrom = "\"Anthony Gilbert\"<anthony.gilbert@advanticagroup.com>";
String mailTo = "\"Anthony Gilbert\"<anthony.gilbert@advanticagroup.com>";
String mailSubject = "Mail Subject";
String mailBody = "Mail Body";
String fileName = "attachment.txt";
String fileMimeType = "application/vnd.ms-excel";
String filename = "c:\\ant.pfx";
String password = "password";
String smtpServerHost = "lomail01";
int tmpInt = 1;
oracle.sql.BLOB pBlob = BLOB.createTemporary(conn, false, tmpInt);
//
// If a parameter has been passed, override the defaults
//
if (mslo_id != null )
{
//
// Lets see if we can get the details
//
PreparedStatement stmt = conn.prepareStatement
("SELECT mslo_id " +
" ,from_name " +
" ,to_names " +
" ,subject " +
" ,message " +
" ,filename " +
" ,file_mime_type " +
" ,cout_system_configuration.get_configuration_item('G_SMIME_KEYSTORE') keystore " +
" ,cout_system_configuration.get_configuration_item('G_SMIME_PASSWORD') password " +
" ,cout_system_configuration.get_configuration_item('SYSTEM_SMTP_SERVER') mailserver " +
"FROM messaging_log " +
"WHERE mslo_id = ?");
stmt.setString(1, mslo_id);
System.out.println("am_smime: " + "retrieving message" + ": " + Sysdate());
ResultSet rset = stmt.executeQuery();
while (rset.next())
{
//
// Set the default to be as returned from the db
//
mailFrom = rset.getString("from_name");
mailTo = rset.getString("to_names");
mailSubject = rset.getString("subject");
mailBody = rset.getString("message");
fileName = rset.getString("filename");
fileMimeType = rset.getString("file_mime_type");
filename = rset.getString("keystore");
password = rset.getString("password");
smtpServerHost = rset.getString("mailserver");
//
// Now return the blob - have to use a different method
//
Statement stmtb = conn.createStatement();
System.out.println("am_smime: " + "retrieving attachment" + ": " + Sysdate());
ResultSet blobdetails = stmtb.executeQuery("SELECT filecontents " +
"FROM messaging_log " +
"WHERE mslo_id = " + mslo_id +" FOR UPDATE ");
//
if (blobdetails.next() )
{
pBlob = (oracle.sql.BLOB) blobdetails.getBlob(1);
stmtb.close();
}
}
rset.close();
stmt.close();
}
System.out.println("am_smime: " + "setup security" + ": " + Sysdate());
//
// Add handler to mailcap
//
MailcapCommandMap _mailcap = (MailcapCommandMap)CommandMap.getDefaultCommandMap();
//
_mailcap.addMailcap("application/pkcs7-signature;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_signature");
_mailcap.addMailcap("application/pkcs7-mime;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_mime");
_mailcap.addMailcap("application/x-pkcs7-signature;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.x_pkcs7_signature");
_mailcap.addMailcap("application/x-pkcs7-mime;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.x_pkcs7_mime");
_mailcap.addMailcap("multipart/signed;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.multipart_signed");
//
CommandMap.setDefaultCommandMap(_mailcap);
//
// Set mail server details
//
String smtpUsername = "";//gilberta";
String smtpPassword = "";//password";
//
String defaultCharset = "iso-8859-2";
//
// Initialise security and keystore
//
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
KeyStore ks = KeyStore.getInstance("pkcs12", "BC");
System.out.println("am_smime: " + "load keystore and apply password" + ": " + Sysdate());
//
// Load the keystore
//
try {
ks.load( new FileInputStream(filename), password.toCharArray());
}
catch (Exception ex) { System.out.println("Error: Problem loading keystore"); throw ex;}
//
System.out.println("am_smime: " + "loaded, extract certificates" + ": " + Sysdate());
//
// Find the parts we need
//
Enumeration e = ks.aliases();
String keyAlias = null;
String alias = null;
while (e.hasMoreElements()) {
alias = (String) e.nextElement();
if (ks.isKeyEntry(alias)) {
keyAlias = alias;
}
}
if (keyAlias == null) {
System.err.println("can't find a private key!");
System.exit(0);
}
//
PrivateKey smimeSigningKey = (PrivateKey)ks.getKey(alias,password.toCharArray());
java.security.cert.Certificate smimeCertChain[] = ks.getCertificateChain(alias);
//
// Setup the ASN1 stuff
//
ASN1EncodableVector signedAttrs = new ASN1EncodableVector();
SMIMECapabilityVector caps = new SMIMECapabilityVector();
//
caps.addCapability(SMIMECapability.dES_EDE3_CBC);
caps.addCapability(SMIMECapability.rC2_CBC, 128);
caps.addCapability(SMIMECapability.dES_CBC);
//
signedAttrs.add(new SMIMECapabilitiesAttribute(caps));
//
// Initialise the S/MIME generator
//
System.out.println("am_smime: " + "init SMIME generator" + ": " + Sysdate());
//
SMIMESignedGenerator gen = new SMIMESignedGenerator();
//
// Add the signer
//
gen.addSigner( smimeSigningKey, (X509Certificate) smimeCertChain[0], SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);
//
// put the certificates into an array
//
ArrayList certList = new ArrayList();
for (int i = 0; i < smimeCertChain.length; i++) {
certList.add(smimeCertChain[i]);
}
//
CertStore certsAndcrls = CertStore.getInstance("Collection", new CollectionCertStoreParameters(certList), "BC");
gen.addCertificatesAndCRLs(certsAndcrls);
//
// Now start building the message
//
System.out.println("am_smime: " + "build message" + ": " + Sysdate());
MimeBodyPart msg1 = new MimeBodyPart();
msg1.setText(mailBody, defaultCharset);
//
// And the attachment
//
MimeBodyPart msg2 = new MimeBodyPart();
//
// Create the multipart
//
MimeMultipart mp = new MimeMultipart();
//
// Create the body
//
MimeBodyPart msg = new MimeBodyPart();
//
if (pBlob != null) {
//
// We have an attachement
//
InputStream inputstream = pBlob.getBinaryStream();
DataHandler dh = new DataHandler(new ByteArrayDataSource(inputstream, fileMimeType));
msg2.setDataHandler(dh);
msg2.setFileName(fileName);
//
// Add the parts
//
mp.addBodyPart(msg1);
mp.addBodyPart(msg2);
//
// Set the content of the message to the multipart
//
msg.setContent(mp);
} else
{
//
// No attachment, set the content of the message to the first part
//
msg.setText(mailBody, defaultCharset);
}
//
// extract the multipart object from the SMIMESigned object.
//
MimeMultipart mm = gen.generate(msg, "BC");
//
// Inititialise mail authenticator
//
authenticator = new DefaultAuthenticator(smtpUsername, smtpPassword);
//
// Set the properties
//
Properties props = new Properties();
props.put("mail.smtp.host", smtpServerHost);
props.put("mail.smtp.user", smtpUsername);
//
// Get a Session object and create the mail message
//
Session session = Session.getDefaultInstance(props, authenticator);
//
// Set from and to
//
Address fromUser = new InternetAddress(mailFrom);
Address toUser = new InternetAddress(mailTo);
//
// Construct the message
//
MimeMessage body = new MimeMessage(session);
body.setFrom(fromUser);
body.setRecipient(Message.RecipientType.TO, toUser);
body.setSubject(mailSubject, defaultCharset);
body.setContent(mm, mm.getContentType());
body.saveChanges();
//
// Send
//
System.out.println("am_smime: " + "send message" + ": " + Sysdate());
Transport.send(body);
//
// Close the database connection
//
if (conn != null || !conn.isClosed()) {
conn.close(); // Close the database connection
conn = null;
System.out.println("am_smime: " + "connection closed" + ": " + Sysdate());
}
}
//
// Standard connection routine - try internal first, otherwise try with above details
//
public static Connection getConnection() throws SQLException {
if ( conn == null ) {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
try {
conn = DriverManager.getConnection("jdbc:default:connection:");
} catch ( Exception e ){}
}
if ( conn == null ) {
conn = DriverManager.getConnection(connection,username,password);
}
conn.setAutoCommit(false); // this is needed to write in update mode to BLOB
return conn;
}
//
// Default authenticator for SMTP passwords
//
private static class DefaultAuthenticator extends Authenticator {
//
// Password authentication instance
//
private PasswordAuthentication auth = null;
//
// CTOR with username and password
//
// @param username
// @param password
//
public DefaultAuthenticator (String username, String password) {
this.auth = new PasswordAuthentication(username, password);
}
//
// Overridden method returning password authentication
//
// @return PasswordAuthentication
//
public PasswordAuthentication getPasswordAuthentication() {
return this.auth;
}
}
}