コード例 #1
0
        /// <exception cref="System.Exception"/>
        public static void ProvisionPasswordsToCredentialProvider()
        {
            FilePath testDir = new FilePath(Runtime.GetProperty("test.build.data", "target/test-dir"
                                                                ));
            Configuration conf    = new Configuration();
            Path          jksPath = new Path(testDir.ToString(), "test.jks");
            string        ourUrl  = JavaKeyStoreProvider.SchemeName + "://file" + jksPath.ToUri();
            FilePath      file    = new FilePath(testDir, "test.jks");

            file.Delete();
            conf.Set(CredentialProviderFactory.CredentialProviderPath, ourUrl);
            CredentialProvider provider = CredentialProviderFactory.GetProviders(conf)[0];

            char[] keypass   = new char[] { 'k', 'e', 'y', 'p', 'a', 's', 's' };
            char[] storepass = new char[] { 's', 't', 'o', 'r', 'e', 'p', 'a', 's', 's' };
            // create new aliases
            try
            {
                provider.CreateCredentialEntry(FileBasedKeyStoresFactory.ResolvePropertyName(SSLFactory.Mode
                                                                                             .Server, FileBasedKeyStoresFactory.SslKeystorePasswordTplKey), storepass);
                provider.CreateCredentialEntry(FileBasedKeyStoresFactory.ResolvePropertyName(SSLFactory.Mode
                                                                                             .Server, FileBasedKeyStoresFactory.SslKeystoreKeypasswordTplKey), keypass);
                // write out so that it can be found in checks
                provider.Flush();
            }
            catch (Exception e)
            {
                Runtime.PrintStackTrace(e);
                throw;
            }
        }
コード例 #2
0
        /// <summary>Creates SSL configuration.</summary>
        /// <param name="mode">SSLFactory.Mode mode to configure</param>
        /// <param name="keystore">String keystore file</param>
        /// <param name="password">
        /// String store password, or null to avoid setting store
        /// password
        /// </param>
        /// <param name="keyPassword">
        /// String key password, or null to avoid setting key
        /// password
        /// </param>
        /// <param name="trustKS">String truststore file</param>
        /// <returns>Configuration for SSL</returns>
        private static Configuration CreateSSLConfig(SSLFactory.Mode mode, string keystore
                                                     , string password, string keyPassword, string trustKS)
        {
            string        trustPassword = "******";
            Configuration sslConf       = new Configuration(false);

            if (keystore != null)
            {
                sslConf.Set(FileBasedKeyStoresFactory.ResolvePropertyName(mode, FileBasedKeyStoresFactory
                                                                          .SslKeystoreLocationTplKey), keystore);
            }
            if (password != null)
            {
                sslConf.Set(FileBasedKeyStoresFactory.ResolvePropertyName(mode, FileBasedKeyStoresFactory
                                                                          .SslKeystorePasswordTplKey), password);
            }
            if (keyPassword != null)
            {
                sslConf.Set(FileBasedKeyStoresFactory.ResolvePropertyName(mode, FileBasedKeyStoresFactory
                                                                          .SslKeystoreKeypasswordTplKey), keyPassword);
            }
            if (trustKS != null)
            {
                sslConf.Set(FileBasedKeyStoresFactory.ResolvePropertyName(mode, FileBasedKeyStoresFactory
                                                                          .SslTruststoreLocationTplKey), trustKS);
            }
            if (trustPassword != null)
            {
                sslConf.Set(FileBasedKeyStoresFactory.ResolvePropertyName(mode, FileBasedKeyStoresFactory
                                                                          .SslTruststorePasswordTplKey), trustPassword);
            }
            sslConf.Set(FileBasedKeyStoresFactory.ResolvePropertyName(mode, FileBasedKeyStoresFactory
                                                                      .SslTruststoreReloadIntervalTplKey), "1000");
            return(sslConf);
        }