Skip to content

Commit 5acbaca

Browse files
authored
0.27.0
AES 256 SHA 256 Lenient salt update
1 parent ceb5a6c commit 5acbaca

File tree

14 files changed

+39
-67
lines changed

14 files changed

+39
-67
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ apply plugin: 'maven'
1313
apply plugin: 'signing'
1414

1515
group 'org.iot-dsa'
16-
version '0.26.0'
16+
version '0.27.0'
1717

1818
sourceCompatibility = 1.6
1919
targetCompatibility = 1.6

dslink-core/src/main/java/com/acuity/iot/dsa/dslink/protocol/v1/DS1Session.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,9 @@ protected void processEnvelope(DSIReader reader) {
287287
getConnection().setRequesterAllowed();
288288
}
289289
} else if (key.equals("salt")) {
290-
if (reader.next() != Token.STRING) {
291-
throw new IllegalStateException("Salt not a string");
292-
}
293-
fine(fine() ? "Next salt: " + reader.getString() : null);
294-
getConnection().updateSalt(reader.getString());
290+
String s = reader.getElement().toString();
291+
fine(fine() ? "Next salt: " + s : null);
292+
getConnection().updateSalt(s);
295293
}
296294
next = reader.next();
297295
} while (next != END_MAP);

dslink-core/src/main/java/com/acuity/iot/dsa/dslink/sys/cert/SysCertManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.iot.dsa.node.DSInfo;
66
import org.iot.dsa.node.DSNode;
77
import org.iot.dsa.node.DSString;
8-
import org.iot.dsa.security.DSPasswordAes;
8+
import org.iot.dsa.security.DSPasswordAes256;
99

1010
/**
1111
* Certificate management for the whole process. This is basically a stub for future
@@ -57,11 +57,11 @@ public void declareDefaults() {
5757
declareDefault(ALLOW_SERVERS, DSBool.TRUE);
5858
declareDefault(CERTFILE, DSString.valueOf("dslink.jks"));
5959
declareDefault(CERTFILE_TYPE, DSString.valueOf("JKS"));
60-
declareDefault(CERTFILE_PASS, DSPasswordAes.valueOf("dsarocks"));
60+
declareDefault(CERTFILE_PASS, DSPasswordAes256.valueOf("dsarocks"));
6161
}
6262

6363
private String getCertFilePass() {
64-
DSPasswordAes pass = (DSPasswordAes) keystorePass.getObject();
64+
DSPasswordAes256 pass = (DSPasswordAes256) keystorePass.getObject();
6565
return pass.decode();
6666
}
6767

dslink-core/src/main/java/org/iot/dsa/node/DSPath.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class DSPath {
1616
///////////////////////////////////////////////////////////////////////////
1717

1818
private static final int caseDiff = ('a' - 'A');
19-
private static final Charset utf8 = Charset.forName("UTF-8");
19+
private static final Charset utf8 = DSString.UTF8;
2020

2121
///////////////////////////////////////////////////////////////////////////
2222
// Fields

dslink-core/src/main/java/org/iot/dsa/node/DSString.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package org.iot.dsa.node;
22

33
import java.nio.charset.Charset;
4-
import java.util.logging.Level;
5-
import org.iot.dsa.logging.DSLogging;
64

75
/**
86
* String wrapper.
@@ -24,7 +22,7 @@ public class DSString extends DSElement {
2422
/**
2523
* The standard UTF8 charset, can be used with string.getBytes(Charset).
2624
*/
27-
public static final Charset UTF8 = utf8();
25+
public static final Charset UTF8 = Charset.forName("UTF-8");
2826

2927
// Fields
3028
// ------
@@ -84,16 +82,12 @@ public boolean isString() {
8482
public boolean toBoolean() {
8583
if (value.equalsIgnoreCase("true")) {
8684
return true;
87-
} else if (value.equalsIgnoreCase("false")) {
88-
return true;
8985
} else if (value.equals("0")) {
9086
return false;
9187
} else if (value.equals("1")) {
9288
return true;
9389
} else if (value.equalsIgnoreCase("on")) {
9490
return true;
95-
} else if (value.equalsIgnoreCase("off")) {
96-
return false;
9791
}
9892
return false;
9993
}
@@ -106,15 +100,6 @@ public String toString() {
106100
return value;
107101
}
108102

109-
private static Charset utf8() {
110-
try {
111-
return Charset.forName("UTF-8");
112-
} catch (Exception x) {
113-
DSLogging.getDefaultLogger().log(Level.SEVERE, "UTF-8 unknown", x);
114-
}
115-
return Charset.defaultCharset();
116-
}
117-
118103
@Override
119104
public DSString valueOf(DSElement arg) {
120105
return valueOf(arg.toString());

dslink-core/src/main/java/org/iot/dsa/security/DSPasswordAes.java renamed to dslink-core/src/main/java/org/iot/dsa/security/DSPasswordAes256.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
*
1515
* @author Aaron Hansen
1616
*/
17-
public class DSPasswordAes extends DSValue implements DSIPassword, DSIStorable {
17+
public class DSPasswordAes256 extends DSValue implements DSIPassword, DSIStorable {
1818

1919
// Constants
2020
// ---------
2121

2222
private static Cipher cipher;
2323
private static Key key;
24-
public static final DSPasswordAes NULL = new DSPasswordAes(DSString.NULL);
24+
public static final DSPasswordAes256 NULL = new DSPasswordAes256(DSString.NULL);
2525

2626
// Fields
2727
// ------
@@ -31,11 +31,11 @@ public class DSPasswordAes extends DSValue implements DSIPassword, DSIStorable {
3131
// Constructors
3232
// ------------
3333

34-
private DSPasswordAes(DSString encrypted) {
34+
private DSPasswordAes256(DSString encrypted) {
3535
this.value = encrypted;
3636
}
3737

38-
private DSPasswordAes(String encrypted) {
38+
private DSPasswordAes256(String encrypted) {
3939
this(DSString.valueOf(encrypted));
4040
}
4141

@@ -86,7 +86,7 @@ public static String encode(String arg) {
8686

8787
@Override
8888
public boolean equals(Object obj) {
89-
if (obj instanceof DSPasswordAes) {
89+
if (obj instanceof DSPasswordAes256) {
9090
return value.equals(obj.toString());
9191
}
9292
return false;
@@ -148,11 +148,11 @@ public DSString store() {
148148
}
149149

150150
@Override
151-
public DSPasswordAes restore(DSElement element) {
151+
public DSPasswordAes256 restore(DSElement element) {
152152
if (element.isNull()) {
153153
return NULL;
154154
}
155-
return new DSPasswordAes(element.toString());
155+
return new DSPasswordAes256(element.toString());
156156
}
157157

158158
/**
@@ -178,7 +178,7 @@ public String toString() {
178178
* @return Returns the NULL instance if the arg is null, isNull() or the empty string.
179179
*/
180180
@Override
181-
public DSPasswordAes valueOf(DSElement arg) {
181+
public DSPasswordAes256 valueOf(DSElement arg) {
182182
if ((arg == null) || arg.isNull()) {
183183
return NULL;
184184
}
@@ -195,13 +195,13 @@ public DSPasswordAes valueOf(DSElement arg) {
195195
* @param arg The text to hash.
196196
* @return Returns the NULL instance if the arg is null or the empty string.
197197
*/
198-
public static DSPasswordAes valueOf(String arg) {
198+
public static DSPasswordAes256 valueOf(String arg) {
199199
if (arg == null) {
200200
return NULL;
201201
} else if (arg.isEmpty()) {
202202
return NULL;
203203
}
204-
return new DSPasswordAes(encode(arg));
204+
return new DSPasswordAes256(encode(arg));
205205
}
206206

207207
// Initialization
@@ -210,14 +210,14 @@ public static DSPasswordAes valueOf(String arg) {
210210
static {
211211
try {
212212
cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
213-
byte[] nameBytes = DSPasswordAes.class.getName().getBytes(DSString.UTF8);
214-
byte[] keyBytes = new byte[16];
215-
System.arraycopy(nameBytes, 0, keyBytes, 0, 16);
213+
byte[] nameBytes = DSPasswordAes256.class.getName().getBytes(DSString.UTF8);
214+
byte[] keyBytes = new byte[32];
215+
System.arraycopy(nameBytes, 0, keyBytes, 0, 32);
216216
key = new SecretKeySpec(keyBytes, "AES");
217217
} catch (Exception x) {
218218
Logger.getLogger("security").log(Level.SEVERE, "AES problem", x);
219219
}
220-
DSRegistry.registerDecoder(DSPasswordAes.class, NULL);
220+
DSRegistry.registerDecoder(DSPasswordAes256.class, NULL);
221221
}
222222

223223
}

dslink-core/src/main/java/org/iot/dsa/security/DSPasswordSha256.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static String encode(String arg) {
5555

5656
@Override
5757
public boolean equals(Object obj) {
58-
if (obj instanceof DSPasswordAes) {
58+
if (obj instanceof DSPasswordAes256) {
5959
return value.equals(obj.toString());
6060
}
6161
return false;

dslink-core/src/test/java/org/iot/dsa/dslink/DSPasswordTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.iot.dsa.node.DSElement;
44
import org.iot.dsa.node.DSString;
5-
import org.iot.dsa.security.DSPasswordAes;
5+
import org.iot.dsa.security.DSPasswordAes256;
66
import org.iot.dsa.security.DSPasswordSha256;
77
import org.junit.Assert;
88
import org.junit.Test;
@@ -25,15 +25,15 @@ public class DSPasswordTests {
2525
// -------
2626

2727
@Test
28-
public void testAes() throws Exception {
29-
DSPasswordAes pass = DSPasswordAes.valueOf("myPass");
28+
public void testAes256() throws Exception {
29+
DSPasswordAes256 pass = DSPasswordAes256.valueOf("myPass");
3030
String encrypted = pass.toString();
3131
Assert.assertFalse(pass.toString().equals("myPass"));
3232
Assert.assertTrue(pass.decode().equals("myPass"));
3333
Assert.assertTrue(pass.isValid(DSString.valueOf("myPass")));
3434
Assert.assertFalse(pass.isValid(DSString.valueOf("asdf")));
3535
DSElement e = pass.store();
36-
pass = DSPasswordAes.NULL.restore(e);
36+
pass = DSPasswordAes256.NULL.restore(e);
3737
Assert.assertFalse(pass.toString().equals("myPass"));
3838
Assert.assertTrue(pass.decode().equals("myPass"));
3939
Assert.assertTrue(pass.toString().equals(encrypted));

dslink-java-v2-poc/dslink.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
"configs": {
88
"handler_class": {
99
"type": "string",
10-
"value": "org.iot.dsa.dslink.test.MainNode"
10+
"value": "org.iot.dsa.dslink.poc.MainNode"
1111
},
1212
"log": {
1313
"desc": "all, trace, debug, fine, warn, info, error, admin, fatal, none",
1414
"type": "enum",
15-
"value": "info"
15+
"value": "all"
1616
},
1717
"token": {
1818
"desc": "Authentication token for the broker.",

dslink-java-v2-poc/src/main/java/org/iot/dsa/dslink/poc/MainNode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public void onRemove(String name) {
9696

9797
@Override
9898
public void onUpdate(String name, DSElement value) {
99-
System.out.println("list update " + name);
99+
System.out.print(name);
100+
System.out.print(": ");
100101
System.out.println(String.valueOf(value));
101102
}
102103

0 commit comments

Comments
 (0)