diff --git a/.gitignore b/.gitignore index 5087ce1eb7e2210e7fc25a9a14ac3f499ad5ac2f..a3b270dc0d610cb7652e68aea45d56c90867ad1f 100644 --- a/.gitignore +++ b/.gitignore @@ -70,6 +70,7 @@ /git-http-backend /git-http-fetch /git-http-push +/git-http-timestamp /git-imap-send /git-index-pack /git-init diff --git a/Makefile b/Makefile index 432c3dedf2d6f05e3a46c336c0486a95be63d021..c717af7acd7d4b7102ba356ec75eec32c7d1d39e 100644 --- a/Makefile +++ b/Makefile @@ -1116,6 +1116,9 @@ else BASIC_CFLAGS += -DEXPAT_NEEDS_XMLPARSE_H endif endif + + PROGRAM_OBJS += http-timestamp.o + PROGRAMS += git-http-timestamp$X endif IMAP_SEND_LDFLAGS += $(OPENSSL_LINK) $(OPENSSL_LIBSSL) $(LIB_4_CRYPTO) @@ -2018,6 +2021,10 @@ git-remote-testsvn$X: remote-testsvn.o GIT-LDFLAGS $(GITLIBS) $(VCSSVN_LIB) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) \ $(VCSSVN_LIB) +git-http-timestamp$X: http.o http-timestamp.o GIT-LDFLAGS $(GITLIBS) + $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ + $(CURL_LIBCURL) $(LIBS) + $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY) $(QUIET_LNCP)$(RM) $@ && \ ln $< $@ 2>/dev/null || \ diff --git a/command-list.txt b/command-list.txt index 2a94137bbb383fda655b481446d0891062d73cb9..3e279c1495ea8790a56fae1be677021a532370f4 100644 --- a/command-list.txt +++ b/command-list.txt @@ -68,6 +68,7 @@ git-help ancillaryinterrogators git-http-backend synchingrepositories git-http-fetch synchelpers git-http-push synchelpers +git-http-timestamp purehelpers git-imap-send foreignscminterface git-index-pack plumbingmanipulators git-init mainporcelain init diff --git a/http-timestamp.c b/http-timestamp.c new file mode 100644 index 0000000000000000000000000000000000000000..86b42e0b13c0d7aad24c3a21a54261fb0e037563 --- /dev/null +++ b/http-timestamp.c @@ -0,0 +1,76 @@ +#include "cache.h" +#include "strbuf.h" +#include "http.h" + +static int obtain_tsr(struct strbuf *tsq, struct strbuf *tsr); + +static void usage_and_die(const char *name); + +static const char *config_tsa_url_key = "ts.tsaurl"; + +int main(int argc, const char *argv[]) +{ + struct strbuf tsr = STRBUF_INIT; + struct strbuf tsq = STRBUF_INIT; + int ret; + + if (argc != 1) + usage_and_die(argv[0]); + + if (strbuf_fread(&tsq, 1024, stdin) < 0) { + strbuf_release(&tsq); + return error(_("strbuf_fread failed: %s"), strerror(errno)); + } + + ret = obtain_tsr(&tsq, &tsr); + + if (!ret) + write_in_full(fileno(stdout), tsr.buf, tsr.len); + + strbuf_release(&tsr); + strbuf_release(&tsq); + return ret; +} + +static int obtain_tsr(struct strbuf *tsq, struct strbuf *tsr) +{ + struct strbuf content_type = STRBUF_INIT; + struct http_request_options options = {0}; + + char *config_tsa_url; + + if (git_config_get_string(config_tsa_url_key, &config_tsa_url)) { + die(_("git config option '%s' must be set"), + config_tsa_url_key); + } + + /* libcurl stuff */ + + http_init(NULL, config_tsa_url, 0); + + strbuf_addstr(&content_type, "application/timestamp-query"); + options.post_content_type = &content_type; + options.postfields = tsq; + + if (http_get_strbuf(config_tsa_url, tsr, &options)) { + strbuf_release(&content_type); + return error(_("sending time-stamp query failed")); + } + + strbuf_release(&content_type); + free(config_tsa_url); + http_cleanup(); + + return 0; +} + +static void usage_and_die(const char *name) +{ + fprintf(stderr, "Usage: %s\n\n", name); + fputs("Obtain a trusted time-stamp from the Time Stamping Authority\n" + "specified in configuration variable `ts.tsaurl` and write the\n" + "result to stdout.\n", + stderr); + + exit(EXIT_FAILURE); +}