-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
android: attempting to respect Android's cleartext policies (#2318)
Rejecting requests which don't have an https scheme if Android disallows cleartext Risk Level: High Testing: TODO (envoyproxy/envoy-mobile#2341) Docs Changes: n/a Release Notes: inline Fixes #1572 Signed-off-by: Alyssa Wilk <alyssar@chromium.org> Signed-off-by: JP Simard <jp@jpsim.com>
- Loading branch information
1 parent
93ce640
commit 18ad777
Showing
6 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "library/common/jni/android_jni_utility.h" | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "source/common/common/assert.h" | ||
|
||
#if defined(__ANDROID_API__) | ||
#include "library/common/data/utility.h" | ||
#include "library/common/jni/import/jni_import.h" | ||
#include "library/common/jni/jni_support.h" | ||
#include "library/common/jni/jni_version.h" | ||
#include "library/common/jni/jni_utility.h" | ||
#endif | ||
|
||
// NOLINT(namespace-envoy) | ||
|
||
bool is_cleartext_permitted(absl::string_view hostname) { | ||
#if defined(__ANDROID_API__) | ||
envoy_data host = Envoy::Data::Utility::copyToBridgeData(hostname); | ||
JNIEnv* env = get_env(); | ||
jstring java_host = native_data_to_string(env, host); | ||
jclass jcls_Boolean = env->FindClass("org/chromium/net/AndroidNetworkLibrary"); | ||
jmethodID jmid_isCleartextTrafficPermitted = | ||
env->GetMethodID(jcls_Boolean, "isCleartextTrafficPermitted", "(Ljava/lang/String;)Z"); | ||
jboolean result = env->CallBooleanMethod(java_host, jmid_isCleartextTrafficPermitted); | ||
env->DeleteLocalRef(java_host); | ||
release_envoy_data(host); | ||
return result == JNI_TRUE; | ||
#else | ||
UNREFERENCED_PARAMETER(hostname); | ||
return true; | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#include "absl/strings/string_view.h" | ||
|
||
// NOLINT(namespace-envoy) | ||
|
||
/* For android, calls up through JNI to see if cleartext is permitted for this | ||
* host. | ||
* For other platforms simply returns true. | ||
*/ | ||
bool is_cleartext_permitted(absl::string_view hostname); |