Skip to content

Allow to verify if an error code is valid for CertificateVerifier#260

Closed
normanmaurer wants to merge 1 commit intomasterfrom
err_valid
Closed

Allow to verify if an error code is valid for CertificateVerifier#260
normanmaurer wants to merge 1 commit intomasterfrom
err_valid

Conversation

@normanmaurer
Copy link
Copy Markdown
Member

Motivation:

CertificateVerifier allows to return an errorCode. We should have a static method to validate that the error code that may be returned is valid.

Modifications:

  • Make CertificateVerifier an abstract class and add method to check if errorCode is valid.

Result:

Easier way to validate if errorCode is valid.

@normanmaurer
Copy link
Copy Markdown
Member Author

@Scottmitch PTAL... I will check if I can add a unit test for this easily here

<maven.deploy.skip>true</maven.deploy.skip>

<!-- Skip tests for now as there is something wrong with the static build for openssl when running on macOS -->
<skipTests>true</skipTests>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@Scottmitch I will investigate in this as a separate issue. Not super urgent tho as we not publish static builds for openssl anyway

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Can be removed once #261 is merged :)

</activation>
<properties>
<!-- Skip tests on windows as its not easy to load the openssl library we link against in the tests -->
<skipTests>true</skipTests>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@Scottmitch there may be a way to fix this, but I am a bit short on time and would love to merge this first. We can do a followup if needed

Copy link
Copy Markdown
Member

@Scottmitch Scottmitch left a comment

Choose a reason for hiding this comment

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

2 comments on the unit test then lgtm

do {
errorCode++;
Assert.assertTrue(errorCode < Integer.MAX_VALUE);
} while (CertificateVerifier.isValid(errorCode));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this seems like a roundabout way to do:

assertFalse(CertificateVerifier.isValid(Integer.MIN_VALUE));

Can we simplify this test?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

sure... just let us hope this one will never be valid ;)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is the intention of this test? To prove that at least 1 negative value is invalid? Seems strange in general. If we are just trying to demonstrate there is at least 1 error code that is not valid we have a few options:

  • create some private markers to indicate "highest" and "lowest" valid value and use these in the test. Negative of this approach is we have to worry about updating these just for testing.
  • make the set package private, sort all the values, and pick a value not in the set.
  • randomly choose values until we find one which is not in the set and make sure its not valid.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yeah that it not always return true. Maybe using Integer.MIN_VALUE is good enough as you said.

for (Field field : fields) {
if (field.isAccessible()) {
int errorCode = field.getInt(null);
Assert.assertTrue(CertificateVerifier.isValid(errorCode));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

add a string description which shows what number errorCode is missing.

Set<Integer> errors = new HashSet<Integer>();
errors.add(X509_V_OK);
errors.add(X509_V_ERR_UNSPECIFIED);
errors.add(X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about just using reflection to get the fields start with X509_V_ERR (and X509_V_OK)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@trustin I was considering this but did not do because of jdk9 and secruitymanagers. Reflection may be disallowed. This is why I added the test-case which will fail if we miss to at stuff to the map.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

jdk9 and secruitymanagers

Really? I thought there's no security restriction on accessing the fields that belong to itself reflectively?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am not sure :) Better be safe then sorry and like I said we will catch it with the unit test anyway.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm fine with that although I still believe it's gonna be fine. :-)

Motivation:

CertificateVerifier allows to return an errorCode. We should have a static method to validate that the error code that may be returned is valid.

Modifications:

- Make CertificateVerifier an abstract class and add method to check if errorCode is valid.

Result:

Easier way to validate if errorCode is valid.
@normanmaurer
Copy link
Copy Markdown
Member Author

Cherry-picked into master after addressing @Scottmitch s comments

@normanmaurer normanmaurer deleted the err_valid branch March 31, 2017 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants