diff --git a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WinPreferencesTest.java b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WinPreferencesTest.java index 3419f235bbd..ce87bbe58cb 100644 --- a/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WinPreferencesTest.java +++ b/bundles/org.eclipse.equinox.security.tests/src/org/eclipse/equinox/internal/security/tests/storage/WinPreferencesTest.java @@ -24,11 +24,11 @@ */ public class WinPreferencesTest extends SecurePreferencesTest { - final private static String WIN_64BIT_BUNDLE = "org.eclipse.equinox.security.win32.x86_64"; + final private static String WIN_BUNDLE = "org.eclipse.equinox.security.win32"; @Before public void setUp() { - org.junit.Assume.assumeTrue(hasBundle(WIN_64BIT_BUNDLE)); + org.junit.Assume.assumeTrue(hasBundle(WIN_BUNDLE)); } /** diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/cpp/jnicrypt.cpp b/bundles/org.eclipse.equinox.security.win32.x86_64/cpp/jnicrypt.cpp deleted file mode 100644 index 29305744070..00000000000 --- a/bundles/org.eclipse.equinox.security.win32.x86_64/cpp/jnicrypt.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers - -#include -#include -#include "jnicrypt.h" - -BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) -{ - return TRUE; -} - -JNIEXPORT jbyteArray JNICALL Java_org_eclipse_equinox_internal_security_win32_WinCrypto_winencrypt - (JNIEnv *env, jobject obj, jbyteArray value) -{ - jsize size = env->GetArrayLength(value); - jbyte *body = env->GetByteArrayElements(value, NULL); - if (body == NULL) - return NULL; - - DATA_BLOB clearText; - DATA_BLOB encryptedText; - clearText.pbData = (BYTE*) body; - clearText.cbData = (DWORD) size; - - BOOL result = CryptProtectData(&clearText, L"Equinox", NULL, NULL, NULL, 0, &encryptedText); - - // release memory allocated by Java environment - env->ReleaseByteArrayElements(value, body, 0); - - if (result == FALSE) - return NULL; - - jbyteArray returnArray = env->NewByteArray(encryptedText.cbData); - env->SetByteArrayRegion(returnArray, 0, encryptedText.cbData, (jbyte*) encryptedText.pbData); - LocalFree(encryptedText.pbData); // no need any more, have Java representation - - return returnArray; -} - -JNIEXPORT jbyteArray JNICALL Java_org_eclipse_equinox_internal_security_win32_WinCrypto_windecrypt - (JNIEnv *env, jobject obj, jbyteArray value) -{ - jsize size = env->GetArrayLength(value); - jbyte *body = env->GetByteArrayElements(value, NULL); - if (body == NULL) - return NULL; - - DATA_BLOB clearText; - DATA_BLOB encryptedText; - encryptedText.pbData = (BYTE*) body; - encryptedText.cbData = (DWORD) size; - - LPWSTR pDescrOut = NULL; - BOOL result = CryptUnprotectData(&encryptedText, &pDescrOut, NULL, NULL, NULL, 0, &clearText); - - if (pDescrOut != NULL) - LocalFree(pDescrOut); - - // release memory allocated by Java environment - env->ReleaseByteArrayElements(value, body, 0); - - if (result == FALSE) - return NULL; - - jbyteArray returnArray = env->NewByteArray(clearText.cbData); - env->SetByteArrayRegion(returnArray, 0, clearText.cbData, (jbyte*) clearText.pbData); - LocalFree(clearText.pbData); // no need any more, have Java representation - - return returnArray; -} diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/cpp/jnicrypt.h b/bundles/org.eclipse.equinox.security.win32.x86_64/cpp/jnicrypt.h deleted file mode 100644 index 377290d5779..00000000000 --- a/bundles/org.eclipse.equinox.security.win32.x86_64/cpp/jnicrypt.h +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -#include - -#ifndef EQUINOX_WIN32_CRYPTO -#define EQUINOX_WIN32_CRYPTO - -#ifdef __cplusplus -extern "C" { -#endif - -JNIEXPORT jbyteArray JNICALL Java_org_eclipse_equinox_internal_security_win32_WinCrypto_windecrypt(JNIEnv *, jobject, jbyteArray); -JNIEXPORT jbyteArray JNICALL Java_org_eclipse_equinox_internal_security_win32_WinCrypto_winencrypt(JNIEnv *, jobject, jbyteArray); - -#ifdef __cplusplus -} -#endif - -#endif // #ifndef EQUINOX_WIN32_CRYPTO - diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/cpp/jnicrypt.vcproj b/bundles/org.eclipse.equinox.security.win32.x86_64/cpp/jnicrypt.vcproj deleted file mode 100644 index a5db9f507e1..00000000000 --- a/bundles/org.eclipse.equinox.security.win32.x86_64/cpp/jnicrypt.vcproj +++ /dev/null @@ -1,463 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/jnicrypt64.dll b/bundles/org.eclipse.equinox.security.win32.x86_64/jnicrypt64.dll deleted file mode 100644 index 4a21b292072..00000000000 Binary files a/bundles/org.eclipse.equinox.security.win32.x86_64/jnicrypt64.dll and /dev/null differ diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/.classpath b/bundles/org.eclipse.equinox.security.win32/.classpath similarity index 100% rename from bundles/org.eclipse.equinox.security.win32.x86_64/.classpath rename to bundles/org.eclipse.equinox.security.win32/.classpath diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/.project b/bundles/org.eclipse.equinox.security.win32/.project similarity index 93% rename from bundles/org.eclipse.equinox.security.win32.x86_64/.project rename to bundles/org.eclipse.equinox.security.win32/.project index 36708287479..755266928af 100644 --- a/bundles/org.eclipse.equinox.security.win32.x86_64/.project +++ b/bundles/org.eclipse.equinox.security.win32/.project @@ -1,6 +1,6 @@ - org.eclipse.equinox.security.win32.x86_64 + org.eclipse.equinox.security.win32 diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/.settings/org.eclipse.core.resources.prefs b/bundles/org.eclipse.equinox.security.win32/.settings/org.eclipse.core.resources.prefs similarity index 100% rename from bundles/org.eclipse.equinox.security.win32.x86_64/.settings/org.eclipse.core.resources.prefs rename to bundles/org.eclipse.equinox.security.win32/.settings/org.eclipse.core.resources.prefs diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/.settings/org.eclipse.core.runtime.prefs b/bundles/org.eclipse.equinox.security.win32/.settings/org.eclipse.core.runtime.prefs similarity index 100% rename from bundles/org.eclipse.equinox.security.win32.x86_64/.settings/org.eclipse.core.runtime.prefs rename to bundles/org.eclipse.equinox.security.win32/.settings/org.eclipse.core.runtime.prefs diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.security.win32/.settings/org.eclipse.jdt.core.prefs similarity index 100% rename from bundles/org.eclipse.equinox.security.win32.x86_64/.settings/org.eclipse.jdt.core.prefs rename to bundles/org.eclipse.equinox.security.win32/.settings/org.eclipse.jdt.core.prefs diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/.settings/org.eclipse.jdt.ui.prefs b/bundles/org.eclipse.equinox.security.win32/.settings/org.eclipse.jdt.ui.prefs similarity index 100% rename from bundles/org.eclipse.equinox.security.win32.x86_64/.settings/org.eclipse.jdt.ui.prefs rename to bundles/org.eclipse.equinox.security.win32/.settings/org.eclipse.jdt.ui.prefs diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.security.win32/META-INF/MANIFEST.MF similarity index 55% rename from bundles/org.eclipse.equinox.security.win32.x86_64/META-INF/MANIFEST.MF rename to bundles/org.eclipse.equinox.security.win32/META-INF/MANIFEST.MF index 4778a524a71..5ae94c7510b 100644 --- a/bundles/org.eclipse.equinox.security.win32.x86_64/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.security.win32/META-INF/MANIFEST.MF @@ -1,12 +1,13 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %fragmentName -Bundle-SymbolicName: org.eclipse.equinox.security.win32.x86_64;singleton:=true -Bundle-Version: 1.2.200.qualifier +Bundle-SymbolicName: org.eclipse.equinox.security.win32;singleton:=true +Bundle-Version: 1.3.0.qualifier Bundle-Vendor: %providerName Fragment-Host: org.eclipse.equinox.security;bundle-version="[1.0.0,2.0.0)" +Import-Package: com.sun.jna.platform.win32;version="[5.14.0,6.0.0)" Bundle-RequiredExecutionEnvironment: JavaSE-17 Bundle-Localization: fragment -Eclipse-PlatformFilter: (& (osgi.os=win32) (osgi.arch=x86_64)) +Eclipse-PlatformFilter: (osgi.os=win32) Export-Package: org.eclipse.equinox.internal.security.win32;x-internal:=true -Automatic-Module-Name: org.eclipse.equinox.security.win32.x86_64 +Automatic-Module-Name: org.eclipse.equinox.security.win32 diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/cpp/ReadMe.txt b/bundles/org.eclipse.equinox.security.win32/ReadMe.txt similarity index 74% rename from bundles/org.eclipse.equinox.security.win32.x86_64/cpp/ReadMe.txt rename to bundles/org.eclipse.equinox.security.win32/ReadMe.txt index baf19d5ed56..d753d7967d3 100644 --- a/bundles/org.eclipse.equinox.security.win32.x86_64/cpp/ReadMe.txt +++ b/bundles/org.eclipse.equinox.security.win32/ReadMe.txt @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 IBM Corporation and others. + * Copyright (c) 2007, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -12,8 +12,8 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ -This is a JNI bridge to access native Windows encryption methods from Java. This version -works in a 64-bit Windows environment. +This is a JNA bridge to access native Windows encryption methods from Java. This version +works in a Windows environment. The methods perform user-specific encryption of the data. The same user can later decrypt data using methods provided by this DLL. A different user won't be able to decrypt the data. @@ -28,9 +28,3 @@ Note that this mechanism is intended to be used with small size data (i.e., pass large amount of data consider encrypting your password using this mechanism and using symmetric encryption to encrypt the data. -To compile this DLL: -=> JAVA_HOME environment variable needs to be setup so that jni.h can be found - -Note C++ projects settings: -=> Additional include directories - "$(JAVA_HOME)/include";"$(JAVA_HOME)/include/win32" -=> Additional linker dependency - Crypt32.lib diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/about.html b/bundles/org.eclipse.equinox.security.win32/about.html similarity index 100% rename from bundles/org.eclipse.equinox.security.win32.x86_64/about.html rename to bundles/org.eclipse.equinox.security.win32/about.html diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/build.properties b/bundles/org.eclipse.equinox.security.win32/build.properties similarity index 87% rename from bundles/org.eclipse.equinox.security.win32.x86_64/build.properties rename to bundles/org.eclipse.equinox.security.win32/build.properties index 399a64b3564..e9ad9abc775 100644 --- a/bundles/org.eclipse.equinox.security.win32.x86_64/build.properties +++ b/bundles/org.eclipse.equinox.security.win32/build.properties @@ -17,8 +17,5 @@ bin.includes = META-INF/,\ .,\ fragment.properties,\ fragment.xml,\ - about.html,\ - jnicrypt64.dll -src.includes = cpp/,\ - META-INF/,\ about.html +src.includes = about.html diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/forceQualifierUpdate.txt b/bundles/org.eclipse.equinox.security.win32/forceQualifierUpdate.txt similarity index 100% rename from bundles/org.eclipse.equinox.security.win32.x86_64/forceQualifierUpdate.txt rename to bundles/org.eclipse.equinox.security.win32/forceQualifierUpdate.txt diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/fragment.properties b/bundles/org.eclipse.equinox.security.win32/fragment.properties similarity index 87% rename from bundles/org.eclipse.equinox.security.win32.x86_64/fragment.properties rename to bundles/org.eclipse.equinox.security.win32/fragment.properties index c9b8604ca76..666520c7561 100644 --- a/bundles/org.eclipse.equinox.security.win32.x86_64/fragment.properties +++ b/bundles/org.eclipse.equinox.security.win32/fragment.properties @@ -11,7 +11,7 @@ # Contributors: # IBM Corporation - initial API and implementation ############################################################################### -fragmentName = Windows Data Protection services integration (64 bit) +fragmentName = Windows Data Protection services integration providerName = Eclipse.org - Equinox -windowsModuleName = Windows Integration (64 bit) +windowsModuleName = Windows Integration providerDescription = The provider uses Windows APIs to encrypt a randomly generated \'master\' password in a way specific to the login credentials. Users who can log into the Windows account can access contents of the secure storage. diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/fragment.xml b/bundles/org.eclipse.equinox.security.win32/fragment.xml similarity index 95% rename from bundles/org.eclipse.equinox.security.win32.x86_64/fragment.xml rename to bundles/org.eclipse.equinox.security.win32/fragment.xml index c9d4d64a9f1..bd63be209c8 100644 --- a/bundles/org.eclipse.equinox.security.win32.x86_64/fragment.xml +++ b/bundles/org.eclipse.equinox.security.win32/fragment.xml @@ -6,7 +6,7 @@ name="%windowsModuleName" point="org.eclipse.equinox.security.secureStorage"> 4.32.0-SNAPSHOT ../../ - org.eclipse.equinox.security.win32.x86_64 - 1.2.200-SNAPSHOT + org.eclipse.equinox.security.win32 + 1.3.0-SNAPSHOT eclipse-plugin diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/src/org/eclipse/equinox/internal/security/win32/WinCrypto.java b/bundles/org.eclipse.equinox.security.win32/src/org/eclipse/equinox/internal/security/win32/WindowsPasswordProvider.java similarity index 86% rename from bundles/org.eclipse.equinox.security.win32.x86_64/src/org/eclipse/equinox/internal/security/win32/WinCrypto.java rename to bundles/org.eclipse.equinox.security.win32/src/org/eclipse/equinox/internal/security/win32/WindowsPasswordProvider.java index 7ccedabb118..f3dc114defd 100644 --- a/bundles/org.eclipse.equinox.security.win32.x86_64/src/org/eclipse/equinox/internal/security/win32/WinCrypto.java +++ b/bundles/org.eclipse.equinox.security.win32/src/org/eclipse/equinox/internal/security/win32/WindowsPasswordProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2017 IBM Corporation and others. + * Copyright (c) 2008, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -7,9 +7,10 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation + * Hannes Wellmann - Migrate to JNA as CPU-architecture independent access to Windows' Crypt32 native library *******************************************************************************/ package org.eclipse.equinox.internal.security.win32; @@ -27,18 +28,24 @@ import org.eclipse.equinox.security.storage.provider.IPreferencesContainer; import org.eclipse.equinox.security.storage.provider.PasswordProvider; +import com.sun.jna.platform.win32.Crypt32Util; + /** * Provides interface with native Windows data protection API. This provider * auto-generates separate passwords for each secure preferences tree. */ -public class WinCrypto extends PasswordProvider { +public class WindowsPasswordProvider extends PasswordProvider { - native public byte[] windecrypt(byte[] encryptedText); - - native public byte[] winencrypt(byte[] clearText); + private static byte[] windecrypt(byte[] encryptedText) { + // Through JNA call + // https://learn.microsoft.com/en-us/windows/win32/api/dpapi/nf-dpapi-cryptunprotectdata + return Crypt32Util.cryptUnprotectData(encryptedText); + } - static { - System.loadLibrary("jnicrypt64"); + private static byte[] winencrypt(byte[] clearText) { + // Through JNA call + // https://learn.microsoft.com/en-us/windows/win32/api/dpapi/nf-dpapi-cryptprotectdata + return Crypt32Util.cryptProtectData(clearText, null, 0, "Equinox", null); } private final static String WIN_PROVIDER_NODE = "/org.eclipse.equinox.secure.storage/windows64"; diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/src/org/eclipse/equinox/internal/security/win32/nls/WinCryptoMessages.java b/bundles/org.eclipse.equinox.security.win32/src/org/eclipse/equinox/internal/security/win32/nls/WinCryptoMessages.java similarity index 100% rename from bundles/org.eclipse.equinox.security.win32.x86_64/src/org/eclipse/equinox/internal/security/win32/nls/WinCryptoMessages.java rename to bundles/org.eclipse.equinox.security.win32/src/org/eclipse/equinox/internal/security/win32/nls/WinCryptoMessages.java diff --git a/bundles/org.eclipse.equinox.security.win32.x86_64/src/org/eclipse/equinox/internal/security/win32/nls/messages.properties b/bundles/org.eclipse.equinox.security.win32/src/org/eclipse/equinox/internal/security/win32/nls/messages.properties similarity index 100% rename from bundles/org.eclipse.equinox.security.win32.x86_64/src/org/eclipse/equinox/internal/security/win32/nls/messages.properties rename to bundles/org.eclipse.equinox.security.win32/src/org/eclipse/equinox/internal/security/win32/nls/messages.properties diff --git a/bundles/org.eclipse.equinox.security/schema/secureStorage.exsd b/bundles/org.eclipse.equinox.security/schema/secureStorage.exsd index d23f7f6756d..59652354ed8 100644 --- a/bundles/org.eclipse.equinox.security/schema/secureStorage.exsd +++ b/bundles/org.eclipse.equinox.security/schema/secureStorage.exsd @@ -141,7 +141,7 @@ <p>The <code>org.eclipse.equinox.security.ui</code> bundle supplies default password provider that prompts user to enter the password.</p> -<p>The <code>org.eclipse.equinox.security.win32.x86_64</code> fragment provides Windows OS integration.</p> +<p>The <code>org.eclipse.equinox.security.win32</code> fragment provides Windows OS integration.</p> <p>The <code>org.eclipse.equinox.security.linux</code> fragment provides Linux OS integration.</p> <p>The <code>org.eclipse.equinox.security.macosx</code> fragment provides Mac OS integration.</p> diff --git a/features/org.eclipse.equinox.core.sdk/feature.xml b/features/org.eclipse.equinox.core.sdk/feature.xml index 65124b9c048..3a892b6d415 100644 --- a/features/org.eclipse.equinox.core.sdk/feature.xml +++ b/features/org.eclipse.equinox.core.sdk/feature.xml @@ -72,13 +72,13 @@ version="0.0.0"/> diff --git a/pom.xml b/pom.xml index 4d75085fd2a..1c07be3c1fa 100644 --- a/pom.xml +++ b/pom.xml @@ -174,7 +174,7 @@ bundles/org.eclipse.equinox.concurrent bundles/org.eclipse.equinox.security bundles/org.eclipse.equinox.security.macosx - bundles/org.eclipse.equinox.security.win32.x86_64 + bundles/org.eclipse.equinox.security.win32 bundles/org.eclipse.equinox.security.linux bundles/org.eclipse.equinox.bidi bundles/org.eclipse.equinox.cm