Element elem,
RequestData data,
WSDocInfo wsDocInfo
) throws WSSecurityException {
// Deserialize the DKT
DerivedKeyToken dkt = new DerivedKeyToken(elem, data.getBSPEnforcer());
// Check for compliance against the defined AlgorithmSuite
AlgorithmSuite algorithmSuite = data.getAlgorithmSuite();
if (algorithmSuite != null) {
AlgorithmSuiteValidator algorithmSuiteValidator = new
AlgorithmSuiteValidator(algorithmSuite);
algorithmSuiteValidator.checkDerivedKeyAlgorithm(
dkt.getAlgorithm()
);
}
byte[] secret = null;
Element secRefElement = dkt.getSecurityTokenReferenceElement();
if (secRefElement != null) {
STRParser strParser = new DerivedKeyTokenSTRParser();
strParser.parseSecurityTokenReference(
secRefElement, data, wsDocInfo, null
);
secret = strParser.getSecretKey();
} else {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_CHECK, "noReference");
}
String tempNonce = dkt.getNonce();
if (tempNonce == null) {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty", "Missing wsc:Nonce value");
}
int length = dkt.getLength();
byte[] keyBytes = dkt.deriveKey(length, secret);
WSSecurityEngineResult result =
new WSSecurityEngineResult(WSConstants.DKT, null, keyBytes, null);
wsDocInfo.addTokenElement(elem);
String tokenId = dkt.getID();
if (!"".equals(tokenId)) {
result.put(WSSecurityEngineResult.TAG_ID, tokenId);
}
result.put(WSSecurityEngineResult.TAG_DERIVED_KEY_TOKEN, dkt);
result.put(WSSecurityEngineResult.TAG_SECRET, secret);
result.put(WSSecurityEngineResult.TAG_TOKEN_ELEMENT, dkt.getElement());
wsDocInfo.addResult(result);
return java.util.Collections.singletonList(result);
}