-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8296143: CertAttrSet's set/get mechanism is not type-safe #10959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
👋 Welcome back weijun! A progress list of the required criteria for merging this PR into |
Webrevs
|
|
In fact, setter methods in all extensions can be removed since they are only called inside tests. |
src/java.base/share/classes/java/security/cert/X509CertSelector.java
Outdated
Show resolved
Hide resolved
src/java.base/share/classes/sun/security/provider/certpath/DistributionPointFetcher.java
Outdated
Show resolved
Hide resolved
|
Way easier to read. Amazing work! |
| "CertAttrSet: CertificateX509Key."); | ||
| } | ||
| public PublicKey getKey() { | ||
| return(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return(key); | |
| return key; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I was just copying lines from the old get method. Will fix.
| * This interface defines a certificate attribute that can be DER-encoded. | ||
| */ | ||
| public interface CertAttrSet<T> { | ||
| public interface CertAttrSet { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we rename this to "CertAttr" since I think it now supports a single attribute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it only has encode now, I'll merge it with DerEncoder and remove it in my next step. Therefore I haven't cared about giving it a better name. I had thought about including the merge inside this change but there are a lot of s/derEncode/encode/ renaming and it's better to be done separately.
seanjmullan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff, just a few minor comments.
| */ | ||
| public byte[] getIssuerAsBytes() throws IOException { | ||
| return (issuer == null ? null: issuer.getEncoded()); | ||
| return issuer == null ? null: issuer.getEncoded(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, add space between "null" and ":".
| String n = oid.toString(); | ||
| KnownOIDs os = KnownOIDs.findMatch(n); | ||
| return (os == null? n : os.stdName()); | ||
| return os == null? n : os.stdName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: add space between "null" and "?".
| case GeneralNameInterface.NAME_NARROWS: | ||
| /* base is descendant of test */ | ||
| return (test.subtreeDepth()-base.subtreeDepth()); | ||
| return test.subtreeDepth()-base.subtreeDepth(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: add spaces around "-".
| info.set(X509CertInfo.SUBJECT, | ||
| dname==null?req.getSubjectName():new X500Name(dname)); | ||
| info.setKey(new CertificateX509Key(req.getSubjectPublicKeyInfo())); | ||
| info.setSubject(dname==null?req.getSubjectName():new X500Name(dname)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add spaces between "?" and ":".
| "CertAttrSet:CertificatePoliciesExtension."); | ||
| } | ||
| public List<PolicyInformation> getCertPolicies() { | ||
| //XXXX May want to consider cloning this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove this comment. This method is internal and as long as the List is not exposed via a public API (please double-check), a clone is not necessary.
| "CertAttrSet:ExtendedKeyUsageExtension."); | ||
| } | ||
| public Vector<ObjectIdentifier> getUsages() { | ||
| //XXXX May want to consider cloning this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comment if returned Vector cannot be accessed via public APIs.
|
@wangweij This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 72 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
|
/integrate |
|
Going to push as commit 671f84b.
Your commit was automatically rebased without conflicts. |
The major change is to remove the
getandsetmethods in variousCertAttrSetchild classes and change them tosetXyzandgetXyzmethods. TheXyzwords might come from the field name or the attribute name. For example,X509CertInfonow hassetExtensionsandsetValidityinstead ofset("extensions", exts)andset("validity", validity). This also has the benefit to remove a lot of try-catch blocks onIOExceptions on "unknown attributes" because everything is known now. At the same time, all the identifier name and attribute names are removed fromCertAttrSetchild classes. The only left isNAMEin extensions since it's still used as keys inCertificateExtensions.Besides assigning a new value to an internal field, the original
setmethods might also re-encode by callingencodeThis, invalidate the cached encoding (inX509CertInfo), or check for read-only flag (inX509CertImp). Newly addedsetXyzmethods are doing the same. This is one place that future new setter methods should remember.Most
getimplementations simply return an internal field. One exception inX509CertImplis that when getting something inside theX509CertInfo, it wraps exceptions into a newCertificateParsingException. This is actually related to the wayCertificateExtensions::getis implemented where an exception is thrown when an extension does not exist.CertificateExtensions::getExtensionhas been rewritten to follow theCRLExtensions::getExtensionstyle wherenullis returned in this case.The only method left in
CertAttrSetisencode, and it no longer throws aCertificateException.Several classes do have their attributes, and still has get/set methods. This includes
CertificateExtensions,CRLExtensions,ReasonFlags,KeyUsageExtension, andNetscapeCertTypeExtensions. Some methods are renamed to be clearer. For example, inCertificateExtensions, we havegetExtensioninstead ofget.There are no more
AttributeNameEnumeration.javaandX509AttributeName.java.Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/10959/head:pull/10959$ git checkout pull/10959Update a local copy of the PR:
$ git checkout pull/10959$ git pull https://git.openjdk.org/jdk pull/10959/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 10959View PR using the GUI difftool:
$ git pr show -t 10959Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/10959.diff