Skip to content

Commit 2b3a0a0

Browse files
authored
Extract and rename config struts from EthSignerBaseCommand (Consensys#212)
1 parent 7d1d1a8 commit 2b3a0a0

File tree

5 files changed

+223
-143
lines changed

5 files changed

+223
-143
lines changed

ethsigner/commandline/src/main/java/tech/pegasys/ethsigner/EthSignerBaseCommand.java

Lines changed: 8 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
*/
1313
package tech.pegasys.ethsigner;
1414

15-
import tech.pegasys.ethsigner.core.config.ClientAuthConstraints;
15+
import tech.pegasys.ethsigner.config.PicoCliDownstreamTrustStore;
16+
import tech.pegasys.ethsigner.config.PicoCliTlsClientCertificateOptions;
17+
import tech.pegasys.ethsigner.config.PicoCliTlsServerOptions;
1618
import tech.pegasys.ethsigner.core.config.Config;
1719
import tech.pegasys.ethsigner.core.config.PkcsStoreConfig;
1820
import tech.pegasys.ethsigner.core.config.TlsOptions;
1921
import tech.pegasys.ethsigner.core.signing.ChainIdProvider;
2022
import tech.pegasys.ethsigner.core.signing.ConfigurationChainId;
2123

22-
import java.io.File;
2324
import java.net.InetAddress;
2425
import java.nio.file.Path;
2526
import java.time.Duration;
@@ -50,142 +51,6 @@
5051
footer = "EthSigner is licensed under the Apache License 2.0")
5152
public class EthSignerBaseCommand implements Config {
5253

53-
static class TlsClientCertificateOptions implements PkcsStoreConfig {
54-
55-
@Option(
56-
names = "--downstream-http-tls-keystore-file",
57-
description =
58-
"Path to a PKCS#12 formatted keystore, contains TLS certificate to present to "
59-
+ "a TLS-enabled web3 provider",
60-
arity = "1",
61-
required = true)
62-
private File clientCertificateFile;
63-
64-
@Option(
65-
names = "--downstream-http-tls-keystore-password-file",
66-
description = "Path to a file containing the password used to decrypt the client cert.",
67-
arity = "1",
68-
required = true)
69-
private File clientCertificatePasswordFile;
70-
71-
@Override
72-
public File getStoreFile() {
73-
return clientCertificateFile;
74-
}
75-
76-
@Override
77-
public File getStorePasswordFile() {
78-
return clientCertificatePasswordFile;
79-
}
80-
}
81-
82-
static class Web3ProviderTrustStore implements PkcsStoreConfig {
83-
84-
@Option(
85-
names = "--downstream-http-tls-truststore-file",
86-
description =
87-
"Path to a PKCS#12 formatted truststore, containing all trusted root "
88-
+ "certificates.",
89-
arity = "1",
90-
required = true)
91-
private File trustStoreFile;
92-
93-
@Option(
94-
names = "--downstream-http-tls-truststore-password-file",
95-
description = "Path to a file containing the password used to decrypt the truststore.",
96-
arity = "1",
97-
required = true)
98-
private File trustStorePasswordFile;
99-
100-
@Override
101-
public File getStoreFile() {
102-
return trustStoreFile;
103-
}
104-
105-
@Override
106-
public File getStorePasswordFile() {
107-
return trustStorePasswordFile;
108-
}
109-
}
110-
111-
static class TlsClientAuthorizationMechanisms implements ClientAuthConstraints {
112-
113-
@Option(
114-
names = "--tls-known-clients-file",
115-
description = "Path to a file containing the fingerprints of authorized clients.",
116-
arity = "1")
117-
private File tlsKnownClientsFile = null;
118-
119-
@Option(
120-
names = "--tls-allow-ca-clients",
121-
description = "If defined, allows clients authorized by the CA to connect to Ethsigner.",
122-
arity = "0")
123-
private Boolean tlsAllowCaClients = false;
124-
125-
@Override
126-
public Optional<File> getKnownClientsFile() {
127-
return Optional.ofNullable(tlsKnownClientsFile);
128-
}
129-
130-
@Override
131-
public boolean isCaAuthorizedClientAllowed() {
132-
return tlsAllowCaClients;
133-
}
134-
}
135-
136-
static class TlsClientAuthentication {
137-
138-
@SuppressWarnings("UnusedVariable")
139-
@ArgGroup(exclusive = false)
140-
private TlsClientAuthorizationMechanisms authMechanisms;
141-
142-
@Option(
143-
names = "--tls-allow-any-client",
144-
description =
145-
"If defined, will allow any client to connect. Is mutually exclusive with other "
146-
+ "client authentication settings",
147-
arity = "0")
148-
private Boolean tlsAllowAnyClient = false;
149-
}
150-
151-
static class TlsServerOptions implements TlsOptions {
152-
153-
@Option(
154-
names = "--tls-keystore-file",
155-
description =
156-
"Path to a PKCS#12 formatted keystore; used to enable TLS on inbound connections.",
157-
arity = "1",
158-
required = true)
159-
private File keyStoreFile;
160-
161-
@Option(
162-
names = "--tls-keystore-password-file",
163-
description = "Path to a file containing the password used to decrypt the keystore.",
164-
arity = "1",
165-
required = true)
166-
private File keyStorePasswordFile;
167-
168-
@ArgGroup(multiplicity = "1", exclusive = true)
169-
private TlsClientAuthentication tlsClientAuthentication;
170-
171-
@Override
172-
public File getKeyStoreFile() {
173-
return keyStoreFile;
174-
}
175-
176-
@Override
177-
public File getKeyStorePasswordFile() {
178-
return keyStorePasswordFile;
179-
}
180-
181-
@Override
182-
public Optional<ClientAuthConstraints> getClientAuthConstraints() {
183-
return tlsClientAuthentication.tlsAllowAnyClient
184-
? Optional.empty()
185-
: Optional.of(tlsClientAuthentication.authMechanisms);
186-
}
187-
}
188-
18954
@Option(
19055
names = {"--logging", "-l"},
19156
paramLabel = "<LOG VERBOSITY LEVEL>",
@@ -245,13 +110,13 @@ public Optional<ClientAuthConstraints> getClientAuthConstraints() {
245110
private Path dataPath;
246111

247112
@ArgGroup(exclusive = false)
248-
private TlsServerOptions tlsServerOptions;
113+
private PicoCliTlsServerOptions picoCliTlsServerOptions;
249114

250115
@ArgGroup(exclusive = false)
251-
private TlsClientCertificateOptions clientTlsCertificateOptions;
116+
private PicoCliTlsClientCertificateOptions clientTlsCertificateOptions;
252117

253118
@ArgGroup(exclusive = false)
254-
private Web3ProviderTrustStore web3ProviderTrustStore;
119+
private PicoCliDownstreamTrustStore picoCliDownstreamTrustStore;
255120

256121
@Override
257122
public Level getLogLevel() {
@@ -295,12 +160,12 @@ public Duration getDownstreamHttpRequestTimeout() {
295160

296161
@Override
297162
public Optional<TlsOptions> getTlsOptions() {
298-
return Optional.ofNullable(tlsServerOptions);
163+
return Optional.ofNullable(picoCliTlsServerOptions);
299164
}
300165

301166
@Override
302167
public Optional<PkcsStoreConfig> getWeb3TrustStoreOptions() {
303-
return Optional.ofNullable(web3ProviderTrustStore);
168+
return Optional.ofNullable(picoCliDownstreamTrustStore);
304169
}
305170

306171
@Override
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2020 ConsenSys AG.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package tech.pegasys.ethsigner.config;
14+
15+
import tech.pegasys.ethsigner.core.config.ClientAuthConstraints;
16+
17+
import java.io.File;
18+
import java.util.Optional;
19+
20+
import picocli.CommandLine.Option;
21+
22+
public class PicoCliClientAuthConstraints implements ClientAuthConstraints {
23+
24+
@Option(
25+
names = "--tls-known-clients-file",
26+
description = "Path to a file containing the fingerprints of authorized clients.",
27+
arity = "1")
28+
private File tlsKnownClientsFile = null;
29+
30+
@Option(
31+
names = "--tls-allow-ca-clients",
32+
description = "If defined, allows clients authorized by the CA to connect to Ethsigner.",
33+
arity = "0")
34+
private Boolean tlsAllowCaClients = false;
35+
36+
@Override
37+
public Optional<File> getKnownClientsFile() {
38+
return Optional.ofNullable(tlsKnownClientsFile);
39+
}
40+
41+
@Override
42+
public boolean isCaAuthorizedClientAllowed() {
43+
return tlsAllowCaClients;
44+
}
45+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2020 ConsenSys AG.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package tech.pegasys.ethsigner.config;
14+
15+
import tech.pegasys.ethsigner.core.config.PkcsStoreConfig;
16+
17+
import java.io.File;
18+
19+
import picocli.CommandLine.Option;
20+
21+
public class PicoCliDownstreamTrustStore implements PkcsStoreConfig {
22+
23+
@Option(
24+
names = "--downstream-http-tls-truststore-file",
25+
description =
26+
"Path to a PKCS#12 formatted truststore, containing all trusted root certificates.",
27+
arity = "1",
28+
required = true)
29+
private File trustStoreFile;
30+
31+
@Option(
32+
names = "--downstream-http-tls-truststore-password-file",
33+
description = "Path to a file containing the password used to decrypt the truststore.",
34+
arity = "1",
35+
required = true)
36+
private File trustStorePasswordFile;
37+
38+
@Override
39+
public File getStoreFile() {
40+
return trustStoreFile;
41+
}
42+
43+
@Override
44+
public File getStorePasswordFile() {
45+
return trustStorePasswordFile;
46+
}
47+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2020 ConsenSys AG.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package tech.pegasys.ethsigner.config;
14+
15+
import tech.pegasys.ethsigner.core.config.PkcsStoreConfig;
16+
17+
import java.io.File;
18+
19+
import picocli.CommandLine.Option;
20+
21+
public class PicoCliTlsClientCertificateOptions implements PkcsStoreConfig {
22+
23+
@Option(
24+
names = "--downstream-http-tls-keystore-file",
25+
description =
26+
"Path to a PKCS#12 formatted keystore, contains TLS certificate to present to "
27+
+ "a TLS-enabled web3 provider.",
28+
arity = "1",
29+
required = true)
30+
private File clientCertificateFile;
31+
32+
@Option(
33+
names = "--downstream-http-tls-keystore-password-file",
34+
description = "Path to a file containing the password used to decrypt the client cert.",
35+
arity = "1",
36+
required = true)
37+
private File clientCertificatePasswordFile;
38+
39+
@Override
40+
public File getStoreFile() {
41+
return clientCertificateFile;
42+
}
43+
44+
@Override
45+
public File getStorePasswordFile() {
46+
return clientCertificatePasswordFile;
47+
}
48+
}

0 commit comments

Comments
 (0)