Skip to content

Commit d7a7576

Browse files
committed
Merge pull request #3 from cne/develop
KeyServer v0.2.3
2 parents 550fa2b + 24f0ed4 commit d7a7576

23 files changed

Lines changed: 953 additions & 214 deletions

File tree

CHANGELOG

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
# KeyServer Change Log
22

3+
v0.2.3
4+
--------------------------------------------------------------------------------
5+
Features:
6+
- Multiple JSON processing on same TLS session.
7+
- Improved security with IP access control.
8+
- Support more cipher suites on https server.
9+
- KeyServer Configuration more parametric.
10+
- Include KeyServer Private Key provider tool.
11+
312
v0.1.3
413
--------------------------------------------------------------------------------
514
Features:
615
- KeyServer accepts multiples connections (system default limited).
7-
- KeyServer log to a file.
16+
- KeyServer log to a file.

KeyServer/pom.xml

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<name>KeyServer</name>
4-
<url>https://pdihub.hi.inet/cne/cne-keyserver</url>
53
<modelVersion>4.0.0</modelVersion>
4+
<!-- The Basics -->
65
<groupId>es.tid.keyserver</groupId>
7-
<artifactId>keyserver</artifactId>
8-
<version>v0.1.3</version>
6+
<artifactId>KeyServer</artifactId>
7+
<version>v0.2.3</version>
98
<packaging>jar</packaging>
109

11-
<properties>
12-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13-
<maven.compiler.source>1.7</maven.compiler.source>
14-
<maven.compiler.target>1.7</maven.compiler.target>
15-
</properties>
16-
17-
<developers>
18-
<developer>
19-
<id>jgm221</id>
20-
<name>Javier Gusano Martinez</name>
21-
<email>javier.gusano@hpe.com</email>
22-
<properties>
23-
<active>true</active>
24-
</properties>
25-
</developer>
26-
<developer>
27-
<id>jgm1986</id>
28-
<name>Javier Gusano Martinez</name>
29-
<email>jgm1986@hotmail.com</email>
30-
<properties>
31-
<active>true</active>
32-
</properties>
33-
</developer>
34-
<developer>
35-
<id>oscargdd</id>
36-
<name>Oscar Gonzalez de Dios</name>
37-
<email>oscar.gonzalezdedios@telefonica.com</email>
38-
<properties>
39-
<active>true</active>
40-
</properties>
41-
</developer>
42-
</developers>
43-
4410
<dependencies>
4511
<dependency>
4612
<groupId>redis.clients</groupId>
@@ -62,7 +28,7 @@
6228
<dependency>
6329
<groupId>org.slf4j</groupId>
6430
<artifactId>slf4j-api</artifactId>
65-
<version>1.7.12</version>
31+
<version>1.7.7</version>
6632
</dependency>
6733
<dependency>
6834
<groupId>ch.qos.logback</groupId>
@@ -76,6 +42,13 @@
7642
</dependency>
7743
</dependencies>
7844

45+
<properties>
46+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
47+
<maven.compiler.source>1.8</maven.compiler.source>
48+
<maven.compiler.target>1.8</maven.compiler.target>
49+
</properties>
50+
51+
<!-- Build Settings -->
7952
<build>
8053
<plugins>
8154
<plugin>
@@ -90,8 +63,13 @@
9063
</archive>
9164
</configuration>
9265
</plugin>
66+
<plugin>
67+
<artifactId>maven-project-info-reports-plugin</artifactId>
68+
<version>2.8.1</version>
69+
</plugin>
9370
<plugin>
9471
<artifactId>maven-assembly-plugin</artifactId>
72+
<version>2.6</version>
9573
<executions>
9674
<execution>
9775
<phase>package</phase>
@@ -120,4 +98,44 @@
12098
</resource>
12199
</resources>
122100
</build>
101+
102+
<!-- More Project Information -->
103+
<name>KeyServer</name>
104+
<description>This tool is a Key Server software that implements the collaborative Solution API. It is intended to run in the Content Provider network. It is used to storage private keys from the Content Provider and reply to queries from the MSP Collaborative API.</description>
105+
<url>https://github.com/mami-project/KeyServer</url>
106+
<inceptionYear>2016</inceptionYear>
107+
<licenses>
108+
<license>
109+
<name>Apache License, Version 2.0</name>
110+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
111+
<distribution>manual</distribution>
112+
<comments>License pending to determine.</comments>
113+
</license>
114+
</licenses>
115+
<developers>
116+
<developer>
117+
<id>jgm1986</id>
118+
<name>Javier Gusano Martinez</name>
119+
<email>javier.gusano@hpe.com</email>
120+
<organization>Hewlett-Packard Enterprise</organization>
121+
<organizationUrl>https://www.hpe.com</organizationUrl>
122+
<timezone>(UTC+01:00) Brussels, Copenhagen, Madrid, Paris</timezone>
123+
</developer>
124+
</developers>
125+
126+
<contributors>
127+
<contributor>
128+
<name>Oscar Gonzalez de Dios</name>
129+
<email>oscar.gonzalezdedios@telefonica.com</email>
130+
<organization>Telefonica</organization>
131+
<organizationUrl>http://www.tid.com</organizationUrl>
132+
<timezone>(UTC+01:00) Brussels, Copenhagen, Madrid, Paris</timezone>
133+
</contributor>
134+
</contributors>
135+
136+
<!-- Environment Settings -->
137+
<issueManagement>
138+
<system>GitHub</system>
139+
<url>https://github.com/mami-project/KeyServer/issues</url>
140+
</issueManagement>
123141
</project>

KeyServer/src/main/java/es/tid/keyserver/config/ConfigFile.java

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,31 @@ public class ConfigFile implements CheckObject{
4141
/**
4242
* Flag for check if the object is correctly initialized.
4343
*/
44-
boolean isInitializated = false;
44+
private boolean isInitializated = false;
4545

4646
/**
4747
* Default class constructor.
4848
* @param fileRoute Contains the name and route to the external
4949
* configuration file.
50+
* @param requiredFields Fields required inside configuration file.
5051
*/
51-
public ConfigFile(String fileRoute){
52+
public ConfigFile(String fileRoute, String [] requiredFields){
5253
File propertiesFile = new File(fileRoute);
5354
String fileLocation;
5455
if((propertiesFile.exists() && propertiesFile.canRead())){
5556
fileLocation = fileRoute;
5657
} else {
5758
logger.warn("Can't access to the specified config file or "
5859
+ "doesn't exists: {}", fileRoute);
59-
System.out.print(" - New config file on default location...");
60+
logger.info("New config file on default location...");
6061
fileLocation = "general.properties";
6162
newDefaultProperties(fileLocation);
6263
}
6364
configFile = new Properties();
64-
// Load the config file parammeters.
65+
// Load the configuration file parameters.
6566
try {
6667
configFile.load(new FileInputStream(fileLocation));
67-
this.isInitializated = true;
68+
this.isInitializated = checkFieldsPresent(requiredFields);
6869
} catch (IOException ex) {
6970
logger.error("Cannot load the configuration file for KeyServer.");
7071
logger.trace("Exceiption message: {}", ex.toString());
@@ -92,17 +93,22 @@ private void newDefaultProperties(String fileLocation) {
9293
try {
9394
FileOutputStream newConfigFile = new FileOutputStream(fileLocation);
9495
Properties defaultParameters = new Properties();
95-
// Default parammeters:
96-
defaultParameters.setProperty("serverAddress", "127.0.0.1");
96+
// Default parameters:
97+
defaultParameters.setProperty("serverAddress", "0.0.0.0");
9798
defaultParameters.setProperty("serverPort", "443");
98-
defaultParameters.setProperty("serverBacklog", "0");
99+
defaultParameters.setProperty("serverSSLContext", "TLSv1.2");
99100
defaultParameters.setProperty("serverKeyFile","HTTPS_keystore.ks");
100101
defaultParameters.setProperty("serverKeyPass","123456");
102+
defaultParameters.setProperty("serverBacklog", "0");
103+
defaultParameters.setProperty("serverKeyManagerFactory", "SunX509");
104+
defaultParameters.setProperty("serverTrustManagerFactory", "SunX509");
105+
defaultParameters.setProperty("serverKeyStore", "JKS");
101106
defaultParameters.setProperty("dbAddress","127.0.0.1");
102107
defaultParameters.setProperty("dbPort", "6379");
108+
defaultParameters.setProperty("whiteList", "IP_whitelist.txt");
103109
// Save parameters on file
104110
defaultParameters.store(newConfigFile, null);
105-
// Close config file.
111+
// Close configuration file.
106112
newConfigFile.close();
107113
} catch (FileNotFoundException ex) {
108114
logger.error("Cannot create a new config file with default parameters.");
@@ -123,4 +129,28 @@ private void newDefaultProperties(String fileLocation) {
123129
public boolean isCorrectlyInitialized() {
124130
return isInitializated;
125131
}
132+
133+
/**
134+
* Checks if the required fields inside KeyServer configuration file are present.
135+
* @param fields Array with the fields name.
136+
* @return True if all is present, false if not.
137+
*/
138+
private boolean checkFieldsPresent(String [] fields){
139+
for (String field : fields) {
140+
if (!configFile.containsKey(field)) {
141+
logger.error("Necessary config field is not present: {}", field);
142+
return false;
143+
}
144+
}
145+
return true;
146+
}
147+
148+
/**
149+
* Check if the specified label is present inside configuration file.
150+
* @param label Label as string.
151+
* @return True if exists, false if not.
152+
*/
153+
public boolean containsKey(String label){
154+
return configFile.containsKey(label);
155+
}
126156
}

KeyServer/src/main/java/es/tid/keyserver/database/DataBase.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ public class DataBase implements CheckObject{
3232
/**
3333
* REDIS Database Connection Object
3434
*/
35-
Jedis dataBaseObj;
35+
private Jedis dataBaseObj;
3636

3737
/**
3838
* Flag for check if the object is correctly initialization.
3939
*/
40-
boolean isInitializated;
40+
private boolean isInitializated;
4141

4242
/**
4343
* Logging object.
@@ -51,9 +51,10 @@ public class DataBase implements CheckObject{
5151
public DataBase(ConfigFile parameters){
5252
JedisPool pool = new JedisPool(parameters.getParameter("dbAddress"), Integer.parseInt(parameters.getParameter("dbPort")));
5353
try {
54-
// Reddis connected.
54+
// Redis connected.
5555
dataBaseObj = pool.getResource();
5656
isInitializated = true;
57+
pool.close();
5758
} catch (JedisConnectionException e) {
5859
logger.debug("Database initialization failed.");
5960
logger.trace("Database exception: {}", e.toString());

KeyServer/src/main/java/es/tid/keyserver/httpkeyserver/HttpKeyServer.java

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.sun.net.httpserver.HttpsServer;
2121
import es.tid.keyserver.config.ConfigFile;
2222
import es.tid.keyserver.database.DataBase;
23+
import es.tid.keyserver.httpkeyserver.whitelist.WhiteList;
2324
import java.io.FileInputStream;
2425
import java.io.IOException;
2526
import java.net.InetAddress;
@@ -30,6 +31,9 @@
3031
import java.security.NoSuchAlgorithmException;
3132
import java.security.UnrecoverableKeyException;
3233
import java.security.cert.CertificateException;
34+
import java.util.Arrays;
35+
import java.util.List;
36+
import java.util.concurrent.Executor;
3337
import javax.net.ssl.KeyManagerFactory;
3438
import javax.net.ssl.SSLContext;
3539
import javax.net.ssl.SSLEngine;
@@ -55,14 +59,14 @@ public class HttpKeyServer implements CheckObject{
5559
/**
5660
* Flag for check if the object is correctly initialized.
5761
*/
58-
boolean isInitializated = false;
62+
private boolean isInitializated = false;
5963
/**
6064
* Main constructor for the HTTPS Server class.
6165
* @param parameters Object with program parameters.
6266
* @param objDB REDIS database Object.
6367
* @see <a href="http://stackoverflow.com/questions/2308479/simple-java-https-server">More info about HttpsServer</a>
6468
*/
65-
public HttpKeyServer(ConfigFile parameters, DataBase objDB){
69+
public HttpKeyServer(final ConfigFile parameters, DataBase objDB){
6670
try {
6771
// Getting the Server parameters from properties file.
6872
int port = Integer.parseInt(parameters.getParameter("serverPort"));
@@ -71,16 +75,16 @@ public HttpKeyServer(ConfigFile parameters, DataBase objDB){
7175
InetSocketAddress address = new InetSocketAddress ( ipaddress, port );
7276
// Create basic Server object
7377
server = HttpsServer.create();
74-
SSLContext sslContext = SSLContext.getInstance("TLS");
75-
// initialise the keystore
78+
SSLContext sslContext = SSLContext.getInstance(parameters.getParameter("serverSSLContext"));
79+
// Initialize the key store object
7680
char[] keystorePassword = parameters.getParameter("serverKeyPass").toCharArray();
77-
KeyStore ks = KeyStore.getInstance("JKS");
81+
KeyStore ks = KeyStore.getInstance(parameters.getParameter("serverKeyStore"));
7882
ks.load(new FileInputStream(parameters.getParameter("serverKeyFile")), keystorePassword);
7983
// setup the key manager factory
80-
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
84+
KeyManagerFactory kmf = KeyManagerFactory.getInstance(parameters.getParameter("serverKeyManagerFactory"));
8185
kmf.init(ks, keystorePassword);
8286
// setup the trust manager factory
83-
TrustManagerFactory tmf = TrustManagerFactory.getInstance ( "SunX509" );
87+
TrustManagerFactory tmf = TrustManagerFactory.getInstance (parameters.getParameter("serverTrustManagerFactory"));
8488
tmf.init ( ks );
8589
// Setup the HTTPs context and parameters.
8690
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
@@ -97,27 +101,62 @@ public HttpKeyServer(ConfigFile parameters, DataBase objDB){
97101
@Override
98102
public void configure(HttpsParameters params){
99103
try {
100-
// Initialise the SSL context
104+
// Initialize the SSL context
101105
SSLContext c = SSLContext.getDefault();
102106
SSLEngine engine = c.createSSLEngine();
103107
params.setNeedClientAuth(false);
104108
params.setCipherSuites(engine.getEnabledCipherSuites());
105109
params.setProtocols(engine.getEnabledProtocols());
106110
// Get the default parameters
107111
SSLParameters defaultSSLParameters = c.getDefaultSSLParameters();
112+
113+
if(parameters.containsKey("serverCiphersSuites") && getCiphers(parameters)!=null){
114+
String [] ciphersuites = getCiphers(parameters);
115+
defaultSSLParameters.setCipherSuites(ciphersuites);
116+
}
108117
params.setSSLParameters(defaultSSLParameters);
109118
} catch (NoSuchAlgorithmException ex) {
110119
logger.error("Problem with SSL context parameters.");
111120
logger.trace("Exceiption message: {}", ex.toString());
112121
}
122+
}
123+
/**
124+
* This method parse the field string to array of values with
125+
* the ciphers names. If the configuration label is not present
126+
* inside configuration file. This, will use all available
127+
* ciphers by default.
128+
* @param parameters Configuration file object.
129+
* @return Array of strings with the ciphers name.
130+
*/
131+
private String[] getCiphers(ConfigFile parameters) {
132+
String [] returnValue = null;
133+
String cipString = parameters.getParameter("serverCiphersSuites");
134+
if(!cipString.equalsIgnoreCase("")){
135+
List<String> items = Arrays.asList(cipString.split("\\s*,\\s*"));
136+
returnValue = (String[]) items.toArray();
137+
}
138+
//logger.trace("List {} of ciphers inside KeyServer configuration file: {}", returnValue.length, returnValue);
139+
return returnValue;
113140
}
114141
});
115-
// Setting config for the server and accepting only BACKLOG variable
116-
// as maximum input conection (0 = System default).
142+
// Setting configuration for the server and accepting only BACKLOG variable
143+
// as maximum input connection (0 = System default).
117144
server.bind(address, backlog);
118-
IncomingRequestProcess processor =new IncomingRequestProcess(objDB);
145+
WhiteList allowedIPs = new WhiteList(parameters.getParameter("whiteList"));
146+
IncomingRequestProcess processor =new IncomingRequestProcess(objDB, allowedIPs);
119147
server.createContext("/", processor);
120-
server.setExecutor(processor);
148+
server.setExecutor(new Executor(){
149+
/**
150+
* Launch the runner for the incoming HTTP request. This method
151+
* call to the handle method to process the incoming HTTP proxy
152+
* request.
153+
* @param r Runnable object for the incoming petition.
154+
*/
155+
@Override
156+
public void execute(Runnable r) {
157+
r.run();
158+
}
159+
});
121160
// Starting server
122161
server.start();
123162
isInitializated = true;

0 commit comments

Comments
 (0)