use of com.sun.identity.saml2.jaxb.xmlenc.EncryptionMethodType in project OpenAM by OpenRock.
the class KeyUtil method getEncInfo.
/**
* Returns the encryption information which will be used in
* encrypting messages intended for the partner entity.
* @param roled <code>RoleDescriptor</code> for the partner entity
* @param entityID partner entity's ID
* @param role entity's role
* @return <code>EncInfo</code> which includes partner entity's
* public key for wrapping the secret key, data encryption algorithm,
* and data encryption strength
*/
public static EncInfo getEncInfo(RoleDescriptorType roled, String entityID, String role) {
String classMethod = "KeyUtil.getEncInfo: ";
if (SAML2SDKUtils.debug.messageEnabled()) {
SAML2SDKUtils.debug.message(classMethod + "Entering... \nEntityID=" + entityID + "\nRole=" + role);
}
// first try to get it from cache
String index = entityID.trim() + "|" + role;
EncInfo encInfo = (EncInfo) encHash.get(index);
if (encInfo != null) {
return encInfo;
}
// else get it from meta
if (roled == null) {
SAML2SDKUtils.debug.error(classMethod + "Null RoleDescriptorType input for entityID=" + entityID + " in " + role + " role.");
return null;
}
KeyDescriptorType kd = getKeyDescriptor(roled, SAML2Constants.ENCRYPTION);
if (kd == null) {
SAML2SDKUtils.debug.error(classMethod + "No encryption KeyDescriptor for entityID=" + entityID + " in " + role + " role.");
return null;
}
java.security.cert.X509Certificate cert = getCert(kd);
if (cert == null) {
SAML2SDKUtils.debug.error(classMethod + "No encryption cert for entityID=" + entityID + " in " + role + " role.");
return null;
}
List emList = kd.getEncryptionMethod();
EncryptionMethodType em = null;
String algorithm = null;
int keySize = 0;
if (emList != null && !emList.isEmpty()) {
em = (EncryptionMethodType) emList.get(0);
if (em != null) {
algorithm = em.getAlgorithm();
List cList = em.getContent();
if (cList != null) {
Iterator cIter = cList.iterator();
while (cIter.hasNext()) {
Object cObject = cIter.next();
if (cObject instanceof EncryptionMethodType.KeySize) {
keySize = ((EncryptionMethodType.KeySize) (cList.get(0))).getValue().intValue();
break;
}
}
}
}
}
if (algorithm == null || algorithm.length() == 0) {
algorithm = XMLCipher.AES_128;
keySize = 128;
}
PublicKey pk = cert.getPublicKey();
if (pk != null) {
encInfo = new EncInfo(pk, algorithm, keySize);
}
if (encInfo != null) {
encHash.put(index, encInfo);
}
return encInfo;
}
Aggregations