blob: b26c22d48c9437d608d4c88d4c2072078aac065c [file] [log] [blame]
Jiri Simsa756772c2015-03-25 15:40:54 -07001// Copyright 2015 The Vanadium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Todd Wang88509682015-04-10 10:28:24 -07005// Package agent defines an interface to keep a private key in memory, and for
6// clients to have access to the private key.
Ryan Brown81789442014-10-30 13:23:53 -07007//
Todd Wang88509682015-04-10 10:28:24 -07008// Protocol
Ryan Brown81789442014-10-30 13:23:53 -07009//
10// The agent starts processes with the VEYRON_AGENT_FD set to one end of a
11// unix domain socket. To connect to the agent, a client should create
12// a unix domain socket pair. Then send one end of the socket to the agent
13// with 1 byte of data. The agent will then serve the Agent service on
Suharsh Sivakumar2c5d8102015-03-23 08:49:12 -070014// the received socket, using SecurityNone.
Ryan Brown81789442014-10-30 13:23:53 -070015//
16// The agent also supports an optional mode where it can manage multiple principals.
Bogdan Caprita2b219362014-12-09 17:03:33 -080017// Typically this is only used by Device Manager. In this mode, VEYRON_AGENT_FD
Ryan Brown81789442014-10-30 13:23:53 -070018// will be 3, and there will be another socket at fd 4.
19// Creating a new principal is similar to connecting to to agent: create a socket
20// pair and send one end on fd 4 with 1 byte of data.
21// Set the data to 1 to request the principal only be stored in memory.
22// The agent will create a new principal and respond with a principal handle on fd 4.
23// To connect using a previously created principal, create a socket pair and send
Ryan Brown81bcb3a2015-02-11 10:58:01 -080024// one end with the principal handle as data on fd 4. The agent will not send a
Ryan Brown81789442014-10-30 13:23:53 -070025// response on fd 4.
26// In either, you can use the normal process to connect to an agent over the
27// other end of the pair. Typically you would pass the other end to a child
28// process and set VEYRON_AGENT_FD so it knows to connect.
Ryan Brown81bcb3a2015-02-11 10:58:01 -080029//
30// The protocol also has limited support for caching: A client can
31// request notification when any other client modifies the principal so it
32// can flush the cache. See NotifyWhenChanged for details.
Todd Wang88509682015-04-10 10:28:24 -070033package agent
Ryan Brownfed691e2014-09-15 13:09:40 -070034
35import (
Jiri Simsa6ac95222015-02-23 16:11:49 -080036 "v.io/v23/security"
Ryan Brownfed691e2014-09-15 13:09:40 -070037)
38
39type Agent interface {
Todd Wang383e88c2014-12-18 01:52:34 -080040 Bless(key []byte, wit security.WireBlessings, extension string, caveat security.Caveat, additionalCaveats []security.Caveat) (security.WireBlessings | error)
41 BlessSelf(name string, caveats []security.Caveat) (security.WireBlessings | error)
42 Sign(message []byte) (security.Signature | error)
Todd Wangb31da592015-02-20 12:50:39 -080043 MintDischarge(forCaveat, caveatOnDischarge security.Caveat, additionalCaveatsOnDischarge []security.Caveat) (security.WireDischarge | error)
Todd Wang383e88c2014-12-18 01:52:34 -080044 PublicKey() ([]byte | error)
45 BlessingsByName(name security.BlessingPattern) ([]security.WireBlessings | error)
gauthamt8dc9a182015-01-08 18:03:18 -080046 BlessingsInfo(blessings security.WireBlessings) (map[string][]security.Caveat | error)
Ryan Brown81789442014-10-30 13:23:53 -070047 AddToRoots(blessing security.WireBlessings) error
Suharsh Sivakumar8a7fba42014-10-27 12:40:48 -070048
Todd Wang383e88c2014-12-18 01:52:34 -080049 BlessingStoreSet(blessings security.WireBlessings, forPeers security.BlessingPattern) (security.WireBlessings | error)
50 BlessingStoreForPeer(peerBlessings []string) (security.WireBlessings | error)
Ryan Brown81789442014-10-30 13:23:53 -070051 BlessingStoreSetDefault(blessings security.WireBlessings) error
Todd Wang383e88c2014-12-18 01:52:34 -080052 BlessingStoreDefault() (security.WireBlessings | error)
53 BlessingStorePeerBlessings() (map[security.BlessingPattern]security.WireBlessings | error)
54 BlessingStoreDebugString() (string | error)
Suharsh Sivakumard7d4e222015-06-22 11:10:44 -070055 BlessingStoreCacheDischarge(discharge security.WireDischarge, caveat security.Caveat, impetus security.DischargeImpetus) error
56 BlessingStoreClearDischarges(discharges []security.WireDischarge) error
57 BlessingStoreDischarge(caveat security.Caveat, impetus security.DischargeImpetus) (wd security.WireDischarge | error)
Suharsh Sivakumar8a7fba42014-10-27 12:40:48 -070058
Ryan Brown81789442014-10-30 13:23:53 -070059 BlessingRootsAdd(root []byte, pattern security.BlessingPattern) error
60 BlessingRootsRecognized(root []byte, blessing string) error
Ankur9e5b7722015-04-28 15:00:25 -070061 BlessingRootsDump() (map[security.BlessingPattern][][]byte | error)
Todd Wang383e88c2014-12-18 01:52:34 -080062 BlessingRootsDebugString() (string | error)
Ryan Brown81bcb3a2015-02-11 10:58:01 -080063
64 // Clients using caching should call NotifyWhenChanged upon connecting to
65 // the server. The server will stream back values whenever the client should
66 // flush the cache. The streamed value is arbitrary, simply flush whenever
67 // recieving a new item.
68 NotifyWhenChanged() stream<_, bool> error
Ryan Brownfed691e2014-09-15 13:09:40 -070069}
Ryan Brown6a6768c2015-08-04 11:22:33 -070070
71type ConnInfo struct {
72 MinVersion, MaxVersion int32
73}
74
75type RpcRequest struct {
76 Id uint64
77 Method string
78 NumArgs uint32
79}
80
81type RpcResponse struct {
82 Id uint64
83 Err error
84 NumArgs uint32
85}
86
87type RpcMessage union {
88 Req RpcRequest
89 Resp RpcResponse
90}