use of org.jose4j.keys.AesKey in project cas by apereo.
the class AccepttoApiUtils method buildAuthorizationHeaderPayloadForAuthentication.
private static String buildAuthorizationHeaderPayloadForAuthentication(final AccepttoMultifactorAuthenticationProperties acceptto) {
val claims = new JwtClaims();
claims.setClaim("uid", acceptto.getOrganizationId());
claims.setExpirationTimeMinutesInTheFuture(1);
val payload = claims.toJson();
LOGGER.trace("Authorization payload is [{}]", payload);
val signingKey = new AesKey(acceptto.getOrganizationSecret().getBytes(StandardCharsets.UTF_8));
LOGGER.trace("Signing authorization payload...");
val signedBytes = EncodingUtils.signJwsHMACSha256(signingKey, payload.getBytes(StandardCharsets.UTF_8), Map.of());
val authzPayload = new String(signedBytes, StandardCharsets.UTF_8);
LOGGER.trace("Signed authorization payload is [{}]", authzPayload);
return authzPayload;
}
use of org.jose4j.keys.AesKey in project cas by apereo.
the class AbstractCipherExecutor method configureSigningKey.
/**
* Sets signing key. If the key provided is resolved as a private key,
* then will create use the private key as is, and will sign values
* using RSA. Otherwise, AES is used.
*
* @param signingSecretKey the signing secret key
*/
protected void configureSigningKey(final String signingSecretKey) {
try {
if (ResourceUtils.doesResourceExist(signingSecretKey)) {
configureSigningKeyFromPrivateKeyResource(signingSecretKey);
}
} finally {
if (this.signingKey == null) {
setSigningKey(new AesKey(signingSecretKey.getBytes(StandardCharsets.UTF_8)));
LOGGER.trace("Created signing key instance [{}] based on provided secret key", this.signingKey.getClass().getSimpleName());
}
}
}
use of org.jose4j.keys.AesKey in project cas by apereo.
the class EncodingUtilsTests method verifyAesKeyForJwtSigning.
@Test
public void verifyAesKeyForJwtSigning() {
val secret = EncodingUtils.generateJsonWebKey(512);
val key = new AesKey(secret.getBytes(StandardCharsets.UTF_8));
val value = "ThisValue";
val signed = EncodingUtils.signJwsHMACSha512(key, value.getBytes(StandardCharsets.UTF_8), Map.of());
val jwt = EncodingUtils.verifyJwsSignature(key, signed);
val result = new String(jwt, StandardCharsets.UTF_8);
assertEquals(value, result);
}
use of org.jose4j.keys.AesKey in project cas by apereo.
the class OidcClientSecretJwtAuthenticatorTests method verifyDisabledServiceAction.
@Test
public void verifyDisabledServiceAction() throws Exception {
val auth = new OidcClientSecretJwtAuthenticator(servicesManager, registeredServiceAccessStrategyEnforcer, ticketRegistry, webApplicationServiceFactory, casProperties, applicationContext);
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
val context = new JEEContext(request, response);
val audience = casProperties.getServer().getPrefix().concat('/' + OidcConstants.BASE_OIDC_URL + '/' + OidcConstants.ACCESS_TOKEN_URL);
val registeredService = getOidcRegisteredService(UUID.randomUUID().toString());
registeredService.setAccessStrategy(new DefaultRegisteredServiceAccessStrategy().setEnabled(false));
servicesManager.save(registeredService);
val claims = getClaims(registeredService.getClientId(), registeredService.getClientId(), registeredService.getClientId(), audience);
val key = EncodingUtils.generateJsonWebKey(512);
val jwt = EncodingUtils.signJwsHMACSha512(new AesKey(key.getBytes(StandardCharsets.UTF_8)), claims.toJson().getBytes(StandardCharsets.UTF_8), Map.of());
val credentials = getCredentials(request, OAuth20Constants.CLIENT_ASSERTION_TYPE_JWT_BEARER, new String(jwt, StandardCharsets.UTF_8), registeredService.getClientId());
auth.validate(credentials, context, JEESessionStore.INSTANCE);
assertNull(credentials.getUserProfile());
}
use of org.jose4j.keys.AesKey in project cas by apereo.
the class OidcClientSecretJwtAuthenticatorTests method verifyAction.
@Test
public void verifyAction() throws Exception {
val auth = new OidcClientSecretJwtAuthenticator(servicesManager, registeredServiceAccessStrategyEnforcer, ticketRegistry, webApplicationServiceFactory, casProperties, applicationContext);
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
val context = new JEEContext(request, response);
val audience = casProperties.getServer().getPrefix().concat('/' + OidcConstants.BASE_OIDC_URL + '/' + OidcConstants.ACCESS_TOKEN_URL);
val registeredService = getOidcRegisteredService();
val claims = getClaims(registeredService.getClientId(), registeredService.getClientId(), registeredService.getClientId(), audience);
val key = EncodingUtils.generateJsonWebKey(512);
val jwt = EncodingUtils.signJwsHMACSha512(new AesKey(key.getBytes(StandardCharsets.UTF_8)), claims.toJson().getBytes(StandardCharsets.UTF_8), Map.of());
val credentials = getCredentials(request, OAuth20Constants.CLIENT_ASSERTION_TYPE_JWT_BEARER, new String(jwt, StandardCharsets.UTF_8), registeredService.getClientId());
auth.validate(credentials, context, JEESessionStore.INSTANCE);
assertNotNull(credentials.getUserProfile());
}
Aggregations