geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r576951 - in /geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto: ./ CryptoContext.java CryptoContextAware.java package-info.java
Date Tue, 18 Sep 2007 15:37:37 GMT
Author: jdillon
Date: Tue Sep 18 08:37:36 2007
New Revision: 576951

URL: http://svn.apache.org/viewvc?rev=576951&view=rev
Log:
Adding some support for crypto muck which is needed for the handshake and maybe other crapo
too

Added:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/CryptoContext.java
  (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/CryptoContextAware.java
  (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/package-info.java
  (with props)

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/CryptoContext.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/CryptoContext.java?rev=576951&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/CryptoContext.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/CryptoContext.java
Tue Sep 18 08:37:36 2007
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.remote.crypto;
+
+import java.security.Key;
+import java.security.KeyFactory;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.PublicKey;
+import java.security.spec.X509EncodedKeySpec;
+
+import javax.crypto.Cipher;
+
+import org.codehaus.plexus.component.annotations.Component;
+
+/**
+ * Provides an abstraction of the crypto bits which are required for some remote shell communications.
+ *
+ * @version $Rev$ $Date$
+ */
+@Component(role= CryptoContext.class)
+public class CryptoContext
+{
+    //
+    // TODO: See if we should use DSA or RSA for this...
+    //
+    
+    // @Configuration
+    private String transformation = "RSA";
+
+    // @Configuration
+    private String provider;
+
+    private final KeyPair keyPair;
+
+    public CryptoContext() throws Exception {
+        KeyPairGenerator keyGen = createKeyPairGenerator();
+        keyGen.initialize(1024);
+        
+        keyPair = keyGen.genKeyPair();
+    }
+
+    public PublicKey getPublicKey() {
+        return keyPair.getPublic();
+    }
+
+    private byte[] codec(final int mode, final Key key, final byte[] bytes) throws Exception
{
+        assert key != null;
+        assert bytes != null;
+
+        Cipher cipher = createCipher();
+        cipher.init(mode, key);
+
+        return cipher.doFinal(bytes);
+    }
+
+    public byte[] encrypt(final Key key, final byte[] bytes) throws Exception {
+        return codec(Cipher.ENCRYPT_MODE, key, bytes);
+    }
+
+    public byte[] encrypt(final byte[] bytes) throws Exception {
+        return encrypt(keyPair.getPublic(), bytes);
+    }
+
+    public byte[] decrypt(final Key key, final byte[] bytes) throws Exception {
+        return codec(Cipher.DECRYPT_MODE, key, bytes);
+    }
+
+    public byte[] decrypt(final byte[] bytes) throws Exception {
+        return decrypt(keyPair.getPrivate(), bytes);
+    }
+
+    public PublicKey deserializePublicKey(final byte[] bytes) throws Exception {
+        assert bytes != null;
+
+        X509EncodedKeySpec spec = new X509EncodedKeySpec(bytes);
+
+        KeyFactory keyFactory = createKeyFactory();
+
+        return keyFactory.generatePublic(spec);
+    }
+    
+    //
+    // JCE Access
+    //
+
+    private KeyPairGenerator createKeyPairGenerator() throws Exception {
+        if (provider != null) {
+            return KeyPairGenerator.getInstance(transformation, provider);
+        }
+        else {
+            return KeyPairGenerator.getInstance(transformation);
+        }
+    }
+
+    private Cipher createCipher() throws Exception {
+        if (provider != null) {
+            return Cipher.getInstance(transformation, provider);
+        }
+        else {
+            return Cipher.getInstance(transformation);
+        }
+    }
+
+    private KeyFactory createKeyFactory() throws Exception {
+        if (provider != null) {
+            return KeyFactory.getInstance(transformation, provider);
+        }
+        else {
+            return KeyFactory.getInstance(transformation);
+        }
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/CryptoContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/CryptoContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/CryptoContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/CryptoContextAware.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/CryptoContextAware.java?rev=576951&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/CryptoContextAware.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/CryptoContextAware.java
Tue Sep 18 08:37:36 2007
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.remote.crypto;
+
+/**
+ * Allows manual injection of the {@link CryptoContext}.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface CryptoContextAware
+{
+    void setCryptoContext(CryptoContext ctx);
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/CryptoContextAware.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/CryptoContextAware.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/CryptoContextAware.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/package-info.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/package-info.java?rev=576951&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/package-info.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/package-info.java
Tue Sep 18 08:37:36 2007
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Support for encryption and decryption and related operations.
+ *
+ * @version $Rev$ $Date$
+ */
+package org.apache.geronimo.gshell.remote.crypto;
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/package-info.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/crypto/package-info.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message