| | |
| | | import javax.net.ssl.TrustManagerFactory; |
| | | import javax.net.ssl.X509TrustManager; |
| | | |
| | | import org.opends.server.util.Platform; |
| | | |
| | | /** |
| | | * This class is in charge of checking whether the certificates that are |
| | | * presented are trusted or not. |
| | |
| | | String userSpecifiedProvider = |
| | | System.getProperty("org.opends.admin.trustmanagerprovider"); |
| | | |
| | | //Handle IBM specific cases if the user did not specify a algorithm and/or |
| | | //provider. |
| | | if(userSpecifiedAlgo == null && Platform.isVendor("IBM")) |
| | | userSpecifiedAlgo = "IbmX509"; |
| | | if(userSpecifiedProvider == null && Platform.isVendor("IBM")) |
| | | userSpecifiedProvider = "IBMJSEE2"; |
| | | |
| | | // Have some fallbacks to choose the provider and algorith of the key |
| | | // manager. First see if the user wanted to use something specific, |
| | | // then try with the SunJSSE provider and SunX509 algorithm. Finally, |
| | |
| | | "SunX509", |
| | | TrustManagerFactory.getDefaultAlgorithm() |
| | | }; |
| | | for (int i=0; i<preferredProvider.length && trustManager == null; i++) |
| | | { |
| | | String provider = preferredProvider[i]; |
| | | String algo = preferredAlgo[i]; |
| | | if (algo == null) |
| | | for (int i=0; i<preferredProvider.length && trustManager == null; i++) |
| | | { |
| | | continue; |
| | | } |
| | | try |
| | | { |
| | | if (provider != null) |
| | | String provider = preferredProvider[i]; |
| | | String algo = preferredAlgo[i]; |
| | | if (algo == null) |
| | | { |
| | | tmf = TrustManagerFactory.getInstance(algo, provider); |
| | | continue; |
| | | } |
| | | else |
| | | try |
| | | { |
| | | tmf = TrustManagerFactory.getInstance(algo); |
| | | } |
| | | tmf.init(keystore); |
| | | TrustManager[] trustManagers = tmf.getTrustManagers(); |
| | | for (int j=0; j < trustManagers.length; j++) |
| | | { |
| | | if (trustManagers[j] instanceof X509TrustManager) |
| | | if (provider != null) |
| | | { |
| | | trustManager = (X509TrustManager)trustManagers[j]; |
| | | break; |
| | | tmf = TrustManagerFactory.getInstance(algo, provider); |
| | | } |
| | | else |
| | | { |
| | | tmf = TrustManagerFactory.getInstance(algo); |
| | | } |
| | | tmf.init(keystore); |
| | | TrustManager[] trustManagers = tmf.getTrustManagers(); |
| | | for (int j=0; j < trustManagers.length; j++) |
| | | { |
| | | if (trustManagers[j] instanceof X509TrustManager) |
| | | { |
| | | trustManager = (X509TrustManager)trustManagers[j]; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | catch (NoSuchProviderException e) |
| | | { |
| | | LOG.log(Level.WARNING, "Error with the provider: "+provider, e); |
| | | } |
| | | catch (NoSuchAlgorithmException e) |
| | | { |
| | | LOG.log(Level.WARNING, "Error with the algorithm: "+algo, e); |
| | | } |
| | | catch (KeyStoreException e) |
| | | { |
| | | LOG.log(Level.WARNING, "Error with the keystore", e); |
| | | } |
| | | } |
| | | catch (NoSuchProviderException e) |
| | | { |
| | | LOG.log(Level.WARNING, "Error with the provider: "+provider, e); |
| | | } |
| | | catch (NoSuchAlgorithmException e) |
| | | { |
| | | LOG.log(Level.WARNING, "Error with the algorithm: "+algo, e); |
| | | } |
| | | catch (KeyStoreException e) |
| | | { |
| | | LOG.log(Level.WARNING, "Error with the keystore", e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |