diff options
Diffstat (limited to 'client/client.go')
-rw-r--r-- | client/client.go | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/client/client.go b/client/client.go index 551eff7..34fa8a2 100644 --- a/client/client.go +++ b/client/client.go @@ -49,7 +49,7 @@ func NewClientFromPath(logId, chainPath, keyPath, operatorsPath string, cli *htt } k, err := stfe.LoadEd25519SigningKey(keyPath) - if err != nil { + if err != nil && keyPath != "" { return nil, err } @@ -119,8 +119,24 @@ func (c *Client) AddEntry(ctx context.Context, name, checksum []byte) (*stfe.StI } func (c *Client) GetSth(ctx context.Context) (*stfe.StItem, error) { - glog.V(2).Info("creating get-sth request") - return nil, fmt.Errorf("TODO") + req, err := http.NewRequest("GET", c.protocol()+c.Log.BaseUrl+"/get-sth", nil) + if err != nil { + return nil, fmt.Errorf("failed creating http request: %v", err) + } + glog.V(2).Infof("created request: %s %s", req.Method, req.URL) + + item, err := c.doRequestWithStItemResponse(ctx, req) + if err != nil { + return nil, err + } + if item.Format != stfe.StFormatSignedTreeHeadV1 { + return nil, fmt.Errorf("bad StItem format: %v", item.Format) + } + if err := item.SignedTreeHeadV1.Verify(c.Log.Scheme, c.Log.PublicKey); err != nil { + return nil, fmt.Errorf("bad SignedDebugInfoV1 signature: %v", err) + } + glog.V(2).Infof("get-sth request succeeded") + return item, nil } func (c *Client) GetConsistencyProof(ctx context.Context, first, second uint64) (*stfe.StItem, error) { @@ -171,6 +187,22 @@ func (c *Client) doRequest(ctx context.Context, req *http.Request, out interface return nil } +func (c *Client) doRequestWithStItemResponse(ctx context.Context, req *http.Request) (*stfe.StItem, error) { + var itemStr string + if err := c.doRequest(ctx, req, &itemStr); err != nil { + return nil, err + } + b, err := base64.StdEncoding.DecodeString(itemStr) + if err != nil { + return nil, fmt.Errorf("failed decoding base64 body: %v", err) + } + var item stfe.StItem + if err := item.Unmarshal(b); err != nil { + return nil, fmt.Errorf("failed decoding StItem: %v", err) + } + return &item, nil +} + // protocol returns a protocol string that preceeds the log's base url func (c *Client) protocol() string { if c.useHttp { |