[bug 234509] Equinox keystore fragment for Linux 64bit

Use libsecret

Change-Id: If2a78c2844bce4232f2e15075c28b380a0737ce4
Signed-off-by: Julien HENRY <henryju@yahoo.fr>
diff --git a/bundles/org.eclipse.equinox.security.linux.x86_64/.classpath b/bundles/org.eclipse.equinox.security.linux.x86_64/.classpath
new file mode 100644
index 0000000..e721d0c
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux.x86_64/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src/"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/bundles/org.eclipse.equinox.security.linux.x86_64/.project b/bundles/org.eclipse.equinox.security.linux.x86_64/.project
new file mode 100644
index 0000000..0bf56d4
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux.x86_64/.project
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.eclipse.equinox.security.linux.x86_64</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.m2e.core.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.m2e.core.maven2Nature</nature>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
+	</natures>
+</projectDescription>
diff --git a/bundles/org.eclipse.equinox.security.linux.x86_64/.settings/org.eclipse.core.runtime.prefs b/bundles/org.eclipse.equinox.security.linux.x86_64/.settings/org.eclipse.core.runtime.prefs
new file mode 100644
index 0000000..5a0ad22
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux.x86_64/.settings/org.eclipse.core.runtime.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+line.separator=\n
diff --git a/bundles/org.eclipse.equinox.security.linux.x86_64/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.security.linux.x86_64/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..35a117b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux.x86_64/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.objectteams.otdt.compiler.option.pure_java=enabled
diff --git a/bundles/org.eclipse.equinox.security.linux.x86_64/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.security.linux.x86_64/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..ad0e448
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux.x86_64/META-INF/MANIFEST.MF
@@ -0,0 +1,11 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %fragmentName
+Bundle-SymbolicName: org.eclipse.equinox.security.linux.x86_64;singleton:=true
+Bundle-Version: 1.0.100.qualifier
+Bundle-Vendor: %providerName
+Fragment-Host: org.eclipse.equinox.security;bundle-version="[1.0.0,2.0.0)"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-Localization: fragment
+Eclipse-PlatformFilter: (& (osgi.os=linux) (osgi.arch=x86_64))
+Export-Package: org.eclipse.equinox.internal.security.linux;x-internal:=true
diff --git a/bundles/org.eclipse.equinox.security.linux.x86_64/about.html b/bundles/org.eclipse.equinox.security.linux.x86_64/about.html
new file mode 100644
index 0000000..4602330
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux.x86_64/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+ 
+<p>June 2, 2006</p>	
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;).  Unless otherwise 
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;).  A copy of the EPL is available 
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is 
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content.  Check the Redistributor's license that was 
+provided with the Content.  If no such license exists, contact the Redistributor.  Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.security.linux.x86_64/build.properties b/bundles/org.eclipse.equinox.security.linux.x86_64/build.properties
new file mode 100644
index 0000000..dbe54d9
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux.x86_64/build.properties
@@ -0,0 +1,21 @@
+###############################################################################
+# Copyright (c) 2005, 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:
+#      Julien HENRY - Linux implementation
+###############################################################################
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .,\
+               fragment.properties,\
+               fragment.xml,\
+               about.html,\
+               libkeystorelinuxnative.so
+src.includes = keystorelinuxnative/,\
+               META-INF/,\
+               about.html
diff --git a/bundles/org.eclipse.equinox.security.linux.x86_64/forceQualifierUpdate.txt b/bundles/org.eclipse.equinox.security.linux.x86_64/forceQualifierUpdate.txt
new file mode 100644
index 0000000..2e3e337
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux.x86_64/forceQualifierUpdate.txt
@@ -0,0 +1,2 @@
+# To force a version qualifier update add the bug here
+
diff --git a/bundles/org.eclipse.equinox.security.linux.x86_64/fragment.properties b/bundles/org.eclipse.equinox.security.linux.x86_64/fragment.properties
new file mode 100644
index 0000000..d9e0592
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux.x86_64/fragment.properties
@@ -0,0 +1,14 @@
+###############################################################################
+# Copyright (c) 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:
+#     Julien HENRY - Linux implementation
+###############################################################################
+fragmentName = Linux libsecret integration (64 bit)
+providerName = Eclipse.org - Equinox
+linuxModuleName = Linux Integration (64 bit)
+providerDescription = The provider uses libsecret to store a randomly generated user-specific \'master\' password. Users who can log into the operating system account can access contents of the secure storage.
diff --git a/bundles/org.eclipse.equinox.security.linux.x86_64/fragment.xml b/bundles/org.eclipse.equinox.security.linux.x86_64/fragment.xml
new file mode 100644
index 0000000..37dac74
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux.x86_64/fragment.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<fragment>
+   <extension
+         id="LinuxKeystoreIntegration"
+         name="%linuxModuleName"
+         point="org.eclipse.equinox.security.secureStorage">
+      <provider
+            class="org.eclipse.equinox.internal.security.linux.LinuxPasswordProvider"
+            description="%providerDescription"
+            priority="5">
+         <hint
+               value="AutomaticPasswordGeneration">
+         </hint>
+      </provider>
+   </extension>
+
+</fragment>
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 0000000..5eee1cb
--- /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 0000000..7dc1aed
--- /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 0000000..c255161
--- /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
diff --git a/bundles/org.eclipse.equinox.security.linux.x86_64/libkeystorelinuxnative.so b/bundles/org.eclipse.equinox.security.linux.x86_64/libkeystorelinuxnative.so
new file mode 100755
index 0000000..c149033
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux.x86_64/libkeystorelinuxnative.so
Binary files differ
diff --git a/bundles/org.eclipse.equinox.security.linux.x86_64/pom.xml b/bundles/org.eclipse.equinox.security.linux.x86_64/pom.xml
new file mode 100644
index 0000000..0c44835
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux.x86_64/pom.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright (c) 2017 Eclipse Foundation.
+  All rights reserved. This program and the accompanying materials
+  are made available under the terms of the Eclipse Distribution License v1.0
+  which accompanies this distribution, and is available at
+  http://www.eclipse.org/org/documents/edl-v10.php
+ 
+  Contributors:
+     Julien HENRY - Linux implementation
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>rt.equinox.bundles</artifactId>
+    <groupId>org.eclipse.equinox.bundles</groupId>
+    <version>4.7.0-SNAPSHOT</version>
+    <relativePath>../../</relativePath>
+  </parent>
+  <groupId>org.eclipse.equinox</groupId>
+  <artifactId>org.eclipse.equinox.security.linux.x86_64</artifactId>
+  <version>1.0.100-SNAPSHOT</version>
+  <packaging>eclipse-plugin</packaging>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.eclipse.tycho</groupId>
+        <artifactId>target-platform-configuration</artifactId>
+        <version>${tycho.version}</version>
+        <configuration>
+          <resolver>p2</resolver>
+          <environments>
+            <environment>
+              <os>linux</os>
+              <ws>gtk</ws>
+              <arch>x86_64</arch>
+            </environment>
+          </environments>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/bundles/org.eclipse.equinox.security.linux.x86_64/src/org/eclipse/equinox/internal/security/linux/LinuxPasswordProvider.java b/bundles/org.eclipse.equinox.security.linux.x86_64/src/org/eclipse/equinox/internal/security/linux/LinuxPasswordProvider.java
new file mode 100644
index 0000000..8ae41c7
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux.x86_64/src/org/eclipse/equinox/internal/security/linux/LinuxPasswordProvider.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ *     Julien HENRY - Linux implementation
+ *******************************************************************************/
+package org.eclipse.equinox.internal.security.linux;
+
+import java.security.SecureRandom;
+import javax.crypto.spec.PBEKeySpec;
+import org.eclipse.equinox.internal.security.auth.AuthPlugin;
+import org.eclipse.equinox.internal.security.linux.nls.LinuxPasswordProviderMessages;
+import org.eclipse.equinox.internal.security.storage.Base64;
+import org.eclipse.equinox.security.storage.provider.IPreferencesContainer;
+import org.eclipse.equinox.security.storage.provider.PasswordProvider;
+
+public class LinuxPasswordProvider extends PasswordProvider {
+
+  /**
+   * The length of the randomly generated password in bytes
+   */
+  private static final int PASSWORD_LENGTH = 64;
+
+  private native String getMasterPassword() throws SecurityException;
+
+  private native void saveMasterPassword(String password) throws SecurityException;
+
+  static {
+    System.loadLibrary("keystorelinuxnative"); //$NON-NLS-1$
+  }
+
+  @Override
+  public PBEKeySpec getPassword(IPreferencesContainer container, int passwordType) {
+
+    boolean newPassword = (passwordType & CREATE_NEW_PASSWORD) != 0;
+    boolean passwordChange = (passwordType & PASSWORD_CHANGE) != 0;
+
+    if (!newPassword && !passwordChange) {
+      try {
+        return new PBEKeySpec(getMasterPassword().toCharArray());
+      } catch (SecurityException e) {
+        AuthPlugin.getDefault().logError(LinuxPasswordProviderMessages.getMasterPasswordError, e);
+        return null;
+      }
+    }
+
+    byte[] rawPassword = new byte[PASSWORD_LENGTH];
+    SecureRandom random = new SecureRandom();
+    random.setSeed(System.currentTimeMillis());
+    random.nextBytes(rawPassword);
+    String newPasswordString = Base64.encode(rawPassword);
+
+    // add info message in the log
+    AuthPlugin.getDefault().logMessage(LinuxPasswordProviderMessages.newMasterPasswordGenerated);
+
+    try {
+      saveMasterPassword(newPasswordString);
+      return new PBEKeySpec(newPasswordString.toCharArray());
+    } catch (SecurityException e) {
+      AuthPlugin.getDefault().logError(LinuxPasswordProviderMessages.saveMasterPasswordError, e);
+      return null;
+    }
+  }
+
+}
diff --git a/bundles/org.eclipse.equinox.security.linux.x86_64/src/org/eclipse/equinox/internal/security/linux/nls/LinuxPasswordProviderMessages.java b/bundles/org.eclipse.equinox.security.linux.x86_64/src/org/eclipse/equinox/internal/security/linux/nls/LinuxPasswordProviderMessages.java
new file mode 100644
index 0000000..06e6e62
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux.x86_64/src/org/eclipse/equinox/internal/security/linux/nls/LinuxPasswordProviderMessages.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ *     Julien HENRY - Linux implementation
+ *******************************************************************************/
+package org.eclipse.equinox.internal.security.linux.nls;
+
+import org.eclipse.osgi.util.NLS;
+
+public class LinuxPasswordProviderMessages extends NLS {
+
+  private static final String BUNDLE_NAME = "org.eclipse.equinox.internal.security.linux.nls.messages"; //$NON-NLS-1$
+
+  public static String getMasterPasswordError;
+  public static String saveMasterPasswordError;
+  public static String newMasterPasswordGenerated;
+
+  static {
+    // load message values from bundle file
+    reloadMessages();
+  }
+
+  public static void reloadMessages() {
+    NLS.initializeMessages(BUNDLE_NAME, LinuxPasswordProviderMessages.class);
+  }
+}
diff --git a/bundles/org.eclipse.equinox.security.linux.x86_64/src/org/eclipse/equinox/internal/security/linux/nls/messages.properties b/bundles/org.eclipse.equinox.security.linux.x86_64/src/org/eclipse/equinox/internal/security/linux/nls/messages.properties
new file mode 100644
index 0000000..86cdba6
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux.x86_64/src/org/eclipse/equinox/internal/security/linux/nls/messages.properties
@@ -0,0 +1,15 @@
+###############################################################################
+# Copyright (c) 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:
+#     Julien HENRY - Linux implementation
+###############################################################################
+
+## Linux libsecure integration module
+getMasterPasswordError=Secure storage was unable to retrieve the master password from the password storage. If secure storage was created using a different user account, you'll have to switch back to that account. Alternatively, you can use the password recovery, or delete and re-create secure storage. 
+saveMasterPasswordError=Secure storage was unable to save the master password.
+newMasterPasswordGenerated=New secure storage master password was generated (Linux libsecret integration module). 
diff --git a/features/org.eclipse.equinox.core.sdk/build.properties b/features/org.eclipse.equinox.core.sdk/build.properties
index e24385b..ea7478c 100644
--- a/features/org.eclipse.equinox.core.sdk/build.properties
+++ b/features/org.eclipse.equinox.core.sdk/build.properties
@@ -26,6 +26,7 @@
 generate.plugin@org.eclipse.osgi.util.source=org.eclipse.osgi.util
 generate.plugin@org.eclipse.equinox.security.win32.x86.source=org.eclipse.equinox.security.win32.x86
 generate.plugin@org.eclipse.equinox.security.win32.x86_64.source=org.eclipse.equinox.security.win32.x86_64
+generate.plugin@org.eclipse.equinox.security.linux.x86_64.source=org.eclipse.equinox.security.linux.x86_64
 generate.plugin@org.eclipse.equinox.security.macosx.source=org.eclipse.equinox.security.macosx
 generate.plugin@org.eclipse.equinox.security.source=org.eclipse.equinox.security
 generate.plugin@org.eclipse.equinox.security.ui.source=org.eclipse.equinox.security.ui
diff --git a/features/org.eclipse.equinox.core.sdk/feature.xml b/features/org.eclipse.equinox.core.sdk/feature.xml
index b69a2ee..ed775fe 100644
--- a/features/org.eclipse.equinox.core.sdk/feature.xml
+++ b/features/org.eclipse.equinox.core.sdk/feature.xml
@@ -236,6 +236,25 @@
          unpack="false"/>
 
    <plugin
+         id="org.eclipse.equinox.security.linux.x86_64"
+         os="linux"
+         arch="x86_64"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         fragment="true"
+         unpack="false"/>
+
+   <plugin
+         id="org.eclipse.equinox.security.linux.x86_64.source"
+         os="linux"
+         arch="x86_64"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
+   <plugin
          id="org.eclipse.equinox.security.macosx"
          os="macosx"
          download-size="0"
diff --git a/pom.xml b/pom.xml
index eb20878..2699f7f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -90,6 +90,7 @@
     <module>bundles/org.eclipse.equinox.security.macosx</module>
     <module>bundles/org.eclipse.equinox.security.win32.x86</module>
     <module>bundles/org.eclipse.equinox.security.win32.x86_64</module>
+    <module>bundles/org.eclipse.equinox.security.linux.x86_64</module>
     <module>bundles/org.eclipse.equinox.bidi</module>
     <module>bundles/org.eclipse.equinox.cm</module>
     <module>bundles/org.eclipse.equinox.console</module>