Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Side by Side Diff: components/certificate_transparency/log_proof_fetcher.h

Issue 1222953002: Certificate Transparency: Add STH Fetching capability. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing review comments Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_
6 #define COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "net/url_request/url_request.h"
16
17 namespace base {
18 class Value;
19 } // namespace base
20
21 namespace net {
22
23 class URLRequestContext;
24
25 namespace ct {
26 struct SignedTreeHead;
27 } // namespace ct
28
29 } // namespace net
30
31 class GURL;
32
33 namespace certificate_transparency {
34
35 // Fetches Signed Tree Heads (STHs) and consistency proofs from Certificate
36 // Transparency logs using the URLRequestContext provided during the instance
37 // construction.
mmenke 2015/08/03 18:18:54 Should mention here, or above the constructor, tha
Eran Messeri 2015/08/04 16:15:43 Done.
38 class LogProofFetcher : public net::URLRequest::Delegate {
39 public:
40 // Callback for successful retrieval of Signed Tree Heads. Called
41 // with the log_id of the log the STH belogs to (as supplied by the caller
42 // to FetchSignedTreeHead) and the STH itself.
43 using SignedTreeHeadFetchedCallback =
44 base::Callback<void(const std::string& log_id,
45 const net::ct::SignedTreeHead& signed_tree_head)>;
46
47 // Callback for failure of Signed Tree Head retrieval. Called with the log_id
48 // that the log fetching was requested for and a net error code of the
49 // failure.
50 using FetchFailedCallback = base::Callback<
51 void(const std::string& log_id, int net_error, int http_response_code)>;
52
53 explicit LogProofFetcher(net::URLRequestContext* request_context);
54 ~LogProofFetcher() override;
55
56 // Fetch the latest Signed Tree Head from the log identified by |log_id|
57 // from |base_log_url|. The |log_id| will be passed into the callbacks to
58 // identify the log the retrieved Signed Tree Head belongs to.
59 // It is possible, but does not make a lot of sense, to have multiple
60 // Signed Tree Head fetching requests going out to the same log, since
61 // they are likely to return the same result.
mmenke 2015/08/03 18:18:54 Maybe mention that callbacks won't be invoked if d
Eran Messeri 2015/08/04 16:15:43 Done.
62 // TODO(eranm): Think further about whether multiple requests to the same
63 // log imply cancellation of previous requests, should be coalesced or handled
64 // independently.
65 void FetchSignedTreeHead(
66 const GURL& base_log_url,
67 const std::string& log_id,
68 const SignedTreeHeadFetchedCallback& fetched_callback,
69 const FetchFailedCallback& failed_callback);
70
71 // net::URLRequest::Delegate
72 void OnResponseStarted(net::URLRequest* request) override;
73 void OnReadCompleted(net::URLRequest* request, int bytes_read) override;
74
75 private:
76 struct FetchState {
77 FetchState(const std::string& id,
mmenke 2015/08/03 18:18:54 suggest calling this log_id to match the correspon
Eran Messeri 2015/08/04 16:15:42 Done.
78 const SignedTreeHeadFetchedCallback& fetched_callback,
79 const FetchFailedCallback& failed_callback);
80 ~FetchState();
81
82 std::string log_id;
83 SignedTreeHeadFetchedCallback fetched_callback;
84 FetchFailedCallback failed_callback;
85 scoped_refptr<net::IOBufferWithSize> response_buffer;
mmenke 2015/08/03 18:18:54 Need to include ref_counted.h in this file instead
Eran Messeri 2015/08/04 16:15:43 Good point, I've moved back to having a forward de
86 std::string assembled_response;
87 };
88
89 // Handles the result of a URLRequest::Read call on |request|.
mmenke 2015/08/03 18:18:54 the result -> the final result / the non-ERR_IO_PE
Eran Messeri 2015/08/04 16:15:43 Changed to "the final result". I didn't go into mu
90 // Returns true if another read should be started, false if the read
91 // failed completely or we have to wait for OnResponseStarted to
92 // be called.
93 bool HandleReadResult(net::URLRequest* request,
94 FetchState* params,
95 int bytes_read);
96
97 // Calls URLRequest::Read on |request| repeatedly, until HandleReadResult
98 // indicates it should no longer be called. Usually this would be when there
99 // is pending IO that requires waiting for OnResponseStarted to be called.
100 void StartNextRead(net::URLRequest* request, FetchState* params);
101
102 // Performs post-report cleanup.
103 void RequestComplete(net::URLRequest* request);
104 // Deletes the request and associated FetchState from the internal map.
105 void CleanupRequest(net::URLRequest* request);
106
107 // Callbacks for parsing the STH's JSON by the SafeJsonParser
108 void OnSTHJsonParseSuccess(net::URLRequest* request,
109 scoped_ptr<base::Value> parsed_json);
110 void OnSTHJsonParseError(net::URLRequest* request, const std::string& error);
111
112 net::URLRequestContext* const request_context_;
113
114 // Owns the contained requests, as well as FetchState.
115 std::map<net::URLRequest*, FetchState*> inflight_requests_;
116
117 base::WeakPtrFactory<LogProofFetcher> weak_factory_;
118
119 DISALLOW_COPY_AND_ASSIGN(LogProofFetcher);
120 };
121
122 } // namespace certificate_transparency
123
124 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698