1 31 package org.objectweb.proactive.ext.security; 32 33 import org.bouncycastle.asn1.x509.X509Name; 34 35 import org.bouncycastle.jce.X509V3CertificateGenerator; 36 import org.bouncycastle.jce.provider.JDKKeyPairGenerator; 37 38 import java.io.IOException ; 39 import java.io.Serializable ; 40 41 import java.math.BigInteger ; 42 43 import java.security.KeyPair ; 44 import java.security.Provider ; 45 import java.security.SecureRandom ; 46 import java.security.Security ; 47 import java.security.cert.X509Certificate ; 48 49 import java.text.DateFormat ; 50 51 import java.util.Date ; 52 import java.util.Hashtable ; 53 import java.util.Random ; 54 import java.util.logging.Logger ; 55 56 57 public class DefaultProActiveSecurityManager extends ProActiveSecurityManager 58 implements Serializable { 59 private transient Logger logger; 60 61 public DefaultProActiveSecurityManager() { 62 } 66 67 public DefaultProActiveSecurityManager(String vide) 68 throws Exception { 69 super(vide); 70 sessions = new Hashtable (); 71 logger = Logger.getLogger( 72 "org.objectweb.proactive.ext.security.DefaultProActiveSecurityManager"); 73 74 Provider myProvider = new org.bouncycastle.jce.provider.BouncyCastleProvider(); 75 Security.addProvider(myProvider); 76 77 78 KeyPair keyPair = null; 79 SecureRandom rand = new SecureRandom (); 80 81 JDKKeyPairGenerator.RSA keyPairGen = new JDKKeyPairGenerator.RSA(); 82 83 keyPairGen.initialize(1024, rand); 84 85 keyPair = keyPairGen.generateKeyPair(); 86 87 privateKey = keyPair.getPrivate(); 88 publicKey = keyPair.getPublic(); 89 90 X509V3CertificateGenerator certifGenerator = new X509V3CertificateGenerator(); 91 92 X509Certificate certif = null; 93 94 DateFormat convert = DateFormat.getDateInstance(); 95 96 certifGenerator.setPublicKey(publicKey); 97 98 String subjectCN = "CN=Generic Certificate" + new Random ().nextLong() + 99 ", OU=Generic Certificate, EmailAddress=none"; 100 101 X509Name subject = new X509Name(subjectCN); 103 X509Name issuer = new X509Name( 104 "CN=Generic Certificate, OU=Generic Certificate, EmailAddress=none"); 105 106 certifGenerator.setSubjectDN(subject); 107 certifGenerator.setIssuerDN(issuer); 108 certifGenerator.setSignatureAlgorithm("MD5withRSA"); 109 110 Date start = new Date (System.currentTimeMillis() - 50000); 113 Date stop = new Date (System.currentTimeMillis() + 50000); 114 115 certifGenerator.setNotAfter(stop); 116 certifGenerator.setNotBefore(start); 117 certifGenerator.setPublicKey(publicKey); 118 certifGenerator.setSerialNumber(new BigInteger ("1")); 119 120 certificate = certifGenerator.generateX509Certificate(privateKey, "BC"); 121 122 byte[] t = certificate.getEncoded(); 123 certificate = ProActiveSecurity.decodeCertificate(t); 124 125 } 130 131 195 199 public ProActiveSecurityManager getProActiveSecurityManager() 200 throws java.io.IOException { 201 return this; 202 } 203 204 public Policy getPolicyFrom(X509Certificate certificate) { 205 return new Policy(); 207 } 208 209 public Policy getPolicyTo(X509Certificate certificate) { 210 return new Policy(); 212 } 213 214 public Communication getPolicyTo(String type, String from, String to) { 215 return new Communication(); 217 } 218 219 private void readObject(java.io.ObjectInputStream in) 220 throws IOException , ClassNotFoundException { 221 in.defaultReadObject(); 222 223 logger = Logger.getLogger( 225 "org.objectweb.proactive.ext.security.DefaultProActiveSecurityManager"); 226 } 227 } 228 | Popular Tags |