Skip to content

Commit

Permalink
Followup fix for PR #22
Browse files Browse the repository at this point in the history
  • Loading branch information
Casey Marshall committed Oct 30, 2014
1 parent dbd6122 commit 29739d6
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions bakery/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion bakery/example/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
6 changes: 3 additions & 3 deletions bakery/example/idservice/idservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 == "" {
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion bakery/example/idservice/idservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion bakery/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
6 changes: 3 additions & 3 deletions bakery/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions httpbakery/discharge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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" {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
}

Expand Down

0 comments on commit 29739d6

Please sign in to comment.