use of java.security.NoSuchProviderException in project oxAuth by GluuFederation.
the class SupportRequestFile method requestFileMethod.
@Parameters({ "userId", "userSecret", "redirectUri", "redirectUris", "sectorIdentifierUri", "requestFileBasePath", "requestFileBaseUrl" })
// This tests requires a place to publish a request object via HTTPS
@Test
public void requestFileMethod(final String userId, final String userSecret, final String redirectUri, final String redirectUris, final String sectorIdentifierUri, final String requestFileBasePath, final String requestFileBaseUrl) throws Exception {
showTitle("OC5:FeatureTest-Support Request File");
List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN);
// 1. Register client
RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris));
registerRequest.setResponseTypes(responseTypes);
registerRequest.setSectorIdentifierUri(sectorIdentifierUri);
RegisterClient registerClient = new RegisterClient(registrationEndpoint);
registerClient.setRequest(registerRequest);
RegisterResponse registerResponse = registerClient.exec();
showClient(registerClient);
assertEquals(registerResponse.getStatus(), 200, "Unexpected response code: " + registerResponse.getEntity());
assertNotNull(registerResponse.getClientId());
assertNotNull(registerResponse.getClientSecret());
assertNotNull(registerResponse.getRegistrationAccessToken());
assertNotNull(registerResponse.getClientIdIssuedAt());
assertNotNull(registerResponse.getClientSecretExpiresAt());
String clientId = registerResponse.getClientId();
String clientSecret = registerResponse.getClientSecret();
// 2. Writing a request object in a file
List<String> scopes = Arrays.asList("openid", "profile", "address", "email");
String nonce = UUID.randomUUID().toString();
String state = UUID.randomUUID().toString();
AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes, redirectUri, nonce);
authorizationRequest.setState(state);
try {
OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider();
JwtAuthorizationRequest jwtAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest, SignatureAlgorithm.HS256, clientSecret, cryptoProvider);
jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.NAME, ClaimValue.createNull()));
jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.NICKNAME, ClaimValue.createEssential(false)));
jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.EMAIL, ClaimValue.createNull()));
jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.EMAIL_VERIFIED, ClaimValue.createNull()));
jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.PICTURE, ClaimValue.createEssential(false)));
jwtAuthorizationRequest.addIdTokenClaim(new Claim(JwtClaimName.AUTHENTICATION_TIME, ClaimValue.createNull()));
jwtAuthorizationRequest.addIdTokenClaim(new Claim(JwtClaimName.AUTHENTICATION_CONTEXT_CLASS_REFERENCE, ClaimValue.createValueList(new String[] { "2" })));
jwtAuthorizationRequest.getIdTokenMember().setMaxAge(86400);
String authJwt = jwtAuthorizationRequest.getEncodedJwt();
String hash = Base64Util.base64urlencode(JwtUtil.getMessageDigestSHA256(authJwt));
String fileName = UUID.randomUUID().toString() + ".txt";
String filePath = requestFileBasePath + File.separator + fileName;
String fileUrl = requestFileBaseUrl + "/" + fileName + "#" + hash;
FileWriter fw = new FileWriter(filePath);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(authJwt);
bw.close();
fw.close();
authorizationRequest.setRequestUri(fileUrl);
System.out.println("Request JWT: " + authJwt);
System.out.println("Request File Path: " + filePath);
System.out.println("Request File URL: " + fileUrl);
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (NoSuchProviderException e) {
e.printStackTrace();
fail(e.getMessage());
}
// 3. Request authorization
AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint);
authorizeClient.setRequest(authorizationRequest);
AuthorizationResponse authorizationResponse = authenticateResourceOwnerAndGrantAccess(authorizationEndpoint, authorizationRequest, userId, userSecret);
assertNotNull(authorizationResponse.getLocation());
assertNotNull(authorizationResponse.getAccessToken());
assertNotNull(authorizationResponse.getState());
}
use of java.security.NoSuchProviderException in project POL-POM-5 by PlayOnLinux.
the class SignatureChecker method check.
public Boolean check() {
final PGPPublicKey pgpSigningKey = readPublicKey(new ByteArrayInputStream(publicKey.getBytes()));
final ArmoredInputStream armoredInputStream;
try {
armoredInputStream = new ArmoredInputStream(new ByteArrayInputStream(signature.getBytes()));
} catch (IOException e) {
throw new SignatureException("Failed to verify signature", e);
}
final PGPObjectFactory pgpObjectFactory = new PGPObjectFactory(armoredInputStream);
try {
final Object nextObject = pgpObjectFactory.nextObject();
PGPSignature pgpSignature = null;
if (nextObject instanceof PGPSignatureList) {
PGPSignatureList list = (PGPSignatureList) nextObject;
if (!list.isEmpty()) {
pgpSignature = list.get(0);
}
}
if (pgpSignature == null) {
return false;
}
initVerify(pgpSignature, pgpSigningKey);
pgpSignature.update(signedData.getBytes());
return pgpSignature.verify();
} catch (IOException | PGPException | NoSuchProviderException | java.security.SignatureException e) {
throw new SignatureException("Failed to verify signature", e);
}
}
use of java.security.NoSuchProviderException in project oxAuth by GluuFederation.
the class OpenIDRequestObjectHttpTest method requestFileMethod.
@Parameters({ "userId", "userSecret", "redirectUris", "redirectUri", "requestFileBasePath", "requestFileBaseUrl", "sectorIdentifierUri" })
// This tests requires a place to publish a request object via HTTPS
@Test
public void requestFileMethod(final String userId, final String userSecret, final String redirectUris, final String redirectUri, @Optional final String requestFileBasePath, final String requestFileBaseUrl, final String sectorIdentifierUri) throws Exception {
showTitle("requestFileMethod");
if (StringHelper.isEmpty(requestFileBasePath)) {
return;
}
List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN);
// 1. Register client
RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris));
registerRequest.setResponseTypes(responseTypes);
registerRequest.setSectorIdentifierUri(sectorIdentifierUri);
RegisterClient registerClient = new RegisterClient(registrationEndpoint);
registerClient.setRequest(registerRequest);
RegisterResponse registerResponse = registerClient.exec();
showClient(registerClient);
assertEquals(registerResponse.getStatus(), 200, "Unexpected response code: " + registerResponse.getEntity());
assertNotNull(registerResponse.getClientId());
assertNotNull(registerResponse.getClientSecret());
assertNotNull(registerResponse.getRegistrationAccessToken());
assertNotNull(registerResponse.getClientIdIssuedAt());
assertNotNull(registerResponse.getClientSecretExpiresAt());
String clientId = registerResponse.getClientId();
String clientSecret = registerResponse.getClientSecret();
// 2. Request Authorization
OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider();
List<String> scopes = Arrays.asList("openid", "profile", "address", "email");
String nonce = UUID.randomUUID().toString();
String state = UUID.randomUUID().toString();
AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes, redirectUri, nonce);
authorizationRequest.setState(state);
try {
JwtAuthorizationRequest jwtAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest, SignatureAlgorithm.HS256, clientSecret, cryptoProvider);
jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.NAME, ClaimValue.createNull()));
jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.NICKNAME, ClaimValue.createEssential(false)));
jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.EMAIL, ClaimValue.createNull()));
jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.EMAIL_VERIFIED, ClaimValue.createNull()));
jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.PICTURE, ClaimValue.createEssential(false)));
jwtAuthorizationRequest.addIdTokenClaim(new Claim(JwtClaimName.AUTHENTICATION_TIME, ClaimValue.createNull()));
jwtAuthorizationRequest.addIdTokenClaim(new Claim(JwtClaimName.AUTHENTICATION_CONTEXT_CLASS_REFERENCE, ClaimValue.createValueList(new String[] { "2" })));
jwtAuthorizationRequest.getIdTokenMember().setMaxAge(86400);
String authJwt = jwtAuthorizationRequest.getEncodedJwt();
String hash = Base64Util.base64urlencode(JwtUtil.getMessageDigestSHA256(authJwt));
String fileName = UUID.randomUUID().toString() + ".txt";
String filePath = requestFileBasePath + File.separator + fileName;
// + "#" + hash;
String fileUrl = requestFileBaseUrl + "/" + fileName;
FileWriter fw = new FileWriter(filePath);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(authJwt);
bw.close();
fw.close();
authorizationRequest.setRequestUri(fileUrl);
System.out.println("Request JWT: " + authJwt);
System.out.println("Request File Path: " + filePath);
System.out.println("Request File URL: " + fileUrl);
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (NoSuchProviderException e) {
e.printStackTrace();
fail(e.getMessage());
}
AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint);
authorizeClient.setRequest(authorizationRequest);
AuthorizationResponse authorizationResponse = authenticateResourceOwnerAndGrantAccess(authorizationEndpoint, authorizationRequest, userId, userSecret);
assertNotNull(authorizationResponse.getLocation(), "The location is null");
assertNotNull(authorizationResponse.getAccessToken(), "The accessToken is null");
assertNotNull(authorizationResponse.getTokenType(), "The tokenType is null");
assertNotNull(authorizationResponse.getState(), "The state is null");
}
use of java.security.NoSuchProviderException in project jdk8u_jdk by JetBrains.
the class XMLSignatureFactory method getInstance.
/**
* Returns an <code>XMLSignatureFactory</code> that supports the
* requested XML processing mechanism and representation type (ex: "DOM"),
* as supplied by the specified provider. The specified provider must be
* registered in the security provider list.
*
* <p>Note that the list of registered providers may be retrieved via
* the {@link Security#getProviders() Security.getProviders()} method.
*
* @param mechanismType the type of the XML processing mechanism and
* representation. See the <a
* href="../../../../../technotes/guides/security/xmldsig/overview.html#Service Provider">
* Service Providers</a> section of the API overview for a list of
* standard mechanism types.
* @param provider the string name of the provider
* @return a new <code>XMLSignatureFactory</code>
* @throws NoSuchProviderException if the specified provider is not
* registered in the security provider list
* @throws NullPointerException if <code>provider</code> or
* <code>mechanismType</code> is <code>null</code>
* @throws NoSuchMechanismException if an <code>XMLSignatureFactory</code>
* implementation for the specified mechanism is not
* available from the specified provider
* @see Provider
*/
public static XMLSignatureFactory getInstance(String mechanismType, String provider) throws NoSuchProviderException {
if (mechanismType == null) {
throw new NullPointerException("mechanismType cannot be null");
} else if (provider == null) {
throw new NullPointerException("provider cannot be null");
} else if (provider.length() == 0) {
throw new NoSuchProviderException();
}
Instance instance;
try {
instance = GetInstance.getInstance("XMLSignatureFactory", null, mechanismType, provider);
} catch (NoSuchAlgorithmException nsae) {
throw new NoSuchMechanismException(nsae);
}
XMLSignatureFactory factory = (XMLSignatureFactory) instance.impl;
factory.mechanismType = mechanismType;
factory.provider = instance.provider;
return factory;
}
use of java.security.NoSuchProviderException in project jdk8u_jdk by JetBrains.
the class CICO method runTest.
public void runTest(String algo, String mo, String pad, int whichRead) throws Exception {
Cipher ci1 = null;
Cipher ci2 = null;
byte[] iv = null;
AlgorithmParameterSpec aps = null;
SecretKey key = null;
try {
// Do initialization
Random rdm = new Random();
rdm.nextBytes(plainText);
KeyGenerator kg = KeyGenerator.getInstance(algo, PROVIDER);
if (!kg.getAlgorithm().equals(algo)) {
throw new RuntimeException("Unexpected algorithm <" + kg.getAlgorithm() + ">, expected value is <" + algo + ">");
}
kg.init(KEY_LENGTH);
key = kg.generateKey();
ci1 = Cipher.getInstance(algo + "/" + mo + "/" + pad, PROVIDER);
if (mo.equalsIgnoreCase("ECB")) {
ci1.init(Cipher.ENCRYPT_MODE, key);
} else {
ci1.init(Cipher.ENCRYPT_MODE, key, aps);
}
if (!mo.equalsIgnoreCase("ECB")) {
iv = ci1.getIV();
aps = new IvParameterSpec(iv);
} else {
aps = null;
}
ci2 = Cipher.getInstance(algo + "/" + mo + "/" + pad, PROVIDER);
if (mo.equalsIgnoreCase("ECB")) {
ci2.init(Cipher.DECRYPT_MODE, key);
} else {
ci2.init(Cipher.DECRYPT_MODE, key, aps);
}
ByteArrayInputStream baInput = new ByteArrayInputStream(plainText);
ByteArrayOutputStream baOutput = new ByteArrayOutputStream();
try (CipherInputStream ciInput = new CipherInputStream(baInput, ci1);
CipherOutputStream ciOutput = new CipherOutputStream(baOutput, ci2)) {
// mark and reset methods
if (ciInput.markSupported()) {
throw new RuntimeException("CipherInputStream unexpectedly supports the mark and reset methods");
}
// of buffering : byte[] and int
switch(whichRead) {
case 0:
int buffer0 = ciInput.read();
while (buffer0 != -1) {
ciOutput.write(buffer0);
buffer0 = ciInput.read();
}
break;
case 1:
byte[] buffer1 = new byte[20];
int len1 = ciInput.read(buffer1);
while (len1 != -1) {
ciOutput.write(buffer1, 0, len1);
len1 = ciInput.read(buffer1);
}
break;
case NREADS - 1:
byte[] buffer2 = new byte[ci1.getOutputSize(plainText.length)];
int offset2 = 0;
int len2 = 0;
while (len2 != -1) {
len2 = ciInput.read(buffer2, offset2, buffer2.length - offset2);
offset2 += len2;
}
ciOutput.write(buffer2, 0, buffer2.length);
break;
}
}
// Get the output
byte[] recoveredText = new byte[baOutput.size()];
recoveredText = baOutput.toByteArray();
if (!java.util.Arrays.equals(plainText, recoveredText)) {
throw new RuntimeException("Original text is not equal with recovered text, with " + algo + "/" + mo + "/" + pad + "/" + whichRead);
}
// Compare input and output
} catch (NoSuchAlgorithmException e) {
//OFB20 is for negative testing
if (!mo.equalsIgnoreCase("OFB20")) {
System.out.println("Unexpected NoSuchAlgorithmException with " + algo + "/" + mo + "/" + pad + "/" + whichRead);
throw new RuntimeException("Test failed!");
}
} catch (IOException | NoSuchProviderException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException e) {
System.out.println("Unexpected Exception with " + algo + "/" + mo + "/" + pad + "/" + whichRead);
System.out.println("Test failed!");
throw e;
}
}
Aggregations