FileDocCategorySizeDatePackage
SSLKeyManager.javaAPI DocExample2552Mon Jan 15 12:18:04 GMT 2001javasec.samples.ch14

SSLKeyManager

public class SSLKeyManager extends Object implements X509KeyManager

Fields Summary
protected String
alias
protected KeyStore
ks
protected char[]
pw
private String
type
private String
issuer
Constructors Summary
SSLKeyManager(KeyStore ks, String s, char[] pw)

        this.ks = ks;
        alias = s;
        this.pw = pw;
        try {
            java.security.cert.Certificate c = ks.getCertificate(s);
            type = c.getPublicKey().getAlgorithm();
            issuer = ((X509Certificate) c).getIssuerDN().getName();
        } catch (Exception e) {
            throw new IllegalArgumentException(s + " has a bad key");
        }
    
Methods Summary
public java.lang.StringchooseClientAlias(java.lang.String type, java.security.Principal[] issuers)

        if (!type.equals(this.type))
            return null;
        if (issuers == null)
            return alias;
        for (int i = 0; i < issuers.length; i++) { 
            if (issuer.equals(issuers[i].getName()))
                return alias;
        }
        return null;
    
public java.lang.StringchooseServerAlias(java.lang.String type, java.security.Principal[] issuers)

        return chooseClientAlias(type, issuers);
    
public java.security.cert.X509Certificate[]getCertificateChain(java.lang.String s)

        try {
            java.security.cert.Certificate[] c =
                                ks.getCertificateChain(s);
            Vector c2 = new Vector(c.length);
            for (int i = 0; i < c.length; i++)
                c2.add(c[i]);
            return (X509Certificate[])
                    c2.toArray(new X509Certificate[0]);
        } catch (KeyStoreException kse) {
            return null;
        }
    
public java.lang.String[]getClientAliases(java.lang.String type, java.security.Principal[] p)

        String[] s;
        String alias = chooseClientAlias(type, p);
        if (alias == null)
            s = new String[0];
        else {
            s = new String[1];
            s[0] = alias;
        }
        return s;
    
public java.security.PrivateKeygetPrivateKey(java.lang.String alias)

        try {
            return (PrivateKey) ks.getKey(alias, pw);
        } catch (Exception e) {
            return null;
        }
    
public java.lang.String[]getServerAliases(java.lang.String type, java.security.Principal[] p)

        return getClientAliases(type, p);