Skip to content

Commit

Permalink
Add setter for CredentialsStore in DtlsConnectorConfig.Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Jul 13, 2018
1 parent 8fd486a commit 6836709
Showing 1 changed file with 50 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,17 @@ public Builder setPskStore(PskStore pskStore) {
return this;
}

/**
* Sets credentials Store use to be able to have different credentials depending on foreign peers
* @param credStore
* the credentials store
* @return this builder for command chaining
*/
public Builder setCredentialsStore(CredentialsStore credStore) {
config.credentialsStore = credStore;
return this;
}

/**
* Sets the connector's identifying properties by means of a private
* and public key pair.
Expand Down Expand Up @@ -971,9 +982,6 @@ public DtlsConnectorConfig build() {
if (config.clientAuthenticationRequired == null) {
config.clientAuthenticationRequired = true;
}
if (config.sendRawKey == null) {
config.sendRawKey = true;
}
if (config.outboundMessageBufferSize == null) {
config.outboundMessageBufferSize = 100000;
}
Expand All @@ -983,43 +991,49 @@ public DtlsConnectorConfig build() {
if (config.staleConnectionThreshold == null) {
config.staleConnectionThreshold = DEFAULT_STALE_CONNECTION_TRESHOLD;
}
if (config.certificateVerifier == null && config.trustStore != null) {
config.certificateVerifier = new StaticCertificateVerifier(config.trustStore);
}
if (config.supportedCipherSuites == null || config.supportedCipherSuites.length == 0) {
determineCipherSuitesFromConfig();
}
if (config.trustedRPKs == null) {
// must be set after determineCipherSuitesFromConfig(),
// otherwise this would be interpreted for client only
// as ECDHE_ECDSA support!
config.trustedRPKs = new TrustAllRpks();
if (config.getCredentialsStore() == null) {
if (config.certificateVerifier == null && config.trustStore != null) {
config.certificateVerifier = new StaticCertificateVerifier(config.trustStore);
}
if (config.sendRawKey == null) {
config.sendRawKey = true;
}
if (config.supportedCipherSuites == null || config.supportedCipherSuites.length == 0) {
determineCipherSuitesFromConfig();
}
if (config.trustedRPKs == null) {
// must be set after determineCipherSuitesFromConfig(),
// otherwise this would be interpreted for client only
// as ECDHE_ECDSA support!
config.trustedRPKs = new TrustAllRpks();
}
// check cipher consistency
if (config.supportedCipherSuites == null || config.supportedCipherSuites.length == 0) {
throw new IllegalStateException("Supported cipher suites must be set either " +
"explicitly or implicitly by means of setting the identity or PSK store");
}
for (CipherSuite suite : config.supportedCipherSuites) {
switch (suite) {
case TLS_PSK_WITH_AES_128_CCM_8:
case TLS_PSK_WITH_AES_128_CBC_SHA256:
case TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256:
verifyPskBasedCipherConfig();
break;
case TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8:
case TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256:
verifyEcBasedCipherConfig();
break;
default:
break;
}
}

config.credentialsStore = new DtlsConfigCredentialsStore(config);
}

if (config.sniEnabled == null) {
config.sniEnabled = Boolean.TRUE;
}

// check cipher consistency
if (config.supportedCipherSuites == null || config.supportedCipherSuites.length == 0) {
throw new IllegalStateException("Supported cipher suites must be set either " +
"explicitly or implicitly by means of setting the identity or PSK store");
}
for (CipherSuite suite : config.supportedCipherSuites) {
switch (suite) {
case TLS_PSK_WITH_AES_128_CCM_8:
case TLS_PSK_WITH_AES_128_CBC_SHA256:
case TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256:
verifyPskBasedCipherConfig();
break;
case TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8:
case TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256:
verifyEcBasedCipherConfig();
break;
default:
break;
}
}

config.credentialsStore = new DtlsConfigCredentialsStore(config);
return config;
}
Expand Down

0 comments on commit 6836709

Please sign in to comment.