Skip to content

Commit

Permalink
Make the lookup for getApplicationProtocol optional (#53001)
Browse files Browse the repository at this point in the history
* Make the lookup for getApplicationProtocol optional

The method getApplicationProtocol in javax.net.ssl.SSLEngine is only supported on API level 29 and above, so running on older devices would result in a crash. This change makes the initial method lookup optional and AndroidCryptoNative_SSLStreamGetApplicationProtocol in pal_sslstream.c will error if it is not supported.

Fixes #52965

* Feedback

Co-authored-by: Steve Pfister <[email protected]>
  • Loading branch information
steveisok and Steve Pfister authored May 20, 2021
1 parent 81a9e9e commit 28c213f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
g_SSLEngine = GetClassGRef(env, "javax/net/ssl/SSLEngine");
g_SSLEngineBeginHandshake = GetMethod(env, false, g_SSLEngine, "beginHandshake", "()V");
g_SSLEngineCloseOutbound = GetMethod(env, false, g_SSLEngine, "closeOutbound", "()V");
g_SSLEngineGetApplicationProtocol = GetMethod(env, false, g_SSLEngine, "getApplicationProtocol", "()Ljava/lang/String;");
g_SSLEngineGetApplicationProtocol = GetOptionalMethod(env, false, g_SSLEngine, "getApplicationProtocol", "()Ljava/lang/String;");
g_SSLEngineGetHandshakeStatus = GetMethod(env, false, g_SSLEngine, "getHandshakeStatus", "()Ljavax/net/ssl/SSLEngineResult$HandshakeStatus;");
g_SSLEngineGetSession = GetMethod(env, false, g_SSLEngine, "getSession", "()Ljavax/net/ssl/SSLSession;");
g_SSLEngineGetSSLParameters = GetMethod(env, false, g_SSLEngine, "getSSLParameters", "()Ljavax/net/ssl/SSLParameters;");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,12 @@ void AndroidCryptoNative_SSLStreamRelease(SSLStream* sslStream)

int32_t AndroidCryptoNative_SSLStreamGetApplicationProtocol(SSLStream* sslStream, uint8_t* out, int32_t* outLen)
{
if (g_SSLEngineGetApplicationProtocol == NULL)
{
// SSLEngine.getApplicationProtocol() is only supported from API level 29 and above
return FAIL;
}

abort_if_invalid_pointer_argument (sslStream);
abort_if_invalid_pointer_argument (outLen);

Expand Down

0 comments on commit 28c213f

Please sign in to comment.