net.handle.hdllib
Class AbstractMessage

java.lang.Object
  extended by net.handle.hdllib.AbstractMessage
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
AbstractRequest, AbstractResponse

public abstract class AbstractMessage
extends java.lang.Object
implements java.lang.Cloneable

Base class for all request types


Field Summary
 boolean authoritative
           
 boolean cacheCertify
           
 boolean certify
           
 boolean continuous
           
 boolean doNotRefer
           
 byte[] encodedMessage
           
 boolean encrypt
           
 int expiration
           
 boolean ignoreRestrictedValues
           
 boolean keepAlive
           
 byte majorProtocolVersion
          The major version of the protocol used to send this message.
 byte[] messageBody
           
 byte minorProtocolVersion
          the minor version of the protocol used to send this message.
 boolean mintNewSuffix
           
static int OC_ADD_VALUE
           
static int OC_BACKUP_SERVER
           
static int OC_CREATE_HANDLE
           
static int OC_DELETE_HANDLE
           
static int OC_DUMP_HANDLES
           
static int OC_GET_NEXT_TXN_ID
           
static int OC_GET_SITE_INFO
           
static int OC_HOME_NA
           
static int OC_LIST_HANDLES
           
static int OC_LIST_HOMED_NAS
           
static int OC_MODIFY_VALUE
           
static int OC_REMOVE_VALUE
           
static int OC_RESERVED
           
static int OC_RESOLUTION
           
static int OC_RESPONSE_TO_CHALLENGE
           
static int OC_RETRIEVE_TXN_LOG
           
static int OC_SESSION_EXCHANGEKEY
           
static int OC_SESSION_SETUP
           
static int OC_SESSION_TERMINATE
           
static int OC_UNHOME_NA
           
static int OC_VERIFY_CHALLENGE
           
 int opCode
           
 boolean overwriteWhenExists
           
static int RC_AUTHEN_ERROR
           
static int RC_AUTHEN_TIMEOUT
           
static int RC_AUTHENTICATION_FAILED
           
static int RC_AUTHENTICATION_NEEDED
           
static int RC_ERROR
           
static int RC_HANDLE_ALREADY_EXISTS
           
static int RC_HANDLE_NOT_FOUND
           
static int RC_INSUFFICIENT_PERMISSIONS
           
static int RC_INVALID_ADMIN
           
static int RC_INVALID_CREDENTIAL
           
static int RC_INVALID_HANDLE
           
static int RC_INVALID_SESSION_KEY
           
static int RC_INVALID_SESSIONSETUP_REQUEST
           
static int RC_INVALID_VALUE
           
static int RC_NEED_RSAKEY_FOR_SESSIONEXCHANGE
           
static int RC_OPERATION_NOT_SUPPORTED
           
static int RC_OUT_OF_DATE_SITE_INFO
           
static int RC_PREFIX_REFERRAL
           
static int RC_PROTOCOL_ERROR
           
static int RC_RECURSION_COUNT_TOO_HIGH
           
static int RC_RESERVED
           
static int RC_SERVER_BACKUP
           
static int RC_SERVER_NOT_RESP
           
static int RC_SERVER_TOO_BUSY
           
static int RC_SERVICE_REFERRAL
           
static int RC_SESSION_FAILED
           
static int RC_SESSION_MESSAGE_REJECTED
           
static int RC_SESSION_TIMEOUT
           
static int RC_SUCCESS
           
static int RC_VALUE_ALREADY_EXISTS
           
static int RC_VALUES_NOT_FOUND
           
 byte rdHashType
           
 short recursionCount
           
 boolean recursive
           
 byte[] requestDigest
           
 int requestId
           
 int responseCode
           
 boolean returnRequestDigest
           
 int sessionCounter
           
 int sessionId
           
 byte[] signature
           
 byte[] signerHdl
           
 int signerHdlIdx
           
 int siteInfoSerial
           
 byte suggestMajorProtocolVersion
           
 byte suggestMinorProtocolVersion
           
 
Constructor Summary
AbstractMessage()
           
AbstractMessage(int opCode)
           
 
Method Summary
 void clearBuffers()
          Removed all cached copies of the encoded message.
protected  AbstractMessage clone()
           
 byte[] getEncodedMessage()
          Get the encoded value of this message.
 byte[] getEncodedMessageBody()
          Encode (if necessary) and retrieve the header and body portion of this message.
static java.lang.String getResponseCodeMessage(int responseCode)
           
 boolean hasEqualOrGreaterVersion(int majorVersion, int minorVersion)
          Return true if the major and minor version of this message is equal to or greater than the given major/minor versions.
static boolean hasEqualOrGreaterVersion(int majorProtocolVersion, int minorProtocolVersion, int majorVersion, int minorVersion)
           
 void setSupportedProtocolVersion()
           
 void setSupportedProtocolVersion(AbstractMessage message)
           
 void setSupportedProtocolVersion(SiteInfo site)
           
 boolean shouldEncrypt()
           
 boolean signatureIsMac()
           
 void signMessage(byte[] secretKey)
          Generate a MAC code with a given secretKey.
 void signMessage(java.security.Signature signer)
          Generate a signature for this message using the given Signature object.
 void takeValuesFrom(AbstractMessage msg)
          Takes the request parameters (certify, cacheCertify, authoritative, and encrypt) from the given request object.
 java.lang.String toString()
           
 boolean verifyMessage(byte[] secretKey)
          Validate the signature for this message.
 boolean verifyMessage(java.security.PublicKey pubKey)
          Validate the signature for this message.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OC_RESERVED

public static final int OC_RESERVED
See Also:
Constant Field Values

OC_RESOLUTION

public static final int OC_RESOLUTION
See Also:
Constant Field Values

OC_GET_SITE_INFO

public static final int OC_GET_SITE_INFO
See Also:
Constant Field Values

OC_CREATE_HANDLE

public static final int OC_CREATE_HANDLE
See Also:
Constant Field Values

OC_DELETE_HANDLE

public static final int OC_DELETE_HANDLE
See Also:
Constant Field Values

OC_ADD_VALUE

public static final int OC_ADD_VALUE
See Also:
Constant Field Values

OC_REMOVE_VALUE

public static final int OC_REMOVE_VALUE
See Also:
Constant Field Values

OC_MODIFY_VALUE

public static final int OC_MODIFY_VALUE
See Also:
Constant Field Values

OC_LIST_HANDLES

public static final int OC_LIST_HANDLES
See Also:
Constant Field Values

OC_RESPONSE_TO_CHALLENGE

public static final int OC_RESPONSE_TO_CHALLENGE
See Also:
Constant Field Values

OC_VERIFY_CHALLENGE

public static final int OC_VERIFY_CHALLENGE
See Also:
Constant Field Values

OC_HOME_NA

public static final int OC_HOME_NA
See Also:
Constant Field Values

OC_UNHOME_NA

public static final int OC_UNHOME_NA
See Also:
Constant Field Values

OC_LIST_HOMED_NAS

public static final int OC_LIST_HOMED_NAS
See Also:
Constant Field Values

OC_SESSION_SETUP

public static final int OC_SESSION_SETUP
See Also:
Constant Field Values

OC_SESSION_TERMINATE

public static final int OC_SESSION_TERMINATE
See Also:
Constant Field Values

OC_SESSION_EXCHANGEKEY

public static final int OC_SESSION_EXCHANGEKEY
See Also:
Constant Field Values

OC_GET_NEXT_TXN_ID

public static final int OC_GET_NEXT_TXN_ID
See Also:
Constant Field Values

OC_RETRIEVE_TXN_LOG

public static final int OC_RETRIEVE_TXN_LOG
See Also:
Constant Field Values

OC_DUMP_HANDLES

public static final int OC_DUMP_HANDLES
See Also:
Constant Field Values

OC_BACKUP_SERVER

public static final int OC_BACKUP_SERVER
See Also:
Constant Field Values

RC_RESERVED

public static final int RC_RESERVED
See Also:
Constant Field Values

RC_SUCCESS

public static final int RC_SUCCESS
See Also:
Constant Field Values

RC_ERROR

public static final int RC_ERROR
See Also:
Constant Field Values

RC_SERVER_TOO_BUSY

public static final int RC_SERVER_TOO_BUSY
See Also:
Constant Field Values

RC_PROTOCOL_ERROR

public static final int RC_PROTOCOL_ERROR
See Also:
Constant Field Values

RC_OPERATION_NOT_SUPPORTED

public static final int RC_OPERATION_NOT_SUPPORTED
See Also:
Constant Field Values

RC_RECURSION_COUNT_TOO_HIGH

public static final int RC_RECURSION_COUNT_TOO_HIGH
See Also:
Constant Field Values

RC_SERVER_BACKUP

public static final int RC_SERVER_BACKUP
See Also:
Constant Field Values

RC_HANDLE_NOT_FOUND

public static final int RC_HANDLE_NOT_FOUND
See Also:
Constant Field Values

RC_HANDLE_ALREADY_EXISTS

public static final int RC_HANDLE_ALREADY_EXISTS
See Also:
Constant Field Values

RC_INVALID_HANDLE

public static final int RC_INVALID_HANDLE
See Also:
Constant Field Values

RC_VALUES_NOT_FOUND

public static final int RC_VALUES_NOT_FOUND
See Also:
Constant Field Values

RC_VALUE_ALREADY_EXISTS

public static final int RC_VALUE_ALREADY_EXISTS
See Also:
Constant Field Values

RC_INVALID_VALUE

public static final int RC_INVALID_VALUE
See Also:
Constant Field Values

RC_OUT_OF_DATE_SITE_INFO

public static final int RC_OUT_OF_DATE_SITE_INFO
See Also:
Constant Field Values

RC_SERVER_NOT_RESP

public static final int RC_SERVER_NOT_RESP
See Also:
Constant Field Values

RC_SERVICE_REFERRAL

public static final int RC_SERVICE_REFERRAL
See Also:
Constant Field Values

RC_PREFIX_REFERRAL

public static final int RC_PREFIX_REFERRAL
See Also:
Constant Field Values

RC_INVALID_ADMIN

public static final int RC_INVALID_ADMIN
See Also:
Constant Field Values

RC_INSUFFICIENT_PERMISSIONS

public static final int RC_INSUFFICIENT_PERMISSIONS
See Also:
Constant Field Values

RC_AUTHENTICATION_NEEDED

public static final int RC_AUTHENTICATION_NEEDED
See Also:
Constant Field Values

RC_AUTHENTICATION_FAILED

public static final int RC_AUTHENTICATION_FAILED
See Also:
Constant Field Values

RC_INVALID_CREDENTIAL

public static final int RC_INVALID_CREDENTIAL
See Also:
Constant Field Values

RC_AUTHEN_TIMEOUT

public static final int RC_AUTHEN_TIMEOUT
See Also:
Constant Field Values

RC_AUTHEN_ERROR

public static final int RC_AUTHEN_ERROR
See Also:
Constant Field Values

RC_SESSION_TIMEOUT

public static final int RC_SESSION_TIMEOUT
See Also:
Constant Field Values

RC_SESSION_FAILED

public static final int RC_SESSION_FAILED
See Also:
Constant Field Values

RC_INVALID_SESSION_KEY

public static final int RC_INVALID_SESSION_KEY
See Also:
Constant Field Values

RC_NEED_RSAKEY_FOR_SESSIONEXCHANGE

public static final int RC_NEED_RSAKEY_FOR_SESSIONEXCHANGE
See Also:
Constant Field Values

RC_INVALID_SESSIONSETUP_REQUEST

public static final int RC_INVALID_SESSIONSETUP_REQUEST
See Also:
Constant Field Values

RC_SESSION_MESSAGE_REJECTED

public static final int RC_SESSION_MESSAGE_REJECTED
See Also:
Constant Field Values

requestId

public int requestId

sessionId

public int sessionId

majorProtocolVersion

public byte majorProtocolVersion
The major version of the protocol used to send this message. This is only valid when the message has been decoded from the network using the Encoder.decodeEnvelope and Encoder.decodeMessage methods.


minorProtocolVersion

public byte minorProtocolVersion
the minor version of the protocol used to send this message. This is only valid when the message has been decoded from the network using the Encoder.decodeEnvelope and Encoder.decodeMessage methods.


suggestMajorProtocolVersion

public byte suggestMajorProtocolVersion

suggestMinorProtocolVersion

public byte suggestMinorProtocolVersion

opCode

public int opCode

responseCode

public int responseCode

siteInfoSerial

public int siteInfoSerial

expiration

public int expiration

recursionCount

public short recursionCount

certify

public boolean certify

cacheCertify

public boolean cacheCertify

authoritative

public boolean authoritative

encrypt

public boolean encrypt

ignoreRestrictedValues

public boolean ignoreRestrictedValues

returnRequestDigest

public boolean returnRequestDigest

recursive

public boolean recursive

continuous

public boolean continuous

keepAlive

public boolean keepAlive

overwriteWhenExists

public boolean overwriteWhenExists

mintNewSuffix

public boolean mintNewSuffix

doNotRefer

public boolean doNotRefer

signerHdl

public byte[] signerHdl

signerHdlIdx

public int signerHdlIdx

messageBody

public byte[] messageBody

signature

public byte[] signature

encodedMessage

public byte[] encodedMessage

requestDigest

public byte[] requestDigest

rdHashType

public byte rdHashType

sessionCounter

public int sessionCounter
Constructor Detail

AbstractMessage

public AbstractMessage()

AbstractMessage

public AbstractMessage(int opCode)
Method Detail

clone

protected AbstractMessage clone()
Overrides:
clone in class java.lang.Object

setSupportedProtocolVersion

public void setSupportedProtocolVersion(AbstractMessage message)

setSupportedProtocolVersion

public void setSupportedProtocolVersion(SiteInfo site)

setSupportedProtocolVersion

public void setSupportedProtocolVersion()

hasEqualOrGreaterVersion

public boolean hasEqualOrGreaterVersion(int majorVersion,
                                        int minorVersion)
Return true if the major and minor version of this message is equal to or greater than the given major/minor versions.


hasEqualOrGreaterVersion

public static boolean hasEqualOrGreaterVersion(int majorProtocolVersion,
                                               int minorProtocolVersion,
                                               int majorVersion,
                                               int minorVersion)

takeValuesFrom

public void takeValuesFrom(AbstractMessage msg)
Takes the request parameters (certify, cacheCertify, authoritative, and encrypt) from the given request object. This is useful when several queries are required to resolve a handle and all of the queries must have the same parameters as the overall request. This is also useful when generating responses to requests that must contain the same flags as the request.


signMessage

public final void signMessage(byte[] secretKey)
                       throws HandleException
Generate a MAC code with a given secretKey. secretKey is a symetric key. The secret keyexchange before hand has to be secured with RSA keys. See HandleResolver.java. One usage now is to sign message with MAC code in session menagement.

 Credential section (including signature) within each message:

        Version         octet           (always be 0)

        Reserved        octet           (set to 0)

        Flags           int2                    

        Signer      Handle              0 length UTF8 string
                index               was sesion id (speicified in message envelop) ... replaced by session counter 

    SignatureType   UTF8String      (the handle type of the signature - HS_MAC)
    SignatureLength int4            (length of signature section)
    SignatureSection                (the bytes of the signature, dependent on SignatureType)


 SignatureSection for MAC signatures:
        DigestAlg       UTF8String      (e.g. SHA-1)
        ContentInfo     int4, signedData (version <= 2.4: Hash on ;
                  version >= 2.5, int4 sessionCounter follower by Hash on session key + protocolMajorVersion + protocolMinorVersion + session id + request id + session counter + 
                                                                      message header + message body + session key)


 
Call verifyMessage(byte[] secretKey) to verify. Also see method signMessage(Signature signer), signMessage(PrivateKey key).

Throws:
HandleException

signMessage

public final void signMessage(java.security.Signature signer)
                       throws HandleException,
                              java.security.SignatureException
Generate a signature for this message using the given Signature object. The Signature object must already have been initialized for signing. There can be more than one type of message signature, but this implementation can currently only handle HS_SIGNED-based signatures.

 Credential section (including signature) within each message:

        Version         octet           (always be 0)

        Reserved        octet           (set to 0)

        Flags           int2                    

        Signer          HdlValueRef     (place holder in hdl authentication)
                                          (note: HdlValueRef: UTF8String:int4)

    SignatureType   UTF8String      (the handle type of the signature - HS_SIGNED, etc)
    SignatureLength int4            (length of signature section)
    SignatureSection                (the bytes of the signature, dependent on SignatureType)


 SignatureSection for HS_SIGNED signatures:
        DigestAlg       UTF8String      (e.g. SHA-1)
        ContentInfo     int4, signedData


 

Throws:
HandleException
java.security.SignatureException

signatureIsMac

public boolean signatureIsMac()
                       throws HandleException
Throws:
HandleException

verifyMessage

public final boolean verifyMessage(byte[] secretKey)
                            throws java.lang.Exception
Validate the signature for this message. The given Signature object must have been initialized with the public key of the entity that supposedly signed this message. Returns true if the signature checks out, false if it doesn't.

Throws:
java.lang.Exception

verifyMessage

public final boolean verifyMessage(java.security.PublicKey pubKey)
                            throws java.lang.Exception
Validate the signature for this message. The given Signature object must have been initialized with the public key of the entity that supposedly signed this message. Returns true if the signature checks out, false if it doesn't.

Throws:
java.lang.Exception

shouldEncrypt

public boolean shouldEncrypt()

clearBuffers

public void clearBuffers()
Removed all cached copies of the encoded message. This should be called after every change to the message object so that the message encoding is regenerated the next time it is used.


getEncodedMessageBody

public final byte[] getEncodedMessageBody()
                                   throws HandleException
Encode (if necessary) and retrieve the header and body portion of this message. This will leave the encoded value laying around (in the messageBody field) for later use.

Throws:
HandleException

getEncodedMessage

public final byte[] getEncodedMessage()
                               throws HandleException
Get the encoded value of this message. Since this object is stupid when it comes to caching the encoded value (for the sake of speed), applications need to make sure that they set the rawMessage and signature fields to null after changing any of the messages fields. This is NOT thread-safe. If you want to make it thread-safe, synchronize this method.

Throws:
HandleException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getResponseCodeMessage

public static final java.lang.String getResponseCodeMessage(int responseCode)