/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* An implemention of X509KeyManager backed by a KeyStore.
*
* The backing KeyStore is inspected when this object is constructed.
* All key entries containing a PrivateKey and a non-empty chain of
* X509Certificate are then copied into an internal store. This means
* that subsequent modifications of the KeyStore have no effect on the
* X509KeyManagerImpl object.
*
* Note that this class assumes that all keys are protected by the same
* password.
*
* The JSSE handshake code currently calls into this class via
* chooseClientAlias() and chooseServerAlias() to find the certificates to
* use. As implemented here, both always return the first alias returned by
* getClientAliases() and getServerAliases(). In turn, these methods are
* implemented by calling getAliases(), which performs the actual lookup.
*
* Note that this class currently implements no checking of the local
* certificates. In particular, it is *not* guaranteed that:
* . the certificates are within their validity period and not revoked
* . the signatures verify
* . they form a PKIX compliant chain.
* . the certificate extensions allow the certificate to be used for
* the desired purpose.
*
* Chains that fail any of these criteria will probably be rejected by
* the remote peer.
*
*/
/*
* The credentials from the KeyStore as
* Map: String(alias) -> X509Credentials(credentials)
*/
/*
* Cached server aliases for the case issuers == null.
* (in the current JSSE implementation, issuers are always null for
* server certs). See chooseServerAlias() for details.
*
* Map: String(keyType) -> String[](alias)
*/
/*
* Basic container for credentials implemented as an inner class.
*/
private static class X509Credentials {
// assert privateKey and certificates != null
this.privateKey = privateKey;
this.certificates = certificates;
}
// lazy initialization
if (issuerX500Principals == null) {
}
}
return issuerX500Principals;
}
}
return;
}
aliases.hasMoreElements(); ) {
continue;
}
if (key instanceof PrivateKey == false) {
continue;
}
continue;
}
if (!(certs instanceof X509Certificate[])) {
}
(X509Certificate[])certs);
+ certs[i]);
}
}
}
}
/*
* Returns the certificate chain associated with the given alias.
*
* @return the certificate chain (ordered with the user's certificate first
* and the root certificate authority last)
*/
return null;
}
return null;
} else {
}
}
/*
* Returns the key associated with the given alias
*/
return null;
}
return null;
} else {
return cred.privateKey;
}
}
/*
* Choose an alias to authenticate the client side of a secure
* socket given the public key type and the list of
* certificate issuer authorities recognized by the peer (if any).
*/
/*
* We currently don't do anything with socket, but
* someday we might. It might be a useful hint for
* selecting one of the aliases we get back from
* getClientAliases().
*/
return null;
}
return aliases[0];
}
}
return null;
}
/*
* Choose an alias to authenticate the client side of an
* <code>SSLEngine</code> connection given the public key type
* and the list of certificate issuer authorities recognized by
* the peer (if any).
*
* @since 1.5
*/
/*
* If we ever start using socket as a selection criteria,
* we'll need to adjust this.
*/
}
/*
* Choose an alias to authenticate the server side of a secure
* socket given the public key type and the list of
* certificate issuer authorities recognized by the peer (if any).
*/
/*
* We currently don't do anything with socket, but
* someday we might. It might be a useful hint for
* selecting one of the aliases we get back from
* getServerAliases().
*/
return null;
}
// Cache the result (positive and negative lookups)
}
}
} else {
}
return aliases[0];
}
return null;
}
/*
* Choose an alias to authenticate the server side of an
* <code>SSLEngine</code> connection given the public key type
* and the list of certificate issuer authorities recognized by
* the peer (if any).
*
* @since 1.5
*/
/*
* If we ever start using socket as a selection criteria,
* we'll need to adjust this.
*/
}
/*
* Get the matching aliases for authenticating the client side of a secure
* socket given the public key type and the list of
* certificate issuer authorities recognized by the peer (if any).
*/
}
/*
* Get the matching aliases for authenticating the server side of a secure
* socket given the public key type and the list of
* certificate issuer authorities recognized by the peer (if any).
*/
}
/*
* Get the matching aliases for authenticating the either side of a secure
* socket given the public key type and the list of
* certificate issuer authorities recognized by the peer (if any).
*
* Issuers comes to us in the form of X500Principal[].
*/
return null;
}
}
if (issuers instanceof X500Principal[] == false) {
// normally, this will never happen but try to recover if it does
}
} else {
}
// the algorithm below does not produce duplicates, so avoid Set
credentialsMap.entrySet()) {
continue;
}
// if possible, check the public key in the issuer cert
continue;
}
} else {
// Check the signature algorithm of the certificate itself.
// Look for the "withRSA" in "SHA1withRSA", etc.
continue;
}
}
}
// no issuer specified, match all
}
} else {
}
break;
}
}
}
}
}
/*
* Convert an array of Principals to an array of X500Principals, if
* possible. Principals that cannot be converted are ignored.
*/
Principal p = principals[i];
if (p instanceof X500Principal) {
} else {
try {
} catch (IllegalArgumentException e) {
// ignore
}
}
}
}
}