forked from netty/netty-tcnative
-
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.
Expose way to use SSL_CTX_set_cert_cb as general replacement of SSL_C…
…TX_set_client_cert_cb and expose some more functions. (netty#388) Motivation: Currently we only support SSL_CTX_set_client_cert_cb which only works for client side and so we have no good way to setup certificates on the server-side in a proper way that is "safe". Beside this SSL_CTX_set_client_cert_cb should be considered as "deprecated" and SSL_CTX_set_cert_cb should be use as its replacement. By using SSL_CTX_set_cert_cb we can also ensure the SSL Hello was send and so the SNI / algorithms etc can be accessed in all cases. Methods for doing so were also mssing. Modifications: - Add method to make use of SSL_CTX_set_cert_cb and mark the old methods that uses SSL_CTX_set_client_cert_cb as deprecated (+ the old callback interface). - Add method to retrieve requested SNI hostname - Add methods to retrieve the supported signature algorithms by the peer. Result: More correct way to hook in validation / keymaterial selection when using client / server mode and ways to retrieve addional infos.
- Loading branch information
1 parent
0a13a3f
commit e47724e
Showing
7 changed files
with
318 additions
and
27 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
51 changes: 51 additions & 0 deletions
51
openssl-dynamic/src/main/java/io/netty/internal/tcnative/CertificateCallback.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,51 @@ | ||
/* | ||
* 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.internal.tcnative; | ||
|
||
/** | ||
* Is called during handshake and hooked into openssl via {@code SSL_CTX_set_cert_cb}. | ||
* | ||
* IMPORTANT: Implementations of this interface should be static as it is stored as a global reference via JNI. This | ||
* means if you use an inner / anonymous class to implement this and also depend on the finalizer of the | ||
* class to free up the SSLContext the finalizer will never run as the object is never GC, due the hard | ||
* reference to the enclosing class. This will most likely result in a memory leak. | ||
*/ | ||
public interface CertificateCallback { | ||
|
||
/** | ||
* The types contained in the {@code keyTypeBytes} array. | ||
*/ | ||
// Extracted from https://github.com/openssl/openssl/blob/master/include/openssl/tls1.h | ||
byte TLS_CT_RSA_SIGN = 1; | ||
byte TLS_CT_DSS_SIGN = 2; | ||
byte TLS_CT_RSA_FIXED_DH = 3; | ||
byte TLS_CT_DSS_FIXED_DH = 4; | ||
byte TLS_CT_ECDSA_SIGN = 64; | ||
byte TLS_CT_RSA_FIXED_ECDH = 65; | ||
byte TLS_CT_ECDSA_FIXED_ECDH = 66; | ||
|
||
/** | ||
* Called during cert selection. If a certificate chain / key should be used | ||
* {@link SSL#setKeyMaterial(long, long, long)} must be called from this callback after | ||
* all preparations / validations were completed. | ||
* | ||
* @param ssl the SSL instance | ||
* @param keyTypeBytes an array of the key types on client-mode or {@code null} on server-mode. | ||
* @param asn1DerEncodedPrincipals the principals or {@code null}. | ||
* | ||
*/ | ||
void handle(long ssl, byte[] keyTypeBytes, byte[][] asn1DerEncodedPrincipals) throws Exception; | ||
} |
Oops, something went wrong.