org/objectweb/proactive/ext/security/DefaultProActiveSecurityManager.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.ext.security;
00032 
00033 import java.io.IOException;
00034 import java.io.Serializable;
00035 import java.math.BigInteger;
00036 import java.security.KeyPair;
00037 import java.security.Provider;
00038 import java.security.SecureRandom;
00039 import java.security.Security;
00040 import java.security.cert.X509Certificate;
00041 import java.text.DateFormat;
00042 import java.util.Date;
00043 import java.util.Hashtable;
00044 import java.util.Random;
00045 
00046 import org.apache.log4j.Logger;
00047 import org.bouncycastle.asn1.x509.X509Name;
00048 import org.bouncycastle.jce.provider.JDKKeyPairGenerator;
00049 import org.bouncycastle.x509.X509V3CertificateGenerator;
00050 import org.objectweb.proactive.core.util.log.Loggers;
00051 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00052 import org.objectweb.proactive.ext.security.crypto.Session;
00053 
00054 
00055 public class DefaultProActiveSecurityManager extends ProActiveSecurityManager
00056     implements Serializable {
00057     private transient Logger logger;
00058 
00059     public DefaultProActiveSecurityManager() {
00060         //      Provider myProvider = new org.bouncycastle.jce.provider.BouncyCastleProvider();
00061         //      Security.addProvider(myProvider);
00062         //                Security.insertProviderAt(myProvider, 0);
00063     }
00064 
00065     public DefaultProActiveSecurityManager(String vide)
00066         throws Exception {
00067         super(vide);
00068         sessions = new Hashtable<Long,Session>();
00069         logger = ProActiveLogger.getLogger(Loggers.SECURITY);
00070 
00071         Provider myProvider = new org.bouncycastle.jce.provider.BouncyCastleProvider();
00072         Security.addProvider(myProvider);
00073 
00074         /* generation of a default certificate */
00075         KeyPair keyPair = null;
00076         SecureRandom rand = new SecureRandom();
00077 
00078         JDKKeyPairGenerator.RSA keyPairGen = new JDKKeyPairGenerator.RSA();
00079 
00080         keyPairGen.initialize(1024, rand);
00081 
00082         keyPair = keyPairGen.generateKeyPair();
00083 
00084         // privateKey = keyPair.getPrivate();
00085         //publicKey = keyPair.getPublic();
00086         X509V3CertificateGenerator certifGenerator = new X509V3CertificateGenerator();
00087 
00088         X509Certificate certif = null;
00089 
00090         DateFormat convert = DateFormat.getDateInstance();
00091 
00092         //certifGenerator.setPublicKey(publicKey);
00093         String subjectCN = "CN=Generic Certificate" + new Random().nextLong() +
00094             ", OU=Generic Certificate, EmailAddress=none";
00095 
00096         //  System.out.println("DefaultCertificate subjectCN " + subjectCN);
00097         X509Name subject = new X509Name(subjectCN);
00098         X509Name issuer = new X509Name(
00099                 "CN=Generic Certificate, OU=Generic Certificate, EmailAddress=none");
00100 
00101         certifGenerator.setSubjectDN(subject);
00102         certifGenerator.setIssuerDN(issuer);
00103         certifGenerator.setSignatureAlgorithm("MD5withRSA");
00104 
00105         //    GregorianCalendar start = new GregorianCalendar(2002, Calendar.JUNE, 13);
00106         //  GregorianCalendar end = new GregorianCalendar(2004, Calendar.JUNE, 31);
00107         Date start = new Date(System.currentTimeMillis() - 50000);
00108         Date stop = new Date(System.currentTimeMillis() + 50000);
00109 
00110         certifGenerator.setNotAfter(stop);
00111         certifGenerator.setNotBefore(start);
00112         //  certifGenerator.setPublicKey(publicKey);
00113         certifGenerator.setSerialNumber(new BigInteger("1"));
00114 
00115         //certificate = certifGenerator.generateX509Certificate(privateKey, "BC");
00116         // byte[] t = certificate.getEncoded();
00117         // certificate = ProActiveSecurity.decodeCertificate(t);
00118         // System.out.println("Generic certificate created " + certificate.getSubjectDN());
00119         //  new RuntimeException().printStackTrace();
00120         //   System.out.println("******************** instantiated DefaultPSM ao Thread " + Thread.currentThread().getName() + "******************");
00121         // throw new SecurityException();
00122     }
00123 
00124     public ProActiveSecurityManager getProActiveSecurityManager() {
00125         return this;
00126     }
00127 
00128     public PolicyRule getPolicyTo(X509Certificate certificate) {
00129         //   logger.info("asked for my policy TO, replied default policy");
00130         return new PolicyRule();
00131     }
00132 
00133     public Communication getPolicyTo(String type, String from, String to) {
00134         //   logger.info("asked for my policy TO, replied default policy");
00135         return new Communication();
00136     }
00137 
00138     private void readObject(java.io.ObjectInputStream in)
00139         throws IOException, ClassNotFoundException {
00140         in.defaultReadObject();
00141 
00142         //System.out.println("reconstruit un DPSM");
00143         logger = ProActiveLogger.getLogger(Loggers.SECURITY);
00144     }
00145 }

Generated on Mon Jan 22 15:16:10 2007 for ProActive by  doxygen 1.5.1