Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.adaptc.gradle:nexus-workflow:0.6'
}
}

apply plugin: 'nexus-workflow'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'signing'

group 'org.iot.dsa'
version '0.25.0'
group 'org.iot-dsa'
version '0.27.0'

sourceCompatibility = 1.6
targetCompatibility = 1.6

install {
repositories.mavenInstaller {
pom.project {
artifactId 'dslink-v2'
}
}
}

repositories {
mavenLocal()
mavenCentral()
Expand All @@ -16,14 +35,20 @@ repositories {
}

dependencies {
testCompile 'junit:junit:+'
testCompile 'junit:junit:[4.12,)'
}

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

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

artifacts {
archives sourcesJar
archives javadocJar
}
Binary file added ci/secring.gpg.enc
Binary file not shown.
51 changes: 51 additions & 0 deletions dslink-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,54 @@ apply from: '../build.gradle'
javadoc {
exclude("**/com/**")
}

signing {
required { gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}

uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}

snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}

pom.project {
name = 'DSLink SDK V2'
artifactId = 'dslink-core-v2'
description = 'V2 Java SDK for the IoT DSA protocol'

packaging = 'jar'
url = 'http://iot-dsa.org'

scm {
connection = 'scm:git:https://github.com/iot-dsa-v2/sdk-dslink-java-v2.git'
developerConnection = 'scm:git:git@github.com:iot-dsa-v2/sdk-dslink-java-v2.git'
url = 'https://github.com/iot-dsa-v2/sdk-dslink-java-v2'
}

licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}

developers {
developer {
id = 'samrg472'
name = 'Samuel Grenier'
email = 'samrg472@gmail.com'
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,9 @@ protected void processEnvelope(DSIReader reader) {
getConnection().setRequesterAllowed();
}
} else if (key.equals("salt")) {
if (reader.next() != Token.STRING) {
throw new IllegalStateException("Salt not a string");
}
fine(fine() ? "Next salt: " + reader.getString() : null);
getConnection().updateSalt(reader.getString());
String s = reader.getElement().toString();
fine(fine() ? "Next salt: " + s : null);
getConnection().updateSalt(s);
}
next = reader.next();
} while (next != END_MAP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.iot.dsa.node.DSInfo;
import org.iot.dsa.node.DSNode;
import org.iot.dsa.node.DSString;
import org.iot.dsa.security.DSPasswordAes;
import org.iot.dsa.security.DSPasswordAes256;

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

private String getCertFilePass() {
DSPasswordAes pass = (DSPasswordAes) keystorePass.getObject();
DSPasswordAes256 pass = (DSPasswordAes256) keystorePass.getObject();
return pass.decode();
}

Expand Down
13 changes: 7 additions & 6 deletions dslink-core/src/main/java/org/iot/dsa/dslink/DSLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,16 @@ public void save() {
*/
public void shutdown() {
stop();
if (runThread == null) {
Thread thread = runThread;
if (thread == null) {
return;
}
synchronized (runThread) {
try {
runThread.join();
} catch (Exception x) {
fine(x);
try {
synchronized (thread) {
thread.join();
}
} catch (Exception x) {
fine(x);
}
}

Expand Down
7 changes: 3 additions & 4 deletions dslink-core/src/main/java/org/iot/dsa/node/DSPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class DSPath {
///////////////////////////////////////////////////////////////////////////

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

///////////////////////////////////////////////////////////////////////////
// Fields
Expand Down Expand Up @@ -56,15 +56,14 @@ public static StringBuilder concat(String leading, String trailing, StringBuilde
}
if (leading.charAt(leading.length() - 1) == '/') {
if (trailing.charAt(0) == '/') {
bucket.append(trailing.substring(1));
return bucket.append(trailing.substring(1));
}
} else {
if (trailing.charAt(0) != '/') {
bucket.append('/');
bucket.append(trailing);
}
}
return bucket;
return bucket.append(trailing);
}

/**
Expand Down
17 changes: 1 addition & 16 deletions dslink-core/src/main/java/org/iot/dsa/node/DSString.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.iot.dsa.node;

import java.nio.charset.Charset;
import java.util.logging.Level;
import org.iot.dsa.logging.DSLogging;

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

// Fields
// ------
Expand Down Expand Up @@ -84,16 +82,12 @@ public boolean isString() {
public boolean toBoolean() {
if (value.equalsIgnoreCase("true")) {
return true;
} else if (value.equalsIgnoreCase("false")) {
return true;
} else if (value.equals("0")) {
return false;
} else if (value.equals("1")) {
return true;
} else if (value.equalsIgnoreCase("on")) {
return true;
} else if (value.equalsIgnoreCase("off")) {
return false;
}
return false;
}
Expand All @@ -106,15 +100,6 @@ public String toString() {
return value;
}

private static Charset utf8() {
try {
return Charset.forName("UTF-8");
} catch (Exception x) {
DSLogging.getDefaultLogger().log(Level.SEVERE, "UTF-8 unknown", x);
}
return Charset.defaultCharset();
}

@Override
public DSString valueOf(DSElement arg) {
return valueOf(arg.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
*
* @author Aaron Hansen
*/
public class DSPasswordAes extends DSValue implements DSIPassword, DSIStorable {
public class DSPasswordAes256 extends DSValue implements DSIPassword, DSIStorable {

// Constants
// ---------

private static Cipher cipher;
private static Key key;
public static final DSPasswordAes NULL = new DSPasswordAes(DSString.NULL);
public static final DSPasswordAes256 NULL = new DSPasswordAes256(DSString.NULL);

// Fields
// ------
Expand All @@ -31,11 +31,11 @@ public class DSPasswordAes extends DSValue implements DSIPassword, DSIStorable {
// Constructors
// ------------

private DSPasswordAes(DSString encrypted) {
private DSPasswordAes256(DSString encrypted) {
this.value = encrypted;
}

private DSPasswordAes(String encrypted) {
private DSPasswordAes256(String encrypted) {
this(DSString.valueOf(encrypted));
}

Expand Down Expand Up @@ -86,7 +86,7 @@ public static String encode(String arg) {

@Override
public boolean equals(Object obj) {
if (obj instanceof DSPasswordAes) {
if (obj instanceof DSPasswordAes256) {
return value.equals(obj.toString());
}
return false;
Expand Down Expand Up @@ -148,11 +148,11 @@ public DSString store() {
}

@Override
public DSPasswordAes restore(DSElement element) {
public DSPasswordAes256 restore(DSElement element) {
if (element.isNull()) {
return NULL;
}
return new DSPasswordAes(element.toString());
return new DSPasswordAes256(element.toString());
}

/**
Expand All @@ -178,7 +178,7 @@ public String toString() {
* @return Returns the NULL instance if the arg is null, isNull() or the empty string.
*/
@Override
public DSPasswordAes valueOf(DSElement arg) {
public DSPasswordAes256 valueOf(DSElement arg) {
if ((arg == null) || arg.isNull()) {
return NULL;
}
Expand All @@ -195,13 +195,13 @@ public DSPasswordAes valueOf(DSElement arg) {
* @param arg The text to hash.
* @return Returns the NULL instance if the arg is null or the empty string.
*/
public static DSPasswordAes valueOf(String arg) {
public static DSPasswordAes256 valueOf(String arg) {
if (arg == null) {
return NULL;
} else if (arg.isEmpty()) {
return NULL;
}
return new DSPasswordAes(encode(arg));
return new DSPasswordAes256(encode(arg));
}

// Initialization
Expand All @@ -210,14 +210,14 @@ public static DSPasswordAes valueOf(String arg) {
static {
try {
cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
byte[] nameBytes = DSPasswordAes.class.getName().getBytes(DSString.UTF8);
byte[] keyBytes = new byte[16];
System.arraycopy(nameBytes, 0, keyBytes, 0, 16);
byte[] nameBytes = DSPasswordAes256.class.getName().getBytes(DSString.UTF8);
byte[] keyBytes = new byte[32];
System.arraycopy(nameBytes, 0, keyBytes, 0, 32);
key = new SecretKeySpec(keyBytes, "AES");
} catch (Exception x) {
Logger.getLogger("security").log(Level.SEVERE, "AES problem", x);
}
DSRegistry.registerDecoder(DSPasswordAes.class, NULL);
DSRegistry.registerDecoder(DSPasswordAes256.class, NULL);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static String encode(String arg) {

@Override
public boolean equals(Object obj) {
if (obj instanceof DSPasswordAes) {
if (obj instanceof DSPasswordAes256) {
return value.equals(obj.toString());
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.iot.dsa.node.DSElement;
import org.iot.dsa.node.DSString;
import org.iot.dsa.security.DSPasswordAes;
import org.iot.dsa.security.DSPasswordAes256;
import org.iot.dsa.security.DSPasswordSha256;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -25,15 +25,15 @@ public class DSPasswordTests {
// -------

@Test
public void testAes() throws Exception {
DSPasswordAes pass = DSPasswordAes.valueOf("myPass");
public void testAes256() throws Exception {
DSPasswordAes256 pass = DSPasswordAes256.valueOf("myPass");
String encrypted = pass.toString();
Assert.assertFalse(pass.toString().equals("myPass"));
Assert.assertTrue(pass.decode().equals("myPass"));
Assert.assertTrue(pass.isValid(DSString.valueOf("myPass")));
Assert.assertFalse(pass.isValid(DSString.valueOf("asdf")));
DSElement e = pass.store();
pass = DSPasswordAes.NULL.restore(e);
pass = DSPasswordAes256.NULL.restore(e);
Assert.assertFalse(pass.toString().equals("myPass"));
Assert.assertTrue(pass.decode().equals("myPass"));
Assert.assertTrue(pass.toString().equals(encrypted));
Expand Down
4 changes: 2 additions & 2 deletions dslink-java-v2-poc/dslink.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"configs": {
"handler_class": {
"type": "string",
"value": "org.iot.dsa.dslink.test.MainNode"
"value": "org.iot.dsa.dslink.poc.MainNode"
},
"log": {
"desc": "all, trace, debug, fine, warn, info, error, admin, fatal, none",
"type": "enum",
"value": "info"
"value": "all"
},
"token": {
"desc": "Authentication token for the broker.",
Expand Down
Loading