com.datastax.driver.$internal.io.netty.handler.ssl.SniHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cassandra-driver Show documentation
Show all versions of cassandra-driver Show documentation
Shaded version of DataStax Java Driver for Apache Cassandra
The newest version!
/*
* Copyright 2014 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 com.datastax.driver.$internal.io.netty.handler.ssl;
import com.datastax.driver.$internal.io.netty.buffer.ByteBuf;
import com.datastax.driver.$internal.io.netty.buffer.ByteBufUtil;
import com.datastax.driver.$internal.io.netty.channel.ChannelHandlerContext;
import com.datastax.driver.$internal.io.netty.handler.codec.ByteToMessageDecoder;
import com.datastax.driver.$internal.io.netty.util.CharsetUtil;
import com.datastax.driver.$internal.io.netty.util.DomainNameMapping;
import com.datastax.driver.$internal.io.netty.util.ReferenceCountUtil;
import com.datastax.driver.$internal.io.netty.util.internal.PlatformDependent;
import com.datastax.driver.$internal.io.netty.util.internal.logging.InternalLogger;
import com.datastax.driver.$internal.io.netty.util.internal.logging.InternalLoggerFactory;
import java.net.IDN;
import java.util.List;
import java.util.Locale;
/**
* Enables SNI
* (Server Name Indication) extension for server side SSL. For clients
* support SNI, the server could have multiple host name bound on a single IP.
* The client will send host name in the handshake data so server could decide
* which certificate to choose for the host name.
*/
public class SniHandler extends ByteToMessageDecoder {
// Maximal number of ssl records to inspect before fallback to the default SslContext.
private static final int MAX_SSL_RECORDS = 4;
private static final InternalLogger logger =
InternalLoggerFactory.getInstance(SniHandler.class);
private static final Selection EMPTY_SELECTION = new Selection(null, null);
private final DomainNameMapping mapping;
private boolean handshakeFailed;
private volatile Selection selection = EMPTY_SELECTION;
/**
* Create a SNI detection handler with configured {@link SslContext}
* maintained by {@link DomainNameMapping}
*
* @param mapping the mapping of domain name to {@link SslContext}
*/
@SuppressWarnings("unchecked")
public SniHandler(DomainNameMapping extends SslContext> mapping) {
if (mapping == null) {
throw new NullPointerException("mapping");
}
this.mapping = (DomainNameMapping) mapping;
}
/**
* @return the selected hostname
*/
public String hostname() {
return selection.hostname;
}
/**
* @return the selected sslcontext
*/
public SslContext sslContext() {
return selection.context;
}
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy