Commit 3d18dff6 authored by Larry Sachs's avatar Larry Sachs Committed by Rick Bell

Android OBT updates for Random PIN

Change-Id: I6c26b878872a4b3c07afa783efd04582ce9d9830
Signed-off-by: Larry Sachs's avatarLarry Sachs <larry.j.sachs@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/29410Tested-by: default avatarIoTivity Jenkins <jenkins-daemon@iotivity.org>
Reviewed-by: George Nash's avatarGeorge Nash <george.nash@intel.com>
Reviewed-by: default avatarRick Bell <richard.s.bell@intel.com>
parent 3336ea3b
......@@ -35,6 +35,10 @@ endif
RM ?= rm
MKDIR ?= mkdir
DYNAMIC ?= 1
SECURE ?= 1
PKI ?= 1
ROOT_DIR = ../..
SWIG_DIR := ../../swig/java_lang
OBJDIR ?= ./${ANDROID_HOST}obj
......@@ -51,7 +55,8 @@ DTLS= aes.c aesni.c arc4.c asn1parse.c asn1write.c base64.c \
sha512.c threading.c timing.c version.c version_features.c \
xtea.c pkcs11.c x509.c x509_crt.c debug.c net_sockets.c \
ssl_cache.c ssl_ciphersuites.c ssl_cli.c ssl_cookie.c \
ssl_srv.c ssl_ticket.c ssl_tls.c rsa_internal.c
ssl_srv.c ssl_ticket.c ssl_tls.c rsa_internal.c x509write_csr.c\
x509write_crt.c x509_create.c
DTLSFLAGS=-I../../deps/mbedtls/include -D__OC_RANDOM
CBOR=../../deps/tinycbor/src/cborencoder.c ../../deps/tinycbor/src/cborencoder_close_container_checked.c ../../deps/tinycbor/src/cborparser.c# ../../deps/tinycbor/src/cbortojson.c ../../deps/tinycbor/src/cborpretty.c ../../deps/tinycbor/src/cborparser_dup_string.c
......@@ -68,7 +73,7 @@ ifeq ($(shell if [ ${ANDROID_API} -gt 23 ]; then echo gt; fi),gt)
endif
HEADERS = $(wildcard ../../include/*.h)
HEADERS += ../../port/android/config.h
HEADERS += ../../port/android/oc_config.h
HEADERS_COAP = $(wildcard ../../messaging/coap/*.h)
HEADERS_UTIL = $(wildcard ../../util/*.h)
......@@ -79,7 +84,7 @@ HEADERS_TINYCBOR = $(wildcard ../../deps/tinycbor/src/*.h)
CFLAGS?=-fPIC -fno-asynchronous-unwind-tables -fno-omit-frame-pointer -ffreestanding -Os -fno-stack-protector -ffunction-sections -fdata-sections -fno-strict-overflow -I./ -I../../include/ -I../../ -std=gnu99 -Wall -D__ANDROID_API__=${ANDROID_API}
OBJ_COMMON=$(addprefix ${OBJDIR}/,$(notdir $(SRC_COMMON:.c=.o)))
OBJ_CLIENT=$(addprefix ${OBJDIR}/client/,$(notdir $(SRC:.c=.o)))
OBJ_SERVER=$(addprefix ${OBJDIR}/server/,$(filter-out oc_obt.o,$(notdir $(SRC:.c=.o))))
OBJ_SERVER=$(addprefix ${OBJDIR}/server/,$(filter-out oc_obt.o oc_obt.o oc_obt_otm_justworks.o oc_obt_otm_randompin.o,$(notdir $(SRC:.c=.o))))
OBJ_CLIENT_SERVER=$(addprefix ${OBJDIR}/client_server/,$(notdir $(SRC:.c=.o)))
OBJ_SWIG=$(addprefix ${OBJDIR}/swig/,$(notdir $(SWIG_SRC_C:.c=.o)))
......@@ -87,40 +92,46 @@ OBJ_SWIG=$(addprefix ${OBJDIR}/swig/,$(notdir $(SWIG_SRC_C:.c=.o)))
VPATH=../../messaging/coap/:../../util/:../../api/:../../deps/tinycbor/src/:../../deps/mbedtls/library:../../api/c-timestamp:
LIBS?= -lm
OBT = onboarding_tool
ifeq ($(DEBUG),1)
CFLAGS += -DOC_DEBUG -g -O0
ifeq ($(DEBUG_TLS),1)
CFLAGS += -DOC_DEBUG_TLS
endif
else
CFLAGS += -Wl,--gc-sections
endif
ifeq ($(PKI),1)
EXTRA_CFLAGS += -DOC_PKI
endif
ifeq ($(DYNAMIC),1)
CFLAGS += -DOC_DYNAMIC_ALLOCATION
EXTRA_CFLAGS += -DOC_DYNAMIC_ALLOCATION
endif
ifneq ($(SECURE),0)
SRC += $(addprefix ../../security/,oc_acl.c oc_cred.c oc_doxm.c oc_pstat.c oc_tls.c oc_svr.c oc_store.c)
SRC += $(addprefix ../../security/,oc_acl.c oc_cred.c oc_doxm.c oc_pstat.c oc_tls.c oc_svr.c oc_store.c oc_pki.c oc_certs.c oc_sp.c oc_keypair.c oc_csr.c oc_roles.c)
SRC_COMMON += $(addprefix $(MBEDTLS_DIR)/library/,${DTLS})
MBEDTLS_PATCH_FILE := $(MBEDTLS_DIR)/patched.txt
ifeq ($(DYNAMIC),1)
SRC += ../../security/oc_obt.c
SAMPLES += ${OBT}
SRC += ../../security/oc_obt.c ../../security/oc_obt_otm_justworks.c ../../security/oc_obt_otm_randompin.c
else
SRC_COMMON += $(MBEDTLS_DIR)/library/memory_buffer_alloc.c
endif
CFLAGS += ${DTLSFLAGS} -DOC_SECURITY
CFLAGS += ${DTLSFLAGS}
EXTRA_CFLAGS += -DOC_SECURITY
VPATH += ../../security/:../../deps/mbedtls/library:
endif
ifeq ($(IPV4),1)
CFLAGS += -DOC_IPV4
EXTRA_CFLAGS += -DOC_IPV4
endif
ifeq ($(TCP),1)
EXTRA_CFLAGS += -DOC_TCP
endif
CFLAGS += $(EXTRA_CFLAGS)
CFLAGS += -DLONG_BIT=64
CONSTRAINED_LIBS = libiotivity-constrained-client-server.so
......@@ -200,6 +211,6 @@ clean:
$(RM) -rf ${OBJDIR} $(CONSTRAINED_LIBS) *.so
cleanall: clean
$(RM) -rf ${all} $(SAMPLES) $(OBT) $(MBEDTLS_PATCH_FILE)
$(RM) -rf ${all} $(MBEDTLS_PATCH_FILE)
distclean: cleanall
......@@ -11,11 +11,14 @@ extern "C" {
typedef uint64_t oc_clock_time_t;
#define OC_CLOCK_CONF_TICKS_PER_SECOND CLOCKS_PER_SEC
#define OC_SPEC_VER_OIC
/* Security Layer */
/* Max inactivity timeout before tearing down DTLS connection */
#define OC_DTLS_INACTIVITY_TIMEOUT (600)
/* Maximum wait time for select function */
#define SELECT_TIMEOUT_SEC (1)
/* Add support for passing network up/down events to the app */
#define OC_NETWORK_MONITOR
/* Add support for passing TCP/TLS/DTLS session connection events to the app */
......
package org.iotivity.onboardingtool;
import android.util.Log;
import android.widget.Toast;
import org.iotivity.OCObtDeviceStatusHandler;
import org.iotivity.OCUuid;
import org.iotivity.OCUuidUtil;
public class GenerateRandomPinHandler implements OCObtDeviceStatusHandler {
private static final String TAG = GenerateRandomPinHandler.class.getSimpleName();
private OnBoardingActivity activity;
public GenerateRandomPinHandler(OnBoardingActivity activity) {
this.activity = activity;
}
@Override
public void handler(OCUuid uuid, int status) {
String deviceId = OCUuidUtil.uuidToString(uuid);
final String msg = (status >= 0) ?
"Successfully generated Random PIN on device " + deviceId :
"Error generating Random PIN on device " + deviceId + ", status = " + status;
Log.d(TAG, msg);
activity.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(activity, msg, Toast.LENGTH_LONG).show();
}
});
}
}
......@@ -10,6 +10,8 @@ import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.Toast;
......@@ -130,11 +132,11 @@ public class OnBoardingActivity extends AppCompatActivity {
break;
case 2: // Reset Device
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(OnBoardingActivity.this);
alertDialogBuilder.setTitle(uuid);
alertDialogBuilder.setMessage(getResources().getStringArray(R.array.ownedDeviceActions)[2]);
AlertDialog.Builder resetDialogBuilder = new AlertDialog.Builder(OnBoardingActivity.this);
resetDialogBuilder.setTitle(uuid);
resetDialogBuilder.setMessage(getResources().getStringArray(R.array.ownedDeviceActions)[2]);
alertDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
resetDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new Thread(new Runnable() {
......@@ -155,13 +157,13 @@ public class OnBoardingActivity extends AppCompatActivity {
}
});
alertDialogBuilder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
resetDialogBuilder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
Dialog resetDeviceDialog = alertDialogBuilder.create();
Dialog resetDeviceDialog = resetDialogBuilder.create();
resetDeviceDialog.show();
break;
......@@ -187,37 +189,137 @@ public class OnBoardingActivity extends AppCompatActivity {
if (uuid != null) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(OnBoardingActivity.this);
alertDialogBuilder.setTitle(uuid);
alertDialogBuilder.setMessage(R.string.justWorks);
alertDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
alertDialogBuilder.setItems(R.array.unownedDeviceActions, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new Thread(new Runnable() {
public void run() {
if (OCObt.performJustWorksOtm(OCUuidUtil.stringToUuid(uuid), new JustWorksHandler(OnBoardingActivity.this)) < 0) {
final String msg = "Failed to perform ownership transfer for uuid " + uuid;
Log.d(TAG, msg);
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(OnBoardingActivity.this, msg, Toast.LENGTH_LONG).show();
}
});
} else {
removeUnownedDevice(uuid);
}
}
}).start();
}
});
switch (which) {
case 0: // Just Works OTM
AlertDialog.Builder justWorksOtmDialogBuilder = new AlertDialog.Builder(OnBoardingActivity.this);
justWorksOtmDialogBuilder.setTitle(uuid);
justWorksOtmDialogBuilder.setMessage(getResources().getStringArray(R.array.unownedDeviceActions)[0]);
alertDialogBuilder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
justWorksOtmDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new Thread(new Runnable() {
public void run() {
if (OCObt.performJustWorksOtm(OCUuidUtil.stringToUuid(uuid), new JustWorksHandler(OnBoardingActivity.this)) < 0) {
final String msg = "Failed to perform ownership transfer for uuid " + uuid;
Log.d(TAG, msg);
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(OnBoardingActivity.this, msg, Toast.LENGTH_LONG).show();
}
});
} else {
removeUnownedDevice(uuid);
}
}
}).start();
}
});
justWorksOtmDialogBuilder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
Dialog justWorksOtmDialog = justWorksOtmDialogBuilder.create();
justWorksOtmDialog.show();
break;
case 1: // Generate Random Pin
AlertDialog.Builder generateRandomPinDialogBuilder = new AlertDialog.Builder(OnBoardingActivity.this);
generateRandomPinDialogBuilder.setTitle(uuid);
generateRandomPinDialogBuilder.setMessage(getResources().getStringArray(R.array.unownedDeviceActions)[1]);
generateRandomPinDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new Thread(new Runnable() {
public void run() {
if (OCObt.requestRandomPin(OCUuidUtil.stringToUuid(uuid), new GenerateRandomPinHandler(OnBoardingActivity.this)) < 0) {
final String msg = "Failed to generate random pin for uuid " + uuid;
Log.d(TAG, msg);
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(OnBoardingActivity.this, msg, Toast.LENGTH_LONG).show();
}
});
}
}
}).start();
}
});
generateRandomPinDialogBuilder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
Dialog generateRandomPinDialog = generateRandomPinDialogBuilder.create();
generateRandomPinDialog.show();
break;
case 2: // Random Pin OTM
LinearLayout layout = new LinearLayout(OnBoardingActivity.this);
layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
layout.setOrientation(LinearLayout.VERTICAL);
final EditText input = new EditText(OnBoardingActivity.this);
layout.addView(input);
AlertDialog.Builder randomPinOtmDialogBuilder = new AlertDialog.Builder(OnBoardingActivity.this);
randomPinOtmDialogBuilder.setTitle(uuid);
randomPinOtmDialogBuilder.setMessage(R.string.enterPin);
randomPinOtmDialogBuilder.setView(layout);
randomPinOtmDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new Thread(new Runnable() {
public void run() {
String pin = input.getText().toString().trim();
if (pin.length() > 24) {
pin = pin.substring(0, 24);
}
Log.d(TAG, "PIN = " + pin);
if (OCObt.performRandomPinOtm(OCUuidUtil.stringToUuid(uuid), pin, pin.length(), new OtmRandomPinHandler(OnBoardingActivity.this)) < 0) {
final String msg = "Failed to perform ownership transfer for uuid " + uuid;
Log.d(TAG, msg);
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(OnBoardingActivity.this, msg, Toast.LENGTH_LONG).show();
}
});
} else {
removeUnownedDevice(uuid);
}
}
}).start();
}
});
randomPinOtmDialogBuilder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
Dialog randomPinOtmDialog = randomPinOtmDialogBuilder.create();
randomPinOtmDialog.show();
break;
default:
break;
}
}
});
Dialog justWorksDialog = alertDialogBuilder.create();
justWorksDialog.show();
Dialog unownedDeviceDialog = alertDialogBuilder.create();
unownedDeviceDialog.show();
} else {
Log.w(TAG, "Uuid not found in list");
......@@ -319,8 +421,9 @@ public class OnBoardingActivity extends AppCompatActivity {
@Override
protected void onDestroy() {
Log.d(TAG, "Calling main_shutdown.");
Log.d(TAG, "Calling Shutdown.");
OCMain.mainShutdown();
OCObt.shutdown();
super.onDestroy();
}
......
package org.iotivity.onboardingtool;
import android.util.Log;
import android.widget.Toast;
import org.iotivity.OCObtDeviceStatusHandler;
import org.iotivity.OCUuid;
import org.iotivity.OCUuidUtil;
public class OtmRandomPinHandler implements OCObtDeviceStatusHandler {
private static final String TAG = OtmRandomPinHandler.class.getSimpleName();
private OnBoardingActivity activity;
public OtmRandomPinHandler(OnBoardingActivity activity) {
this.activity = activity;
}
@Override
public void handler(OCUuid uuid, int status) {
String deviceId = OCUuidUtil.uuidToString(uuid);
final String msg = (status >= 0) ?
"Successfully performed OTM on device " + deviceId :
"Error performing ownership transfer on device " + deviceId + ", status = " + status;
Log.d(TAG, msg);
activity.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(activity, msg, Toast.LENGTH_LONG).show();
}
});
}
}
......@@ -3,7 +3,7 @@
<string name="owned">Owned</string>
<string name="unowned">Unowned</string>
<string name="refresh">Refresh</string>
<string name="justWorks">Take ownership of device (Just Works)</string>
<string name="enterPin">Enter PIN</string>
<string name="selectDevice">Select device for pairing</string>
<string name="selectAceSubject">Select subject or device</string>
<string name="aceAnonClear">anon-clear</string>
......@@ -16,6 +16,11 @@
<string name="interfacesDialogTitle">Select Resource ? Interfaces (if any)</string>
<string name="addMoreResourceDialogMessage">Add more resources to this ACE?</string>
<string name="permissionsDialogTitle">Select ACE Permissions (if any)</string>
<string-array name="unownedDeviceActions">
<item>Just-Works Ownership Transfer Method</item>
<item>Request Random PIN from device for OTM</item>
<item>Random PIN Ownership Transfer Method</item>
</string-array>
<string-array name="ownedDeviceActions">
<item>Provision pair-wise credentials</item>
<item>Provision ACE2</item>
......
......@@ -29,6 +29,7 @@ public class GetLightRequestHandler implements OCRequestHandler {
activity.msg("Get Light:");
++light.power; // auto increment
light.state = !light.state; // auto toggle
activity.msg("\t" + light.name + ", " + light.power + ", " + light.state);
activity.printLine();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment