|
Message Security Layer (MSL) | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.netflix.msl.tokens.ServiceToken
public class ServiceToken
Service tokens are service-defined tokens carried as part of any MSL message. These tokens should be used to carry service state.
Service tokens are optionally bound to a specific master token and user ID token by their serial numbers.
Service tokens are either verified or encrypted. Verified tokens carry their data in the clear but are accompanied by a signature allowing the issuer to ensure the data has not been tampered with. Encrypted tokens encrypt their data as well as contain a signature.
Service tokens should use application- or service-specific crypto contexts and not the crypto context associated with the entity credentials or master token.
Service tokens are represented as
servicetoken = {
"#mandatory" : [ "tokendata", "signature" ],
"tokendata" : "base64,
"signature" : "base64"
}
where:
tokendata
is the Base64-encoded service token data (servicetokendata)signature
is the Base64-encoded verification data of the service token dataThe token data is represented as
servicetokendata = {
"#mandatory" : [ "name", "mtserialnumber", "uitserialnumber", "encrypted", "servicedata" ],
"name" : "string",
"mtserialnumber" : "int64(0,2^53^)",
"uitserialnumber" : "int64(0,2^53^)",
"encrypted" : "boolean",
"compressionalgo" : "enum(GZIP|LZW)",
"servicedata" : "base64"
}
where:
name
is the token namemtserialnumber
is the master token serial number or -1 if unboundutserialnumber
is the user ID token serial number or -1 if unboundencrypted
indicates if the service data is encrypted or notcompressionalgo
indicates the algorithm used to compress the dataservicedata
is the Base64-encoded optionally encrypted service dataService token names should follow a reverse fully-qualified domain hierarchy. e.g. com.netflix.service.tokenname.
Field Summary | |
---|---|
private MslConstants.CompressionAlgorithm |
compressionAlgo
Compression algorithm. |
private MslContext |
ctx
MSL context. |
private boolean |
encrypted
Service token data is encrypted. |
private static String |
KEY_COMPRESSION_ALGORITHM
JSON key compression algorithm. |
private static String |
KEY_ENCRYPTED
JSON key encrypted. |
private static String |
KEY_MASTER_TOKEN_SERIAL_NUMBER
JSON key master token serial number. |
private static String |
KEY_NAME
JSON key token name. |
private static String |
KEY_SERVICEDATA
JSON key service data. |
private static String |
KEY_SIGNATURE
JSON key signature. |
private static String |
KEY_TOKENDATA
JSON key token data. |
private static String |
KEY_USER_ID_TOKEN_SERIAL_NUMBER
JSON key user ID token serial number. |
private long |
mtSerialNumber
The service token master token serial number. |
private String |
name
The service token name. |
private byte[] |
servicedata
The service token data. |
private byte[] |
signature
Token data signature. |
private byte[] |
tokendata
Token data. |
private long |
uitSerialNumber
The service token user ID token serial number. |
private boolean |
verified
Token is verified. |
Constructor Summary | |
---|---|
ServiceToken(MslContext ctx,
JSONObject serviceTokenJO,
MasterToken masterToken,
UserIdToken userIdToken,
ICryptoContext cryptoContext)
Construct a new service token from the provided JSON object. |
|
ServiceToken(MslContext ctx,
JSONObject serviceTokenJO,
MasterToken masterToken,
UserIdToken userIdToken,
Map<String,ICryptoContext> cryptoContexts)
Construct a new service token from the provided JSON object and attempt to decrypt and verify the signature of the service token using the appropriate crypto context. |
|
ServiceToken(MslContext ctx,
String name,
byte[] data,
MasterToken masterToken,
UserIdToken userIdToken,
boolean encrypted,
MslConstants.CompressionAlgorithm compressionAlgo,
ICryptoContext cryptoContext)
Construct a new service token with the specified name and data. |
Method Summary | |
---|---|
boolean |
equals(Object obj)
|
MslConstants.CompressionAlgorithm |
getCompressionAlgo()
|
byte[] |
getData()
Returns the service data if the token data was not encrypted or we were able to decrypt it. |
long |
getMasterTokenSerialNumber()
Returns the serial number of the master token this service token is bound to. |
String |
getName()
|
long |
getUserIdTokenSerialNumber()
Returns the serial number of the user ID token this service token is bound to. |
int |
hashCode()
|
boolean |
isBoundTo(MasterToken masterToken)
|
boolean |
isBoundTo(UserIdToken userIdToken)
|
boolean |
isDecrypted()
|
boolean |
isDeleted()
|
boolean |
isEncrypted()
|
boolean |
isMasterTokenBound()
|
boolean |
isUnbound()
|
boolean |
isUserIdTokenBound()
Returns true if this token is bound to a user ID token. |
boolean |
isVerified()
|
private static ICryptoContext |
selectCryptoContext(JSONObject serviceTokenJO,
Map<String,ICryptoContext> cryptoContexts)
Select the appropriate crypto context for the service token represented by the provided JSON object. |
String |
toJSONString()
|
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final String KEY_TOKENDATA
private static final String KEY_SIGNATURE
private static final String KEY_NAME
private static final String KEY_MASTER_TOKEN_SERIAL_NUMBER
private static final String KEY_USER_ID_TOKEN_SERIAL_NUMBER
private static final String KEY_ENCRYPTED
private static final String KEY_COMPRESSION_ALGORITHM
private static final String KEY_SERVICEDATA
private final MslContext ctx
private final byte[] tokendata
private final byte[] signature
private final String name
private final long mtSerialNumber
private final long uitSerialNumber
private final boolean encrypted
private final MslConstants.CompressionAlgorithm compressionAlgo
private final byte[] servicedata
private final boolean verified
Constructor Detail |
---|
public ServiceToken(MslContext ctx, String name, byte[] data, MasterToken masterToken, UserIdToken userIdToken, boolean encrypted, MslConstants.CompressionAlgorithm compressionAlgo, ICryptoContext cryptoContext) throws MslEncodingException, MslCryptoException, MslException
Construct a new service token with the specified name and data. If a master token is provided, the service token is bound to the master token's serial number. If a user ID token is provided, the service token is bound to the user ID token's serial number.
For encrypted tokens, the token data is encrypted using the provided crypto context. For verified tokens, the token data is signed using the provided crypto context.
ctx
- the MSL context.name
- the service token name--must be unique.data
- the service token data (unencrypted).masterToken
- the master token. May be null.userIdToken
- the user ID token. May be null.encrypted
- true if the token should be encrypted.compressionAlgo
- the compression algorithm. May be null
for no compression.cryptoContext
- the crypto context.
MslEncodingException
- if there is an error encoding the JSON
data.
MslCryptoException
- if there is an error encrypting or signing
the token data.
MslException
- if there is an error compressing the data.public ServiceToken(MslContext ctx, JSONObject serviceTokenJO, MasterToken masterToken, UserIdToken userIdToken, Map<String,ICryptoContext> cryptoContexts) throws MslEncodingException, MslCryptoException, MslException
Construct a new service token from the provided JSON object and attempt to decrypt and verify the signature of the service token using the appropriate crypto context. If the data cannot be decrypted or the signature cannot be verified, the token will still be created.
If the service token name exists as a key in the map of crypto contexts, the mapped crypto context will be used. Otherwise the default crypto context mapped from the empty string key will be used.
If a matching crypto context is found, the token data will be decrypted and its signature verified.
If the service token is bound to a master token or user ID token it will be verified against the provided master token or user ID tokens which must not be null.
ctx
- the MSL context.serviceTokenJO
- the JSON object.masterToken
- the master token. May be null.userIdToken
- the user ID token. May be null.cryptoContexts
- a map of service token names onto crypto contexts.
MslEncodingException
- if there is a problem parsing the JSON.
MslCryptoException
- if there is an error decrypting or verifying
the token data.
MslException
- if the service token is bound to a master token or
user ID token and the provided tokens are null or the serial
numbers do not match, or if bound to a user ID token but not to
a master token, or if the service data is missing, or if the
compression algorithm is not known or there is an error
uncompressing the data.public ServiceToken(MslContext ctx, JSONObject serviceTokenJO, MasterToken masterToken, UserIdToken userIdToken, ICryptoContext cryptoContext) throws MslCryptoException, MslEncodingException, MslException
Construct a new service token from the provided JSON object.
If a crypto context is provided, the token data will be decrypted and its signature verified. If the data cannot be decrypted or the signature cannot be verified, the token will still be created.
If the service token is bound to a master token or user ID token it will be verified against the provided master token or user ID tokens which must not be null.
ctx
- the MSL context.serviceTokenJO
- the JSON object.masterToken
- the master token. May be null.userIdToken
- the user ID token. May be null.cryptoContext
- the crypto context. May be null.
MslCryptoException
- if there is a problem decrypting or verifying
the token data.
MslEncodingException
- if there is a problem parsing the JSON, the
token data is missing or invalid, or the signature is invalid.
MslException
- if the service token is bound to a master token or
user ID token and the provided tokens are null or the serial
numbers do not match, or if bound to a user ID token but not to
a master token, or if the service data is missing, or if the
service token master token serial number is out of range, or if
the service token user ID token serial number is out of range,
or if the compression algorithm is not known or there is an
error uncompressing the data.Method Detail |
---|
private static ICryptoContext selectCryptoContext(JSONObject serviceTokenJO, Map<String,ICryptoContext> cryptoContexts) throws MslEncodingException
Select the appropriate crypto context for the service token represented by the provided JSON object.
If the service token name exists as a key in the map of crypto contexts, the mapped crypto context will be returned. Otherwise the default crypto context mapped from the empty string key will be returned. If no explicit or default crypto context exists null will be returned.
serviceTokenJO
- the JSON object.cryptoContexts
- the map of service token names onto crypto
contexts used to decrypt and verify service tokens.
MslEncodingException
- if there is a problem parsing the JSON.public boolean isEncrypted()
public boolean isDecrypted()
public boolean isVerified()
public String getName()
public boolean isDeleted()
getData()
public MslConstants.CompressionAlgorithm getCompressionAlgo()
null
if not
compressed.public byte[] getData()
isDeleted()
public long getMasterTokenSerialNumber()
public boolean isMasterTokenBound()
public boolean isBoundTo(MasterToken masterToken)
masterToken
- master token. May be null.
public long getUserIdTokenSerialNumber()
public boolean isUserIdTokenBound()
public boolean isBoundTo(UserIdToken userIdToken)
userIdToken
- user ID token. May be null.
public boolean isUnbound()
public String toJSONString()
public String toString()
toString
in class Object
public boolean equals(Object obj)
equals
in class Object
obj
- the reference object with which to compare.
Object.equals(java.lang.Object)
public int hashCode()
hashCode
in class Object
|
Message Security Layer (MSL) | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |