27 unsigned read_all = 0;
30 if ((read_chunk = read(0, buf + read_all, num_bytes - read_all)) <= 0)
32 read_all += read_chunk;
33 }
while (read_all < num_bytes);
37 assert(read_all == num_bytes);
42 const uint16_t num_bytes) {
44 unsigned wrote_all = 0;
47 if ((wrote_chunk = write(1, buf + wrote_all, num_bytes - wrote_all)) <= 0)
49 wrote_all += wrote_chunk;
50 }
while (wrote_all < num_bytes);
52 assert(wrote_all == num_bytes);
60 len = (buf[0] << 8) | buf[1];
70 li = (len >> 8) & 0xff;
81 if (args.find(
'v') != args.end())
83 if ((args.find(
's') != args.end()) && verify) {
85 "invalid option combination (sign + verify)");
90 string repository_url;
91 string certificate_path;
92 string certificate_password;
94 uint64_t max_age = kDefaultMaxAge;
96 repository_url = *args.find(
'r')->second;
98 if (args.find(
'e') != args.end())
101 certificate_path = *args.find(
'c')->second;
102 if (args.find(
'p') != args.end())
103 certificate_password = *args.find(
'p')->second;
104 if (args.find(
'a') != args.end()) {
115 fqrn = *args.find(
'f')->second;
116 key_path = *args.find(
'k')->second;
117 if (args.find(
't') != args.end())
118 text = *args.find(
't')->second;
124 if (!InitSignatureManager(key_path)) {
128 const bool follow_redirects =
false;
129 const unsigned max_pool_handles = 2;
130 const string proxy = (args.find(
'@') != args.end())
131 ? *args.find(
'@')->second
133 if (!this->InitDownloadManager(follow_redirects, proxy, max_pool_handles)) {
139 signature_manager());
140 retval_wl = whitelist.
LoadUrl(repository_url);
148 const char *ready =
"ready";
149 WriteErlang(reinterpret_cast<const unsigned char *>(ready), 5);
155 unsigned char buf[65000];
157 text = string(reinterpret_cast<char *>(buf), length);
162 while ((num_read = read(0, &c, 1)) == 1) {
172 if ((time(NULL) + 3600 * 24 * 3) > whitelist.
expires()) {
175 signature_manager());
176 retval_wl = refresh.
LoadUrl(repository_url);
184 retval_ltr = letter.
Verify(max_age, &message, &cert);
205 if ((exit_code == 0) && (message.length() > 60000))
207 WriteErlang(reinterpret_cast<unsigned char *>(&exit_code), 1);
209 WriteErlang(reinterpret_cast<const unsigned char *>(message.data()),
222 if (!InitSignatureManager(
"", certificate_path, key_path)) {
228 while (read(0, &c, 1) == 1) {
237 text_letter.
Sign(hash_algorithm).c_str());
Failures LoadUrl(const std::string &base_url)
Failures VerifyLoadedCertificate() const
Failures Verify(uint64_t max_age, std::string *msg, std::string *cert)
assert((mem||(size==0))&&"Out Of Memory")
static void ReadStdinBytes(unsigned char *buf, const uint16_t num_bytes)
std::string Sign(const shash::Algorithms hash_algorithm)
const char * Code2Ascii(const Failures error)
static void WriteStdoutBytes(const unsigned char *buf, const uint16_t num_bytes)
int Main(const ArgumentList &args)
const whitelist::Whitelist * whitelist() const
uint64_t String2Uint64(const string &value)
std::map< char, SharedPtr< std::string > > ArgumentList
Algorithms ParseHashAlgorithm(const string &algorithm_option)
const char * Code2Ascii(const Failures error)
static void WriteErlang(const unsigned char *buf, int len)
static uint16_t ReadErlang(unsigned char *buf)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)