00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.ext.security;
00032
00033 import java.io.ByteArrayInputStream;
00034 import java.io.ByteArrayOutputStream;
00035 import java.io.IOException;
00036 import java.io.Serializable;
00037 import java.security.KeyStore;
00038 import java.security.KeyStoreException;
00039 import java.security.NoSuchAlgorithmException;
00040 import java.security.NoSuchProviderException;
00041 import java.security.cert.CertificateException;
00042
00043
00048 public class SerializableKeyStore implements Serializable {
00049 protected transient KeyStore keyStore;
00050 protected byte[] encodedKeyStore;
00051
00052 public SerializableKeyStore(KeyStore keyStore) {
00053 this.keyStore = keyStore;
00054 }
00055
00056 private void writeObject(java.io.ObjectOutputStream out)
00057 throws IOException {
00058 ByteArrayOutputStream bout = new ByteArrayOutputStream();
00059
00060 try {
00061 keyStore.store(bout, "ha".toCharArray());
00062 } catch (KeyStoreException e) {
00063 e.printStackTrace();
00064 } catch (NoSuchAlgorithmException e) {
00065 e.printStackTrace();
00066 } catch (CertificateException e) {
00067 e.printStackTrace();
00068 } catch (IOException e) {
00069 e.printStackTrace();
00070 }
00071
00072 encodedKeyStore = bout.toByteArray();
00073 bout.close();
00074
00075 out.defaultWriteObject();
00076 }
00077
00078 private void readObject(java.io.ObjectInputStream in)
00079 throws IOException, ClassNotFoundException {
00080 in.defaultReadObject();
00081
00082 try {
00083 keyStore = KeyStore.getInstance("PKCS12", "BC");
00084 keyStore.load(new ByteArrayInputStream(encodedKeyStore),
00085 "ha".toCharArray());
00086 } catch (KeyStoreException e) {
00087
00088 e.printStackTrace();
00089 } catch (NoSuchProviderException e) {
00090
00091 e.printStackTrace();
00092 } catch (NoSuchAlgorithmException e) {
00093
00094 e.printStackTrace();
00095 } catch (CertificateException e) {
00096
00097 e.printStackTrace();
00098 } catch (IOException e) {
00099
00100 e.printStackTrace();
00101 }
00102 }
00103
00104 public KeyStore getKeyStore() {
00105 return keyStore;
00106 }
00107 }