Skip to content

Commit

Permalink
Merge pull request #266 from Netflix/restore-sender
Browse files Browse the repository at this point in the history
Include sender field when constructing a message header with a master token.
  • Loading branch information
wmiaw authored Apr 25, 2018
2 parents 5965124 + be9e9d4 commit 0e190bc
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 153 deletions.
17 changes: 17 additions & 0 deletions core/src/main/java/com/netflix/msl/msg/MessageHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public class MessageHeader extends Header {
private static final long MILLISECONDS_PER_SECOND = 1000;

// Message header data.
/** Key sender. */
private static final String KEY_SENDER = "sender";
/** Key timestamp. */
private static final String KEY_TIMESTAMP = "timestamp";
/** Key message ID. */
Expand Down Expand Up @@ -268,6 +270,20 @@ public MessageHeader(final MslContext ctx, final EntityAuthenticationData entity
}
if (!encrypted && headerData.userAuthData != null)
throw new MslInternalException("User authentication data cannot be included if the message is not encrypted.");

// Older MSL stacks expect the sender if a master token is being used.
//
// If the local entity does not know its entity identity, then use the
// empty string. This will work except for the case where the old MSL
// stack is receiving a message for which it is also the issuer of the
// master token. That scenario will continue to fail.
final String sender;
if (masterToken != null) {
final String localIdentity = ctx.getEntityAuthenticationData(null).getIdentity();
sender = (localIdentity != null) ? localIdentity : "";
} else {
sender = null;
}

this.entityAuthData = (masterToken == null) ? entityAuthData : null;
this.masterToken = masterToken;
Expand Down Expand Up @@ -341,6 +357,7 @@ public MessageHeader(final MslContext ctx, final EntityAuthenticationData entity
try {
final MslEncoderFactory encoder = ctx.getMslEncoderFactory();
headerdata = encoder.createObject();
if (sender != null) headerdata.put(KEY_SENDER, sender);
headerdata.put(KEY_TIMESTAMP, this.timestamp);
headerdata.put(KEY_MESSAGE_ID, this.messageId);
headerdata.put(KEY_NON_REPLAYABLE, this.nonReplayableId != null);
Expand Down
Loading

0 comments on commit 0e190bc

Please sign in to comment.