Class AbstractMessage

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

public abstract class AbstractMessage extends Object implements Cloneable
Base class for all request types
  • Field Details

    • OC_RESERVED

      public static final int OC_RESERVED
      See Also:
    • OC_RESOLUTION

      public static final int OC_RESOLUTION
      See Also:
    • OC_GET_SITE_INFO

      public static final int OC_GET_SITE_INFO
      See Also:
    • OC_CREATE_HANDLE

      public static final int OC_CREATE_HANDLE
      See Also:
    • OC_DELETE_HANDLE

      public static final int OC_DELETE_HANDLE
      See Also:
    • OC_ADD_VALUE

      public static final int OC_ADD_VALUE
      See Also:
    • OC_REMOVE_VALUE

      public static final int OC_REMOVE_VALUE
      See Also:
    • OC_MODIFY_VALUE

      public static final int OC_MODIFY_VALUE
      See Also:
    • OC_LIST_HANDLES

      public static final int OC_LIST_HANDLES
      See Also:
    • OC_RESPONSE_TO_CHALLENGE

      public static final int OC_RESPONSE_TO_CHALLENGE
      See Also:
    • OC_VERIFY_CHALLENGE

      public static final int OC_VERIFY_CHALLENGE
      See Also:
    • OC_HOME_NA

      public static final int OC_HOME_NA
      See Also:
    • OC_UNHOME_NA

      public static final int OC_UNHOME_NA
      See Also:
    • OC_LIST_HOMED_NAS

      public static final int OC_LIST_HOMED_NAS
      See Also:
    • OC_SESSION_SETUP

      public static final int OC_SESSION_SETUP
      See Also:
    • OC_SESSION_TERMINATE

      public static final int OC_SESSION_TERMINATE
      See Also:
    • OC_SESSION_EXCHANGEKEY

      public static final int OC_SESSION_EXCHANGEKEY
      See Also:
    • OC_GET_NEXT_TXN_ID

      public static final int OC_GET_NEXT_TXN_ID
      See Also:
    • OC_RETRIEVE_TXN_LOG

      public static final int OC_RETRIEVE_TXN_LOG
      See Also:
    • OC_DUMP_HANDLES

      public static final int OC_DUMP_HANDLES
      See Also:
    • OC_BACKUP_SERVER

      public static final int OC_BACKUP_SERVER
      See Also:
    • RC_RESERVED

      public static final int RC_RESERVED
      See Also:
    • RC_SUCCESS

      public static final int RC_SUCCESS
      See Also:
    • RC_ERROR

      public static final int RC_ERROR
      See Also:
    • RC_SERVER_TOO_BUSY

      public static final int RC_SERVER_TOO_BUSY
      See Also:
    • RC_PROTOCOL_ERROR

      public static final int RC_PROTOCOL_ERROR
      See Also:
    • RC_OPERATION_NOT_SUPPORTED

      public static final int RC_OPERATION_NOT_SUPPORTED
      See Also:
    • RC_RECURSION_COUNT_TOO_HIGH

      public static final int RC_RECURSION_COUNT_TOO_HIGH
      See Also:
    • RC_SERVER_BACKUP

      public static final int RC_SERVER_BACKUP
      See Also:
    • RC_HANDLE_NOT_FOUND

      public static final int RC_HANDLE_NOT_FOUND
      See Also:
    • RC_HANDLE_ALREADY_EXISTS

      public static final int RC_HANDLE_ALREADY_EXISTS
      See Also:
    • RC_INVALID_HANDLE

      public static final int RC_INVALID_HANDLE
      See Also:
    • RC_VALUES_NOT_FOUND

      public static final int RC_VALUES_NOT_FOUND
      See Also:
    • RC_VALUE_ALREADY_EXISTS

      public static final int RC_VALUE_ALREADY_EXISTS
      See Also:
    • RC_INVALID_VALUE

      public static final int RC_INVALID_VALUE
      See Also:
    • RC_OUT_OF_DATE_SITE_INFO

      public static final int RC_OUT_OF_DATE_SITE_INFO
      See Also:
    • RC_SERVER_NOT_RESP

      public static final int RC_SERVER_NOT_RESP
      See Also:
    • RC_SERVICE_REFERRAL

      public static final int RC_SERVICE_REFERRAL
      See Also:
    • RC_PREFIX_REFERRAL

      public static final int RC_PREFIX_REFERRAL
      See Also:
    • RC_INVALID_ADMIN

      public static final int RC_INVALID_ADMIN
      See Also:
    • RC_INSUFFICIENT_PERMISSIONS

      public static final int RC_INSUFFICIENT_PERMISSIONS
      See Also:
    • RC_AUTHENTICATION_NEEDED

      public static final int RC_AUTHENTICATION_NEEDED
      See Also:
    • RC_AUTHENTICATION_FAILED

      public static final int RC_AUTHENTICATION_FAILED
      See Also:
    • RC_INVALID_CREDENTIAL

      public static final int RC_INVALID_CREDENTIAL
      See Also:
    • RC_AUTHEN_TIMEOUT

      public static final int RC_AUTHEN_TIMEOUT
      See Also:
    • RC_AUTHEN_ERROR

      public static final int RC_AUTHEN_ERROR
      See Also:
    • RC_SESSION_TIMEOUT

      public static final int RC_SESSION_TIMEOUT
      See Also:
    • RC_SESSION_FAILED

      public static final int RC_SESSION_FAILED
      See Also:
    • RC_INVALID_SESSION_KEY

      public static final int RC_INVALID_SESSION_KEY
      See Also:
    • RC_NEED_RSAKEY_FOR_SESSIONEXCHANGE

      public static final int RC_NEED_RSAKEY_FOR_SESSIONEXCHANGE
      See Also:
    • RC_INVALID_SESSIONSETUP_REQUEST

      public static final int RC_INVALID_SESSIONSETUP_REQUEST
      See Also:
    • RC_SESSION_MESSAGE_REJECTED

      public static final int RC_SESSION_MESSAGE_REJECTED
      See Also:
    • 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 Details

    • AbstractMessage

      public AbstractMessage()
    • AbstractMessage

      public AbstractMessage(int opCode)
  • Method Details

    • clone

      protected AbstractMessage clone()
      Overrides:
      clone in class 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 session key + message header + message body + session key;
                        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(Signature signer) throws HandleException, 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
      SignatureException
    • signatureIsMac

      public boolean signatureIsMac() throws HandleException
      Throws:
      HandleException
    • verifyMessage

      public final boolean verifyMessage(byte[] secretKey) throws 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:
      Exception
    • verifyMessage

      public final boolean verifyMessage(PublicKey pubKey) throws 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:
      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 String toString()
      Overrides:
      toString in class Object
    • getResponseCodeMessage

      public static final String getResponseCodeMessage(int responseCode)