From 29739d6e1f498685f74d38a8fdb24ffe6e7f837e Mon Sep 17 00:00:00 2001 From: Casey Marshall Date: Thu, 30 Oct 2014 10:48:51 -0500 Subject: [PATCH] Followup fix for PR #22 --- bakery/codec.go | 8 ++++---- bakery/example/example_test.go | 2 +- bakery/example/idservice/idservice.go | 6 +++--- bakery/example/idservice/idservice_test.go | 2 +- bakery/example/main.go | 2 +- bakery/keys.go | 6 +++--- httpbakery/discharge.go | 10 +++++----- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/bakery/codec.go b/bakery/codec.go index a8506f7..f733f0c 100644 --- a/bakery/codec.go +++ b/bakery/codec.go @@ -71,10 +71,10 @@ func (enc *boxEncoder) newCaveatId(cav Caveat, rootKey []byte, thirdPartyPub *Pu if err != nil { return nil, fmt.Errorf("cannot marshal %#v: %v", &plain, err) } - sealed := box.Seal(nil, plainData, &nonce, (*[32]byte)(thirdPartyPub), (*[32]byte)(enc.key.PrivateKey())) + sealed := box.Seal(nil, plainData, &nonce, (*[32]byte)(thirdPartyPub), (*[32]byte)(&enc.key.Private)) return &caveatId{ ThirdPartyPublicKey: thirdPartyPub[:], - FirstPartyPublicKey: enc.key.PublicKey()[:], + FirstPartyPublicKey: enc.key.Public[:], Nonce: nonce[:], Id: base64.StdEncoding.EncodeToString(sealed), }, nil @@ -120,7 +120,7 @@ func (d *boxDecoder) encryptedCaveatId(id caveatId) ([]byte, error) { if d.key == nil { return nil, fmt.Errorf("no public key for caveat id decryption") } - if !bytes.Equal(d.key.PublicKey()[:], id.ThirdPartyPublicKey) { + if !bytes.Equal(d.key.Public[:], id.ThirdPartyPublicKey) { return nil, fmt.Errorf("public key mismatch") } var nonce [NonceLen]byte @@ -139,7 +139,7 @@ func (d *boxDecoder) encryptedCaveatId(id caveatId) ([]byte, error) { if err != nil { return nil, fmt.Errorf("cannot base64-decode encrypted caveat id: %v", err) } - out, ok := box.Open(nil, sealed, &nonce, (*[KeyLen]byte)(&firstPartyPublicKey), (*[KeyLen]byte)(d.key.PrivateKey())) + out, ok := box.Open(nil, sealed, &nonce, (*[KeyLen]byte)(&firstPartyPublicKey), (*[KeyLen]byte)(&d.key.Private)) if !ok { return nil, fmt.Errorf("decryption of public-key encrypted caveat id %#v failed", id) } diff --git a/bakery/example/example_test.go b/bakery/example/example_test.go index aa51c43..81c9bb4 100644 --- a/bakery/example/example_test.go +++ b/bakery/example/example_test.go @@ -23,7 +23,7 @@ var _ = gc.Suite(&exampleSuite{}) func (s *exampleSuite) SetUpSuite(c *gc.C) { key, err := bakery.GenerateKey() c.Assert(err, gc.IsNil) - s.authPublicKey = key.PublicKey() + s.authPublicKey = &key.Public s.authEndpoint, err = serve(func(endpoint string) (http.Handler, error) { return authService(endpoint, key) }) diff --git a/bakery/example/idservice/idservice.go b/bakery/example/idservice/idservice.go index 5e7c3aa..9f10bfd 100644 --- a/bakery/example/idservice/idservice.go +++ b/bakery/example/idservice/idservice.go @@ -70,7 +70,7 @@ func New(p Params) (http.Handler, error) { // userHandler handles requests to add new users, change user details, etc. // It is only accessible to users that are members of the admin group. -func (h *handler) userHandler(_ http.Header, req *http.Request) (interface{}, error) { +func (h *handler) userHandler(_ http.ResponseWriter, req *http.Request) (interface{}, error) { ctxt := h.newContext(req, "change-user") breq := h.svc.NewRequest(req, ctxt) err := breq.Check() @@ -262,7 +262,7 @@ func (h *handler) needLogin(cavId string, caveat string, why string) error { // waitHandler serves an HTTP endpoint that waits until a macaroon // has been discharged, and returns the discharge macaroon. -func (h *handler) waitHandler(_ http.Header, req *http.Request) (interface{}, error) { +func (h *handler) waitHandler(_ http.ResponseWriter, req *http.Request) (interface{}, error) { req.ParseForm() waitId := req.Form.Get("waitid") if waitId == "" { @@ -296,7 +296,7 @@ func (h *handler) waitHandler(_ http.Header, req *http.Request) (interface{}, er }, nil } -func (h *handler) questionHandler(_ http.Header, req *http.Request) (interface{}, error) { +func (h *handler) questionHandler(_ http.ResponseWriter, req *http.Request) (interface{}, error) { return nil, errgo.New("question unimplemented") // TODO // req.ParseForm() diff --git a/bakery/example/idservice/idservice_test.go b/bakery/example/idservice/idservice_test.go index 20fe3ca..f772bb4 100644 --- a/bakery/example/idservice/idservice_test.go +++ b/bakery/example/idservice/idservice_test.go @@ -28,7 +28,7 @@ var _ = gc.Suite(&suite{}) func (s *suite) SetUpSuite(c *gc.C) { key, err := bakery.GenerateKey() c.Assert(err, gc.IsNil) - s.authPublicKey = key.PublicKey() + s.authPublicKey = &key.Public s.authEndpoint = serve(c, func(endpoint string) (http.Handler, error) { return idservice.New(idservice.Params{ Users: map[string]*idservice.UserInfo{ diff --git a/bakery/example/main.go b/bakery/example/main.go index ab8ef33..d9f1422 100644 --- a/bakery/example/main.go +++ b/bakery/example/main.go @@ -31,7 +31,7 @@ func main() { if err != nil { log.Fatalf("cannot generate auth service key pair: %v", err) } - authPublicKey := key.PublicKey() + authPublicKey := &key.Public authEndpoint := mustServe(func(endpoint string) (http.Handler, error) { return authService(endpoint, key) }) diff --git a/bakery/keys.go b/bakery/keys.go index 9f0d065..25ecbb7 100644 --- a/bakery/keys.go +++ b/bakery/keys.go @@ -58,14 +58,14 @@ func GenerateKey() (*KeyPair, error) { if err != nil { return nil, err } - key.public = PublicKey(*pub) - key.private = *priv + key.Public = PublicKey(*pub) + key.Private = *priv return &key, nil } // String implements the fmt.Stringer interface. func (key *KeyPair) String() string { - return hex.EncodeToString(key.public[:]) + return hex.EncodeToString(key.Public[:]) } type publicKeyRecord struct { diff --git a/httpbakery/discharge.go b/httpbakery/discharge.go index f6e14f6..676061b 100644 --- a/httpbakery/discharge.go +++ b/httpbakery/discharge.go @@ -85,8 +85,8 @@ type dischargeResponse struct { Macaroon *macaroon.Macaroon `json:",omitempty"` } -func (d *dischargeHandler) serveDischarge(h http.Header, req *http.Request) (interface{}, error) { - r, err := d.serveDischarge1(h, req) +func (d *dischargeHandler) serveDischarge(_ http.ResponseWriter, req *http.Request) (interface{}, error) { + r, err := d.serveDischarge1(req) if err != nil { log.Printf("serveDischarge -> error %#v", err) } else { @@ -95,7 +95,7 @@ func (d *dischargeHandler) serveDischarge(h http.Header, req *http.Request) (int return r, err } -func (d *dischargeHandler) serveDischarge1(h http.Header, req *http.Request) (interface{}, error) { +func (d *dischargeHandler) serveDischarge1(req *http.Request) (interface{}, error) { log.Printf("dischargeHandler.serveDischarge {") defer log.Printf("}") if req.Method != "POST" { @@ -133,7 +133,7 @@ type caveatIdResponse struct { Error string } -func (d *dischargeHandler) serveCreate(h http.Header, req *http.Request) (interface{}, error) { +func (d *dischargeHandler) serveCreate(_ http.ResponseWriter, req *http.Request) (interface{}, error) { req.ParseForm() condition := req.Form.Get("condition") rootKeyStr := req.Form.Get("root-key") @@ -170,7 +170,7 @@ func (d *dischargeHandler) serveCreate(h http.Header, req *http.Request) (interf }, nil } -func (d *dischargeHandler) servePublicKey(h http.Header, r *http.Request) (interface{}, error) { +func (d *dischargeHandler) servePublicKey(_ http.ResponseWriter, r *http.Request) (interface{}, error) { return nil, fmt.Errorf("not implemented yet") }