@Test public void canSignUri() throws IOException { final String login = "user"; final Signer signer = new Signer(this.useNativeCodeToSign); RequestHttpSigner requestSigner = new RequestHttpSigner(testKeyPair, login, testKeyFingerprint, useNativeCodeToSign); URI uri = URI.create("http: URI signedUri = requestSigner.signURI(uri, "GET", 0L); String expected = "http: Assert.assertEquals(signedUri.toString(), expected); }
@Deprecated public URI signURI(final URI uri, final String method, final long expires) throws IOException { Objects.requireNonNull(method, "Method must be present"); Objects.requireNonNull(uri, "URI must be present"); if (uri.getQuery() != null && !uri.getQuery().isEmpty()) { throw new IllegalArgumentException("Query must be empty"); } final String charset = "UTF-8"; final String algorithm = signer.get().getHttpHeaderAlgorithm().toUpperCase(); final String keyId = String.format("/%s/keys/%s", getLogin(), KeyFingerprinter.md5Fingerprint(getKeyPair())); final String keyIdEncoded = URLEncoder.encode(keyId, charset); StringBuilder sigText = new StringBuilder(); sigText.append(method).append("\n") .append(uri.getHost()).append("\n") .append(uri.getPath()).append("\n") .append("algorithm=").append(algorithm).append("&") .append("expires=").append(expires).append("&") .append("keyId=").append(keyIdEncoded); StringBuilder request = new StringBuilder(); final byte[] sigBytes = sigText.toString().getBytes(StandardCharsets.US_ASCII); final byte[] signed = signer.get().sign(getLogin(), getKeyPair(), sigBytes); final String encoded = new String(Base64.encode(signed), charset); final String urlEncoded = URLEncoder.encode(encoded, charset); request.append(uri).append("?") .append("algorithm=").append(algorithm).append("&") .append("expires=").append(expires).append("&") .append("keyId=").append(keyIdEncoded).append("&") .append("signature=").append(urlEncoded); return URI.create(request.toString()); }
RequestHttpSigner { @Deprecated public URI signURI(final URI uri, final String method, final long expires) throws IOException { Objects.requireNonNull(method, "Method must be present"); Objects.requireNonNull(uri, "URI must be present"); if (uri.getQuery() != null && !uri.getQuery().isEmpty()) { throw new IllegalArgumentException("Query must be empty"); } final String charset = "UTF-8"; final String algorithm = signer.get().getHttpHeaderAlgorithm().toUpperCase(); final String keyId = String.format("/%s/keys/%s", getLogin(), KeyFingerprinter.md5Fingerprint(getKeyPair())); final String keyIdEncoded = URLEncoder.encode(keyId, charset); StringBuilder sigText = new StringBuilder(); sigText.append(method).append("\n") .append(uri.getHost()).append("\n") .append(uri.getPath()).append("\n") .append("algorithm=").append(algorithm).append("&") .append("expires=").append(expires).append("&") .append("keyId=").append(keyIdEncoded); StringBuilder request = new StringBuilder(); final byte[] sigBytes = sigText.toString().getBytes(StandardCharsets.US_ASCII); final byte[] signed = signer.get().sign(getLogin(), getKeyPair(), sigBytes); final String encoded = new String(Base64.encode(signed), charset); final String urlEncoded = URLEncoder.encode(encoded, charset); request.append(uri).append("?") .append("algorithm=").append(algorithm).append("&") .append("expires=").append(expires).append("&") .append("keyId=").append(keyIdEncoded).append("&") .append("signature=").append(urlEncoded); return URI.create(request.toString()); } }
RequestHttpSigner { @Deprecated public URI signURI(final URI uri, final String method, final long expires) throws IOException { Objects.requireNonNull(method, "Method must be present"); Objects.requireNonNull(uri, "URI must be present"); if (uri.getQuery() != null && !uri.getQuery().isEmpty()) { throw new IllegalArgumentException("Query must be empty"); } final String charset = "UTF-8"; final String algorithm = signer.get().getHttpHeaderAlgorithm().toUpperCase(); final String keyId = String.format("/%s/keys/%s", getLogin(), KeyFingerprinter.md5Fingerprint(getKeyPair())); final String keyIdEncoded = URLEncoder.encode(keyId, charset); StringBuilder sigText = new StringBuilder(); sigText.append(method).append("\n") .append(uri.getHost()).append("\n") .append(uri.getPath()).append("\n") .append("algorithm=").append(algorithm).append("&") .append("expires=").append(expires).append("&") .append("keyId=").append(keyIdEncoded); StringBuilder request = new StringBuilder(); final byte[] sigBytes = sigText.toString().getBytes(StandardCharsets.US_ASCII); final byte[] signed = signer.get().sign(getLogin(), getKeyPair(), sigBytes); final String encoded = new String(Base64.encode(signed), charset); final String urlEncoded = URLEncoder.encode(encoded, charset); request.append(uri).append("?") .append("algorithm=").append(algorithm).append("&") .append("expires=").append(expires).append("&") .append("keyId=").append(keyIdEncoded).append("&") .append("signature=").append(urlEncoded); return URI.create(request.toString()); } @Deprecated  RequestHttpSigner(final KeyPair keyPair, final String login, final String fingerprint,
                             final boolean useNativeCodeToSign); @Deprecated  RequestHttpSigner(final KeyPair keyPair, final String login, final String fingerprint,
                             final ThreadLocalSigner signer);  RequestHttpSigner(final KeyPair keyPair, final String login,
                             final ThreadLocalSigner signer); }
RequestHttpSigner { @Deprecated public URI signURI(final URI uri, final String method, final long expires) throws IOException { Objects.requireNonNull(method, "Method must be present"); Objects.requireNonNull(uri, "URI must be present"); if (uri.getQuery() != null && !uri.getQuery().isEmpty()) { throw new IllegalArgumentException("Query must be empty"); } final String charset = "UTF-8"; final String algorithm = signer.get().getHttpHeaderAlgorithm().toUpperCase(); final String keyId = String.format("/%s/keys/%s", getLogin(), KeyFingerprinter.md5Fingerprint(getKeyPair())); final String keyIdEncoded = URLEncoder.encode(keyId, charset); StringBuilder sigText = new StringBuilder(); sigText.append(method).append("\n") .append(uri.getHost()).append("\n") .append(uri.getPath()).append("\n") .append("algorithm=").append(algorithm).append("&") .append("expires=").append(expires).append("&") .append("keyId=").append(keyIdEncoded); StringBuilder request = new StringBuilder(); final byte[] sigBytes = sigText.toString().getBytes(StandardCharsets.US_ASCII); final byte[] signed = signer.get().sign(getLogin(), getKeyPair(), sigBytes); final String encoded = new String(Base64.encode(signed), charset); final String urlEncoded = URLEncoder.encode(encoded, charset); request.append(uri).append("?") .append("algorithm=").append(algorithm).append("&") .append("expires=").append(expires).append("&") .append("keyId=").append(keyIdEncoded).append("&") .append("signature=").append(urlEncoded); return URI.create(request.toString()); } @Deprecated  RequestHttpSigner(final KeyPair keyPair, final String login, final String fingerprint,
                             final boolean useNativeCodeToSign); @Deprecated  RequestHttpSigner(final KeyPair keyPair, final String login, final String fingerprint,
                             final ThreadLocalSigner signer);  RequestHttpSigner(final KeyPair keyPair, final String login,
                             final ThreadLocalSigner signer); void signRequest(final HttpRequest request); @Deprecated URI signURI(final URI uri, final String method, final long expires); boolean verifyRequest(final HttpRequest request); KeyPair getKeyPair(); String getLogin(); @Deprecated String getFingerprint(); ThreadLocalSigner getSignerThreadLocal(); }
RequestHttpSigner { @Deprecated public URI signURI(final URI uri, final String method, final long expires) throws IOException { Objects.requireNonNull(method, "Method must be present"); Objects.requireNonNull(uri, "URI must be present"); if (uri.getQuery() != null && !uri.getQuery().isEmpty()) { throw new IllegalArgumentException("Query must be empty"); } final String charset = "UTF-8"; final String algorithm = signer.get().getHttpHeaderAlgorithm().toUpperCase(); final String keyId = String.format("/%s/keys/%s", getLogin(), KeyFingerprinter.md5Fingerprint(getKeyPair())); final String keyIdEncoded = URLEncoder.encode(keyId, charset); StringBuilder sigText = new StringBuilder(); sigText.append(method).append("\n") .append(uri.getHost()).append("\n") .append(uri.getPath()).append("\n") .append("algorithm=").append(algorithm).append("&") .append("expires=").append(expires).append("&") .append("keyId=").append(keyIdEncoded); StringBuilder request = new StringBuilder(); final byte[] sigBytes = sigText.toString().getBytes(StandardCharsets.US_ASCII); final byte[] signed = signer.get().sign(getLogin(), getKeyPair(), sigBytes); final String encoded = new String(Base64.encode(signed), charset); final String urlEncoded = URLEncoder.encode(encoded, charset); request.append(uri).append("?") .append("algorithm=").append(algorithm).append("&") .append("expires=").append(expires).append("&") .append("keyId=").append(keyIdEncoded).append("&") .append("signature=").append(urlEncoded); return URI.create(request.toString()); } @Deprecated  RequestHttpSigner(final KeyPair keyPair, final String login, final String fingerprint,
                             final boolean useNativeCodeToSign); @Deprecated  RequestHttpSigner(final KeyPair keyPair, final String login, final String fingerprint,
                             final ThreadLocalSigner signer);  RequestHttpSigner(final KeyPair keyPair, final String login,
                             final ThreadLocalSigner signer); void signRequest(final HttpRequest request); @Deprecated URI signURI(final URI uri, final String method, final long expires); boolean verifyRequest(final HttpRequest request); KeyPair getKeyPair(); String getLogin(); @Deprecated String getFingerprint(); ThreadLocalSigner getSignerThreadLocal();  }