|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.vattp.data.StartUpProtocol
Untamed:
Field Summary | |
private static String[] |
errTokNames
|
private static BigInteger |
g
|
private Vector |
hisMessagesToSign
Messages I've received whose signature is to be checked as part of end point identification. |
private static BigInteger |
modulus
|
private DataPath |
myDataPath
The DataPath object we are working with. |
private String |
myEMsgProtocolVersion
The agreed E message protocol version |
private PublicKey |
myHisPublicKey
The public key of the remote end |
private KeyPair |
myIdentityKeys
|
private boolean |
myIsIncoming
Whether we are build for initiating an outbound connection or responding to a remote connection |
private String |
myLocalFlattenedSearchPath
The semicolon separated search path for this vat |
private String |
myLocalVatID
The vatID of this vat |
private Vector |
myMessagesToSign
Messages I've sent which are to be signed for as part of end point authentication. |
private byte[] |
myOutgoingSuspendID
The suspend ID to present to the other end for a reconnect. |
private String |
myProtocolSuite
The agreed upon protocol suite |
private String |
myRemoteVatID
The remote vatID we are communicating with |
private Signature |
mySignature
The Signature object used for signing and checking signatures |
private int |
myState
Current state of the startup protocol state machine |
private boolean |
myStop
Set true if we should stop attempting to make a connection before outgoingSetup has been called. |
private VatLocationLookup |
myVLS
Entity from which to lookup foreign vatIDs |
(package private) static String |
PROTO_3DES_SDH_M
|
(package private) static String |
PROTO_3DES_SDH_M2
|
(package private) static String |
PROTO_NONE
|
private static int |
ST_DEAD
|
(package private) static int |
ST_EXPECT_MESSAGE
|
private static int |
ST_INCOMING_EXPECT_GIVEINFO
|
(package private) static int |
ST_INCOMING_EXPECT_GO
|
private static int |
ST_INCOMING_EXPECT_IWANT
|
(package private) static int |
ST_OUTGOING_EXPECT_GOTOO
|
private static int |
ST_OUTGOING_EXPECT_IAM
|
private static int |
ST_OUTGOING_EXPECT_REPLYINFO
|
private static int |
ST_TRY_NEXT
|
private static int |
ST_UNSTARTED
|
private static String |
TheAuthProtocols
The protocol negotiation string we send, least desired last |
private static String[] |
TheAuthProtocolTable
The authentication protocols we support. |
private static byte |
TOK_BYE
|
private static byte |
TOK_DUP
|
private static byte |
TOK_ERR_INTERNAL
|
private static byte |
TOK_ERR_PROTOCOL
|
private static byte |
TOK_ERR_WRONG_ID
|
private static byte |
TOK_GIVEINFO
|
private static byte |
TOK_GO
|
private static byte |
TOK_GOTOO
|
private static byte |
TOK_IAM
|
private static byte |
TOK_IWANT
|
private static byte |
TOK_NOT_ME
|
private static byte |
TOK_REPLYINFO
|
private static byte |
TOK_RESUME
|
private static byte |
TOK_TRY
|
private static byte |
TOK_YOUCHOSE
|
private static String[] |
tokNames
|
private BigInteger |
x
|
Constructor Summary | |
(package private) |
StartUpProtocol(DataPath path,
boolean isIncoming,
String remoteVatID,
KeyPair identityKeys,
String localVatID,
byte[] outgoingSuspendID,
String localFlattenedSearchPath,
VatLocationLookup vls)
Make a StartUpProtocol object. |
Method Summary | |
static String[] |
authProtocolTable()
Enabled: |
private void |
checkProtocolVersion(DataInputStream packetIn,
byte[] packet)
Respond to the initator's Msg.PROTOCOL_VERSION message. |
void |
connectionDead(VatTPConnection willBeNull,
Throwable reason)
Enabled: Process a connection failure |
private byte[] |
firstDH()
Perform the first calculation in Diffie Hellman key exchange. |
private String |
formatStartupPacket(byte[] packet)
Format a Msg.STARTUP packet for error messages. |
(package private) int |
getState()
Return the connection startup state |
private void |
handleStateIncomingExpectGIVEINFO(byte token,
DataInputStream packetIn,
byte[] packet)
Process expecting an GIVEINFO |
private void |
handleStateIncomingExpectGO(byte token,
DataInputStream packetIn,
byte[] packet)
Process expecting a GO |
private void |
handleStateIncomingExpectIWANT(byte token,
DataInputStream packetIn,
byte[] packet)
Process expecting a IWANT |
private void |
handleStateOutgoingExpectGOTOO(byte token,
DataInputStream packetIn,
byte[] packet)
Process expecting a GOTOO |
private void |
handleStateOutgoingExpectIAM(byte token,
DataInputStream packetIn,
byte[] packet)
Process expecting an IAM |
private void |
handleStateOutgoingExpectREPLYINFO(byte token,
DataInputStream packetIn,
byte[] packet)
Process expecting a REPLYINFO |
private boolean |
isHisPublicKeyOK(String vatID,
byte[] hisKey,
int token)
Decode the line form of his public key and check that it is for his vatID. |
private boolean |
isSecondDHOK(byte[] publicdh,
byte[] sig,
byte token)
Perform the second calculation in Diffie Hellman key exchange. |
private boolean |
isSigGood(byte[] data,
byte[] sig,
byte token)
Check the signature on the data received. |
private String |
matchProtocols(String protocol)
Match a suggested authorization protocol with the ones we support. |
private byte[] |
md5Hash(int pad,
byte[] data,
MessageDigest md5)
Calculate the MD5 hash of some data with a specific padding. |
void |
processMessage(byte[] packetArray,
VatTPConnection willBeNull)
Enabled: Process the next packet of the connection startup protocol. |
private void |
processProtocolAccepted(DataInputStream packetIn,
byte[] packet)
Handle the Msg.PROTOCOL_ACCEPTED message. |
private void |
sendErrProtocol(String msg)
Send a TOK_ERR_PROTOCOL packet |
private void |
sendGiveInfo()
Send a TOK_GIVEINFO packet |
private void |
sendGo(String protocol)
Send a TOK_GO packet |
private void |
sendGo(String protocol,
byte[] dhparm,
byte[] sig)
Send a TOK_GO packet |
private void |
sendGoToo(String protocol)
Send a TOK_GOTOO packet. |
private void |
sendGoToo(String protocol,
byte[] dhparm,
byte[] sig)
Send a TOK_GOTOO packet |
private void |
sendIAm()
Send a TOK_IAM packet |
private void |
sendIWant()
Send a TOK_IWANT packet |
private void |
sendMessageForSignature(byte[] message)
Send a message to the other end and save the message for signature calculation. |
private void |
sendReplyInfo()
Send a TOK_REPLYINFO packet |
private void |
sendResume()
Send a TOK_RESUME packet |
private void |
sendTry(String location)
Send a TOK_TRY packet |
private void |
sendYouChose()
Send a TOK_YOUCHOSE packet |
private byte[] |
signSent(byte[] data,
byte token)
Return a our signature on the data sent. |
private void |
startupError(byte errorToken,
String msg)
Terminate the connection setup protocol with an error that will get passed to the remote end too. |
private void |
startupError(byte errorToken,
String msg,
Throwable t)
Terminate the connection setup protocol with an error that will get passed to the remote end too. |
private void |
startupLocalError(String msg)
Terminate the connection setup protocol with an error. |
private void |
startupSuccessful()
Startup protocol has succeeded, let the messages flow. |
(package private) void |
stopStartUpProtocol()
Stop the start up protocol. |
private byte[] |
subbytearray(byte[] bytes,
int offset,
int len)
Return a subarray of a given array. |
private static String |
tokName(int tok)
Translate a startup protocol message token to a printable string for error messages and the like. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final int ST_UNSTARTED
private static final int ST_INCOMING_EXPECT_IWANT
private static final int ST_OUTGOING_EXPECT_IAM
private static final int ST_INCOMING_EXPECT_GIVEINFO
private static final int ST_OUTGOING_EXPECT_REPLYINFO
static final int ST_INCOMING_EXPECT_GO
static final int ST_OUTGOING_EXPECT_GOTOO
static final int ST_EXPECT_MESSAGE
private static final int ST_DEAD
private static final int ST_TRY_NEXT
private static final byte TOK_BYE
private static final byte TOK_DUP
private static final byte TOK_GIVEINFO
private static final byte TOK_GO
private static final byte TOK_GOTOO
private static final byte TOK_IAM
private static final byte TOK_IWANT
private static final byte TOK_NOT_ME
private static final byte TOK_REPLYINFO
private static final byte TOK_TRY
private static final byte TOK_RESUME
private static final byte TOK_YOUCHOSE
private static final byte TOK_ERR_PROTOCOL
private static final byte TOK_ERR_WRONG_ID
private static final byte TOK_ERR_INTERNAL
static final String PROTO_NONE
static final String PROTO_3DES_SDH_M
static final String PROTO_3DES_SDH_M2
private static String TheAuthProtocols
private static String[] TheAuthProtocolTable
private static final String[] tokNames
private static final String[] errTokNames
private final DataPath myDataPath
private final boolean myIsIncoming
private String myRemoteVatID
private byte[] myOutgoingSuspendID
private PublicKey myHisPublicKey
private final KeyPair myIdentityKeys
private final VatLocationLookup myVLS
private final String myLocalVatID
private final String myLocalFlattenedSearchPath
private int myState
private boolean myStop
private String myEMsgProtocolVersion
private String myProtocolSuite
private Signature mySignature
private final Vector myMessagesToSign
private final Vector hisMessagesToSign
private BigInteger x
private static final BigInteger g
private static final BigInteger modulus
Constructor Detail |
StartUpProtocol(DataPath path, boolean isIncoming, String remoteVatID, KeyPair identityKeys, String localVatID, byte[] outgoingSuspendID, String localFlattenedSearchPath, VatLocationLookup vls)
path
- the DataPath this StartUpProtocol is to serve.isIncoming
- true if this StartUpProtocol is to work with an
incoming connection. False if this end is the initator.remoteVatID
- if isIncoming, then null, othersize
the VatID for the remote vat.identityKeys
- the KeyPair which defines the identity of this vat.localVatID
- The vatID of the local vat.outgoingSuspendID
- The ID to resume a suspended connection if
this DataPath is outgoing and is to resume a suspended
connection. Otherwise nulllocalFlattenedSearchPath
- the search path we publish for others
looking for the local vat in semicolon separated form.Method Detail |
public static String[] authProtocolTable()
private void checkProtocolVersion(DataInputStream packetIn, byte[] packet) throws IOException
packetIn
- The PROTOCOL_VERSION packet stream postioned after the
type byte.
java.io.IOException
- When there is no protocol in common with
the remote end. An ERR_PROTOCOL message is sent to the
remote end.public void connectionDead(VatTPConnection willBeNull, Throwable reason)
connectionDead
in interface MsgHandler
willBeNull
- The VatTPConnection object which has just died.reason
- is a Throwable which describes why the connection died.private byte[] firstDH()
This method gets a random x and calculate g**x mod p. Return the value as a String base 10.
private String formatStartupPacket(byte[] packet)
packet
- the byte array which is the complete packet.
int getState()
private void handleStateIncomingExpectGIVEINFO(byte token, DataInputStream packetIn, byte[] packet) throws IOException
token
- the actual message token received.packetIn
- is the DataInputStream on the input message positioned
after the startup protocol token.packet
- The entire message received as a string for error
messages.
ConnectionStartupException
- is thrown if this MsgConnection
should terminate.
ConnectionStartupLocalException
- is thrown if this MsgConnection should terminate without
notifing the other end.
IOException
private void handleStateIncomingExpectGO(byte token, DataInputStream packetIn, byte[] packet) throws IOException
token
- the actual message token received.packetIn
- is the DataInputStream on the input message positioned
after the startup protocol token.packet
- The entire message received as a string for error
messages.
ConnectionStartupException
- is thrown if this MsgConnection
should terminate.
ConnectionStartupLocalException
- is thrown if this MsgConnection should terminate without
notifing the other end.
IOException
private void handleStateIncomingExpectIWANT(byte token, DataInputStream packetIn, byte[] packet) throws IOException
token
- the actual message token received.packetIn
- is the DataInputStream on the input message positioned
after the startup protocol token.packet
- The entire message received as a string for error
messages.
ConnectionStartupException
- is thrown if this MsgConnection
should terminate.
IOException
private void handleStateOutgoingExpectGOTOO(byte token, DataInputStream packetIn, byte[] packet) throws IOException
token
- the actual message token received.packetIn
- is the DataInputStream on the input message positioned
after the startup protocol token.packet
- The entire message received as a string for error
messages.
ConnectionStartupException
- is thrown if this MsgConnection
should terminate.
ConnectionStartupLocalException
- is thrown if this MsgConnection should terminate without
notifing the other end.
IOException
private void handleStateOutgoingExpectIAM(byte token, DataInputStream packetIn, byte[] packet) throws IOException
token
- the actual message token received.packetIn
- is the DataInputStream on the input message positioned
after the startup protocol token.packet
- The entire message received as a string for error
messages.
ConnectionStartupException
- is thrown if this MsgConnection
should terminate.
ConnectionStartupLocalException
- is thrown if this MsgConnection should terminate without
notifing the other end.
IOException
private void handleStateOutgoingExpectREPLYINFO(byte token, DataInputStream packetIn, byte[] packet) throws IOException
token
- the actual message token received.packetIn
- is the DataInputStream on the input message positioned
after the startup protocol token.packet
- The entire message received as a string for error
messages.
ConnectionStartupException
- is thrown if this MsgConnection
should terminate.
ConnectionStartupLocalException
- is thrown if this MsgConnection should terminate without
notifing the other end.
IOException
private boolean isHisPublicKeyOK(String vatID, byte[] hisKey, int token) throws IOException
vatID
- His vatID.hisKey
- His DSA public key expressed as a byte array.
ConnectionStartupException
- If hisKey has a bad format, or is
invalid.
IOException
private boolean isSecondDHOK(byte[] publicdh, byte[] sig, byte token) throws IOException
This method takes the remote end's g**y mod p, and the sitnature on it. It checks ths signature and performs the second Diffie Hellman calculation as (g**y mod p) ** x mod p.
It then takes the resulting dh secret and calculates values for the initial sequence numbers (both send path and receive path).
publicdh
- is a byte array containing the far end's first Diffie
Hellman calculation.sig
- is a byte array containing the far end's DSS signature on
the startup protocol.token
- The startup protocol token being processed. (For
determining whether we are the initator or receipent and
error reporting.)
IOException
private boolean isSigGood(byte[] data, byte[] sig, byte token) throws IOException
data
- is the data to check.sig
- is the signature.token
- is the startup protocol token being processed for error
reporting.
IOException
private String matchProtocols(String protocol)
protocol
- the one to match.
private byte[] md5Hash(int pad, byte[] data, MessageDigest md5)
The padding allows different values to be obtained from the same data by varing the padding value. We use it to get the different authentication values from the same Diffie Hellman shared secret.
pad
- The int (treated as a byte) to be used to pad the MD5 calculation.data
- The data to be hashed.md5
- The message digest object to be used.
public void processMessage(byte[] packetArray, VatTPConnection willBeNull)
processMessage
in interface MsgHandler
packetArray
- The startup protocol message to process.willBeNull
- is the VatTPConnection object on which the the message
arrived.Msg
,
VatTPConnection
private void processProtocolAccepted(DataInputStream packetIn, byte[] packet) throws IOException
packet
- the packet received.
IOException
private void sendErrProtocol(String msg) throws IOException
msg
- is a message describing the error.
IOException
- is thrown if there is a problem on the send.private void sendGiveInfo() throws IOException
IOException
- is thrown if there is a problem on the send.private void sendGo(String protocol) throws IOException
protocol
- is the chosen authorization protocol as a String.
IOException
- is thrown if there is a problem on the send.private void sendGo(String protocol, byte[] dhparm, byte[] sig) throws IOException
protocol
- is the chosen authorization protocol as a String.dhparm
- is the public Diffie Hellman parametersig
- is the signature for authentication.
IOException
- is thrown if there is a problem on the send.private void sendGoToo(String protocol) throws IOException
protocol
- is the chosen authorization protocol as a String or null.
If null is specified, nothing will be sent in that place.
IOException
- is thrown if there is a problem on the send.private void sendGoToo(String protocol, byte[] dhparm, byte[] sig) throws IOException
protocol
- is the chosen authorization protocol as a String.dhparm
- is the public Diffie Hellman parametersig
- is the signature for authentication.
IOException
- is thrown if there is a problem on the send.private void sendIAm() throws IOException
IOException
- is thrown if there is a problem on the send.private void sendIWant() throws IOException
IOException
- is thrown if there is a problem on the send.private void sendMessageForSignature(byte[] message)
message
- is the message to send.private void sendReplyInfo() throws IOException
IOException
- is thrown if there is a problem on the send.private void sendResume() throws IOException
IOException
- is thrown if there is a problem on the send.private void sendTry(String location) throws IOException
IOException
- is thrown if there is a problem on the send.private void sendYouChose() throws IOException
IOException
- is thrown if there is a problem on the send.private byte[] signSent(byte[] data, byte token) throws IOException
data
- The additional data to sign.token
- The startup protocol token being processed for error
reporting.
ConnectionStartupException
- For a bunch of "can't occur"
situations.
IOException
private void startupError(byte errorToken, String msg) throws IOException
errorToken
- The error token to be passed to the remote endmsg
- A message string describing the error.
IOException
private void startupError(byte errorToken, String msg, Throwable t) throws IOException
errorToken
- The error token to be passed to the remote endmsg
- A message string describing the error.t
- A throwable associated with the error.
IOException
private void startupLocalError(String msg)
private void startupSuccessful() throws IOException
IOException
void stopStartUpProtocol()
private byte[] subbytearray(byte[] bytes, int offset, int len)
The subarray must be within the given array or an exception will be thrown.
bytes
- The array.offset
- The offset in bytes to the start of the subarray.len
- The length of the subarray.
private static String tokName(int tok)
tok
- The integer startup token to represent as a string.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |