fapifta commented on code in PR #12114:
URL: https://github.com/apache/ozone/pull/12114#discussion_r4720702959
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/authority/DefaultApprover.java:
##########
@@ -87,6 +88,22 @@ public DefaultApprover(PKIProfile pkiProfile, SecurityConfig
config) {
this.securityConfig = Objects.requireNonNull(config);
}
+ @SuppressWarnings("ParameterNumber")
+ @Override
+ public X509Certificate sign(
Review Comment:
If we do not preserve backward compatibility which we does not need to, then
this method is also unnecessary. It is not a real issue now, but if we add an
other override (which we shouldn't), then this becomes quite easily a mess, the
interface method will remain there, so if someone carelessly just adds a
parameter to the next method, leaves this method as is, then anyone who calls
this method will run into an infinite recursion.
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/authority/CertificateServer.java:
##########
@@ -96,6 +96,20 @@ Future<CertPath> requestCertificate(
CertificateApprover.ApprovalType type, NodeType role,
String certSerialId) throws SCMSecurityException;
+ /**
+ * Like {@link #requestCertificate(PKCS10CertificationRequest,
CertificateApprover.ApprovalType, NodeType, String)},
+ * with the commonName to issue instead of the CSR's when that is longer
than RFC 5280 ub-common-name.
+ * The default ignores {@code commonNameIfTooLong}, so an implementation
without this method still works.
+ *
+ * @param commonNameIfTooLong - commonName for a CSR commonName longer than
64 characters, or null to keep it.
+ */
+ default Future<CertPath> requestCertificate(
Review Comment:
Same applies here as with CertificateApprover#sign. This is an internal
interface, there is no need to keep backward compatibility here either.
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/authority/DefaultCAServer.java:
##########
@@ -211,6 +211,14 @@ public Future<CertPath> requestCertificate(
PKCS10CertificationRequest csr,
CertificateApprover.ApprovalType approverType, NodeType role,
String certSerialId) {
+ return requestCertificate(csr, approverType, role, certSerialId, null);
+ }
+
+ @Override
+ public Future<CertPath> requestCertificate(
Review Comment:
Same goes to here as to the DefaultApprover's sign overrides.
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/authority/DefaultApprover.java:
##########
@@ -135,6 +154,12 @@ public X509Certificate sign(
toASN1Primitive().toString();
String cn = x500Name.getRDNs(BCStyle.CN)[0].getFirst().getValue()
.toASN1Primitive().toString();
+ if (commonNameIfTooLong != null && cn.length() > MAX_COMMON_NAME_LENGTH) {
Review Comment:
I am not sure I understand correctly, but the problem statement says:
> Since the Bouncy Castle 1.85 upgrade
([HDDS-15974](https://issues.apache.org/jira/browse/HDDS-15974)), new
X500Name(String) throws when the commonName (CN) is longer than 64 characters
Now if this is true, then I am not sure how the X500Name we get here can
store a string that is longer than the MAX_COMMON_NAME_LENGTH. Can you please
elaborate?
My understanding is that the approver at this point gets a
CertificateSignRequest from the clients, the clients should not be able to
construct the X500Name in the first place as it would throw at CSR creation
already.
All in all I think we may check this here, but we can not do a substitution
on behalf of the client as the server should not decide on an alternative
common name in itself.
I see that this is called from test code, but the test code should not test
this here, it may test whether a CSR containing a long CN is rejected properly,
but that is it, our clients should never send a CN that is long, and that seems
to be enough... isn't it?
If I am right here, then potentially we do not need the whole
commonNameIfTooLong piece on the server side at all, just a rejection if
something like that arrives via the CSR, as a forged CSR might not be built
according to BC's standards and as BC may fail on that and ruins the server
side, we need to handle it, but we should not replace it, instead we should
make sure valid clients send in a proper CN. What do you think?
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/authority/CertificateApprover.java:
##########
@@ -66,6 +66,32 @@ X509Certificate sign(
String certSerialId)
throws IOException, CertificateException;
+ /**
+ * Like {@link #sign(SecurityConfig, PrivateKey, X509Certificate, Date,
Date, PKCS10CertificationRequest, String,
+ * String, String)}, with the commonName to use instead of the CSR's when
that is longer than RFC 5280
+ * ub-common-name, as in a CSR from a client that predates
+ * {@link
org.apache.hadoop.hdds.security.x509.certificate.utils.CertificateSignRequest#commonName}.
+ * The default ignores {@code commonNameIfTooLong}, so an implementation
without this method still works.
+ *
+ * @param commonNameIfTooLong - commonName for a CSR commonName longer than
64 characters, or null to keep it.
+ */
+ @SuppressWarnings("ParameterNumber")
+ default X509Certificate sign(
Review Comment:
CertificateApprover is an internal interface that should not be used
elsewhere. I have seen copilot suggesting to change this in a backward
compatible way, but imho this is just unnecessary clutter as no outside
implementors should depend on this interface.
--
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]