mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-15 04:55:22 +02:00
[259905][api] Provide a facility to use its own keystore
This commit is contained in:
parent
f7c9ff507f
commit
c6ef422d99
1 changed files with 24 additions and 7 deletions
|
@ -13,12 +13,14 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* David McKnight (IBM) - [225507][api][breaking] RSE dstore API leaks non-API types
|
* David McKnight (IBM) - [225507][api][breaking] RSE dstore API leaks non-API types
|
||||||
|
* Noriaki Takatsu (IBM) - [259905][api] Provide a facility to use its own keystore
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.dstore.internal.core.util.ssl;
|
package org.eclipse.dstore.internal.core.util.ssl;
|
||||||
|
|
||||||
import java.security.KeyStore;
|
import java.security.KeyStore;
|
||||||
|
|
||||||
|
import javax.net.ssl.KeyManager;
|
||||||
import javax.net.ssl.KeyManagerFactory;
|
import javax.net.ssl.KeyManagerFactory;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import javax.net.ssl.TrustManager;
|
import javax.net.ssl.TrustManager;
|
||||||
|
@ -29,12 +31,20 @@ import org.eclipse.dstore.core.util.ssl.IDataStoreTrustManager;
|
||||||
|
|
||||||
public class DStoreSSLContext
|
public class DStoreSSLContext
|
||||||
{
|
{
|
||||||
|
private static KeyManager[] _keyManagers;
|
||||||
|
|
||||||
|
public static void setKeyManager(KeyManager[] keyManagers)
|
||||||
|
{
|
||||||
|
_keyManagers = keyManagers;
|
||||||
|
}
|
||||||
|
|
||||||
public static SSLContext getServerSSLContext(String filePath, String password)
|
public static SSLContext getServerSSLContext(String filePath, String password)
|
||||||
{
|
{
|
||||||
SSLContext serverContext = null;
|
SSLContext serverContext = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
if (_keyManagers == null)
|
||||||
{
|
{
|
||||||
KeyStore ks = DStoreKeyStore.getKeyStore(filePath, password);
|
KeyStore ks = DStoreKeyStore.getKeyStore(filePath, password);
|
||||||
String keymgrAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
|
String keymgrAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
|
||||||
|
@ -44,6 +54,13 @@ public class DStoreSSLContext
|
||||||
serverContext = SSLContext.getInstance("SSL"); //$NON-NLS-1$
|
serverContext = SSLContext.getInstance("SSL"); //$NON-NLS-1$
|
||||||
serverContext.init(kmf.getKeyManagers(), null, null);
|
serverContext.init(kmf.getKeyManagers(), null, null);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
serverContext = SSLContext.getInstance("SSL"); //$NON-NLS-1$
|
||||||
|
serverContext.init(_keyManagers, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -64,7 +81,7 @@ public class DStoreSSLContext
|
||||||
mgrs[0] = trustManager;
|
mgrs[0] = trustManager;
|
||||||
|
|
||||||
|
|
||||||
clientContext.init(null, mgrs, null);
|
clientContext.init(_keyManagers, mgrs, null);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue