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

verification: enable ip subj. validation on android. #28

Merged
merged 1 commit into from
Aug 31, 2023

Conversation

cpu
Copy link
Member

@cpu cpu commented Aug 30, 2023

While the Android verifier defers to the platform verifier for most certificate validation options, it relies on webpki for ensuring that a certificate is valid for a given subject name. Since Webpki v0.100.x it's been possible to use webpki to validate IP address subject names, and so we want this capability to be enabled for the Android verifier.

This commit updates the Android verifier to accomplish this. Additionally it enables the mock IP address subject test cases in the mock test suite to ensure things work as expected.

In order to support this change the function signature of the inner Verifier.verify_certificate fn has to change from accepting a &str server name, to also accepting the &rustls::ServerName that the trait based ServerCertVerifier.verify_server_cert was already accepting. There are two main reasons for this:

  1. If we try to pull out a String to pass forward from the rustls::ServerName::IpAddress(&IpAddr) using IpAddr.to_string() we'll get back a "compressed" address for IPv6 addresses. This is problematic when later trying to convert to a webpki::IpAddrRef for the validation call using IpAddrRef::try_from_ascii_str, because it doesn't support the compressed form.
  2. By passing through the rustls::ServerName directly we can defer the actual process of interacting with webpki to the newly exposed rustls::client::verify_server_name fn offered with the dangerous_configuration feature. This will ensure the logic for name validation is applied consistently between Rustls and the platform verifier. It also allows removing the Android specific pki_name_error helper, and the Android target's usage of the general crate::verification::invalid_certificate helper.

Resolves #15

@cpu cpu self-assigned this Aug 30, 2023
@cpu cpu force-pushed the cpu-15-android-ip-subj-verification branch from 7e1f5c5 to bd4668b Compare August 30, 2023 20:49
@cpu cpu force-pushed the cpu-15-android-ip-subj-verification branch 2 times, most recently from ea7097b to 043c62a Compare August 31, 2023 14:48
Copy link
Collaborator

@complexspaces complexspaces left a comment

Choose a reason for hiding this comment

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

This ended up much easier then I expected based on when I last tried this, so this is great to see. I wonder if your first point about compressed IPv6 addresses was what was messing this up in the last attempt, since I think that I did try roundtripping it through string parsing.

src/tests/verification_mock/mod.rs Outdated Show resolved Hide resolved
src/verification/android.rs Show resolved Hide resolved
src/verification/android.rs Outdated Show resolved Hide resolved
While the Android verifier defers to the platform verifier for most
certificate validation options, it relies on `webpki` for ensuring that
a certificate is valid for a given subject name. Since Webpki v0.100.x
it's been possible to use `webpki` to validate IP address subject names,
and so we want this capability to be enabled for the Android verifier.

This commit updates the Android `verifier` to accomplish this.
Additionally it enables the mock IP address subject test cases in the
mock test suite to ensure things work as expected.

In order to support this change the function signature of the inner
`Verifier.verify_certificate` fn has to change from accepting a `&str`
server name, to also accepting the `&rustls::ServerName` that the trait
based `ServerCertVerifier.verify_server_cert` was already accepting.
There are two main reasons for this:

1. If we try to pull out a `String` to pass forward from the
   `rustls::ServerName::IpAddress(&IpAddr)` using `IpAddr.to_string()`
   we'll get back a "compressed" address for IPv6 addresses. This is
   problematic when later trying to convert to a `webpki::IpAddrRef` for
   the validation call using `IpAddrRef::try_from_ascii_str`, because it
   doesn't support the compressed form.
2. By passing through the `rustls::ServerName` directly we can defer the
   actual process of interacting with `webpki` to the newly exposed
   `rustls::client::verify_server_name` fn offered with the
   `dangerous_configuration` feature. This will ensure the logic for
   name validation is applied consistently between Rustls and the
   platform verifier.
@cpu cpu force-pushed the cpu-15-android-ip-subj-verification branch from 043c62a to a02ff32 Compare August 31, 2023 16:38
Copy link
Collaborator

@complexspaces complexspaces left a comment

Choose a reason for hiding this comment

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

This looks good to go now, LGTM.

@cpu
Copy link
Member Author

cpu commented Aug 31, 2023

Thanks for all the help :-)

@cpu cpu merged commit b25faa4 into rustls:main Aug 31, 2023
11 checks passed
@cpu cpu deleted the cpu-15-android-ip-subj-verification branch August 31, 2023 17:40
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.

Support IP Address verification on Android
3 participants