Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Convert strings to byte arrays before crossing over
  • Loading branch information
bretambrose committed May 14, 2020
commit f1cb2997a722b73556f6fd0469c40507f88730bd
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ private X509CredentialsProvider(X509CredentialsProviderBuilder builder) {
thingName.getBytes(UTF8),
roleAlias.getBytes(UTF8),
endpoint.getBytes(UTF8),
proxyHost,
proxyHost != null ? proxyHost.getBytes(UTF8) : null,
proxyPort,
proxyTlsContextHandle,
proxyAuthorizationType,
proxyAuthorizationUsername,
proxyAuthorizationPassword);
proxyAuthorizationUsername != null ? proxyAuthorizationUsername.getBytes(UTF8) : null,
proxyAuthorizationPassword != null ? proxyAuthorizationPassword.getBytes(UTF8) : null);

acquireNativeHandle(nativeHandle);
addReferenceTo(clientBootstrap);
Expand All @@ -191,10 +191,10 @@ private static native long x509CredentialsProviderNew(X509CredentialsProvider th
byte[] thingName,
byte[] roleAlias,
byte[] endpoint,
String proxyHost,
byte[] proxyHost,
int proxyPort,
long proxyTlsContext,
int proxyAuthorizationType,
String proxyAuthorizationUsername,
String proxyAuthorizationPassword);
byte[] proxyAuthorizationUsername,
byte[] proxyAuthorizationPassword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package software.amazon.awssdk.crt.http;

import java.net.URI;
import java.nio.charset.Charset;
import java.util.Queue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentLinkedQueue;
Expand All @@ -34,6 +35,7 @@ public class HttpClientConnectionManager extends CrtResource {
private static final String HTTPS = "https";
private static final int DEFAULT_HTTP_PORT = 80;
private static final int DEFAULT_HTTPS_PORT = 443;
private final static Charset UTF8 = java.nio.charset.StandardCharsets.UTF_8;

private final int windowSize;
private final URI uri;
Expand Down Expand Up @@ -112,15 +114,15 @@ private HttpClientConnectionManager(HttpClientConnectionManagerOptions options)
socketOptions.getNativeHandle(),
useTls ? tlsContext.getNativeHandle() : 0,
windowSize,
uri.getHost(),
uri.getHost().getBytes(UTF8),
port,
maxConnections,
proxyHost,
proxyHost != null ? proxyHost.getBytes(UTF8) : null,
proxyPort,
proxyTlsContext != null ? proxyTlsContext.getNativeHandle() : 0,
proxyAuthorizationType,
proxyAuthorizationUsername,
proxyAuthorizationPassword,
proxyAuthorizationUsername != null ? proxyAuthorizationUsername.getBytes(UTF8) : null,
proxyAuthorizationPassword != null ? proxyAuthorizationPassword.getBytes(UTF8) : null,
options.isManualWindowManagement()));

/* we don't need to add a reference to socketOptions since it's copied during connection manager construction */
Expand Down Expand Up @@ -250,15 +252,15 @@ private static native long httpClientConnectionManagerNew(HttpClientConnectionMa
long socketOptions,
long tlsContext,
int windowSize,
String endpoint,
byte[] endpoint,
int port,
int maxConns,
String proxyHost,
byte[] proxyHost,
int proxyPort,
long proxyTlsContext,
int proxyAuthorizationType,
String proxyAuthorizationUsername,
String proxyAuthorizationPassword,
byte[] proxyAuthorizationUsername,
byte[] proxyAuthorizationPassword,
boolean isManualWindowManagement) throws CrtRuntimeException;

private static native void httpClientConnectionManagerRelease(long conn_manager) throws CrtRuntimeException;
Expand Down
6 changes: 3 additions & 3 deletions src/native/credentials_provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ JNIEXPORT jlong JNICALL
jbyteArray thing_name,
jbyteArray role_alias,
jbyteArray endpoint,
jstring jni_proxy_host,
jbyteArray jni_proxy_host,
jint jni_proxy_port,
jlong jni_proxy_tls_context,
jint jni_proxy_authorization_type,
jstring jni_proxy_authorization_username,
jstring jni_proxy_authorization_password) {
jbyteArray jni_proxy_authorization_username,
jbyteArray jni_proxy_authorization_password) {

(void)jni_class;
(void)env;
Expand Down
36 changes: 18 additions & 18 deletions src/native/http_connection_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ void aws_http_proxy_options_jni_init(
JNIEnv *env,
struct aws_http_proxy_options *options,
struct aws_tls_connection_options *tls_options,
jstring proxy_host,
jbyteArray proxy_host,
uint16_t proxy_port,
jstring proxy_authorization_username,
jstring proxy_authorization_password,
jbyteArray proxy_authorization_username,
jbyteArray proxy_authorization_password,
int proxy_authorization_type,
struct aws_tls_ctx *proxy_tls_ctx) {

Expand All @@ -86,15 +86,15 @@ void aws_http_proxy_options_jni_init(
options->auth_type = proxy_authorization_type;

if (proxy_host != NULL) {
options->host = aws_jni_byte_cursor_from_jstring_acquire(env, proxy_host);
options->host = aws_jni_byte_cursor_from_jbyteArray_acquire(env, proxy_host);
}

if (proxy_authorization_username != NULL) {
options->auth_username = aws_jni_byte_cursor_from_jstring_acquire(env, proxy_authorization_username);
options->auth_username = aws_jni_byte_cursor_from_jbyteArray_acquire(env, proxy_authorization_username);
}

if (proxy_authorization_password != NULL) {
options->auth_password = aws_jni_byte_cursor_from_jstring_acquire(env, proxy_authorization_password);
options->auth_password = aws_jni_byte_cursor_from_jbyteArray_acquire(env, proxy_authorization_password);
}

if (proxy_tls_ctx != NULL) {
Expand All @@ -107,20 +107,20 @@ void aws_http_proxy_options_jni_init(
void aws_http_proxy_options_jni_clean_up(
JNIEnv *env,
struct aws_http_proxy_options *options,
jstring proxy_host,
jstring proxy_authorization_username,
jstring proxy_authorization_password) {
jbyteArray proxy_host,
jbyteArray proxy_authorization_username,
jbyteArray proxy_authorization_password) {

if (options->host.ptr != NULL) {
aws_jni_byte_cursor_from_jstring_release(env, proxy_host, options->host);
aws_jni_byte_cursor_from_jbyteArray_release(env, proxy_host, options->host);
}

if (options->auth_username.ptr != NULL) {
aws_jni_byte_cursor_from_jstring_release(env, proxy_authorization_username, options->auth_username);
aws_jni_byte_cursor_from_jbyteArray_release(env, proxy_authorization_username, options->auth_username);
}

if (options->auth_password.ptr != NULL) {
aws_jni_byte_cursor_from_jstring_release(env, proxy_authorization_password, options->auth_password);
aws_jni_byte_cursor_from_jbyteArray_release(env, proxy_authorization_password, options->auth_password);
}

if (options->tls_options != NULL) {
Expand All @@ -136,15 +136,15 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_HttpClientConnectio
jlong jni_socket_options,
jlong jni_tls_ctx,
jint jni_window_size,
jstring jni_endpoint,
jbyteArray jni_endpoint,
jint jni_port,
jint jni_max_conns,
jstring jni_proxy_host,
jbyteArray jni_proxy_host,
jint jni_proxy_port,
jlong jni_proxy_tls_context,
jint jni_proxy_authorization_type,
jstring jni_proxy_authorization_username,
jstring jni_proxy_authorization_password,
jbyteArray jni_proxy_authorization_username,
jbyteArray jni_proxy_authorization_password,
jboolean jni_manual_window_management) {

(void)jni_class;
Expand All @@ -165,7 +165,7 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_HttpClientConnectio
}

struct aws_allocator *allocator = aws_jni_get_allocator();
struct aws_byte_cursor endpoint = aws_jni_byte_cursor_from_jstring_acquire(env, jni_endpoint);
struct aws_byte_cursor endpoint = aws_jni_byte_cursor_from_jbyteArray_acquire(env, jni_endpoint);

if (jni_port <= 0 || 65535 < jni_port) {
aws_jni_throw_runtime_exception(env, "Port must be between 1 and 65535");
Expand Down Expand Up @@ -254,7 +254,7 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_HttpClientConnectio
}

cleanup:
aws_jni_byte_cursor_from_jstring_release(env, jni_endpoint, endpoint);
aws_jni_byte_cursor_from_jbyteArray_release(env, jni_endpoint, endpoint);

return (jlong)conn_manager;
}
Expand Down
12 changes: 6 additions & 6 deletions src/native/http_connection_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ void aws_http_proxy_options_jni_init(
JNIEnv *env,
struct aws_http_proxy_options *options,
struct aws_tls_connection_options *tls_options,
jstring proxy_host,
jbyteArray proxy_host,
uint16_t proxy_port,
jstring proxy_authorization_username,
jstring proxy_authorization_password,
jbyteArray proxy_authorization_username,
jbyteArray proxy_authorization_password,
int proxy_authorization_type,
struct aws_tls_ctx *proxy_tls_ctx);

void aws_http_proxy_options_jni_clean_up(
JNIEnv *env,
struct aws_http_proxy_options *options,
jstring proxy_host,
jstring proxy_authorization_username,
jstring proxy_authorization_password);
jbyteArray proxy_host,
jbyteArray proxy_authorization_username,
jbyteArray proxy_authorization_password);

#endif /* AWS_JNI_CRT_HTTP_CONNECTION_MANAGER_H */