001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase;
019
020import java.io.IOException;
021import java.net.ServerSocket;
022import java.net.Socket;
023import java.util.ArrayList;
024import javax.net.ssl.SSLSocket;
025import javax.net.ssl.SSLSocketFactory;
026import javax.rmi.ssl.SslRMIServerSocketFactory;
027import org.apache.yetus.audience.InterfaceAudience;
028
029/**
030 * Avoid SSL V3.0 "Poodle" Vulnerability - CVE-2014-3566
031 */
032@InterfaceAudience.Private
033public class SslRMIServerSocketFactorySecure extends SslRMIServerSocketFactory {
034  // If you add more constructors, you may have to change the rest of this implementation,
035  // which assumes an empty constructor, i.e. there are no specially enabled protocols or
036  // cipher suites on this RMI factory nor a provided SSLContext
037  public SslRMIServerSocketFactorySecure() {
038    super();
039  }
040
041  @Override
042  public ServerSocket createServerSocket(int port) throws IOException {
043    return new ServerSocket(port) {
044      @Override
045      public Socket accept() throws IOException {
046        Socket socket = super.accept();
047        SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
048        SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(socket,
049          socket.getInetAddress().getHostName(), socket.getPort(), true);
050        sslSocket.setUseClientMode(false);
051        sslSocket.setNeedClientAuth(false);
052
053        ArrayList<String> secureProtocols = new ArrayList<>();
054        for (String p : sslSocket.getEnabledProtocols()) {
055          if (!p.contains("SSLv3")) {
056            secureProtocols.add(p);
057          }
058        }
059        sslSocket.setEnabledProtocols(secureProtocols.toArray(new String[secureProtocols.size()]));
060
061        return sslSocket;
062      }
063    };
064  }
065}