RESOLVED FIXED190956
[WPE][GTK] Certificates loaded from the cache don't include the certificate chain
https://bugs.webkit.org/show_bug.cgi?id=190956
Summary [WPE][GTK] Certificates loaded from the cache don't include the certificate c...
Claudio Saavedra
Reported 2018-10-26 05:51:11 PDT
[WPE][GTK] Certificates loaded from the cache don't include the certificate chain
Attachments
Patch (4.95 KB, patch)
2018-10-26 05:53 PDT, Claudio Saavedra
no flags
Patch (8.27 KB, patch)
2018-10-30 06:02 PDT, Claudio Saavedra
no flags
Patch (8.26 KB, patch)
2018-10-30 08:09 PDT, Claudio Saavedra
no flags
Patch (8.05 KB, patch)
2018-10-30 09:00 PDT, Claudio Saavedra
youennf: review+
Claudio Saavedra
Comment 1 2018-10-26 05:53:52 PDT
Created attachment 353177 [details] Patch I didn't increase the cache version because I am not sure if this change needs it. AFAICT, the loader would load a boolean as integer, which would be interpreted as 1 and then the iteration would try to load only one certificate from the cache.
Claudio Saavedra
Comment 2 2018-10-26 05:55:39 PDT
I also think that at some point it would be interesting to check if we can factor the code to a common place so that both IPC and Cache coders use the same encoding/decoding code/format. Not sure it's needed to have this redundant code in different places. For now, let's fix this though.
Michael Catanzaro
Comment 3 2018-10-26 07:14:01 PDT
Comment on attachment 353177 [details] Patch r=me on the code changes, since this is just syncing the cache coders with the IPC coders that we've now reviewed thoroughly. I'm not sure about the rules for changing the cache coders either, though. I think it does probably need a new cache version, otherwise downgrades could break: old WebKitGTK+ could interpret 3 certificates as a bool true, then read only one certificate, and cache corruption would ensue. And the cache version is shared for all ports, so I fear this needs owner approval to bump the cache version. Let's see what Youenn thinks.
Michael Catanzaro
Comment 4 2018-10-26 07:25:55 PDT
(In reply to Claudio Saavedra from comment #2) > I also think that at some point it would be interesting to check if we can > factor the code to a common place so that both IPC and Cache coders use the > same encoding/decoding code/format. Not sure it's needed to have this > redundant code in different places. For now, let's fix this though. We discussed this is probably to make it easier to make changes to the IPC coders.
Michael Catanzaro
Comment 5 2018-10-26 07:38:38 PDT
Another question: what actually happens to these certificates stored in the cache? Obviously they are not used for anything important, because without the full chain, they have been broken up till now.
youenn fablet
Comment 6 2018-10-26 08:18:02 PDT
Comment on attachment 353177 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=353177&action=review > Source/WebKit/ChangeLog:9 > + the entire certificate chain in the cache coder. Yes, we need to increment NetworkCache::Storage::version. Incrementing the counter is invalidating the whole cache for all users. I wonder whether this is okayish or whether we should introduce two counters, one for cross-platform changes and one for platform-specific changes. John for some other stuff might bump the version for all platforms as well so maybe we do not care. Antti, any suggestion? > Source/WebKit/NetworkProcess/cache/NetworkCacheCodersSoup.cpp:36 > + encoder << 0; Is there a guarantee that this line is always equivalent to below encoding of the vector? I would tend to write it this way: Vector<GRefPtr<GByteArray>> certificatesDataListFromCertificateInfo(const WebCore::CertificateInfo& certificateInfo) { if (!certificate) return { }; ... } void Coder<WebCore::CertificateInfo>::encode(Encoder& encoder, const WebCore::CertificateInfo& certificateInfo) { encoder << certificatesDataListFromCertificateInfo(certificateInfo); } This requires introducing a coder for GRefPtr<GByteArray>. > Source/WebKit/NetworkProcess/cache/NetworkCacheCodersSoup.cpp:69 > { Ditto here, we should be able to do: decoder >> certificateDataList; That way, we are sure that encoding/decoding of the vector is consistent.
Claudio Saavedra
Comment 7 2018-10-26 08:36:29 PDT
Comment on attachment 353177 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=353177&action=review >> Source/WebKit/NetworkProcess/cache/NetworkCacheCodersSoup.cpp:36 >> + encoder << 0; > > Is there a guarantee that this line is always equivalent to below encoding of the vector? > I would tend to write it this way: > Vector<GRefPtr<GByteArray>> certificatesDataListFromCertificateInfo(const WebCore::CertificateInfo& certificateInfo) > { > if (!certificate) > return { }; > ... > } > > void Coder<WebCore::CertificateInfo>::encode(Encoder& encoder, const WebCore::CertificateInfo& certificateInfo) > { > encoder << certificatesDataListFromCertificateInfo(certificateInfo); > } > > This requires introducing a coder for GRefPtr<GByteArray>. GRefPtr<GByteArray> or just GByteArray?
Michael Catanzaro
Comment 8 2018-10-26 08:49:13 PDT
(In reply to youenn fablet from comment #6) > Yes, we need to increment NetworkCache::Storage::version. > Incrementing the counter is invalidating the whole cache for all users. > I wonder whether this is okayish or whether we should introduce two > counters, one for cross-platform changes and one for platform-specific > changes. > John for some other stuff might bump the version for all platforms as well > so maybe we do not care. > Antti, any suggestion? It's the first time I remember having to do this, and I don't expect it to happen again anytime soon. So perhaps we should just remember to land this whenever you next need to bump the cache version.
Claudio Saavedra
Comment 9 2018-10-26 09:00:57 PDT
(In reply to Michael Catanzaro from comment #8) > So perhaps we should just remember to land this > whenever you next need to bump the cache version. Eh, no. Actually as it is the certificate chain for a resource loaded from the cache or from the network are different. From WK's pov it might not matter, but the WKGTK/WPE API will have inconsistent certificate info depending on whether a webview was loaded from the cache or the network. So I think we need to fix this before 2.24.
Michael Catanzaro
Comment 10 2018-10-26 09:44:36 PDT
OK, good point. Then let's try to coordinate this bump with Antti and John.
youenn fablet
Comment 11 2018-10-26 12:23:20 PDT
> GRefPtr<GByteArray> or just GByteArray? Not sure, GRefPtr<GByteArray> will work. You might be able to do like optional, see PersistentCoders.h
Claudio Saavedra
Comment 12 2018-10-30 06:02:17 PDT
Created attachment 353363 [details] Patch Let's try again.
youenn fablet
Comment 13 2018-10-30 07:56:07 PDT
Comment on attachment 353363 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=353363&action=review > Source/WebKit/NetworkProcess/cache/NetworkCacheCodersSoup.cpp:62 > + for (uint32_t i = 0; i < certificatesDataList.size(); i++) { for (auto& certificateData : certificatesDataList) or remove the reverse above and decrement the counter here. > Source/WebKit/NetworkProcess/cache/NetworkCacheCodersSoup.cpp:85 > + decoder.decode(certificatesDataList); We should probably check the returned value here. > Source/WebKit/NetworkProcess/cache/NetworkCacheCodersSoup.cpp:116 > + byteArray = adoptGRef(g_byte_array_append(bytes, vector.data(), vector.size())); We do two memory allocations. Is GByteArray allowing to make only one?
Claudio Saavedra
Comment 14 2018-10-30 08:07:21 PDT
Comment on attachment 353363 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=353363&action=review >> Source/WebKit/NetworkProcess/cache/NetworkCacheCodersSoup.cpp:116 >> + byteArray = adoptGRef(g_byte_array_append(bytes, vector.data(), vector.size())); > > We do two memory allocations. Is GByteArray allowing to make only one? Not sure I understand. There's only one allocation, afaik (the new() call). g_byte_array_append() doesn't add a reference.
Claudio Saavedra
Comment 15 2018-10-30 08:09:55 PDT
youenn fablet
Comment 16 2018-10-30 08:10:20 PDT
(In reply to Claudio Saavedra from comment #14) > Comment on attachment 353363 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=353363&action=review > > >> Source/WebKit/NetworkProcess/cache/NetworkCacheCodersSoup.cpp:116 > >> + byteArray = adoptGRef(g_byte_array_append(bytes, vector.data(), vector.size())); > > > > We do two memory allocations. Is GByteArray allowing to make only one? > > Not sure I understand. There's only one allocation, afaik (the new() call). > g_byte_array_append() doesn't add a reference. There is the Vector<allocation> and then the GByteArray allocation. I am not sure whether it is feasible to just have one allocation here.
Claudio Saavedra
Comment 17 2018-10-30 08:24:57 PDT
Comment on attachment 353363 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=353363&action=review >>>> Source/WebKit/NetworkProcess/cache/NetworkCacheCodersSoup.cpp:116 >>>> + byteArray = adoptGRef(g_byte_array_append(bytes, vector.data(), vector.size())); >>> >>> We do two memory allocations. Is GByteArray allowing to make only one? >> >> Not sure I understand. There's only one allocation, afaik (the new() call). g_byte_array_append() doesn't add a reference. > > There is the Vector<allocation> and then the GByteArray allocation. > I am not sure whether it is feasible to just have one allocation here. I see. One can pass the data without reallocating it but then it will eventually be freed with g_free(). I'm not sure if that will match whatever Vector is using to allocate memory.
Claudio Saavedra
Comment 18 2018-10-30 09:00:29 PDT
Created attachment 353373 [details] Patch Okay, this should do it. Let's get rid of the need for a Vector and decode directly into the GByteArray.
Michael Catanzaro
Comment 19 2018-10-30 10:41:02 PDT
Comment on attachment 353373 [details] Patch Should these be synced with the IPC coders now?
Claudio Saavedra
Comment 20 2018-10-30 11:32:30 PDT
I don't think that's necessary. These are entirely independent implementations. We could improve the other one though but that's a story for another day..
youenn fablet
Comment 21 2018-10-30 12:06:46 PDT
Comment on attachment 353373 [details] Patch LGTM, it would be good to have another LGTM from soup side. As of the refactoring for sharing with IPC, maybe a templated encode/decode routine could be added to CertificateInfo directly. Some unit test might be feasible, especially if that was a source of issues in the past. View in context: https://bugs.webkit.org/attachment.cgi?id=353373&action=review > Source/WebKit/NetworkProcess/cache/NetworkCacheCodersSoup.cpp:90 > + certificateInfo.setCertificate(certificateFromCertificatesDataList(certificatesDataList).get()); Should setCertificate take a GRefPtr<>&&?
Michael Catanzaro
Comment 22 2018-10-30 19:21:04 PDT
(In reply to youenn fablet from comment #21) > LGTM, it would be good to have another LGTM from soup side. LGTM
Claudio Saavedra
Comment 23 2018-10-31 00:29:30 PDT
Note You need to log in before you can comment on or make changes to this bug.