Skip to content
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

Fix missing OID mappings #997

Merged
merged 2 commits into from
Mar 14, 2024
Merged

Conversation

fmarco76
Copy link
Member

Pretty print some additional OID:

OCSP No Check - id-pkix-ocsp-nocheck { 1.3.6.1.5.5.7.48.1.5} Inhibit Any Policy {2.5.29.54}
Extended Key Usage:

  • serverAuth {1 3 6 1 5 5 7 3 1}
  • clientAuth {1 3 6 1 5 5 7 3 2}
  • codeSigning {1 3 6 1 5 5 7 3 3}
  • emailProtection {1 3 6 1 5 5 7 3 4}

@fmarco76 fmarco76 requested a review from edewata March 11, 2024 15:38
@fmarco76
Copy link
Member Author

Sonar does not like the name convention for OID_OCSPSigning and the new added entries because of the case. They are consistent among them and the one already present are used in pki code. We can update all of them and update pki after the merge. @edewata can we go ahead and change them in the master for both?

Copy link
Contributor

@edewata edewata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some comments, but we can address that in a separate PR. Feel free to merge the PR as is.

We can certainly fix the constant names, but to avoid breaking existing code we should deprecate them first, then drop the old constants in a future release.

{ 1, 3, 6, 1, 5, 5, 7, 3, 4 };
public static final ObjectIdentifier OID_EMAIL_PROTECTION = new
ObjectIdentifier(OID_EMAIL_PROTECTION_STR);

public static final int OID_CODE_SIGNING_STR[] =
{ 1, 3, 6, 1, 5, 5, 7, 3, 3 };
public static final ObjectIdentifier OID_CODE_SIGNING = new
ObjectIdentifier(OID_OCSP_SIGNING_STR);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an existing code, but I think it should be OID_CODE_SIGNING_STR instead of OID_OCSP_SIGNING_STR. I wonder why we never see a problem caused by this bug.

@ladycfu ^^

public static final int OID_EMAIL_PROTECTION_STR[] =
{ 1, 3, 6, 1, 5, 5, 7, 3, 4 };
public static final ObjectIdentifier OID_EMAIL_PROTECTION = new
ObjectIdentifier(OID_EMAIL_PROTECTION_STR);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid similar bugs we probably should not define the OID multiple times. I'm thinking we can just define this object like this:

public static final ObjectIdentifier OID_EMAIL_PROTECTION = \
    new ObjectIdentifier("1.3.6.1.5.5.7.3.4");

Then if we need the String OID we can just call OID_EMAIL_PROTECTION.toString() or something like that.

We should also deprecate the existing OID_OCSPSigning and OID_CODESigning.

@@ -94,9 +96,12 @@ public class OIDMap {

public static final String EXT_KEY_USAGE_NAME = "ExtendedKeyUsageExtension";
public static final String EXT_INHIBIT_ANY_POLICY_NAME = "InhibitAnyPolicyExtension";
private static final String EXT_INHIBIT_ANY_POLICY = ROOT + "." + InhibitAnyPolicyExtension.NAME;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note that the InhibitAnyPolicyExtension.NAME is actually pointing back to EXT_INHIBIT_ANY_POLICY_NAME. We probably should move EXT_INHIBIT_ANY_POLICY_NAME into InhibitAnyPolicyExtension.NAME later.

@@ -132,6 +137,8 @@ private static void loadNamesDefault(Properties props) {
props.put(AUTH_KEY_IDENTIFIER, "2.5.29.35");
props.put(SUBJ_DIR_ATTR, "2.5.29.9");
props.put(EXT_KEY_USAGE, "2.5.29.37");
props.put(EXT_INHIBIT_ANY_POLICY, "2.5.29.54");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This OID is already defined in InhibitAnyPolicyExtension.OID. Should we use that instead?

@@ -132,6 +137,8 @@ private static void loadNamesDefault(Properties props) {
props.put(AUTH_KEY_IDENTIFIER, "2.5.29.35");
props.put(SUBJ_DIR_ATTR, "2.5.29.9");
props.put(EXT_KEY_USAGE, "2.5.29.37");
props.put(EXT_INHIBIT_ANY_POLICY, "2.5.29.54");
props.put(OCSP_NO_CHECK, "1.3.6.1.5.5.7.48.1.5");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also already defined in OCSPNoCheckExtension.OID. Should we use that one?

Comment on lines 176 to 179
props.put(EXT_INHIBIT_ANY_POLICY,
"org.mozilla.jss.netscape.security.extensions.InhibitAnyPolicyExtension");
props.put(OCSP_NO_CHECK,
"org.mozilla.jss.netscape.security.extensions.OCSPNoCheckExtension");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To ensure that the class names and packages are correct we probably should use InhibitAnyPolicyExtension.class.getName() and OCSPNoCheckExtension.class.getName().

@fmarco76
Copy link
Member Author

@edewata I have just read in RHCS-4883 about other OIDs which are not printed. I'll incorporate these other OID and reorganise this code for better maintainability. Moving this PR to draft for the moment. Thanks

@fmarco76 fmarco76 marked this pull request as draft March 12, 2024 09:45
Pretty print some additional OID:

OCSP No Check - id-pkix-ocsp-nocheck { 1.3.6.1.5.5.7.48.1.5}
Inhibit Any Policy {2.5.29.54}
Extended Key Usage:
- serverAuth {1 3 6 1 5 5 7 3 1}
- clientAuth {1 3 6 1 5 5 7 3 2}
- codeSigning {1 3 6 1 5 5 7 3 3}
- emailProtection {1 3 6 1 5 5 7 3 4}
- id-kp-ipsecIKE {1 3 6 1 5 5 7 3 17}
- iKEIntermediate {1 3 6 1 5 5 8 2 2}
@fmarco76 fmarco76 force-pushed the FixMissOIDPrint branch 4 times, most recently from 416fe84 to 4854289 Compare March 13, 2024 18:03
@fmarco76 fmarco76 requested a review from edewata March 13, 2024 18:13
@fmarco76
Copy link
Member Author

@edewata I have reorganised the code and going deeply I found the real reason some of the extension were not shown. There was a static code which was never invoked when used with PrettyPrintCert because the extension class was never loaded. The reference to the class were resolved at compile time since they are static final. I have moved the loading code to a different place and it works with PrettyPrintCert and it should work with PKI since OIDMap is always loaded to access the maps.

There is a problem with postgresql but it is also in other PR. We can investigate in a separate PR.

@fmarco76 fmarco76 marked this pull request as ready for review March 13, 2024 18:35
Copy link
Contributor

@edewata edewata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update! I have some more comments but the changes look good. Feel free to update/merge.

Comment on lines 482 to 505
if (oid.equals(ExtendedKeyUsageExtension.OID_IKE_INTERMEDIATE)) {
sb.append(pp.indent(mIndentSize + 8) + "ipsec Intermediate System Usage" +
" - " + oid.toString() + "\n");
} else if (oid.equals(ExtendedKeyUsageExtension.OID_ID_KP_IPSEC_IKE)) {
sb.append(pp.indent(mIndentSize + 8) + "ipsec Internet Key Exchange" +
" - " + oid.toString() + "\n");
} else if (oid.equals(ExtendedKeyUsageExtension.OID_OCSP_SIGNING)) {
sb.append(pp.indent(mIndentSize + 8) + "OCSPSigning" +
" - " + oid.toString() + "\n");
} else if (oid.equals(ExtendedKeyUsageExtension.OID_EMAIL_PROTECTION)) {
sb.append(pp.indent(mIndentSize + 8) + "emailProtection" +
" - " + oid.toString() + "\n");
} else if (oid.equals(ExtendedKeyUsageExtension.OID_CODE_SIGNING)) {
sb.append(pp.indent(mIndentSize + 8) + "codeSigning" +
" - " + oid.toString() + "\n");
} else if (oid.equals(ExtendedKeyUsageExtension.OID_CLIENT_AUTH)) {
sb.append(pp.indent(mIndentSize + 8) + "clientAuth" +
" - " + oid.toString() + "\n");
} else if (oid.equals(ExtendedKeyUsageExtension.OID_SERVER_AUTH)) {
sb.append(pp.indent(mIndentSize + 8) + "serverAuth" +
" - " + oid.toString() + "\n");
} else {
sb.append(pp.indent(mIndentSize + 8) + oid.toString() + "\n");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The toString() is redundant since it's implicitly called during string concatenation.

@@ -131,43 +143,28 @@ private static void loadNamesDefault(Properties props) {
props.put(CERT_POLICIES, "2.5.29.32");
props.put(AUTH_KEY_IDENTIFIER, "2.5.29.35");
props.put(SUBJ_DIR_ATTR, "2.5.29.9");
props.put(EXT_KEY_USAGE, "2.5.29.37");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm, so the EXT_KEY_USAGE doesn't need to be specified here anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ExtendedKeyUsageExtension class was adding itself here. I have not investigated there reason but it is like adding this extension whatever is the map. However, this code was not executed so I moved in the static block of the OIDMap with the addClass() method.

Comment on lines -167 to -168
props.put(EXT_KEY_USAGE,
"org.mozilla.jss.netscape.security.extensions.ExtendedKeyUsageExtension");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing, so the EXT_KEY_USAGE doesn't need to be specified here anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same anwer.

Static code inside the extension is not loaded by PrettyPrintCert because
only static final values of the class are referenced and these values are
resolved at compile time.

The static initialisation has moved from static block in the extension
to the OIDMap static block which is the class loaded at runtime.

Useless OID string from ExtendedKeyUsageExtension has been removed from previous
commit and existing OIDs (ocsp signing and code signing) have been deprecated.
Copy link

@fmarco76
Copy link
Member Author

@edewata Thanks! I have just remove the useless toString() before merge.

@fmarco76 fmarco76 merged commit 5ecb67d into dogtagpki:master Mar 14, 2024
34 of 35 checks passed
@fmarco76 fmarco76 deleted the FixMissOIDPrint branch March 14, 2024 10:05
@fmarco76 fmarco76 mentioned this pull request May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants