net.sf.tumbler
Class TumblerKnock

java.lang.Object
  extended bynet.sf.tumbler.TumblerKnock
Direct Known Subclasses:
TumblerKnockV2

public class TumblerKnock
extends java.lang.Object

A java implementation of the TUMBLER1 protocol (see Tumbler on SourceForge). The TumblerKnock class allows for the building and transmission of tumbler knocks using the TUMBLER1 protocol. To send TUMBLER2 knocks, see the TumblerKnockV2 class in this package.

Sending a knock consists of three steps: For example, the following code sends a knock from IP address 1.2.3.4 to a tumblerd daemon at IP address 4.5.6.7 on port 8765. The knock uses a secret "pAsSwOrD" and a timestamp equal to the time the knock is sent.
 		TumblerKnock knock = new TumblerKnock();
		knock.setSourceAddress(InetAddress.getByName("1.2.3.4"));
		knock.setSecret("pAsSwOrD");
		knock.send(InetAddress.getByName("4.5.6.7"), 8765);
 

Author:
Marty Lamb

Method Summary
static void main(java.lang.String[] args)
          Insanely simple and almost completely non-robust test/example program that sends a TUMBLER1 knock.
 void send(java.net.InetAddress dest, int port)
          Sends the knock to the specified recipient.
 void setSecret(java.lang.String secret)
          Sets the "secret" (e.g., password) portion of the knock.
 void setSourceAddress(java.net.InetAddress src)
          Sets the source IP address to embed within the knock.
 void setTimestamp(java.util.Date timestamp)
          Sets the timestamp (to minute resolution) to embed within the knock.
 java.lang.String toString()
          Returns a String representation of the knock request, consisting of the protocol declaration and the hashed knock data.
 java.lang.String toUnhashedString()
          Returns the unhashed knock data, without the protocol declaration.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

toString

public final java.lang.String toString()
Returns a String representation of the knock request, consisting of the protocol declaration and the hashed knock data. This String is the payload of the UDP packet sent by the send() method.


toUnhashedString

public java.lang.String toUnhashedString()
Returns the unhashed knock data, without the protocol declaration. This exists mainly for debugging and tinkering purposes.

Returns:
the unhashed knock request, without the protocol declaration

setSecret

public void setSecret(java.lang.String secret)
Sets the "secret" (e.g., password) portion of the knock.

Parameters:
secret - the secret to embed within the knock

setSourceAddress

public void setSourceAddress(java.net.InetAddress src)
Sets the source IP address to embed within the knock. This must be the IP address from which the packet will appear to originate.

Parameters:
src - the source IP address of the knock from the receiver's point of view

setTimestamp

public void setTimestamp(java.util.Date timestamp)
Sets the timestamp (to minute resolution) to embed within the knock. The timestamp will be set automatically if necessary.

Parameters:
timestamp - the timestamp to embed within the knock

send

public void send(java.net.InetAddress dest,
                 int port)
          throws java.net.SocketException,
                 java.io.UnsupportedEncodingException,
                 java.io.IOException
Sends the knock to the specified recipient.

Parameters:
dest - the IP address to knock
port - the port # to knock
Throws:
java.net.SocketException - if a socket error occurs
java.io.UnsupportedEncodingException - if US-ASCII is for some reason unavailable as an encoding
java.io.IOException - if anything else goes wrong

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception

Insanely simple and almost completely non-robust test/example program that sends a TUMBLER1 knock.

Invoke with no arguments for usage information.

Throws:
java.lang.Exception - if anything at all goes wrong.