aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Tang <gtang@affinegy.com>2016-09-18 18:07:00 -0500
committerRy Jones <rjones@linuxfoundation.org>2016-09-23 23:58:30 +0000
commit19168181bd2de22e6fcaae0953a6afe9835570a2 (patch)
tree32c2933619f10472600e29ed48eaa194374d51ae
parentf69152d3ce3c87e3522935263cf3896f4d4707a4 (diff)
ASACORE-3156 Sec2 PermissionConfigurationListener
added jni and java implementation of PermissionConfigurationListener added to the test for PermissionConfigurator added enablePeerSecurity exposure that uses the PermissionConfigurationListener Fixed some problems with GetSigningPublicKey -method signature -return type It appears KeyInfoECC in common doesn't return a valid public key on GetPublicKey, so you must use KeyInfoNISTP256 instead. Also, java will have a class cast exception if the java method definition returns KeyInfoECC and if the returned object is casted to KeyInfoNISTP256, even if you are calling KeyInfoNISTP256 constructor from the JNI layer. Change-Id: I826642b5df5a1aaf3bc62117986acbac5c5bda65 Signed-off-by: George Tang <gtang@affinegy.com>
-rw-r--r--alljoyn_java/jni/JBusAttachment.h3
-rw-r--r--alljoyn_java/jni/JPermissionConfigurationListener.cc227
-rw-r--r--alljoyn_java/jni/JPermissionConfigurationListener.h45
-rw-r--r--alljoyn_java/jni/PermissionConfigurator.cc13
-rw-r--r--alljoyn_java/jni/SConscript2
-rw-r--r--alljoyn_java/jni/alljoyn_java.cc18
-rw-r--r--alljoyn_java/jni/alljoyn_jni_helper.h1
-rw-r--r--alljoyn_java/src/org/alljoyn/bus/BusAttachment.java43
-rw-r--r--alljoyn_java/src/org/alljoyn/bus/PermissionConfigurationListener.java43
-rw-r--r--alljoyn_java/src/org/alljoyn/bus/PermissionConfigurator.java2
-rw-r--r--alljoyn_java/test/org/alljoyn/bus/PermissionConfiguratorTest.java76
11 files changed, 454 insertions, 19 deletions
diff --git a/alljoyn_java/jni/JBusAttachment.h b/alljoyn_java/jni/JBusAttachment.h
index 467cbcc..7685cca 100644
--- a/alljoyn_java/jni/JBusAttachment.h
+++ b/alljoyn_java/jni/JBusAttachment.h
@@ -32,6 +32,7 @@
#include <alljoyn/DBusStd.h>
#include "JAuthListener.h"
+#include "JPermissionConfigurationListener.h"
#include "JKeyStoreListener.h"
#include "JSignalHandler.h"
#include "JAboutObject.h"
@@ -55,7 +56,7 @@ class JBusAttachment : public ajn::BusAttachment {
QStatus Connect(const char* connectArgs, jobject jkeyStoreListener, const char* authMechanisms,
jobject jauthListener, const char* keyStoreFileName, jboolean isShared);
void Disconnect();
- QStatus EnablePeerSecurity(const char* authMechanisms, jobject jauthListener, const char* keyStoreFileName, jboolean isShared);
+ QStatus EnablePeerSecurity(const char* authMechanisms, jobject jauthListener, const char* keyStoreFileName, jboolean isShared, JPermissionConfigurationListener jpcl = NULL);
QStatus RegisterBusObject(const char* objPath, jobject jbusObject, jobjectArray jbusInterfaces,
jboolean jsecure, jstring jlangTag, jstring jdesc, jobject jtranslator);
void UnregisterBusObject(jobject jbusObject);
diff --git a/alljoyn_java/jni/JPermissionConfigurationListener.cc b/alljoyn_java/jni/JPermissionConfigurationListener.cc
new file mode 100644
index 0000000..7920db1
--- /dev/null
+++ b/alljoyn_java/jni/JPermissionConfigurationListener.cc
@@ -0,0 +1,227 @@
+/******************************************************************************
+ * Copyright AllSeen Alliance. All rights reserved.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ******************************************************************************/
+
+#include <jni.h>
+#include <alljoyn/PermissionConfigurationListener.h>
+#include <qcc/Debug.h>
+
+#include "JPermissionConfigurationListener.h"
+#include "alljoyn_jni_helper.h"
+
+#define QCC_MODULE "JNI_PCNFLSTNR"
+
+JPermissionConfigurationListener::JPermissionConfigurationListener(jobject jlistener) : jpcListener(NULL)
+{
+ QCC_DbgTrace(("%s", __FUNCTION__));
+
+ JNIEnv* env = GetEnv();
+
+ if (!jlistener) {
+ QCC_LogError(ER_FAIL, ("%s: jlistener null", __FUNCTION__));
+ return;
+ }
+
+ QCC_DbgPrintf(("%s: Taking weak global reference to listener %p", __FUNCTION__, jlistener));
+ jpcListener = env->NewWeakGlobalRef(jlistener);
+ if (!jpcListener) {
+ QCC_LogError(ER_FAIL, ("%s: Can't create new weak global reference", __FUNCTION__));
+ return;
+ }
+
+ JLocalRef<jclass> clazz = env->GetObjectClass(jlistener);
+ if (!clazz) {
+ QCC_LogError(ER_FAIL, ("%s: Can't GetObjectClass()", __FUNCTION__));
+ return;
+ }
+
+ MID_factoryReset = env->GetMethodID(clazz, "factoryReset", "()Lorg/alljoyn/bus/Status;");
+ if (!MID_factoryReset) {
+ QCC_DbgPrintf(("%s: Can't find factoryReset", __FUNCTION__));
+ }
+
+ MID_policyChanged = env->GetMethodID(clazz, "policyChanged", "()V");
+ if (!MID_policyChanged) {
+ QCC_DbgPrintf(("%s: Can't find policyChanged", __FUNCTION__));
+ }
+
+ MID_startManagement = env->GetMethodID(clazz, "startManagement", "()V");
+ if (!MID_startManagement) {
+ QCC_DbgPrintf(("%s: Can't find startManagement", __FUNCTION__));
+ }
+
+ MID_endManagement = env->GetMethodID(clazz, "endManagement", "()V");
+ if (!MID_endManagement) {
+ QCC_DbgPrintf(("%s: Can't find endManagement", __FUNCTION__));
+ }
+}
+
+JPermissionConfigurationListener::~JPermissionConfigurationListener()
+{
+ QCC_DbgTrace(("%s", __FUNCTION__));
+ if (jpcListener) {
+ QCC_DbgPrintf(("%s: Releasing weak global reference to listener %p", __FUNCTION__, jpcListener));
+ GetEnv()->DeleteWeakGlobalRef(jpcListener);
+ jpcListener = NULL;
+ }
+}
+
+QStatus JPermissionConfigurationListener::FactoryReset()
+{
+ QCC_DbgTrace(("%s", __FUNCTION__));
+
+ /*
+ * JScopedEnv will automagically attach the JVM to the current native
+ * thread.
+ */
+ JScopedEnv env;
+
+ /*
+ * The weak global reference jpinglistener cannot be directly used. We have to get
+ * a "hard" reference to it and then use that. If you try to use a weak reference
+ * directly you will crash and burn.
+ */
+ jobject jo = env->NewLocalRef(jpcListener);
+ if (!jo) {
+ QCC_LogError(ER_FAIL, ("%s: Can't get new local reference to listener", __FUNCTION__));
+ return ER_FAIL;
+ }
+
+ /*
+ * This call out to the listener means that the DestinationFound method
+ * must be MT-Safe. This is implied by the definition of the listener.
+ */
+ QCC_DbgPrintf(("%s: Call out to listener object and method", __FUNCTION__));
+ jobject status = env->CallObjectMethod(jo, MID_factoryReset);
+ if (env->ExceptionCheck()) {
+ QCC_LogError(ER_FAIL, ("%s: Exception", __FUNCTION__));
+ return ER_FAIL;
+ }
+
+ jfieldID fid = env->GetFieldID(CLS_Status, "errorCode", "I");
+ if (!fid) {
+ QCC_LogError(ER_FAIL, ("%s: Can't find errorCode field ID in Status", __FUNCTION__));
+ return ER_FAIL;
+ }
+
+ jint jerrorCode = env->GetIntField(status, fid);
+ if (env->ExceptionCheck()) {
+ QCC_LogError(ER_FAIL, ("%s: Can't get int errorcode from Status", __FUNCTION__));
+ return ER_FAIL;
+ }
+
+ return static_cast<QStatus>(jerrorCode);
+}
+
+void JPermissionConfigurationListener::PolicyChanged()
+{
+ QCC_DbgTrace(("%s", __FUNCTION__));
+
+ /*
+ * JScopedEnv will automagically attach the JVM to the current native
+ * thread.
+ */
+ JScopedEnv env;
+
+ /*
+ * The weak global reference jpinglistener cannot be directly used. We have to get
+ * a "hard" reference to it and then use that. If you try to use a weak reference
+ * directly you will crash and burn.
+ */
+ jobject jo = env->NewLocalRef(jpcListener);
+ if (!jo) {
+ QCC_LogError(ER_FAIL, ("%s: Can't get new local reference to listener", __FUNCTION__));
+ return;
+ }
+
+ /*
+ * This call out to the listener means that the DestinationFound method
+ * must be MT-Safe. This is implied by the definition of the listener.
+ */
+ QCC_DbgPrintf(("%s: Call out to listener object and method", __FUNCTION__));
+ env->CallObjectMethod(jo, MID_policyChanged);
+ if (env->ExceptionCheck()) {
+ QCC_LogError(ER_FAIL, ("%s: Exception", __FUNCTION__));
+ }
+
+}
+
+void JPermissionConfigurationListener::StartManagement()
+{
+ QCC_DbgTrace(("%s", __FUNCTION__));
+
+ /*
+ * JScopedEnv will automagically attach the JVM to the current native
+ * thread.
+ */
+ JScopedEnv env;
+
+ /*
+ * The weak global reference jpinglistener cannot be directly used. We have to get
+ * a "hard" reference to it and then use that. If you try to use a weak reference
+ * directly you will crash and burn.
+ */
+ jobject jo = env->NewLocalRef(jpcListener);
+ if (!jo) {
+ QCC_LogError(ER_FAIL, ("%s: Can't get new local reference to listener", __FUNCTION__));
+ return;
+ }
+
+ /*
+ * This call out to the listener means that the DestinationFound method
+ * must be MT-Safe. This is implied by the definition of the listener.
+ */
+ QCC_DbgPrintf(("%s: Call out to listener object and method", __FUNCTION__));
+ env->CallObjectMethod(jo, MID_startManagement);
+ if (env->ExceptionCheck()) {
+ QCC_LogError(ER_FAIL, ("%s: Exception", __FUNCTION__));
+ }
+
+}
+
+void JPermissionConfigurationListener::EndManagement()
+{
+ QCC_DbgTrace(("%s", __FUNCTION__));
+
+ /*
+ * JScopedEnv will automagically attach the JVM to the current native
+ * thread.
+ */
+ JScopedEnv env;
+
+ /*
+ * The weak global reference jpinglistener cannot be directly used. We have to get
+ * a "hard" reference to it and then use that. If you try to use a weak reference
+ * directly you will crash and burn.
+ */
+ jobject jo = env->NewLocalRef(jpcListener);
+ if (!jo) {
+ QCC_LogError(ER_FAIL, ("%s: Can't get new local reference to listener", __FUNCTION__));
+ return;
+ }
+
+ /*
+ * This call out to the listener means that the DestinationFound method
+ * must be MT-Safe. This is implied by the definition of the listener.
+ */
+ QCC_DbgPrintf(("%s: Call out to listener object and method", __FUNCTION__));
+ env->CallObjectMethod(jo, MID_endManagement);
+ if (env->ExceptionCheck()) {
+ QCC_LogError(ER_FAIL, ("%s: Exception", __FUNCTION__));
+ }
+
+}
+
diff --git a/alljoyn_java/jni/JPermissionConfigurationListener.h b/alljoyn_java/jni/JPermissionConfigurationListener.h
new file mode 100644
index 0000000..d582915
--- /dev/null
+++ b/alljoyn_java/jni/JPermissionConfigurationListener.h
@@ -0,0 +1,45 @@
+/******************************************************************************
+ * Copyright AllSeen Alliance. All rights reserved.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ******************************************************************************/
+#ifndef _ALLJOYN_JPERMISSIONCONFIGURATIONLISTENER_H
+#define _ALLJOYN_JPERMISSIONCONFIGURATIONLISTENER_H
+
+#include <jni.h>
+#include <alljoyn/PermissionConfigurationListener.h>
+
+class JBusAttachment;
+
+class JPermissionConfigurationListener : public ajn::PermissionConfigurationListener {
+ public:
+
+ JPermissionConfigurationListener(jobject jlistener);
+ ~JPermissionConfigurationListener();
+ QStatus FactoryReset();
+ void PolicyChanged();
+ void StartManagement();
+ void EndManagement();
+
+ private:
+
+ JBusAttachment* busPtr;
+ jweak jpcListener;
+ jmethodID MID_factoryReset;
+ jmethodID MID_policyChanged;
+ jmethodID MID_startManagement;
+ jmethodID MID_endManagement;
+};
+
+#endif
diff --git a/alljoyn_java/jni/PermissionConfigurator.cc b/alljoyn_java/jni/PermissionConfigurator.cc
index 51739b9..b8384c8 100644
--- a/alljoyn_java/jni/PermissionConfigurator.cc
+++ b/alljoyn_java/jni/PermissionConfigurator.cc
@@ -203,15 +203,20 @@ JNIEXPORT jobject JNICALL Java_org_alljoyn_bus_PermissionConfigurator_getSigning
return NULL;
}
- KeyInfoECC keyInfoECC;
- QStatus status = pconfPtr->GetSigningPublicKey(keyInfoECC);
+ KeyInfoNISTP256 keyInfo;
+ QStatus status = pconfPtr->GetSigningPublicKey(keyInfo);
if (status != ER_OK) {
jenv->ThrowNew(CLS_BusException, QCC_StatusText(status));
return NULL;
}
- const ECCPublicKey* retKey = keyInfoECC.GetPublicKey();
+ const ECCPublicKey* retKey = keyInfo.GetPublicKey();
+ if (retKey == NULL) {
+ QCC_LogError(ER_FAIL, ("%s: retKey is null", __FUNCTION__));
+ jenv->ThrowNew(CLS_BusException, QCC_StatusText(ER_FAIL));
+ return NULL;
+ }
jmethodID mid = jenv->GetMethodID(CLS_KeyInfoNISTP256, "<init>", "()V");
if (!mid) {
@@ -232,7 +237,7 @@ JNIEXPORT jobject JNICALL Java_org_alljoyn_bus_PermissionConfigurator_getSigning
jobject jretKey = jenv->NewObject(CLS_ECCPublicKey, midC, arrayX.move(), arrayY.move());
- jmethodID midSet = jenv->GetMethodID(CLS_KeyInfoNISTP256, "setPublicKey", "(Lorg/alljoyn/bus/common/ECCPublicKey;)");
+ jmethodID midSet = jenv->GetMethodID(CLS_KeyInfoNISTP256, "setPublicKey", "(Lorg/alljoyn/bus/common/ECCPublicKey;)V");
if (!midSet) {
QCC_LogError(ER_FAIL, ("%s: Can't find setPublicKey", __FUNCTION__));
return NULL;
diff --git a/alljoyn_java/jni/SConscript b/alljoyn_java/jni/SConscript
index 2cffbb7..91f6711 100644
--- a/alljoyn_java/jni/SConscript
+++ b/alljoyn_java/jni/SConscript
@@ -16,7 +16,7 @@
Import('env')
# JNI library sources
-srcs = ['alljoyn_java.cc', 'alljoyn_jni_helper.cc', 'CryptoECC.cc', 'SecurityApplicationProxy.cc', 'PermissionConfigurator.cc', 'CertificateX509.cc']
+srcs = env.Glob('*.cc')
# JNI library
bdenv = env.Clone()
diff --git a/alljoyn_java/jni/alljoyn_java.cc b/alljoyn_java/jni/alljoyn_java.cc
index a27ac1f..6254e15 100644
--- a/alljoyn_java/jni/alljoyn_java.cc
+++ b/alljoyn_java/jni/alljoyn_java.cc
@@ -45,6 +45,7 @@
#include <BusInternal.h>
#include "JBusAttachment.h"
+#include "JPermissionConfigurationListener.h"
#include "alljoyn_java.h"
#include "alljoyn_jni_helper.h"
@@ -762,7 +763,7 @@ static jclass CLS_BusObjectListener = NULL;
static jclass CLS_MessageContext = NULL;
static jclass CLS_MsgArg = NULL;
static jclass CLS_Signature = NULL;
-static jclass CLS_Status = NULL;
+jclass CLS_Status = NULL;
static jclass CLS_Variant = NULL;
static jclass CLS_BusAttachment = NULL;
static jclass CLS_SessionOpts = NULL;
@@ -4082,7 +4083,7 @@ void JBusAttachment::Disconnect()
gBusObjectMapLock.Unlock();
}
-QStatus JBusAttachment::EnablePeerSecurity(const char* authMechanisms, jobject jauthListener, const char* keyStoreFileName, jboolean isShared)
+QStatus JBusAttachment::EnablePeerSecurity(const char* authMechanisms, jobject jauthListener, const char* keyStoreFileName, jboolean isShared, JPermissionConfigurationListener jpcl)
{
QCC_DbgPrintf(("JBusAttachment::EnablePeerSecurity()"));
@@ -4169,7 +4170,7 @@ QStatus JBusAttachment::EnablePeerSecurity(const char* authMechanisms, jobject j
QCC_DbgPrintf(("JBusAttachment::EnablePeerSecurity(): Releasing Bus Attachment common lock"));
baCommonLock.Unlock();
- QStatus status = BusAttachment::EnablePeerSecurity(authMechanisms, authListener, keyStoreFileName, isShared);
+ QStatus status = BusAttachment::EnablePeerSecurity(authMechanisms, authListener, keyStoreFileName, isShared, &jpcl);
/*
* We're back, and depending on what has happened out from under us we
@@ -8053,8 +8054,7 @@ JNIEXPORT void JNICALL Java_org_alljoyn_bus_BusAttachment_nativeDisconnect(JNIEn
busPtr->Disconnect();
}
-JNIEXPORT jobject JNICALL Java_org_alljoyn_bus_BusAttachment_enablePeerSecurity(JNIEnv* env, jobject thiz, jstring jauthMechanisms, jobject jauthListener,
- jstring jkeyStoreFileName, jboolean isShared)
+JNIEXPORT jobject JNICALL Java_org_alljoyn_bus_BusAttachment_enablePeerSecurity(JNIEnv* env, jobject thiz, jstring jauthMechanisms, jobject jauthListener, jstring jkeyStoreFileName, jboolean isShared, jobject jpclistener)
{
QCC_DbgPrintf(("BusAttachment_enablePeerSecurity()"));
@@ -8068,6 +8068,12 @@ JNIEXPORT jobject JNICALL Java_org_alljoyn_bus_BusAttachment_enablePeerSecurity(
return NULL;
}
+ JPermissionConfigurationListener permListener(jpclistener);
+ if (env->ExceptionCheck()) {
+ env->ExceptionClear();
+ permListener = NULL;
+ }
+
JBusAttachment* busPtr = GetHandle<JBusAttachment*>(thiz);
if (env->ExceptionCheck()) {
return NULL;
@@ -8085,7 +8091,7 @@ JNIEXPORT jobject JNICALL Java_org_alljoyn_bus_BusAttachment_enablePeerSecurity(
QCC_DbgPrintf(("BusAttachment_enablePeerSecurity(): Refcount on busPtr is %d", busPtr->GetRef()));
- QStatus status = busPtr->EnablePeerSecurity(authMechanisms.c_str(), jauthListener, keyStoreFileName.c_str(), isShared);
+ QStatus status = busPtr->EnablePeerSecurity(authMechanisms.c_str(), jauthListener, keyStoreFileName.c_str(), isShared, permListener);
if (env->ExceptionCheck()) {
QCC_LogError(ER_FAIL, ("BusAttachment_enablePeerSecurity(): Exception"));
return NULL;
diff --git a/alljoyn_java/jni/alljoyn_jni_helper.h b/alljoyn_java/jni/alljoyn_jni_helper.h
index a0a4858..09fa473 100644
--- a/alljoyn_java/jni/alljoyn_jni_helper.h
+++ b/alljoyn_java/jni/alljoyn_jni_helper.h
@@ -22,6 +22,7 @@
#include <alljoyn/MsgArg.h>
extern jclass CLS_BusException;
+extern jclass CLS_Status;
extern jclass CLS_ECCPublicKey;
extern jclass CLS_ECCPrivateKey;
diff --git a/alljoyn_java/src/org/alljoyn/bus/BusAttachment.java b/alljoyn_java/src/org/alljoyn/bus/BusAttachment.java
index c0bf09f..0a40863 100644
--- a/alljoyn_java/src/org/alljoyn/bus/BusAttachment.java
+++ b/alljoyn_java/src/org/alljoyn/bus/BusAttachment.java
@@ -1100,7 +1100,7 @@ public class BusAttachment {
private native void nativeDisconnect();
private native Status enablePeerSecurity(String authMechanisms,
- AuthListenerInternal busAuthListener, String keyStoreFileName, boolean isShared);
+ AuthListenerInternal busAuthListener, String keyStoreFileName, boolean isShared, PermissionConfigurationListener pcl);
private native Status registerBusObject(String objPath, BusObject busObj,
InterfaceDescription[] busInterfaces, boolean secure,
@@ -1770,10 +1770,11 @@ public class BusAttachment {
* programs must have read/write
* permissions to the keyStoreFileName
* file.
+ * @param pcl PermissionConfigurationListener enables security 2.0
* @return OK if successful
*/
public Status registerAuthListener(String authMechanisms, AuthListener listener,
- String keyStoreFileName, boolean isShared) {
+ String keyStoreFileName, boolean isShared, PermissionConfigurationListener pcl) {
/*
* It is not possible to register multiple AuthListeners or replace an
@@ -1788,7 +1789,7 @@ public class BusAttachment {
this.keyStoreFileName = keyStoreFileName;
this.isShared = isShared;
Status status = enablePeerSecurity(this.authMechanisms, busAuthListener,
- this.keyStoreFileName, isShared);
+ this.keyStoreFileName, isShared, pcl);
if (status != Status.OK) {
busAuthListener.setAuthListener(null);
this.authMechanisms = null;
@@ -1797,6 +1798,38 @@ public class BusAttachment {
}
/**
+ * Registers a user-defined authentication listener class with a specific
+ * default key store.
+ *
+ * @param authMechanisms the authentication mechanism(s) to use
+ * for peer-to-peer authentication. This
+ * is a space separated list of any of the
+ * following values: ALLJOYN_SRP_LOGON,
+ * ALLJOYN_SRP_KEYX, ALLJOYN_ECDHE_NULL,
+ * ALLJOYN_ECDHE_PSK, ALLJOYN_ECDHE_ECDSA,
+ * GSSAPI.
+ * @param listener the authentication listener
+ * @param keyStoreFileName the name of the default key store.
+ * Under Android, the recommended value of
+ * this parameter is {@code
+ * Context.getFileStreamPath("alljoyn_keystore").getAbsolutePath()}.
+ * Note that the default key store
+ * implementation may be overrided with
+ * {@link
+ * #registerKeyStoreListener(KeyStoreListener)}.
+ * @param isShared Set to true if the default keystore will be
+ * shared between multiple programs. All
+ * programs must have read/write
+ * permissions to the keyStoreFileName
+ * file.
+ * @return OK if successful
+ */
+ public Status registerAuthListener(String authMechanisms, AuthListener listener,
+ String keyStoreFileName, boolean isShared) {
+ return registerAuthListener(authMechanisms, listener, keyStoreFileName, isShared, null);
+ }
+
+ /**
* Registers a user-defined authentication listener class with a specific default key store.
*
* @param authMechanisms the authentication mechanism(s) to use
@@ -1819,7 +1852,7 @@ public class BusAttachment {
*/
public Status registerAuthListener(String authMechanisms, AuthListener listener,
String keyStoreFileName){
- return registerAuthListener(authMechanisms, listener, keyStoreFileName, false);
+ return registerAuthListener(authMechanisms, listener, keyStoreFileName, false, null);
}
/**
@@ -1838,7 +1871,7 @@ public class BusAttachment {
* @return OK if successful
*/
public Status registerAuthListener(String authMechanisms, AuthListener listener) {
- return registerAuthListener(authMechanisms, listener, null, false);
+ return registerAuthListener(authMechanisms, listener, null, false, null);
}
/**
diff --git a/alljoyn_java/src/org/alljoyn/bus/PermissionConfigurationListener.java b/alljoyn_java/src/org/alljoyn/bus/PermissionConfigurationListener.java
new file mode 100644
index 0000000..e869d7d
--- /dev/null
+++ b/alljoyn_java/src/org/alljoyn/bus/PermissionConfigurationListener.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright AllSeen Alliance. All rights reserved.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package org.alljoyn.bus;
+
+public interface PermissionConfigurationListener {
+
+ /**
+ * Handler for doing a factory reset of application state.
+ *
+ * @return Return ER_OK if the application state reset was successful.
+ */
+ Status factoryReset();
+
+ /**
+ * Notification that the security manager has updated the security policy
+ * for the application.
+ */
+ void policyChanged();
+
+ /**
+ * Notification provided before Security Manager is starting to change settings for this application.
+ */
+ void startManagement();
+
+ /**
+ * Notification provided after Security Manager finished changing settings for this application.
+ */
+ void endManagement();
+}
diff --git a/alljoyn_java/src/org/alljoyn/bus/PermissionConfigurator.java b/alljoyn_java/src/org/alljoyn/bus/PermissionConfigurator.java
index 6518be1..db48350 100644
--- a/alljoyn_java/src/org/alljoyn/bus/PermissionConfigurator.java
+++ b/alljoyn_java/src/org/alljoyn/bus/PermissionConfigurator.java
@@ -112,7 +112,7 @@ public class PermissionConfigurator {
* @return keyInfo the public key info
* @throws BusException an error code.
*/
- public native KeyInfoECC getSigningPublicKey() throws BusException;
+ public native KeyInfoNISTP256 getSigningPublicKey() throws BusException;
/**
* Sign the X509 certificate using the signing key
diff --git a/alljoyn_java/test/org/alljoyn/bus/PermissionConfiguratorTest.java b/alljoyn_java/test/org/alljoyn/bus/PermissionConfiguratorTest.java
index 11730ed..0b9ba49 100644
--- a/alljoyn_java/test/org/alljoyn/bus/PermissionConfiguratorTest.java
+++ b/alljoyn_java/test/org/alljoyn/bus/PermissionConfiguratorTest.java
@@ -19,6 +19,9 @@ import junit.framework.TestCase;
import java.io.File;
+import org.alljoyn.bus.common.KeyInfoNISTP256;
+import org.alljoyn.bus.common.KeyInfoECC;
+
public class PermissionConfiguratorTest extends TestCase {
static {
@@ -28,6 +31,24 @@ public class PermissionConfiguratorTest extends TestCase {
private PermissionConfigurator permissionConfigurator;
private BusAttachment busAttachment;
+ private String defaultManifestTemplate = "<manifest>" +
+ "<node>" +
+ "<interface name=\"org.alljoyn.security2.test\">" +
+ "<method name=\"Up\">" +
+ "<annotation name = \"org.alljoyn.Bus.Action\" value = \"Modify\"/>" +
+ "</method>" +
+ "<method name=\"Down\">" +
+ "<annotation name = \"org.alljoyn.Bus.Action\" value = \"Modify\"/>" +
+ "</method>" +
+ "</interface>" +
+ "<interface name=\"org.allseenalliance.control.Mouse*\">" +
+ "<any>" +
+ "<annotation name = \"org.alljoyn.Bus.Action\" value = \"Modify\"/>" +
+ "</any>" +
+ "</interface>" +
+ "</node>" +
+ "</manifest>";
+
public void setUp() throws Exception {
busAttachment = new BusAttachment("PermissionConfiguratorTest");
busAttachment.connect();
@@ -44,10 +65,63 @@ public class PermissionConfiguratorTest extends TestCase {
}
}
- public void testBasic() throws Exception {
+ public void testNotClaimable() throws Exception {
busAttachment.registerAuthListener("ALLJOYN_ECDHE_NULL", null);
permissionConfigurator = busAttachment.getPermissionConfigurator();
assertEquals(permissionConfigurator.getApplicationState(), PermissionConfigurator.ApplicationState.NOT_CLAIMABLE);
}
+
+ public void testBasic() throws Exception {
+ if (System.getProperty("os.name").startsWith("Windows")) {
+ assertEquals(Status.OK,
+ busAttachment.registerAuthListener("ALLJOYN_ECDHE_NULL", null, null, false, pclistener));
+ } else if (System.getProperty("java.vm.name").startsWith("Dalvik")) {
+ /*
+ * on some Android devices File.createTempFile trys to create a file in
+ * a location we do not have permission to write to. Resulting in a
+ * java.io.IOException: Permission denied error.
+ * This code assumes that the junit tests will have file IO permission
+ * for /data/data/org.alljoyn.bus
+ */
+ assertEquals(Status.OK,
+ busAttachment.registerAuthListener("ALLJOYN_ECDHE_NULL", null,
+ "/data/data/org.alljoyn.bus/files/alljoyn.ks", false, pclistener));
+ } else {
+ assertEquals(Status.OK,
+ busAttachment.registerAuthListener("ALLJOYN_ECDHE_NULL", null,
+ File.createTempFile("alljoyn", "ks").getAbsolutePath(), false, pclistener));
+ }
+ permissionConfigurator = busAttachment.getPermissionConfigurator();
+ assertEquals(permissionConfigurator.getApplicationState(), PermissionConfigurator.ApplicationState.NOT_CLAIMABLE);
+ permissionConfigurator.setManifestTemplateFromXml(defaultManifestTemplate);
+ assertEquals(permissionConfigurator.getApplicationState(), PermissionConfigurator.ApplicationState.CLAIMABLE);
+
+ KeyInfoNISTP256 securityManagerKey = permissionConfigurator.getSigningPublicKey();
+
+ }
+
+ private boolean factoryReset = false;
+ private boolean policyChanged = false;
+ private boolean startManagement = false;
+ private boolean endManagement = false;
+ private PermissionConfigurationListener pclistener = new PermissionConfigurationListener() {
+
+ public Status factoryReset() {
+ factoryReset = true;
+ return Status.OK;
+ }
+
+ public void policyChanged() {
+ policyChanged = true;
+ }
+
+ public void startManagement() {
+ startManagement = true;
+ }
+
+ public void endManagement() {
+ endManagement = true;
+ }
+ };
}