View Javadoc
1   /*
2    * Copyright 2014 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.handler.ssl;
17  
18  import org.apache.tomcat.jni.SSLContext;
19  
20  import javax.net.ssl.SSLSession;
21  import javax.net.ssl.SSLSessionContext;
22  import java.util.Enumeration;
23  import java.util.NoSuchElementException;
24  
25  /**
26   * OpenSSL specific {@link SSLSessionContext} implementation.
27   */
28  public abstract class OpenSslSessionContext implements SSLSessionContext {
29      private static final Enumeration<byte[]> EMPTY = new EmptyEnumeration();
30  
31      private final OpenSslSessionStats stats;
32      final long context;
33  
34      OpenSslSessionContext(long context) {
35          this.context = context;
36          stats = new OpenSslSessionStats(context);
37      }
38  
39      @Override
40      public SSLSession getSession(byte[] bytes) {
41          if (bytes == null) {
42              throw new NullPointerException("bytes");
43          }
44          return null;
45      }
46  
47      @Override
48      public Enumeration<byte[]> getIds() {
49          return EMPTY;
50      }
51  
52      /**
53       * Sets the SSL session ticket keys of this context.
54       */
55      public void setTicketKeys(byte[] keys) {
56          if (keys == null) {
57              throw new NullPointerException("keys");
58          }
59          SSLContext.setSessionTicketKeys(context, keys);
60      }
61  
62      /**
63       * Enable or disable caching of SSL sessions.
64       */
65      public abstract void setSessionCacheEnabled(boolean enabled);
66  
67      /**
68       * Return {@code true} if caching of SSL sessions is enabled, {@code false} otherwise.
69       */
70      public abstract boolean isSessionCacheEnabled();
71  
72      /**
73       * Returns the stats of this context.
74       */
75      public OpenSslSessionStats stats() {
76          return stats;
77      }
78  
79      private static final class EmptyEnumeration implements Enumeration<byte[]> {
80          @Override
81          public boolean hasMoreElements() {
82              return false;
83          }
84  
85          @Override
86          public byte[] nextElement() {
87              throw new NoSuchElementException();
88          }
89      }
90  }