public String base64Decode(String encoded) throws IllegalArgumentException, UnsupportedEncodingException { byte[] decoded = Base64Util.base64urldecode(encoded); return new String(decoded, "UTF-8"); }
@JsonIgnore public X509Certificate getAttestationCertificate() throws CertificateException, NoSuchFieldException { if (attestationCert == null) { throw new NoSuchFieldException(); } return CertificateParser.parseDer(Base64Util.base64urldecode(attestationCert)); }
private boolean restoreLogoutParametersFromSession(SessionId sessionId) throws IllegalArgumentException, JsonParseException, JsonMappingException, IOException { if (sessionId == null) { return false; } this.sessionId = sessionId; Map<String, String> sessionAttributes = sessionId.getSessionAttributes(); boolean restoreParameters = sessionAttributes.containsKey(EXTERNAL_LOGOUT); if (!restoreParameters) { return false; } String logoutParametersBase64 = sessionAttributes.get(EXTERNAL_LOGOUT_DATA); String logoutParametersJson = new String(Base64Util.base64urldecode(logoutParametersBase64), Util.UTF8_STRING_ENCODING); LogoutParameters logoutParameters = jsonService.jsonToObject(logoutParametersJson, LogoutParameters.class); this.idTokenHint = logoutParameters.getIdTokenHint(); this.postLogoutRedirectUri = logoutParameters.getPostLogoutRedirectUri(); return true; }
@Test(dataProvider = "webKeysDataProvider") public void webKeyTest(final String n, final String e, final String x5c) throws CertificateException { showTitle("webKeyTest"); byte[] nBytes = Base64Util.base64urldecode(n); BigInteger modulus = new BigInteger(1, nBytes); byte[] eBytes = Base64Util.base64urldecode(e); BigInteger exponent = new BigInteger(1, eBytes); System.out.println("n: " + n); System.out.println("n: " + modulus); System.out.println("e: " + e); System.out.println("e: " + exponent); byte[] certBytes = Base64Util.base64urldecode(x5c); X509Certificate cert = new X509CertImpl(certBytes); PublicKey publicKey = cert.getPublicKey(); RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey; assertEquals(rsaPublicKey.getModulus(), modulus); assertEquals(rsaPublicKey.getPublicExponent(), exponent); }
public RawAuthenticateResponse parseRawAuthenticateResponse(String rawDataBase64) { ByteDataInputStream bis = new ByteDataInputStream(Base64Util.base64urldecode(rawDataBase64)); try { return new RawAuthenticateResponse(bis.readSigned(), bis.readInt(), bis.readAll()); } catch (IOException ex) { throw new BadInputException("Failed to parse RAW authenticate response", ex); } finally { IOUtils.closeQuietly(bis); } }
} else { String keyHandleWithoutPading = Base64Util.base64urlencode(Base64Util.base64urldecode(keyHandle));
public List<DeviceRegistration> findDeviceRegistrationsByKeyHandle(String appId, String keyHandle, String ... returnAttributes) { if (org.xdi.util.StringHelper.isEmpty(appId) || StringHelper.isEmpty(keyHandle)) { return new ArrayList<DeviceRegistration>(0); } byte[] keyHandleDecoded = Base64Util.base64urldecode(keyHandle); String baseDn = userService.getDnForUser(null); Filter deviceObjectClassFilter = Filter.createEqualityFilter("objectClass", "oxDeviceRegistration"); Filter deviceHashCodeFilter = Filter.createEqualityFilter("oxDeviceHashCode", String.valueOf(getKeyHandleHashCode(keyHandleDecoded))); Filter deviceKeyHandleFilter = Filter.createEqualityFilter("oxDeviceKeyHandle", keyHandle); Filter appIdFilter = Filter.createEqualityFilter("oxApplication", appId); Filter filter = Filter.createANDFilter(deviceObjectClassFilter, deviceHashCodeFilter, appIdFilter, deviceKeyHandleFilter); return ldapEntryManager.findEntries(baseDn, DeviceRegistration.class, filter, returnAttributes); }
@Test public void setClaimTestJsonObj() { try { String stringJson = StringUtil.fromBytes(Base64Util.base64urldecode("eyJzYWx0IjoibWFjbmgiLCJwcm92aWRlciI6ImlkcDEifQ==")); JSONObject jobj = new JSONObject(stringJson); JwtClaims claims = new JwtClaims(); claims.setClaim("test_claim", jobj); assertEquals(jobj, claims.toJsonObject().get("test_claim")); } catch (Exception ex) { fail(ex.getMessage()); } }
public RawRegisterResponse parseRawRegisterResponse(String rawDataBase64) throws BadInputException { ByteDataInputStream bis = new ByteDataInputStream(Base64Util.base64urldecode(rawDataBase64)); try { try { byte reservedByte = bis.readSigned(); if (reservedByte != REGISTRATION_RESERVED_BYTE_VALUE) { throw new BadInputException("Incorrect value of reserved byte. Expected: " + REGISTRATION_RESERVED_BYTE_VALUE + ". Was: " + reservedByte); } return new RawRegisterResponse(bis.read(65), bis.read(bis.readUnsigned()), CertificateParser.parseDer(bis), bis.readAll()); } catch (IOException ex) { throw new BadInputException("Failed to parse RAW register response", ex); } catch (CertificateException e) { throw new BadInputException("Malformed attestation certificate", e); } } finally { IOUtils.closeQuietly(bis); } }
public boolean testDecryptWithJose4J(String jwe) { try { PublicJsonWebKey jwk = PublicJsonWebKey.Factory.newPublicJwk(recipientJwkJson); JsonWebEncryption receiverJwe = new JsonWebEncryption(); AlgorithmConstraints algConstraints = new AlgorithmConstraints(ConstraintType.WHITELIST, KeyManagementAlgorithmIdentifiers.RSA_OAEP); receiverJwe.setAlgorithmConstraints(algConstraints); AlgorithmConstraints encConstraints = new AlgorithmConstraints(ConstraintType.WHITELIST, ContentEncryptionAlgorithmIdentifiers.AES_128_GCM); receiverJwe.setContentEncryptionAlgorithmConstraints(encConstraints); receiverJwe.setKey(jwk.getPrivateKey()); receiverJwe.setCompactSerialization(jwe); final String decryptedPayload = new String(Base64Util.base64urldecode(receiverJwe.getPlaintextString())); System.out.println("Jose4j decrypt succeed: " + decryptedPayload); if (decryptedPayload.equals(PAYLOAD)) { return true; } } catch (Exception e) { System.out.println("Jose4j decrypt failed: " + e.getMessage()); e.printStackTrace(); } return false; }
private boolean testDecryptNimbusJoseJwt(String jwe) { try { EncryptedJWT encryptedJwt = EncryptedJWT.parse(jwe); //EncryptedJWT encryptedJwt = EncryptedJWT.parse(encryptWithGluu()); //EncryptedJWT encryptedJwt = EncryptedJWT.parse(encryptWithNimbus()); JWK jwk = JWK.parse(recipientJwkJson); RSAPrivateKey rsaPrivateKey = ((RSAKey) jwk).toRSAPrivateKey(); JWEDecrypter decrypter = new RSADecrypter(rsaPrivateKey); decrypter.getJCAContext().setProvider(BouncyCastleProviderSingleton.getInstance()); encryptedJwt.decrypt(decrypter); final String decryptedPayload = new String(Base64Util.base64urldecode(encryptedJwt.getPayload().toString())); System.out.println("Nimbusds decrypt succeed: " + decryptedPayload); if (decryptedPayload.equals(PAYLOAD)) { return true; } } catch (Exception e) { System.out.println("Nimbusds decrypt failed: " + e.getMessage()); e.printStackTrace(); } return false; }
if (StringHelper.isNotEmpty(responseDeviceData)) { try { String responseDeviceDataDecoded = new String(Base64Util.base64urldecode(responseDeviceData)); DeviceData deviceData = ServerUtil.jsonMapperWithWrapRoot().readValue(responseDeviceDataDecoded, DeviceData.class); deviceRegistration.setDeviceData(deviceData);
String header = new String(Base64Util.base64urldecode(encodedHeader), Util.UTF8_STRING_ENCODING); String payload = new String(Base64Util.base64urldecode(encodedClaim), Util.UTF8_STRING_ENCODING); payload = payload.replace("\\", "");
Base64Util.base64urldecode(usedDeviceRegistration.getDeviceRegistrationConfiguration().getPublicKey())); rawAuthenticateResponse.checkUserPresence(); usedDeviceRegistration.checkAndUpdateCounter(rawAuthenticateResponse.getCounter());