private byte[] entropyBytes;
private byte[] secret;
private boolean computedKey;
public SymmetricKeyHandler(TokenProviderParameters tokenParameters) {
KeyRequirements keyRequirements = tokenParameters.getKeyRequirements();
// Test KeySize
keySize = Long.valueOf(keyRequirements.getKeySize()).intValue();
STSPropertiesMBean stsProperties = tokenParameters.getStsProperties();
SignatureProperties signatureProperties = stsProperties.getSignatureProperties();
if (keySize < signatureProperties.getMinimumKeySize()
|| keySize > signatureProperties.getMaximumKeySize()) {
keySize = Long.valueOf(signatureProperties.getKeySize()).intValue();
LOG.log(
Level.WARNING, "Received KeySize of " + keyRequirements.getKeySize()
+ " not accepted so defaulting to " + signatureProperties.getKeySize()
);
}
// Test Entropy
clientEntropy = keyRequirements.getEntropy();
if (clientEntropy == null) {
LOG.log(Level.WARNING, "A SymmetricKey KeyType is requested, but no client entropy is provided");
} else {
String binarySecurityType = clientEntropy.getBinarySecretType();
byte[] nonce = clientEntropy.getBinarySecretValue();
if (!STSConstants.NONCE_TYPE.equals(binarySecurityType)) {
LOG.log(Level.WARNING, "The type " + binarySecurityType + " is not supported");
throw new STSException(
"No user supplied entropy for SymmetricKey case", STSException.INVALID_REQUEST
);
}
if (nonce == null || (nonce.length < (keySize / 8))) {
LOG.log(Level.WARNING, "User Entropy rejected");
clientEntropy = null;
}
String computedKeyAlgorithm = keyRequirements.getComputedKeyAlgorithm();
if (!STSConstants.COMPUTED_KEY_PSHA1.equals(computedKeyAlgorithm)) {
LOG.log(
Level.WARNING,
"The computed key algorithm of " + computedKeyAlgorithm + " is not supported"
);