org.openuat.util
Class BluetoothOpportunisticConnector

java.lang.Object
  extended by org.openuat.authentication.AuthenticationEventSender
      extended by org.openuat.util.BluetoothOpportunisticConnector
All Implemented Interfaces:
HostAuthenticationServer

public class BluetoothOpportunisticConnector
extends AuthenticationEventSender
implements HostAuthenticationServer

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().

Version:
1.0
Author:
Rene Mayrhofer

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.
 java.lang.String getRegisteredServiceURL()
          Returns the URL under which the Bluetooth service is reachable for incoming authentication requests.
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

serviceUUID

public static final javax.bluetooth.UUID serviceUUID
This is the Bluetooth service UUID used for the opportunistic authentication service.


serviceName

public static final java.lang.String serviceName
The Bluetooth service will be advertised under this friendly name.

See Also:
Constant Field Values

maxConnectionRetries

public static final int maxConnectionRetries
The maximum number of connection attempts for a service that advertises the serviceUUID.

See Also:
Constant Field Values

retryConnectionDelay

public static final int retryConnectionDelay
The sleep time before re-attempting a connection in ms.

See Also:
Constant Field Values

maximumKeyAgreementRuntime

public static final int maximumKeyAgreementRuntime
The maximum duration, in ms, that we allow a key agreement to take.

See Also:
Constant Field Values

useJSSE

public static final boolean useJSSE
See Also:
Constant Field Values
Constructor Detail

BluetoothOpportunisticConnector

protected BluetoothOpportunisticConnector()
                                   throws java.io.IOException
Initializes the object with defaults, but does not start any server or inquiry processes yet.

Throws:
java.io.IOException - If the Bluetooth support could not be initialized.
Method Detail

getInstance

public static BluetoothOpportunisticConnector getInstance()
                                                   throws java.io.IOException
Returns the local instance of BluetoothOpportunisticConnector.

Throws:
java.io.IOException

getRegisteredServiceURL

public java.lang.String getRegisteredServiceURL()
Returns the URL under which the Bluetooth service is reachable for incoming authentication requests. This URL may be used by clients to connect (when e.g. transmitted over some out-of-band means).


getKeepConnected

public static boolean getKeepConnected()
Gets the current value of keepConnected.

Returns:
true if RFCOMM channels will be left open after successful key agreement, false if they will be closed.

setKeepConnected

public static void setKeepConnected(boolean keepConnected)
Sets the current value of keepConnected.

Parameters:
keepConnected - true if RFCOMM channels should be left open after successful key agreement, false if they should be closed.

addProtocolCommandHandler

public void addProtocolCommandHandler(java.lang.String command,
                                      ProtocolCommandHandler handler)
Description copied from interface: HostAuthenticationServer
Adds a protocol command handler.

Specified by:
addProtocolCommandHandler in interface HostAuthenticationServer
Parameters:
command - The command to react to.
handler - The handler that will be called to handle the protocol session when it is started with command.
See Also:
HostProtocolHandler.addProtocolCommandHandler(java.lang.String, org.openuat.util.ProtocolCommandHandler)

removeProtocolCommandHandler

public boolean removeProtocolCommandHandler(java.lang.String command)
Description copied from interface: HostAuthenticationServer
Removes a protocol command handler.

Specified by:
removeProtocolCommandHandler in interface HostAuthenticationServer
Parameters:
command - The command to stop reacting to.
Returns:
true if the command handler was removed, false otherwise (if no handler was previously registered for this command).
See Also:
HostProtocolHandler.removeProtocolCommandHandler(java.lang.String)

setProtocolCommandHandler

public boolean setProtocolCommandHandler(java.util.Hashtable handlers)
See Also:
HostProtocolHandler.setProtocolCommandHandlers(java.util.Hashtable)

setKeyManager

public 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).

Parameters:
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).

start

public void start()
           throws java.io.IOException
Starts the local authentication service and the background discovery of remote devices and their authentication services. As soon as another authentication service is discovered, this class will try to connect to it and run a HostProtocolHandler instance with it.

Specified by:
start in interface HostAuthenticationServer
Throws:
java.io.IOException

stop

public void stop()
Stops the local authentication service and the background inquiry.

Specified by:
stop in interface HostAuthenticationServer

dispose

public void dispose()
Make sure to free resources when destroyed - particularly to remove the SDP record again (which happens in service.stopListening.


main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Throws:
java.io.IOException


2005-2009, Rene Mayrhofer.