FileDocCategorySizeDatePackage
SSLClientVerifier.javaAPI DocExample1227Mon Feb 19 12:24:18 GMT 2001javasec.samples.ch14

SSLClientVerifier

public class SSLClientVerifier extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)


        SocketFactory sf = SSLSocketFactory.getDefault();
        SSLSocket s = (SSLSocket) sf.createSocket(
                       args[0], Integer.parseInt(args[1]));

        SSLSession sess = s.getSession();
        String host = sess.getPeerHost();
        X509Certificate[] certs = sess.getPeerCertificateChain();
        String dn = certs[0].getSubjectDN().getName();
        X500Name name = new X500Name(dn);
        if (!host.equals(name.getCN()))
            System.out.println("Warning: Expected " + host +
                                " and got " + name.getCN());

        BufferedReader br = new BufferedReader(
                                    new InputStreamReader(
                                        s.getInputStream()));
        PrintWriter pw = new PrintWriter(s.getOutputStream());
        System.out.println("Who is Sylvia?");
        pw.println("Who is Sylvia?");
        pw.flush();
        System.out.println(br.readLine());
        s.close();