View Javadoc

1   /*
2    *  MicroEmulator
3    *  Copyright (C) 2006 Bartek Teodorczyk <barteo@barteo.net>
4    *
5    *  It is licensed under the following two licenses as alternatives:
6    *    1. GNU Lesser General Public License (the "LGPL") version 2.1 or any newer version
7    *    2. Apache License (the "AL") Version 2.0
8    *
9    *  You may not use this file except in compliance with at least one of
10   *  the above two licenses.
11   *
12   *  You may obtain a copy of the LGPL at
13   *      http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
14   *
15   *  You may obtain a copy of the AL at
16   *      http://www.apache.org/licenses/LICENSE-2.0
17   *
18   *  Unless required by applicable law or agreed to in writing, software
19   *  distributed under the License is distributed on an "AS IS" BASIS,
20   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21   *  See the LGPL or the AL for the specific language governing permissions and
22   *  limitations.
23   */
24  
25  package org.microemu.cldc;
26  
27  import javax.microedition.io.SecurityInfo;
28  import javax.microedition.pki.Certificate;
29  import org.microemu.log.Logger;
30  
31  public class SecurityInfoImpl implements SecurityInfo {
32  
33  	private String cipherSuite;
34  	private String protocolName;
35  	private Certificate certificate;
36  
37  	public SecurityInfoImpl(String cipherSuite, String protocolName, Certificate certificate) {
38  		this.cipherSuite = cipherSuite;
39  		this.protocolName = protocolName;
40  		this.certificate = certificate;
41  	}
42  
43  	public String getCipherSuite() {
44  		return cipherSuite;
45  	}
46  
47  	public String getProtocolName() {
48  		if (protocolName.startsWith("TLS")) {
49  			return "TLS";
50  		} else if (protocolName.startsWith("SSL")) {
51  			return "SSL";
52  		} else {
53  			// TODO Auto-generated method stub
54  			try {
55  				throw new RuntimeException();
56  			} catch (RuntimeException ex) {
57  				Logger.error(ex);
58  				throw ex;
59  			}
60  		}
61  	}
62  
63  	public String getProtocolVersion() {
64  		if (protocolName.startsWith("TLS")) {
65  			return "3.1";
66  		} else if (getProtocolName().equals("SSL")) {
67  			return "3.0";
68  		} else {
69  			// TODO Auto-generated method stub
70  			try {
71  				throw new RuntimeException();
72  			} catch (RuntimeException ex) {
73  				Logger.error(ex);
74  				throw ex;
75  			}
76  		}
77  	}
78  
79  	public Certificate getServerCertificate() {
80  		return certificate;
81  	}
82  
83  }