changes to Base64 (sun --> apache codec)

This commit is contained in:
Dave
2015-01-06 18:59:34 +02:00
parent 2d754af0c2
commit 2f71b567a8
4 changed files with 12 additions and 17 deletions

BIN
lib/commons-codec-1.10.jar Normal file

Binary file not shown.

View File

@@ -50,18 +50,15 @@ public final class NoCore {
public static void setup(NoConfigInterface config, NoHashSphereInterface hashSphere) { public static void setup(NoConfigInterface config, NoHashSphereInterface hashSphere) {
NoCore.setup(config); NoCore.setup(config);
NoCore.setup(hashSphere); NoCore.setup(hashSphere);
com.sun.org.apache.xml.internal.security.Init.init();
} }
public static void setup(NoConfigInterface config) { public static void setup(NoConfigInterface config) {
NoCore.config = config; NoCore.config = config;
com.sun.org.apache.xml.internal.security.Init.init();
} }
public static void setup(NoHashSphereInterface hashSphere) { public static void setup(NoHashSphereInterface hashSphere) {
NoCore.hashSphere = hashSphere; NoCore.hashSphere = hashSphere;
hashSphere.setup(); hashSphere.setup();
com.sun.org.apache.xml.internal.security.Init.init();
} }
public static void setup() { public static void setup() {
@@ -73,7 +70,6 @@ public final class NoCore {
} }
NoCore.setup(newConfig); NoCore.setup(newConfig);
NoCore.setup(new NoHashSphereDefault()); NoCore.setup(new NoHashSphereDefault());
com.sun.org.apache.xml.internal.security.Init.init();
} }
public static byte[] login(byte[] data, char[] password) throws NoUserNotValidException, NoUserAlreadyOnlineException, NoSessionExpiredException { public static byte[] login(byte[] data, char[] password) throws NoUserNotValidException, NoUserAlreadyOnlineException, NoSessionExpiredException {

View File

@@ -24,6 +24,8 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.codec.binary.Base64;
import nodash.core.NoRegister; import nodash.core.NoRegister;
import nodash.exceptions.NoByteSetBadDecryptionException; import nodash.exceptions.NoByteSetBadDecryptionException;
import nodash.exceptions.NoDashFatalException; import nodash.exceptions.NoDashFatalException;
@@ -42,7 +44,7 @@ import nodash.models.NoSession.NoState;
public final class NoSessionSphere { public final class NoSessionSphere {
private static ConcurrentHashMap<UUID, NoSession> sessions = new ConcurrentHashMap<UUID, NoSession>(); private static ConcurrentHashMap<UUID, NoSession> sessions = new ConcurrentHashMap<UUID, NoSession>();
private static Set<byte[]> originalHashesOnline = Collections.newSetFromMap(new ConcurrentHashMap<byte[], Boolean>()); private static Set<String> originalHashesOnline = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
public static synchronized void prune() { public static synchronized void prune() {
for (UUID uuid : NoSessionSphere.sessions.keySet()) { for (UUID uuid : NoSessionSphere.sessions.keySet()) {
@@ -56,7 +58,7 @@ public final class NoSessionSphere {
if (NoSessionSphere.sessions.containsKey(uuid)) { if (NoSessionSphere.sessions.containsKey(uuid)) {
NoSession session = NoSessionSphere.sessions.get(uuid); NoSession session = NoSessionSphere.sessions.get(uuid);
NoByteSetSphere.addList(session.incoming, session.current.getRSAPublicKey()); NoByteSetSphere.addList(session.incoming, session.current.getRSAPublicKey());
NoSessionSphere.originalHashesOnline.remove(session.getOriginalHash()); NoSessionSphere.originalHashesOnline.remove(Base64.encodeBase64String(session.getOriginalHash()));
NoSessionSphere.sessions.remove(uuid); NoSessionSphere.sessions.remove(uuid);
session = null; session = null;
} }
@@ -84,11 +86,11 @@ public final class NoSessionSphere {
/* 1. Login with byte[] data and byte[] password */ /* 1. Login with byte[] data and byte[] password */
NoSession session = new NoSession(data, password); NoSession session = new NoSession(data, password);
/* 1.1. User currently has an online session, must wait for it to expire. */ /* 1.1. User currently has an online session, must wait for it to expire. */
if (originalHashesOnline.contains(session.getOriginalHash())) { if (originalHashesOnline.contains(Base64.encodeBase64String(session.getOriginalHash()))) {
throw new NoUserAlreadyOnlineException(); throw new NoUserAlreadyOnlineException();
} }
/* 1.2. User successfully logged in: set up session records. */ /* 1.2. User successfully logged in: set up session records. */
NoSessionSphere.originalHashesOnline.add(session.getOriginalHash()); NoSessionSphere.originalHashesOnline.add(Base64.encodeBase64String(session.getOriginalHash()));
NoSessionSphere.sessions.put(session.uuid, session); NoSessionSphere.sessions.put(session.uuid, session);
/* 2. Check NoByteSetSphere for incoming Influences */ /* 2. Check NoByteSetSphere for incoming Influences */

View File

@@ -8,8 +8,7 @@ import java.util.UUID;
import javax.crypto.BadPaddingException; import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException; import javax.crypto.IllegalBlockSizeException;
import com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException; import org.apache.commons.codec.binary.Base64;
import com.sun.org.apache.xml.internal.security.utils.Base64;
import nodash.core.NoCore; import nodash.core.NoCore;
import nodash.core.NoUtil; import nodash.core.NoUtil;
@@ -188,11 +187,7 @@ public final class NoSession implements Serializable {
} }
public byte[] getEncryptedUUID() { public byte[] getEncryptedUUID() {
try { return NoUtil.encrypt(Base64.encodeBase64(this.uuid.toString().getBytes()));
return NoUtil.encrypt(Base64.decode(this.uuid.toString()));
} catch (Base64DecodingException e) {
throw new NoDashFatalException("Base64DecodingException while decoding session UUID.", e);
}
} }
public String getEncryptedUUIDAsString() { public String getEncryptedUUIDAsString() {
@@ -213,7 +208,9 @@ public final class NoSession implements Serializable {
} }
try { try {
return UUID.fromString(new String(NoUtil.decrypt(data))); return UUID.fromString(new String(Base64.decodeBase64(NoUtil.decrypt(data))));
} catch (IllegalArgumentException e) {
throw new NoDashSessionBadUUIDException();
}catch (IllegalBlockSizeException e) { }catch (IllegalBlockSizeException e) {
throw new NoDashSessionBadUUIDException(); throw new NoDashSessionBadUUIDException();
} catch (BadPaddingException e) { } catch (BadPaddingException e) {