changes to include Postfix, some changes to include OpenPGP, some changes to be able to use bouncy castle direct from git and as well bc149

This commit is contained in:
Timothy Prepscius 2013-09-16 14:58:37 -04:00
parent fb2a267e33
commit a1c9eb4041
1273 changed files with 15870 additions and 163171 deletions

View File

@ -1 +1,2 @@
cd ../java && ./build-java-projects

View File

@ -6,3 +6,6 @@ ant -buildfile exportScripts/MailStreamServer.xml
rm exported/Tools.jar
ant -buildfile exportScripts/Tools.xml
rm exported/PostFixMailReceiver.jar
ant -buildfile exportScripts/PostFixMailReceiver.xml

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="create_run_jar" name="Create Runnable Jar for Project Mailiverse.Core">
<!--this file was created by Eclipse Runnable JAR Export Wizard-->
<!--ANT 1.7 is required -->
<target name="create_run_jar">
<jar destfile="../../build/exported/PostfixMailReceiver.jar" filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class" value="mail.server.postfix.PostfixMailReceiver"/>
<attribute name="Class-Path" value="."/>
</manifest>
<fileset dir="../../java/core/bin"/>
<fileset dir="../../java/ext/bc-packaged/bin"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/annotations-api.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/catalina-ant.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/catalina-ha.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/catalina-tribes.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/catalina.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/ecj-4.2.1.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/el-api.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/jasper-el.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/jasper.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/jsp-api.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/servlet-api.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/tomcat-api.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/tomcat-coyote.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/tomcat-dbcp.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/tomcat-i18n-es.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/tomcat-i18n-fr.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/tomcat-i18n-ja.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/tomcat-jdbc.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../ext/apache-tomcat-7.0.37/lib/tomcat-util.jar"/>
<fileset dir="../../java/ext/jordanzimmerman/bin"/>
<fileset dir="../../java/ext/json/bin"/>
<zipfileset excludes="META-INF/*.SF" src="../../java/core/lib/dropbox-java-sdk-1.3.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../java/core/lib/aws-java-sdk.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../java/core/lib/javamail-1.4.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../java/core/lib/activation-1.1.1.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../java/core/lib/slf4j-api-1.3.1.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../java/core/lib/slf4j-simple-1.3.1.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../java/core/lib/mysql-connector-java-3.1.14-bin.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../java/core/lib/mina-core-2.0.4.jar"/>
<fileset dir="../../java/ext/apache/bin"/>
<zipfileset excludes="META-INF/*.SF" src="../../java/core/lib/commons-codec-1.4.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../java/core/lib/commons-logging-1.1.1.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../java/core/lib/httpclient-4.1.1.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../java/core/lib/httpcore-4.1.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../java/core/lib/JavaPNS_2.2.jar"/>
<zipfileset excludes="META-INF/*.SF" src="../../java/core/lib/log4j-1.2.15.jar"/>
</jar>
</target>
</project>

View File

@ -1,9 +1,10 @@
./server-shutdown tunnel
#./server-shutdown tunnel
./server-deploy tomcat
./server-deploy james
#./server-deploy james
./server-deploy postfix
./server-deploy mail-user
./server-deploy mail-key
./server-deploy tools
./web-deploy
./server-deploy tunnel
#./server-deploy tunnel

View File

@ -1,5 +1,6 @@
./dev-server-deploy tomcat
./dev-server-deploy james
#./dev-server-deploy james
./dev-server-deploy postfix
./dev-server-deploy mail-user
./dev-server-deploy mail-key
./dev-server-deploy tools

View File

@ -0,0 +1 @@
../../../../passwords/postfix

0
deploy/postfix-user. Normal file
View File

5
deploy/postfix-user/catalog Executable file
View File

@ -0,0 +1,5 @@
cd ~
mkdir -p deploy-catalog
V=`date "+%Y%m%d_%H%M%S"`
tar -czf deploy-catalog/deploy_$V.tar.gz deploy

View File

@ -0,0 +1,8 @@
# Postfix dynamic maps configuration file.
#
#type location of .so file open function (mkmap func)
#==== ================================ ============= ============
tcp /usr/lib/postfix/dict_tcp.so dict_tcp_open
sqlite /usr/lib/postfix/dict_sqlite.so dict_sqlite_open
mysql /usr/lib/postfix/dict_mysql.so dict_mysql_open
pcre /usr/lib/postfix/dict_pcre.so dict_pcre_open

View File

@ -0,0 +1,40 @@
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
readme_directory = no
# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
javapipe_destination_recipient_limit = 1
virtual_mailbox_domains = hash:/etc/postfix/virtual_domains
virtual_mailbox_maps = mysql:/etc/postfix/virtual_mailbox_maps.cf
virtual_transport = javapipe

View File

@ -0,0 +1,65 @@
#
# Postfix master process configuration file. For details on the format
# of the file, see the master(5) manual page (command: "man 5 master").
#
# Do not forget to execute "postfix reload" after editing this file.
#
# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
# ==========================================================================
smtp inet n - - - - smtpd
#smtp inet n - - - 1 postscreen
#smtpd pass - - - - - smtpd
#dnsblog unix - - - - 0 dnsblog
#tlsproxy unix - - - - 0 tlsproxy
#submission inet n - - - - smtpd
# -o syslog_name=postfix/submission
# -o smtpd_tls_security_level=encrypt
# -o smtpd_sasl_auth_enable=yes
# -o smtpd_reject_unlisted_recipient=no
# -o smtpd_client_restrictions=$mua_client_restrictions
# -o smtpd_helo_restrictions=$mua_helo_restrictions
# -o smtpd_sender_restrictions=$mua_sender_restrictions
# -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
#smtps inet n - - - - smtpd
# -o syslog_name=postfix/smtps
# -o smtpd_tls_wrappermode=yes
# -o smtpd_sasl_auth_enable=yes
# -o smtpd_reject_unlisted_recipient=no
# -o smtpd_client_restrictions=$mua_client_restrictions
# -o smtpd_helo_restrictions=$mua_helo_restrictions
# -o smtpd_sender_restrictions=$mua_sender_restrictions
# -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
#628 inet n - - - - qmqpd
pickup unix n - - 60 1 pickup
cleanup unix n - - - 0 cleanup
qmgr unix n - n 300 1 qmgr
#qmgr unix n - n 300 1 oqmgr
tlsmgr unix - - - 1000? 1 tlsmgr
rewrite unix - - - - - trivial-rewrite
bounce unix - - - - 0 bounce
defer unix - - - - 0 bounce
trace unix - - - - 0 bounce
verify unix - - - - 1 verify
flush unix n - - 1000? 0 flush
proxymap unix - - n - - proxymap
proxywrite unix - - n - 1 proxymap
smtp unix - - - - - smtp
#relay unix - - - - - smtp
# -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq unix n - - - - showq
error unix - - - - - error
retry unix - - - - - error
discard unix - - - - - discard
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - - - - lmtp
anvil unix - - - - 1 anvil
scache unix - - - - 1 scache
javapipe unix - n n - - pipe
user=postfix-user flags=DRhuX argv=java -jar /home/postfix-user/PostfixMailReceiver.jar -args $recipient

View File

@ -0,0 +1,2 @@
/^.*/ OK

View File

@ -0,0 +1,16 @@
#
# mysql config file for local(8) aliases(5) lookups
#
# The user name and password to log into the mysql server.
hosts = 127.0.0.1
user = postfix
password = postfix
# The database name on the servers.
dbname = postfix
# For Postfix 2.2 and later The SQL query template.
# See mysql_table(5) for details.
query = SELECT name FROM user WHERE name='%s'

View File

@ -0,0 +1 @@
../../../config/hosts

View File

@ -0,0 +1 @@
../../../../passwords/BucketCreate-AWS-AccessKey

View File

@ -0,0 +1 @@
../../../../passwords/BucketCreate-AWS-SecretKey

View File

@ -0,0 +1 @@
../../../../passwords/mail

View File

@ -0,0 +1 @@
../../../../passwords/mail-pbe

View File

@ -0,0 +1 @@
../../../../passwords/mail_extra

View File

@ -0,0 +1 @@
../../../../passwords/postfix

View File

@ -0,0 +1 @@
../../../../passwords/push-certificate

8
deploy/postfix-user/run Executable file
View File

@ -0,0 +1,8 @@
./setup
echo "----------------------------------------------" >> ../run.log
date >> ../run.log
echo "----------------------------------------------" >> ../run.log
sudo /etc/init.d/postfix start

6
deploy/postfix-user/setup Executable file
View File

@ -0,0 +1,6 @@
cd ~
ln -fs deploy/PostfixMailReceiver.jar
ln -fs deploy/config
ln -fs deploy/resources
cp resources/hosts/prod config/virtual_domains

1
deploy/postfix-user/shutdown Executable file
View File

@ -0,0 +1 @@
sudo /etc/init.d/postfix stop

View File

@ -0,0 +1,24 @@
package core.crypt;
import java.io.IOException;
public abstract class CryptorPGP extends CryptorJS
{
byte[] publicKeyBytes, privateKeyBytes;
public byte[] getPublicKey ()
{
return publicKeyBytes;
}
public byte[] getPrivateKey ()
{
return privateKeyBytes;
}
protected void initialize (byte[] publicKeyBytes, byte[] privateKeyBytes) throws IOException
{
this.privateKeyBytes = privateKeyBytes;
this.publicKeyBytes = publicKeyBytes;
}
}

View File

@ -0,0 +1,58 @@
package core.crypt;
import java.io.IOException;
import java.io.InputStream;
import app.service.JSInvoker;
import core.callback.Callback;
import core.callback.CallbackDefault;
import core.util.Base64;
import core.util.Pair;
public class CryptorPGPFactory
{
protected native String jsGenerate(int bits, String userId, String password) /*-{
var keyPair = $wnd.pgp_genKeyPair(bits, userId, password);
var joined = keyPair.publicKey + "," + keyPair.privateKey;
return joined;
}-*/;
protected native void jsGenerate(int bits, String userId, String password, Object callback) /*-{
$wnd.mAsync.pgp_genKeyPair(
{ invoke: function(keyPair) { callback.invoke(keyPair.publicKey, keyPair.privateKey); } },
bits,
userId, password
);
}-*/;
public Pair<byte[], byte[]> generate (int bits, String userId, String password)
{
String joined = jsGenerate(bits, userId, password);
String[] split = joined.split(",");
return new Pair<byte[], byte[]>(Base64.decode(split[0]), Base64.decode(split[1]));
}
public void generate (int bits, String userId, String password, Callback callback)
{
Callback synth = new CallbackDefault() {
public void onSuccess(Object... arguments) throws Exception
{
String split[] = { (String)arguments[0], (String)arguments[1] };
callback.invoke(new Pair<byte[], byte[]>(Base64.decode(split[0]), Base64.decode(split[1])));
}
}.setReturn(callback);
jsGenerate(bits, userId, password, JSInvoker.wrap(synth));
}
public static CryptorPGP fromResources(InputStream publicKey, InputStream privateKey) throws IOException {
return new CryptorPGPJS(publicKey, privateKey);
}
public static CryptorRSA fromString(String publicKey, Object object) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -0,0 +1,39 @@
package core.crypt;
import core.constants.ConstantsEnvironmentKeys;
import core.exceptions.CryptoException;
import core.util.Base64;
import core.util.Environment;
public class CryptorPGPFactoryEnvironment {
public static CryptorPGP create(Environment environment) throws CryptoException
{
return createJS(environment);
}
public static CryptorPGP createJS (Environment env) throws CryptoException
{
try
{
String publicKeyString = env.get(ConstantsEnvironmentKeys.PGP_PUBLIC_KEY);
byte[] publicKeyBytes = null;
if (publicKeyString != null)
publicKeyBytes = Base64.decode(publicKeyString);
String privateKeyString = env.get(ConstantsEnvironmentKeys.PGP_PRIVATE_KEY);
byte[] privateKeyBytes = null;
if (privateKeyString != null)
privateKeyBytes = Base64.decode(privateKeyString);
return new CryptorPGPJS (
publicKeyBytes,
privateKeyBytes
);
}
catch (Exception e)
{
throw new CryptoException(e);
}
}
}

View File

@ -0,0 +1,87 @@
package core.crypt;
import java.io.IOException;
import java.io.InputStream;
import app.service.JSInvoker;
import com.google.gwt.core.client.JavaScriptObject;
import core.util.Base64;
import core.util.LogNull;
import core.util.LogOut;
import core.util.Strings;
import core.callback.Callback;
import core.callback.CallbackDefault;
import core.util.Streams;
public class CryptorPGPJS extends CryptorPGP
{
static LogNull log = new LogNull(CryptorPGPJS.class);
JavaScriptObject privateKey, publicKey;
protected void initialize (byte[] publicKeyBytes, byte[] privateKeyBytes) throws IOException
{
super.initialize(publicKeyBytes, privateKeyBytes);
if (privateKeyBytes != null)
privateKey = jsGetPrivKey(Base64.encode(privateKeyBytes));
if (publicKeyBytes != null)
publicKey = jsGetPubKey(Base64.encode(publicKeyBytes));
}
public CryptorPGPJS(InputStream pri, InputStream pub) throws IOException
{
initialize(
pub != null ? Streams.readFullyBytes(pub) : null,
pri != null ? Streams.readFullyBytes(pri) : null
);
}
public CryptorPGPJS(byte[] publicKeyBytes, byte[] privateKeyBytes) throws IOException
{
initialize(publicKeyBytes, privateKeyBytes);
}
//------------------------------------------------------------
public Callback jsEncrypt_()
{
return new CallbackDefault() {
public void onSuccess(Object... arguments) throws Exception {
log.debug("jsEncrypt_",arguments[0]);
jsEncrypt(publicKey, (String)(arguments[0]), JSInvoker.wrap(callback));
}
};
}
public Callback jsDecrypt_()
{
return new CallbackDefault() {
public void onSuccess(Object... arguments) throws Exception {
log.debug("jsDecrypt_", arguments[0]);
jsDecrypt(privateKey, (String)(arguments[0]), JSInvoker.wrap(callback));
}
};
}
//------------------------------------------------------------
public native JavaScriptObject jsGetPrivKey (String pem64) /*-{
return $wnd.mSupport.pgp_getPrivateKey(pem64);
}-*/;
public native JavaScriptObject jsGetPubKey (String pem64) /*-{
return $wnd.mSupport.pgp_getPublicKey(pem64);
}-*/;
public native void jsEncrypt(JavaScriptObject key, String bytes64, JavaScriptObject callback) /*-{
return $wnd.mAsync.pgp_encrypt(callback, key, bytes64);
}-*/;
public native void jsDecrypt(JavaScriptObject key, String bytes64, JavaScriptObject callback) /*-{
return $wnd.mAsync.pgp_decrypt(callback, key, bytes64);
}-*/;
}

View File

@ -0,0 +1,12 @@
package core.util;
import app.service.JSHttpDelegate;
import app.service.Main;
public class HttpDelegateFactory
{
static HttpDelegate create ()
{
return new JSHttpDelegate(Main.delegate);
}
}

View File

@ -125,7 +125,7 @@ public class Zip
{
try
{
return new CallbackSync<byte[]>(inflate_()).export();
return new CallbackSync(inflate_()).<byte[]>export();
}
catch(Exception e)
{

View File

@ -2,6 +2,7 @@ set -x
./create-server-account-user.remote web
./create-server-account-user.remote james
./create-server-account-user.remote postfix-user
./create-server-account-user.remote mail-user
./create-server-account-user.remote mail-key
./create-server-account-user.remote tomcat

View File

@ -4,5 +4,5 @@ M_ROOT=`cat requirements/server_root_account`
M_HOST=$1
scp setup-java.remote $M_ROOT@$M_HOST:
ssh $M_ROOT@$M_HOST ./setup-java.remote
ssh $M_ROOT@$M_HOST sudo ./setup-java.remote

View File

@ -2,10 +2,14 @@
# because icetea has errors. After spending near 30 hours trying to negotiate icetea screw ups
# I realized: why bother?
sudo add-apt-repository ppa:webupd8team/java --yes
sudo apt-get update
#sudo apt-get install oracle-java7-installer --yes
sudo apt-get install oracle-java6-installer --yes
add-apt-repository ppa:webupd8team/java --yes
apt-get update
echo "yes
yes" | apt-get install oracle-java7-installer --yes
#echo "yes
#yes" | apt-get install oracle-java6-installer --yes
echo "Check the version after running this script, if it is not sun java then"
echo "read this: http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html"

View File

@ -1,6 +1,8 @@
set -x
sudo apt-get install mysql-server --yes
echo "
" | sudo apt-get install mysql-server --yes
mysql -u root < setup-mysql.sql
rm setup-mysql.sql

View File

@ -1,14 +1,17 @@
CREATE DATABASE mail DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
CREATE DATABASE mail_extra DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
CREATE DATABASE captcha DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
CREATE DATABASE postfix DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
CREATE DATABASE james CHARACTER SET utf8;
CREATE USER 'mail'@'localhost' IDENTIFIED BY 'MAIL_PASSWORD';
CREATE USER 'mail_extra'@'localhost' IDENTIFIED BY 'MAIL_EXTRA_PASSWORD';
CREATE USER 'captcha'@'localhost' IDENTIFIED BY 'CAPTCHA_PASSWORD';
CREATE USER 'james'@'localhost' IDENTIFIED BY 'JAMES_PASSWORD';
CREATE USER 'postfix'@'localhost' IDENTIFIED BY 'postfix';
GRANT ALL PRIVILEGES ON mail.* TO 'mail'@'localhost';
GRANT ALL PRIVILEGES ON mail_extra.* TO 'mail_extra'@'localhost';
GRANT ALL PRIVILEGES ON captcha.* TO 'captcha'@'localhost';
GRANT ALL PRIVILEGES ON james.* TO 'james'@'localhost';
GRANT ALL PRIVILEGES ON postfix.* TO 'postfix'@'localhost';

9
install/setup-postfix Executable file
View File

@ -0,0 +1,9 @@
set -x
M_HOST=$1
M_ROOT=`cat requirements/server_root_account`
scp sudoers.d-postfix-user $M_ROOT@$M_HOST:
scp setup-postfix.remote $M_ROOT@$M_HOST:
ssh $M_ROOT@$M_HOST sudo ./setup-postfix.remote

17
install/setup-postfix.remote Executable file
View File

@ -0,0 +1,17 @@
set -x
echo "1" | apt-get install postfix postfix-mysql postfix-pcre --yes
cp sudoers.d-postfix-user /etc/sudoers.d/postfix-user
chmod 0440 /etc/sudoers.d/postfix-user
cd /etc/postfix
rm main.cf
rm master.cf
ln -fs /home/postfix-user/config/main.cf
ln -fs /home/postfix-user/config/master.cf
#ln -fs /home/postfix-user/config/virtual_domains.pcre
ln -fs /home/postfix-user/config/virtual_domains
ln -fs /home/postfix-user/config/virtual_mailbox_maps.cf

View File

@ -7,7 +7,8 @@ M_HOST=$1
./create-server-accounts $M_HOST
./setup-utils $M_HOST
./setup-james $M_HOST
#./setup-james $M_HOST
./setup-postfix $M_HOST
./setup-java $M_HOST
./setup-mysql $M_HOST
./setup-tomcat $M_HOST

View File

@ -1,8 +1,8 @@
set -x
sudo ./setup-nginx.remote
./setup-nginx.remote
sudo mkdir -p /var/log/nginx
mkdir -p /var/log/nginx
chdown nginx /var/log/nginx
cp sudoers.d-web /etc/sudoers.d/web

View File

@ -0,0 +1 @@
postfix-user ALL = (root) NOPASSWD :/etc/init.d/postfix stop,/etc/init.d/postfix start

View File

@ -28,6 +28,7 @@ import core.constants.ConstantsEnvironmentKeys;
import core.constants.ConstantsClient;
import core.constants.ConstantsStorage;
import core.constants.ConstantsVersion;
import core.crypt.CryptorPGPFactory;
import core.crypt.CryptorRSAFactory;
import core.crypt.KeyPairFromPassword;
import core.io.IoChain;
@ -145,8 +146,11 @@ public class JSSignUp implements Exportable, SRPClientListener
String awsReadWriteAccessKey, awsReadWriteSecretKey;
String smtpPassword;
byte[] publicKey;
byte[] privateKey;
byte[] rsaPublicKey;
byte[] rsaPrivateKey;
byte[] pgpPublicKey;
byte[] pgpPrivateKey;
String stripeCardNumber, stripeCardExpMonth, stripeCardExpYear, stripeCardCVC;
String stripeTransactionID;
@ -209,8 +213,25 @@ public class JSSignUp implements Exportable, SRPClientListener
public void onSuccess(Object... arguments) throws Exception {
Pair<byte[], byte[]> pair = (Pair<byte[], byte[]>)arguments[0];
publicKey = pair.first;
privateKey = pair.second;
rsaPublicKey = pair.first;
rsaPrivateKey = pair.second;
callback.invoke();
}
}.setReturn(callback)
);
}
public void calculatePGP (Callback callback) throws NoSuchAlgorithmException
{
new CryptorPGPFactory().generate(2048, name, password, new CallbackDefault() {
@Override
public void onSuccess(Object... arguments) throws Exception {
Pair<byte[], byte[]> pair = (Pair<byte[], byte[]>)arguments[0];
pgpPublicKey = pair.first;
pgpPrivateKey = pair.second;
callback.invoke();
}
@ -234,7 +255,11 @@ public class JSSignUp implements Exportable, SRPClientListener
serverEnvironment.put(prefix + ConstantsDropbox.DropboxTokenSecret, dropboxUserSecret);
serverEnvironment.put(
ConstantsEnvironmentKeys.PUBLIC_ENCRYPTION_KEY,
Base64.encode(publicKey)
Base64.encode(rsaPublicKey)
);
serverEnvironment.put(
ConstantsEnvironmentKeys.PGP_PUBLIC_KEY,
Base64.encode(pgpPublicKey)
);
clientEnvironment = new Environment();
@ -248,11 +273,19 @@ public class JSSignUp implements Exportable, SRPClientListener
clientEnvironment.put(prefix + ConstantsDropbox.DropboxTokenSecret, dropboxUserSecret);
clientEnvironment.put(
ConstantsEnvironmentKeys.PUBLIC_ENCRYPTION_KEY,
Base64.encode(publicKey)
Base64.encode(rsaPublicKey)
);
clientEnvironment.put(
ConstantsEnvironmentKeys.PRIVATE_DECRYPTION_KEY,
Base64.encode(privateKey)
Base64.encode(rsaPrivateKey)
);
clientEnvironment.put(
ConstantsEnvironmentKeys.PGP_PUBLIC_KEY,
Base64.encode(pgpPublicKey)
);
clientEnvironment.put(
ConstantsEnvironmentKeys.PGP_PRIVATE_KEY,
Base64.encode(pgpPrivateKey)
);
completeEnvironment = new Environment();
@ -276,7 +309,11 @@ public class JSSignUp implements Exportable, SRPClientListener
serverEnvironment.put(prefix + ConstantsS3.AWSBucketRegion, awsBucketRegion);
serverEnvironment.put(
ConstantsEnvironmentKeys.PUBLIC_ENCRYPTION_KEY,
Base64.encode(publicKey)
Base64.encode(rsaPublicKey)
);
serverEnvironment.put(
ConstantsEnvironmentKeys.PGP_PUBLIC_KEY,
Base64.encode(pgpPublicKey)
);
clientEnvironment = new Environment();
@ -289,11 +326,19 @@ public class JSSignUp implements Exportable, SRPClientListener
clientEnvironment.put(prefix + ConstantsS3.AWSBucketRegion, awsBucketRegion);
clientEnvironment.put(
ConstantsEnvironmentKeys.PUBLIC_ENCRYPTION_KEY,
Base64.encode(publicKey)
Base64.encode(rsaPublicKey)
);
clientEnvironment.put(
ConstantsEnvironmentKeys.PRIVATE_DECRYPTION_KEY,
Base64.encode(privateKey)
Base64.encode(rsaPrivateKey)
);
clientEnvironment.put(
ConstantsEnvironmentKeys.PGP_PUBLIC_KEY,
Base64.encode(pgpPublicKey)
);
clientEnvironment.put(
ConstantsEnvironmentKeys.PGP_PRIVATE_KEY,
Base64.encode(pgpPrivateKey)
);
completeEnvironment = new Environment();
@ -345,6 +390,16 @@ public class JSSignUp implements Exportable, SRPClientListener
}
});
signUpChain.addCallback(new CallbackDefault(info) {
public void onSuccess(Object... arguments) throws Exception {
log.debug("signUp_step_createPGP");
SignUpInfo info = (SignUpInfo)V(0);
JSInvoker.invoke(info.callback.getCallback(), "progress", new Object[] { "Creating PGP key pair." });
info.calculatePGP(callback);
}
});
signUpChain.addCallback(new CallbackDefault(info) {
public void onSuccess(Object... arguments) throws Exception {
log.debug("signUp_step_genKeyPair");

View File

@ -38,7 +38,7 @@ public class Main extends JSApplet implements Exportable, SRPClientListener
static String VERSION_STRING = "M";
Object delegate;
public static Object delegate;
JSEventPropagator eventPropagator;
public Main ()

View File

@ -9,7 +9,7 @@
<property name="Mailiverse.App.Tools.location" value="../app/tools"/>
<property name="ECLIPSE_HOME" value="../../../../Desktop/eclipse"/>
<property name="Mailiverse.Ext.Apache.location" value="../ext/apache"/>
<property name="Mailiverse.Ext.BouncyCastle.location" value="../ext/lcrypto-jdk15on-148"/>
<property name="Mailiverse.Ext.BouncyCastle.location" value="../ext/bouncycastle"/>
<property name="Mailiverse.Ext.JordanZimmerman.location" value="../ext/jordanzimmerman"/>
<property name="Mailiverse.Ext.Json.location" value="../ext/json"/>
<property name="debuglevel" value="source,lines,vars"/>

View File

@ -6,7 +6,7 @@
package core.callback;
public class CallbackSync<T>
public class CallbackSync
{
CallbackChain chain;
Object[] results;
@ -16,7 +16,7 @@ public class CallbackSync<T>
chain = callback.addCallback(setResults_());
}
public CallbackSync<T> invoke (Object...args)
public CallbackSync invoke (Object...args)
{
chain.invoke(args);
return this;
@ -31,7 +31,7 @@ public class CallbackSync<T>
};
}
public T exportNoException ()
public <T> T exportNoException ()
{
try
{
@ -47,7 +47,7 @@ public class CallbackSync<T>
}
}
public T export() throws Exception
public <T> T export() throws Exception
{
if (results != null && results.length > 0)
{
@ -62,4 +62,21 @@ public class CallbackSync<T>
return null;
}
public <T> T export(int i) throws Exception
{
if (results != null && results.length > i)
{
if (results[0] instanceof Exception)
{
Exception e = (Exception)results[0];
throw e;
}
return (T)results[i];
}
return null;
}
}

View File

@ -13,4 +13,7 @@ public class ConstantsEnvironmentKeys
public static final String VERSION = "version";
public static final String CLIENT_ENVIRONMENT = "client";
public static final String SERVER_ENVIRONMENT = "server";
public static final String PGP_PUBLIC_KEY = "PGP-PublicKey";
public static final String PGP_PRIVATE_KEY = "PGP-PrivateKey";
}

View File

@ -9,6 +9,7 @@ public class ConstantsServer
public static final String LOCAL_MAIL_SERVER, DBCONNECTION_PREFIX;
public static final String KEY_SERVER;
public static final String LOCAL_SMTP_HOST;
public static final String AT_HOST;
static
{
@ -20,6 +21,7 @@ public class ConstantsServer
DBCONNECTION_PREFIX = "jdbc:mysql://" + Hosts.getHostFor("local_db_dev") + "/";
KEY_SERVER = Hosts.getHostFor("local_key_dev");
LOCAL_SMTP_HOST = Hosts.getHostFor("local_smtp_dev");
AT_HOST = "@" + Hosts.getHostFor("dev");
}
else
{
@ -31,6 +33,7 @@ public class ConstantsServer
LOCAL_MAIL_SERVER = Hosts.getHostFor("local_mail_prod");
DBCONNECTION_PREFIX = "jdbc:mysql://" + Hosts.getHostFor("local_db_prod") + "/";
LOCAL_SMTP_HOST = Hosts.getHostFor("local_smtp_prod");
AT_HOST = "@" + Hosts.getHostFor("prod");
}
}

View File

@ -193,7 +193,7 @@ public class CryptorRSAAES extends Cryptor
{
try
{
return new CallbackSync<byte[]>(encrypt_()).invoke(bytes).export();
return new CallbackSync(encrypt_()).invoke(bytes).export();
}
catch (Exception e)
{
@ -206,7 +206,7 @@ public class CryptorRSAAES extends Cryptor
{
try
{
return new CallbackSync<byte[]>(decrypt_()).invoke(bytes).export();
return new CallbackSync(decrypt_()).invoke(bytes).export();
}
catch (Exception e)
{

View File

@ -32,8 +32,8 @@ public class CryptorRSABC extends CryptorRSA
public final int MAX_RSA_BLOCK_SIZE = 117;
RSAPublicKey publicKey;
RSAPrivateKey privateKey;
public RSAPublicKey publicKey;
public RSAPrivateKey privateKey;
public static final byte[] iv = Arrays.generate(16, 0);

View File

@ -0,0 +1,332 @@
package core.crypt;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.NoSuchProviderException;
import java.util.Date;
import java.util.Iterator;
import org.bc.bcpg.ArmoredOutputStream;
import org.bc.crypto.params.AsymmetricKeyParameter;
import org.bc.crypto.util.PrivateKeyFactory;
import org.bc.crypto.util.PublicKeyFactory;
import org.bc.openpgp.PGPCompressedData;
import org.bc.openpgp.PGPCompressedDataGenerator;
import org.bc.openpgp.PGPEncryptedData;
import org.bc.openpgp.PGPEncryptedDataGenerator;
import org.bc.openpgp.PGPEncryptedDataList;
import org.bc.openpgp.PGPException;
import org.bc.openpgp.PGPLiteralData;
import org.bc.openpgp.PGPLiteralDataGenerator;
import org.bc.openpgp.PGPObjectFactory;
import org.bc.openpgp.PGPPrivateKey;
import org.bc.openpgp.PGPPublicKey;
import org.bc.openpgp.PGPPublicKeyEncryptedData;
import org.bc.openpgp.PGPUtil;
import org.bc.openpgp.operator.KeyFingerPrintCalculator;
import org.bc.openpgp.operator.bc.BcPGPDataEncryptorBuilder;
import org.bc.openpgp.operator.bc.BcPGPKeyConverter;
import org.bc.openpgp.operator.bc.BcPublicKeyDataDecryptorFactory;
import org.bc.openpgp.operator.bc.BcPublicKeyKeyEncryptionMethodGenerator;
import core.util.Pair;
/**
* Simple routine to encrypt and decrypt using a Public and Private key with passphrase. This service
* routine provides the basic PGP services between byte arrays.
*
*/
public class PgpEncryption {
/*
private static PGPPrivateKey findSecretKey(
PGPSecretKeyRingCollection pgpSec, long keyID, char[] pass)
throws PGPException, NoSuchProviderException {
PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);
if (pgpSecKey == null) {
return null;
}
return pgpSecKey.extractPrivateKey(pass, "BC");
}
*/
private static boolean isCorrectPublicKey (
PGPPrivateKey sKey, long keyID
)
{
return sKey.getKeyID() == keyID;
}
/**
* decrypt the passed in message stream
*
* @param encrypted
* The message to be decrypted.
* @param passPhrase
* Pass phrase (key)
*
* @return Clear text as a byte array. I18N considerations are not handled
* by this routine
* @exception IOException
* @exception PGPException
* @exception NoSuchProviderException
*/
public static byte[] decrypt(byte[] encrypted, PGPPrivateKey sKey)
throws IOException, PGPException, NoSuchProviderException {
KeyFingerPrintCalculator keyFingerPrintCalculator = null;
InputStream in = new ByteArrayInputStream(encrypted);
in = PGPUtil.getDecoderStream(in);
PGPObjectFactory pgpF = new PGPObjectFactory(in, keyFingerPrintCalculator);
PGPEncryptedDataList enc = null;
Object o = pgpF.nextObject();
//
// the first object might be a PGP marker packet.
//
if (o instanceof PGPEncryptedDataList) {
enc = (PGPEncryptedDataList) o;
} else {
enc = (PGPEncryptedDataList) pgpF.nextObject();
}
//
// find the secret key
//
Iterator it = enc.getEncryptedDataObjects();
// PGPPrivateKey sKey = null;
PGPPublicKeyEncryptedData pbe = null;
// PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(
// PGPUtil.getDecoderStream(keyIn));
while (it.hasNext()) {
pbe = (PGPPublicKeyEncryptedData) it.next();
if (isCorrectPublicKey(sKey, pbe.getKeyID()))
break;
// sKey = findSecretKey(pgpSec, pbe.getKeyID(), password);
}
if (!isCorrectPublicKey(sKey, pbe.getKeyID())) {
throw new IllegalArgumentException(
"secret key for message not found.");
}
InputStream clear = pbe.getDataStream(new BcPublicKeyDataDecryptorFactory(sKey));
PGPObjectFactory pgpFact = new PGPObjectFactory(clear, keyFingerPrintCalculator);
PGPCompressedData cData = (PGPCompressedData) pgpFact.nextObject();
pgpFact = new PGPObjectFactory(cData.getDataStream(), keyFingerPrintCalculator);
PGPLiteralData ld = (PGPLiteralData) pgpFact.nextObject();
InputStream unc = ld.getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
int ch;
while ((ch = unc.read()) >= 0) {
out.write(ch);
}
byte[] returnBytes = out.toByteArray();
out.close();
return returnBytes;
}
/**
* Simple PGP encryptor between byte[].
*
* @param clearData
* The test to be encrypted
* @param passPhrase
* The pass phrase (key). This method assumes that the key is a
* simple pass phrase, and does not yet support RSA or more
* sophisiticated keying.
* @param fileName
* File name. This is used in the Literal Data Packet (tag 11)
* which is really inly important if the data is to be related to
* a file to be recovered later. Because this routine does not
* know the source of the information, the caller can set
* something here for file name use that will be carried. If this
* routine is being used to encrypt SOAP MIME bodies, for
* example, use the file name from the MIME type, if applicable.
* Or anything else appropriate.
*
* @param armor
*
* @return encrypted data.
* @exception IOException
* @exception PGPException
* @exception NoSuchProviderException
*/
public static byte[] encrypt(byte[] clearData, PGPPublicKey encKey,
String fileName,boolean withIntegrityCheck, boolean armor)
throws IOException, PGPException, NoSuchProviderException {
if (fileName == null) {
fileName = PGPLiteralData.CONSOLE;
}
ByteArrayOutputStream encOut = new ByteArrayOutputStream();
OutputStream out = encOut;
if (armor) {
out = new ArmoredOutputStream(out);
}
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(
PGPCompressedDataGenerator.ZIP);
OutputStream cos = comData.open(bOut); // open it with the final
// destination
PGPLiteralDataGenerator lData = new PGPLiteralDataGenerator();
// we want to generate compressed data. This might be a user option
// later,
// in which case we would pass in bOut.
OutputStream pOut = lData.open(cos, // the compressed output stream
PGPLiteralData.BINARY, fileName, // "filename" to store
clearData.length, // length of clear data
new Date() // current time
);
pOut.write(clearData);
lData.close();
comData.close();
PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(
new BcPGPDataEncryptorBuilder(PGPEncryptedData.CAST5)
);
cPk.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(encKey));
byte[] bytes = bOut.toByteArray();
OutputStream cOut = cPk.open(out, bytes.length);
cOut.write(bytes); // obtain the actual bytes from the compressed stream
cOut.close();
out.close();
return encOut.toByteArray();
}
/*
private static PGPPublicKey readPublicKey(InputStream in)
throws IOException, PGPException {
in = PGPUtil.getDecoderStream(in);
PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(in);
//
// we just loop through the collection till we find a key suitable for
// encryption, in the real
// world you would probably want to be a bit smarter about this.
//
//
// iterate through the key rings.
//
Iterator rIt = pgpPub.getKeyRings();
while (rIt.hasNext()) {
PGPPublicKeyRing kRing = (PGPPublicKeyRing) rIt.next();
Iterator kIt = kRing.getPublicKeys();
while (kIt.hasNext()) {
PGPPublicKey k = (PGPPublicKey) kIt.next();
if (k.isEncryptionKey()) {
return k;
}
}
}
throw new IllegalArgumentException(
"Can't find encryption key in key ring.");
}
*/
private static PGPPublicKey readPublicKey(InputStream in)
throws IOException, PGPException {
return null;
};
public static byte[] getBytesFromFile(File file) throws IOException {
InputStream is = new FileInputStream(file);
// Get the size of the file
long length = file.length();
if (length > Integer.MAX_VALUE) {
// File is too large
}
// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];
// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < bytes.length
&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}
// Ensure all the bytes have been read in
if (offset < bytes.length) {
throw new IOException("Could not completely read file "+file.getName());
}
// Close the input stream and return bytes
is.close();
return bytes;
}
public static void main(String[] args) throws Exception {
byte[] original = "Hello world".getBytes();
System.out.println("Starting PGP test");
CryptorRSAFactory factory= new CryptorRSAFactory();
Pair<byte[], byte[]> result = factory.generate(2048);
Date date = new Date();
BcPGPKeyConverter converter = new BcPGPKeyConverter();
AsymmetricKeyParameter publicKeyParameter = PublicKeyFactory.createKey(result.first);
PGPPublicKey pgpPublicKey = converter.getPGPPublicKey(1, publicKeyParameter, date);
byte[] encrypted = encrypt(original, pgpPublicKey, null,
true, true);
System.out.println("\nencrypted data = '" + new String(encrypted) + "'");
AsymmetricKeyParameter privateKeyParameter = PrivateKeyFactory.createKey(result.second);
PGPPrivateKey pgpPrivateKey = converter.getPGPPrivateKey(pgpPublicKey, privateKeyParameter);
byte[] decrypted = decrypt(encrypted, pgpPrivateKey);
System.out.println("\ndecrypted data = '" + new String(decrypted) + "'");
}
}

View File

@ -10,7 +10,7 @@ INSERT IGNORE INTO registry (k,v) VALUES ("max_users", "1000");
CREATE TABLE IF NOT EXISTS user (
version VARCHAR(50),
id INTEGER AUTO_INCREMENT,
name VARCHAR(255) COLLATE utf8_general_ci NOT NULL DEFAULT '',
name VARCHAR(255) NOT NULL DEFAULT '',
v TEXT,
s TEXT,
mark TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
@ -41,7 +41,7 @@ CREATE TABLE IF NOT EXISTS failure (
CREATE TABLE IF NOT EXISTS deleted_user (
version VARCHAR(50),
id INTEGER AUTO_INCREMENT,
name VARCHAR(255) COLLATE utf8_general_ci NOT NULL DEFAULT '',
name VARCHAR(255) NOT NULL DEFAULT '',
v TEXT,
s TEXT,
mark TIMESTAMP NULL DEFAULT NULL,
@ -51,5 +51,4 @@ CREATE TABLE IF NOT EXISTS deleted_user (
CREATE TABLE IF NOT EXISTS deleted_mail_block LIKE mail_block;
CREATE TABLE IF NOT EXISTS deleted_key_block LIKE key_block;
DROP TABLE IF EXISTS metadata;

View File

@ -27,7 +27,7 @@ public abstract class HttpDelegate
boolean binaryInput = (Boolean)V(3);
boolean binaryOutput = (Boolean)V(4);
byte[] content = (byte[])arguments[0];
byte[] content = (arguments!=null && arguments.length > 0) ? (byte[])arguments[0] : null;
execute(action, url, headers, binaryInput, binaryOutput, content, callback);
}

View File

@ -10,6 +10,7 @@ import mail.client.model.Attachments;
import mail.client.model.Body;
import mail.client.model.Conversation;
import mail.client.model.Header;
import mail.client.model.Identity;
import mail.client.model.Mail;
import mail.client.model.Recipients;
import mail.client.model.TransportState;
@ -167,4 +168,9 @@ public class Actions extends Servent<Master>
return reply;
}
public void lookUpPGPKeyFor (Identity identity)
{
master.getMailer().lookUpPGPFor (identity);
}
}

View File

@ -151,4 +151,8 @@ public class Mailer extends Servent<Master>
master.getIndexer().conversationChanged(conversation);
master.getEventPropagator().signal(Events.SendFailed, mail);
}
public void lookUpPGPFor(Identity identity)
{
}
}

View File

@ -0,0 +1,9 @@
package mail.server.db;
public interface ExternalData {
public void addUser (String name, String password) throws Exception;
public void removeUser (String name) throws Exception;
public void setUserPassword (String name, String password) throws Exception;
}

View File

@ -0,0 +1,11 @@
package mail.server.db;
import mail.server.postfix.ExternalDataPostfix;
public class ExternalDataFactory {
public static ExternalData createInstance () throws Exception
{
return new ExternalDataPostfix();
}
}

View File

@ -0,0 +1,34 @@
package mail.server.james;
import org.apache.james.cli.probe.impl.JmxServerProbe;
import mail.server.db.ExternalData;
public class ExternalDataJames implements ExternalData
{
JmxServerProbe jamesConnection;
public ExternalDataJames () throws Exception
{
jamesConnection = new JmxServerProbe("localhost");
}
@Override
public void addUser(String name, String password) throws Exception
{
jamesConnection.addUser(name, password);
}
@Override
public void removeUser(String name) throws Exception
{
jamesConnection.removeUser(name);
}
@Override
public void setUserPassword(String name, String password) throws Exception
{
jamesConnection.setPassword(name, password);
}
}

View File

@ -0,0 +1,123 @@
package mail.server.postfix;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import core.util.LogOut;
import core.util.Passwords;
import mail.server.db.ExternalData;
import mail.server.postfix.sql.Catalog;
public class ExternalDataPostfix implements ExternalData
{
Catalog catalog = new Catalog();
LogOut log = new LogOut (ExternalDataPostfix.class);
public ExternalDataPostfix() throws Exception
{
ensureTables();
}
public void ensureTables() throws SQLException, IOException
{
Connection connection = openConnection();
try
{
for (String sql : catalog.getMulti(catalog.CREATE_TABLES))
{
PreparedStatement statement = connection.prepareStatement (sql);
log(statement);
statement.executeUpdate();
}
}
finally
{
closeConnection(connection);
}
}
@Override
public void addUser(String name, String password) throws Exception
{
Connection connection = openConnection();
try
{
PreparedStatement statement = connection.prepareStatement (catalog.getSingle(catalog.ADD_USER));
statement.setString(1, name);
statement.setString(2, password);
statement.executeUpdate();
}
finally
{
closeConnection(connection);
}
}
@Override
public void removeUser (String name) throws Exception
{
Connection connection = openConnection();
try
{
PreparedStatement statement = connection.prepareStatement (catalog.getSingle(catalog.REMOVE_USER));
statement.setString(1, name);
statement.executeUpdate();
}
finally
{
closeConnection(connection);
}
}
@Override
public void setUserPassword(String name, String password) throws Exception
{
Connection connection = openConnection();
try
{
PreparedStatement statement = connection.prepareStatement (catalog.getSingle(catalog.CHANGE_PASSWORD));
statement.setString(1, password);
statement.setString(2, name);
statement.executeUpdate();
}
finally
{
closeConnection(connection);
}
}
public Connection openConnection () throws IOException, SQLException
{
log.debug("Connecting to", catalog.CONNECTION_STRING);
return DriverManager.getConnection(catalog.CONNECTION_STRING, catalog.USER, Passwords.getPasswordFor(catalog.USER));
}
public void closeConnection (Connection connection)
{
try
{
if (connection != null)
connection.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void log (Statement sql)
{
log.debug (sql);
}
}

View File

@ -0,0 +1,26 @@
package mail.server.postfix;
import java.io.ByteArrayInputStream;
import mail.server.handler.UserInformation;
import mail.server.handler.UserInformationFactory;
import core.util.Streams;
public class PostfixMailReceiver
{
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
String toAddress = args[1];
byte[] bytes = Streams.readFullyBytes(System.in);
UserInformation userInfo = UserInformationFactory.getInstance().getUserInformation(toAddress);
userInfo.handleIn(new ByteArrayInputStream(bytes));
}
}

View File

@ -0,0 +1,36 @@
/**
* Author: Timothy Prepscius
* License: GPLv3 Affero + keep my name in the code!
*/
package mail.server.postfix.sql;
import java.io.IOException;
import core.constants.ConstantsServer;
import core.util.Passwords;
import core.util.SqlCatalog;
public final class Catalog extends SqlCatalog
{
public String CONNECTION_STRING = ConstantsServer.DBCONNECTION_PREFIX + "postfix";
public String USER = "postfix";
public int FAILURE_TIMEOUT_SECONDS = 60;
public final String
CREATE_TABLES = "create_tables.sql",
ADD_USER = "add_user.sql",
REMOVE_USER = "remove_user.sql",
CHANGE_PASSWORD = "change_password.sql";
public Catalog ()
{
}
public String getPassword () throws IOException
{
return Passwords.getPasswordFor(USER);
}
}

View File

@ -0,0 +1 @@
INSERT INTO user (name, password) VALUES (?, ?)

View File

@ -0,0 +1,5 @@
UPDATE user
SET
password = ?
WHERE
name = ?

View File

@ -0,0 +1,8 @@
CREATE TABLE IF NOT EXISTS user (
name VARCHAR(255) NOT NULL DEFAULT '',
password VARCHAR(255),
mark TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (name)
);

View File

@ -0,0 +1 @@
DELETE FROM user WHERE user.name=?

View File

@ -9,6 +9,8 @@ import java.math.BigInteger;
import java.sql.SQLException;
import java.util.Random;
import mail.server.db.ExternalData;
import mail.server.db.ExternalDataFactory;
import mail.server.db.MailUserDb;
import org.apache.james.cli.probe.impl.JmxServerProbe;
@ -47,15 +49,14 @@ public class MailServerSessionDb implements SRPServerUserSessionDb
public void setBlock (String userName, byte[] block) throws Exception
{
ExternalData externalData = ExternalDataFactory.createInstance();
log.debug("setBlock", userName, Strings.toString(block));
Environment e = JSONSerializer.deserialize(block);
String newPassword = e.get(ConstantsEnvironmentKeys.SMTP_PASSWORD);
JmxServerProbe jamesConnection = new JmxServerProbe("localhost");
if (newPassword != null)
jamesConnection.setPassword(userName, newPassword);
externalData.setUserPassword(userName, newPassword);
db.setBlock(userName, block);
}
@ -77,7 +78,7 @@ public class MailServerSessionDb implements SRPServerUserSessionDb
log.debug("createUser", version, userName);
try
{
JmxServerProbe jamesConnection = new JmxServerProbe("localhost");
ExternalData externalData = ExternalDataFactory.createInstance();
if (USE_CAPTCHA)
{
@ -93,7 +94,7 @@ public class MailServerSessionDb implements SRPServerUserSessionDb
Random random = new Random();
String randomLong = BigInteger.valueOf(Math.abs(random.nextLong())).toString(32);
jamesConnection.addUser(userName, randomLong);
externalData.addUser(userName, randomLong);
}
catch (PublicMessageException e)
{
@ -112,10 +113,10 @@ public class MailServerSessionDb implements SRPServerUserSessionDb
log.debug("deleteUser", userName);
try
{
JmxServerProbe jamesConnection = new JmxServerProbe("localhost");
ExternalData externalData = ExternalDataFactory.createInstance();
db.deleteUser(userName);
jamesConnection.removeUser(userName);
externalData.removeUser(userName);
}
catch (PublicMessageException e)
{

2
java/ext/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
lcrypto-jdk15on-*
bc-packaged

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry excluding="**/*Test*|**/*test*|**/test/*" kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0">
<attributes>

View File

@ -59,6 +59,9 @@
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src"/>
<exclude name="**/*Test*"/>
<exclude name="**/test/*"/>
<exclude name="**/*test*"/>
<classpath refid="Mailiverse.Ext.BouncyCastle.classpath"/>
</javac>
</target>

1
java/ext/bc-project Symbolic link
View File

@ -0,0 +1 @@
lcrypto-jdk15on-149

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>bc-project</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1 @@
../../../../bc-java/core/src/main/java/org/bouncycastle/LICENSE.java

View File

@ -0,0 +1 @@
../../../../bc-java/pg/src/main/java/org/bouncycastle/apache

View File

@ -0,0 +1 @@
../../../../bc-java/core/src/main/java/org/bouncycastle/asn1

View File

@ -0,0 +1 @@
../../../../bc-java/pg/src/main/java/org/bouncycastle/bcpg

View File

@ -0,0 +1 @@
../../../../bc-java/core/src/main/java/org/bouncycastle/crypto

View File

@ -0,0 +1 @@
../../../../bc-java/core/src/main/java/org/bouncycastle/i18n

View File

@ -0,0 +1 @@
../../../../bc-java/core/src/main/java/org/bouncycastle/math

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPAlgorithmParameters.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPCompressedData.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPCompressedDataGenerator.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPDataValidationException.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPEncryptedData.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPEncryptedDataGenerator.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPEncryptedDataList.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPException.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPKdfParameters.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPKeyFlags.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPKeyPair.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPKeyRing.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPKeyRingGenerator.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPKeyValidationException.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPLiteralData.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPLiteralDataGenerator.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPMarker.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPObjectFactory.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPOnePassSignature.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPOnePassSignatureList.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPPBEEncryptedData.java

View File

@ -0,0 +1 @@
../../../../../bc-java/pg/src/main/java/org/bouncycastle/openpgp/PGPPrivateKey.java

Some files were not shown because too many files have changed in this diff Show More