FileDocCategorySizeDatePackage
X509KeyManagerImpl.javaAPI DocAndroid 1.5 API10123Wed May 06 22:41:06 BST 2009org.apache.harmony.xnet.tests.support

X509KeyManagerImpl

public class X509KeyManagerImpl extends Object implements X509KeyManager

Fields Summary
private String
keyType
private String
client
private String
server
private KeyStore
keyTest
private X509Certificate[]
cert
String
certificate
ByteArrayInputStream
certArray
String
certificate2
ByteArrayInputStream
certArray2
String
certificate3
ByteArrayInputStream
certArray3
Constructors Summary
public X509KeyManagerImpl(String name)

    
    
       
        keyType = name;
        try {
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
            keyTest.load(null, null);
            if (keyType.equals(client)) {
                cert = new X509Certificate[2];
                cert[0] = (X509Certificate) cf.generateCertificate(certArray);
                cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
                //keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
                //keyTest.load(null, null);
                keyTest.setCertificateEntry("clientAlias_01", cert[0]);
                keyTest.setCertificateEntry("clientAlias_02", cert[0]);
                keyTest.setCertificateEntry("clientAlias_03", cert[1]);
            } else if (keyType.equals(server)) {
                //CertificateFactory cf = CertificateFactory.getInstance("X.509");
                cert = new X509Certificate[1];
                cert[0] = (X509Certificate) cf.generateCertificate(certArray3);
                //keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
                //keyTest.load(null, null);
                keyTest.setCertificateEntry("serverAlias_00", cert[0]);
            }
        } catch (Exception ex) {
            throw new IllegalArgumentException(ex.getMessage());
        }
    
Methods Summary
public java.lang.StringchooseClientAlias(java.lang.String[] as, java.security.Principal[] aprincipal, java.net.Socket socket)

        String alias = null;
        if (as == null || as.length == 0) {
            return null;
        }
        try {
            if (as.length == 1 && as[0].equals(client)) {
                if (socket == null) {
                    alias = keyTest.getCertificateAlias(cert[0]);
                } else {
                    alias = keyTest.getCertificateAlias(cert[1]);
                }
                return alias;
            }
        } catch (Exception ex) {
            throw new IllegalArgumentException(ex.getMessage());
        }
        return null;
    
public java.lang.StringchooseServerAlias(java.lang.String as, java.security.Principal[] aprincipal, java.net.Socket socket)

        String alias = null;
        if (as == null || as.equals("")) {
            return null;
        }
        try {
            if (as.equals(server) && socket != null) {
                    return alias = keyTest.getCertificateAlias(cert[0]);
             } else return null;
        } catch (Exception ex) {
            throw new IllegalArgumentException(ex.getMessage());
        }
    
public java.security.cert.X509Certificate[]getCertificateChain(java.lang.String s)

        /*try {
            if (s != null && !s.equals("")) {
                X509Certificate[] cert = (X509Certificate[]) keyTest.getCertificateChain(s);
                return cert;
            } else return null;
        } catch (Exception ex) {
            throw new IllegalArgumentException(ex.getMessage());
        }*/
        return null;
    
public java.lang.String[]getClientAliases(java.lang.String s, java.security.Principal[] aprincipal)

        if (s == null || s.equals("")) {
            return null;
        }
        try {
            if (s.equals(client)) {
                Enumeration<String> aliase = keyTest.aliases();
                Vector vec = new Vector();
                int i = 0;
                while (aliase.hasMoreElements()) {
                    vec.addElement(aliase.nextElement());
                    i++;
                }
                String[] res = new String[vec.size()];
                for (i = 0; i < vec.size(); i++) {
                    res[i] = vec.elementAt(i).toString();
                }
                return res;
            } else return null;
        } catch (Exception ex) {
            throw new IllegalArgumentException(ex.getMessage());
        }
    
public java.security.PrivateKeygetPrivateKey(java.lang.String s)

        /*try {
            if (s != null && !s.equals("")) {
                Certificate[] cert = keyTest.getCertificateChain(s);
                PrivateKey pk = (PrivateKey) keyTest.getKey(s, null);
                return pk;
            } else return null;
        } catch (Exception ex) {
            throw new IllegalArgumentException(ex.getMessage());
        }*/
        return null;
    
public java.lang.String[]getServerAliases(java.lang.String s, java.security.Principal[] aprincipal)

        if (s == null || s.equals("")) {
            return null;
        }
        try {
            if (s.equals(server)) {
                Enumeration<String> aliase = keyTest.aliases();
                Vector vec = new Vector();
                int i = 0;
                while (aliase.hasMoreElements()) {
                    vec.addElement(aliase.nextElement());
                    i++;
                }
                String[] res = new String[vec.size()];
                for (i = 0; i < vec.size(); i++) {
                    res[i] = vec.elementAt(i).toString();
                }
                return res;
            } else return null; 
        } catch (Exception ex) {
            throw new IllegalArgumentException(ex.getMessage());
        }