|
66 | 66 | import static org.hyperledger.fabric.sdk.helper.Utils.parseGrpcUrl;
|
67 | 67 |
|
68 | 68 | class Endpoint {
|
| 69 | + public static final String CLIENT_CERT_FILE = "clientCertFile"; |
| 70 | + public static final String CLIENT_KEY_FILE = "clientKeyFile"; |
| 71 | + public static final String CLIENT_CERT_BYTES = "clientCertBytes"; |
| 72 | + public static final String CLIENT_KEY_BYTES = "clientKeyBytes"; |
| 73 | + |
69 | 74 | private static final Log logger = LogFactory.getLog(Endpoint.class);
|
70 | 75 |
|
71 | 76 | private static final String SSLPROVIDER = Config.getConfig().getDefaultSSLProvider();
|
@@ -172,28 +177,28 @@ class Endpoint {
|
172 | 177 | }
|
173 | 178 | // check for mutual TLS - both clientKey and clientCert must be present
|
174 | 179 | byte[] ckb = null, ccb = null;
|
175 |
| - if (properties.containsKey("clientKeyFile") && properties.containsKey("clientKeyBytes")) { |
| 180 | + if (properties.containsKey(CLIENT_KEY_FILE) && properties.containsKey(CLIENT_KEY_BYTES)) { |
176 | 181 | throw new RuntimeException("Properties \"clientKeyFile\" and \"clientKeyBytes\" must cannot both be set");
|
177 |
| - } else if (properties.containsKey("clientCertFile") && properties.containsKey("clientCertBytes")) { |
| 182 | + } else if (properties.containsKey(CLIENT_CERT_FILE) && properties.containsKey(CLIENT_CERT_BYTES)) { |
178 | 183 | throw new RuntimeException("Properties \"clientCertFile\" and \"clientCertBytes\" must cannot both be set");
|
179 |
| - } else if (properties.containsKey("clientKeyFile") || properties.containsKey("clientCertFile")) { |
180 |
| - if ((properties.getProperty("clientKeyFile") != null) && (properties.getProperty("clientCertFile") != null)) { |
| 184 | + } else if (properties.containsKey(CLIENT_KEY_FILE) || properties.containsKey(CLIENT_CERT_FILE)) { |
| 185 | + if ((properties.getProperty(CLIENT_KEY_FILE) != null) && (properties.getProperty(CLIENT_CERT_FILE) != null)) { |
181 | 186 | try {
|
182 |
| - logger.trace(format("Endpoint %s reading clientKeyFile: %s", url, properties.getProperty("clientKeyFile"))); |
183 |
| - ckb = Files.readAllBytes(Paths.get(properties.getProperty("clientKeyFile"))); |
184 |
| - logger.trace(format("Endpoint %s reading clientCertFile: %s", url, properties.getProperty("clientCertFile"))); |
185 |
| - ccb = Files.readAllBytes(Paths.get(properties.getProperty("clientCertFile"))); |
| 187 | + logger.trace(format("Endpoint %s reading clientKeyFile: %s", url, properties.getProperty(CLIENT_KEY_FILE))); |
| 188 | + ckb = Files.readAllBytes(Paths.get(properties.getProperty(CLIENT_KEY_FILE))); |
| 189 | + logger.trace(format("Endpoint %s reading clientCertFile: %s", url, properties.getProperty(CLIENT_CERT_FILE))); |
| 190 | + ccb = Files.readAllBytes(Paths.get(properties.getProperty(CLIENT_CERT_FILE))); |
186 | 191 | } catch (IOException e) {
|
187 | 192 | throw new RuntimeException("Failed to parse TLS client key and/or cert", e);
|
188 | 193 | }
|
189 | 194 | } else {
|
190 |
| - throw new RuntimeException("Properties \"clientKeyFile\" and \"clientCertFile\" must both be set or both be null"); |
| 195 | + throw new RuntimeException(String.format("Properties \"%s\" and \"%s\" must both be set or both be null", CLIENT_KEY_FILE, CLIENT_CERT_FILE)); |
191 | 196 | }
|
192 |
| - } else if (properties.containsKey("clientKeyBytes") || properties.containsKey("clientCertBytes")) { |
193 |
| - ckb = (byte[]) properties.get("clientKeyBytes"); |
194 |
| - ccb = (byte[]) properties.get("clientCertBytes"); |
| 197 | + } else if (properties.containsKey(CLIENT_KEY_BYTES) || properties.containsKey(CLIENT_CERT_BYTES)) { |
| 198 | + ckb = (byte[]) properties.get(CLIENT_KEY_BYTES); |
| 199 | + ccb = (byte[]) properties.get(CLIENT_CERT_BYTES); |
195 | 200 | if ((ckb == null) || (ccb == null)) {
|
196 |
| - throw new RuntimeException("Properties \"clientKeyBytes\" and \"clientCertBytes\" must both be set or both be null"); |
| 201 | + throw new RuntimeException(String.format("Properties \"%s\" and \"%s\" must both be set or both be null", CLIENT_KEY_BYTES, CLIENT_CERT_BYTES)); |
197 | 202 | }
|
198 | 203 | }
|
199 | 204 |
|
@@ -400,28 +405,28 @@ AbstractMap.SimpleImmutableEntry<PrivateKey, X509Certificate[]> getClientTLSProp
|
400 | 405 |
|
401 | 406 | // check for mutual TLS - both clientKey and clientCert must be present
|
402 | 407 | byte[] ckb = null, ccb = null;
|
403 |
| - if (properties.containsKey("clientKeyFile") && properties.containsKey("clientKeyBytes")) { |
| 408 | + if (properties.containsKey(CLIENT_KEY_FILE) && properties.containsKey(CLIENT_KEY_BYTES)) { |
404 | 409 | throw new RuntimeException("Properties \"clientKeyFile\" and \"clientKeyBytes\" must cannot both be set");
|
405 |
| - } else if (properties.containsKey("clientCertFile") && properties.containsKey("clientCertBytes")) { |
| 410 | + } else if (properties.containsKey(CLIENT_CERT_FILE) && properties.containsKey(CLIENT_CERT_BYTES)) { |
406 | 411 | throw new RuntimeException("Properties \"clientCertFile\" and \"clientCertBytes\" must cannot both be set");
|
407 |
| - } else if (properties.containsKey("clientKeyFile") || properties.containsKey("clientCertFile")) { |
408 |
| - if ((properties.getProperty("clientKeyFile") != null) && (properties.getProperty("clientCertFile") != null)) { |
| 412 | + } else if (properties.containsKey(CLIENT_KEY_FILE) || properties.containsKey(CLIENT_CERT_FILE)) { |
| 413 | + if ((properties.getProperty(CLIENT_KEY_FILE) != null) && (properties.getProperty(CLIENT_CERT_FILE) != null)) { |
409 | 414 | try {
|
410 |
| - logger.trace(format("Endpoint %s reading clientKeyFile: %s", url, new File(properties.getProperty("clientKeyFile")).getAbsolutePath())); |
411 |
| - ckb = Files.readAllBytes(Paths.get(properties.getProperty("clientKeyFile"))); |
412 |
| - logger.trace(format("Endpoint %s reading clientCertFile: %s", url, new File(properties.getProperty("clientCertFile")).getAbsolutePath())); |
413 |
| - ccb = Files.readAllBytes(Paths.get(properties.getProperty("clientCertFile"))); |
| 415 | + logger.trace(format("Endpoint %s reading clientKeyFile: %s", url, new File(properties.getProperty(CLIENT_KEY_FILE)).getAbsolutePath())); |
| 416 | + ckb = Files.readAllBytes(Paths.get(properties.getProperty(CLIENT_KEY_FILE))); |
| 417 | + logger.trace(format("Endpoint %s reading clientCertFile: %s", url, new File(properties.getProperty(CLIENT_CERT_FILE)).getAbsolutePath())); |
| 418 | + ccb = Files.readAllBytes(Paths.get(properties.getProperty(CLIENT_CERT_FILE))); |
414 | 419 | } catch (IOException e) {
|
415 | 420 | throw new RuntimeException("Failed to parse TLS client key and/or cert", e);
|
416 | 421 | }
|
417 | 422 | } else {
|
418 |
| - throw new RuntimeException("Properties \"clientKeyFile\" and \"clientCertFile\" must both be set or both be null"); |
| 423 | + throw new RuntimeException(String.format("Properties \"%s\" and \"%s\" must both be set or both be null", CLIENT_KEY_FILE, CLIENT_CERT_FILE)); |
419 | 424 | }
|
420 |
| - } else if (properties.containsKey("clientKeyBytes") || properties.containsKey("clientCertBytes")) { |
421 |
| - ckb = (byte[]) properties.get("clientKeyBytes"); |
422 |
| - ccb = (byte[]) properties.get("clientCertBytes"); |
| 425 | + } else if (properties.containsKey(CLIENT_KEY_BYTES) || properties.containsKey(CLIENT_CERT_BYTES)) { |
| 426 | + ckb = (byte[]) properties.get(CLIENT_KEY_BYTES); |
| 427 | + ccb = (byte[]) properties.get(CLIENT_CERT_BYTES); |
423 | 428 | if ((ckb == null) || (ccb == null)) {
|
424 |
| - throw new RuntimeException("Properties \"clientKeyBytes\" and \"clientCertBytes\" must both be set or both be null"); |
| 429 | + throw new RuntimeException(String.format("Properties \"%s\" and \"%s\" must both be set or both be null", CLIENT_KEY_BYTES, CLIENT_CERT_BYTES)); |
425 | 430 | }
|
426 | 431 | }
|
427 | 432 |
|
|
0 commit comments