Class 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 Detail

      • OC_RESPONSE_TO_CHALLENGE

        public static final int OC_RESPONSE_TO_CHALLENGE
        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_HANDLE_ALREADY_EXISTS

        public static final int RC_HANDLE_ALREADY_EXISTS
        See Also:
        Constant Field Values
      • RC_VALUE_ALREADY_EXISTS

        public static final int RC_VALUE_ALREADY_EXISTS
        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_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_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 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​(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
      • 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)