Message Security Layer (MSL)

com.netflix.msl.msg
Class MessageInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.netflix.msl.msg.MessageInputStream
All Implemented Interfaces:
Closeable

public class MessageInputStream
extends InputStream

A MSL message consists of a single MSL header followed by one or more payload chunks carrying application data. Each payload chunk is individually packaged but sequentially ordered. No payload chunks may be included in an error message.

Data is read until an end-of-message payload chunk is encountered or an error occurs. Closing a MessageInputStream does not close the source input stream in case additional MSL messages will be read.


Constructor Summary
MessageInputStream(MslContext ctx, InputStream source, Charset charset, Set<KeyRequestData> keyRequestData, Map<String,ICryptoContext> cryptoContexts)
          Construct a new message input stream.
 
Method Summary
 int available()
           
 void close()
           
 void closeSource(boolean close)
          By default the source input stream is not closed when this message input stream is closed.
protected  void finalize()
           
 ErrorHeader getErrorHeader()
           
 String getIdentity()
          Returns the sender's entity identity.
 ICryptoContext getKeyExchangeCryptoContext()
           
 MessageHeader getMessageHeader()
           
 ICryptoContext getPayloadCryptoContext()
           
 com.netflix.msl.tokens.MslUser getUser()
          Returns the user associated with the message.
 boolean isHandshake()
          Returns true if the message is a handshake message.
 void mark(int readlimit)
           
 boolean markSupported()
           
 int read()
           
 int read(byte[] cbuf)
           
 int read(byte[] cbuf, int off, int len)
           
 void reset()
           
 long skip(long n)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageInputStream

public MessageInputStream(MslContext ctx,
                          InputStream source,
                          Charset charset,
                          Set<KeyRequestData> keyRequestData,
                          Map<String,ICryptoContext> cryptoContexts)
                   throws MslEncodingException,
                          MslEntityAuthException,
                          MslCryptoException,
                          MslUserAuthException,
                          MslMessageException,
                          MslKeyExchangeException,
                          MslMasterTokenException,
                          MslUserIdTokenException,
                          MslMessageException,
                          MslException

Construct a new message input stream. The header is parsed.

If key request data is provided and a matching key response data is found in the message header the key exchange will be performed to process the message payloads.

Service tokens will be decrypted and verified with the provided crypto contexts identified by token name. A default crypto context may be provided by using the empty string as the token name; if a token name is not explcitly mapped onto a crypto context, the default crypto context will be used.

Parameters:
ctx - MSL context.
source - MSL input stream.
charset - input stream character set encoding.
keyRequestData - key request data to use when processing key response data.
cryptoContexts - the map of service token names onto crypto contexts used to decrypt and verify service tokens.
Throws:
MslEncodingException - if there is an error parsing the message.
MslCryptoException - if there is an error decrypting or verifying the header or creating the message payload crypto context.
MslEntityAuthException - if unable to create the entity authentication data.
MslUserAuthException - if unable to create the user authentication data.
MslMessageException - if the message master token is expired and the message is not renewable.
MslMasterTokenException - if the master token is not trusted and needs to be or if it has been revoked.
MslUserIdTokenException - if the user ID token has been revoked.
MslKeyExchangeException - if there is an error with the key request data or key response data or the key exchange scheme is not supported.
MslMessageException - if the message master token is expired and the message is not renewable.
MslException - if the message does not contain an entity authentication data or a master token, or a token is improperly bound to another token.
Method Detail

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

isHandshake

public boolean isHandshake()
                    throws MslCryptoException,
                           MslEncodingException,
                           MslMessageException,
                           MslInternalException,
                           MslException
Returns true if the message is a handshake message. FIXME This method should be removed by a direct query of the message header once the old behavior of inferred handshake messages based on a single empty payload chunk is no longer supported.

Returns:
true if the message is a handshake message.
Throws:
MslCryptoException - if there is a problem decrypting or verifying the payload chunk.
MslEncodingException - if there is a problem parsing the JSON.
MslMessageException - if the payload verification failed.
MslInternalException - if attempting to access payloads of an error message.
MslException - if there is an error uncompressing the data.

getMessageHeader

public MessageHeader getMessageHeader()
Returns:
the message header. Will be null for error messages.

getErrorHeader

public ErrorHeader getErrorHeader()
Returns:
the error header. Will be null except for error messages.

getIdentity

public String getIdentity()
                   throws MslCryptoException
Returns the sender's entity identity. The identity will be unknown if the local entity is a trusted network client and the message was sent by a trusted network server using the local entity's master token.

Returns:
the sender's entity identity or null if unknown.
Throws:
MslCryptoException - if there is a crypto error accessing the entity identity;

getUser

public com.netflix.msl.tokens.MslUser getUser()
Returns the user associated with the message. The user will be unknown if the local entity is a trusted network client and the message was sent by a trusted network server.

Returns:
the user associated with the message or null if unknown.

getPayloadCryptoContext

public ICryptoContext getPayloadCryptoContext()
Returns:
the payload crypto context. Will be null for error messages.

getKeyExchangeCryptoContext

public ICryptoContext getKeyExchangeCryptoContext()
Returns:
the key exchange crypto context. Will be null if no key response data was returned in this message and for error messages.

available

public int available()
              throws IOException
Overrides:
available in class InputStream
Throws:
IOException

closeSource

public void closeSource(boolean close)
By default the source input stream is not closed when this message input stream is closed. If it should be closed then this method can be used to dictate the desired behavior.

Parameters:
close - true if the source input stream should be closed, false if it should not.

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException

mark

public void mark(int readlimit)
Overrides:
mark in class InputStream

markSupported

public boolean markSupported()
Overrides:
markSupported in class InputStream

read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] cbuf,
                int off,
                int len)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

read

public int read(byte[] cbuf)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

reset

public void reset()
           throws IOException
Overrides:
reset in class InputStream
Throws:
IOException

skip

public long skip(long n)
          throws IOException
Overrides:
skip in class InputStream
Throws:
IOException

Message Security Layer (MSL)

Copyright © 2014 Netflix, Inc. All Rights Reserved.