Skip to content

Commit

Permalink
Fix password decoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
rpseng committed Apr 24, 2024
1 parent f7b92a3 commit cf20205
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,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 @@ -159,15 +159,15 @@ 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 (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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
import eu.chargetime.ocpp.model.SessionInformation;

public interface ListenerEvents {
void authenticateSession(SessionInformation information, String username, byte[] password)
void authenticateSession(SessionInformation information, String username, String password)
throws AuthenticationException;

void newSession(ISession session, SessionInformation information);
Expand Down
2 changes: 1 addition & 1 deletion ocpp-common/src/main/java/eu/chargetime/ocpp/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void open(String hostname, int port, ServerEvents serverEvents) {

@Override
public void authenticateSession(
SessionInformation information, String username, byte[] password)
SessionInformation information, String username, String password)
throws AuthenticationException {
serverEvents.authenticateSession(information, username, password);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.UUID;

public interface ServerEvents {
void authenticateSession(SessionInformation information, String username, byte[] password) throws AuthenticationException;
void authenticateSession(SessionInformation information, String username, String password) throws AuthenticationException;

void newSession(UUID sessionIndex, SessionInformation information);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public ServerEvents generateServerEventsHandler() {
return 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 cf20205

Please sign in to comment.