aswinshakil commented on a change in pull request #3027:
URL: https://github.com/apache/ozone/pull/3027#discussion_r796988483



##########
File path: 
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconServer.java
##########
@@ -129,6 +166,108 @@ public Void call() throws Exception {
     return null;
   }
 
+  /**
+   * Initializes secure Recon.
+   * */
+  private void initializeCertificateClient(OzoneConfiguration conf)
+      throws IOException {
+    LOG.info("Initializing secure Recon.");
+    certClient = new ReconCertificateClient(
+        new SecurityConfig(configuration),
+        reconStorage.getReconCertSerialId());
+
+    CertificateClient.InitResponse response = certClient.init();
+    LOG.info("Init response: {}", response);
+    switch (response) {
+    case SUCCESS:
+      LOG.info("Initialization successful, case:{}.", response);
+      break;
+    case GETCERT:
+      getSCMSignedCert(conf);
+      LOG.info("Successfully stored SCM signed certificate, case:{}.",
+          response);
+      break;
+    case FAILURE:
+      LOG.error("Recon security initialization failed, case:{}.", response);
+      throw new RuntimeException("Recon security initialization failed.");
+    case RECOVER:
+      LOG.error("Recon security initialization failed. Recon certificate is " +
+          "missing.");
+      throw new RuntimeException("Recon security initialization failed.");
+    default:
+      LOG.error("Recon security initialization failed. Init response: {}",
+          response);
+      throw new RuntimeException("Recon security initialization failed.");
+    }
+  }
+
+  /**
+   * Get SCM signed certificate and store it using certificate client.
+   * @param config
+   * */
+  private void getSCMSignedCert(OzoneConfiguration config) {
+    try {
+      PKCS10CertificationRequest csr = getCSR(config);
+      SCMSecurityProtocolClientSideTranslatorPB secureScmClient =
+          HddsServerUtil.getScmSecurityClientWithMaxRetry(config);
+      HddsProtos.ReconDetailsProto.Builder reconDetailsProtoBuilder =
+          HddsProtos.ReconDetailsProto.newBuilder()
+              .setHostName(InetAddress.getLocalHost().getHostName())
+              .setClusterId(reconStorage.getClusterID())
+              .setUuid(reconStorage.getReconId());
+
+      SCMSecurityProtocolProtos.SCMGetCertResponseProto response =
+          secureScmClient.getReconCertificateChain(
+              reconDetailsProtoBuilder.build(),
+              getEncodedString(csr));
+      // Persist certificates.
+      if(response.hasX509CACertificate()) {
+        String pemEncodedCert = response.getX509Certificate();
+        certClient.storeCertificate(pemEncodedCert, true);
+        certClient.storeCertificate(response.getX509CACertificate(), true,
+            true);
+
+        // Store Root CA certificate.
+        if (response.hasX509RootCACertificate()) {
+          certClient.storeRootCACertificate(
+              response.getX509RootCACertificate(), true);
+        }
+        String reconCertSerialId = getX509Certificate(pemEncodedCert).
+            getSerialNumber().toString();
+        reconStorage.setReconCertSerialId(reconCertSerialId);
+      } else {
+        throw new RuntimeException("Unable to retrieve recon certificate " +
+            "chain");
+      }
+    } catch (IOException | CertificateException e) {
+      LOG.error("Error while storing SCM signed certificate.", e);
+      throw new RuntimeException(e);
+    }
+  }
+
+  /**
+   * Creates CSR for Recon.
+   * @param config
+   * */
+  private PKCS10CertificationRequest getCSR(OzoneConfiguration config)

Review comment:
       Sure, I'll add this as a utility method.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to