Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* Copyright (c) 2017, 2018 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.html.
*
* Contributors:
* Bosch Software Innovations GmbH - initial implementation
* Achim Kraus (Bosch Software Innovations GmbH) - add ETSI credentials
* Achim Kraus (Bosch Software Innovations GmbH) - make added endpoints more selectable
******************************************************************************/
package org.eclipse.californium.plugtests;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.security.GeneralSecurityException;
import java.security.cert.Certificate;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;
import javax.crypto.SecretKey;
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSessionContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509KeyManager;
import org.eclipse.californium.core.CoapServer;
import org.eclipse.californium.core.coap.CoAP;
import org.eclipse.californium.core.config.CoapConfig;
import org.eclipse.californium.core.config.CoapConfig.MatcherMode;
import org.eclipse.californium.core.network.CoapEndpoint;
import org.eclipse.californium.core.network.Endpoint;
import org.eclipse.californium.core.network.interceptors.AnonymizedOriginTracer;
import org.eclipse.californium.core.network.interceptors.HealthStatisticLogger;
import org.eclipse.californium.core.network.interceptors.MessageTracer;
import org.eclipse.californium.elements.PrincipalEndpointContextMatcher;
import org.eclipse.californium.elements.config.Configuration;
import org.eclipse.californium.elements.config.IntegerDefinition;
import org.eclipse.californium.elements.config.SystemConfig;
import org.eclipse.californium.elements.config.TcpConfig;
import org.eclipse.californium.elements.config.TimeDefinition;
import org.eclipse.californium.elements.tcp.netty.TcpServerConnector;
import org.eclipse.californium.elements.tcp.netty.TlsServerConnector;
import org.eclipse.californium.elements.util.NetworkInterfacesUtil;
import org.eclipse.californium.elements.util.SslContextUtil;
import org.eclipse.californium.elements.util.StringUtil;
import org.eclipse.californium.plugtests.PlugtestServer.BaseConfig;
import org.eclipse.californium.scandium.DTLSConnector;
import org.eclipse.californium.scandium.DtlsHealthLogger;
import org.eclipse.californium.scandium.MdcConnectionListener;
import org.eclipse.californium.scandium.config.DtlsConfig;
import org.eclipse.californium.scandium.config.DtlsConnectorConfig;
import org.eclipse.californium.scandium.dtls.ConnectionId;
import org.eclipse.californium.scandium.dtls.PskPublicInformation;
import org.eclipse.californium.scandium.dtls.PskSecretResult;
import org.eclipse.californium.scandium.dtls.cipher.CipherSuite;
import org.eclipse.californium.scandium.dtls.pskstore.AsyncAdvancedPskStore;
import org.eclipse.californium.scandium.dtls.pskstore.MultiPskFileStore;
import org.eclipse.californium.scandium.dtls.resumption.AsyncResumptionVerifier;
import org.eclipse.californium.scandium.dtls.x509.AsyncKeyManagerCertificateProvider;
import org.eclipse.californium.scandium.dtls.x509.AsyncNewAdvancedCertificateVerifier;
import org.eclipse.californium.scandium.util.SecretUtil;
import org.eclipse.californium.scandium.util.ServerNames;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Base for test servers.
*/
public abstract class AbstractTestServer extends CoapServer {
/**
* @since 3.10
*/
private static final Logger LOGGER = LoggerFactory.getLogger(CoapServer.class);
public enum Protocol {
UDP, DTLS, TCP, TLS
}
public enum InterfaceType {
LOCAL, EXTERNAL, IPV4, IPV6,
}
public static class Select {
public final Protocol protocol;
public final InterfaceType interfaceType;
public Select(Protocol protocol) {
this.protocol = protocol;
this.interfaceType = null;
}
public Select(InterfaceType interfaceType) {
this.protocol = null;
this.interfaceType = interfaceType;
}
public Select(Protocol protocol, InterfaceType interfaceType) {
this.protocol = protocol;
this.interfaceType = interfaceType;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((interfaceType == null) ? 0 : interfaceType.hashCode());
result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Select other = (Select) obj;
if (interfaceType != other.interfaceType)
return false;
if (protocol != other.protocol)
return false;
return true;
}
}
// exit codes for runtime errors
private static final char[] KEY_STORE_PASSWORD = "endPass".toCharArray();
private static final String KEY_STORE_LOCATION = "certs/keyStore.jks";
private static final char[] TRUST_STORE_PASSWORD = "rootPass".toCharArray();
private static final String TRUST_STORE_LOCATION = "certs/trustStore.jks";
private static final String SERVER_NAME = "server";
private static final String PSK_IDENTITY_PREFIX = "cali.";
private static final SecretKey PSK_SECRET = SecretUtil.create(".fornium".getBytes(), "PSK");
// from ETSI Plugtest test spec
public static final String ETSI_PSK_IDENTITY = "password";
public static final SecretKey ETSI_PSK_SECRET = SecretUtil.create("sesame".getBytes(), "PSK");
// easier testing with openssl clients
public static final String OPENSSL_PSK_IDENTITY = "Client_identity";
public static final SecretKey OPENSSL_PSK_SECRET = SecretUtil.create("secretPSK".getBytes(), "PSK");
public static final TimeDefinition DTLS_HANDSHAKE_RESULT_DELAY = new TimeDefinition("DTLS_HANDSHAKE_RESULT_DELAY",
"Delay for DTLS handshake results. Only for testing!!!\n0 no delay, < 0 blocking delay, > 0 non-blocking delay.");
public static final Pattern HONO_IDENTITY_PATTERN = Pattern.compile("^[^@]{8,}@.{8,}$");
public static final SecretKey HONO_PSK_SECRET = SecretUtil.create("secret".getBytes(), "PSK");
public static final Pattern IPV6_SCOPE = Pattern.compile("^([0-9a-fA-F:]+)(%\\w+)?$");
/**
* Preferred blocksize when using coap/UDP on external interface.
*
* Small value to prevent amplification.
*/
public static final IntegerDefinition EXTERNAL_UDP_PREFERRED_BLOCK_SIZE = new IntegerDefinition(
"EXTERNAL_UDP_PREFERRED_BLOCK_SIZE",
"Preferred blocksize for blockwise transfer with coap/UDP using an external network interface.", 64, 16);
/**
* Maximum payload size before using blockwise when using coap/UDP on
* external interface.
*
* Small value to prevent amplification.
*/
public static final IntegerDefinition EXTERNAL_UDP_MAX_MESSAGE_SIZE = new IntegerDefinition(
"EXTERNAL_UDP_MAX_MESSAGE_SIZE", "Maximum payload size with coap/UDP using an external network interface.",
64, 16);
/**
* Interval to read number of dropped udp messages.
*/
public static final TimeDefinition UDP_DROPS_READ_INTERVAL = new TimeDefinition("UDP_DROPS_READ_INTERVAL",
"Interval to read upd drops from OS (currently only Linux).", 2000, TimeUnit.MILLISECONDS);
private final Configuration config;
private final Map