From 2cbb708dcab3aff63b2815c30ccecf592f5c17be Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 7 Feb 2020 22:37:48 +0100 Subject: [PATCH 1/7] Updated LoginCredentials constructor --- .../java/envoy/data/LoginCredentials.java | 48 ++++++++++++++----- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/src/main/java/envoy/data/LoginCredentials.java b/src/main/java/envoy/data/LoginCredentials.java index 9b29c07..e9b9b1c 100644 --- a/src/main/java/envoy/data/LoginCredentials.java +++ b/src/main/java/envoy/data/LoginCredentials.java @@ -17,26 +17,43 @@ import java.util.Formatter; */ public class LoginCredentials implements Serializable { - private final String name; + private final String identifier; + private final long id; private final byte[] passwordHash; private final boolean registration; private static final long serialVersionUID = -7395245059059523314L; /** - * Creates an in stance of {@link LoginCredentials}. + * Creates an instance of {@link LoginCredentials} for a new {@link User}. * - * @param name the name of the user - * @param password the password of the user (will be converted to a hash) - * @param registration signifies that these credentials are used for user - * registration instead of user login + * @param identifier the identifier of the user + * @param password the password of the user (will be converted to a hash) * @throws NoSuchAlgorithmException if the algorithm used is unknown * @since Envoy Common v0.2-alpha */ - public LoginCredentials(String name, char[] password, boolean registration) throws NoSuchAlgorithmException { - this.name = name; + public LoginCredentials(String identifier, char[] password) throws NoSuchAlgorithmException { + this.identifier = identifier; + this.id = -1; passwordHash = getSha256(toByteArray(password)); - this.registration = registration; + this.registration = true; + } + + /** + * Creates an instance of {@link LoginCredentials} for an {@link User} who + * already registered himself (knows his id). + * + * @param id the id of the user + * @param password the password of the user (will be converted to a hash) + * @throws NoSuchAlgorithmException if the algorithm used is unknown + * @since Envoy Common v0.2-alpha + */ + public LoginCredentials(long id, char[] password) throws NoSuchAlgorithmException { + if (id <= 0) throw new IllegalArgumentException("Entered an illegal Id. Ids can not be below 1. Id was " + id); + this.id = id; + passwordHash = getSha256(toByteArray(password)); + this.registration = false; + this.identifier = ""; } private byte[] getSha256(byte[] input) throws NoSuchAlgorithmException { return MessageDigest.getInstance("SHA-256").digest(input); } @@ -53,7 +70,8 @@ public class LoginCredentials implements Serializable { @Override public String toString() { try (Formatter form = new Formatter()) { - form.format("LoginCredentials[name=%s,passwordHash=", name); + if (registration) form.format("LoginCredentials[identifier=%s,passwordHash=", identifier); + else form.format("LoginCredentials[id=%d,passwordHash=", id); for (byte element : passwordHash) form.format("%02x", element); return form.format(",registration=%b]", registration).toString(); @@ -61,10 +79,10 @@ public class LoginCredentials implements Serializable { } /** - * @return the name of the user performing the login + * @return the identifier of the user performing the login * @since Envoy Common v0.2-alpha */ - public String getName() { return name; } + public String getIdentifier() { return identifier; } /** * @return the password hash of the user performing the login @@ -72,6 +90,12 @@ public class LoginCredentials implements Serializable { */ public byte[] getPasswordHash() { return passwordHash; } + /** + * @return the id of the underlying user + * @since Envoy Common v0.2-alpha + */ + public long getId() { return id; } + /** * @return {@code true} if these credentials are used for user registration * instead of user login From 5cae57139c5e9e543dff9168b2dd2eb7f0fe93b8 Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 7 Feb 2020 23:29:22 +0100 Subject: [PATCH 2/7] Added default reasons to HandshakeRejectionEvent --- .../envoy/event/HandshakeRejectionEvent.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/envoy/event/HandshakeRejectionEvent.java b/src/main/java/envoy/event/HandshakeRejectionEvent.java index aca655e..5537a18 100644 --- a/src/main/java/envoy/event/HandshakeRejectionEvent.java +++ b/src/main/java/envoy/event/HandshakeRejectionEvent.java @@ -1,5 +1,7 @@ package envoy.event; +import envoy.data.LoginCredentials; + /** * Signifies to the client that the handshake failed for the attached * reason.
@@ -13,6 +15,28 @@ package envoy.event; */ public class HandshakeRejectionEvent implements Event { + /** + * Select this value if a given password hash was incorrect + */ + public static final String WRONG_PASSWORD = "an incorrect password was entered"; + + /** + * Select this value if a given {@link LoginCredentials} pointed at a client who + * is already online + */ + public static final String ALREADY_ONLINE = "user is already online"; + + /** + * Select this value if a given {@link LoginCredentials} pointed at a client who + * does not exist + */ + public static final String USER_DOES_NOT_EXIST = "user does not exist"; + + /** + * Select this value if an unknown error occurred + */ + public static final String UNKNOWN_REASON = "cause of failure is unknown"; + private final String reason; private static final long serialVersionUID = -8723270093452609197L; From 4cfdf2f007b32cec12c744ab83850eb849770843 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 8 Feb 2020 09:17:11 +0100 Subject: [PATCH 3/7] Added another default reason --- src/main/java/envoy/event/HandshakeRejectionEvent.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/envoy/event/HandshakeRejectionEvent.java b/src/main/java/envoy/event/HandshakeRejectionEvent.java index 5537a18..66bbbc8 100644 --- a/src/main/java/envoy/event/HandshakeRejectionEvent.java +++ b/src/main/java/envoy/event/HandshakeRejectionEvent.java @@ -32,6 +32,13 @@ public class HandshakeRejectionEvent implements Event { */ public static final String USER_DOES_NOT_EXIST = "user does not exist"; + /** + * Select this value if a given {@link LoginCredentials} with + * {@link LoginCredentials#isRegistration()}==true points at an already existing + * user + */ + public static final String USER_EXISTS_ALREADY = "user can not be created as he already exists"; + /** * Select this value if an unknown error occurred */ From 12ef0fca6fdcfe9030d9905789b4ba2c418eabf6 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 8 Feb 2020 09:47:59 +0100 Subject: [PATCH 4/7] Removed ID artifact from LoginCredentials --- .../java/envoy/data/LoginCredentials.java | 38 ++++--------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/src/main/java/envoy/data/LoginCredentials.java b/src/main/java/envoy/data/LoginCredentials.java index e9b9b1c..fbcb398 100644 --- a/src/main/java/envoy/data/LoginCredentials.java +++ b/src/main/java/envoy/data/LoginCredentials.java @@ -18,7 +18,6 @@ import java.util.Formatter; public class LoginCredentials implements Serializable { private final String identifier; - private final long id; private final byte[] passwordHash; private final boolean registration; @@ -27,33 +26,17 @@ public class LoginCredentials implements Serializable { /** * Creates an instance of {@link LoginCredentials} for a new {@link User}. * - * @param identifier the identifier of the user - * @param password the password of the user (will be converted to a hash) + * @param identifier the identifier of the user + * @param password the password of the user (will be converted to a hash) + * @param registration if true, the user registers himself with this + * {@link LoginCredentials} * @throws NoSuchAlgorithmException if the algorithm used is unknown * @since Envoy Common v0.2-alpha */ - public LoginCredentials(String identifier, char[] password) throws NoSuchAlgorithmException { + public LoginCredentials(String identifier, char[] password, boolean registration) throws NoSuchAlgorithmException { this.identifier = identifier; - this.id = -1; passwordHash = getSha256(toByteArray(password)); - this.registration = true; - } - - /** - * Creates an instance of {@link LoginCredentials} for an {@link User} who - * already registered himself (knows his id). - * - * @param id the id of the user - * @param password the password of the user (will be converted to a hash) - * @throws NoSuchAlgorithmException if the algorithm used is unknown - * @since Envoy Common v0.2-alpha - */ - public LoginCredentials(long id, char[] password) throws NoSuchAlgorithmException { - if (id <= 0) throw new IllegalArgumentException("Entered an illegal Id. Ids can not be below 1. Id was " + id); - this.id = id; - passwordHash = getSha256(toByteArray(password)); - this.registration = false; - this.identifier = ""; + this.registration = registration; } private byte[] getSha256(byte[] input) throws NoSuchAlgorithmException { return MessageDigest.getInstance("SHA-256").digest(input); } @@ -70,8 +53,7 @@ public class LoginCredentials implements Serializable { @Override public String toString() { try (Formatter form = new Formatter()) { - if (registration) form.format("LoginCredentials[identifier=%s,passwordHash=", identifier); - else form.format("LoginCredentials[id=%d,passwordHash=", id); + form.format("LoginCredentials[identifier=%s,passwordHash=", identifier); for (byte element : passwordHash) form.format("%02x", element); return form.format(",registration=%b]", registration).toString(); @@ -90,12 +72,6 @@ public class LoginCredentials implements Serializable { */ public byte[] getPasswordHash() { return passwordHash; } - /** - * @return the id of the underlying user - * @since Envoy Common v0.2-alpha - */ - public long getId() { return id; } - /** * @return {@code true} if these credentials are used for user registration * instead of user login From 66653de4c22d6a0c16dba6feeee630a60d202c4e Mon Sep 17 00:00:00 2001 From: delvh Date: Sun, 9 Feb 2020 16:42:02 +0100 Subject: [PATCH 5/7] adapted Javadoc slightly --- src/main/java/envoy/data/LoginCredentials.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/envoy/data/LoginCredentials.java b/src/main/java/envoy/data/LoginCredentials.java index fbcb398..4cf4af2 100644 --- a/src/main/java/envoy/data/LoginCredentials.java +++ b/src/main/java/envoy/data/LoginCredentials.java @@ -28,8 +28,8 @@ public class LoginCredentials implements Serializable { * * @param identifier the identifier of the user * @param password the password of the user (will be converted to a hash) - * @param registration if true, the user registers himself with this - * {@link LoginCredentials} + * @param registration signifies that these credentials are used for user + * registration instead of user login * @throws NoSuchAlgorithmException if the algorithm used is unknown * @since Envoy Common v0.2-alpha */ From 55e3630f6e81c7ae5c243f280101d27878e1039a Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Wed, 12 Feb 2020 06:26:33 +0100 Subject: [PATCH 6/7] Removed unnecessary instance variable from HandshakeRejectionEvent --- .settings/org.eclipse.jdt.core.prefs | 100 ++++++++++++++++++ .../envoy/event/HandshakeRejectionEvent.java | 2 - 2 files changed, 100 insertions(+), 2 deletions(-) diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index ddd0785..eb4b86c 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,11 +1,111 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled +org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore +org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull +org.eclipse.jdt.core.compiler.annotation.nonnull.secondary= +org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault +org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary= +org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable +org.eclipse.jdt.core.compiler.annotation.nullable.secondary= +org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.APILeak=warning +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.autoboxing=ignore +org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning +org.eclipse.jdt.core.compiler.problem.deadCode=warning +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=info org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning +org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning +org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled +org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning +org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning +org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error +org.eclipse.jdt.core.compiler.problem.nullReference=warning +org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error +org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore +org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore +org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning +org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning +org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info +org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore +org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning +org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled +org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore +org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedImport=warning +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameter=warning +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=warning +org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=1.8 diff --git a/src/main/java/envoy/event/HandshakeRejectionEvent.java b/src/main/java/envoy/event/HandshakeRejectionEvent.java index 8304a11..c89405d 100644 --- a/src/main/java/envoy/event/HandshakeRejectionEvent.java +++ b/src/main/java/envoy/event/HandshakeRejectionEvent.java @@ -44,8 +44,6 @@ public class HandshakeRejectionEvent extends Event { */ public static final String UNKNOWN_REASON = "cause of failure is unknown"; - private final String reason; - private static final long serialVersionUID = -8723270093452609197L; /** From eacfefb8363c5e8f8a92a2a8cb781e9a6a9e16b2 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Wed, 12 Feb 2020 22:15:42 +0100 Subject: [PATCH 7/7] Fixed Event.Valueless#toString() to not display the null value --- src/main/java/envoy/event/Event.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/envoy/event/Event.java b/src/main/java/envoy/event/Event.java index 9d42bf5..5b13306 100644 --- a/src/main/java/envoy/event/Event.java +++ b/src/main/java/envoy/event/Event.java @@ -42,5 +42,8 @@ public abstract class Event implements Serializable { private static final long serialVersionUID = -9019362144094097997L; protected Valueless() { super(null); } + + @Override + public String toString() { return this.getClass().getSimpleName(); } } }