static byte[] hmacSHA256(String data, byte[] key) { try { String algorithm = "HmacSHA256"; Mac mac = Mac.getInstance(algorithm); mac.init(new SecretKeySpec(key, algorithm)); return mac.doFinal(data.getBytes(UTF_8)); } catch (GeneralSecurityException e) { throw new HttpException(e); } }
@VisibleForTesting void parseLastModifiedOrThrowException(HttpResponse from, MutableContainerPropertiesWithMetadata metadata) throws HttpException { String lastModified = from.getFirstHeaderOrNull(HttpHeaders.LAST_MODIFIED); if (lastModified == null) throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: " + from); metadata.setLastModified(dateParser.rfc822DateParse(lastModified)); if (metadata.getLastModified() == null) throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": " + lastModified); }
@VisibleForTesting String hashPath(String path) { try { return base64().encode(ByteSource.wrap(canonicalPath(path).getBytes(UTF_8)).hash(sha1()).asBytes()); } catch (Exception e) { Throwables.propagateIfPossible(e); throw new HttpException("error creating sigature for path: " + path, e); } }
public String signString(String toSign) { try { ByteProcessor<byte[]> hmacSHA256 = asByteProcessor(crypto.hmacSHA256(base64().decode(creds.get().credential))); return base64().encode(readBytes(toInputStream(toSign), hmacSHA256)); } catch (Exception e) { throw new HttpException("error signing request", e); } }
@VisibleForTesting void parseLastModifiedOrThrowException(HttpResponse from, MutableContainerPropertiesWithMetadata metadata) throws HttpException { String lastModified = from.getFirstHeaderOrNull(HttpHeaders.LAST_MODIFIED); if (lastModified == null) throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: " + from); metadata.setLastModified(dateParser.rfc822DateParse(lastModified)); if (metadata.getLastModified() == null) throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": " + lastModified); }
@VisibleForTesting void parseLastModifiedOrThrowException(HttpResponse from, MutableContainerPropertiesWithMetadata metadata) throws HttpException { String lastModified = from.getFirstHeaderOrNull(HttpHeaders.LAST_MODIFIED); if (lastModified == null) throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: " + from); metadata.setLastModified(dateParser.rfc822DateParse(lastModified)); if (metadata.getLastModified() == null) throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": " + lastModified); }
public String signString(String toSign) { try { ByteProcessor<byte[]> hmacSHA256 = asByteProcessor(crypto.hmacSHA256(base64().decode(creds.get().credential))); return base64().encode(readBytes(toInputStream(toSign), hmacSHA256)); } catch (Exception e) { throw new HttpException("error signing request", e); } }
@VisibleForTesting void parseLastModifiedOrThrowException(HttpResponse from, MutableContainerPropertiesWithMetadata metadata) throws HttpException { String lastModified = from.getFirstHeaderOrNull(HttpHeaders.LAST_MODIFIED); if (lastModified == null) throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: " + from); metadata.setLastModified(dateParser.rfc822DateParse(lastModified)); if (metadata.getLastModified() == null) throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": " + lastModified); }
@VisibleForTesting void parseLastModifiedOrThrowException(HttpResponse from, MutableContainerPropertiesWithMetadata metadata) throws HttpException { String lastModified = from.getFirstHeaderOrNull(HttpHeaders.LAST_MODIFIED); if (lastModified == null) throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: " + from); metadata.setLastModified(dateParser.rfc822DateParse(lastModified)); if (metadata.getLastModified() == null) throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": " + lastModified); }
public String signString(String toSign) { try { ByteProcessor<byte[]> hmacSHA1 = asByteProcessor(crypto.hmacSHA1(base64().decode(creds.get().credential))); return base64().encode(readBytes(toInputStream(toSign), hmacSHA1)); } catch (Exception e) { throw new HttpException("error signing request", e); } }
public String signString(String toSign) { try { ByteProcessor<byte[]> hmacSHA1 = asByteProcessor(crypto.hmacSHA1(base64().decode(creds.get().credential))); return base64().encode(readBytes(toInputStream(toSign), hmacSHA1)); } catch (Exception e) { throw new HttpException("error signing request", e); } }
public String sign(String toSign) { try { ByteProcessor<byte[]> hmacSHA1 = asByteProcessor(crypto.hmacSHA1(creds.get().credential.getBytes(UTF_8))); return base64().encode(readBytes(toInputStream(toSign), hmacSHA1)); } catch (Exception e) { throw new HttpException("error signing request", e); } }
public String sign(String toSign) { try { ByteProcessor<byte[]> hmacSHA1 = asByteProcessor( crypto.hmacSHA1(creds.get().credential.getBytes(UTF_8))); return base64().encode(readBytes(toInputStream(toSign), hmacSHA1)); } catch (Exception e) { throw new HttpException("error signing request", e); } }
public String sign(String toSign) { try { byte[] encrypted = ByteStreams2.toByteArrayAndClose(new RSAEncryptingPayload(crypto, Payloads.newStringPayload(toSign), supplyKey.get()).openStream()); return base64().encode(encrypted); } catch (IOException e) { throw new HttpException("error signing request", e); } }
public String apply(HttpResponse from) { releasePayload(from); String eTag = from.getFirstHeaderOrNull(ETAG); if (eTag == null) { // TODO: Cloud Files sends incorrectly cased ETag header... Remove this when fixed. eTag = from.getFirstHeaderOrNull("Etag"); } if (eTag != null) { return eTag; } throw new HttpException("did not receive ETag"); }
public String apply(HttpResponse from) { releasePayload(from); String eTag = from.getFirstHeaderOrNull(ETAG); if (eTag == null) { // TODO: Cloud Files sends incorrectly cased ETag header... Remove this when fixed. eTag = from.getFirstHeaderOrNull("Etag"); } if (eTag != null) { return eTag; } throw new HttpException("did not receive ETag"); }
public String sign(String toSign) { String signature; try { signature = CryptoStreams.base64(CryptoStreams.mac(InputSuppliers.of(toSign), crypto.hmacSHA1(secretKey .getBytes()))); } catch (Exception e) { throw new HttpException("error signing request", e); } return signature; }
public String apply(HttpResponse from) { releasePayload(from); String eTag = from.getFirstHeaderOrNull(ETAG); if (eTag == null) { // TODO: Cloud Files sends incorrectly cased ETag header... Remove this when fixed. eTag = from.getFirstHeaderOrNull("Etag"); } if (eTag != null) { return eTag; } throw new HttpException("did not receive ETag"); }
public String apply(HttpResponse from) { releasePayload(from); String eTag = from.getFirstHeaderOrNull(ETAG); if (eTag == null) { // TODO: Cloud Files sends incorrectly cased ETag header... Remove this when fixed. eTag = from.getFirstHeaderOrNull("Etag"); } if (eTag != null) { return eTag; } throw new HttpException("did not receive ETag"); }
@VisibleForTesting public String sign(String stringToSign) { String signature; try { signature = base64(mac(InputSuppliers.of(stringToSign), crypto.hmacSHA256(creds.get().credential.getBytes()))); if (signatureWire.enabled()) signatureWire.input(toInputStream(signature)); } catch (Exception e) { throw new HttpException("error signing request", e); } return signature; }