This commit adds the git-http-timestamp helper tool. It does all the
communication to a Time Stamping Authority via libcurl and passes the received
data to the caller via stdout.

Libcurl by default depends on GnuTLS, the new RFC3161 time-stamping
functionality depends on libcrypto (OpenSSL) as GnuTLS does not support RFC3161
time-stamps. The git-http-timestamp helper tool is introduced to avoid linking
OpenSSL and GnuTLS together in a single binary.

Signed-off-by: Anton Würfel <anton.wuer...@fau.de>
Signed-off-by: Phillip Raffeck <phillip.raff...@fau.de>
---
 .gitignore       |  1 +
 Makefile         |  7 ++++++
 command-list.txt |  1 +
 http-timestamp.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 85 insertions(+)
 create mode 100644 http-timestamp.c

diff --git a/.gitignore b/.gitignore
index 5087ce1..a3b270d 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 432c3de..c717af7 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 2a94137..3e279c1 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 0000000..86b42e0
--- /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);
+}
-- 
2.8.0.rc0.62.gfc8aefa.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to