aboutsummaryrefslogtreecommitdiff
path: root/internal/node/secondary/endpoint_internal.go
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2022-05-24 23:33:38 +0200
committerRasmus Dahlberg <rasmus@mullvad.net>2022-06-23 11:33:17 +0200
commit559bccccd40d028e412d9f11709ded0250ba6dcd (patch)
tree50f3193dbe70fec21357963c11e5f663013f4b4c /internal/node/secondary/endpoint_internal.go
parent4b20ef0c1732bcef633c0ed7104501898aa84e2c (diff)
implement primary and secondary role, for replicationv0.5.0
Diffstat (limited to 'internal/node/secondary/endpoint_internal.go')
-rw-r--r--internal/node/secondary/endpoint_internal.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/internal/node/secondary/endpoint_internal.go b/internal/node/secondary/endpoint_internal.go
new file mode 100644
index 0000000..f60d6d8
--- /dev/null
+++ b/internal/node/secondary/endpoint_internal.go
@@ -0,0 +1,44 @@
+package secondary
+
+// This file implements internal HTTP handler callbacks for secondary nodes.
+
+import (
+ "context"
+ "crypto/ed25519"
+ "fmt"
+ "net/http"
+
+ "git.sigsum.org/log-go/internal/node/handler"
+ "git.sigsum.org/sigsum-go/pkg/log"
+ "git.sigsum.org/sigsum-go/pkg/merkle"
+ "git.sigsum.org/sigsum-go/pkg/types"
+)
+
+func getTreeHeadToCosign(ctx context.Context, c handler.Config, w http.ResponseWriter, _ *http.Request) (int, error) {
+ s := c.(Secondary)
+ log.Debug("handling get-tree-head-to-cosign request")
+
+ signedTreeHead := func() (*types.SignedTreeHead, error) {
+ tctx, cancel := context.WithTimeout(ctx, s.Config.Deadline)
+ defer cancel()
+ th, err := treeHeadFromTrillian(tctx, s.TrillianClient)
+ if err != nil {
+ return nil, fmt.Errorf("getting tree head: %w", err)
+ }
+ namespace := merkle.HashFn(s.Signer.Public().(ed25519.PublicKey))
+ sth, err := th.Sign(s.Signer, namespace)
+ if err != nil {
+ return nil, fmt.Errorf("signing tree head: %w", err)
+ }
+ return sth, nil
+ }
+
+ sth, err := signedTreeHead()
+ if err != nil {
+ return http.StatusInternalServerError, err
+ }
+ if err := sth.ToASCII(w); err != nil {
+ return http.StatusInternalServerError, err
+ }
+ return http.StatusOK, nil
+}