Skip to content

Commit 63fe226

Browse files
committed
Revert commits breaking API and binary OCPP 1.6 passwords
These commits were based on a misunderstanding of the OCPP-J 1.6 specification, which clearly states that the password is a byte sequence and not a string: Revert "More password fixes." This reverts commit fb5d0fb. Revert "Fix password decoding." This reverts commit cf20205. Revert "Recommended by 1.6 spec is a 20 byte (40 chars) key." This reverts commit f7b92a3. This commit breaks the API, because the behaviour of the method is changed to return the last configuration instead of the default configuration: Revert "A single instace, otherwise a static get() method makes no sense." This reverts commit 953f50b.
1 parent 088b78c commit 63fe226

File tree

8 files changed

+17
-19
lines changed

8 files changed

+17
-19
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ public class JSONConfiguration {
4949

5050
private JSONConfiguration() {}
5151

52-
private static final JSONConfiguration instance = new JSONConfiguration();
53-
5452
public static JSONConfiguration get() {
55-
return instance;
53+
return new JSONConfiguration();
5654
}
5755

5856
public <T> JSONConfiguration setParameter(String name, T value) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class WebSocketListener implements Listener {
5151
private static final int TIMEOUT_IN_MILLIS = 10000;
5252

5353
private static final int OCPPJ_CP_MIN_PASSWORD_LENGTH = 16;
54-
private static final int OCPPJ_CP_MAX_PASSWORD_LENGTH = 40;
54+
private static final int OCPPJ_CP_MAX_PASSWORD_LENGTH = 20;
5555

5656
private static final String HTTP_HEADER_PROXIED_ADDRESS = "X-Forwarded-For";
5757

@@ -146,7 +146,7 @@ public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(
146146
.build();
147147

148148
String username = null;
149-
String password = null;
149+
byte[] 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 = new String(Arrays.copyOfRange(credDecoded, i + 1, credDecoded.length));
162+
password = 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

Lines changed: 1 addition & 1 deletion
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, String password)
31+
void authenticateSession(SessionInformation information, String username, byte[] password)
3232
throws AuthenticationException;
3333

3434
void newSession(ISession session, SessionInformation information);

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

Lines changed: 1 addition & 1 deletion
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, String password)
84+
SessionInformation information, String username, byte[] password)
8585
throws AuthenticationException {
8686
serverEvents.authenticateSession(information, username, password);
8787
}

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

Lines changed: 1 addition & 1 deletion
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, String password) throws AuthenticationException;
32+
void authenticateSession(SessionInformation information, String username, byte[] 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

Lines changed: 1 addition & 1 deletion
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, String password) throws AuthenticationException {}
206+
SessionInformation information, String username, byte[] password) throws AuthenticationException {}
207207

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

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-
String password = null;
168+
byte[] 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 = new String(Arrays.copyOfRange(credDecoded, i + 1, credDecoded.length));
181+
password = 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, String password) throws AuthenticationException {}
77+
SessionInformation information, String username, byte[] password) throws AuthenticationException {}
7878

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

0 commit comments

Comments
 (0)