|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.svrCore.datasource.ExhibitDataTunnelSource.PacketProtector
public static final class ExhibitDataTunnelSource.PacketProtector
The immutable adjunct for a RawPacket that includes the HMAC and other anti-attack data. Note that this class is NOT directly serialisable, with the data fields sent in some other way, eg as HTTP header fields "out-of-band" from the actual HTTP message.
| Field Summary | |
|---|---|
private static java.util.regex.Pattern |
fieldSplitPattern
Field splitter regex pattern compiled once for efficiency; never null. |
int |
length
The length of the entire frame/datastream being protected, input to each MAC; non-negative. |
java.util.List<ROByteArray> |
mac
The immutable in-order list of MAC authenticator segments for the stream and fields herein; never null nor empty nor containing nulls. |
static int |
MAX_CHECK_STRING_CHARS
Maximum size in (ASCII) characters of output of toCheckString(); strictly positive. |
static int |
MAX_SEGMENT_SIZE
Maximum segment size; strictly positive power of two. |
static int |
MAX_SEGMENTS
Maximum number of segments protected stream may be broken into; strictly positive power of two. |
static int |
MIN_SEGMENT_SIZE
Minimum segment size (other than final segment); strictly positive power of two. |
long |
timestamp
The timestamp for the RawPacket, input to each MAC; strictly positive. |
| Constructor Summary | |
|---|---|
ExhibitDataTunnelSource.PacketProtector(ExhibitDataTunnelSource.RawPacket raw,
long timestamp,
javax.crypto.SecretKey key)
Create an adjunct to protect a RawPacket, including the given timestamp. |
|
ExhibitDataTunnelSource.PacketProtector(ExhibitDataTunnelSource.RawPacket raw,
javax.crypto.SecretKey key)
Create an adjunct to protect a RawPacket, including a current timestamp. |
|
ExhibitDataTunnelSource.PacketProtector(long timestamp,
int length,
java.util.List<ROByteArray> mac)
Create an adjunct to protect a RawPacket. |
|
| Method Summary | |
|---|---|
static java.util.List<ROByteArray> |
computeMAC(long timestamp,
ExhibitDataTunnelSource.RawPacket raw,
javax.crypto.SecretKey key)
Compute the MAC given the message and other fields to be included; never null. |
private static int |
computeSegmentSize(int frameLength)
Compute segment size; strictly positive power of two. |
boolean |
equals(java.lang.Object obj)
Equality depends on all the members being equal. |
static ExhibitDataTunnelSource.PacketProtector |
fromCheckString(java.lang.String check)
Parses a check-string as generated by toCheckString(); never null. |
int |
hashCode()
We use the timestamp and length fields in the hash for the entire collection. |
java.io.InputStream |
protectInputStream(java.security.Key key,
java.io.InputStream is)
Protect an input stream with our MAC; aborts with IOException in case of corruption. |
java.lang.String |
toCheckString()
Generate (HTTP-header) check-string; never null nor empty. |
void |
validateObject()
Checks only that the object content is valid. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public final long timestamp
public final int length
public final java.util.List<ROByteArray> mac
Note that the last MAC, which depends on all the data being protected, can be used as a unique message MAC on its own.
public static final int MAX_CHECK_STRING_CHARS
private static final java.util.regex.Pattern fieldSplitPattern
public static final int MAX_SEGMENTS
This value is capped to limit the amount of MAC data that needs to be sent, eg in an HTTP header of limited length.
public static final int MIN_SEGMENT_SIZE
This is small enough to represent a reasonable incremental amount of CPU for streamed inputs.
public static final int MAX_SEGMENT_SIZE
| Constructor Detail |
|---|
public ExhibitDataTunnelSource.PacketProtector(ExhibitDataTunnelSource.RawPacket raw,
javax.crypto.SecretKey key)
throws java.security.InvalidKeyException
raw - the RawPacket to protect; never nullkey - the (secret) key for the HMAC; never null
java.security.InvalidKeyException
public ExhibitDataTunnelSource.PacketProtector(ExhibitDataTunnelSource.RawPacket raw,
long timestamp,
javax.crypto.SecretKey key)
throws java.security.InvalidKeyException
raw - the RawPacket to protect; never nulltimestamp - the timestamp for creation/send of the RawPacket; strictly positivekey - the (secret) key for the HMAC; never null
java.security.InvalidKeyException
public ExhibitDataTunnelSource.PacketProtector(long timestamp,
int length,
java.util.List<ROByteArray> mac)
timestamp - the timestamp for creation/send of the RawPacket; strictly positivemac - the HMAC for the RawPacket and other fields, not checked; never null| Method Detail |
|---|
public java.lang.String toCheckString()
This object is suitable (short enough, avoidance of meta-characters) to be used directly in an HTTP header.
This value is suitable to be decoded by fromCheckString().
The format is a space-separated list of fields:
public static ExhibitDataTunnelSource.PacketProtector fromCheckString(java.lang.String check)
java.lang.IllegalArgumentException - if the input is unparsableprivate static final int computeSegmentSize(int frameLength)
All segments are of the same size, except the last one which may be shorter.
public static java.util.List<ROByteArray> computeMAC(long timestamp,
ExhibitDataTunnelSource.RawPacket raw,
javax.crypto.SecretKey key)
throws java.security.InvalidKeyException
The MAC is computed on a series of segments of the input of the same length (except for a possibly-shorter final segment) producing an HMAC on each segment.
Each HMAC is computed over a binary message consisting of:
The chaining should make it impossible to reorder the segments.
The segmentation is so that the data in each segment is known-safe and can be safely consumed by incremental/streaming CPU-heavy operations before subsequent segments have been received and decoded. This segmentation also means that we can abort a damaged message as soon as we check the damaged segment: we do not need to wait to receive and store and check the whole message.
raw - the RawPacket to protect; never nulltimestamp - the timestamp for creation/send of the RawPacket; strictly positivekey - the (secret) key for the HMAC; never null
java.security.InvalidKeyException - if the Key supplied is inappropriate
java.lang.IllegalArgumentException - if the timestamp is non-positive
or any other argument is null
java.lang.IllegalStateException - if the HMAC algorithm is unavailable
public java.io.InputStream protectInputStream(java.security.Key key,
java.io.InputStream is)
This closes its input stream and vetoes any further operations once any error has been encountered.
We use Key rather than SecretKey, since the latter depends on Java extensions that may not be available, eg when run in JWS.
Returned input stream not to be multi-threaded.
public void validateObject()
throws java.io.InvalidObjectException
Partly this does not check the MAC because it does not have access to the key.
java.io.InvalidObjectExceptionpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object
|
DHD Multimedia Gallery V1.60.69 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||