You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "neils-dev (via GitHub)" <gi...@apache.org> on 2023/03/22 21:34:25 UTC

[GitHub] [ozone] neils-dev commented on a diff in pull request #4427: HDDS-8177. Persist all certificates in bundle into service metadata directory.

neils-dev commented on code in PR #4427:
URL: https://github.com/apache/ozone/pull/4427#discussion_r1145431139


##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/client/DefaultCertificateClient.java:
##########
@@ -503,6 +505,56 @@ public void storeCertificate(String pemEncodedCert,
         certificateCodec, true);
   }
 
+  /**
+   * Stores all Certificates in this response on local disk.
+   * @param response - response from SCM
+   * @return first certificate ID
+   * @throws CertificateException - on Error
+   */
+  public String storeCertificate(SCMGetCertResponseProto response)

Review Comment:
   Thanks @ChenSammi for this patch as part of supporting scm primordial node decommissioning.  
   We can add "@ Override" annotation to implementation of `storeCertificate`.



##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/client/DefaultCertificateClient.java:
##########
@@ -503,6 +505,56 @@ public void storeCertificate(String pemEncodedCert,
         certificateCodec, true);
   }
 
+  /**
+   * Stores all Certificates in this response on local disk.
+   * @param response - response from SCM
+   * @return first certificate ID
+   * @throws CertificateException - on Error
+   */
+  public String storeCertificate(SCMGetCertResponseProto response)
+      throws CertificateException {
+    return storeCertificate(response,
+        getSecurityConfig().getCertificateLocation(getComponentName()));
+  }
+
+  protected String storeCertificate(SCMGetCertResponseProto response,
+      Path codecPath) throws CertificateException {
+    CertificateCodec certCodec = new CertificateCodec(securityConfig,
+        codecPath);
+    try {
+      String pemEncodedCert = response.getX509Certificate();

Review Comment:
   Should we check for the certificate here, similar to `if (response.hasX509Certificate()) {} else { throw new CertificateException("Unable to retrieve ...` ?



##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/client/DefaultCertificateClient.java:
##########
@@ -503,6 +505,56 @@ public void storeCertificate(String pemEncodedCert,
         certificateCodec, true);
   }
 
+  /**
+   * Stores all Certificates in this response on local disk.
+   * @param response - response from SCM
+   * @return first certificate ID
+   * @throws CertificateException - on Error
+   */
+  public String storeCertificate(SCMGetCertResponseProto response)
+      throws CertificateException {
+    return storeCertificate(response,
+        getSecurityConfig().getCertificateLocation(getComponentName()));
+  }
+
+  protected String storeCertificate(SCMGetCertResponseProto response,
+      Path codecPath) throws CertificateException {
+    CertificateCodec certCodec = new CertificateCodec(securityConfig,
+        codecPath);
+    try {
+      String pemEncodedCert = response.getX509Certificate();
+      if (!response.hasX509RootCACertificate()) {
+        throw new CertificateException("Unable to find SCM root certificate");
+      }
+      String pemEncodedRootCert = response.getX509RootCACertificate();
+      X509Certificate rootCert =
+          CertificateCodec.getX509Certificate(pemEncodedRootCert);
+      CertPath path =
+          CertificateCodec.getCertPathFromPemEncodedString(pemEncodedCert);
+      for (Certificate c: path.getCertificates()) {
+        X509Certificate cert = (X509Certificate) c;
+        CAType caType = CAType.NONE;
+        if (cert.getBasicConstraints() != -1) {
+          if (rootCert.getSerialNumber().toString().equals(
+              cert.getSerialNumber().toString())) {
+            caType = CAType.ROOT;
+          } else {
+            caType = CAType.SUBORDINATE;
+          }
+        }
+        String certName = String.format(CERT_FILE_NAME_FORMAT,
+            caType.getFileNamePrefix() + cert.getSerialNumber().toString());
+        certCodec.writeCertificate(
+            CertificateCodec.getCertificateHolder(cert), certName);
+      }
+      return ((X509Certificate)path.getCertificates().get(0))

Review Comment:
   Q. is the first certificate in the list the "default" certificate?  similar to :
   
   >  // Return the default certificate ID



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org