1 /*
2  * Created on 17-Jun-2004
3  * Created by Paul Gardner
4  * Copyright (C) Azureus Software, Inc, All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  * This program 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
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  *
18  */
19 
20 package org.gudy.azureus2.plugins.utils.security;
21 
22 /**
23  * @author parg
24  *
25  */
26 
27 import java.net.Authenticator;
28 import java.net.URL;
29 import java.security.KeyStore;
30 import java.security.cert.Certificate;
31 
32 import javax.net.ssl.SSLSocketFactory;
33 
34 import org.gudy.azureus2.plugins.messaging.generic.GenericMessageConnection;
35 
36 public interface
37 SESecurityManager
38 {
39 	public static final int	BLOCK_ENCRYPTION_NONE		= 1;
40 	public static final int	BLOCK_ENCRYPTION_AES		= 2;
41 
42 		// runs the given task with the supplied Authenticator. Note that the
43 		// scope of the authenticator is "vm-wide" so that if by chance another
44 		// thread attempts to perform an operation that requires authentication
45 		// which the supplied one is in force, the request will be directed to the
46 		// authenticator
47 
48 	public void
runWithAuthenticator( Authenticator authenticator, Runnable task )49 	runWithAuthenticator(
50 		Authenticator	authenticator,
51 		Runnable		task );
52 
53 	public void
addPasswordListener( PasswordListener listener )54 	addPasswordListener(
55 		PasswordListener	listener );
56 
57 	public void
removePasswordListener( PasswordListener listener )58 	removePasswordListener(
59 		PasswordListener	listener );
60 
61 	public void
addCertificateListener( CertificateListener listener )62 	addCertificateListener(
63 		CertificateListener	listener );
64 
65 	public void
removeCertificateListener( CertificateListener listener )66 	removeCertificateListener(
67 		CertificateListener	listener );
68 
69 		/**
70 		 * returns the SHA1 hash of the input data
71 		 * @param data_in
72 		 * @return
73 		 */
74 
75 	public byte[]
calculateSHA1( byte[] data_in )76 	calculateSHA1(
77 		byte[]		data_in );
78 
79 		/**
80 		 * Installs the SSL certificate necessary to support the connection
81 		 * @param url
82 		 */
83 
84 	public SSLSocketFactory
installServerCertificate( URL url )85 	installServerCertificate(
86 		URL		url );
87 
88 	public KeyStore
getKeyStore()89 	getKeyStore()
90 
91 		throws Exception;
92 
93 	public KeyStore
getTrustStore()94 	getTrustStore()
95 
96 		throws Exception;
97 
98 		/**
99 		 * creates and installs a certificate capable of supporting SSL of type MD5withRSA
100 		 * @param alias		alias - e.g. "mycert"
101 		 * @param cert_dn	dn for the cert  e.g. "CN=fred,OU=wap,O=wip,L=here,ST=there,C=GB"
102 		 * @param strength	keyt strength - e.g. 1024
103 		 * @return
104 		 * @throws Exception
105 		 */
106 
107 	public Certificate
createSelfSignedCertificate( String alias, String cert_dn, int strength )108 	createSelfSignedCertificate(
109 		String		alias,
110 		String		cert_dn,
111 		int			strength )
112 
113 		throws Exception;
114 
115 		/**
116 		 * Gets this azureus instance's unique random identity
117 		 * @return
118 		 */
119 
120 	public byte[]
getIdentity()121 	getIdentity();
122 
123 		/**
124 		 * Gets the public key for this az instance of the supplied key type
125 		 * @param key_type	see KEY_TYPE_x constants in SEPublicKey
126 		 * @param reason_resource a message text resource giving the reason for the key being required
127 		 * @return
128 		 */
129 
130 	public SEPublicKey
getPublicKey( int key_type, String reason_resource )131 	getPublicKey(
132 		int		key_type,
133 		String	reason_resource )
134 
135 		throws Exception;
136 
137 	public SEPublicKey
decodePublicKey( byte[] encoded )138 	decodePublicKey(
139 		byte[]	encoded )
140 
141 		throws Exception;
142 
143 		/**
144 		 * Returns a proxy generic STS connection for incoming connection requests
145 		 * @param connection
146 		 * @param my_public_key
147 		 * @param key_locator
148 		 * @return
149 		 * @throws Exception
150 		 */
151 
152 	public GenericMessageConnection
getSTSConnection( GenericMessageConnection connection, SEPublicKey my_public_key, SEPublicKeyLocator key_locator, String reason_resource, int block_encryption )153 	getSTSConnection(
154 		GenericMessageConnection	connection,
155 		SEPublicKey					my_public_key,
156 		SEPublicKeyLocator			key_locator,
157 		String						reason_resource,
158 		int							block_encryption )
159 
160 		throws Exception;
161 }
162