Skip to content

Instantly share code, notes, and snippets.

@jvehent
Created June 27, 2018 13:12
Show Gist options
  • Save jvehent/cfc6fff97156e31c465991a28860dfc6 to your computer and use it in GitHub Desktop.
Save jvehent/cfc6fff97156e31c465991a28860dfc6 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
tsp "github.com/digitorus/timestamp"
)
func main() {
tsreq, err := tsp.CreateRequest(strings.NewReader("Content to by time-stamped"), nil)
if err != nil {
panic(err)
}
req, err := http.NewRequest("POST", "http://timestamp.digicert.com/", bytes.NewReader(tsreq))
if err != nil {
log.Fatal(err)
}
req.Header.Set("Content-Type", "application/timestamp-query")
cli := &http.Client{}
resp, err := cli.Do(req)
if err != nil || resp == nil {
log.Fatal(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
if resp.StatusCode != http.StatusOK {
log.Fatalf("%s %s", resp.Status, body)
}
tsresp, err := tsp.ParseResponse(body)
if err != nil {
log.Fatal(err)
}
tsresp.Certificates = nil
jsonTs, err := json.MarshalIndent(tsresp, "", " ")
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", jsonTs)
}
@jvehent
Copy link
Author

jvehent commented Jun 27, 2018

$ go run get_timestamp.go

{
    "HashAlgorithm": 5,
    "HashedMessage": "YmM8MjIRVFSWPOZB5QlcSKhdvskToIMyrThYa5EKOyc=",
    "Time": "2018-06-27T13:11:57Z",
    "Accuracy": 0,
    "SerialNumber": 142820471890552379720677726973857460188,
    "Certificates": null,
    "Extensions": null,
    "ExtraExtensions": null
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment