Skip to content

Commit

Permalink
More password fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
rpseng committed Apr 24, 2024
1 parent cf20205 commit fb5d0fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(
.build();

String username = null;
byte[] password = null;
String password = null;
if (clientHandshake.hasFieldValue("Authorization")) {
String authorization = clientHandshake.getFieldValue("Authorization");
if (authorization != null && authorization.toLowerCase().startsWith("basic")) {
Expand All @@ -178,21 +178,21 @@ public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(
username =
new String(Arrays.copyOfRange(credDecoded, 0, i), StandardCharsets.UTF_8);
if (i + 1 < credDecoded.length) {
password = Arrays.copyOfRange(credDecoded, i + 1, credDecoded.length);
password = new String(Arrays.copyOfRange(credDecoded, i + 1, credDecoded.length));
}
break;
}
}
}
if (protocolVersion == null || protocolVersion == ProtocolVersion.OCPP1_6) {
if (password == null
|| password.length < configuration.getParameter(JSONConfiguration.OCPPJ_CP_MIN_PASSWORD_LENGTH, OCPPJ_CP_MIN_PASSWORD_LENGTH)
|| password.length > configuration.getParameter(JSONConfiguration.OCPPJ_CP_MAX_PASSWORD_LENGTH, OCPPJ_CP_MAX_PASSWORD_LENGTH))
|| password.length() < configuration.getParameter(JSONConfiguration.OCPPJ_CP_MIN_PASSWORD_LENGTH, OCPPJ_CP_MIN_PASSWORD_LENGTH)
|| password.length() > configuration.getParameter(JSONConfiguration.OCPPJ_CP_MAX_PASSWORD_LENGTH, OCPPJ_CP_MAX_PASSWORD_LENGTH))
throw new InvalidDataException(401, "Invalid password length");
} else {
if (password == null
|| password.length < configuration.getParameter(JSONConfiguration.OCPP2J_CP_MIN_PASSWORD_LENGTH, OCPP2J_CP_MIN_PASSWORD_LENGTH)
|| password.length > configuration.getParameter(JSONConfiguration.OCPP2J_CP_MAX_PASSWORD_LENGTH, OCPP2J_CP_MAX_PASSWORD_LENGTH))
|| password.length() < configuration.getParameter(JSONConfiguration.OCPP2J_CP_MIN_PASSWORD_LENGTH, OCPP2J_CP_MIN_PASSWORD_LENGTH)
|| password.length() > configuration.getParameter(JSONConfiguration.OCPP2J_CP_MAX_PASSWORD_LENGTH, OCPP2J_CP_MAX_PASSWORD_LENGTH))
throw new InvalidDataException(401, "Invalid password length");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void started() throws Exception {
new ServerEvents() {
@Override
public void authenticateSession(
SessionInformation information, String username, byte[] password) throws AuthenticationException {}
SessionInformation information, String username, String password) throws AuthenticationException {}

@Override
public void newSession(UUID sessionIndex, SessionInformation information) {
Expand Down

0 comments on commit fb5d0fb

Please sign in to comment.