Skip to content

Commit 852777d

Browse files
authored
0.27.0 (#47)
Path concat fix. Fix NPE in DSLink.shutdown(). Set up push and release to maven central Make gradlew runnable. Add gradle.properties with defaults for ossrhUsername and ossrhPassword AES 256 SHA 256 Lenient salt update
1 parent ba0424f commit 852777d

File tree

20 files changed

+181
-80
lines changed

20 files changed

+181
-80
lines changed

build.gradle

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral()
4+
}
5+
dependencies {
6+
classpath 'com.adaptc.gradle:nexus-workflow:0.6'
7+
}
8+
}
9+
10+
apply plugin: 'nexus-workflow'
111
apply plugin: 'java'
212
apply plugin: 'maven'
13+
apply plugin: 'signing'
314

4-
group 'org.iot.dsa'
5-
version '0.25.0'
15+
group 'org.iot-dsa'
16+
version '0.27.0'
617

718
sourceCompatibility = 1.6
819
targetCompatibility = 1.6
920

21+
install {
22+
repositories.mavenInstaller {
23+
pom.project {
24+
artifactId 'dslink-v2'
25+
}
26+
}
27+
}
28+
1029
repositories {
1130
mavenLocal()
1231
mavenCentral()
@@ -16,14 +35,20 @@ repositories {
1635
}
1736

1837
dependencies {
19-
testCompile 'junit:junit:+'
38+
testCompile 'junit:junit:[4.12,)'
2039
}
2140

2241
task sourcesJar(group: 'build', type: Jar, dependsOn: classes) {
2342
classifier = 'sources'
2443
from sourceSets.main.allJava
2544
}
2645

46+
task javadocJar(type: Jar, dependsOn: javadoc) {
47+
classifier = 'javadoc'
48+
from javadoc.destinationDir
49+
}
50+
2751
artifacts {
2852
archives sourcesJar
53+
archives javadocJar
2954
}

ci/secring.gpg.enc

4.86 KB
Binary file not shown.

dslink-core/build.gradle

+51
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,54 @@ apply from: '../build.gradle'
33
javadoc {
44
exclude("**/com/**")
55
}
6+
7+
signing {
8+
required { gradle.taskGraph.hasTask("uploadArchives") }
9+
sign configurations.archives
10+
}
11+
12+
uploadArchives {
13+
repositories {
14+
mavenDeployer {
15+
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
16+
17+
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2") {
18+
authentication(userName: ossrhUsername, password: ossrhPassword)
19+
}
20+
21+
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots") {
22+
authentication(userName: ossrhUsername, password: ossrhPassword)
23+
}
24+
25+
pom.project {
26+
name = 'DSLink SDK V2'
27+
artifactId = 'dslink-core-v2'
28+
description = 'V2 Java SDK for the IoT DSA protocol'
29+
30+
packaging = 'jar'
31+
url = 'http://iot-dsa.org'
32+
33+
scm {
34+
connection = 'scm:git:https://github.com/iot-dsa-v2/sdk-dslink-java-v2.git'
35+
developerConnection = 'scm:git:[email protected]:iot-dsa-v2/sdk-dslink-java-v2.git'
36+
url = 'https://github.com/iot-dsa-v2/sdk-dslink-java-v2'
37+
}
38+
39+
licenses {
40+
license {
41+
name = 'The Apache License, Version 2.0'
42+
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
43+
}
44+
}
45+
46+
developers {
47+
developer {
48+
id = 'samrg472'
49+
name = 'Samuel Grenier'
50+
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}

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

+3-5
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

+3-3
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/dslink/DSLink.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,16 @@ public void save() {
356356
*/
357357
public void shutdown() {
358358
stop();
359-
if (runThread == null) {
359+
Thread thread = runThread;
360+
if (thread == null) {
360361
return;
361362
}
362-
synchronized (runThread) {
363-
try {
364-
runThread.join();
365-
} catch (Exception x) {
366-
fine(x);
363+
try {
364+
synchronized (thread) {
365+
thread.join();
367366
}
367+
} catch (Exception x) {
368+
fine(x);
368369
}
369370
}
370371

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

+3-4
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
@@ -56,15 +56,14 @@ public static StringBuilder concat(String leading, String trailing, StringBuilde
5656
}
5757
if (leading.charAt(leading.length() - 1) == '/') {
5858
if (trailing.charAt(0) == '/') {
59-
bucket.append(trailing.substring(1));
59+
return bucket.append(trailing.substring(1));
6060
}
6161
} else {
6262
if (trailing.charAt(0) != '/') {
6363
bucket.append('/');
64-
bucket.append(trailing);
6564
}
6665
}
67-
return bucket;
66+
return bucket.append(trailing);
6867
}
6968

7069
/**

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

+1-16
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

+14-14
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

+1-1
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

+4-4
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

+2-2
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.",

0 commit comments

Comments
 (0)