Example #1
0
func (c *Client) GetSTH() (*STH, error) {
	c.init()

	res, err := denet.Require200(c.Client.Get(c.LogURL + "/ct/v1/get-sth"))
	if err != nil {
		return nil, err
	}

	defer res.Body.Close()

	var sthResponse sth
	err = json.NewDecoder(res.Body).Decode(&sthResponse)
	if err != nil {
		return nil, err
	}

	if len(sthResponse.SHA256RootHash) != 32 {
		return nil, fmt.Errorf("unexpected hash length")
	}

	s := &STH{
		TreeSize:      sthResponse.TreeSize,
		Time:          time.Unix(sthResponse.Timestamp/1000, (sthResponse.Timestamp%1000)*1000000),
		HeadSignature: sthResponse.TreeHeadSignature,
	}
	copy(s.RootHash[:], sthResponse.SHA256RootHash)

	return s, nil
}
Example #2
0
// numEntries includes any entries which could not be parsed, which are not included in entries.
func (c *Client) GetEntries(start, end int64) (entries []*Entry, numEntries int, err error) {
	c.init()

	u := fmt.Sprintf("%s/ct/v1/get-entries?start=%d&end=%d", c.LogURL, start, end)
	res, err := denet.Require200(c.Client.Get(u))
	if err != nil {
		return nil, 0, err
	}

	defer res.Body.Close()

	var ger getEntriesResponse
	err = json.NewDecoder(res.Body).Decode(&ger)
	if err != nil {
		return nil, 0, err
	}

	for i, e := range ger.Entries {
		ee, err := decodeEntry(e)
		if err == nil {
			ee.Index = int64(i) + start
			entries = append(entries, ee)
		} else {
			log.Errorf("unknown entry in log %#v: %v", c.LogURL, err)
		}
	}

	return entries, len(ger.Entries), nil
}