private void writeQuote(OutputStream os, Class<?> type) throws IOException { if (type == String.class) { os.write(StringUtils.toBytesASCII("\"")); } } public void setSupportSimpleTypesOnly(boolean supportSimpleTypesOnly) {
private void writeQuote(OutputStream os, Class<?> type) throws IOException { if (type == String.class) { os.write(StringUtils.toBytesASCII("\"")); } } public void setSupportSimpleTypesOnly(boolean supportSimpleTypesOnly) {
public static byte[] toCipherAdditionalAuthData(String headersJson) { byte[] headerBytes = StringUtils.toBytesUTF8(headersJson); String base64UrlHeadersInJson = Base64UrlUtility.encode(headerBytes); return StringUtils.toBytesASCII(base64UrlHeadersInJson); }
public static byte[] toCipherAdditionalAuthData(String headersJson) { byte[] headerBytes = StringUtils.toBytesUTF8(headersJson); String base64UrlHeadersInJson = Base64UrlUtility.encode(headerBytes); return StringUtils.toBytesASCII(base64UrlHeadersInJson); }
@Override public void writeTo(JwsDetachedSignature parts, Class<?> cls, Type t, Annotation[] anns, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException { JoseUtils.traceHeaders(parts.getHeaders()); byte[] finalBytes = parts.getSignature().sign(); if (!parts.isUseJwsJsonSignatureFormat()) { os.write(StringUtils.toBytesASCII(parts.getEncodedHeaders())); byte[] dotBytes = new byte[]{'.'}; os.write(dotBytes); os.write(dotBytes); Base64UrlUtility.encodeAndStream(finalBytes, 0, finalBytes.length, os); } else { // use flattened JWS JSON format os.write(StringUtils.toBytesASCII("{")); String headersProp = "\"protected\":\"" + parts.getEncodedHeaders() + "\""; os.write(StringUtils.toBytesUTF8(headersProp)); os.write(StringUtils.toBytesASCII(",")); String sigProp = "\"signature\":\"" + Base64UrlUtility.encode(finalBytes) + "\""; os.write(StringUtils.toBytesUTF8(sigProp)); os.write(StringUtils.toBytesASCII("}")); } }
throw new JweException(JweException.Error.KEY_ENCRYPTION_FAILURE); byte[] algorithmId = concatenateDatalenAndData(StringUtils.toBytesASCII(algoName)); byte[] partyUInfo = apuBytes == null ? emptyPartyInfo : concatenateDatalenAndData(apuBytes); byte[] partyVInfo = apvBytes == null ? emptyPartyInfo : concatenateDatalenAndData(apvBytes);
throw new JweException(JweException.Error.KEY_ENCRYPTION_FAILURE); byte[] algorithmId = concatenateDatalenAndData(StringUtils.toBytesASCII(algoName)); byte[] partyUInfo = apuBytes == null ? emptyPartyInfo : concatenateDatalenAndData(apuBytes); byte[] partyVInfo = apvBytes == null ? emptyPartyInfo : concatenateDatalenAndData(apvBytes);
private static String calculateHash(String value, SignatureAlgorithm sigAlgo) { if (sigAlgo == SignatureAlgorithm.NONE) { throw new JwsException(JwsException.Error.INVALID_ALGORITHM); } String algoShaSizeString = sigAlgo.getJwaName().substring(2); String javaShaAlgo = "SHA-" + algoShaSizeString; int algoShaSize = Integer.parseInt(algoShaSizeString); int valueHashSize = (algoShaSize / 8) / 2; try { byte[] atBytes = StringUtils.toBytesASCII(value); byte[] digest = MessageDigestUtils.createDigest(atBytes, javaShaAlgo); return Base64UrlUtility.encodeChunk(digest, 0, valueHashSize); } catch (NoSuchAlgorithmException ex) { throw new OAuthServiceException(ex); } } public static void setStateClaimsProperty(OAuthRedirectionState state,
private static String calculateHash(String value, SignatureAlgorithm sigAlgo) { if (sigAlgo == SignatureAlgorithm.NONE) { throw new JwsException(JwsException.Error.INVALID_ALGORITHM); } String algoShaSizeString = sigAlgo.getJwaName().substring(2); String javaShaAlgo = "SHA-" + algoShaSizeString; int algoShaSize = Integer.parseInt(algoShaSizeString); int valueHashSize = (algoShaSize / 8) / 2; try { byte[] atBytes = StringUtils.toBytesASCII(value); byte[] digest = MessageDigestUtils.createDigest(atBytes, javaShaAlgo); return Base64UrlUtility.encodeChunk(digest, 0, valueHashSize); } catch (NoSuchAlgorithmException ex) { throw new OAuthServiceException(ex); } } public static void setStateClaimsProperty(OAuthRedirectionState state,
@Override public void writeTo(T t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException { if (!supportSimpleTypesOnly && !InjectionUtils.isPrimitive(type)) { @SuppressWarnings("unchecked") MessageBodyWriter<T> next = (MessageBodyWriter<T>)providers.getMessageBodyWriter(type, genericType, annotations, mediaType); JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, this); try { next.writeTo(t, type, genericType, annotations, mediaType, headers, os); } finally { JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, null); } } else { os.write(StringUtils.toBytesASCII("{\"" + type.getSimpleName().toLowerCase() + "\":")); writeQuote(os, type); primitiveHelper.writeTo(t, type, genericType, annotations, mediaType, headers, os); writeQuote(os, type); os.write(StringUtils.toBytesASCII("}")); } }
@Override public void writeTo(T t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException { if (!supportSimpleTypesOnly && !InjectionUtils.isPrimitive(type)) { @SuppressWarnings("unchecked") MessageBodyWriter<T> next = (MessageBodyWriter<T>)providers.getMessageBodyWriter(type, genericType, annotations, mediaType); JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, this); try { next.writeTo(t, type, genericType, annotations, mediaType, headers, os); } finally { JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, null); } } else { os.write(StringUtils.toBytesASCII("{\"" + type.getSimpleName().toLowerCase() + "\":")); writeQuote(os, type); primitiveHelper.writeTo(t, type, genericType, annotations, mediaType, headers, os); writeQuote(os, type); os.write(StringUtils.toBytesASCII("}")); } }
byte[] headerBytesWithDot = StringUtils.toBytesASCII(base64UrlEncodedHeaders + "."); jwsSignature.update(headerBytesWithDot, 0, headerBytesWithDot.length); AttachmentUtils.addMultipartOutFilter(new JwsMultipartSignatureOutFilter(jwsSignature));
byte[] headerBytesWithDot = StringUtils.toBytesASCII(base64UrlEncodedHeaders + "."); sig.update(headerBytesWithDot, 0, headerBytesWithDot.length);