Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upDelegate resource reading to embedder #20533
Conversation
highfive
commented
Apr 4, 2018
|
Heads up! This PR modifies the following files:
|
1cc07ad
to
48f2222
|
Note to self:
|
|
eb91969 fixes the sandboxing issues. |
|
Tested on Android and Mac. Sandboxing has been tested too. |
|
@mbrubeck r? |
|
(fixed the Windows failure) |
| buffer | ||
| } | ||
| fn sandbox_access_files_rec(&self) -> Vec<PathBuf> { | ||
| vec![resources_dir_path().expect("Can't find resources directory")] |
This comment has been minimized.
This comment has been minimized.
mbrubeck
Apr 18, 2018
Contributor
If this just returns paths to top-level directories (rather than recursively iterating over the files inside those directories), maybe it should be renamed to sandox_access_files_dirs.
| @@ -1740,11 +1741,11 @@ fn get_root_flow_background_color(flow: &mut Flow) -> webrender_api::ColorF { | |||
| fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> { | |||
| fn parse_ua_stylesheet( | |||
| shared_lock: &SharedRwLock, | |||
| filename: &'static str, | |||
| filename: &str, | |||
| content: String, | |||
This comment has been minimized.
This comment has been minimized.
mbrubeck
Apr 18, 2018
Contributor
This could take Vec<u8> or &[u8] instead, and then the callers could use read_bytes instead of read_string to avoid needless UTF-8 validation.
|
Looks good overall. Some minor suggestions/concerns below. |
| path.push(file); | ||
| let mut buffer = vec![]; | ||
| File::open(path).expect(&format!("Can't find file: {}", file)) | ||
| .read_to_end(&mut buffer).expect("Can't read file"); |
This comment has been minimized.
This comment has been minimized.
mbrubeck
Apr 18, 2018
Contributor
This could use the new std::fs::read which pre-allocates a buffer.
| let mut txt = String::new(); | ||
| let mut file = File::open(PathBuf::from(path)) | ||
| .expect("Couldn't not find certificate file"); | ||
| file.read_to_string(&mut txt).expect("Cant read certificate"); |
This comment has been minimized.
This comment has been minimized.
| ssl_connector_builder.set_ca_file(ca_file).expect("could not set CA file"); | ||
| loop { | ||
| if let Some(index) = certs.rfind("-----BEGIN CERTIFICATE-----") { | ||
| let cert = certs.split_off(index); |
This comment has been minimized.
This comment has been minimized.
mbrubeck
Apr 18, 2018
Contributor
We could avoid allocating and copying here, by keeping cert as &str instead of String, and doing:
let (cert, rest) = certs.split_at(i);
certs = rest;| } | ||
| }).expect("could not set CA file"); | ||
| } else { | ||
| break; |
This comment has been minimized.
This comment has been minimized.
mbrubeck
Apr 18, 2018
Contributor
It looks like this might skip the last certificate in the file, because it's not followed by a BEGIN CERTIFICATE line.
This comment has been minimized.
This comment has been minimized.
| let mut ssl_connector_builder = SslConnectorBuilder::new(SslMethod::tls()).unwrap(); | ||
| ssl_connector_builder.set_ca_file(ca_file).expect("could not set CA file"); |
This comment has been minimized.
This comment has been minimized.
mbrubeck
Apr 18, 2018
Contributor
Maybe we should add a function to the openssl crate that takes the certificate file contents as a string. Then we could continue to let OpenSSL do the parsing here.
This comment has been minimized.
This comment has been minimized.
paulrouget
Apr 20, 2018
Author
Contributor
It already has a method to parse the whole certs file, but it's a "all or non" operation (not like the previous method we were passing a file instead of a buffer). If it fails to load one of the certificate, they are all rejected. And in our case, it might fail because some certificates were already registered (so it's fine to ignore the error). So if we were to improve the Rust OpenSSL API, we should allow OpenSSL to ignore the duplicate error.
I can file a bug for that. Sounds to me that it's a OpenSSL issue, not a Rust OpenSSL problem though.
|
(comments addressed) |
|
@bors-servo r+ |
|
|
Delegate resource reading to embedder Now the embedder provides the content of the files itself. Now, on Android, we can use regular assets instead of unzipping all the resources on the scared at startup. --- <!-- 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 - [ ] `./mach build-geckolib` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15635 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- 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/20533) <!-- Reviewable:end -->
|
|
Delegate resource reading to embedder Now the embedder provides the content of the files itself. Now, on Android, we can use regular assets instead of unzipping all the resources on the scared at startup. --- <!-- 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 - [ ] `./mach build-geckolib` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15635 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- 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/20533) <!-- Reviewable:end -->
|
|
|
@bors-servo retry
|
|
|
|
@bors-servo retry force |
|
|
|
|
|
Sorry again @paulrouget, Homu was sitting on its hands doing nothing. @bors-servo p=1 |
|
|
|
|
|
@paulrouget CI is still a bit foobar'd. Please don't retry this, I'll do it myself once I know it can build without constant attention. |
|
@bors-servo r=mbrubeck |
|
|
|
Delegate resource reading to embedder Now the embedder provides the content of the files itself. Now, on Android, we can use regular assets instead of unzipping all the resources on the scared at startup. --- <!-- 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 - [ ] `./mach build-geckolib` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15635 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- 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/20533) <!-- Reviewable:end -->
|
|
paulrouget commentedApr 4, 2018
•
edited
Now the embedder provides the content of the files itself. Now, on Android, we can use regular assets instead of unzipping all the resources on the scared at startup.
./mach build -ddoes not report any errors./mach build-geckolibdoes not report any errors./mach test-tidydoes not report any errorsThis change is