Skip to content

Commit cf20205

Browse files
author
rpseng
committed
Fix password decoding.
1 parent f7b92a3 commit cf20205

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

OCPP-J/src/main/java/eu/chargetime/ocpp/WebSocketListener.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(
146146
.build();
147147

148148
String username = null;
149-
byte[] password = null;
149+
String password = null;
150150
if (clientHandshake.hasFieldValue("Authorization")) {
151151
String authorization = clientHandshake.getFieldValue("Authorization");
152152
if (authorization != null && authorization.toLowerCase().startsWith("basic")) {
@@ -159,15 +159,15 @@ public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(
159159
username =
160160
new String(Arrays.copyOfRange(credDecoded, 0, i), StandardCharsets.UTF_8);
161161
if (i + 1 < credDecoded.length) {
162-
password = Arrays.copyOfRange(credDecoded, i + 1, credDecoded.length);
162+
password = new String(Arrays.copyOfRange(credDecoded, i + 1, credDecoded.length));
163163
}
164164
break;
165165
}
166166
}
167167
}
168168
if (password == null
169-
|| password.length < configuration.getParameter(JSONConfiguration.OCPPJ_CP_MIN_PASSWORD_LENGTH, OCPPJ_CP_MIN_PASSWORD_LENGTH)
170-
|| password.length > configuration.getParameter(JSONConfiguration.OCPPJ_CP_MAX_PASSWORD_LENGTH, OCPPJ_CP_MAX_PASSWORD_LENGTH))
169+
|| password.length() < configuration.getParameter(JSONConfiguration.OCPPJ_CP_MIN_PASSWORD_LENGTH, OCPPJ_CP_MIN_PASSWORD_LENGTH)
170+
|| password.length() > configuration.getParameter(JSONConfiguration.OCPPJ_CP_MAX_PASSWORD_LENGTH, OCPPJ_CP_MAX_PASSWORD_LENGTH))
171171
throw new InvalidDataException(401, "Invalid password length");
172172
}
173173

ocpp-common/src/main/java/eu/chargetime/ocpp/ListenerEvents.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
2828
import eu.chargetime.ocpp.model.SessionInformation;
2929

3030
public interface ListenerEvents {
31-
void authenticateSession(SessionInformation information, String username, byte[] password)
31+
void authenticateSession(SessionInformation information, String username, String password)
3232
throws AuthenticationException;
3333

3434
void newSession(ISession session, SessionInformation information);

ocpp-common/src/main/java/eu/chargetime/ocpp/Server.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void open(String hostname, int port, ServerEvents serverEvents) {
8181

8282
@Override
8383
public void authenticateSession(
84-
SessionInformation information, String username, byte[] password)
84+
SessionInformation information, String username, String password)
8585
throws AuthenticationException {
8686
serverEvents.authenticateSession(information, username, password);
8787
}

ocpp-common/src/main/java/eu/chargetime/ocpp/ServerEvents.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ of this software and associated documentation files (the "Software"), to deal
2929
import java.util.UUID;
3030

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

3434
void newSession(UUID sessionIndex, SessionInformation information);
3535

ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/DummyHandlers.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public ServerEvents generateServerEventsHandler() {
203203
return new ServerEvents() {
204204
@Override
205205
public void authenticateSession(
206-
SessionInformation information, String username, byte[] password) throws AuthenticationException {}
206+
SessionInformation information, String username, String password) throws AuthenticationException {}
207207

208208
@Override
209209
public void newSession(UUID sessionIndex, SessionInformation information) {

0 commit comments

Comments
 (0)