identity: Pass the public key of the publicID to javascript.
Change-Id: I6d622a62449883594f7f564623a2a7481ced9a6d
diff --git a/services/wsprd/app/app.go b/services/wsprd/app/app.go
index 003820f..efd6acc 100644
--- a/services/wsprd/app/app.go
+++ b/services/wsprd/app/app.go
@@ -85,13 +85,6 @@
Name string
}
-// PublicIDHandle is a handle given to Javascript that is linked
-// to a PublicID in go.
-type PublicIDHandle struct {
- Handle int64
- Names []string
-}
-
// Controller represents all the state of a Veyron Web App. This is the struct
// that is in charge performing all the veyron options.
type Controller struct {
@@ -627,15 +620,15 @@
}
}
-func (c *Controller) getPublicIDHandle(handle int64) (*PublicIDHandle, error) {
+func (c *Controller) getPublicIDHandle(handle int64) (*identity.PublicIDHandle, error) {
id := c.idStore.Get(handle)
if id == nil {
return nil, verror2.Make(unknownPublicID, nil)
}
- return &PublicIDHandle{Handle: handle, Names: id.Names()}, nil
+ return identity.ConvertPublicIDToHandle(id, handle), nil
}
-func (c *Controller) bless(request blessingRequest) (*PublicIDHandle, error) {
+func (c *Controller) bless(request blessingRequest) (*identity.PublicIDHandle, error) {
var caveats []security.Caveat
for _, c := range request.Caveats {
cav, err := decodeCaveat(c)
@@ -658,7 +651,7 @@
return nil, err
}
- return &PublicIDHandle{Handle: c.idStore.Add(blessed), Names: blessed.Names()}, nil
+ return identity.ConvertPublicIDToHandle(blessed, c.idStore.Add(blessed)), nil
}
// HandleBlessing handles a blessing request from JS.
@@ -696,7 +689,7 @@
}
publicID := id.PublicID()
- jsID := &PublicIDHandle{Handle: c.idStore.Add(publicID), Names: publicID.Names()}
+ jsID := identity.ConvertPublicIDToHandle(publicID, c.idStore.Add(publicID))
if err := w.Send(lib.ResponseFinal, jsID); err != nil {
w.Error(verror2.Convert(verror2.Internal, nil, err))
return
diff --git a/services/wsprd/app/app_test.go b/services/wsprd/app/app_test.go
index 51243aa..f82b94d 100644
--- a/services/wsprd/app/app_test.go
+++ b/services/wsprd/app/app_test.go
@@ -1,6 +1,7 @@
package app
import (
+ "encoding/base64"
"encoding/json"
"fmt"
"reflect"
@@ -552,11 +553,21 @@
}
rt.controller.HandleLookupResponse(2, string(bytes))
+ id := rt.controller.rt.Identity().PublicID()
typedNames := rt.controller.rt.Identity().PublicID().Names()
names := []interface{}{}
for _, n := range typedNames {
names = append(names, n)
}
+ k := id.PublicKey()
+ keyBytes, err := k.MarshalBinary()
+
+ if err != nil {
+ t.Errorf("Failed to marshal key, %v", err)
+ return
+ }
+
+ publicKey := base64.StdEncoding.EncodeToString(keyBytes)
// The expectedHandle for the javascript ID. Since we don't always call the authorizer
// this handle could be different by the time we make the start rpc call.
@@ -577,12 +588,14 @@
"suffix": "adder",
"label": 8.0, // This is a read label.
"localId": map[string]interface{}{
- "Handle": 1.0,
- "Names": names,
+ "Handle": 1.0,
+ "Names": names,
+ "PublicKey": publicKey,
},
"remoteId": map[string]interface{}{
- "Handle": 2.0,
- "Names": names,
+ "Handle": 2.0,
+ "Names": names,
+ "PublicKey": publicKey,
},
"localEndpoint": endpoint.String(),
"remoteEndpoint": "remoteEndpoint",
@@ -633,12 +646,14 @@
"suffix": "adder",
"label": 16.0,
"localId": map[string]interface{}{
- "Handle": 3.0,
- "Names": names,
+ "Handle": 3.0,
+ "Names": names,
+ "PublicKey": publicKey,
},
"remoteId": map[string]interface{}{
- "Handle": 4.0,
- "Names": names,
+ "Handle": 4.0,
+ "Names": names,
+ "PublicKey": publicKey,
},
"localEndpoint": endpoint.String(),
"remoteEndpoint": "remoteEndpoint",
@@ -676,8 +691,9 @@
"Name": "adder",
"Suffix": "adder",
"RemoteID": map[string]interface{}{
- "Handle": expectedIDHandle,
- "Names": names,
+ "Handle": expectedIDHandle,
+ "Names": names,
+ "PublicKey": publicKey,
},
},
},
diff --git a/services/wsprd/identity/public_id.go b/services/wsprd/identity/public_id.go
new file mode 100644
index 0000000..7ae7a1b
--- /dev/null
+++ b/services/wsprd/identity/public_id.go
@@ -0,0 +1,24 @@
+package identity
+
+import (
+ "encoding/base64"
+ "veyron.io/veyron/veyron2/security"
+)
+
+type PublicIDHandle struct {
+ Handle int64
+ PublicKey string
+ Names []string
+}
+
+func ConvertPublicIDToHandle(id security.PublicID, handle int64) *PublicIDHandle {
+ bytes, err := id.PublicKey().MarshalBinary()
+ if err != nil {
+ panic(err)
+ }
+ return &PublicIDHandle{
+ Handle: handle,
+ PublicKey: base64.StdEncoding.EncodeToString(bytes),
+ Names: id.Names(),
+ }
+}
diff --git a/services/wsprd/ipc/server/server.go b/services/wsprd/ipc/server/server.go
index df3483a..eb31feb 100644
--- a/services/wsprd/ipc/server/server.go
+++ b/services/wsprd/ipc/server/server.go
@@ -7,6 +7,7 @@
"sync"
vsecurity "veyron.io/veyron/veyron/security"
+ "veyron.io/wspr/veyron/services/wsprd/identity"
"veyron.io/wspr/veyron/services/wsprd/lib"
"veyron.io/wspr/veyron/services/wsprd/signature"
@@ -31,16 +32,11 @@
Context serverRPCRequestContext
}
-type publicID struct {
- Handle int64
- Names []string
-}
-
// call context for a serverRPCRequest
type serverRPCRequestContext struct {
Suffix string
Name string
- RemoteID publicID
+ RemoteID identity.PublicIDHandle
}
// The response from the javascript server to the proxy.
@@ -74,14 +70,14 @@
}
type context struct {
- Method string `json:"method"`
- Name string `json:"name"`
- Suffix string `json:"suffix"`
- Label security.Label `json:"label"`
- LocalID publicID `json:"localId"`
- RemoteID publicID `json:"remoteId"`
- LocalEndpoint string `json:"localEndpoint"`
- RemoteEndpoint string `json:"remoteEndpoint"`
+ Method string `json:"method"`
+ Name string `json:"name"`
+ Suffix string `json:"suffix"`
+ Label security.Label `json:"label"`
+ LocalID identity.PublicIDHandle `json:"localId"`
+ RemoteID identity.PublicIDHandle `json:"remoteId"`
+ LocalEndpoint string `json:"localEndpoint"`
+ RemoteEndpoint string `json:"remoteEndpoint"`
}
type authRequest struct {
@@ -145,12 +141,9 @@
s.mu.Unlock()
remoteID := call.RemoteID()
context := serverRPCRequestContext{
- Suffix: call.Suffix(),
- Name: call.Name(),
- RemoteID: publicID{
- Handle: s.helper.AddIdentity(remoteID),
- Names: remoteID.Names(),
- },
+ Suffix: call.Suffix(),
+ Name: call.Name(),
+ RemoteID: s.convertPublicIDToHandle(remoteID),
}
// Send a invocation request to JavaScript
message := serverRPCRequest{
@@ -194,12 +187,8 @@
}
}
-func (s *Server) convertPublicID(id security.PublicID) publicID {
- return publicID{
- Handle: s.helper.AddIdentity(id),
- Names: id.Names(),
- }
-
+func (s *Server) convertPublicIDToHandle(id security.PublicID) identity.PublicIDHandle {
+ return *identity.ConvertPublicIDToHandle(id, s.helper.AddIdentity(id))
}
type remoteAuthFunc func(security.Context) error
@@ -219,8 +208,8 @@
Name: ctx.Name(),
Suffix: ctx.Suffix(),
Label: ctx.Label(),
- LocalID: s.convertPublicID(ctx.LocalID()),
- RemoteID: s.convertPublicID(ctx.RemoteID()),
+ LocalID: s.convertPublicIDToHandle(ctx.LocalID()),
+ RemoteID: s.convertPublicIDToHandle(ctx.RemoteID()),
LocalEndpoint: ctx.LocalEndpoint().String(),
RemoteEndpoint: ctx.RemoteEndpoint().String(),
},