Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/security/provider/DomainKeyStore.java
38830 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.security.provider;2627import java.io.*;28import java.net.*;29import java.security.*;30import java.security.cert.Certificate;31import java.security.cert.CertificateFactory;32import java.security.cert.CertificateException;33import java.util.*;3435import sun.misc.IOUtils;36import sun.security.pkcs.EncryptedPrivateKeyInfo;37import sun.security.util.PolicyUtil;3839/**40* This class provides the domain keystore type identified as "DKS".41* DKS presents a collection of separate keystores as a single logical keystore.42* The collection of keystores is specified in a domain configuration file which43* is passed to DKS in a {@link DomainLoadStoreParameter}.44* <p>45* The following properties are supported:46* <dl>47* <dt> {@code keystoreType="<type>"} </dt>48* <dd> The keystore type. </dd>49* <dt> {@code keystoreURI="<url>"} </dt>50* <dd> The keystore location. </dd>51* <dt> {@code keystoreProviderName="<name>"} </dt>52* <dd> The name of the keystore's JCE provider. </dd>53* <dt> {@code keystorePasswordEnv="<environment-variable>"} </dt>54* <dd> The environment variable that stores a keystore password.55* <dt> {@code entryNameSeparator="<separator>"} </dt>56* <dd> The separator between a keystore name prefix and an entry name.57* When specified, it applies to all the entries in a domain.58* Its default value is a space. </dd>59* </dl>60*61* @since 1.862*/6364abstract class DomainKeyStore extends KeyStoreSpi {6566// regular DKS67public static final class DKS extends DomainKeyStore {68String convertAlias(String alias) {69return alias.toLowerCase(Locale.ENGLISH);70}71}7273// DKS property names74private static final String ENTRY_NAME_SEPARATOR = "entrynameseparator";75private static final String KEYSTORE_PROVIDER_NAME = "keystoreprovidername";76private static final String KEYSTORE_TYPE = "keystoretype";77private static final String KEYSTORE_URI = "keystoreuri";78private static final String KEYSTORE_PASSWORD_ENV = "keystorepasswordenv";7980// RegEx meta characters81private static final String REGEX_META = ".$|()[{^?*+\\";8283// Default prefix for keystores loaded-by-stream84private static final String DEFAULT_STREAM_PREFIX = "iostream";85private int streamCounter = 1;86private String entryNameSeparator = " ";87private String entryNameSeparatorRegEx = " ";8889// Default keystore type90private static final String DEFAULT_KEYSTORE_TYPE =91KeyStore.getDefaultType();9293// Domain keystores94private final Map<String, KeyStore> keystores = new HashMap<>();9596DomainKeyStore() {97}9899// convert an alias to internal form, overridden in subclasses:100// lower case for regular DKS101abstract String convertAlias(String alias);102103/**104* Returns the key associated with the given alias, using the given105* password to recover it.106*107* @param alias the alias name108* @param password the password for recovering the key109*110* @return the requested key, or null if the given alias does not exist111* or does not identify a <i>key entry</i>.112*113* @exception NoSuchAlgorithmException if the algorithm for recovering the114* key cannot be found115* @exception UnrecoverableKeyException if the key cannot be recovered116* (e.g., the given password is wrong).117*/118public Key engineGetKey(String alias, char[] password)119throws NoSuchAlgorithmException, UnrecoverableKeyException120{121AbstractMap.SimpleEntry<String, Collection<KeyStore>> pair =122getKeystoresForReading(alias);123Key key = null;124125try {126String entryAlias = pair.getKey();127for (KeyStore keystore : pair.getValue()) {128key = keystore.getKey(entryAlias, password);129if (key != null) {130break;131}132}133} catch (KeyStoreException e) {134throw new IllegalStateException(e);135}136137return key;138}139140/**141* Returns the certificate chain associated with the given alias.142*143* @param alias the alias name144*145* @return the certificate chain (ordered with the user's certificate first146* and the root certificate authority last), or null if the given alias147* does not exist or does not contain a certificate chain (i.e., the given148* alias identifies either a <i>trusted certificate entry</i> or a149* <i>key entry</i> without a certificate chain).150*/151public Certificate[] engineGetCertificateChain(String alias) {152153AbstractMap.SimpleEntry<String, Collection<KeyStore>> pair =154getKeystoresForReading(alias);155Certificate[] chain = null;156157try {158String entryAlias = pair.getKey();159for (KeyStore keystore : pair.getValue()) {160chain = keystore.getCertificateChain(entryAlias);161if (chain != null) {162break;163}164}165} catch (KeyStoreException e) {166throw new IllegalStateException(e);167}168169return chain;170}171172/**173* Returns the certificate associated with the given alias.174*175* <p>If the given alias name identifies a176* <i>trusted certificate entry</i>, the certificate associated with that177* entry is returned. If the given alias name identifies a178* <i>key entry</i>, the first element of the certificate chain of that179* entry is returned, or null if that entry does not have a certificate180* chain.181*182* @param alias the alias name183*184* @return the certificate, or null if the given alias does not exist or185* does not contain a certificate.186*/187public Certificate engineGetCertificate(String alias) {188189AbstractMap.SimpleEntry<String, Collection<KeyStore>> pair =190getKeystoresForReading(alias);191Certificate cert = null;192193try {194String entryAlias = pair.getKey();195for (KeyStore keystore : pair.getValue()) {196cert = keystore.getCertificate(entryAlias);197if (cert != null) {198break;199}200}201} catch (KeyStoreException e) {202throw new IllegalStateException(e);203}204205return cert;206}207208/**209* Returns the creation date of the entry identified by the given alias.210*211* @param alias the alias name212*213* @return the creation date of this entry, or null if the given alias does214* not exist215*/216public Date engineGetCreationDate(String alias) {217218AbstractMap.SimpleEntry<String, Collection<KeyStore>> pair =219getKeystoresForReading(alias);220Date date = null;221222try {223String entryAlias = pair.getKey();224for (KeyStore keystore : pair.getValue()) {225date = keystore.getCreationDate(entryAlias);226if (date != null) {227break;228}229}230} catch (KeyStoreException e) {231throw new IllegalStateException(e);232}233234return date;235}236237/**238* Assigns the given private key to the given alias, protecting239* it with the given password as defined in PKCS8.240*241* <p>The given java.security.PrivateKey <code>key</code> must242* be accompanied by a certificate chain certifying the243* corresponding public key.244*245* <p>If the given alias already exists, the keystore information246* associated with it is overridden by the given key and certificate247* chain.248*249* @param alias the alias name250* @param key the private key to be associated with the alias251* @param password the password to protect the key252* @param chain the certificate chain for the corresponding public253* key (only required if the given key is of type254* <code>java.security.PrivateKey</code>).255*256* @exception KeyStoreException if the given key is not a private key,257* cannot be protected, or this operation fails for some other reason258*/259public void engineSetKeyEntry(String alias, Key key, char[] password,260Certificate[] chain)261throws KeyStoreException262{263AbstractMap.SimpleEntry<String,264AbstractMap.SimpleEntry<String, KeyStore>> pair =265getKeystoreForWriting(alias);266267if (pair == null) {268throw new KeyStoreException("Error setting key entry for '" +269alias + "'");270}271String entryAlias = pair.getKey();272Map.Entry<String, KeyStore> keystore = pair.getValue();273keystore.getValue().setKeyEntry(entryAlias, key, password, chain);274}275276/**277* Assigns the given key (that has already been protected) to the given278* alias.279*280* <p>If the protected key is of type281* <code>java.security.PrivateKey</code>, it must be accompanied by a282* certificate chain certifying the corresponding public key. If the283* underlying keystore implementation is of type <code>jks</code>,284* <code>key</code> must be encoded as an285* <code>EncryptedPrivateKeyInfo</code> as defined in the PKCS #8 standard.286*287* <p>If the given alias already exists, the keystore information288* associated with it is overridden by the given key (and possibly289* certificate chain).290*291* @param alias the alias name292* @param key the key (in protected format) to be associated with the alias293* @param chain the certificate chain for the corresponding public294* key (only useful if the protected key is of type295* <code>java.security.PrivateKey</code>).296*297* @exception KeyStoreException if this operation fails.298*/299public void engineSetKeyEntry(String alias, byte[] key,300Certificate[] chain)301throws KeyStoreException302{303AbstractMap.SimpleEntry<String,304AbstractMap.SimpleEntry<String, KeyStore>> pair =305getKeystoreForWriting(alias);306307if (pair == null) {308throw new KeyStoreException(309"Error setting protected key entry for '" + alias + "'");310}311String entryAlias = pair.getKey();312Map.Entry<String, KeyStore> keystore = pair.getValue();313keystore.getValue().setKeyEntry(entryAlias, key, chain);314}315316/**317* Assigns the given certificate to the given alias.318*319* <p>If the given alias already exists in this keystore and identifies a320* <i>trusted certificate entry</i>, the certificate associated with it is321* overridden by the given certificate.322*323* @param alias the alias name324* @param cert the certificate325*326* @exception KeyStoreException if the given alias already exists and does327* not identify a <i>trusted certificate entry</i>, or this operation328* fails for some other reason.329*/330public void engineSetCertificateEntry(String alias, Certificate cert)331throws KeyStoreException332{333AbstractMap.SimpleEntry<String,334AbstractMap.SimpleEntry<String, KeyStore>> pair =335getKeystoreForWriting(alias);336337if (pair == null) {338throw new KeyStoreException("Error setting certificate entry for '"339+ alias + "'");340}341String entryAlias = pair.getKey();342Map.Entry<String, KeyStore> keystore = pair.getValue();343keystore.getValue().setCertificateEntry(entryAlias, cert);344}345346/**347* Deletes the entry identified by the given alias from this keystore.348*349* @param alias the alias name350*351* @exception KeyStoreException if the entry cannot be removed.352*/353public void engineDeleteEntry(String alias) throws KeyStoreException354{355AbstractMap.SimpleEntry<String,356AbstractMap.SimpleEntry<String, KeyStore>> pair =357getKeystoreForWriting(alias);358359if (pair == null) {360throw new KeyStoreException("Error deleting entry for '" + alias +361"'");362}363String entryAlias = pair.getKey();364Map.Entry<String, KeyStore> keystore = pair.getValue();365keystore.getValue().deleteEntry(entryAlias);366}367368/**369* Lists all the alias names of this keystore.370*371* @return enumeration of the alias names372*/373public Enumeration<String> engineAliases() {374final Iterator<Map.Entry<String, KeyStore>> iterator =375keystores.entrySet().iterator();376377return new Enumeration<String>() {378private int index = 0;379private Map.Entry<String, KeyStore> keystoresEntry = null;380private String prefix = null;381private Enumeration<String> aliases = null;382383public boolean hasMoreElements() {384try {385if (aliases == null) {386if (iterator.hasNext()) {387keystoresEntry = iterator.next();388prefix = keystoresEntry.getKey() +389entryNameSeparator;390aliases = keystoresEntry.getValue().aliases();391} else {392return false;393}394}395if (aliases.hasMoreElements()) {396return true;397} else {398if (iterator.hasNext()) {399keystoresEntry = iterator.next();400prefix = keystoresEntry.getKey() +401entryNameSeparator;402aliases = keystoresEntry.getValue().aliases();403} else {404return false;405}406}407} catch (KeyStoreException e) {408return false;409}410411return aliases.hasMoreElements();412}413414public String nextElement() {415if (hasMoreElements()) {416return prefix + aliases.nextElement();417}418throw new NoSuchElementException();419}420};421}422423/**424* Checks if the given alias exists in this keystore.425*426* @param alias the alias name427*428* @return true if the alias exists, false otherwise429*/430public boolean engineContainsAlias(String alias) {431432AbstractMap.SimpleEntry<String, Collection<KeyStore>> pair =433getKeystoresForReading(alias);434435try {436String entryAlias = pair.getKey();437for (KeyStore keystore : pair.getValue()) {438if (keystore.containsAlias(entryAlias)) {439return true;440}441}442} catch (KeyStoreException e) {443throw new IllegalStateException(e);444}445446return false;447}448449/**450* Retrieves the number of entries in this keystore.451*452* @return the number of entries in this keystore453*/454public int engineSize() {455456int size = 0;457try {458for (KeyStore keystore : keystores.values()) {459size += keystore.size();460}461} catch (KeyStoreException e) {462throw new IllegalStateException(e);463}464465return size;466}467468/**469* Returns true if the entry identified by the given alias is a470* <i>key entry</i>, and false otherwise.471*472* @return true if the entry identified by the given alias is a473* <i>key entry</i>, false otherwise.474*/475public boolean engineIsKeyEntry(String alias) {476477AbstractMap.SimpleEntry<String, Collection<KeyStore>> pair =478getKeystoresForReading(alias);479480try {481String entryAlias = pair.getKey();482for (KeyStore keystore : pair.getValue()) {483if (keystore.isKeyEntry(entryAlias)) {484return true;485}486}487} catch (KeyStoreException e) {488throw new IllegalStateException(e);489}490491return false;492}493494/**495* Returns true if the entry identified by the given alias is a496* <i>trusted certificate entry</i>, and false otherwise.497*498* @return true if the entry identified by the given alias is a499* <i>trusted certificate entry</i>, false otherwise.500*/501public boolean engineIsCertificateEntry(String alias) {502503AbstractMap.SimpleEntry<String, Collection<KeyStore>> pair =504getKeystoresForReading(alias);505506try {507String entryAlias = pair.getKey();508for (KeyStore keystore : pair.getValue()) {509if (keystore.isCertificateEntry(entryAlias)) {510return true;511}512}513} catch (KeyStoreException e) {514throw new IllegalStateException(e);515}516517return false;518}519520/*521* Returns a keystore entry alias and a list of target keystores.522* When the supplied alias prefix identifies a keystore then that single523* keystore is returned. When no alias prefix is supplied then all the524* keystores are returned.525*/526private AbstractMap.SimpleEntry<String, Collection<KeyStore>>527getKeystoresForReading(String alias) {528529String[] splits = alias.split(this.entryNameSeparatorRegEx, 2);530if (splits.length == 2) { // prefixed alias531KeyStore keystore = keystores.get(splits[0]);532if (keystore != null) {533return new AbstractMap.SimpleEntry<>(splits[1],534(Collection<KeyStore>) Collections.singleton(keystore));535}536} else if (splits.length == 1) { // unprefixed alias537// Check all keystores for the first occurrence of the alias538return new AbstractMap.SimpleEntry<>(alias, keystores.values());539}540return new AbstractMap.SimpleEntry<>("",541(Collection<KeyStore>) Collections.<KeyStore>emptyList());542}543544/*545* Returns a keystore entry alias and a single target keystore.546* An alias prefix must be supplied.547*/548private549AbstractMap.SimpleEntry<String, AbstractMap.SimpleEntry<String, KeyStore>>550getKeystoreForWriting(String alias) {551552String[] splits = alias.split(this.entryNameSeparator, 2);553if (splits.length == 2) { // prefixed alias554KeyStore keystore = keystores.get(splits[0]);555if (keystore != null) {556return new AbstractMap.SimpleEntry<>(splits[1],557new AbstractMap.SimpleEntry<>(splits[0], keystore));558}559}560return null;561}562563/**564* Returns the (alias) name of the first keystore entry whose certificate565* matches the given certificate.566*567* <p>This method attempts to match the given certificate with each568* keystore entry. If the entry being considered569* is a <i>trusted certificate entry</i>, the given certificate is570* compared to that entry's certificate. If the entry being considered is571* a <i>key entry</i>, the given certificate is compared to the first572* element of that entry's certificate chain (if a chain exists).573*574* @param cert the certificate to match with.575*576* @return the (alias) name of the first entry with matching certificate,577* or null if no such entry exists in this keystore.578*/579public String engineGetCertificateAlias(Certificate cert) {580581try {582583String alias = null;584for (KeyStore keystore : keystores.values()) {585if ((alias = keystore.getCertificateAlias(cert)) != null) {586break;587}588}589return alias;590591} catch (KeyStoreException e) {592throw new IllegalStateException(e);593}594}595596/**597* Stores this keystore to the given output stream, and protects its598* integrity with the given password.599*600* @param stream the output stream to which this keystore is written.601* @param password the password to generate the keystore integrity check602*603* @exception IOException if there was an I/O problem with data604* @exception NoSuchAlgorithmException if the appropriate data integrity605* algorithm could not be found606* @exception CertificateException if any of the certificates included in607* the keystore data could not be stored608*/609public void engineStore(OutputStream stream, char[] password)610throws IOException, NoSuchAlgorithmException, CertificateException611{612// Support storing to a stream only when a single keystore has been613// configured614try {615if (keystores.size() == 1) {616keystores.values().iterator().next().store(stream, password);617return;618}619} catch (KeyStoreException e) {620throw new IllegalStateException(e);621}622623throw new UnsupportedOperationException(624"This keystore must be stored using a DomainLoadStoreParameter");625}626627@Override628public void engineStore(KeyStore.LoadStoreParameter param)629throws IOException, NoSuchAlgorithmException, CertificateException630{631if (param instanceof DomainLoadStoreParameter) {632DomainLoadStoreParameter domainParameter =633(DomainLoadStoreParameter) param;634List<KeyStoreBuilderComponents> builders = getBuilders(635domainParameter.getConfiguration(),636domainParameter.getProtectionParams());637638for (KeyStoreBuilderComponents builder : builders) {639640try {641642KeyStore.ProtectionParameter pp = builder.protection;643if (!(pp instanceof KeyStore.PasswordProtection)) {644throw new KeyStoreException(645new IllegalArgumentException("ProtectionParameter" +646" must be a KeyStore.PasswordProtection"));647}648char[] password =649((KeyStore.PasswordProtection) builder.protection)650.getPassword();651652// Store the keystores653KeyStore keystore = keystores.get(builder.name);654655try (FileOutputStream stream =656new FileOutputStream(builder.file)) {657658keystore.store(stream, password);659}660} catch (KeyStoreException e) {661throw new IOException(e);662}663}664} else {665throw new UnsupportedOperationException(666"This keystore must be stored using a " +667"DomainLoadStoreParameter");668}669}670671/**672* Loads the keystore from the given input stream.673*674* <p>If a password is given, it is used to check the integrity of the675* keystore data. Otherwise, the integrity of the keystore is not checked.676*677* @param stream the input stream from which the keystore is loaded678* @param password the (optional) password used to check the integrity of679* the keystore.680*681* @exception IOException if there is an I/O or format problem with the682* keystore data683* @exception NoSuchAlgorithmException if the algorithm used to check684* the integrity of the keystore cannot be found685* @exception CertificateException if any of the certificates in the686* keystore could not be loaded687*/688public void engineLoad(InputStream stream, char[] password)689throws IOException, NoSuchAlgorithmException, CertificateException690{691// Support loading from a stream only for a JKS or default type keystore692try {693KeyStore keystore = null;694695try {696keystore = KeyStore.getInstance("JKS");697keystore.load(stream, password);698699} catch (Exception e) {700// Retry701if (!"JKS".equalsIgnoreCase(DEFAULT_KEYSTORE_TYPE)) {702keystore = KeyStore.getInstance(DEFAULT_KEYSTORE_TYPE);703keystore.load(stream, password);704} else {705throw e;706}707}708String keystoreName = DEFAULT_STREAM_PREFIX + streamCounter++;709keystores.put(keystoreName, keystore);710711} catch (Exception e) {712throw new UnsupportedOperationException(713"This keystore must be loaded using a " +714"DomainLoadStoreParameter");715}716}717718@Override719public void engineLoad(KeyStore.LoadStoreParameter param)720throws IOException, NoSuchAlgorithmException, CertificateException721{722if (param instanceof DomainLoadStoreParameter) {723DomainLoadStoreParameter domainParameter =724(DomainLoadStoreParameter) param;725List<KeyStoreBuilderComponents> builders = getBuilders(726domainParameter.getConfiguration(),727domainParameter.getProtectionParams());728729for (KeyStoreBuilderComponents builder : builders) {730731try {732// Load the keystores (file-based and non-file-based)733if (builder.file != null) {734keystores.put(builder.name,735KeyStore.Builder.newInstance(builder.type,736builder.provider, builder.file,737builder.protection)738.getKeyStore());739} else {740keystores.put(builder.name,741KeyStore.Builder.newInstance(builder.type,742builder.provider, builder.protection)743.getKeyStore());744}745} catch (KeyStoreException e) {746throw new IOException(e);747}748}749} else {750throw new UnsupportedOperationException(751"This keystore must be loaded using a " +752"DomainLoadStoreParameter");753}754}755756/*757* Parse a keystore domain configuration file and associated collection758* of keystore passwords to create a collection of KeyStore.Builder.759*/760private List<KeyStoreBuilderComponents> getBuilders(URI configuration,761Map<String, KeyStore.ProtectionParameter> passwords)762throws IOException {763764PolicyParser parser = new PolicyParser(true); // expand properties765Collection<PolicyParser.DomainEntry> domains = null;766List<KeyStoreBuilderComponents> builders = new ArrayList<>();767String uriDomain = configuration.getFragment();768769try (InputStreamReader configurationReader =770new InputStreamReader(771PolicyUtil.getInputStream(configuration.toURL()), "UTF-8")) {772parser.read(configurationReader);773domains = parser.getDomainEntries();774775} catch (MalformedURLException mue) {776throw new IOException(mue);777778} catch (PolicyParser.ParsingException pe) {779throw new IOException(pe);780}781782for (PolicyParser.DomainEntry domain : domains) {783Map<String, String> domainProperties = domain.getProperties();784785if (uriDomain != null &&786(!uriDomain.equalsIgnoreCase(domain.getName()))) {787continue; // skip this domain788}789790if (domainProperties.containsKey(ENTRY_NAME_SEPARATOR)) {791this.entryNameSeparator =792domainProperties.get(ENTRY_NAME_SEPARATOR);793// escape any regex meta characters794char ch = 0;795StringBuilder s = new StringBuilder();796for (int i = 0; i < this.entryNameSeparator.length(); i++) {797ch = this.entryNameSeparator.charAt(i);798if (REGEX_META.indexOf(ch) != -1) {799s.append('\\');800}801s.append(ch);802}803this.entryNameSeparatorRegEx = s.toString();804}805806Collection<PolicyParser.KeyStoreEntry> keystores =807domain.getEntries();808for (PolicyParser.KeyStoreEntry keystore : keystores) {809String keystoreName = keystore.getName();810Map<String, String> properties =811new HashMap<>(domainProperties);812properties.putAll(keystore.getProperties());813814String keystoreType = DEFAULT_KEYSTORE_TYPE;815if (properties.containsKey(KEYSTORE_TYPE)) {816keystoreType = properties.get(KEYSTORE_TYPE);817}818819Provider keystoreProvider = null;820if (properties.containsKey(KEYSTORE_PROVIDER_NAME)) {821String keystoreProviderName =822properties.get(KEYSTORE_PROVIDER_NAME);823keystoreProvider =824Security.getProvider(keystoreProviderName);825if (keystoreProvider == null) {826throw new IOException("Error locating JCE provider: " +827keystoreProviderName);828}829}830831File keystoreFile = null;832if (properties.containsKey(KEYSTORE_URI)) {833String uri = properties.get(KEYSTORE_URI);834835try {836if (uri.startsWith("file://")) {837keystoreFile = new File(new URI(uri));838} else {839keystoreFile = new File(uri);840}841842} catch (URISyntaxException | IllegalArgumentException e) {843throw new IOException(844"Error processing keystore property: " +845"keystoreURI=\"" + uri + "\"", e);846}847}848849KeyStore.ProtectionParameter keystoreProtection = null;850if (passwords.containsKey(keystoreName)) {851keystoreProtection = passwords.get(keystoreName);852853} else if (properties.containsKey(KEYSTORE_PASSWORD_ENV)) {854String env = properties.get(KEYSTORE_PASSWORD_ENV);855String pwd = System.getenv(env);856if (pwd != null) {857keystoreProtection =858new KeyStore.PasswordProtection(pwd.toCharArray());859} else {860throw new IOException(861"Error processing keystore property: " +862"keystorePasswordEnv=\"" + env + "\"");863}864} else {865keystoreProtection = new KeyStore.PasswordProtection(null);866}867868builders.add(new KeyStoreBuilderComponents(keystoreName,869keystoreType, keystoreProvider, keystoreFile,870keystoreProtection));871}872break; // skip other domains873}874if (builders.isEmpty()) {875throw new IOException("Error locating domain configuration data " +876"for: " + configuration);877}878879return builders;880}881882/*883* Utility class that holds the components used to construct a KeyStore.Builder884*/885class KeyStoreBuilderComponents {886String name;887String type;888Provider provider;889File file;890KeyStore.ProtectionParameter protection;891892KeyStoreBuilderComponents(String name, String type, Provider provider,893File file, KeyStore.ProtectionParameter protection) {894this.name = name;895this.type = type;896this.provider = provider;897this.file = file;898this.protection = protection;899}900}901}902903904