1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
package stfe
import (
"fmt"
"crypto/ed25519"
"net/http"
"github.com/system-transparency/stfe/types"
)
func (lp *LogParameters) parseAddEntryV1Request(r *http.Request) (*types.Leaf, error) {
var req types.LeafRequest
if err := req.UnmarshalASCII(r.Body); err != nil {
return nil, fmt.Errorf("UnmarshalASCII: %v", err)
}
if pub, msg, sig := ed25519.PublicKey(req.VerificationKey[:]), req.Message.Marshal(), req.Signature[:]; !ed25519.Verify(pub, msg, sig) {
return nil, fmt.Errorf("Invalid signature")
}
// TODO: check shard hint
// TODO: check domain hint
return &types.Leaf{
Message: req.Message,
SigIdent: types.SigIdent{
Signature: req.Signature,
KeyHash: types.Hash(req.VerificationKey[:]),
},
}, nil
}
func (lp *LogParameters) parseAddCosignatureRequest(r *http.Request) (*types.CosignatureRequest, error) {
var req types.CosignatureRequest
if err := req.UnmarshalASCII(r.Body); err != nil {
return nil, fmt.Errorf("unpackOctetPost: %v", err)
}
if _, ok := lp.Witnesses[*req.KeyHash]; !ok {
return nil, fmt.Errorf("Unknown witness: %x", req.KeyHash)
}
return &req, nil
}
func (lp *LogParameters) parseGetConsistencyProofRequest(r *http.Request) (*types.ConsistencyProofRequest, error) {
var req types.ConsistencyProofRequest
if err := req.UnmarshalASCII(r.Body); err != nil {
return nil, fmt.Errorf("UnmarshalASCII: %v", err)
}
if req.OldSize < 1 {
return nil, fmt.Errorf("OldSize(%d) must be larger than zero", req.OldSize)
}
if req.NewSize <= req.OldSize {
return nil, fmt.Errorf("NewSize(%d) must be larger than OldSize(%d)", req.NewSize, req.OldSize)
}
return &req, nil
}
//func (lp *LogParameters) parseGetProofByHashV1Request(r *http.Request) (*types.GetProofByHashV1, error) {
// var item types.GetProofByHashV1
// if err := unpackOctetPost(r, &item); err != nil {
// return nil, fmt.Errorf("unpackOctetPost: %v", err)
// }
// if item.TreeSize < 1 {
// return nil, fmt.Errorf("TreeSize(%d) must be larger than zero", item.TreeSize)
// }
// return &item, nil
//}
//
//func (lp *LogParameters) parseGetEntriesV1Request(r *http.Request) (*types.GetEntriesV1, error) {
// var item types.GetEntriesV1
// if err := unpackOctetPost(r, &item); err != nil {
// return nil, fmt.Errorf("unpackOctetPost: %v", err)
// }
//
// if item.Start > item.End {
// return nil, fmt.Errorf("start(%v) must be less than or equal to end(%v)", item.Start, item.End)
// }
// if item.End-item.Start+1 > uint64(lp.MaxRange) {
// item.End = item.Start + uint64(lp.MaxRange) - 1
// }
// return &item, nil
//}
//
//func unpackOctetPost(r *http.Request, out interface{}) error {
// body, err := ioutil.ReadAll(r.Body)
// if err != nil {
// return fmt.Errorf("failed reading request body: %v", err)
// }
// if err := types.Unmarshal(body, out); err != nil {
// return fmt.Errorf("Unmarshal: %v", err)
// }
// return nil
//}
|