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

Implement HSTS fetch step #14716

Merged
merged 1 commit into from Dec 29, 2016
Merged

Implement HSTS fetch step #14716

merged 1 commit into from Dec 29, 2016

Conversation

@nmvk
Copy link
Contributor

nmvk commented Dec 24, 2016

Implemented step nine of the main fetch. If current URL scheme is 'HTTP' and
current URL's host is domain and if current URL's host matched with Known
HSTS Host Domain Name Matching results in either a superdomain match with
an asserted includeSubDomains directive or a congruent match then we
change request scheme to 'https'. This change has been made in method.rs

A test case to validate this has been added in fetch.rs. For asserting
https scheme, a https localhost was required. For this purpose I have
created a self-signed certificate and refactored fetch-context and
connector.rs to programmatically trust this certificate for running this
test case.

This should fix #14363


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #14363
  • There are tests for these changes

This change is Reviewable

@highfive
Copy link

highfive commented Dec 24, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/net/fetch/methods.rs, components/net/resource_thread.rs, components/net/http_loader.rs, components/net/connector.rs
@nmvk nmvk force-pushed the nmvk:hsts branch 2 times, most recently from 8fb4c4d to 24a883c Dec 25, 2016
@nmvk
Copy link
Contributor Author

nmvk commented Dec 25, 2016

Travis failure The command "./mach test-stylo" exited with 101. not due to the current change.

@jdm
Copy link
Member

jdm commented Dec 25, 2016

That's #14723 .

@bors-servo
Copy link
Contributor

bors-servo commented Dec 27, 2016

The latest upstream changes (presumably #14741) made this pull request unmergeable. Please resolve the merge conflicts.

@nmvk nmvk force-pushed the nmvk:hsts branch from 24a883c to e8099df Dec 28, 2016
@nmvk
Copy link
Contributor Author

nmvk commented Dec 28, 2016

I have addressed conflicts. @emilio did you get a chance to review the changes?

@emilio
Copy link
Member

emilio commented Dec 28, 2016

I think @jdm or @Ms2ger are more suited to review this than me.

There should probably be a WPT test or similar for this.

@bors-servo try

@bors-servo
Copy link
Contributor

bors-servo commented Dec 28, 2016

Trying commit e8099df with merge 1ccb92f...

bors-servo added a commit that referenced this pull request Dec 28, 2016
Implement HSTS fetch step

Implemented step nine of the main fetch. If current URL scheme is 'HTTP' and
current URL's host is domain and if current URL's host matched with Known
HSTS Host Domain Name Matching results in either a superdomain match with
an asserted includeSubDomains directive or a congruent match then we
change request scheme to 'https'. This change has been made in method.rs

A test case to validate this has been added in fetch.rs. For asserting
https scheme, a https localhost was required. For this purpose I have
created a self-signed certificate and refactored fetch-context and
connector.rs to programmatically trust this certificate for running this
test case.

This should fix #14363
<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #14363

<!-- Either: -->
- [X] There are tests for these changes

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14716)
<!-- Reviewable:end -->
@emilio
Copy link
Member

emilio commented Dec 28, 2016

@highfive highfive assigned Ms2ger and unassigned emilio Dec 28, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Dec 28, 2016

💔 Test failed - linux-rel-wpt

@nmvk
Copy link
Contributor Author

nmvk commented Dec 28, 2016

Is the test failure due to network issue?

Copy link
Member

emilio left a comment

Seems like the failures may be legit? We can retry to verify it.

Other option would be that that check makes stuff immensely slower, in which case we'd need a faster data-structure for HstsList.

@@ -189,7 +189,15 @@ pub fn main_fetch(request: Rc<Request>,
}

// Step 9
// TODO this step (HSTS)
if request.current_url().scheme() == "http" && request.current_url().domain() != None {

This comment has been minimized.

@emilio

emilio Dec 28, 2016

Member

nit: use request.current_url().domain().is_some()?

@emilio
Copy link
Member

emilio commented Dec 28, 2016

@bors-servo retry

@bors-servo
Copy link
Contributor

bors-servo commented Dec 28, 2016

Trying commit e8099df with merge 35d62a5...

bors-servo added a commit that referenced this pull request Dec 28, 2016
Implement HSTS fetch step

Implemented step nine of the main fetch. If current URL scheme is 'HTTP' and
current URL's host is domain and if current URL's host matched with Known
HSTS Host Domain Name Matching results in either a superdomain match with
an asserted includeSubDomains directive or a congruent match then we
change request scheme to 'https'. This change has been made in method.rs

A test case to validate this has been added in fetch.rs. For asserting
https scheme, a https localhost was required. For this purpose I have
created a self-signed certificate and refactored fetch-context and
connector.rs to programmatically trust this certificate for running this
test case.

This should fix #14363
<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #14363

<!-- Either: -->
- [X] There are tests for these changes

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14716)
<!-- Reviewable:end -->
@emilio
Copy link
Member

emilio commented Dec 28, 2016

IMO the hsts list seems pretty big to use a vec as a backing store, but maybe other people have different opinions.

@nmvk
Copy link
Contributor Author

nmvk commented Dec 28, 2016

Thanks, @emilio, Maybe I could refactor HstsList to use HashSet or HashMap which could provide faster lookup?

@emilio
Copy link
Member

emilio commented Dec 28, 2016

Tests seem green, so it's likely to have been another kind of error. I've opened #14756 to change the underlying storage of the HSTS list. I think it's worth to land that refactoring separately as a followup.

@nmvk nmvk force-pushed the nmvk:hsts branch from e8099df to 8730f09 Dec 28, 2016
@nmvk nmvk force-pushed the nmvk:hsts branch from 8730f09 to d5d9e89 Dec 28, 2016
Copy link
Member

jdm left a comment

Great work!

@@ -0,0 +1,22 @@
-----BEGIN CERTIFICATE-----

This comment has been minimized.

@jdm

jdm Dec 28, 2016

Member

This file should be called self_signed_certificate_for_testing.crt to make its purpose clear ;)

@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----

This comment has been minimized.

@jdm

jdm Dec 28, 2016

Member

This should be called privatekey_for_testing.key.

list.push(HstsEntry::new("localhost".to_owned(), IncludeSubdomains::NotIncluded, None)
.unwrap());
}
let do_fetch = |url: ServoUrl| {

This comment has been minimized.

@jdm

jdm Dec 28, 2016

Member

I don't think having this closure makes the test any more readable, so let's remove it.

fn test_fetch_with_hsts() {
static MESSAGE: &'static [u8] = b"";
let handler = move |_: HyperRequest, response: HyperResponse| {
response.send(MESSAGE).unwrap();

This comment has been minimized.

@jdm

jdm Dec 28, 2016

Member

Let's have the response contain the scheme of the request's URL instead. This will let us verify that the server never receives a non-HTTPS connection.

This comment has been minimized.

@nmvk

nmvk Dec 29, 2016

Author Contributor

If I correctly understand, you want request.url.scheme() to be sent as part of response body?. Here we use hyper::server::request::Request which does not capture information about request scheme. If we make a non-HTTPS connection to the server, then we get response error saying "Connection reset"

This comment has been minimized.

@jdm

jdm Dec 29, 2016

Member

Ah, good point. This test is fine as-is, in that case.

Implemented step nine of the main fetch. If current URL scheme is 'HTTP'
and current URL's host is domain and if current URL's host matched with
Known
HSTS Host Domain Name Matching results in either a superdomain match with
an asserted includeSubDomains directive or a congruent match then we
change request scheme to 'https'. This change has been made in method.rs

A test case to validate this has been added in fetch.rs. For asserting
https scheme, a https localhost was required. For this purpose I have
created a self-signed certificate and refactored fetch-context and
connector.rs to programmatically trust this certificate for running this
test case.
@jdm
Copy link
Member

jdm commented Dec 29, 2016

@bors-servo: r+
Thanks for fixing this and figuring out how to use HTTPS servers in unit tests!

@bors-servo
Copy link
Contributor

bors-servo commented Dec 29, 2016

📌 Commit 6020b4c has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Dec 29, 2016

Testing commit 6020b4c with merge c7991d5...

bors-servo added a commit that referenced this pull request Dec 29, 2016
Implement HSTS fetch step

Implemented step nine of the main fetch. If current URL scheme is 'HTTP' and
current URL's host is domain and if current URL's host matched with Known
HSTS Host Domain Name Matching results in either a superdomain match with
an asserted includeSubDomains directive or a congruent match then we
change request scheme to 'https'. This change has been made in method.rs

A test case to validate this has been added in fetch.rs. For asserting
https scheme, a https localhost was required. For this purpose I have
created a self-signed certificate and refactored fetch-context and
connector.rs to programmatically trust this certificate for running this
test case.

This should fix #14363
<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #14363

<!-- Either: -->
- [X] There are tests for these changes

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14716)
<!-- Reviewable:end -->
@bors-servo bors-servo merged commit 6020b4c into servo:master Dec 29, 2016
2 of 3 checks passed
2 of 3 checks passed
continuous-integration/travis-ci/pr The Travis CI build failed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
homu Test successful
Details
@bors-servo bors-servo mentioned this pull request Dec 29, 2016
4 of 4 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants
You can’t perform that action at this time.