|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.openuat.authentication.AuthenticationEventSender
org.openuat.util.BluetoothOpportunisticConnector
public class BluetoothOpportunisticConnector
This class tries to authenticate to all Bluetooth devices that are discovered to support the OpenUAT authentication service. It uses the BluetoothPeerManager for continous backgound inquiries and SDP service browsing, BluetoothRFCOMMServer for providing the authentication service itself, and HostProtocolHandler with BluetoothRFCOMMChannel to opportunistically connect to all discovered authentication services. As this class currently uses a hard-coded UUID for the Bluetooth authentication service, it is a singleton, i.e. there can be only one instance on each host. In future revisions, other protocols should probably be supported as well in addition to Diffie-Hellman key agreement that is currently used implicitly via HostProtocolHandler. Clients of this class should register for AuthenticationProgressEvents and, upon AuthenticationSuccessEvent, proceed to verify the peer device. KeyManager would be a good option to register as a listener. Note: Due to a circular dependency, for best operation (read: in the normal case when you don't know exactly why it should be otherwise), a KeyManager object needs to be registered twice with the BluetoothOpportunisticConnector singleton. First, it needs to be registered as an AuthenticationProgressHandler by calling the method addAuthenticationProgressHandler(keyManager.getHostAuthenticationHandler()). This enabled the KeyManager to react to HostAuthentication events and therefore manage the keys that are agreed to by (incoming or outgoing) HostProtocolHandler runs. Second, the same KeyManager objects needs to be set by a call to setKeyManager(keyManager), so that outgoing connection attempts will be prevented when the respective remote device already has a known state (i.e. a key agreement is running or has already finished). Both calls should be made before starting the RFCOMM service and the background inquiry with start().
| Nested Class Summary | |
|---|---|
protected class |
BluetoothOpportunisticConnector.AuthenticationEventsHandler
|
protected class |
BluetoothOpportunisticConnector.BluetoothPeerEventsHandler
|
| Field Summary | |
|---|---|
static int |
maxConnectionRetries
The maximum number of connection attempts for a service that advertises the serviceUUID. |
static int |
maximumKeyAgreementRuntime
The maximum duration, in ms, that we allow a key agreement to take. |
static int |
retryConnectionDelay
The sleep time before re-attempting a connection in ms. |
static java.lang.String |
serviceName
The Bluetooth service will be advertised under this friendly name. |
static javax.bluetooth.UUID |
serviceUUID
This is the Bluetooth service UUID used for the opportunistic authentication service. |
static boolean |
useJSSE
|
| Fields inherited from class org.openuat.authentication.AuthenticationEventSender |
|---|
eventsHandlers |
| Constructor Summary | |
|---|---|
protected |
BluetoothOpportunisticConnector()
Initializes the object with defaults, but does not start any server or inquiry processes yet. |
| Method Summary | |
|---|---|
void |
addProtocolCommandHandler(java.lang.String command,
ProtocolCommandHandler handler)
Adds a protocol command handler. |
void |
dispose()
Make sure to free resources when destroyed - particularly to remove the SDP record again (which happens in service.stopListening. |
static BluetoothOpportunisticConnector |
getInstance()
Returns the local instance of BluetoothOpportunisticConnector. |
static boolean |
getKeepConnected()
Gets the current value of keepConnected. |
static void |
main(java.lang.String[] args)
|
boolean |
removeProtocolCommandHandler(java.lang.String command)
Removes a protocol command handler. |
static void |
setKeepConnected(boolean keepConnected)
Sets the current value of keepConnected. |
void |
setKeyManager(KeyManager keyManager)
Sets the keyManager object that should be used for preventing to start new connections when hosts are already known (by the keyManager). |
boolean |
setProtocolCommandHandler(java.util.Hashtable handlers)
|
void |
start()
Starts the local authentication service and the background discovery of remote devices and their authentication services. |
void |
stop()
Stops the local authentication service and the background inquiry. |
| Methods inherited from class org.openuat.authentication.AuthenticationEventSender |
|---|
addAuthenticationProgressHandler, raiseAuthenticationFailureEvent, raiseAuthenticationProgressEvent, raiseAuthenticationStartedEvent, raiseAuthenticationSuccessEvent, removeAuthenticationProgressHandler, setAuthenticationProgressHandlers |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.openuat.util.HostAuthenticationServer |
|---|
addAuthenticationProgressHandler, removeAuthenticationProgressHandler |
| Field Detail |
|---|
public static final javax.bluetooth.UUID serviceUUID
public static final java.lang.String serviceName
public static final int maxConnectionRetries
public static final int retryConnectionDelay
public static final int maximumKeyAgreementRuntime
public static final boolean useJSSE
| Constructor Detail |
|---|
protected BluetoothOpportunisticConnector()
throws java.io.IOException
java.io.IOException - If the Bluetooth support could not be initialized.| Method Detail |
|---|
public static BluetoothOpportunisticConnector getInstance()
throws java.io.IOException
java.io.IOExceptionpublic static boolean getKeepConnected()
public static void setKeepConnected(boolean keepConnected)
keepConnected - true if RFCOMM channels should be left open after successful key
agreement, false if they should be closed.
public void addProtocolCommandHandler(java.lang.String command,
ProtocolCommandHandler handler)
HostAuthenticationServer
addProtocolCommandHandler in interface HostAuthenticationServercommand - The command to react to.handler - The handler that will be called to handle the protocol
session when it is started with command.HostProtocolHandler.addProtocolCommandHandler(java.lang.String, org.openuat.util.ProtocolCommandHandler)public boolean removeProtocolCommandHandler(java.lang.String command)
HostAuthenticationServer
removeProtocolCommandHandler in interface HostAuthenticationServercommand - The command to stop reacting to.
HostProtocolHandler.removeProtocolCommandHandler(java.lang.String)public boolean setProtocolCommandHandler(java.util.Hashtable handlers)
HostProtocolHandler.setProtocolCommandHandlers(java.util.Hashtable)public void setKeyManager(KeyManager keyManager)
keyManager - This object will be queried for known keys before
attempting a new connection.
TODO: This interface is a bit ugly and should probably be refactored.
But the problem is the circular dependency DHWithVerification
-> HostServerBase (the latter needs to be given to the former's
constructor) and BluetoothOpportunisticConnector -> KeyManager
(where the former implements the HostServerBase interface, but
needs access to the keyManager object contained within the e.g.
DHWithVerification).
public void start()
throws java.io.IOException
start in interface HostAuthenticationServerjava.io.IOExceptionpublic void stop()
stop in interface HostAuthenticationServerpublic void dispose()
public static void main(java.lang.String[] args)
throws java.io.IOException
java.io.IOException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||