xiaoyuyao commented on a change in pull request #574: HDDS-1119. DN get OM certificate from SCM CA for block token validation. URL: https://github.com/apache/hadoop/pull/574#discussion_r264441255
########## File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/client/DefaultCertificateClient.java ########## @@ -159,6 +210,51 @@ public X509Certificate getCertificate() { return x509Certificate; } + /** + * Returns the certificate with the specified certificate serial id if it + * exists else throws CertificateException. + * @param certSerialId + * + * @return certificate or Null if there is no data. + */ + @Override + public X509Certificate getCertificateFromLocal(String certSerialId) + throws CertificateException { + // Check if it is in cache. + if (certificateMap.containsKey(certSerialId)) { + return certificateMap.get(certSerialId); + } + + throw new CertificateException("Certificate with certSerialId:" + + certSerialId + " not found.", CERTIFICATE_NOT_FOUND_ERROR); + } + + /** + * Get certificate from SCM and store it in local file system. + * @param certSerialId + * @return certificate + */ + @Override + public X509Certificate getCertificateFromScm(String certSerialId) + throws CertificateException { + + getLogger().info("Getting certificate with certSerialId:{}.", + certSerialId); + try { + SCMSecurityProtocol scmSecurityProtocolClient = getScmSecurityClient( + (OzoneConfiguration) securityConfig.getConfiguration()); + String pemEncodedCert = + scmSecurityProtocolClient.getCertificate(certSerialId); + this.storeCertificate(pemEncodedCert, true, false); + return CertificateCodec.getX509Certificate(pemEncodedCert); Review comment: should we update the certificateMap here after store it? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org