forked from netty/netty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix possible NPE introduced by a137291 when using SslProvider.OPENSSL…
… and init via files or OpenSslX509KeyManagerFactory (netty#8126) Motivation: a137291 introduced a way to get the most speed out of OpenSSL by not only caching keymaterial but pre-compute these. The problem was we missed to check for null before doing an instanceof check and then a cast which could lead to a NPE as we tried to cast null to Exception and throw it. Modifications: Add null check and unit test. Result: No more NPE when keymaterial was not found for requested alias.
- Loading branch information
1 parent
8186c9a
commit df08467
Showing
4 changed files
with
51 additions
and
31 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
38 changes: 38 additions & 0 deletions
38
handler/src/test/java/io/netty/handler/ssl/OpenSslX509KeyManagerFactoryProviderTest.java
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,38 @@ | ||
/* | ||
* Copyright 2018 The Netty Project | ||
* | ||
* The Netty Project licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package io.netty.handler.ssl; | ||
|
||
import javax.net.ssl.KeyManagerFactory; | ||
import java.security.KeyStore; | ||
|
||
public class OpenSslX509KeyManagerFactoryProviderTest extends OpenSslCachingKeyMaterialProviderTest { | ||
|
||
@Override | ||
protected KeyManagerFactory newKeyManagerFactory() throws Exception { | ||
char[] password = PASSWORD.toCharArray(); | ||
final KeyStore keystore = KeyStore.getInstance("PKCS12"); | ||
keystore.load(getClass().getResourceAsStream("mutual_auth_server.p12"), password); | ||
|
||
OpenSslX509KeyManagerFactory kmf = new OpenSslX509KeyManagerFactory(); | ||
kmf.init(keystore, password); | ||
return kmf; | ||
} | ||
|
||
@Override | ||
protected OpenSslKeyMaterialProvider newMaterialProvider(KeyManagerFactory kmf, String password) { | ||
return ((OpenSslX509KeyManagerFactory) kmf).newProvider(); | ||
} | ||
} |