Skip to content

Improve handling of errors - #227

Merged
jsha merged 5 commits into
mainfrom
fix_is_cert_error
Nov 15, 2021
Merged

jsha merged 5 commits into
mainfrom
fix_is_cert_error

Conversation

@jsha

@jsha jsha commented Nov 14, 2021

Copy link
Copy Markdown
Collaborator

There were still three places where we could have undefined behavior if
C gave us an invalid rustls_result:

  • rustls_result_is_cert_error took a rustls_result as a parameter.
  • The callback for server certificate validation returned
    rustls_result.
  • The callbacks for session storage returned rustls_result.

Change all of these to use u32 and the try_from implementation.

Fix the comment for the session storage callbacks, which indicated the
wrong error strategy.

Remove result_to_error in favor of directly implementing Display on
rustls_result. This fixes an issue where CertInvalidData was turned into
Either::String rather than Either::Error, which caused
rustls_result_is_cert_error to (incorrectly) say it wasn't a cert error.
This PR also removes the Either struct and the From impls on it.

Fixes #226

There were still three places where we could have undefined behavior if
C gave us an invalid rustls_result:

 - rustls_result_is_cert_error took a rustls_result as a parameter.
 - The callback for server certificate validation returned
   rustls_result.
 - The callbacks for session storage returned rustls_result.

Change all of these to use u32 and the try_from implementation.

Fix the comment for the session storage callbacks, which indicated the
wrong error strategy.

Remove result_to_error in favor of directly implementing Display on
rustls_result. This fixes an issue where CertInvalidData was turned into
Either::String rather than Either::Error, which caused
rustls_result_is_cert_error to (incorrectly) say it wasn't a cert error.
This PR also removes the Either struct and the From impls on it.
@jsha
jsha requested a review from djc November 14, 2021 22:56
Comment thread src/error.rs Outdated
}
}

/// For cert-related resutl_results, turn them into a rustls::Error. For other

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

rustls_results

Comment thread src/error.rs Outdated
CorruptMessagePayload => write!(f, "received corrupt message"),

PeerIncompatibleError => write!(f, "peer is incompatible"),
PeerMisbehavedError => write!(f, "peer is incompatible"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy paste?

@kevinburke

Copy link
Copy Markdown
Contributor

Looks OK to me, should we update the changelog now vs. later?

@jsha

jsha commented Nov 15, 2021

Copy link
Copy Markdown
Collaborator Author

We should update the CHANGELOG as part of the PR - I'll push a commit with that later on.

@djc

djc commented Nov 15, 2021

Copy link
Copy Markdown
Member

Seems okay to me.

@jsha
jsha merged commit 40d302b into main Nov 15, 2021
@jsha
jsha deleted the fix_is_cert_error branch November 15, 2021 23:03
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.

Update rustls_result_is_cert_error to include InvalidCertificateData

3 participants