summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-04 03:16:37 (EDT)
committerEike Stepper2007-10-04 03:16:37 (EDT)
commit472ba195981fd5996148ca2b80f1e740fe6a7a4c (patch)
tree5779e93e5e41d004979774e55e3487d4ca4ae0c1
parentbf079c56ef6ecebfdc8bd4196be52d51ddf4566f (diff)
downloadcdo-472ba195981fd5996148ca2b80f1e740fe6a7a4c.zip
cdo-472ba195981fd5996148ca2b80f1e740fe6a7a4c.tar.gz
cdo-472ba195981fd5996148ca2b80f1e740fe6a7a4c.tar.bz2
[205027] Implement challenge/response based negotiator
https://bugs.eclipse.org/bugs/show_bug.cgi?id=205027
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SecurityTest.java84
-rw-r--r--plugins/org.eclipse.net4j.util/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeNegotiator.java179
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Credentials.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/ConnectorCredentials.java)8
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/FileUserManager.java134
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/NegotiationContext.java95
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Negotiator.java118
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/PasswordCredentials.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/net4j/IConnectorNegotiator.java)29
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Randomizer.java145
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ResponseNegotiator.java77
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/UserManager.java95
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/UserManagerNegotiator.java71
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/IBufferReceiver.java21
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/IChallengeResponse.java27
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/ICredentials.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/net4j/IConnectorCredentials.java)7
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/ICredentialsProvider.java19
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/INegotiationContext.java29
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/INegotiator.java19
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/IRandomizer.java35
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/IUserManager.java23
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/SecurityUtil.java64
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Connector.java13
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/IConnector.java7
23 files changed, 1262 insertions, 39 deletions
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SecurityTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SecurityTest.java
new file mode 100644
index 0000000..98d3fb0
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SecurityTest.java
@@ -0,0 +1,84 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.tests;
+
+import org.eclipse.net4j.internal.util.security.ChallengeNegotiator;
+import org.eclipse.net4j.internal.util.security.NegotiationContext;
+import org.eclipse.net4j.internal.util.security.Randomizer;
+import org.eclipse.net4j.internal.util.security.ResponseNegotiator;
+import org.eclipse.net4j.internal.util.security.UserManager;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Eike Stepper
+ */
+public class SecurityTest extends AbstractOMTest
+{
+ private Randomizer randomizer = new Randomizer();
+
+ private UserManager userManager = new UserManager();
+
+ private NegotiationContext challengeContext = new NegotiationContext()
+ {
+ public void transmitBuffer(ByteBuffer buffer)
+ {
+ buffer.flip();
+ responseContext.getBufferReceiver().receiveBuffer(buffer);
+ }
+ };
+
+ private NegotiationContext responseContext = new NegotiationContext()
+ {
+ public void transmitBuffer(ByteBuffer buffer)
+ {
+ buffer.flip();
+ challengeContext.getBufferReceiver().receiveBuffer(buffer);
+ }
+ };
+
+ public void testNegotiation() throws Exception
+ {
+ randomizer.activate();
+ userManager.activate();
+ userManager.addUser("stepper", "eike2007".toCharArray());
+
+ ResponseNegotiator responseNegotiator = new ResponseNegotiator();
+ new Thread()
+ {
+ @Override
+ public void run()
+ {
+ ChallengeNegotiator negotiator = new ChallengeNegotiator();
+ negotiator.setRandomizer(randomizer);
+ negotiator.setUserManager(userManager);
+ negotiator.setTokenLength(1024);
+
+ try
+ {
+ negotiator.activate();
+ negotiator.startNegotiation(challengeContext);
+ NegotiationContext.State result = challengeContext.waitForResult(2000);
+ System.out.println(result);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+ finally
+ {
+ negotiator.deactivate();
+ }
+ }
+ }.start();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.util/META-INF/MANIFEST.MF
index a7eb223..020cc78 100644
--- a/plugins/org.eclipse.net4j.util/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.util/META-INF/MANIFEST.MF
@@ -27,6 +27,7 @@ Export-Package: org.eclipse.net4j.internal.util.cache;version="0.8.0",
org.eclipse.net4j.internal.util.om.pref;version="0.8.0",
org.eclipse.net4j.internal.util.om.trace;version="0.8.0",
org.eclipse.net4j.internal.util.registry;version="0.8.0",
+ org.eclipse.net4j.internal.util.security;version="0.8.0",
org.eclipse.net4j.internal.util.transaction;version="0.8.0",
org.eclipse.net4j.util;version="0.8.0",
org.eclipse.net4j.util.cache;version="0.8.0",
@@ -45,5 +46,6 @@ Export-Package: org.eclipse.net4j.internal.util.cache;version="0.8.0",
org.eclipse.net4j.util.om.pref;version="0.8.0",
org.eclipse.net4j.util.om.trace;version="0.8.0",
org.eclipse.net4j.util.registry;version="0.8.0",
+ org.eclipse.net4j.util.security;version="0.8.0",
org.eclipse.net4j.util.transaction;version="0.8.0"
Eclipse-LazyStart: true
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeNegotiator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeNegotiator.java
new file mode 100644
index 0000000..c41aeb8
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeNegotiator.java
@@ -0,0 +1,179 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.internal.util.security;
+
+import org.eclipse.net4j.internal.util.bundle.OM;
+import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+import org.eclipse.net4j.util.security.IChallengeResponse;
+import org.eclipse.net4j.util.security.IRandomizer;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+/**
+ * @author Eike Stepper
+ */
+public class ChallengeNegotiator extends UserManagerNegotiator implements IChallengeResponse
+{
+ public static final int DEFAULT_TOKEN_LENGTH = 128;
+
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, ChallengeNegotiator.class);
+
+ private int tokenLength = DEFAULT_TOKEN_LENGTH;
+
+ private IRandomizer randomizer;
+
+ private transient byte[] randomToken;
+
+ public ChallengeNegotiator()
+ {
+ super(true);
+ }
+
+ public int getTokenLength()
+ {
+ return tokenLength;
+ }
+
+ public void setTokenLength(int tokenLength)
+ {
+ this.tokenLength = tokenLength;
+ }
+
+ public IRandomizer getRandomizer()
+ {
+ return randomizer;
+ }
+
+ public void setRandomizer(IRandomizer randomizer)
+ {
+ this.randomizer = randomizer;
+ }
+
+ @Override
+ protected int negotiate(int phase, ByteBuffer buffer)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Negotiating phase {0}", phase);
+ }
+
+ switch (phase)
+ {
+ case INITIAL:
+ challenge();
+ return PHASE_RESPONSE;
+
+ case PHASE_RESPONSE:
+ try
+ {
+ if (verifyResponse(buffer))
+ {
+ acknowledge(true);
+ return SUCCESS;
+ }
+ else
+ {
+ return NEED_MORE_BUFFERS;
+ }
+ }
+ catch (SecurityException ex)
+ {
+ acknowledge(false);
+ return FAILURE;
+ }
+
+ case PHASE_ACKNOWLEDGE:
+ break;
+
+ default:
+ break;
+ }
+ return 0;
+ }
+
+ /**
+ * Use {@link #getBuffer()} and {@link #transmitBuffer(ByteBuffer)} to send the challenge.
+ */
+ protected void challenge()
+ {
+ if (TRACER.isEnabled()) TRACER.trace("Transmitting token");
+ randomToken = createRandomToken();
+ ByteBuffer buffer = getBuffer();
+ buffer.putInt(randomToken.length);
+ buffer.put(randomToken);
+ transmitBuffer(buffer);
+ }
+
+ /**
+ * Use the passed <code>ByteBuffer</code> to authenticate the user.
+ *
+ * @return <code>true</code> if authentication was successful, <code>false</code> if more buffers are needed.
+ * @throws SecurityException
+ * if authentication was not successful.
+ */
+ protected boolean verifyResponse(ByteBuffer buffer) throws SecurityException
+ {
+ if (TRACER.isEnabled()) TRACER.trace("Received cryptedToken");
+ int size = buffer.getInt();
+ byte[] cryptedTokenFromClient = new byte[size];
+ buffer.get(cryptedTokenFromClient);
+
+ if (TRACER.isEnabled()) TRACER.trace("Received userID");
+ size = buffer.getInt();
+ byte[] userIDBytes = new byte[size];
+ buffer.get(userIDBytes);
+
+ String userID = new String(userIDBytes);
+ byte[] cryptedToken = encrypt(userID, randomToken);
+
+ if (Arrays.equals(cryptedToken, cryptedTokenFromClient))
+ {
+ return true;
+ }
+
+ throw new SecurityException("User could not be authenticated: " + userID);
+ }
+
+ /**
+ * Use {@link #getBuffer()} and {@link #transmitBuffer(ByteBuffer)} to send the acknowledgement. The default
+ * implementation of this method jsut sends a buffer with <code>(byte)1</code> if <code>success == true</code> or
+ * <code>(byte)0</code> if <code>success == false</code>.
+ */
+ protected void acknowledge(boolean success)
+ {
+ ByteBuffer buffer = getBuffer();
+ buffer.put(success ? ACKNOWLEDGE_SUCCESS : ACKNOWLEDGE_FAILURE);
+ transmitBuffer(buffer);
+ }
+
+ @Override
+ protected void doBeforeActivate() throws Exception
+ {
+ super.doBeforeActivate();
+ if (tokenLength <= 0)
+ {
+ throw new IllegalStateException("tokenLength must be positive");
+ }
+
+ if (randomizer == null)
+ {
+ throw new IllegalStateException("randomizer == null");
+ }
+ }
+
+ protected byte[] createRandomToken()
+ {
+ byte[] token = new byte[tokenLength];
+ randomizer.nextBytes(token);
+ return token;
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/ConnectorCredentials.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Credentials.java
index 7edb50b..010347c 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/ConnectorCredentials.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Credentials.java
@@ -8,18 +8,18 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.internal.net4j;
+package org.eclipse.net4j.internal.util.security;
-import org.eclipse.net4j.IConnectorCredentials;
+import org.eclipse.net4j.util.security.ICredentials;
/**
* @author Eike Stepper
*/
-public class ConnectorCredentials implements IConnectorCredentials
+public class Credentials implements ICredentials
{
private String userID;
- public ConnectorCredentials(String userID)
+ public Credentials(String userID)
{
this.userID = userID;
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/FileUserManager.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/FileUserManager.java
new file mode 100644
index 0000000..bf2c3cf
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/FileUserManager.java
@@ -0,0 +1,134 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.internal.util.security;
+
+import org.eclipse.net4j.util.io.IORuntimeException;
+import org.eclipse.net4j.util.io.IOUtil;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.MessageFormat;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Map.Entry;
+
+/**
+ * @author Eike Stepper
+ */
+public class FileUserManager extends UserManager
+{
+ protected String fileName;
+
+ public FileUserManager()
+ {
+ }
+
+ public String getFileName()
+ {
+ return fileName;
+ }
+
+ public void setFileName(String fileName)
+ {
+ this.fileName = fileName;
+ }
+
+ @Override
+ protected void doBeforeActivate() throws Exception
+ {
+ super.doBeforeActivate();
+ if (fileName == null)
+ {
+ throw new IllegalStateException("fileName == null");
+ }
+
+ File file = new File(fileName);
+ if (file.exists() && !file.isFile())
+ {
+ throw new IllegalStateException("Not a file: " + fileName);
+ }
+ }
+
+ @Override
+ protected void load(Map<String, char[]> users) throws IORuntimeException
+ {
+ File file = new File(fileName);
+ if (!file.exists())
+ {
+ return;
+ }
+
+ FileInputStream stream = IOUtil.openInputStream(new File(fileName));
+ try
+ {
+ load(users, stream);
+ }
+ catch (IOException ex)
+ {
+ throw new IORuntimeException(ex);
+ }
+ finally
+ {
+ IOUtil.closeSilent(stream);
+ }
+ }
+
+ protected void load(Map<String, char[]> users, InputStream stream) throws IOException
+ {
+ Properties properties = new Properties();
+ properties.load(stream);
+ for (Entry<Object, Object> entry : properties.entrySet())
+ {
+ String userID = (String)entry.getKey();
+ char[] password = ((String)entry.getValue()).toCharArray();
+ users.put(userID, password);
+ }
+ }
+
+ @Override
+ protected void save(Map<String, char[]> users) throws IORuntimeException
+ {
+ File file = new File(fileName);
+ if (!file.exists())
+ {
+ return;
+ }
+
+ FileOutputStream stream = IOUtil.openOutputStream(new File(fileName));
+ try
+ {
+ save(users, stream);
+ }
+ catch (IOException ex)
+ {
+ throw new IORuntimeException(ex);
+ }
+ finally
+ {
+ IOUtil.closeSilent(stream);
+ }
+ }
+
+ protected void save(Map<String, char[]> users, FileOutputStream stream) throws IOException
+ {
+ Properties properties = new Properties();
+ for (Entry<String, char[]> entry : users.entrySet())
+ {
+ properties.put(entry.getKey(), new String(entry.getValue()));
+ }
+
+ String comment = MessageFormat.format("User database {0,date} {0,time}", System.currentTimeMillis());
+ properties.store(stream, comment);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/NegotiationContext.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/NegotiationContext.java
new file mode 100644
index 0000000..3048a5f
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/NegotiationContext.java
@@ -0,0 +1,95 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.internal.util.security;
+
+import org.eclipse.net4j.util.security.IBufferReceiver;
+import org.eclipse.net4j.util.security.INegotiationContext;
+
+import java.nio.ByteBuffer;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class NegotiationContext implements INegotiationContext
+{
+ private IBufferReceiver bufferReceiver;
+
+ private State state = State.ONGOING;
+
+ private CountDownLatch ongoingLatch = new CountDownLatch(1);
+
+ public NegotiationContext()
+ {
+ }
+
+ public IBufferReceiver getBufferReceiver()
+ {
+ return bufferReceiver;
+ }
+
+ public void setBufferReceiver(IBufferReceiver bufferReceiver)
+ {
+ this.bufferReceiver = bufferReceiver;
+ }
+
+ public State getState()
+ {
+ return state;
+ }
+
+ public ByteBuffer getBuffer()
+ {
+ return ByteBuffer.allocateDirect(4096);
+ }
+
+ public void negotiationSuccess()
+ {
+ state = State.SUCCESS;
+ ongoingLatch.countDown();
+ }
+
+ public void negotiationFailure()
+ {
+ state = State.FAILURE;
+ ongoingLatch.countDown();
+ }
+
+ public State waitForResult(long timeout)
+ {
+ try
+ {
+ if (timeout == -1)
+ {
+ ongoingLatch.await();
+ }
+ else
+ {
+ ongoingLatch.await(timeout, TimeUnit.MILLISECONDS);
+ }
+ }
+ catch (InterruptedException ex)
+ {
+ state = State.INTERRUPTED;
+ }
+
+ return state;
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static enum State
+ {
+ ONGOING, SUCCESS, FAILURE, INTERRUPTED;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Negotiator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Negotiator.java
new file mode 100644
index 0000000..68cfe01
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Negotiator.java
@@ -0,0 +1,118 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.internal.util.security;
+
+import org.eclipse.net4j.internal.util.lifecycle.Lifecycle;
+import org.eclipse.net4j.util.security.IBufferReceiver;
+import org.eclipse.net4j.util.security.INegotiationContext;
+import org.eclipse.net4j.util.security.INegotiator;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class Negotiator extends Lifecycle implements INegotiator, IBufferReceiver
+{
+ public static final int INITIAL = 0;
+
+ public static final int SUCCESS = -1;
+
+ public static final int FAILURE = -2;
+
+ public static final int NEED_MORE_BUFFERS = -3;
+
+ private int phase = INITIAL;
+
+ private boolean initiator;
+
+ private INegotiationContext context;
+
+ public Negotiator(boolean initiator)
+ {
+ this.initiator = initiator;
+ }
+
+ public int getPhase()
+ {
+ return phase;
+ }
+
+ public boolean isInitiator()
+ {
+ return initiator;
+ }
+
+ public void startNegotiation(INegotiationContext context)
+ {
+ this.context = context;
+ context.setBufferReceiver(this);
+ if (initiator)
+ {
+ doNegotiation(null);
+ }
+ }
+
+ public void receiveBuffer(ByteBuffer buffer)
+ {
+ checkContext();
+
+ try
+ {
+ doNegotiation(buffer);
+ }
+ catch (SecurityException ex)
+ {
+ context.negotiationFailure();
+ }
+ }
+
+ protected void doNegotiation(ByteBuffer buffer)
+ {
+ int result = negotiate(phase, buffer);
+ switch (result)
+ {
+ case SUCCESS:
+ context.negotiationSuccess();
+ break;
+ case FAILURE:
+ context.negotiationSuccess();
+ break;
+ case NEED_MORE_BUFFERS:
+ break;
+ default:
+ phase = result;
+ break;
+ }
+ }
+
+ protected abstract int negotiate(int phase, ByteBuffer buffer);
+
+ protected ByteBuffer getBuffer()
+ {
+ checkContext();
+ return context.getBuffer();
+ }
+
+ protected void transmitBuffer(ByteBuffer buffer)
+ {
+ checkContext();
+ context.transmitBuffer(buffer);
+ }
+
+ private void checkContext()
+ {
+ if (context == null)
+ {
+ throw new IllegalStateException("context == null");
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/IConnectorNegotiator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/PasswordCredentials.java
index c2136fe..4b8995f 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/IConnectorNegotiator.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/PasswordCredentials.java
@@ -8,19 +8,28 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j;
+package org.eclipse.net4j.internal.util.security;
/**
- * Provides the ability to execute a negotitation phase between two connectors.
- *
* @author Eike Stepper
*/
-public interface IConnectorNegotiator
+public class PasswordCredentials extends Credentials
{
- /**
- * Executes the negotitation phase between the given connector and ts peer connector.
- *
- * @return <code>true</code> if the negotiation succeeded, <code>false</code> otherwise.
- */
- public boolean negotiate(IConnector connector);
+ private char[] password;
+
+ public PasswordCredentials(String userID, char[] password)
+ {
+ super(userID);
+ this.password = password;
+ }
+
+ public char[] getPassword()
+ {
+ return password;
+ }
+
+ public void setPassword(char[] password)
+ {
+ this.password = password;
+ }
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Randomizer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Randomizer.java
new file mode 100644
index 0000000..058f29b
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Randomizer.java
@@ -0,0 +1,145 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.internal.util.security;
+
+import org.eclipse.net4j.internal.util.lifecycle.Lifecycle;
+import org.eclipse.net4j.util.security.IRandomizer;
+
+import java.security.SecureRandom;
+
+/**
+ * @author Eike Stepper
+ */
+public class Randomizer extends Lifecycle implements IRandomizer
+{
+ public static final String ALGORITHM_SHA1PRNG = "SHA1PRNG";
+
+ public static final String DEFAULT_ALGORITHM_NAME = ALGORITHM_SHA1PRNG;
+
+ private String algorithmName = DEFAULT_ALGORITHM_NAME;
+
+ private String providerName;
+
+ private transient SecureRandom secureRandom;
+
+ public String getAlgorithmName()
+ {
+ return algorithmName;
+ }
+
+ public void setAlgorithmName(String algorithmName)
+ {
+ this.algorithmName = algorithmName;
+ }
+
+ public String getProviderName()
+ {
+ return providerName;
+ }
+
+ public void setProviderName(String providerName)
+ {
+ this.providerName = providerName;
+ }
+
+ public boolean nextBoolean()
+ {
+ return secureRandom.nextBoolean();
+ }
+
+ public double nextDouble()
+ {
+ return secureRandom.nextDouble();
+ }
+
+ public float nextFloat()
+ {
+ return secureRandom.nextFloat();
+ }
+
+ public synchronized double nextGaussian()
+ {
+ return secureRandom.nextGaussian();
+ }
+
+ public int nextInt()
+ {
+ return secureRandom.nextInt();
+ }
+
+ public int nextInt(int n)
+ {
+ return secureRandom.nextInt(n);
+ }
+
+ public long nextLong()
+ {
+ return secureRandom.nextLong();
+ }
+
+ public byte[] generateSeed(int numBytes)
+ {
+ return secureRandom.generateSeed(numBytes);
+ }
+
+ public String getAlgorithm()
+ {
+ return secureRandom.getAlgorithm();
+ }
+
+ public synchronized void nextBytes(byte[] bytes)
+ {
+ secureRandom.nextBytes(bytes);
+ }
+
+ public synchronized void setSeed(byte[] seed)
+ {
+ secureRandom.setSeed(seed);
+ }
+
+ public void setSeed(long seed)
+ {
+ secureRandom.setSeed(seed);
+ }
+
+ @Override
+ protected void doBeforeActivate() throws Exception
+ {
+ super.doBeforeActivate();
+ if (algorithmName == null)
+ {
+ throw new IllegalStateException("algorithmName == null");
+ }
+ }
+
+ @Override
+ protected void doActivate() throws Exception
+ {
+ super.doActivate();
+ if (providerName == null)
+ {
+ secureRandom = SecureRandom.getInstance(algorithmName);
+ }
+ else
+ {
+ secureRandom = SecureRandom.getInstance(algorithmName, providerName);
+ }
+
+ secureRandom.setSeed(System.currentTimeMillis());
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ secureRandom = null;
+ super.doDeactivate();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ResponseNegotiator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ResponseNegotiator.java
new file mode 100644
index 0000000..80d4160
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ResponseNegotiator.java
@@ -0,0 +1,77 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.internal.util.security;
+
+import org.eclipse.net4j.internal.util.bundle.OM;
+import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+import org.eclipse.net4j.util.security.IChallengeResponse;
+import org.eclipse.net4j.util.security.ICredentialsProvider;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Eike Stepper
+ */
+public class ResponseNegotiator extends UserManagerNegotiator implements IChallengeResponse
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, ResponseNegotiator.class);
+
+ private ICredentialsProvider credentialsProvider;
+
+ public ResponseNegotiator()
+ {
+ super(false);
+ }
+
+ public ICredentialsProvider getCredentialsProvider()
+ {
+ return credentialsProvider;
+ }
+
+ public void setCredentialsProvider(ICredentialsProvider credentialsProvider)
+ {
+ this.credentialsProvider = credentialsProvider;
+ }
+
+ @Override
+ protected int negotiate(int phase, ByteBuffer buffer)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Negotiating phase {0}", phase);
+ }
+
+ switch (phase)
+ {
+ case INITIAL:
+ return PHASE_RESPONSE;
+
+ case PHASE_RESPONSE:
+ case PHASE_ACKNOWLEDGE:
+ break;
+
+ default:
+ break;
+ }
+
+ return 0;
+ }
+
+ @Override
+ protected void doBeforeActivate() throws Exception
+ {
+ super.doBeforeActivate();
+ if (credentialsProvider == null)
+ {
+ throw new IllegalStateException("credentialsProvider == null");
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/UserManager.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/UserManager.java
new file mode 100644
index 0000000..cca3c0b
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/UserManager.java
@@ -0,0 +1,95 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.internal.util.security;
+
+import org.eclipse.net4j.internal.util.lifecycle.Lifecycle;
+import org.eclipse.net4j.util.io.IORuntimeException;
+import org.eclipse.net4j.util.security.IUserManager;
+import org.eclipse.net4j.util.security.SecurityUtil;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class UserManager extends Lifecycle implements IUserManager
+{
+ // Transient to prevent from logging
+ protected transient Map<String, char[]> users = new HashMap<String, char[]>();
+
+ public UserManager()
+ {
+ }
+
+ public synchronized void addUser(String userID, char[] password)
+ {
+ users.put(userID, password);
+ save(users);
+ }
+
+ public synchronized void removeUser(String userID)
+ {
+ if (users.remove(userID) != null)
+ {
+ save(users);
+ }
+ }
+
+ public byte[] encrypt(String userID, byte[] data, String algorithmName) throws SecurityException
+ {
+ char[] password;
+ synchronized (this)
+ {
+ password = users.get(userID);
+ }
+
+ if (password == null)
+ {
+ throw new SecurityException("No such user: " + userID);
+ }
+
+ try
+ {
+ return SecurityUtil.encrypt(data, password, algorithmName);
+ }
+ catch (RuntimeException ex)
+ {
+ throw ex;
+ }
+ catch (Exception ex)
+ {
+ throw new SecurityException(ex);
+ }
+ }
+
+ @Override
+ protected void doActivate() throws Exception
+ {
+ super.doActivate();
+ load(users);
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ users.clear();
+ super.doDeactivate();
+ }
+
+ protected void load(Map<String, char[]> users) throws IORuntimeException
+ {
+ }
+
+ protected void save(Map<String, char[]> users) throws IORuntimeException
+ {
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/UserManagerNegotiator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/UserManagerNegotiator.java
new file mode 100644
index 0000000..5fa6b00
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/UserManagerNegotiator.java
@@ -0,0 +1,71 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.internal.util.security;
+
+import org.eclipse.net4j.util.security.IUserManager;
+import org.eclipse.net4j.util.security.SecurityUtil;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class UserManagerNegotiator extends Negotiator
+{
+ public static final String DEFAULT_ALGORITHM_NAME = SecurityUtil.PBE_WITH_MD5_AND_DES;
+
+ private String algorithmName = DEFAULT_ALGORITHM_NAME;
+
+ private IUserManager userManager;
+
+ public UserManagerNegotiator(boolean starter)
+ {
+ super(starter);
+ }
+
+ public String getAlgorithmName()
+ {
+ return algorithmName;
+ }
+
+ public void setAlgorithmName(String algorithmName)
+ {
+ this.algorithmName = algorithmName;
+ }
+
+ public IUserManager getUserManager()
+ {
+ return userManager;
+ }
+
+ public void setUserManager(IUserManager userManager)
+ {
+ this.userManager = userManager;
+ }
+
+ protected byte[] encrypt(String userID, byte[] data) throws SecurityException
+ {
+ return userManager.encrypt(userID, data, algorithmName);
+ }
+
+ @Override
+ protected void doBeforeActivate() throws Exception
+ {
+ super.doBeforeActivate();
+ if (algorithmName == null)
+ {
+ throw new IllegalStateException("algorithmName == null");
+ }
+
+ if (userManager == null)
+ {
+ throw new IllegalStateException("userManager == null");
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/IBufferReceiver.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/IBufferReceiver.java
new file mode 100644
index 0000000..b2b95bb
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/IBufferReceiver.java
@@ -0,0 +1,21 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.security;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IBufferReceiver
+{
+ public void receiveBuffer(ByteBuffer buffer);
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/IChallengeResponse.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/IChallengeResponse.java
new file mode 100644
index 0000000..8ada22e
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/IChallengeResponse.java
@@ -0,0 +1,27 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.security;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IChallengeResponse
+{
+ public static final int PHASE_CHALLENGE = 1;
+
+ public static final int PHASE_RESPONSE = 2;
+
+ public static final int PHASE_ACKNOWLEDGE = 3;
+
+ public static final byte ACKNOWLEDGE_SUCCESS = 1;
+
+ public static final byte ACKNOWLEDGE_FAILURE = 0;
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/IConnectorCredentials.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/ICredentials.java
index 99d0a08..6378621 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/IConnectorCredentials.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/ICredentials.java
@@ -8,15 +8,12 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j;
+package org.eclipse.net4j.util.security;
/**
* @author Eike Stepper
*/
-public interface IConnectorCredentials
+public interface ICredentials
{
- /**
- * Returns the userID of this connector.
- */
public String getUserID();
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/ICredentialsProvider.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/ICredentialsProvider.java
new file mode 100644
index 0000000..6990167
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/ICredentialsProvider.java
@@ -0,0 +1,19 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.security;
+
+/**
+ * @author Eike Stepper
+ */
+public interface ICredentialsProvider
+{
+ public ICredentials getCredentials();
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/INegotiationContext.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/INegotiationContext.java
new file mode 100644
index 0000000..2f785bc
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/INegotiationContext.java
@@ -0,0 +1,29 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.security;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Eike Stepper
+ */
+public interface INegotiationContext
+{
+ public ByteBuffer getBuffer();
+
+ public void transmitBuffer(ByteBuffer buffer);
+
+ public void setBufferReceiver(IBufferReceiver receiver);
+
+ public void negotiationSuccess();
+
+ public void negotiationFailure();
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/INegotiator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/INegotiator.java
new file mode 100644
index 0000000..eada3f0
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/INegotiator.java
@@ -0,0 +1,19 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.security;
+
+/**
+ * @author Eike Stepper
+ */
+public interface INegotiator
+{
+ public void startNegotiation(INegotiationContext context);
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/IRandomizer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/IRandomizer.java
new file mode 100644
index 0000000..b775d3c
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/IRandomizer.java
@@ -0,0 +1,35 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.security;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IRandomizer
+{
+ public boolean nextBoolean();
+
+ public double nextDouble();
+
+ public float nextFloat();
+
+ public double nextGaussian();
+
+ public int nextInt();
+
+ public int nextInt(int n);
+
+ public long nextLong();
+
+ public byte[] generateSeed(int numBytes);
+
+ public void nextBytes(byte[] bytes);
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/IUserManager.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/IUserManager.java
new file mode 100644
index 0000000..ef45d96
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/IUserManager.java
@@ -0,0 +1,23 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.security;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IUserManager
+{
+ public void addUser(String userID, char[] password);
+
+ public void removeUser(String userID);
+
+ public byte[] encrypt(String userID, byte[] data, String algorithmName) throws SecurityException;
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/SecurityUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/SecurityUtil.java
new file mode 100644
index 0000000..61246d3
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/SecurityUtil.java
@@ -0,0 +1,64 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.security;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.PBEKeySpec;
+import javax.crypto.spec.PBEParameterSpec;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.spec.InvalidKeySpecException;
+
+
+/**
+ * @author Eike Stepper
+ */
+public final class SecurityUtil
+{
+ public static final String PBE_WITH_MD5_AND_DES = "PBEWithMD5AndDES";
+
+ private SecurityUtil()
+ {
+ }
+
+ public static byte[] encrypt(byte[] data, char[] password, String algorithmName) throws NoSuchAlgorithmException,
+ InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException,
+ IllegalBlockSizeException, BadPaddingException
+ {
+ // Salt
+ final byte[] salt = { (byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c, (byte)0x7e, (byte)0xc8, (byte)0xee,
+ (byte)0x99 }; // TODO Make configurable
+
+ // Iteration count
+ final int count = 20; // TODO Make configurable
+
+ // Create PBE parameter set
+ PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, count);
+ PBEKeySpec pbeKeySpec = new PBEKeySpec(password);
+ SecretKeyFactory keyFac = SecretKeyFactory.getInstance(algorithmName);
+ SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
+
+ // Create PBE Cipher
+ Cipher pbeCipher = Cipher.getInstance(algorithmName);
+
+ // Initialize PBE Cipher with key and parameters
+ pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
+
+ return pbeCipher.doFinal(data);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Connector.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Connector.java
index 3be9ff4..c31ed6c 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Connector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Connector.java
@@ -17,7 +17,6 @@ import org.eclipse.net4j.IBuffer;
import org.eclipse.net4j.IBufferProvider;
import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.IConnector;
-import org.eclipse.net4j.IConnectorCredentials;
import org.eclipse.net4j.IConnectorStateEvent;
import org.eclipse.net4j.IProtocol;
import org.eclipse.net4j.internal.util.container.Container;
@@ -59,8 +58,6 @@ public abstract class Connector extends Container<IChannel> implements IConnecto
private String userID;
- private IConnectorCredentials credentials;
-
private IRegistry<IFactoryKey, IFactory> protocolFactoryRegistry;
private List<IElementProcessor> protocolPostProcessors;
@@ -164,16 +161,6 @@ public abstract class Connector extends Container<IChannel> implements IConnecto
this.userID = userID;
}
- public IConnectorCredentials getCredentials()
- {
- return credentials;
- }
-
- public void setCredentials(IConnectorCredentials credentials)
- {
- this.credentials = credentials;
- }
-
public ConnectorState getState()
{
return connectorState;
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/IConnector.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/IConnector.java
index cede42f..c2076d2 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/IConnector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/IConnector.java
@@ -73,17 +73,10 @@ public interface IConnector extends IContainer<IChannel>
/**
* Returns the userID of this connector.
- * <p>
- * Same as <code>{@link #getCredentials()}.{@link IConnectorCredentials#getUserID() getUserID()}</code>.
*/
public String getUserID();
/**
- * Returns the credentials of this connector.
- */
- public IConnectorCredentials getCredentials();
-
- /**
* Returns the factory registry used by this connector to lookup factories that can create {@link IProtocol}s for
* newly opened {@link IChannel}s.
* <p>