Unverified Commit 83eb1b9d authored by Javier Guerra's avatar Javier Guerra Committed by GitHub

Merge pull request #6 from openconnectivity/develop

Merge develop into master
parents 2a91e6aa cfbfdec7
......@@ -24,29 +24,68 @@
## Overview
## Project Setup
### IoTivity Base API
To import the IoTivity Base API Binary into the OTGC Linux App project:
### IoTivity-lite API
To import the IoTivity-lite API Binary into the OTGC Linux App project:
1. Create a new directory called `lib` in the project root.
2. Build the IoTivity binary in linux.
scons BUILD_JAVA=1
2. Create a new directory called `jni` into <otgc-linux>/lib
3. Copy the `iotivity.jar` into `lib` directory. This file is found in:
3. Copy **iotivity.jar** into <otgc-linux>/lib.
<iotivity>/out/linux/<your arch>/<release mode>/java/iotivity.jar
4. Copy **libiotivity-lite.so** into &lt;otgc-linux>/lib/jni
4. Add iotivity.jar to the libraries of the project.
5. Add the following command, to link the previous libraries with iotivity.jar, in the run/debug configuration:
```
-Djava.library.path=<otgc-linux>/lib/jni
```
5. Copy the libraries (only .so files) for IoTivity into the `lib` directory. These libraries is found in:
<iotivity>/out/linux/<your arch>/<release mode>
6. Add the following command, to link the previous libraries with iotivity.jar, in the run/debug configuration:
-Djava.library.path=<project directory>/lib/
## Build
### IoTivity-lite Linux API
The steps required to build the binary of the IoTivity-lite Linux API are shown below:
1. Change to the swig branch.
```
git checkout swig
```
2. Go to the linux directory.
```
cd <iotivity-lite>/port/linux
```
3. Execute the command to build the library.
```
make DEBUG=1 SECURE=1 IPV4=1 TCP=0 PKI=1 DYNAMIC=1 CLOUD=0 JAVA=1 IDD=1
```
Once built, the library can be found at:
```
<iotivity-lite>/swig/iotivity-lite-java/libs
```
### OTGC
The steps to build the OTGC are shown below:
1. To build the project, execute the command:
```
mvn jfx:jar
```
2. When the project is built, go to the Debian directory
```
cd <otgc-linux>/build/debian
```
3. To create the Debian package, execute the command:
```
./otgc_native.sh <otgc-linux>/target/jfx/app
```
Once the Debian package is build, it can be found in:
```
<otgc-linux>/build/debian/out
```
## Testing
......
Package: OTGC
Version: 2.0.4
Version: 2.0.5
Section: custom
Priority: optional
Architecture: amd64
......
......@@ -11,7 +11,7 @@
# Constants
PROJECT_NAME="otgc"
VERSION="2.0.4"
VERSION="2.0.5"
program=$0
......
iotivity-lite @ 1b955e8d
Subproject commit a2722849a41b724fa759199f4f296ac1f85c96e6
Subproject commit 1b955e8d56e87d8fe7c18098f7df4740e9ce0867
......@@ -6,7 +6,7 @@
<groupId>otgc</groupId>
<artifactId>otgc</artifactId>
<version>2.0.4</version>
<version>2.0.5</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......
......@@ -43,8 +43,7 @@ public class AmsRepository {
public Single<OcAcl> getAcl(String endpoint, String deviceId) {
return Single.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid uuid = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, uuid);
......@@ -69,8 +68,7 @@ public class AmsRepository {
private Completable provisionAcl(String endpoint, String deviceId, OcAcl acl) {
return Completable.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid uuid = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, uuid);
......@@ -104,6 +102,42 @@ public class AmsRepository {
});
}
private Completable provisionAce(String deviceId, OCSecurityAce ace, List<String> verticalResources, long permission) {
return Completable.create(emitter -> {
int ret;
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
ret = setAceResources(ace, verticalResources);
if (ret == -1) {
String errorMsg = "ERROR: Could not create ACE resources";
LOG.error(errorMsg);
emitter.onError(new Exception(errorMsg));
}
OCObt.aceAddPermission(ace, (int)permission);
OCObtDeviceStatusHandler handler = (OCUuid uuid, int status) -> {
if (status >= 0) {
LOG.debug("Successfully provisioned ACE to device " + OCUuidUtil.uuidToString(uuid));
emitter.onComplete();
} else {
String errorMsg = "ERROR provisioning ACE to device " + OCUuidUtil.uuidToString(uuid);
LOG.error(errorMsg);
emitter.onError(new Exception(errorMsg));
}
};
ret = OCObt.provisionAce(di, ace, handler);
if (ret >= 0) {
LOG.debug("Successfully issued request to provision ACE");
} else {
String errorMsg = "ERROR issuing request to provision ACE";
LOG.error(errorMsg);
emitter.onError(new Exception(errorMsg));
}
});
}
public Completable provisionUuidAcl(String endpoint, String deviceId, String subjectId, List<String> verticalResources, long permission) {
OcAceSubject subject = new OcAceSubject();
subject.setType(OcAceSubjectType.UUID_TYPE);
......@@ -120,6 +154,19 @@ public class AmsRepository {
return provisionAcl(endpoint, deviceId, acl);
}
public Completable provisionUuidAce(String deviceId, String subjectId, List<String> verticalResources, long permission) {
OCUuid di = OCUuidUtil.stringToUuid(subjectId);
OCSecurityAce ace = OCObt.newAceForSubject(di);
if (ace == null) {
String errorMsg = "ERROR: Could not create ACE";
LOG.error(errorMsg);
return Completable.error(new Exception(errorMsg));
}
return provisionAce(deviceId, ace, verticalResources, permission);
}
public Completable provisionRoleAcl(String endpoint, String deviceId, String roleId, String roleAuthority, List<String> verticalResources, long permission) {
OcAceSubject subject = new OcAceSubject();
subject.setType(OcAceSubjectType.ROLE_TYPE);
......@@ -137,6 +184,17 @@ public class AmsRepository {
return provisionAcl(endpoint, deviceId, acl);
}
public Completable provisionRoleAce(String deviceId, String roleId, String roleAuthority, List<String> verticalResources, long permission) {
OCSecurityAce ace = OCObt.newAceForRole(roleId, roleAuthority);
if (ace == null) {
String errorMsg = "ERROR: Could not create ACE";
LOG.error(errorMsg);
return Completable.error(new Exception(errorMsg));
}
return provisionAce(deviceId, ace, verticalResources, permission);
}
public Completable provisionConntypeAcl(String endpoint, String deviceId, boolean isAuthCrypt, List<String> verticalResources, long permission) {
OcAceSubject subject = new OcAceSubject();
subject.setType(OcAceSubjectType.CONN_TYPE);
......@@ -153,10 +211,72 @@ public class AmsRepository {
return provisionAcl(endpoint, deviceId, acl);
}
public Completable provisionConntypeAce(String deviceId, boolean isAuthCrypt, List<String> verticalResources, long permission) {
OCSecurityAce ace = OCObt.newAceForConnection(isAuthCrypt ? OCAceConnectionType.OC_CONN_AUTH_CRYPT : OCAceConnectionType.OC_CONN_ANON_CLEAR);
if (ace == null) {
String errorMsg = "ERROR: Could not create ACE";
LOG.error(errorMsg);
return Completable.error(new Exception(errorMsg));
}
return provisionAce(deviceId, ace, verticalResources, permission);
}
public Completable provisionAuthWildcardAce(String deviceId) {
return Completable.create(emitter -> {
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCObtDeviceStatusHandler handler = (OCUuid uuid, int status) -> {
if (status >= 0) {
LOG.debug("Successfully provisioned auth-crypt * ACE to device " + OCUuidUtil.uuidToString(uuid));
emitter.onComplete();
} else {
String errorMsg = "ERROR provisioning ACE to device " + OCUuidUtil.uuidToString(uuid);
LOG.error(errorMsg);
emitter.onError(new IOException(errorMsg));
}
};
int ret = OCObt.provisionAuthWildcardAce(di, handler);
if (ret >= 0) {
LOG.debug("Successfully issued request to provision auth-crypt * ACE");
} else {
String errorMsg = "ERROR issuing request to provision auth-crypt * ACE";
LOG.error(errorMsg);
emitter.onError(new IOException(errorMsg));
}
});
}
public Completable provisionRoleWildcardAce(String deviceId, String roleId, String roleAuthority) {
return Completable.create(emitter -> {
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCObtDeviceStatusHandler handler = (OCUuid uuid, int status) -> {
if (status >= 0) {
LOG.debug("Successfully provisioned role * ACE to device " + OCUuidUtil.uuidToString(uuid));
emitter.onComplete();
} else {
String errorMsg = "ERROR provisioning ACE to device " + OCUuidUtil.uuidToString(uuid);
LOG.error(errorMsg);
emitter.onError(new IOException(errorMsg));
}
};
int ret = OCObt.provisionRoleWildcardAce(di, roleId, roleAuthority, handler);
if (ret >= 0) {
LOG.debug("Successfully issued request to provision role * ACE");
} else {
String errorMsg = "ERROR issuing request to provision role * ACE";
LOG.error(errorMsg);
emitter.onError(new IOException(errorMsg));
}
});
}
public Completable deleteAcl(String endpoint, String deviceId, long aceId) {
return Completable.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid uuid = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, uuid);
......@@ -200,4 +320,35 @@ public class AmsRepository {
return resources;
}
private int setAceResources(OCSecurityAce ace, List<String> resources) {
for (String resource : resources) {
OCAceResource res = OCObt.aceNewResource(ace);
if (res == null) {
String errorMsg = "ERROR: Could not allocate new resource for ACE";
LOG.error(errorMsg);
OCObt.freeAce(ace);
return -1;
}
if (OcfWildcard.isWildcard(resource)) {
if (resource.equals(OcfWildcard.OC_WILDCARD_ALL_NCR)) {
OCObt.aceResourceSetWc(res, OCAceWildcard.OC_ACE_WC_ALL);
} else if (resource.equals(OcfWildcard.OC_WILDCARD_ALL_SECURE_NCR)) {
OCObt.aceResourceSetWc(res, OCAceWildcard.OC_ACE_WC_ALL_SECURED);
} else if (resource.equals(OcfWildcard.OC_WILDCARD_ALL_NON_SECURE_NCR)) {
OCObt.aceResourceSetWc(res, OCAceWildcard.OC_ACE_WC_ALL_PUBLIC);
}
} else {
OCObt.aceResourceSetHref(res, resource);
OCObt.aceResourceSetWc(res, OCAceWildcard.OC_ACE_NO_WC);
}
// TODO: Set resource types
// TODO: Set interfaces
}
return 0;
}
}
......@@ -20,7 +20,6 @@
package org.openconnectivity.otgc.data.repository;
import io.reactivex.Completable;
import io.reactivex.CompletableSource;
import io.reactivex.Single;
import org.apache.log4j.Logger;
import org.iotivity.*;
......@@ -46,8 +45,7 @@ public class CmsRepository {
public Single<OcCredentials> getCredentials(String endpoint, String deviceId) {
return Single.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid uuid = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, uuid);
......@@ -74,8 +72,7 @@ public class CmsRepository {
public Single<OcCsr> retrieveCsr(String endpoint, String deviceId) {
return Single.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid uuid = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, uuid);
......@@ -100,8 +97,7 @@ public class CmsRepository {
public Completable provisionTrustAnchor(String endpoint, String deviceId, String rootCert) {
return Completable.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, di);
......@@ -153,8 +149,7 @@ public class CmsRepository {
return provisionTrustAnchor(endpoint, deviceId, rootCert)
.andThen(
Completable.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, di);
......@@ -202,10 +197,29 @@ public class CmsRepository {
}));
}
public Completable provisionIdentityCertificate(String deviceId) {
return Completable.create(emitter -> {
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCObtStatusHandler handler = (int status) -> {
if (status >= 0) {
LOG.debug("Provision identity certificate succeeded");
emitter.onComplete();
} else {
emitter.onError(new IOException("Provision identity certificate error"));
}
};
int ret = OCObt.provisionIdentityCertificate(di, handler);
if (ret < 0) {
emitter.onError(new IOException("Provision identity certificate error"));
}
});
}
public Completable provisionRoleCertificate(String endpoint, String deviceId, String roleCert, String roleId, String roleAuthority) {
return Completable.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, di);
......@@ -258,10 +272,33 @@ public class CmsRepository {
});
}
public Completable provisionRoleCertificate(String deviceId, String roleId, String roleAuthority) {
return Completable.create(emitter -> {
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCRole role = new OCRole();
role.setRole(roleId);
role.setAuthority(roleAuthority);
OCObtStatusHandler handler = (int status) -> {
if (status >= 0) {
LOG.debug("Provision role certificate succeeded");
emitter.onComplete();
} else {
emitter.onError(new IOException("Provision role certificate error"));
}
};
int ret = OCObt.provisionRoleCertificate(role, di, handler);
if (ret < 0) {
emitter.onError(new IOException("Provision role certificate error"));
}
});
}
public Completable createPskCredential(String endpoint, String deviceId, String targetUuid, byte[] symmetricKey) {
return Completable.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, di);
......@@ -308,10 +345,36 @@ public class CmsRepository {
});
}
public Completable provisionPairwiseCredential(String clientId, String serverId) {
return Completable.create(emitter -> {
OCUuid cliendDi = OCUuidUtil.stringToUuid(clientId);
OCUuid serverDi = OCUuidUtil.stringToUuid(serverId);
OCObtStatusHandler handler = (int status) -> {
if (status >= 0) {
LOG.debug("Successfully provisioned pair-wise credentials");
emitter.onComplete();
} else {
String errorMsg = "ERROR provisioning pair-wise credentials";
LOG.error(errorMsg);
emitter.onError(new Exception(errorMsg));
}
};
int ret = OCObt.provisionPairwiseCredentials(cliendDi, serverDi, handler);
if (ret >= 0) {
LOG.debug("Successfully issued request to provision credentials");
} else {
String errorMsg = "ERROR issuing request to provision credentials";
LOG.error(errorMsg);
emitter.onError(new Exception(errorMsg));
}
});
}
public Completable deleteCredential(String endpoint, String deviceId, long credId) {
return Completable.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid uuid = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, uuid);
......
......@@ -64,7 +64,7 @@ public class DoxsRepository {
if (status >= 0) {
LOG.debug("Successfully request Random PIN " + OCUuidUtil.uuidToString(ocUuid));
String pin = randomPinHandler.handler();
if (OCObt.performRandomPinOtm(uuid, pin, pin.length(), handler) != -1){
if (OCObt.performRandomPinOtm(uuid, pin, handler) != -1){
emitter.onComplete();
} else {
String error = "ERROR send random PIN on device " + OCUuidUtil.uuidToString(ocUuid);
......@@ -119,8 +119,7 @@ public class DoxsRepository {
public Single<OcDoxm> retrieveOTMethods(String endpoint) {
return Single.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCResponseHandler handler = (OCClientResponse response) -> {
OCStatus code = response.getCode();
......@@ -155,8 +154,7 @@ public class DoxsRepository {
public Single<OcDoxm> get(String endpoint, String deviceId) {
return Single.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid uuid = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, uuid);
......@@ -181,8 +179,7 @@ public class DoxsRepository {
public Completable post(String endpoint, String deviceId, OcDoxm doxm) {
return Completable.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid uuid = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, uuid);
......
......@@ -236,22 +236,45 @@ public class IotivityRepository {
OcRes res = new OcRes();
res.parseOCRepresentation(response.getPayload());
OcResource resource = res.getResourceList().get(0);
String deviceId = resource.getAnchor().replace("ocf://", "");
List<String> endpoints = new ArrayList<>();
for (OcEndpoint ep : resource.getEndpoints()) {
endpoints.add(ep.getEndpoint());
}
if (!res.getResourceList().isEmpty()) {
OcResource resource = res.getResourceList().get(0);
String deviceId = resource.getAnchor().replace("ocf://", "");
List<String> endpoints = new ArrayList<>();
for (OcEndpoint ep : resource.getEndpoints()) {
endpoints.add(ep.getEndpoint());
}
DeviceEntity device = deviceDao.findById(deviceId);
if (device == null) {
deviceDao.insert(new DeviceEntity(deviceId, "", endpoints, DeviceType.OWNED_BY_OTHER, Device.NOTHING_PERMITS));
allDevices.add(new Device(DeviceType.OWNED_BY_OTHER, deviceId, new OcDeviceInfo(), endpoints, Device.NOTHING_PERMITS));
} else {
deviceDao.insert(new DeviceEntity(deviceId, device.getName(), endpoints, device.getType(), device.getPermits()));
allDevices.add(new Device(device.getType(), deviceId, new OcDeviceInfo(), endpoints, device.getPermits()));
}
DeviceEntity device = deviceDao.findById(deviceId);
if (device == null) {
deviceDao.insert(new DeviceEntity(deviceId, "", endpoints, DeviceType.OWNED_BY_OTHER, Device.NOTHING_PERMITS));
allDevices.add(new Device(DeviceType.OWNED_BY_OTHER, deviceId, new OcDeviceInfo(), endpoints, Device.NOTHING_PERMITS));
} else {
boolean isUnowned = false;
for (Device d : unownedDevices) {
if (d.getDeviceId().equals(deviceId)) {
isUnowned = true;
break;
}
}
boolean isOwned = false;
for (Device d : ownedDevices) {
if (d.getDeviceId().equals(deviceId)) {
isOwned = true;
break;
}
}
if (!isUnowned && !isOwned) {
DeviceType deviceType = device.getType() == DeviceType.UNOWNED || device.getType() == DeviceType.OWNED_BY_SELF
? DeviceType.OWNED_BY_OTHER
: device.getType();
deviceDao.insert(new DeviceEntity(deviceId, device.getName(), endpoints, deviceType, device.getPermits()));
allDevices.add(new Device(deviceType, deviceId, new OcDeviceInfo(), endpoints, device.getPermits()));
}
}
}
}
};
......@@ -280,26 +303,6 @@ public class IotivityRepository {
public Observable<Device> scanOwnedByOtherDevices() {
return scanHosts()
.andThen(Observable.fromIterable(allDevices))
.filter(device -> {
boolean isNotUnowned = true;
for (Device d : unownedDevices) {
if (d.getDeviceId().equals(device.getDeviceId())) {
isNotUnowned = false;
}
}
return isNotUnowned;