aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--handler.go17
-rw-r--r--reqres.go87
-rw-r--r--type.go8
3 files changed, 23 insertions, 89 deletions
diff --git a/handler.go b/handler.go
index 47151c8..c86281f 100644
--- a/handler.go
+++ b/handler.go
@@ -73,9 +73,9 @@ func addEntry(ctx context.Context, i *Instance, w http.ResponseWriter, r *http.R
return http.StatusInternalServerError, fmt.Errorf("failed creating signed debug info: %v", err)
}
- response, err := NewAddEntryResponse(sdi)
+ response, err := StItemToB64(sdi)
if err != nil {
- return http.StatusInternalServerError, fmt.Errorf("failed creating AddEntryResponse: %v", err)
+ return http.StatusInternalServerError, err
}
if err := WriteJsonResponse(response, w); err != nil {
return http.StatusInternalServerError, err
@@ -160,9 +160,9 @@ func getProofByHash(ctx context.Context, i *Instance, w http.ResponseWriter, r *
}
// TODO: verify that proof is valid?
- response, err := NewGetProofByHashResponse(i.LogParameters.LogId, uint64(request.TreeSize), trillianResponse.Proof[0])
+ response, err := StItemToB64(NewInclusionProofV1(i.LogParameters.LogId, uint64(request.TreeSize), trillianResponse.Proof[0]))
if err != nil {
- return http.StatusInternalServerError, fmt.Errorf("failed creating get-proof-by-hash response: %v", err)
+ return http.StatusInternalServerError, err
}
if err := WriteJsonResponse(response, w); err != nil {
return http.StatusInternalServerError, err
@@ -189,15 +189,14 @@ func getConsistencyProof(ctx context.Context, i *Instance, w http.ResponseWriter
}
// TODO: santity-checks?
- response, err := NewGetConsistencyProofResponse(i.LogParameters.LogId, request.First, request.Second, trillianResponse.Proof)
+ response, err := StItemToB64(NewConsistencyProofV1(i.LogParameters.LogId, request.First, request.Second, trillianResponse.Proof))
if err != nil {
- return http.StatusInternalServerError, fmt.Errorf("failed creating get-consistency-proof response: %v", err)
+ return http.StatusInternalServerError, err
}
if err := WriteJsonResponse(response, w); err != nil {
return http.StatusInternalServerError, err
}
return http.StatusOK, nil
- return http.StatusOK, nil // TODO
}
// getSth provides the most recent STH
@@ -221,9 +220,9 @@ func getSth(ctx context.Context, i *Instance, w http.ResponseWriter, _ *http.Req
}
glog.Infof("%v", sth)
- response, err := NewGetSthResponse(sth)
+ response, err := StItemToB64(sth)
if err != nil {
- return http.StatusInternalServerError, fmt.Errorf("failed creating GetSthResponse: %v", err)
+ return http.StatusInternalServerError, err
}
if err := WriteJsonResponse(response, w); err != nil {
return http.StatusInternalServerError, err
diff --git a/reqres.go b/reqres.go
index 0c14d89..66e07b8 100644
--- a/reqres.go
+++ b/reqres.go
@@ -36,13 +36,8 @@ type GetProofByHashRequest struct {
// GetConsistencyProofRequest is a collection of get-consistency-proof input
// parameters
type GetConsistencyProofRequest struct {
- First int64 `json:"first"`
- Second int64 `json:"second"`
-}
-
-// AddEntryResponse is an assembled add-entry response
-type AddEntryResponse struct {
- SignedDebugInfo string `json:"sdi"`
+ First int64 `json:"first"` // size of the older Merkle tree
+ Second int64 `json:"second"` // size of the newer Merkle tree
}
// GetEntryResponse is an assembled log entry and its associated appendix
@@ -52,30 +47,6 @@ type GetEntryResponse struct {
Chain []string `json:"chain"` // base64-encoded X.509 certificates
}
-// GetEntriesResponse is an assembled get-entries responses
-type GetEntriesResponse struct {
- Entries []GetEntryResponse `json:"entries"`
-}
-
-// GetProofByHashResponse is an assembled inclusion proof response
-type GetProofByHashResponse struct {
- InclusionProof string `json:"inclusion_proof"` // base64-encoded StItem
-}
-
-type GetConsistencyProofResponse struct {
- ConsistencyProof string `json:"consistency_proof"` // base64-encoded StItem
-}
-
-// GetAnchorsResponse is an assembled get-anchor response
-type GetAnchorsResponse struct {
- Certificates []string `json:"certificates"`
-}
-
-// GetSthResponse is an assembled get-sth response
-type GetSthResponse struct {
- SignedTreeHead string `json:"sth"` // base64-encoded StItem
-}
-
// NewAddEntryRequest parses and sanitizes the JSON-encoded add-entry
// parameters from an incoming HTTP post. The resulting AddEntryRequest is
// well-formed, but not necessarily trusted (further sanitization is needed).
@@ -159,17 +130,6 @@ func NewGetConsistencyProofRequest(httpRequest *http.Request) (GetConsistencyPro
return GetConsistencyProofRequest{First: first, Second: second}, nil
}
-// NewAddEntryResponse assembles an add-entry response from an SDI
-func NewAddEntryResponse(sdi StItem) (AddEntryResponse, error) {
- b, err := tls.Marshal(sdi)
- if err != nil {
- return AddEntryResponse{}, fmt.Errorf("tls marshal failed: %v", err)
- }
- return AddEntryResponse{
- SignedDebugInfo: base64.StdEncoding.EncodeToString(b),
- }, nil
-}
-
// NewGetEntryResponse assembles a log entry and its appendix
func NewGetEntryResponse(leaf, appendix []byte) (GetEntryResponse, error) {
var app Appendix
@@ -193,57 +153,24 @@ func NewGetEntryResponse(leaf, appendix []byte) (GetEntryResponse, error) {
}
// NewGetEntriesResponse assembles a get-entries response
-func NewGetEntriesResponse(leaves []*trillian.LogLeaf) (GetEntriesResponse, error) {
+func NewGetEntriesResponse(leaves []*trillian.LogLeaf) ([]GetEntryResponse, error) {
entries := make([]GetEntryResponse, 0, len(leaves))
for _, leaf := range leaves {
entry, err := NewGetEntryResponse(leaf.GetLeafValue(), leaf.GetExtraData())
if err != nil {
- return GetEntriesResponse{}, err
+ return nil, err
}
entries = append(entries, entry)
}
- return GetEntriesResponse{entries}, nil
-}
-
-// NewGetProofByHashResponse assembles a get-proof-by-hash response
-func NewGetProofByHashResponse(logId []byte, treeSize uint64, inclusionProof *trillian.Proof) (*GetProofByHashResponse, error) {
- item := NewInclusionProofV1(logId, treeSize, inclusionProof)
- b, err := tls.Marshal(item)
- if err != nil {
- return nil, fmt.Errorf("tls marshal failed: %v", err)
- }
- return &GetProofByHashResponse{
- InclusionProof: base64.StdEncoding.EncodeToString(b),
- }, nil
-}
-
-func NewGetConsistencyProofResponse(logId []byte, first, second int64, consistencyProof *trillian.Proof) (*GetConsistencyProofResponse, error) {
- item := NewConsistencyProofV1(logId, first, second, consistencyProof)
- b, err := tls.Marshal(item)
- if err != nil {
- return nil, fmt.Errorf("tls marshal failed: %v", err)
- }
- return &GetConsistencyProofResponse{
- ConsistencyProof: base64.StdEncoding.EncodeToString(b),
- }, nil
+ return entries, nil
}
-func NewGetAnchorsResponse(anchors []*x509.Certificate) GetAnchorsResponse {
+func NewGetAnchorsResponse(anchors []*x509.Certificate) []string {
certificates := make([]string, 0, len(anchors))
for _, certificate := range anchors {
certificates = append(certificates, base64.StdEncoding.EncodeToString(certificate.Raw))
}
- return GetAnchorsResponse{Certificates: certificates}
-}
-
-func NewGetSthResponse(sth StItem) (GetSthResponse, error) {
- b, err := tls.Marshal(sth)
- if err != nil {
- return GetSthResponse{}, fmt.Errorf("tls marshal failed: %v", err)
- }
- return GetSthResponse{
- SignedTreeHead: base64.StdEncoding.EncodeToString(b),
- }, nil
+ return certificates
}
// VerifyAddEntryRequest determines whether a well-formed AddEntryRequest should
diff --git a/type.go b/type.go
index 7d505c7..060ce30 100644
--- a/type.go
+++ b/type.go
@@ -262,6 +262,14 @@ func StItemFromB64(s string) (StItem, error) {
return item, nil
}
+func StItemToB64(i StItem) (string, error) {
+ b, err := tls.Marshal(i)
+ if err != nil {
+ return "", fmt.Errorf("StItem(%v) tls marshal failed: %v", i.Format, err)
+ }
+ return base64.StdEncoding.EncodeToString(b), nil
+}
+
// Appendix is extra data that Trillian can store about a leaf
type Appendix struct {
Signature []byte `tls:"minlen:0,maxlen:16383"`