CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
server_tool.cc
Go to the documentation of this file.
1 
5 #include "server_tool.h"
6 
7 #include "util/posix.h"
8 
10 
13  signature_manager_->Fini();
14  }
15 }
16 
17 bool ServerTool::InitDownloadManager(const bool follow_redirects,
18  const std::string &proxy,
19  const unsigned max_pool_handles) {
20  if (download_manager_.IsValid()) {
21  return true;
22  }
23 
24  download_manager_ = new download::DownloadManager(max_pool_handles,
25  perf::StatisticsTemplate("download", statistics()));
27 
29  download_manager_->SetRetryParameters(kDownloadRetries, 2000, 5000);
30  download_manager_->UseSystemCertificatePath();
31 
32  if (proxy != "") {
33  download_manager_->SetProxyChain(proxy, "",
35  }
36 
37  if (follow_redirects) {
38  download_manager_->EnableRedirects();
39  }
40 
41  return true;
42 }
43 
44 bool ServerTool::InitVerifyingSignatureManager(const std::string &pubkey_path) {
46  return true;
47  }
48 
51  signature_manager_->Init();
52 
53  if (!signature_manager_->LoadPublicRsaKeys(pubkey_path)) {
54  LogCvmfs(kLogCvmfs, kLogStderr, "failed to load public repo key '%s'",
55  pubkey_path.c_str());
56  return false;
57  }
58 
59  return true;
60 }
61 
63  const std::string &certificate_path, const std::string &private_key_path,
64  const std::string &private_key_password) {
66  return true;
67  }
68 
71  signature_manager_->Init();
72 
73  // Load certificate
74  if (!signature_manager_->LoadCertificatePath(certificate_path)) {
75  LogCvmfs(kLogCvmfs, kLogStderr, "failed to load certificate '%s'",
76  certificate_path.c_str());
77  return false;
78  }
79 
80  // Load private key
81  if (!signature_manager_->LoadPrivateKeyPath(private_key_path,
82  private_key_password)) {
83  LogCvmfs(kLogCvmfs, kLogStderr, "failed to load private key '%s' (%s)",
84  private_key_path.c_str(),
85  signature_manager_->GetCryptoError().c_str());
86  return false;
87  }
88 
89  if (!signature_manager_->KeysMatch()) {
91  "the private key '%s' doesn't seem to match certificate '%s' (%s)",
92  private_key_path.c_str(), certificate_path.c_str(),
93  signature_manager_->GetCryptoError().c_str());
94  signature_manager_->UnloadPrivateKey();
95  return false;
96  }
97 
98  return true;
99 }
100 
103  return download_manager_.weak_ref();
104 }
105 
108  return signature_manager_.weak_ref();
109 }
110 
112  const std::string path) const {
113  return manifest::Manifest::LoadFile(path);
114 }
115 
117  const std::string &repository_url, const std::string &repository_name,
118  manifest::ManifestEnsemble *ensemble) const {
119  const uint64_t minimum_timestamp = 0;
120  const shash::Any *base_catalog = NULL;
121  return manifest::Fetch(repository_url, repository_name, minimum_timestamp,
122  base_catalog, signature_manager(), download_manager(),
123  ensemble);
124 }
125 
127  const std::string &repository_url, const std::string &repository_name,
128  const shash::Any &base_hash) const {
129  manifest::ManifestEnsemble manifest_ensemble;
131 
132  // fetch (and verify) the manifest
134  repository_url, repository_name, &manifest_ensemble);
135 
136  if (retval != manifest::kFailOk) {
138  "failed to fetch repository manifest "
139  "(%d - %s)",
140  retval, manifest::Code2Ascii(retval));
141  return NULL;
142  } else {
143  // copy-construct a fresh manifest object because ManifestEnsemble will
144  // free manifest_ensemble.manifest when it goes out of scope
145  manifest = new manifest::Manifest(*manifest_ensemble.manifest);
146  }
147 
148  // check if manifest fetching was successful
149  if (!manifest.IsValid()) {
150  LogCvmfs(kLogCvmfs, kLogStderr, "failed to load repository manifest");
151  return NULL;
152  }
153 
154  // check the provided base hash of the repository if provided
155  if (!base_hash.IsNull() && manifest->catalog_hash() != base_hash) {
157  "base hash does not match manifest "
158  "(found: %s expected: %s)",
159  manifest->catalog_hash().ToString().c_str(),
160  base_hash.ToString().c_str());
161  return NULL;
162  }
163 
164  // return the fetched manifest (releasing pointer ownership)
165  return manifest.Release();
166 }
167 
169  const std::string &temp_directory, const std::string &repo_name) {
170  // create a new Reflog if there was none found yet
171  const std::string tmp_path_prefix = temp_directory + "/new_reflog";
172  const std::string tmp_path = CreateTempPath(tmp_path_prefix, 0600);
173 
174  LogCvmfs(kLogCvmfs, kLogDebug, "creating new reflog '%s' for %s",
175  tmp_path.c_str(), repo_name.c_str());
176  return manifest::Reflog::Create(tmp_path, repo_name);
177 }
bool IsNull() const
Definition: hash.h:383
static const unsigned kDownloadTimeout
Definition: server_tool.h:57
const manifest::Manifest * manifest() const
Definition: repository.h:125
T * weak_ref() const
Definition: pointer.h:42
std::string ToString(const bool with_suffix=false) const
Definition: hash.h:249
UniquePtr< download::DownloadManager > download_manager_
Definition: server_tool.h:52
static const unsigned kDownloadRetries
Definition: server_tool.h:58
std::string CreateTempPath(const std::string &path_prefix, const int mode)
Definition: posix.cc:1034
manifest::Manifest * FetchRemoteManifest(const std::string &repository_url, const std::string &repository_name, const shash::Any &base_hash=shash::Any()) const
Definition: server_tool.cc:126
assert((mem||(size==0))&&"Out Of Memory")
bool InitVerifyingSignatureManager(const std::string &pubkey_path)
Definition: server_tool.cc:44
manifest::Failures FetchRemoteManifestEnsemble(const std::string &repository_url, const std::string &repository_name, manifest::ManifestEnsemble *ensemble) const
Definition: server_tool.cc:116
static Reflog * Create(const std::string &database_path, const std::string &repo_name)
Definition: reflog.cc:32
signature::SignatureManager * signature_manager() const
Definition: server_tool.cc:106
download::DownloadManager * download_manager() const
Definition: server_tool.cc:101
Failures Fetch(const std::string &base_url, const std::string &repository_name, const uint64_t minimum_timestamp, const shash::Any *base_catalog, signature::SignatureManager *signature_manager, download::DownloadManager *download_manager, ManifestEnsemble *ensemble)
perf::Statistics * statistics()
Definition: server_tool.h:48
bool IsValid() const
Definition: pointer.h:43
UniquePtr< signature::SignatureManager > signature_manager_
Definition: server_tool.h:53
manifest::Manifest * OpenLocalManifest(const std::string path) const
Definition: server_tool.cc:111
T * Release()
Definition: pointer.h:44
virtual ~ServerTool()
Definition: server_tool.cc:11
manifest::Reflog * CreateEmptyReflog(const std::string &temp_directory, const std::string &repo_name)
Definition: server_tool.cc:168
bool InitDownloadManager(const bool follow_redirects, const std::string &proxy, const unsigned max_pool_handles=1)
Definition: server_tool.cc:17
static Manifest * LoadFile(const std::string &path)
Definition: manifest.cc:92
bool InitSigningSignatureManager(const std::string &certificate_path, const std::string &private_key_path, const std::string &private_key_password)
Definition: server_tool.cc:62
const char * Code2Ascii(const Failures error)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition: logging.cc:528