View Javadoc

1   /*
2    *  MicroEmulator
3    *  Copyright (C) 2006 Bartek Teodorczyk <barteo@barteo.net>
4    *
5    *  This library is free software; you can redistribute it and/or
6    *  modify it under the terms of the GNU Lesser General Public
7    *  License as published by the Free Software Foundation; either
8    *  version 2.1 of the License, or (at your option) any later version.
9    *
10   *  This library is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   *  Lesser General Public License for more details.
14   *
15   *  You should have received a copy of the GNU Lesser General Public
16   *  License along with this library; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.microemu.cldc;
21  
22  import javax.microedition.io.SecurityInfo;
23  import javax.microedition.pki.Certificate;
24  import org.microemu.log.Logger;
25  
26  public class SecurityInfoImpl implements SecurityInfo {
27  
28  	private String cipherSuite;
29  	private String protocolName;
30  	private Certificate certificate;
31  
32  	public SecurityInfoImpl(String cipherSuite, String protocolName, Certificate certificate) {
33  		this.cipherSuite = cipherSuite;
34  		this.protocolName = protocolName;
35  		this.certificate = certificate;
36  	}
37  
38  	public String getCipherSuite() {
39  		return cipherSuite;
40  	}
41  
42  	public String getProtocolName() {
43  		if (protocolName.startsWith("TLS")) {
44  			return "TLS";
45  		} else if (protocolName.startsWith("SSL")) {
46  			return "SSL";
47  		} else {
48  			// TODO Auto-generated method stub
49  			try {
50  				throw new RuntimeException();
51  			} catch (RuntimeException ex) {
52  				Logger.error(ex);
53  				throw ex;
54  			}
55  		}
56  	}
57  
58  	public String getProtocolVersion() {
59  		if (protocolName.startsWith("TLS")) {
60  			return "3.1";
61  		} else if (getProtocolName().equals("SSL")) {
62  			return "3.0";
63  		} else {
64  			// TODO Auto-generated method stub
65  			try {
66  				throw new RuntimeException();
67  			} catch (RuntimeException ex) {
68  				Logger.error(ex);
69  				throw ex;
70  			}
71  		}
72  	}
73  
74  	public Certificate getServerCertificate() {
75  		return certificate;
76  	}
77  
78  }