Skip to content

Commit fb5d0fb

Browse files
author
rpseng
committed
More password fixes.
1 parent cf20205 commit fb5d0fb

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

ocpp-v2/src/main/java/eu/chargetime/ocpp/MultiProtocolWebSocketListener.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(
165165
.build();
166166

167167
String username = null;
168-
byte[] password = null;
168+
String password = null;
169169
if (clientHandshake.hasFieldValue("Authorization")) {
170170
String authorization = clientHandshake.getFieldValue("Authorization");
171171
if (authorization != null && authorization.toLowerCase().startsWith("basic")) {
@@ -178,21 +178,21 @@ public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(
178178
username =
179179
new String(Arrays.copyOfRange(credDecoded, 0, i), StandardCharsets.UTF_8);
180180
if (i + 1 < credDecoded.length) {
181-
password = Arrays.copyOfRange(credDecoded, i + 1, credDecoded.length);
181+
password = new String(Arrays.copyOfRange(credDecoded, i + 1, credDecoded.length));
182182
}
183183
break;
184184
}
185185
}
186186
}
187187
if (protocolVersion == null || protocolVersion == ProtocolVersion.OCPP1_6) {
188188
if (password == null
189-
|| password.length < configuration.getParameter(JSONConfiguration.OCPPJ_CP_MIN_PASSWORD_LENGTH, OCPPJ_CP_MIN_PASSWORD_LENGTH)
190-
|| password.length > configuration.getParameter(JSONConfiguration.OCPPJ_CP_MAX_PASSWORD_LENGTH, OCPPJ_CP_MAX_PASSWORD_LENGTH))
189+
|| password.length() < configuration.getParameter(JSONConfiguration.OCPPJ_CP_MIN_PASSWORD_LENGTH, OCPPJ_CP_MIN_PASSWORD_LENGTH)
190+
|| password.length() > configuration.getParameter(JSONConfiguration.OCPPJ_CP_MAX_PASSWORD_LENGTH, OCPPJ_CP_MAX_PASSWORD_LENGTH))
191191
throw new InvalidDataException(401, "Invalid password length");
192192
} else {
193193
if (password == null
194-
|| password.length < configuration.getParameter(JSONConfiguration.OCPP2J_CP_MIN_PASSWORD_LENGTH, OCPP2J_CP_MIN_PASSWORD_LENGTH)
195-
|| password.length > configuration.getParameter(JSONConfiguration.OCPP2J_CP_MAX_PASSWORD_LENGTH, OCPP2J_CP_MAX_PASSWORD_LENGTH))
194+
|| password.length() < configuration.getParameter(JSONConfiguration.OCPP2J_CP_MIN_PASSWORD_LENGTH, OCPP2J_CP_MIN_PASSWORD_LENGTH)
195+
|| password.length() > configuration.getParameter(JSONConfiguration.OCPP2J_CP_MAX_PASSWORD_LENGTH, OCPP2J_CP_MAX_PASSWORD_LENGTH))
196196
throw new InvalidDataException(401, "Invalid password length");
197197
}
198198
}

ocpp-v2_0-test/src/main/java/eu/chargetime/ocpp/test/FakeCentralSystem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void started() throws Exception {
7474
new ServerEvents() {
7575
@Override
7676
public void authenticateSession(
77-
SessionInformation information, String username, byte[] password) throws AuthenticationException {}
77+
SessionInformation information, String username, String password) throws AuthenticationException {}
7878

7979
@Override
8080
public void newSession(UUID sessionIndex, SessionInformation information) {

0 commit comments

Comments
 (0)