www.pudn.com > TestCertificate.rar > HttpsCertificate.java


/* 
 * HttpsCertificate.java 
 * 
 * Created on 2006Äê2ÔÂ15ÈÕ, ÏÂÎç8:12 
 * 
 * To change this template, choose Tools | Template Manager 
 * and open the template in the editor. 
 */ 
 
import javax.microedition.io.*; 
import javax.microedition.pki.*; 
import java.io.IOException; 
import javax.microedition.lcdui.*; 
/** 
 * 
 * @author Administrator 
 */ 
public class HttpsCertificate { 
     
     
    private Form form; 
    /** Creates a new instance of HttpsCertificate */ 
    public HttpsCertificate(Form form) { 
        this.form = form; 
    } 
     
    public void getSecurityInfo(){ 
        lable0: 
        try{ 
            HttpsConnection hc = (HttpsConnection)Connector.open("https://www.cert.org");            
            //int port = hc.getPort(); 
            //TextField tf1 = new TextField("Port",port+"",20,TextField.UNEDITABLE); 
            //form.append(tf1); 
            //System.out.println(port); 
            SecurityInfo si = hc.getSecurityInfo();   
            ///SecureConnection sc = (SecureConnection)Connector.open("ssl://mail.google.com:80"); 
            ///SecurityInfo si = sc.getSecurityInfo();                         
            //System.out.println(si); 
            if(si == null){ 
                TextField tf2 = new TextField("SecurityInfo","null",20,TextField.UNEDITABLE); 
                form.append(tf2); 
                break lable0; 
            }else{ 
                TextField tf2 = new TextField("SecurityInfo",si.toString(),100,TextField.UNEDITABLE); 
                form.append(tf2); 
            }     
            String CipherSuite = si.getCipherSuite(); 
            if(CipherSuite == null){ 
                TextField tf3 = new TextField("CipherSuite","null",20,TextField.UNEDITABLE); 
                form.append(tf3); 
            }else{ 
                TextField tf3 = new TextField("CipherSuite",CipherSuite,20,TextField.UNEDITABLE); 
                form.append(tf3); 
            } 
            String ProtocolName = si.getProtocolName(); 
            if(ProtocolName == null){ 
                TextField tf4 = new TextField("ProtocolName","null",20,TextField.UNEDITABLE); 
                form.append(tf4); 
            }else{ 
                TextField tf4 = new TextField("ProtocolName",ProtocolName,20,TextField.UNEDITABLE); 
                form.append(tf4); 
            }   
            String ProtocolVersion = si.getProtocolVersion(); 
            if(ProtocolVersion == null){ 
                TextField tf5 = new TextField("ProtocolVersion","null",20,TextField.UNEDITABLE); 
                form.append(tf5); 
            }else{ 
                TextField tf5 = new TextField("ProtocolVersion",ProtocolVersion,20,TextField.UNEDITABLE); 
                form.append(tf5); 
            } 
            Certificate cf = si.getServerCertificate(); 
            if(cf == null){ 
                TextField tf6 = new TextField("Certificate","null",20,TextField.UNEDITABLE); 
                form.append(tf6); 
                break lable0; 
            }else{ 
                TextField tf6 = new TextField("Certificate",cf.toString(),20,TextField.UNEDITABLE); 
                form.append(tf6); 
            }    
            break lable0; 
            /*String cfinfo = cf.toString(); 
            System.out.println(CipherSuite); 
            System.out.println(ProtocolName); 
            System.out.println(ProtocolVersion); 
            System.out.println(cfinfo); 
            System.out.println("End");*/ 
        }catch(Exception e){ 
            //e.printStackTrace(); 
            //System.out.println("Exception"); 
            TextField tf7 = new TextField("Exception",e.toString(),100,TextField.UNEDITABLE); 
            form.append(tf7); 
        }    
        //System.out.println("End"); 
    } 
     
}