Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

Commit

Permalink
Merge pull request #6 from openconnectivity/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
javiguerra committed Sep 19, 2019
2 parents 2a91e6a + cfbfdec commit 83eb1b9
Show file tree
Hide file tree
Showing 43 changed files with 1,040 additions and 591 deletions.
65 changes: 52 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion build/debian/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: OTGC
Version: 2.0.4
Version: 2.0.5
Section: custom
Priority: optional
Architecture: amd64
Expand Down
2 changes: 1 addition & 1 deletion build/debian/otgc_native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# Constants
PROJECT_NAME="otgc"
VERSION="2.0.4"
VERSION="2.0.5"

program=$0

Expand Down
2 changes: 1 addition & 1 deletion extlibs/iotivity-lite
Submodule iotivity-lite updated from a27228 to 1b955e
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public 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);

Expand All @@ -69,8 +68,7 @@ public Single<OcAcl> getAcl(String endpoint, String deviceId) {

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);

Expand Down Expand Up @@ -104,6 +102,42 @@ private Completable provisionAcl(String endpoint, String deviceId, OcAcl acl) {
});
}

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);
Expand All @@ -120,6 +154,19 @@ public Completable provisionUuidAcl(String endpoint, String deviceId, String sub
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);
Expand All @@ -137,6 +184,17 @@ public Completable provisionRoleAcl(String endpoint, String deviceId, String rol
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);
Expand All @@ -153,10 +211,72 @@ public Completable provisionConntypeAcl(String endpoint, String deviceId, boolea
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);

Expand Down Expand Up @@ -200,4 +320,35 @@ private List<OcAceResource> getResources(List<String> verticalResources) {

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;
}
}
Loading

0 comments on commit 83eb1b9

Please sign in to comment.