1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
/* -*- indent-tabs-mode: nil -*- */
#include "client/http_log_client.h"
#include <event2/buffer.h>
#include <glog/logging.h>
#include <functional>
#include <memory>
#include "log/cert.h"
#include "proto/ct.pb.h"
#include "proto/serializer.h"
#include "util/json_wrapper.h"
#include "util/util.h"
namespace libevent = cert_trans::libevent;
using cert_trans::AsyncLogClient;
using cert_trans::Cert;
using cert_trans::CertChain;
using cert_trans::HTTPLogClient;
using cert_trans::PreCertChain;
using cert_trans::ThreadPool;
using ct::MerkleAuditProof;
using ct::SignedCertificateTimestamp;
using ct::SignedTreeHead;
using std::bind;
using std::placeholders::_1;
using std::string;
using std::unique_ptr;
using std::vector;
using util::Status;
using util::StatusOr;
namespace {
void DoneRequest(AsyncLogClient::Status status, AsyncLogClient::Status* retval,
bool* done) {
*retval = status;
*done = true;
}
} // namespace
HTTPLogClient::HTTPLogClient(const string& server)
: base_(new libevent::Base()),
pool_(),
fetcher_(base_.get(), &pool_),
client_(base_.get(), &fetcher_, server) {
}
StatusOr<SignedCertificateTimestamp> HTTPLogClient::UploadSubmission(
const string& submission, bool pre) {
SignedCertificateTimestamp sct;
AsyncLogClient::Status status(AsyncLogClient::UNKNOWN_ERROR);
bool done(false);
if (pre) {
PreCertChain pre_cert_chain(submission);
client_.AddPreCertChain(pre_cert_chain, &sct,
bind(&DoneRequest, _1, &status, &done));
} else {
CertChain cert_chain(submission);
client_.AddCertChain(cert_chain, &sct,
bind(&DoneRequest, _1, &status, &done));
}
while (!done) {
base_->DispatchOnce();
}
if (status == AsyncLogClient::OK) {
return sct;
}
return Status::UNKNOWN;
}
StatusOr<SignedTreeHead> HTTPLogClient::GetSTH() {
SignedTreeHead sth;
AsyncLogClient::Status status(AsyncLogClient::UNKNOWN_ERROR);
bool done(false);
client_.GetSTH(&sth, bind(&DoneRequest, _1, &status, &done));
while (!done) {
base_->DispatchOnce();
}
if (status == AsyncLogClient::OK) {
return sth;
}
return Status::UNKNOWN;
}
StatusOr<vector<unique_ptr<Cert>>> HTTPLogClient::GetRoots() {
vector<unique_ptr<Cert>> roots;
AsyncLogClient::Status status(AsyncLogClient::UNKNOWN_ERROR);
bool done(false);
client_.GetRoots(&roots, bind(&DoneRequest, _1, &status, &done));
while (!done) {
base_->DispatchOnce();
}
if (status == AsyncLogClient::OK) {
return move(roots);
}
return Status::UNKNOWN;
}
StatusOr<MerkleAuditProof> HTTPLogClient::QueryAuditProof(
const string& merkle_leaf_hash) {
const StatusOr<SignedTreeHead> sth(GetSTH());
if (!sth.status().ok()) {
return sth.status();
}
MerkleAuditProof proof;
AsyncLogClient::Status status(AsyncLogClient::UNKNOWN_ERROR);
bool done(false);
client_.QueryInclusionProof(sth.ValueOrDie(), merkle_leaf_hash, &proof,
bind(&DoneRequest, _1, &status, &done));
while (!done) {
base_->DispatchOnce();
}
if (status == AsyncLogClient::OK) {
return proof;
}
return Status::UNKNOWN;
}
StatusOr<vector<AsyncLogClient::Entry>> HTTPLogClient::GetEntries(int first,
int last) {
vector<AsyncLogClient::Entry> entries;
AsyncLogClient::Status status(AsyncLogClient::UNKNOWN_ERROR);
bool done(false);
client_.GetEntries(first, last, &entries,
bind(&DoneRequest, _1, &status, &done));
while (!done) {
base_->DispatchOnce();
}
if (status == AsyncLogClient::OK) {
return move(entries);
}
return Status::UNKNOWN;
}
StatusOr<vector<string>> HTTPLogClient::GetSTHConsistency(int64_t size1,
int64_t size2) {
vector<string> proof;
AsyncLogClient::Status status(AsyncLogClient::UNKNOWN_ERROR);
bool done(false);
client_.GetSTHConsistency(size1, size2, &proof,
bind(&DoneRequest, _1, &status, &done));
while (!done) {
base_->DispatchOnce();
}
if (status == AsyncLogClient::OK) {
return proof;
}
return Status::UNKNOWN;
}
|