Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.equinox.security.linux.x86_64/keystorelinuxnative')
-rw-r--r--bundles/org.eclipse.equinox.security.linux.x86_64/keystorelinuxnative/keystoreLinuxNative.c133
-rw-r--r--bundles/org.eclipse.equinox.security.linux.x86_64/keystorelinuxnative/keystoreLinuxNative.h40
-rw-r--r--bundles/org.eclipse.equinox.security.linux.x86_64/keystorelinuxnative/makefile18
3 files changed, 191 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.security.linux.x86_64/keystorelinuxnative/keystoreLinuxNative.c b/bundles/org.eclipse.equinox.security.linux.x86_64/keystorelinuxnative/keystoreLinuxNative.c
new file mode 100644
index 000000000..5eee1cb32
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux.x86_64/keystorelinuxnative/keystoreLinuxNative.c
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2017 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * LinuxPasswordProviderMessages.java
+ *******************************************************************************/
+#include <jni.h>
+#include "keystoreLinuxNative.h"
+#include <libsecret/secret.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <string.h>
+
+const SecretSchema *
+equinox_get_schema (void)
+{
+ static const SecretSchema the_schema = {
+ "org.eclipse.equinox", SECRET_SCHEMA_NONE,
+ {
+ { "NULL", 0 },
+ }
+ };
+ return &the_schema;
+}
+
+#define EQUINOX_SCHEMA equinox_get_schema ()
+
+static void unlock_secret_service(JNIEnv *env)
+{
+ GError *error = NULL;
+ GList *l, *ul;
+ gchar* lbl;
+ gint nu;
+
+ SecretService* secretservice = secret_service_get_sync(SECRET_SERVICE_LOAD_COLLECTIONS, NULL, &error);
+ if (error != NULL) {
+ (*env)->ExceptionClear(env);
+ char buffer [60];
+ sprintf(buffer, "Unable to get secret service: %s", error->message);
+ (*env)->ThrowNew(env, (* env)->FindClass(env, "java/lang/SecurityException"), buffer);
+ g_error_free (error);
+ return;
+ }
+
+ SecretCollection* defaultcollection = secret_collection_for_alias_sync(secretservice, SECRET_COLLECTION_DEFAULT, SECRET_COLLECTION_NONE, NULL, &error);
+ if (error != NULL) {
+ (*env)->ExceptionClear(env);
+ char buffer [60];
+ sprintf(buffer, "Unable to get secret service: %s", error->message);
+ (*env)->ThrowNew(env, (* env)->FindClass(env, "java/lang/SecurityException"), buffer);
+ g_error_free (error);
+ return;
+ }
+
+ if (secret_collection_get_locked(defaultcollection))
+ {
+ lbl = secret_collection_get_label(defaultcollection);
+ l = NULL;
+ l = g_list_append(l, defaultcollection);
+ nu = secret_service_unlock_sync(secretservice, l, NULL, &ul, &error);
+ g_list_free(l);
+ g_list_free(ul);
+ if (error != NULL) {
+ (*env)->ExceptionClear(env);
+ char buffer [60];
+ sprintf(buffer, "Unable to unlock: %s", error->message);
+ (*env)->ThrowNew(env, (* env)->FindClass(env, "java/lang/SecurityException"), buffer);
+ g_error_free (error);
+ return;
+ }
+
+ }
+ return;
+}
+
+JNIEXPORT jstring JNICALL Java_org_eclipse_equinox_internal_security_linux_LinuxPasswordProvider_getMasterPassword(JNIEnv *env, jobject this) {
+ GError *error = NULL;
+ jstring result;
+
+ unlock_secret_service(env);
+ if ((*env)->ExceptionOccurred(env)) {
+ return NULL;
+ }
+
+ gchar *password = secret_password_lookup_sync(EQUINOX_SCHEMA, NULL, &error, NULL);
+
+ if (error != NULL) {
+ (*env)->ExceptionClear(env);
+ char buffer [60];
+ sprintf(buffer, "%s. Result: %d", error->message, error->code);
+ (*env)->ThrowNew(env, (* env)->FindClass(env, "java/lang/SecurityException"), buffer);
+ g_error_free (error);
+ return NULL;
+ } else if (password == NULL) {
+ (*env)->ExceptionClear(env);
+ (*env)->ThrowNew(env, (* env)->FindClass(env, "java/lang/SecurityException"), "Unable to find password");
+ return NULL;
+ } else {
+ result = (*env)->NewStringUTF(env, password);
+ free(password);
+ return result;
+ }
+}
+
+JNIEXPORT void JNICALL Java_org_eclipse_equinox_internal_security_linux_LinuxPasswordProvider_saveMasterPassword(JNIEnv *env, jobject this, jstring password) {
+ GError *error = NULL;
+
+ unlock_secret_service(env);
+ if ((*env)->ExceptionOccurred(env)) {
+ return;
+ }
+
+ const char *passwordUTF = (*env)->GetStringUTFChars(env, password, NULL);
+ secret_password_store_sync (EQUINOX_SCHEMA, SECRET_COLLECTION_DEFAULT,
+ "Equinox master password", passwordUTF, NULL, &error,
+ NULL);
+
+ // free the UTF strings
+ (*env)->ReleaseStringUTFChars( env, password, passwordUTF );
+
+ if (error != NULL) {
+ (*env)->ExceptionClear(env);
+ char buffer [60];
+ sprintf(buffer, "%s. Result: %d", error->message, error->code);
+ (*env)->ThrowNew(env, (* env)->FindClass(env, "java/lang/SecurityException"), buffer);
+ g_error_free (error);
+ }
+}
+
diff --git a/bundles/org.eclipse.equinox.security.linux.x86_64/keystorelinuxnative/keystoreLinuxNative.h b/bundles/org.eclipse.equinox.security.linux.x86_64/keystorelinuxnative/keystoreLinuxNative.h
new file mode 100644
index 000000000..7dc1aedf8
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux.x86_64/keystorelinuxnative/keystoreLinuxNative.h
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2017 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * LinuxPasswordProviderMessages.java
+ *******************************************************************************/
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class LinuxPasswordProvider */
+
+#ifndef _Included_LinuxPasswordProvider
+#define _Included_LinuxPasswordProvider
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Class: LinuxPasswordProvider
+ * Method: getMasterPassword
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_org_eclipse_equinox_internal_security_linux_LinuxPasswordProvider_getMasterPassword
+ (JNIEnv *, jobject);
+
+/*
+ * Class: LinuxPasswordProvider
+ * Method: saveMasterPassword
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_equinox_internal_security_linux_LinuxPasswordProvider_saveMasterPassword
+ (JNIEnv *, jobject, jstring);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/bundles/org.eclipse.equinox.security.linux.x86_64/keystorelinuxnative/makefile b/bundles/org.eclipse.equinox.security.linux.x86_64/keystorelinuxnative/makefile
new file mode 100644
index 000000000..c2551614c
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux.x86_64/keystorelinuxnative/makefile
@@ -0,0 +1,18 @@
+LIBSECRET_CFLAGS = `pkg-config --cflags libsecret-1`
+LIBSECRET_LIBS = `pkg-config --libs libsecret-1`
+
+CFLAGS = -shared -fPIC -I"${JAVA_HOME}/include" -I"${JAVA_HOME}/include/linux"
+
+all: ../libkeystorelinuxnative.so
+
+clean:
+ rm ../libkeystorelinuxnative.so ../target/keystoreLinuxNative.o
+
+../libkeystorelinuxnative.so: ../target/keystoreLinuxNative.o
+ $(CC) $(CFLAGS) -o $@ $< $(LIBSECRET_LIBS)
+
+../target/keystoreLinuxNative.o: ../target keystoreLinuxNative.c
+ $(CC) -c -fPIC -I"${JAVA_HOME}/include" -I"${JAVA_HOME}/include/linux" -o $@ $(TESTFLAGS) $(LIBSECRET_CFLAGS) keystoreLinuxNative.c
+
+../target:
+ mkdir -p ../target

Back to the top