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