use of org.opensaml.xmlsec.keyinfo.impl.X509KeyInfoGeneratorFactory in project syncope by apache.
the class SAML2ReaderWriter method init.
public void init() {
X509KeyInfoGeneratorFactory keyInfoGeneratorFactory = new X509KeyInfoGeneratorFactory();
keyInfoGeneratorFactory.setEmitEntityCertificate(true);
keyInfoGenerator = keyInfoGeneratorFactory.newInstance();
// Try to load a signature algorithm
if (loader.getSignatureAlgorithm() != null) {
SignatureAlgorithm loadedSignatureAlgorithm = SignatureAlgorithm.valueOf(loader.getSignatureAlgorithm());
if (loadedSignatureAlgorithm != null) {
sigAlgo = loadedSignatureAlgorithm.getAlgorithm();
jceSigAlgo = JCEMapper.translateURItoJCEID(sigAlgo);
}
if (jceSigAlgo == null) {
LOG.warn("Signature algorithm {} is not valid. Using default algorithm instead.", loader.getSignatureAlgorithm());
sigAlgo = null;
}
}
if (sigAlgo == null) {
sigAlgo = SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA1;
String pubKeyAlgo = loader.getCredential().getPublicKey().getAlgorithm();
if (pubKeyAlgo.equalsIgnoreCase("DSA")) {
sigAlgo = SignatureConstants.ALGO_ID_SIGNATURE_DSA_SHA1;
} else if (pubKeyAlgo.equalsIgnoreCase("EC")) {
sigAlgo = SignatureConstants.ALGO_ID_SIGNATURE_ECDSA_SHA1;
}
jceSigAlgo = JCEMapper.translateURItoJCEID(sigAlgo);
}
callbackHandler = new SAMLSPCallbackHandler(loader.getKeyPass());
}
use of org.opensaml.xmlsec.keyinfo.impl.X509KeyInfoGeneratorFactory in project spring-security by spring-projects.
the class OpenSamlSigningUtils method buildSignatureKeyInfoGeneratorManager.
private static NamedKeyInfoGeneratorManager buildSignatureKeyInfoGeneratorManager() {
final NamedKeyInfoGeneratorManager namedManager = new NamedKeyInfoGeneratorManager();
namedManager.setUseDefaultManager(true);
final KeyInfoGeneratorManager defaultManager = namedManager.getDefaultManager();
// Generator for X509Credentials
final X509KeyInfoGeneratorFactory x509Factory = new X509KeyInfoGeneratorFactory();
x509Factory.setEmitEntityCertificate(true);
x509Factory.setEmitEntityCertificateChain(true);
defaultManager.registerFactory(x509Factory);
return namedManager;
}
use of org.opensaml.xmlsec.keyinfo.impl.X509KeyInfoGeneratorFactory in project spring-security by spring-projects.
the class OpenSamlSigningUtils method buildSignatureKeyInfoGeneratorManager.
private static NamedKeyInfoGeneratorManager buildSignatureKeyInfoGeneratorManager() {
final NamedKeyInfoGeneratorManager namedManager = new NamedKeyInfoGeneratorManager();
namedManager.setUseDefaultManager(true);
final KeyInfoGeneratorManager defaultManager = namedManager.getDefaultManager();
// Generator for X509Credentials
final X509KeyInfoGeneratorFactory x509Factory = new X509KeyInfoGeneratorFactory();
x509Factory.setEmitEntityCertificate(true);
x509Factory.setEmitEntityCertificateChain(true);
defaultManager.registerFactory(x509Factory);
return namedManager;
}
use of org.opensaml.xmlsec.keyinfo.impl.X509KeyInfoGeneratorFactory in project spring-security by spring-projects.
the class OpenSamlSigningUtils method buildSignatureKeyInfoGeneratorManager.
private static NamedKeyInfoGeneratorManager buildSignatureKeyInfoGeneratorManager() {
final NamedKeyInfoGeneratorManager namedManager = new NamedKeyInfoGeneratorManager();
namedManager.setUseDefaultManager(true);
final KeyInfoGeneratorManager defaultManager = namedManager.getDefaultManager();
// Generator for X509Credentials
final X509KeyInfoGeneratorFactory x509Factory = new X509KeyInfoGeneratorFactory();
x509Factory.setEmitEntityCertificate(true);
x509Factory.setEmitEntityCertificateChain(true);
defaultManager.registerFactory(x509Factory);
return namedManager;
}
use of org.opensaml.xmlsec.keyinfo.impl.X509KeyInfoGeneratorFactory in project cxf by apache.
the class CombinedValidatorTest method signResponse.
private void signResponse(Response response, String issuerKeyName, String issuerKeyPassword, Crypto issuerCrypto, boolean useKeyInfo) throws Exception {
//
// Create the signature
//
Signature signature = OpenSAMLUtil.buildSignature();
signature.setCanonicalizationAlgorithm(SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);
// prepare to sign the SAML token
CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ALIAS);
cryptoType.setAlias(issuerKeyName);
X509Certificate[] issuerCerts = issuerCrypto.getX509Certificates(cryptoType);
if (issuerCerts == null) {
throw new Exception("No issuer certs were found to sign the SAML Assertion using issuer name: " + issuerKeyName);
}
String sigAlgo = SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA1;
String pubKeyAlgo = issuerCerts[0].getPublicKey().getAlgorithm();
if ("DSA".equalsIgnoreCase(pubKeyAlgo)) {
sigAlgo = SignatureConstants.ALGO_ID_SIGNATURE_DSA;
}
PrivateKey privateKey = issuerCrypto.getPrivateKey(issuerKeyName, issuerKeyPassword);
signature.setSignatureAlgorithm(sigAlgo);
BasicX509Credential signingCredential = new BasicX509Credential(issuerCerts[0], privateKey);
signature.setSigningCredential(signingCredential);
if (useKeyInfo) {
X509KeyInfoGeneratorFactory kiFactory = new X509KeyInfoGeneratorFactory();
kiFactory.setEmitEntityCertificate(true);
try {
KeyInfo keyInfo = kiFactory.newInstance().generate(signingCredential);
signature.setKeyInfo(keyInfo);
} catch (org.opensaml.security.SecurityException ex) {
throw new Exception("Error generating KeyInfo from signing credential", ex);
}
}
// add the signature to the assertion
SignableSAMLObject signableObject = response;
signableObject.setSignature(signature);
signableObject.releaseDOM();
signableObject.releaseChildrenDOM(true);
}
Aggregations