massive changes
- Changed NoCore to a non-static object - Cut out all spheres in favour of a NoAdapter interface - Added basic NoDefaultAdapter object, should be overridden in prod uses
This commit is contained in:
41
src/nodash/core/NoAdapter.java
Normal file
41
src/nodash/core/NoAdapter.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package nodash.core;
|
||||
|
||||
import java.security.PublicKey;
|
||||
import java.util.Collection;
|
||||
|
||||
import nodash.core.exceptions.NoAdapterException;
|
||||
import nodash.exceptions.NoUserAlreadyOnlineException;
|
||||
import nodash.exceptions.NoUserNotValidException;
|
||||
import nodash.models.NoByteSet;
|
||||
import nodash.models.NoSession;
|
||||
|
||||
public interface NoAdapter {
|
||||
public void insertHash(byte[] hash) throws NoAdapterException;
|
||||
|
||||
public void removeHash(byte[] hash) throws NoAdapterException;
|
||||
|
||||
public void checkHash(byte[] hash) throws NoAdapterException, NoUserNotValidException;
|
||||
|
||||
public byte[][] exportHashes() throws NoAdapterException;
|
||||
|
||||
public long hashCount() throws NoAdapterException;
|
||||
|
||||
public void goOnline(byte[] hash) throws NoAdapterException, NoUserAlreadyOnlineException;
|
||||
|
||||
public boolean isOnline(byte[] hash) throws NoAdapterException;
|
||||
|
||||
public void goOffline(byte[] hash) throws NoAdapterException;
|
||||
|
||||
public void addNoSession(NoSession session) throws NoAdapterException;
|
||||
|
||||
public boolean containsNoSession(byte[] encryptedUuid) throws NoAdapterException;
|
||||
|
||||
public void shredNoSession(byte[] encryptedUuid) throws NoAdapterException;
|
||||
|
||||
public NoSession getNoSession(byte[] encryptedUuid) throws NoAdapterException;
|
||||
|
||||
public Collection<NoByteSet> pollNoByteSets(PublicKey address) throws NoAdapterException;
|
||||
|
||||
public void addNoByteSets(Collection<NoByteSet> noByteSets, PublicKey address)
|
||||
throws NoAdapterException;
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package nodash.core;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
import nodash.exceptions.NoDashFatalException;
|
||||
|
||||
public abstract class NoConfigBase implements NoConfigInterface {
|
||||
protected boolean ready;
|
||||
protected SecretKey secretKey;
|
||||
protected boolean saveDatabase;
|
||||
protected boolean saveByteSets;
|
||||
|
||||
protected final void generateSecretKey() {
|
||||
try {
|
||||
KeyGenerator keyGenerator = KeyGenerator.getInstance(NoUtil.CIPHER_KEY_SPEC);
|
||||
keyGenerator.init(NoUtil.AES_STRENGTH);
|
||||
this.secretKey = keyGenerator.generateKey();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new NoDashFatalException("Value for CIPHER_KEY_SPEC not valid.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void construct() {
|
||||
this.generateSecretKey();
|
||||
this.ready = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SecretKey getSecretKey() {
|
||||
return this.secretKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveDatabase() {
|
||||
return this.saveDatabase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveByteSets() {
|
||||
return this.saveByteSets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void saveNoConfig();
|
||||
|
||||
@Override
|
||||
public abstract NoConfigInterface loadNoConfig() throws IOException;
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 David Horscroft
|
||||
*
|
||||
* Licensed 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.
|
||||
*
|
||||
* The NoConfig is a means to store the server secret key, database address and other configs.
|
||||
*/
|
||||
|
||||
package nodash.core;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
|
||||
import nodash.exceptions.NoDashFatalException;
|
||||
|
||||
public final class NoConfigDefault extends NoConfigBase implements NoConfigInterface, Serializable {
|
||||
private static final long serialVersionUID = -8498303909736017075L;
|
||||
|
||||
private static final String CONFIG_FILENAME = "noconfig.cfg";
|
||||
|
||||
private String databaseFileName = "nodatabase.hash";
|
||||
|
||||
@Override
|
||||
public boolean saveDatabase() {
|
||||
return saveDatabase;
|
||||
}
|
||||
|
||||
public String getDatabaseName() {
|
||||
return databaseFileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveByteSets() {
|
||||
return saveByteSets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveNoConfig() {
|
||||
try {
|
||||
File file = new File(NoConfigDefault.CONFIG_FILENAME);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(this);
|
||||
byte[] data = baos.toByteArray();
|
||||
|
||||
Files.write(file.toPath(), data, StandardOpenOption.CREATE_NEW);
|
||||
} catch (IOException e) {
|
||||
throw new NoDashFatalException("Unable to save config, including generated secret key.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoConfigInterface loadNoConfig() throws IOException {
|
||||
File file = new File(NoConfigDefault.CONFIG_FILENAME);
|
||||
byte[] data = Files.readAllBytes(file.toPath());
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
NoConfigInterface noConfig;
|
||||
try {
|
||||
noConfig = (NoConfigDefault) ois.readObject();
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new NoDashFatalException(
|
||||
"Given bytestream does not compile into a configuration object.", e);
|
||||
}
|
||||
this.ready = true;
|
||||
return noConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReady() {
|
||||
return this.ready;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package nodash.core;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
public interface NoConfigInterface {
|
||||
public void construct();
|
||||
|
||||
public SecretKey getSecretKey();
|
||||
|
||||
public boolean saveDatabase();
|
||||
|
||||
public boolean saveByteSets();
|
||||
|
||||
public void saveNoConfig();
|
||||
|
||||
public NoConfigInterface loadNoConfig() throws IOException;
|
||||
|
||||
public boolean isReady();
|
||||
}
|
||||
@@ -17,14 +17,9 @@
|
||||
|
||||
package nodash.core;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.PublicKey;
|
||||
|
||||
import nodash.core.spheres.NoByteSetSphere;
|
||||
import nodash.core.spheres.NoHashSphereDefault;
|
||||
import nodash.core.spheres.NoHashSphereInterface;
|
||||
import nodash.core.spheres.NoSessionSphere;
|
||||
import nodash.exceptions.NoDashSessionBadUUIDException;
|
||||
import nodash.core.exceptions.NoAdapterException;
|
||||
import nodash.exceptions.NoByteSetBadDecryptionException;
|
||||
import nodash.exceptions.NoDashFatalException;
|
||||
import nodash.exceptions.NoSessionAlreadyAwaitingConfirmationException;
|
||||
import nodash.exceptions.NoSessionConfirmedException;
|
||||
import nodash.exceptions.NoSessionExpiredException;
|
||||
@@ -33,98 +28,198 @@ import nodash.exceptions.NoSessionNotChangedException;
|
||||
import nodash.exceptions.NoUserAlreadyOnlineException;
|
||||
import nodash.exceptions.NoUserNotValidException;
|
||||
import nodash.models.NoByteSet;
|
||||
import nodash.models.NoSession;
|
||||
import nodash.models.NoUser;
|
||||
import nodash.models.NoSession.NoState;
|
||||
|
||||
public final class NoCore {
|
||||
public static NoConfigInterface config;
|
||||
public static NoHashSphereInterface hashSphere;
|
||||
private NoAdapter adapter;
|
||||
|
||||
public static boolean isReady() {
|
||||
return (config != null && config.isReady()) && (hashSphere != null && hashSphere.isReady());
|
||||
public NoCore(NoAdapter adapter) {
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
public static void setup(NoConfigInterface config, NoHashSphereInterface hashSphere) {
|
||||
NoCore.setup(config);
|
||||
NoCore.setup(hashSphere);
|
||||
}
|
||||
|
||||
public static void setup(NoConfigInterface config) {
|
||||
NoCore.config = config;
|
||||
}
|
||||
|
||||
public static void setup(NoHashSphereInterface hashSphere) {
|
||||
NoCore.hashSphere = hashSphere;
|
||||
hashSphere.setup();
|
||||
}
|
||||
|
||||
public static void setup() {
|
||||
NoConfigInterface newConfig = new NoConfigDefault();
|
||||
private NoSession getNoSession(byte[] cookie) throws NoSessionExpiredException {
|
||||
boolean containsSession;
|
||||
try {
|
||||
newConfig = newConfig.loadNoConfig();
|
||||
} catch (IOException e) {
|
||||
newConfig.construct();
|
||||
containsSession = adapter.containsNoSession(cookie);
|
||||
} catch (NoAdapterException e) {
|
||||
throw new NoDashFatalException("Could not verify existence of session.", e);
|
||||
}
|
||||
NoCore.setup(newConfig);
|
||||
NoCore.setup(new NoHashSphereDefault());
|
||||
|
||||
if (containsSession) {
|
||||
try {
|
||||
return adapter.getNoSession(cookie);
|
||||
} catch (NoAdapterException e) {
|
||||
throw new NoDashFatalException("Could not get session.", e);
|
||||
}
|
||||
}
|
||||
throw new NoSessionExpiredException();
|
||||
}
|
||||
|
||||
public static byte[] login(byte[] data, char[] password) throws NoUserNotValidException,
|
||||
public byte[] login(byte[] data, char[] password) throws NoUserNotValidException,
|
||||
NoUserAlreadyOnlineException, NoSessionExpiredException {
|
||||
/* steps 1 through to pre-3 */
|
||||
return NoSessionSphere.login(data, password);
|
||||
NoSession session = new NoSession(adapter, data, password);
|
||||
|
||||
/* 1. Check that user is a valid user of the system based on their hash. */
|
||||
try {
|
||||
adapter.checkHash(session.getOriginalHash());
|
||||
} catch (NoAdapterException e) {
|
||||
throw new NoDashFatalException("Unable to verify user.");
|
||||
}
|
||||
|
||||
/* 2. Attempt to set user to online (avoid two of the same account online at the same time) */
|
||||
try {
|
||||
adapter.goOnline(session.getOriginalHash());
|
||||
} catch (NoAdapterException e) {
|
||||
throw new NoDashFatalException("Could not mark user as online.", e);
|
||||
}
|
||||
|
||||
/* 3. Add the session to the live session pool. */
|
||||
try {
|
||||
adapter.addNoSession(session);
|
||||
} catch (NoAdapterException e) {
|
||||
throw new NoDashFatalException("Could not add the session.", e);
|
||||
}
|
||||
|
||||
/* 4. Transfer any incoming NoByteSets to session. */
|
||||
try {
|
||||
session.setIncoming(adapter.pollNoByteSets(session.getNoUserSafe().getRsaPublicKey()));
|
||||
} catch (NoAdapterException e) {
|
||||
throw new NoDashFatalException("Could not get incoming byte sets.", e);
|
||||
}
|
||||
|
||||
/* 5. Apply any incoming ByteSets to the session. */
|
||||
for (NoByteSet byteSet : session.getIncomingSafe()) {
|
||||
try {
|
||||
session.consume(byteSet);
|
||||
} catch (NoByteSetBadDecryptionException e) {
|
||||
throw new NoDashFatalException("Bad byte sets on consumption.", e);
|
||||
} catch (NoSessionConfirmedException e) {
|
||||
throw new NoDashFatalException("NoSession is confirmed despite being newly created.");
|
||||
} finally {
|
||||
try {
|
||||
adapter.addNoByteSets(session.getIncomingSafe(), session.getNoUserSafe()
|
||||
.getRsaPublicKey());
|
||||
} catch (NoAdapterException e) {
|
||||
throw new NoDashFatalException("Could not return failed byte sets to pool.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 6. Check the session to see if the incoming actions have modified it at all. */
|
||||
try {
|
||||
session.check();
|
||||
} catch (NoSessionConfirmedException e) {
|
||||
throw new NoDashFatalException("NoSession is confirmed despite being newly created.");
|
||||
}
|
||||
|
||||
return session.getEncryptedUuid();
|
||||
}
|
||||
|
||||
public static NoRegister register(NoUser user, char[] password) {
|
||||
/* Straight to step 4 */
|
||||
return NoSessionSphere.registerUser(user, password);
|
||||
public NoRegister register(NoUser user, char[] password) {
|
||||
NoSession session = new NoSession(user);
|
||||
try {
|
||||
adapter.addNoSession(session);
|
||||
} catch (NoAdapterException e) {
|
||||
throw new NoDashFatalException("Adapter could not save the session.", e);
|
||||
}
|
||||
|
||||
byte[] cookie = session.getEncryptedUuid();
|
||||
byte[] userFile;
|
||||
try {
|
||||
userFile = save(cookie, password);
|
||||
} catch (NoSessionExpiredException e) {
|
||||
throw new NoDashFatalException("Session expired despite just being created.");
|
||||
} catch (NoSessionConfirmedException e) {
|
||||
throw new NoDashFatalException("Session confirmed despite just being created.");
|
||||
} catch (NoSessionNotChangedException e) {
|
||||
throw new NoDashFatalException(
|
||||
"Session throwing NotChangedException despite being a new user");
|
||||
} catch (NoSessionAlreadyAwaitingConfirmationException e) {
|
||||
throw new NoDashFatalException(
|
||||
"Session already waiting confirmation despite just being created.");
|
||||
}
|
||||
|
||||
return new NoRegister(cookie, userFile);
|
||||
}
|
||||
|
||||
public static NoUser getUser(byte[] cookie) throws NoSessionExpiredException,
|
||||
NoSessionConfirmedException, NoDashSessionBadUUIDException {
|
||||
/*
|
||||
* Facilitates step 3 allow website-side modifications to the NoUser or NoUser inheritant
|
||||
*/
|
||||
return NoSessionSphere.getUser(cookie);
|
||||
public NoUser getNoUser(byte[] cookie) throws NoSessionExpiredException,
|
||||
NoSessionConfirmedException {
|
||||
boolean containsSession;
|
||||
try {
|
||||
containsSession = adapter.containsNoSession(cookie);
|
||||
} catch (NoAdapterException e) {
|
||||
throw new NoDashFatalException("Could not verify existence of session.", e);
|
||||
}
|
||||
|
||||
if (containsSession) {
|
||||
try {
|
||||
return adapter.getNoSession(cookie).getNoUser();
|
||||
} catch (NoAdapterException e) {
|
||||
throw new NoDashFatalException("Could not get session.", e);
|
||||
}
|
||||
} else {
|
||||
throw new NoSessionExpiredException();
|
||||
}
|
||||
}
|
||||
|
||||
public static NoState getSessionState(byte[] cookie) throws NoSessionExpiredException,
|
||||
NoSessionConfirmedException, NoDashSessionBadUUIDException {
|
||||
/*
|
||||
* Facilitates step 3 allow front-side to keep track of session state
|
||||
*/
|
||||
return NoSessionSphere.getState(cookie);
|
||||
public NoState getSessionState(byte[] cookie) throws NoSessionConfirmedException,
|
||||
NoSessionExpiredException {
|
||||
return getNoSession(cookie).getNoState();
|
||||
}
|
||||
|
||||
public static byte[] requestSave(byte[] cookie, char[] password)
|
||||
throws NoSessionExpiredException, NoSessionConfirmedException, NoSessionNotChangedException,
|
||||
NoSessionAlreadyAwaitingConfirmationException, NoDashSessionBadUUIDException {
|
||||
/* Step 4. Provides a user with the new binary file */
|
||||
return NoSessionSphere.save(cookie, password);
|
||||
public byte[] save(byte[] cookie, char[] password) throws NoSessionExpiredException,
|
||||
NoSessionConfirmedException, NoSessionNotChangedException,
|
||||
NoSessionAlreadyAwaitingConfirmationException {
|
||||
NoSession session = getNoSession(cookie);
|
||||
session.check();
|
||||
if (session.getNoState().equals(NoState.IDLE)) {
|
||||
throw new NoSessionNotChangedException();
|
||||
} else if (session.getNoState().equals(NoState.AWAITING_CONFIRMATION)) {
|
||||
throw new NoSessionAlreadyAwaitingConfirmationException();
|
||||
}
|
||||
return session.initiateSaveAttempt(password);
|
||||
}
|
||||
|
||||
public static void confirm(byte[] cookie, char[] password, byte[] data)
|
||||
throws NoSessionExpiredException, NoSessionConfirmedException,
|
||||
NoSessionNotAwaitingConfirmationException, NoUserNotValidException,
|
||||
NoDashSessionBadUUIDException {
|
||||
/*
|
||||
* Step 5. Assumes the user has re-uploaded the file along with providing the same password.
|
||||
* Further attempts of getUser or getSessionState will fail with a NoSessionExpiredException
|
||||
*/
|
||||
NoSessionSphere.confirm(cookie, password, data);
|
||||
public void confirm(byte[] cookie, char[] password, byte[] data) throws NoSessionExpiredException, NoSessionConfirmedException, NoSessionNotAwaitingConfirmationException, NoUserNotValidException {
|
||||
NoSession session = getNoSession(cookie);
|
||||
byte[] oldHash = session.getOriginalHash();
|
||||
byte[] newHash = session.getNoUserSafe().createHash();
|
||||
|
||||
session.confirmSave(adapter, data, password);
|
||||
|
||||
try {
|
||||
adapter.insertHash(newHash);
|
||||
} catch (NoAdapterException e) {
|
||||
throw new NoDashFatalException("Could not insert confirmed hash.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
adapter.goOffline(newHash);
|
||||
} catch (NoAdapterException e) {
|
||||
throw new NoDashFatalException("Could not go offline.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
adapter.shredNoSession(cookie);
|
||||
} catch (NoAdapterException e) {
|
||||
throw new NoDashFatalException("Could not shred session.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
adapter.removeHash(oldHash);
|
||||
} catch (NoAdapterException e) {
|
||||
throw new NoDashFatalException("Could not remove old hash.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addByteSet(NoByteSet byteSet, PublicKey publicKey) {
|
||||
NoByteSetSphere.add(byteSet, publicKey);
|
||||
}
|
||||
|
||||
public static void shred(byte[] cookie) {
|
||||
/* 3.2 Hot pull */
|
||||
NoSessionSphere.shred(cookie);
|
||||
}
|
||||
|
||||
public static void triggerPrune() {
|
||||
NoSessionSphere.prune();
|
||||
public void shred(byte[] cookie) {
|
||||
try {
|
||||
adapter.shredNoSession(cookie);
|
||||
} catch (NoAdapterException e) {
|
||||
throw new NoDashFatalException("Could not shred session.", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
229
src/nodash/core/NoDefaultAdapter.java
Normal file
229
src/nodash/core/NoDefaultAdapter.java
Normal file
@@ -0,0 +1,229 @@
|
||||
package nodash.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.security.PublicKey;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import nodash.core.exceptions.NoAdapterException;
|
||||
import nodash.exceptions.NoDashFatalException;
|
||||
import nodash.exceptions.NoUserAlreadyOnlineException;
|
||||
import nodash.exceptions.NoUserNotValidException;
|
||||
import nodash.models.NoByteSet;
|
||||
import nodash.models.NoSession;
|
||||
|
||||
public class NoDefaultAdapter implements NoAdapter {
|
||||
private static Map<PublicKey, Collection<NoByteSet>> byteSets =
|
||||
new ConcurrentHashMap<PublicKey, Collection<NoByteSet>>();
|
||||
private static Map<String, NoSession> sessions = new ConcurrentHashMap<String, NoSession>();
|
||||
private static Set<String> online = Collections
|
||||
.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
|
||||
|
||||
private static final String HASH_FILE = "nosystem.hash";
|
||||
|
||||
private static byte[] getFile() throws NoAdapterException {
|
||||
try {
|
||||
return alterFile(null, null);
|
||||
} catch (IOException e) {
|
||||
throw new NoAdapterException("Could not get hash file.", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static synchronized byte[] alterFile(byte[] hashToAdd, byte[] hashToRemove)
|
||||
throws IOException {
|
||||
if (!(hashToAdd == null ^ hashToRemove == null) && Arrays.equals(hashToAdd, hashToRemove)) {
|
||||
throw new IllegalArgumentException("Hashes to add and remove cannot be the same.");
|
||||
}
|
||||
|
||||
File file = new File(HASH_FILE);
|
||||
byte[] originalFileBytes = Files.readAllBytes(file.toPath());
|
||||
if (hashToAdd == null && hashToRemove == null) {
|
||||
return originalFileBytes;
|
||||
}
|
||||
|
||||
int hashes = originalFileBytes.length / 64;
|
||||
List<Byte> newFile = new ArrayList<Byte>();
|
||||
|
||||
for (int x = 0; x < hashes; x++) {
|
||||
byte[] hash = Arrays.copyOfRange(originalFileBytes, x * 64, x * 64 + 64);
|
||||
|
||||
if (hashToRemove == null || !Arrays.equals(hash, hashToRemove)) {
|
||||
for (byte hashByte : hash) {
|
||||
newFile.add(hashByte);
|
||||
}
|
||||
}
|
||||
|
||||
if (hashToAdd != null || Arrays.equals(hash, hashToAdd)) {
|
||||
hashToAdd = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (hashToAdd != null) {
|
||||
for (byte hashByte : hashToAdd) {
|
||||
newFile.add(hashByte);
|
||||
}
|
||||
}
|
||||
|
||||
byte[] newFileAsPrimitive = new byte[newFile.size()];
|
||||
for (int x = 0; x < newFile.size(); x++) {
|
||||
newFileAsPrimitive[x] = newFile.get(x).byteValue();
|
||||
}
|
||||
|
||||
Files.write(file.toPath(), newFileAsPrimitive);
|
||||
|
||||
return newFileAsPrimitive;
|
||||
}
|
||||
|
||||
public NoDefaultAdapter() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertHash(byte[] hash) throws NoAdapterException {
|
||||
try {
|
||||
alterFile(hash, null);
|
||||
} catch (IOException e) {
|
||||
throw new NoAdapterException("Trouble while inserting hash.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHash(byte[] hash) throws NoAdapterException {
|
||||
try {
|
||||
alterFile(null, hash);
|
||||
} catch (IOException e) {
|
||||
throw new NoAdapterException("Trouble removing hash.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkHash(byte[] hash) throws NoAdapterException, NoUserNotValidException {
|
||||
byte[] hashFile = getFile();
|
||||
int hashes = hashFile.length / 64;
|
||||
for (int x = 0; x < hashes; x++) {
|
||||
byte[] examine = Arrays.copyOfRange(hashFile, x * 64, x * 64 + 64);
|
||||
if (Arrays.equals(hash, examine)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new NoUserNotValidException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[][] exportHashes() throws NoAdapterException {
|
||||
byte[] hashFile = getFile();
|
||||
int hashes = hashFile.length / 64;
|
||||
byte[][] export = new byte[hashes][64];
|
||||
for (int x = 0; x < hashes; x++) {
|
||||
byte[] hash = Arrays.copyOfRange(hashFile, x * 64, x * 64 + 64);
|
||||
export[x] = hash;
|
||||
}
|
||||
return export;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long hashCount() throws NoAdapterException {
|
||||
byte[] hashFile = getFile();
|
||||
return hashFile.length / 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNoSession(NoSession session) {
|
||||
if (containsNoSession(session.getEncryptedUuid())) {
|
||||
throw new NoDashFatalException("No such session exists.");
|
||||
}
|
||||
sessions.put(session.getUuid(), session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsNoSession(byte[] encryptedUuid) {
|
||||
String uuid;
|
||||
try {
|
||||
uuid = Base64.encodeBase64String(NoUtil.decrypt(encryptedUuid));
|
||||
} catch (IllegalBlockSizeException | BadPaddingException e) {
|
||||
throw new NoDashFatalException("Could not decrypt given UUID.", e);
|
||||
}
|
||||
|
||||
return sessions.containsKey(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shredNoSession(byte[] encryptedUuid) {
|
||||
NoSession session = getNoSession(encryptedUuid);
|
||||
addNoByteSets(session.getIncomingSafe(), session.getNoUserSafe().getRsaPublicKey());
|
||||
sessions.remove(session.getUuid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoSession getNoSession(byte[] encryptedUuid) {
|
||||
if (containsNoSession(encryptedUuid)) {
|
||||
String uuid;
|
||||
try {
|
||||
uuid = Base64.encodeBase64String(NoUtil.decrypt(encryptedUuid));
|
||||
} catch (IllegalBlockSizeException | BadPaddingException e) {
|
||||
throw new NoDashFatalException("Could not decrypt given UUID.", e);
|
||||
}
|
||||
return sessions.get(uuid);
|
||||
}
|
||||
throw new NoDashFatalException("No such session exists.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<NoByteSet> pollNoByteSets(PublicKey address) {
|
||||
if (byteSets.containsKey(address)) {
|
||||
Collection<NoByteSet> storedByteSets = byteSets.get(address);
|
||||
Collection<NoByteSet> result = new ArrayList<NoByteSet>();
|
||||
for (NoByteSet byteSet : storedByteSets) {
|
||||
result.add(byteSet);
|
||||
storedByteSets.remove(byteSet);
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return new ArrayList<NoByteSet>();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNoByteSets(Collection<NoByteSet> addedByteSets, PublicKey address) {
|
||||
if (byteSets.containsKey(address)) {
|
||||
byteSets.get(address).addAll(addedByteSets);
|
||||
} else {
|
||||
byteSets.put(address, addedByteSets);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void goOnline(byte[] hash) throws NoUserAlreadyOnlineException {
|
||||
String hashString = Base64.encodeBase64String(hash);
|
||||
if (online.contains(hashString)) {
|
||||
throw new NoUserAlreadyOnlineException();
|
||||
}
|
||||
online.add(hashString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline(byte[] hash) {
|
||||
String hashString = Base64.encodeBase64String(hash);
|
||||
return online.contains(hashString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void goOffline(byte[] hash) {
|
||||
String hashString = Base64.encodeBase64String(hash);
|
||||
online.remove(hashString);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,8 +18,8 @@
|
||||
package nodash.core;
|
||||
|
||||
public final class NoRegister {
|
||||
public byte[] cookie;
|
||||
public byte[] data;
|
||||
public final byte[] cookie;
|
||||
public final byte[] data;
|
||||
|
||||
public NoRegister(byte[] cookie, byte[] data) {
|
||||
this.cookie = cookie;
|
||||
|
||||
15
src/nodash/core/exceptions/NoAdapterException.java
Normal file
15
src/nodash/core/exceptions/NoAdapterException.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package nodash.core.exceptions;
|
||||
|
||||
import nodash.exceptions.NoDashException;
|
||||
|
||||
public class NoAdapterException extends NoDashException {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public NoAdapterException(String message, Throwable e) {
|
||||
super(message, e);
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 David Horscroft
|
||||
*
|
||||
* Licensed 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.
|
||||
*
|
||||
* The NoByteSetSphere stores user-to-user influences and their encryption keys in an accessible
|
||||
* manner.
|
||||
*/
|
||||
|
||||
package nodash.core.spheres;
|
||||
|
||||
import java.security.PublicKey;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import nodash.models.NoByteSet;
|
||||
import nodash.models.NoUser;
|
||||
|
||||
public final class NoByteSetSphere {
|
||||
private static final List<NoByteSet> EMPTY_BYTESET_LIST = new ArrayList<NoByteSet>(0);
|
||||
|
||||
private static ConcurrentHashMap<PublicKey, ArrayList<NoByteSet>> byteSets =
|
||||
new ConcurrentHashMap<PublicKey, ArrayList<NoByteSet>>();
|
||||
|
||||
public static void add(NoByteSet byteSet, PublicKey publicKey) {
|
||||
if (!NoByteSetSphere.byteSets.containsKey(publicKey)) {
|
||||
NoByteSetSphere.byteSets.put(publicKey, new ArrayList<NoByteSet>());
|
||||
}
|
||||
NoByteSetSphere.byteSets.get(publicKey).add(byteSet);
|
||||
}
|
||||
|
||||
public static void addList(List<NoByteSet> byteSetList, PublicKey publicKey) {
|
||||
if (!NoByteSetSphere.byteSets.containsKey(publicKey)) {
|
||||
NoByteSetSphere.byteSets.put(publicKey, new ArrayList<NoByteSet>());
|
||||
}
|
||||
NoByteSetSphere.byteSets.get(publicKey).addAll(byteSetList);
|
||||
}
|
||||
|
||||
public static List<NoByteSet> consume(NoUser user) {
|
||||
if (NoByteSetSphere.byteSets.containsKey(user.getRsaPublicKey())) {
|
||||
ArrayList<NoByteSet> result = NoByteSetSphere.byteSets.get(user.getRsaPublicKey());
|
||||
NoByteSetSphere.byteSets.remove(user.getRsaPublicKey());
|
||||
return result;
|
||||
} else {
|
||||
return NoByteSetSphere.EMPTY_BYTESET_LIST;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 David Horscroft
|
||||
*
|
||||
* Licensed 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.
|
||||
*
|
||||
* The NoHashSpehre stores database hashes for user verification.
|
||||
*
|
||||
* Must be used with something that uses NoConfigDefault or an extension.
|
||||
*/
|
||||
|
||||
package nodash.core.spheres;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import nodash.core.NoCore;
|
||||
import nodash.core.NoConfigDefault;
|
||||
import nodash.exceptions.NoDashFatalException;
|
||||
import nodash.models.NoUser;
|
||||
|
||||
public final class NoHashSphereDefault implements NoHashSphereInterface {
|
||||
private Set<String> database = Collections
|
||||
.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
|
||||
private String fileName;
|
||||
private boolean ready = false;
|
||||
|
||||
public NoHashSphereDefault(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public NoHashSphereDefault() {
|
||||
this.fileName = ((NoConfigDefault) NoCore.config).getDatabaseName();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setup() {
|
||||
if (NoCore.config.saveDatabase()) {
|
||||
File file = new File(this.fileName);
|
||||
if (file.exists()) {
|
||||
try {
|
||||
byte[] data = Files.readAllBytes(file.toPath());
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
this.database = (Set<String>) ois.readObject();
|
||||
ois.close();
|
||||
bais.close();
|
||||
} catch (IOException e) {
|
||||
throw new NoDashFatalException("Unable to load up given database file.", e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new NoDashFatalException("Database file not in a verifiable format.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.ready = true;
|
||||
}
|
||||
|
||||
public synchronized void saveToFile() throws IOException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(this.database);
|
||||
byte[] data = baos.toByteArray();
|
||||
oos.close();
|
||||
baos.close();
|
||||
File file = new File(((NoConfigDefault) NoCore.config).getDatabaseName());
|
||||
Files.write(file.toPath(), data, StandardOpenOption.CREATE);
|
||||
}
|
||||
|
||||
public synchronized void addNewNoUser(NoUser user) throws IOException {
|
||||
String hash = user.createHashString();
|
||||
this.database.add(hash);
|
||||
this.saveToFile();
|
||||
}
|
||||
|
||||
public synchronized void insertHash(String hash) throws IOException {
|
||||
this.database.add(hash);
|
||||
this.saveToFile();
|
||||
}
|
||||
|
||||
public synchronized void removeHash(String hash) throws IOException {
|
||||
this.database.remove(hash);
|
||||
this.saveToFile();
|
||||
}
|
||||
|
||||
public synchronized boolean checkHash(String hash) {
|
||||
return this.database.contains(hash);
|
||||
}
|
||||
|
||||
public synchronized long size() {
|
||||
return this.database.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReady() {
|
||||
return this.ready;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package nodash.core.spheres;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import nodash.models.NoUser;
|
||||
|
||||
public interface NoHashSphereInterface {
|
||||
public void setup();
|
||||
|
||||
public void saveToFile() throws IOException;
|
||||
|
||||
public void addNewNoUser(NoUser user) throws IOException;
|
||||
|
||||
public void insertHash(String hash) throws IOException;
|
||||
|
||||
public void removeHash(String hash) throws IOException;
|
||||
|
||||
public boolean checkHash(String hash);
|
||||
|
||||
public long size();
|
||||
|
||||
public boolean isReady();
|
||||
}
|
||||
@@ -1,199 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 David Horscroft
|
||||
*
|
||||
* Licensed 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.
|
||||
*
|
||||
* The NoSessionSphere stores user sessions and allows their access and manipulation with the use of
|
||||
* their UUID.
|
||||
*/
|
||||
|
||||
package nodash.core.spheres;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import nodash.core.NoRegister;
|
||||
import nodash.exceptions.NoByteSetBadDecryptionException;
|
||||
import nodash.exceptions.NoDashFatalException;
|
||||
import nodash.exceptions.NoDashSessionBadUUIDException;
|
||||
import nodash.exceptions.NoSessionAlreadyAwaitingConfirmationException;
|
||||
import nodash.exceptions.NoSessionConfirmedException;
|
||||
import nodash.exceptions.NoSessionExpiredException;
|
||||
import nodash.exceptions.NoSessionNotAwaitingConfirmationException;
|
||||
import nodash.exceptions.NoSessionNotChangedException;
|
||||
import nodash.exceptions.NoUserAlreadyOnlineException;
|
||||
import nodash.exceptions.NoUserNotValidException;
|
||||
import nodash.models.NoByteSet;
|
||||
import nodash.models.NoSession;
|
||||
import nodash.models.NoUser;
|
||||
import nodash.models.NoSession.NoState;
|
||||
|
||||
public final class NoSessionSphere {
|
||||
private static ConcurrentHashMap<UUID, NoSession> sessions =
|
||||
new ConcurrentHashMap<UUID, NoSession>();
|
||||
private static Set<String> originalHashesOnline = Collections
|
||||
.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
|
||||
|
||||
public static synchronized void prune() {
|
||||
for (UUID uuid : NoSessionSphere.sessions.keySet()) {
|
||||
pruneSingle(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
public static void shred(byte[] encryptedUuid) {
|
||||
try {
|
||||
UUID uuid = NoSession.decryptUuid(encryptedUuid);
|
||||
if (NoSessionSphere.sessions.containsKey(uuid)) {
|
||||
NoSession session = NoSessionSphere.sessions.get(uuid);
|
||||
NoByteSetSphere.addList(session.incoming, session.current.getRsaPublicKey());
|
||||
NoSessionSphere.originalHashesOnline.remove(Base64.encodeBase64String(session
|
||||
.getOriginalHash()));
|
||||
NoSessionSphere.sessions.remove(uuid);
|
||||
session = null;
|
||||
}
|
||||
} catch (NoDashSessionBadUUIDException e) {
|
||||
// Suppress, doesn't matter
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void pruneSingle(UUID uuid) {
|
||||
NoSession session = NoSessionSphere.sessions.get(uuid);
|
||||
try {
|
||||
session.check();
|
||||
} catch (NoSessionExpiredException e) {
|
||||
/* Resultant from 3.1 and 3.2 */
|
||||
NoByteSetSphere.addList(session.incoming, session.current.getRsaPublicKey());
|
||||
NoSessionSphere.originalHashesOnline.remove(session.getOriginalHash());
|
||||
NoSessionSphere.sessions.remove(uuid);
|
||||
session = null;
|
||||
} catch (NoSessionConfirmedException e) {
|
||||
/* Should be cleaned up at 5.2 */
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized byte[] login(byte[] data, char[] password)
|
||||
throws NoUserNotValidException, NoUserAlreadyOnlineException, NoSessionExpiredException {
|
||||
/* 1. Login with byte[] data and byte[] password */
|
||||
NoSession session = new NoSession(data, password);
|
||||
/* 1.1. User currently has an online session, must wait for it to expire. */
|
||||
if (originalHashesOnline.contains(Base64.encodeBase64String(session.getOriginalHash()))) {
|
||||
throw new NoUserAlreadyOnlineException();
|
||||
}
|
||||
/* 1.2. User successfully logged in: set up session records. */
|
||||
NoSessionSphere.originalHashesOnline.add(Base64.encodeBase64String(session.getOriginalHash()));
|
||||
NoSessionSphere.sessions.put(session.uuid, session);
|
||||
|
||||
/* 2. Check NoByteSetSphere for incoming Influences */
|
||||
session.incoming = NoByteSetSphere.consume(session.current);
|
||||
for (NoByteSet nbs : session.incoming) {
|
||||
/* 2.1 Decrypt NoInfluence from NoByteSet, let the current user consume them */
|
||||
try {
|
||||
session.consume(nbs);
|
||||
} catch (NoByteSetBadDecryptionException e) {
|
||||
throw new NoDashFatalException("Bad byte sets on consumption.", e);
|
||||
}
|
||||
} /* 2.2 Alternatively, no NoByteSets to consume */
|
||||
|
||||
try {
|
||||
session.check();
|
||||
} catch (NoSessionConfirmedException e) {
|
||||
/* Should be impossible to reach */
|
||||
throw new NoDashFatalException(e);
|
||||
}
|
||||
|
||||
/* Will set to 2.1[MODIFIED] or 2.2[IDLE] */
|
||||
|
||||
/* Precursor to 3.; allow website to associate user session with a cookie. */
|
||||
return session.getEncryptedUuid();
|
||||
}
|
||||
|
||||
public static NoUser getUser(byte[] encryptedUUID) throws NoDashSessionBadUUIDException,
|
||||
NoSessionExpiredException, NoSessionConfirmedException {
|
||||
UUID uuid = NoSession.decryptUuid(encryptedUUID);
|
||||
if (NoSessionSphere.sessions.containsKey(uuid)) {
|
||||
NoSessionSphere.pruneSingle(uuid);
|
||||
try {
|
||||
return NoSessionSphere.sessions.get(uuid).getNoUser();
|
||||
} catch (NullPointerException e) {
|
||||
throw new NoSessionExpiredException();
|
||||
}
|
||||
}
|
||||
throw new NoSessionExpiredException();
|
||||
}
|
||||
|
||||
public static NoState getState(byte[] encryptedUUID) throws NoDashSessionBadUUIDException,
|
||||
NoSessionExpiredException, NoSessionConfirmedException {
|
||||
UUID uuid = NoSession.decryptUuid(encryptedUUID);
|
||||
if (NoSessionSphere.sessions.containsKey(uuid)) {
|
||||
NoSessionSphere.pruneSingle(uuid);
|
||||
NoSession session = NoSessionSphere.sessions.get(uuid);
|
||||
return session.getNoState();
|
||||
}
|
||||
throw new NoSessionExpiredException();
|
||||
}
|
||||
|
||||
public static synchronized byte[] save(byte[] encryptedUUID, char[] password)
|
||||
throws NoDashSessionBadUUIDException, NoSessionExpiredException, NoSessionConfirmedException,
|
||||
NoSessionNotChangedException, NoSessionAlreadyAwaitingConfirmationException {
|
||||
UUID uuid = NoSession.decryptUuid(encryptedUUID);
|
||||
if (NoSessionSphere.sessions.containsKey(uuid)) {
|
||||
NoSessionSphere.pruneSingle(uuid);
|
||||
NoSession session = NoSessionSphere.sessions.get(uuid);
|
||||
|
||||
if (session.getNoState().equals(NoState.IDLE)) {
|
||||
throw new NoSessionNotChangedException();
|
||||
} else if (session.getNoState().equals(NoState.AWAITING_CONFIRMATION)) {
|
||||
throw new NoSessionAlreadyAwaitingConfirmationException();
|
||||
}
|
||||
return session.initiateSaveAttempt(password);
|
||||
}
|
||||
throw new NoSessionExpiredException();
|
||||
}
|
||||
|
||||
public static synchronized void confirm(byte[] encryptedUUID, char[] password, byte[] data)
|
||||
throws NoDashSessionBadUUIDException, NoSessionExpiredException, NoSessionConfirmedException,
|
||||
NoSessionNotAwaitingConfirmationException, NoUserNotValidException {
|
||||
UUID uuid = NoSession.decryptUuid(encryptedUUID);
|
||||
if (NoSessionSphere.sessions.containsKey(uuid)) {
|
||||
NoSessionSphere.pruneSingle(uuid);
|
||||
NoSession session = NoSessionSphere.sessions.get(uuid);
|
||||
session.confirmSave(data, password);
|
||||
return;
|
||||
}
|
||||
throw new NoSessionExpiredException();
|
||||
}
|
||||
|
||||
public static synchronized NoRegister registerUser(NoUser user, char[] password) {
|
||||
NoSession session = new NoSession(user);
|
||||
NoSessionSphere.sessions.put(session.uuid, session);
|
||||
try {
|
||||
byte[] cookie = session.getEncryptedUuid();
|
||||
return new NoRegister(cookie, NoSessionSphere.save(cookie, password));
|
||||
} catch (NoDashSessionBadUUIDException e) {
|
||||
throw new NoDashFatalException("Immediately generated cookie throwing bad cookie error.", e);
|
||||
} catch (NoSessionExpiredException e) {
|
||||
throw new NoDashFatalException("Session expired before it was even returned to client.", e);
|
||||
} catch (NoSessionConfirmedException e) {
|
||||
throw new NoDashFatalException(
|
||||
"Session is in confirmed state before it was returned to client.", e);
|
||||
} catch (NoSessionNotChangedException e) {
|
||||
throw new NoDashFatalException(
|
||||
"Session claims to be unchanged but user is newly registered.", e);
|
||||
} catch (NoSessionAlreadyAwaitingConfirmationException e) {
|
||||
throw new NoDashFatalException(
|
||||
"Session claims to be awaiting confirmation before returning data to the user.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user