View Javadoc
1   /*
2    * Copyright 2016 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.internal.tcnative;
17  
18  /**
19   * Is called during handshake and hooked into openssl via {@code SSL_CTX_set_client_cert_cb}.
20   *
21   * IMPORTANT: Implementations of this interface should be static as it is stored as a global reference via JNI. This
22   *            means if you use an inner / anonymous class to implement this and also depend on the finalizer of the
23   *            class to free up the SSLContext the finalizer will never run as the object is never GC, due the hard
24   *            reference to the enclosing class. This will most likely result in a memory leak.
25   */
26  public interface CertificateRequestedCallback {
27  
28      /**
29       * The types contained in the {@code keyTypeBytes} array.
30       */
31      // Extracted from https://github.com/openssl/openssl/blob/master/include/openssl/tls1.h
32      byte TLS_CT_RSA_SIGN = 1;
33      byte TLS_CT_DSS_SIGN = 2;
34      byte TLS_CT_RSA_FIXED_DH = 3;
35      byte TLS_CT_DSS_FIXED_DH = 4;
36      byte TLS_CT_ECDSA_SIGN = 64;
37      byte TLS_CT_RSA_FIXED_ECDH = 65;
38      byte TLS_CT_ECDSA_FIXED_ECDH = 66;
39  
40      /**
41       * Called during cert selection. If a certificate chain / key should be used
42       * {@link SSL#setKeyMaterialClientSide(long, long, long, long, long)} must be called from this callback after
43       * all preparations / validations were completed.
44       *
45       * @param ssl                       the SSL instance
46       * @param certOut                   the pointer to the pointer of the certificate to use.
47       * @param keyOut                    the pointer to the pointer of the private key to use.
48       * @param keyTypeBytes              an array of the key types.
49       * @param asn1DerEncodedPrincipals  the principals
50       *
51       */
52      void requested(long ssl, long certOut, long keyOut, byte[] keyTypeBytes, byte[][] asn1DerEncodedPrincipals)
53              throws Exception;
54  }