User: starksm 
  Date: 02/03/07 21:31:02

  Added:       src/main/org/jboss/crypto CipherClientSocketFactory.java
                        CipherServerSocket.java
                        CipherServerSocketFactory.java CipherSocket.java
                        JBossSXProvider.java
  Log:
  Custom JBossSX security provider classes and crypto related stuff
  
  Revision  Changes    Path
  1.1                  jbosssx/src/main/org/jboss/crypto/CipherClientSocketFactory.java
  
  Index: CipherClientSocketFactory.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE WebOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.crypto;
  
  import java.io.IOException;
  import java.io.Serializable;
  import java.net.Socket;
  import java.rmi.server.RMIClientSocketFactory;
  
  import org.jboss.logging.Logger;
  
  /** An implementation of RMIClientSocketFactory that uses the JCE Cipher
   with an SRP session key to create an encrypted stream.
  
  @author  [EMAIL PROTECTED]
  @version $Revision: 1.1 $
  */
  public class CipherClientSocketFactory implements RMIClientSocketFactory, 
Serializable
  {
     private static final long serialVersionUID = -6412485012870705607L;
  
     /** Creates new CipherClientSocketFactory */
     public CipherClientSocketFactory()
     {
     }
  
     /** Create a client socket connected to the specified host and port.
     * @param host - the host name
     * @param port - the port number
     * @return a socket connected to the specified host and port.
     * @exception IOException if an I/O error occurs during socket creation.
     */
     public Socket createSocket(String host, int port)
        throws IOException
     {
        CipherSocket socket = null;
        return socket;
     }
  
     public boolean equals(Object obj)
     {
        return obj instanceof CipherClientSocketFactory;
     }
     public int hashCode()
     {
        return getClass().getName().hashCode();
     }
  
  }
  
  
  
  1.1                  jbosssx/src/main/org/jboss/crypto/CipherServerSocket.java
  
  Index: CipherServerSocket.java
  ===================================================================
  package org.jboss.crypto;
  
  import java.io.IOException;
  import java.net.InetAddress;
  import java.net.ServerSocket;
  import java.net.Socket;
  import javax.crypto.SecretKey;
  
  /**
   *
   * @author  [EMAIL PROTECTED]
   */
  public class CipherServerSocket extends ServerSocket
  {
     String algorithm;
     SecretKey key;
  
     /** Creates a new instance of CipherServerSocket */
     public CipherServerSocket(int port, int backlog,
        InetAddress bindAddr, String algorithm, SecretKey key) throws IOException
     {
        super(port, backlog, bindAddr);
        this.algorithm = algorithm;
        this.key = key;
     }
  
     public Socket accept() throws IOException
     {
        Socket s = super.accept();
        return new CipherSocket(s, algorithm, key);
     }
  }
  
  
  
  1.1                  jbosssx/src/main/org/jboss/crypto/CipherServerSocketFactory.java
  
  Index: CipherServerSocketFactory.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.crypto;
  
  import java.io.IOException;
  import java.io.Serializable;
  import java.net.ServerSocket;
  import java.net.UnknownHostException;
  import java.rmi.server.RMIServerSocketFactory;
  
  
  /** An implementation of RMIServerSocketFactory that uses a
   DomainServerSocketFactory for its implementation. This class is just an
   adaptor from the RMIServerSocketFactory to the DomainServerSocketFactory.
  
   This class is not suitable for RMI object that require a Serializable socket
   factory like activatable services. The reason for this limitation is that
   a SecurityDomain is not serializable due to its association with a local
   KeyStore.
  
  @author [EMAIL PROTECTED]
  @version $Revision: 1.1 $
  */
  public class CipherServerSocketFactory implements RMIServerSocketFactory
  {
  
     /** Creates new RMISSLServerSocketFactory */
     public CipherServerSocketFactory()
     {
     }
  
  
     /**
      * Create a server socket on the specified port (port 0 indicates
      * an anonymous port).
      * @param  port the port number
      * @return the server socket on the specified port
      * @exception IOException if an I/O error occurs during server socket
      * creation
      */
     public ServerSocket createServerSocket(int port)
        throws IOException
     {
        CipherServerSocket socket = null;
        return socket;
     }
  
     public boolean equals(Object obj)
     {
        return obj instanceof CipherServerSocketFactory;
     }
     public int hashCode()
     {
        return getClass().getName().hashCode();
     }
  }
  
  
  
  1.1                  jbosssx/src/main/org/jboss/crypto/CipherSocket.java
  
  Index: CipherSocket.java
  ===================================================================
  package org.jboss.crypto;
  
  import java.io.InputStream;
  import java.io.IOException;
  import java.io.OutputStream;
  import java.net.Socket;
  import java.util.Arrays;
  import javax.crypto.Cipher;
  import javax.crypto.CipherInputStream;
  import javax.crypto.CipherOutputStream;
  import javax.crypto.spec.IvParameterSpec;
  import javax.crypto.SecretKey;
  
  /**
   *
   * @author  [EMAIL PROTECTED]
   */
  public class CipherSocket extends Socket
  {
     private Cipher cipher;
     private Socket delegate;
     String algorithm;
     SecretKey key;
  
     /** Creates a new instance of CipherSocket */
     public CipherSocket(String host, int port, String algorithm, SecretKey key)
        throws IOException
     {
        super(host, port);
        this.algorithm = algorithm;
        this.key = key;
     }
     public CipherSocket(Socket delegate, String algorithm, SecretKey key)
        throws IOException
     {
        this.delegate = delegate;
        this.algorithm = algorithm;
        this.key = key;
     }
  
     public InputStream getInputStream() throws IOException
     {
        InputStream is = delegate == null ? super.getInputStream() : 
delegate.getInputStream();
        Cipher cipher = null;
        try
        {
           cipher = Cipher.getInstance(algorithm);
           int size = cipher.getBlockSize();
           byte[] tmp = new byte[size];
           Arrays.fill(tmp, (byte)15);
           IvParameterSpec iv = new IvParameterSpec(tmp);
           cipher.init(Cipher.DECRYPT_MODE, key, iv);
        }
        catch(Exception e)
        {
           e.printStackTrace();
           throw new IOException("Failed to init cipher: "+e.getMessage());
        }
        CipherInputStream cis = new CipherInputStream(is, cipher);
        return cis;
     }
  
     public OutputStream getOutputStream() throws IOException
     {
        OutputStream os = delegate == null ? super.getOutputStream() : 
delegate.getOutputStream();
        Cipher cipher = null;
        try
        {
           cipher = Cipher.getInstance(algorithm);
           int size = cipher.getBlockSize();
           byte[] tmp = new byte[size];
           Arrays.fill(tmp, (byte)15);
           IvParameterSpec iv = new IvParameterSpec(tmp);
           cipher.init(Cipher.ENCRYPT_MODE, key, iv);
        }
        catch(Exception e)
        {
           throw new IOException("Failed to init cipher: "+e.getMessage());
        }
        CipherOutputStream cos = new CipherOutputStream(os, cipher);
        return cos;
     }
  }
  
  
  
  1.1                  jbosssx/src/main/org/jboss/crypto/JBossSXProvider.java
  
  Index: JBossSXProvider.java
  ===================================================================
  package org.jboss.crypto;
  
  /** A Java2 security provider for cryptographic algorithms provided by
   the JBossSX framework.
  
  @author [EMAIL PROTECTED]
  @version $Revision: 1.1 $
  */
  public class JBossSXProvider extends java.security.Provider
  {
     public static final String PROVIDER_NAME = "JBossSX";
     public static final String PROVIDER_INFO = "JBossSX Provier Version 1.0";
     public static final double PROVIDER_VERSION = 1.0;
  
     /** Creates a new instance of Provider */
     public JBossSXProvider()
     {
        this(PROVIDER_NAME, PROVIDER_VERSION, PROVIDER_INFO);
     }
     protected JBossSXProvider(String name, double version, String info)
     {
        super(name, version, info);
        // Setup
        super.put("MessageDigest.SHA_Interleave", 
"org.jboss.crypto.digest.SHAInterleave");
        super.put("Alg.Alias.MessageDigest.SHA-Interleave", "SHA_Interleave");
        super.put("Alg.Alias.MessageDigest.SHA-SRP", "SHA_Interleave");
  
        super.put("MessageDigest.SHA_ReverseInterleave", 
"org.jboss.crypto.digest.SHAReverseInterleave");
        super.put("Alg.Alias.MessageDigest.SHA-SRP-Reverse", "SHA_ReverseInterleave");
     }
  
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to