Suharsh Sivakumar | 1d61f64 | 2015-02-17 20:56:14 -0800 | [diff] [blame^] | 1 | // The following enables go generate to generate the doc.go file. |
| 2 | //go:generate go run $VANADIUM_ROOT/release/go/src/v.io/lib/cmdline/testdata/gendoc.go . |
| 3 | |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 4 | package main |
| 5 | |
| 6 | import ( |
| 7 | "bytes" |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 8 | "crypto/rand" |
| 9 | "crypto/subtle" |
Asim Shankar | b3a82ba | 2014-10-29 11:41:27 -0700 | [diff] [blame] | 10 | "encoding/base64" |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 11 | "errors" |
| 12 | "fmt" |
| 13 | "io" |
| 14 | "os" |
| 15 | "os/user" |
| 16 | "time" |
| 17 | |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 18 | _ "v.io/core/veyron/profiles/static" |
Jiri Simsa | 764efb7 | 2014-12-25 20:57:03 -0800 | [diff] [blame] | 19 | vsecurity "v.io/core/veyron/security" |
Jiri Simsa | 764efb7 | 2014-12-25 20:57:03 -0800 | [diff] [blame] | 20 | "v.io/core/veyron2" |
Matt Rosencrantz | 89445a4 | 2015-01-05 13:32:37 -0800 | [diff] [blame] | 21 | "v.io/core/veyron2/context" |
Jiri Simsa | 764efb7 | 2014-12-25 20:57:03 -0800 | [diff] [blame] | 22 | "v.io/core/veyron2/ipc" |
Jiri Simsa | 764efb7 | 2014-12-25 20:57:03 -0800 | [diff] [blame] | 23 | "v.io/core/veyron2/security" |
Todd Wang | 3425a90 | 2015-01-21 18:43:59 -0800 | [diff] [blame] | 24 | "v.io/core/veyron2/vom" |
Todd Wang | 478fcf9 | 2014-12-26 12:37:37 -0800 | [diff] [blame] | 25 | "v.io/lib/cmdline" |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | var ( |
| 29 | // Flags for the "blessself" command |
Suharsh Sivakumar | 1d61f64 | 2015-02-17 20:56:14 -0800 | [diff] [blame^] | 30 | flagBlessSelfCaveats caveatsFlag |
| 31 | flagBlessSelfFor time.Duration |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 32 | |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 33 | // Flags for the "bless" command |
Suharsh Sivakumar | 1d61f64 | 2015-02-17 20:56:14 -0800 | [diff] [blame^] | 34 | flagBlessCaveats caveatsFlag |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 35 | flagBlessFor time.Duration |
| 36 | flagBlessWith string |
| 37 | flagBlessRemoteKey string |
| 38 | flagBlessRemoteToken string |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 39 | |
Ankur | 77c32ac | 2014-12-18 14:18:19 -0800 | [diff] [blame] | 40 | // Flags for the "fork" command |
Suharsh Sivakumar | 1d61f64 | 2015-02-17 20:56:14 -0800 | [diff] [blame^] | 41 | flagForkCaveats caveatsFlag |
| 42 | flagForkFor time.Duration |
| 43 | flagForkWith string |
Ankur | 77c32ac | 2014-12-18 14:18:19 -0800 | [diff] [blame] | 44 | |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 45 | // Flags for the "seekblessings" command |
| 46 | flagSeekBlessingsFrom string |
| 47 | flagSeekBlessingsSetDefault bool |
| 48 | flagSeekBlessingsForPeer string |
Suharsh Sivakumar | a76dba6 | 2014-12-22 16:00:34 -0800 | [diff] [blame] | 49 | flagSeekBlessingsBrowser bool |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 50 | |
| 51 | // Flags common to many commands |
Ankur | c24ff42 | 2014-12-16 17:59:26 -0800 | [diff] [blame] | 52 | flagAddToRoots bool |
| 53 | flagCreateOverwrite bool |
Ankur | 1d46f55 | 2014-10-09 12:13:31 -0700 | [diff] [blame] | 54 | |
Ankur | e548f39 | 2014-12-08 18:42:41 -0800 | [diff] [blame] | 55 | // Flags for the "recvblessings" command |
| 56 | flagRecvBlessingsSetDefault bool |
| 57 | flagRecvBlessingsForPeer string |
| 58 | |
Ankur | 1615a7d | 2014-10-09 11:58:02 -0700 | [diff] [blame] | 59 | cmdDump = &cmdline.Command{ |
| 60 | Name: "dump", |
| 61 | Short: "Dump out information about the principal", |
| 62 | Long: ` |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 63 | Prints out information about the principal specified by the environment |
Asim Shankar | 1789b8a | 2014-10-31 17:31:41 -0700 | [diff] [blame] | 64 | that this tool is running in. |
Ankur | 1615a7d | 2014-10-09 11:58:02 -0700 | [diff] [blame] | 65 | `, |
| 66 | Run: func(cmd *cmdline.Command, args []string) error { |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 67 | ctx, shutdown := veyron2.Init() |
| 68 | defer shutdown() |
Matt Rosencrantz | 574d5e1 | 2014-11-26 10:01:37 -0800 | [diff] [blame] | 69 | |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 70 | p := veyron2.GetPrincipal(ctx) |
Ankur | 1615a7d | 2014-10-09 11:58:02 -0700 | [diff] [blame] | 71 | fmt.Printf("Public key : %v\n", p.PublicKey()) |
Ankur | 1615a7d | 2014-10-09 11:58:02 -0700 | [diff] [blame] | 72 | fmt.Println("---------------- BlessingStore ----------------") |
| 73 | fmt.Printf("%v", p.BlessingStore().DebugString()) |
Ankur | 1615a7d | 2014-10-09 11:58:02 -0700 | [diff] [blame] | 74 | fmt.Println("---------------- BlessingRoots ----------------") |
| 75 | fmt.Printf("%v", p.Roots().DebugString()) |
| 76 | return nil |
| 77 | }, |
| 78 | } |
| 79 | |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 80 | cmdDumpBlessings = &cmdline.Command{ |
| 81 | Name: "dumpblessings", |
| 82 | Short: "Dump out information about the provided blessings", |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 83 | Long: ` |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 84 | Prints out information about the blessings (typically obtained from this tool) |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 85 | encoded in the provided file. |
| 86 | `, |
| 87 | ArgsName: "<file>", |
| 88 | ArgsLong: ` |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 89 | <file> is the path to a file containing blessings typically obtained from |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 90 | this tool. - is used for STDIN. |
| 91 | `, |
| 92 | Run: func(cmd *cmdline.Command, args []string) error { |
| 93 | if len(args) != 1 { |
| 94 | return fmt.Errorf("requires exactly one argument, <file>, provided %d", len(args)) |
| 95 | } |
| 96 | blessings, err := decodeBlessings(args[0]) |
| 97 | if err != nil { |
| 98 | return fmt.Errorf("failed to decode provided blessings: %v", err) |
| 99 | } |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 100 | wire := security.MarshalBlessings(blessings) |
| 101 | fmt.Printf("Blessings : %v\n", blessings) |
| 102 | fmt.Printf("PublicKey : %v\n", blessings.PublicKey()) |
Asim Shankar | df88a2e | 2014-10-21 17:20:28 -0700 | [diff] [blame] | 103 | fmt.Printf("Certificate chains : %d\n", len(wire.CertificateChains)) |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 104 | for idx, chain := range wire.CertificateChains { |
Asim Shankar | df88a2e | 2014-10-21 17:20:28 -0700 | [diff] [blame] | 105 | fmt.Printf("Chain #%d (%d certificates). Root certificate public key: %v\n", idx, len(chain), rootkey(chain)) |
| 106 | for certidx, cert := range chain { |
| 107 | fmt.Printf(" Certificate #%d: %v with ", certidx, cert.Extension) |
| 108 | switch n := len(cert.Caveats); n { |
| 109 | case 1: |
| 110 | fmt.Printf("1 caveat") |
| 111 | default: |
| 112 | fmt.Printf("%d caveats", n) |
| 113 | } |
| 114 | fmt.Println("") |
| 115 | for cavidx, cav := range cert.Caveats { |
| 116 | fmt.Printf(" (%d) %v\n", cavidx, &cav) |
| 117 | } |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 118 | } |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 119 | } |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 120 | return nil |
| 121 | }, |
| 122 | } |
| 123 | |
| 124 | cmdBlessSelf = &cmdline.Command{ |
| 125 | Name: "blessself", |
| 126 | Short: "Generate a self-signed blessing", |
| 127 | Long: ` |
Asim Shankar | 1789b8a | 2014-10-31 17:31:41 -0700 | [diff] [blame] | 128 | Returns a blessing with name <name> and self-signed by the principal specified |
| 129 | by the environment that this tool is running in. Optionally, the blessing can |
Suharsh Sivakumar | 1d61f64 | 2015-02-17 20:56:14 -0800 | [diff] [blame^] | 130 | be restricted with an expiry caveat specified using the --for flag. Additional |
| 131 | caveats can be added with the --caveat flag. |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 132 | `, |
| 133 | ArgsName: "[<name>]", |
| 134 | ArgsLong: ` |
| 135 | <name> is the name used to create the self-signed blessing. If not |
| 136 | specified, a name will be generated based on the hostname of the |
| 137 | machine and the name of the user running this command. |
| 138 | `, |
| 139 | Run: func(cmd *cmdline.Command, args []string) error { |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 140 | var name string |
| 141 | switch len(args) { |
| 142 | case 0: |
| 143 | name = defaultBlessingName() |
| 144 | case 1: |
| 145 | name = args[0] |
| 146 | default: |
| 147 | return fmt.Errorf("requires at most one argument, provided %d", len(args)) |
| 148 | } |
| 149 | |
Suharsh Sivakumar | 1d61f64 | 2015-02-17 20:56:14 -0800 | [diff] [blame^] | 150 | caveats, err := flagBlessSelfCaveats.Compile() |
| 151 | if err != nil { |
| 152 | return fmt.Errorf("failed to parse caveats: %v", err) |
| 153 | } |
| 154 | |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 155 | if flagBlessSelfFor != 0 { |
| 156 | cav, err := security.ExpiryCaveat(time.Now().Add(flagBlessSelfFor)) |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 157 | if err != nil { |
Ankur | 8d30412 | 2014-10-07 10:43:43 -0700 | [diff] [blame] | 158 | return fmt.Errorf("failed to create expiration Caveat: %v", err) |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 159 | } |
| 160 | caveats = append(caveats, cav) |
| 161 | } |
Matt Rosencrantz | 574d5e1 | 2014-11-26 10:01:37 -0800 | [diff] [blame] | 162 | |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 163 | ctx, shutdown := veyron2.Init() |
| 164 | defer shutdown() |
| 165 | principal := veyron2.GetPrincipal(ctx) |
Matt Rosencrantz | f1c3b44 | 2015-01-12 17:53:08 -0800 | [diff] [blame] | 166 | blessing, err := principal.BlessSelf(name, caveats...) |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 167 | if err != nil { |
| 168 | return fmt.Errorf("failed to create self-signed blessing for name %q: %v", name, err) |
| 169 | } |
| 170 | |
| 171 | return dumpBlessings(blessing) |
| 172 | }, |
| 173 | } |
| 174 | |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 175 | cmdBless = &cmdline.Command{ |
| 176 | Name: "bless", |
| 177 | Short: "Bless another principal", |
| 178 | Long: ` |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 179 | Bless another principal. |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 180 | |
Ankur | c24ff42 | 2014-12-16 17:59:26 -0800 | [diff] [blame] | 181 | The blesser is obtained from the runtime this tool is using. The blessing that |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 182 | will be extended is the default one from the blesser's store, or specified by |
Suharsh Sivakumar | 1d61f64 | 2015-02-17 20:56:14 -0800 | [diff] [blame^] | 183 | the --with flag. Expiration on the blessing are controlled via the --for flag. |
| 184 | Additional caveats are controlled with the --caveat flag. |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 185 | |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 186 | For example, let's say a principal "alice" wants to bless another principal "bob" |
| 187 | as "alice/friend", the invocation would be: |
| 188 | VEYRON_CREDENTIALS=<path to alice> principal bless <path to bob> friend |
| 189 | and this will dump the blessing to STDOUT. |
| 190 | |
| 191 | With the --remote_key and --remote_token flags, this command can be used to |
| 192 | bless a principal on a remote machine as well. In this case, the blessing is |
| 193 | not dumped to STDOUT but sent to the remote end. Use 'principal help |
| 194 | recvblessings' for more details on that. |
| 195 | `, |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 196 | ArgsName: "<principal to bless> <extension>", |
| 197 | ArgsLong: ` |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 198 | <principal to bless> represents the principal to be blessed (i.e., whose public |
| 199 | key will be provided with a name). This can be either: |
| 200 | (a) The directory containing credentials for that principal, |
| 201 | OR |
| 202 | (b) The filename (- for STDIN) containing any other blessings of that |
| 203 | principal, |
| 204 | OR |
| 205 | (c) The object name produced by the 'recvblessings' command of this tool |
| 206 | running on behalf of another principal (if the --remote_key and |
| 207 | --remote_token flags are specified). |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 208 | |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 209 | <extension> is the string extension that will be applied to create the |
| 210 | blessing. |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 211 | `, |
| 212 | Run: func(cmd *cmdline.Command, args []string) error { |
| 213 | if len(args) != 2 { |
| 214 | return fmt.Errorf("require exactly two arguments, provided %d", len(args)) |
| 215 | } |
Matt Rosencrantz | 574d5e1 | 2014-11-26 10:01:37 -0800 | [diff] [blame] | 216 | |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 217 | ctx, shutdown := veyron2.Init() |
| 218 | defer shutdown() |
Matt Rosencrantz | 574d5e1 | 2014-11-26 10:01:37 -0800 | [diff] [blame] | 219 | |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 220 | p := veyron2.GetPrincipal(ctx) |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 221 | |
Suharsh Sivakumar | 1d61f64 | 2015-02-17 20:56:14 -0800 | [diff] [blame^] | 222 | var ( |
| 223 | err error |
| 224 | with security.Blessings |
| 225 | ) |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 226 | if len(flagBlessWith) > 0 { |
| 227 | if with, err = decodeBlessings(flagBlessWith); err != nil { |
| 228 | return fmt.Errorf("failed to read blessings from --with=%q: %v", flagBlessWith, err) |
| 229 | } |
| 230 | } else { |
| 231 | with = p.BlessingStore().Default() |
| 232 | } |
| 233 | |
Suharsh Sivakumar | 1d61f64 | 2015-02-17 20:56:14 -0800 | [diff] [blame^] | 234 | caveats, err := flagBlessCaveats.Compile() |
| 235 | if err != nil { |
| 236 | return fmt.Errorf("failed to parse caveats: %v", err) |
| 237 | } |
| 238 | |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 239 | if c, err := security.ExpiryCaveat(time.Now().Add(flagBlessFor)); err != nil { |
| 240 | return fmt.Errorf("failed to create ExpiryCaveat: %v", err) |
| 241 | } else { |
| 242 | caveats = append(caveats, c) |
| 243 | } |
Suharsh Sivakumar | 1d61f64 | 2015-02-17 20:56:14 -0800 | [diff] [blame^] | 244 | |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 245 | tobless, extension := args[0], args[1] |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 246 | if (len(flagBlessRemoteKey) == 0) != (len(flagBlessRemoteToken) == 0) { |
| 247 | return fmt.Errorf("either both --remote_key and --remote_token should be set, or neither should") |
| 248 | } |
| 249 | if len(flagBlessRemoteKey) > 0 { |
| 250 | // Send blessings to a "server" started by a "recvblessings" command |
| 251 | granter := &granter{p, with, extension, caveats, flagBlessRemoteKey} |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 252 | return sendBlessings(ctx, tobless, granter, flagBlessRemoteToken) |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 253 | } |
| 254 | // Blessing a principal whose key is available locally. |
| 255 | var key security.PublicKey |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 256 | if finfo, err := os.Stat(tobless); err == nil && finfo.IsDir() { |
Suharsh Sivakumar | aca1c32 | 2014-10-21 11:27:32 -0700 | [diff] [blame] | 257 | other, err := vsecurity.LoadPersistentPrincipal(tobless, nil) |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 258 | if err != nil { |
Suharsh Sivakumar | aca1c32 | 2014-10-21 11:27:32 -0700 | [diff] [blame] | 259 | if other, err = vsecurity.CreatePersistentPrincipal(tobless, nil); err != nil { |
| 260 | return fmt.Errorf("failed to read principal in directory %q: %v", tobless, err) |
| 261 | } |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 262 | } |
| 263 | key = other.PublicKey() |
| 264 | } else if other, err := decodeBlessings(tobless); err != nil { |
| 265 | return fmt.Errorf("failed to decode blessings in %q: %v", tobless, err) |
| 266 | } else { |
| 267 | key = other.PublicKey() |
| 268 | } |
| 269 | |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 270 | blessings, err := p.Bless(key, with, extension, caveats[0], caveats[1:]...) |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 271 | if err != nil { |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 272 | return fmt.Errorf("Bless(%v, %v, %q, ...) failed: %v", key, with, extension, err) |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 273 | } |
| 274 | return dumpBlessings(blessings) |
| 275 | }, |
| 276 | } |
| 277 | |
| 278 | cmdStoreForPeer = &cmdline.Command{ |
| 279 | Name: "forpeer", |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 280 | Short: "Return blessings marked for the provided peer", |
| 281 | Long: ` |
| 282 | Returns blessings that are marked for the provided peer in the |
Asim Shankar | 1789b8a | 2014-10-31 17:31:41 -0700 | [diff] [blame] | 283 | BlessingStore specified by the environment that this tool is |
| 284 | running in. |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 285 | `, |
| 286 | ArgsName: "[<peer_1> ... <peer_k>]", |
| 287 | ArgsLong: ` |
| 288 | <peer_1> ... <peer_k> are the (human-readable string) blessings bound |
| 289 | to the peer. The returned blessings are marked with a pattern that is |
| 290 | matched by at least one of these. If no arguments are specified, |
| 291 | store.forpeer returns the blessings that are marked for all peers (i.e., |
| 292 | blessings set on the store with the "..." pattern). |
| 293 | `, |
| 294 | Run: func(cmd *cmdline.Command, args []string) error { |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 295 | ctx, shutdown := veyron2.Init() |
| 296 | defer shutdown() |
| 297 | principal := veyron2.GetPrincipal(ctx) |
Matt Rosencrantz | f1c3b44 | 2015-01-12 17:53:08 -0800 | [diff] [blame] | 298 | return dumpBlessings(principal.BlessingStore().ForPeer(args...)) |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 299 | }, |
| 300 | } |
| 301 | |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 302 | cmdStoreDefault = &cmdline.Command{ |
| 303 | Name: "default", |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 304 | Short: "Return blessings marked as default", |
| 305 | Long: ` |
Asim Shankar | 1789b8a | 2014-10-31 17:31:41 -0700 | [diff] [blame] | 306 | Returns blessings that are marked as default in the BlessingStore specified by |
| 307 | the environment that this tool is running in. |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 308 | `, |
| 309 | Run: func(cmd *cmdline.Command, args []string) error { |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 310 | ctx, shutdown := veyron2.Init() |
| 311 | defer shutdown() |
| 312 | principal := veyron2.GetPrincipal(ctx) |
Matt Rosencrantz | f1c3b44 | 2015-01-12 17:53:08 -0800 | [diff] [blame] | 313 | return dumpBlessings(principal.BlessingStore().Default()) |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 314 | }, |
| 315 | } |
Ankur | 8d30412 | 2014-10-07 10:43:43 -0700 | [diff] [blame] | 316 | |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 317 | cmdStoreSet = &cmdline.Command{ |
| 318 | Name: "set", |
Ankur | 8d30412 | 2014-10-07 10:43:43 -0700 | [diff] [blame] | 319 | Short: "Set provided blessings for peer", |
| 320 | Long: ` |
Asim Shankar | 1789b8a | 2014-10-31 17:31:41 -0700 | [diff] [blame] | 321 | Marks the provided blessings to be shared with the provided peers on the |
| 322 | BlessingStore specified by the environment that this tool is running in. |
Ankur | 8d30412 | 2014-10-07 10:43:43 -0700 | [diff] [blame] | 323 | |
| 324 | 'set b pattern' marks the intention to reveal b to peers who |
| 325 | present blessings of their own matching 'pattern'. |
| 326 | |
| 327 | 'set nil pattern' can be used to remove the blessings previously |
| 328 | associated with the pattern (by a prior 'set' command). |
| 329 | |
| 330 | It is an error to call 'store.set' with blessings whose public |
| 331 | key does not match the public key of this principal specified |
| 332 | by the environment. |
| 333 | `, |
| 334 | ArgsName: "<file> <pattern>", |
| 335 | ArgsLong: ` |
| 336 | <file> is the path to a file containing a blessing typically obtained |
| 337 | from this tool. - is used for STDIN. |
| 338 | |
| 339 | <pattern> is the BlessingPattern used to identify peers with whom this |
| 340 | blessing can be shared with. |
| 341 | `, |
| 342 | Run: func(cmd *cmdline.Command, args []string) error { |
| 343 | if len(args) != 2 { |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 344 | return fmt.Errorf("requires exactly two arguments <file>, <pattern>, provided %d", len(args)) |
Ankur | 8d30412 | 2014-10-07 10:43:43 -0700 | [diff] [blame] | 345 | } |
| 346 | blessings, err := decodeBlessings(args[0]) |
| 347 | if err != nil { |
| 348 | return fmt.Errorf("failed to decode provided blessings: %v", err) |
| 349 | } |
| 350 | pattern := security.BlessingPattern(args[1]) |
Matt Rosencrantz | 574d5e1 | 2014-11-26 10:01:37 -0800 | [diff] [blame] | 351 | |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 352 | ctx, shutdown := veyron2.Init() |
| 353 | defer shutdown() |
Matt Rosencrantz | 574d5e1 | 2014-11-26 10:01:37 -0800 | [diff] [blame] | 354 | |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 355 | p := veyron2.GetPrincipal(ctx) |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 356 | if _, err := p.BlessingStore().Set(blessings, pattern); err != nil { |
Ankur | 8d30412 | 2014-10-07 10:43:43 -0700 | [diff] [blame] | 357 | return fmt.Errorf("failed to set blessings %v for peers %v: %v", blessings, pattern, err) |
| 358 | } |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 359 | if flagAddToRoots { |
| 360 | if err := p.AddToRoots(blessings); err != nil { |
| 361 | return fmt.Errorf("AddToRoots failed: %v", err) |
| 362 | } |
| 363 | } |
Ankur | 8d30412 | 2014-10-07 10:43:43 -0700 | [diff] [blame] | 364 | return nil |
| 365 | }, |
| 366 | } |
| 367 | |
Mike Burrows | 367515e | 2014-12-02 11:30:18 -0800 | [diff] [blame] | 368 | cmdStoreAddToRoots = &cmdline.Command{ |
| 369 | Name: "addtoroots", |
| 370 | Short: "Add provided blessings to root set", |
| 371 | Long: ` |
| 372 | Adds the provided blessings to the set of trusted roots for this principal. |
| 373 | |
| 374 | 'addtoroots b' adds blessings b to the trusted root set. |
| 375 | |
| 376 | For example, to make the principal in credentials directory A trust the |
| 377 | root of the default blessing in credentials directory B: |
| 378 | principal -veyron.credentials=B bless A some_extension | |
| 379 | principal -veyron.credentials=A store addtoroots - |
| 380 | |
| 381 | The extension 'some_extension' has no effect in the command above. |
| 382 | `, |
| 383 | ArgsName: "<file>", |
| 384 | ArgsLong: ` |
| 385 | <file> is the path to a file containing a blessing typically obtained |
| 386 | from this tool. - is used for STDIN. |
| 387 | `, |
| 388 | Run: func(cmd *cmdline.Command, args []string) error { |
| 389 | if len(args) != 1 { |
| 390 | return fmt.Errorf("requires exactly one argument <file>, provided %d", len(args)) |
| 391 | } |
| 392 | blessings, err := decodeBlessings(args[0]) |
| 393 | if err != nil { |
| 394 | return fmt.Errorf("failed to decode provided blessings: %v", err) |
| 395 | } |
| 396 | |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 397 | ctx, shutdown := veyron2.Init() |
| 398 | defer shutdown() |
Mike Burrows | 367515e | 2014-12-02 11:30:18 -0800 | [diff] [blame] | 399 | |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 400 | p := veyron2.GetPrincipal(ctx) |
Mike Burrows | 367515e | 2014-12-02 11:30:18 -0800 | [diff] [blame] | 401 | if err := p.AddToRoots(blessings); err != nil { |
| 402 | return fmt.Errorf("AddToRoots failed: %v", err) |
| 403 | } |
| 404 | return nil |
| 405 | }, |
| 406 | } |
| 407 | |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 408 | cmdStoreSetDefault = &cmdline.Command{ |
| 409 | Name: "setdefault", |
Ankur | 8d30412 | 2014-10-07 10:43:43 -0700 | [diff] [blame] | 410 | Short: "Set provided blessings as default", |
| 411 | Long: ` |
Asim Shankar | 1789b8a | 2014-10-31 17:31:41 -0700 | [diff] [blame] | 412 | Sets the provided blessings as default in the BlessingStore specified by the |
| 413 | environment that this tool is running in. |
Ankur | 8d30412 | 2014-10-07 10:43:43 -0700 | [diff] [blame] | 414 | |
Asim Shankar | 1789b8a | 2014-10-31 17:31:41 -0700 | [diff] [blame] | 415 | It is an error to call 'store.setdefault' with blessings whose public key does |
| 416 | not match the public key of the principal specified by the environment. |
Ankur | 8d30412 | 2014-10-07 10:43:43 -0700 | [diff] [blame] | 417 | `, |
| 418 | ArgsName: "<file>", |
| 419 | ArgsLong: ` |
| 420 | <file> is the path to a file containing a blessing typically obtained from |
| 421 | this tool. - is used for STDIN. |
| 422 | `, |
| 423 | Run: func(cmd *cmdline.Command, args []string) error { |
| 424 | if len(args) != 1 { |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 425 | return fmt.Errorf("requires exactly one argument, <file>, provided %d", len(args)) |
Ankur | 8d30412 | 2014-10-07 10:43:43 -0700 | [diff] [blame] | 426 | } |
| 427 | blessings, err := decodeBlessings(args[0]) |
| 428 | if err != nil { |
| 429 | return fmt.Errorf("failed to decode provided blessings: %v", err) |
| 430 | } |
Matt Rosencrantz | 574d5e1 | 2014-11-26 10:01:37 -0800 | [diff] [blame] | 431 | |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 432 | ctx, shutdown := veyron2.Init() |
| 433 | defer shutdown() |
Matt Rosencrantz | 574d5e1 | 2014-11-26 10:01:37 -0800 | [diff] [blame] | 434 | |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 435 | p := veyron2.GetPrincipal(ctx) |
Asim Shankar | 1789b8a | 2014-10-31 17:31:41 -0700 | [diff] [blame] | 436 | if err := p.BlessingStore().SetDefault(blessings); err != nil { |
Ankur | 8d30412 | 2014-10-07 10:43:43 -0700 | [diff] [blame] | 437 | return fmt.Errorf("failed to set blessings %v as default: %v", blessings, err) |
| 438 | } |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 439 | if flagAddToRoots { |
| 440 | if err := p.AddToRoots(blessings); err != nil { |
| 441 | return fmt.Errorf("AddToRoots failed: %v", err) |
| 442 | } |
| 443 | } |
| 444 | return nil |
| 445 | }, |
| 446 | } |
| 447 | |
| 448 | cmdCreate = &cmdline.Command{ |
| 449 | Name: "create", |
| 450 | Short: "Create a new principal and persist it into a directory", |
| 451 | Long: ` |
Ankur | 4704f5f | 2014-10-23 12:40:54 -0700 | [diff] [blame] | 452 | Creates a new principal with a single self-blessed blessing and writes it out |
Ankur | c24ff42 | 2014-12-16 17:59:26 -0800 | [diff] [blame] | 453 | to the provided directory. The same directory can then be used to set the |
| 454 | VEYRON_CREDENTIALS environment variable for other veyron applications. |
Ankur | 4704f5f | 2014-10-23 12:40:54 -0700 | [diff] [blame] | 455 | |
| 456 | The operation fails if the directory already contains a principal. In this case |
Ankur | c24ff42 | 2014-12-16 17:59:26 -0800 | [diff] [blame] | 457 | the --overwrite flag can be provided to clear the directory and write out the |
gauthamt | b7bb39b | 2014-11-10 11:40:41 -0800 | [diff] [blame] | 458 | new principal. |
Ankur | 4704f5f | 2014-10-23 12:40:54 -0700 | [diff] [blame] | 459 | `, |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 460 | ArgsName: "<directory> <blessing>", |
| 461 | ArgsLong: ` |
Ankur | c24ff42 | 2014-12-16 17:59:26 -0800 | [diff] [blame] | 462 | <directory> is the directory to which the new principal will be persisted. |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 463 | <blessing> is the self-blessed blessing that the principal will be setup to use by default. |
| 464 | `, |
| 465 | Run: func(cmd *cmdline.Command, args []string) error { |
| 466 | if len(args) != 2 { |
| 467 | return fmt.Errorf("requires exactly two arguments: <directory> and <blessing>, provided %d", len(args)) |
| 468 | } |
| 469 | dir, name := args[0], args[1] |
Ankur | 4704f5f | 2014-10-23 12:40:54 -0700 | [diff] [blame] | 470 | if flagCreateOverwrite { |
Ankur | c24ff42 | 2014-12-16 17:59:26 -0800 | [diff] [blame] | 471 | if err := os.RemoveAll(dir); err != nil { |
gauthamt | b7bb39b | 2014-11-10 11:40:41 -0800 | [diff] [blame] | 472 | return err |
| 473 | } |
Ankur | 4704f5f | 2014-10-23 12:40:54 -0700 | [diff] [blame] | 474 | } |
Ankur | c24ff42 | 2014-12-16 17:59:26 -0800 | [diff] [blame] | 475 | p, err := vsecurity.CreatePersistentPrincipal(dir, nil) |
Suharsh Sivakumar | aca1c32 | 2014-10-21 11:27:32 -0700 | [diff] [blame] | 476 | if err != nil { |
| 477 | return err |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 478 | } |
| 479 | blessings, err := p.BlessSelf(name) |
| 480 | if err != nil { |
| 481 | return fmt.Errorf("BlessSelf(%q) failed: %v", name, err) |
| 482 | } |
Ankur | c24ff42 | 2014-12-16 17:59:26 -0800 | [diff] [blame] | 483 | if err := vsecurity.SetDefaultBlessings(p, blessings); err != nil { |
| 484 | return fmt.Errorf("could not set blessings %v as default: %v", blessings, err) |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 485 | } |
Ankur | c24ff42 | 2014-12-16 17:59:26 -0800 | [diff] [blame] | 486 | return nil |
| 487 | }, |
| 488 | } |
| 489 | |
| 490 | cmdFork = &cmdline.Command{ |
| 491 | Name: "fork", |
| 492 | Short: "Fork a new principal from the principal that this tool is running as and persist it into a directory", |
| 493 | Long: ` |
| 494 | Creates a new principal with a blessing from the principal specified by the |
| 495 | environment that this tool is running in, and writes it out to the provided |
| 496 | directory. The blessing that will be extended is the default one from the |
Suharsh Sivakumar | 1d61f64 | 2015-02-17 20:56:14 -0800 | [diff] [blame^] | 497 | blesser's store, or specified by the --with flag. Expiration on the blessing |
| 498 | are controlled via the --for flag. Additional caveats on the blessing are |
| 499 | controlled with the --caveat flag. The blessing is marked as default and |
Ankur | c24ff42 | 2014-12-16 17:59:26 -0800 | [diff] [blame] | 500 | shareable with all peers on the new principal's blessing store. |
| 501 | |
| 502 | The operation fails if the directory already contains a principal. In this case |
| 503 | the --overwrite flag can be provided to clear the directory and write out the |
| 504 | forked principal. |
| 505 | `, |
| 506 | ArgsName: "<directory> <extension>", |
| 507 | ArgsLong: ` |
| 508 | <directory> is the directory to which the forked principal will be persisted. |
| 509 | <extension> is the extension under which the forked principal is blessed. |
| 510 | `, |
| 511 | Run: func(cmd *cmdline.Command, args []string) error { |
| 512 | if len(args) != 2 { |
| 513 | return fmt.Errorf("requires exactly two arguments: <directory> and <extension>, provided %d", len(args)) |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 514 | } |
Ankur | c24ff42 | 2014-12-16 17:59:26 -0800 | [diff] [blame] | 515 | dir, extension := args[0], args[1] |
| 516 | |
| 517 | if flagCreateOverwrite { |
| 518 | if err := os.RemoveAll(dir); err != nil { |
| 519 | return err |
| 520 | } |
| 521 | } |
| 522 | p, err := vsecurity.CreatePersistentPrincipal(dir, nil) |
| 523 | if err != nil { |
| 524 | return err |
| 525 | } |
| 526 | |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 527 | ctx, shutdown := veyron2.Init() |
| 528 | defer shutdown() |
Ankur | c24ff42 | 2014-12-16 17:59:26 -0800 | [diff] [blame] | 529 | |
Suharsh Sivakumar | 1d61f64 | 2015-02-17 20:56:14 -0800 | [diff] [blame^] | 530 | caveats, err := flagForkCaveats.Compile() |
| 531 | if err != nil { |
| 532 | return fmt.Errorf("failed to parse caveats: %v", err) |
| 533 | } |
| 534 | |
| 535 | var with security.Blessings |
Ankur | 77c32ac | 2014-12-18 14:18:19 -0800 | [diff] [blame] | 536 | if len(flagForkWith) > 0 { |
| 537 | if with, err = decodeBlessings(flagForkWith); err != nil { |
| 538 | return fmt.Errorf("failed to read blessings from --with=%q: %v", flagForkWith, err) |
Ankur | c24ff42 | 2014-12-16 17:59:26 -0800 | [diff] [blame] | 539 | } |
| 540 | } else { |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 541 | with = veyron2.GetPrincipal(ctx).BlessingStore().Default() |
Ankur | c24ff42 | 2014-12-16 17:59:26 -0800 | [diff] [blame] | 542 | } |
Ankur | 77c32ac | 2014-12-18 14:18:19 -0800 | [diff] [blame] | 543 | if c, err := security.ExpiryCaveat(time.Now().Add(flagForkFor)); err != nil { |
Ankur | c24ff42 | 2014-12-16 17:59:26 -0800 | [diff] [blame] | 544 | return fmt.Errorf("failed to create ExpiryCaveat: %v", err) |
| 545 | } else { |
| 546 | caveats = append(caveats, c) |
| 547 | } |
Ankur | c24ff42 | 2014-12-16 17:59:26 -0800 | [diff] [blame] | 548 | |
| 549 | key := p.PublicKey() |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 550 | rp := veyron2.GetPrincipal(ctx) |
Matt Rosencrantz | f1c3b44 | 2015-01-12 17:53:08 -0800 | [diff] [blame] | 551 | blessings, err := rp.Bless(key, with, extension, caveats[0], caveats[1:]...) |
Ankur | c24ff42 | 2014-12-16 17:59:26 -0800 | [diff] [blame] | 552 | if err != nil { |
| 553 | return fmt.Errorf("Bless(%v, %v, %q, ...) failed: %v", key, with, extension, err) |
| 554 | } |
| 555 | if err := vsecurity.SetDefaultBlessings(p, blessings); err != nil { |
| 556 | return fmt.Errorf("could not set blessings %v as default: %v", blessings, err) |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 557 | } |
Ankur | 8d30412 | 2014-10-07 10:43:43 -0700 | [diff] [blame] | 558 | return nil |
| 559 | }, |
| 560 | } |
Ankur | 1d46f55 | 2014-10-09 12:13:31 -0700 | [diff] [blame] | 561 | |
| 562 | cmdSeekBlessings = &cmdline.Command{ |
| 563 | Name: "seekblessings", |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 564 | Short: "Seek blessings from a web-based Veyron blessing service", |
Ankur | 1d46f55 | 2014-10-09 12:13:31 -0700 | [diff] [blame] | 565 | Long: ` |
| 566 | Seeks blessings from a web-based Veyron blesser which |
| 567 | requires the caller to first authenticate with Google using OAuth. Simply |
| 568 | run the command to see what happens. |
| 569 | |
Asim Shankar | 1789b8a | 2014-10-31 17:31:41 -0700 | [diff] [blame] | 570 | The blessings are sought for the principal specified by the environment that |
| 571 | this tool is running in. |
Ankur | 1d46f55 | 2014-10-09 12:13:31 -0700 | [diff] [blame] | 572 | |
Ankur | e548f39 | 2014-12-08 18:42:41 -0800 | [diff] [blame] | 573 | The blessings obtained are set as default, unless the --set_default flag is |
| 574 | set to true, and are also set for sharing with all peers, unless a more |
Ankur | 1d46f55 | 2014-10-09 12:13:31 -0700 | [diff] [blame] | 575 | specific peer pattern is provided using the --for_peer flag. |
| 576 | `, |
| 577 | Run: func(cmd *cmdline.Command, args []string) error { |
Asim Shankar | 08ab389 | 2014-10-16 12:04:07 -0700 | [diff] [blame] | 578 | // Initialize the runtime first so that any local errors are reported |
| 579 | // before the HTTP roundtrips for obtaining the macaroon begin. |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 580 | ctx, shutdown := veyron2.Init() |
| 581 | defer shutdown() |
Matt Rosencrantz | 574d5e1 | 2014-11-26 10:01:37 -0800 | [diff] [blame] | 582 | |
Ankur | 1d46f55 | 2014-10-09 12:13:31 -0700 | [diff] [blame] | 583 | blessedChan := make(chan string) |
| 584 | defer close(blessedChan) |
Suharsh Sivakumar | a76dba6 | 2014-12-22 16:00:34 -0800 | [diff] [blame] | 585 | macaroonChan, err := getMacaroonForBlessRPC(flagSeekBlessingsFrom, blessedChan, flagSeekBlessingsBrowser) |
Ankur | 1d46f55 | 2014-10-09 12:13:31 -0700 | [diff] [blame] | 586 | if err != nil { |
| 587 | return fmt.Errorf("failed to get macaroon from Veyron blesser: %v", err) |
| 588 | } |
Ankur | 1d46f55 | 2014-10-09 12:13:31 -0700 | [diff] [blame] | 589 | |
Suharsh Sivakumar | 67ef84a | 2015-02-13 13:04:44 -0800 | [diff] [blame] | 590 | blessings, err := exchangeMacaroonForBlessing(ctx, macaroonChan) |
Ankur | 1d46f55 | 2014-10-09 12:13:31 -0700 | [diff] [blame] | 591 | if err != nil { |
Suharsh Sivakumar | 67ef84a | 2015-02-13 13:04:44 -0800 | [diff] [blame] | 592 | return err |
Ankur | 1d46f55 | 2014-10-09 12:13:31 -0700 | [diff] [blame] | 593 | } |
| 594 | blessedChan <- fmt.Sprint(blessings) |
| 595 | // Wait for getTokenForBlessRPC to clean up: |
| 596 | <-macaroonChan |
| 597 | |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 598 | p := veyron2.GetPrincipal(ctx) |
Matt Rosencrantz | f1c3b44 | 2015-01-12 17:53:08 -0800 | [diff] [blame] | 599 | |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 600 | if flagSeekBlessingsSetDefault { |
Matt Rosencrantz | f1c3b44 | 2015-01-12 17:53:08 -0800 | [diff] [blame] | 601 | if err := p.BlessingStore().SetDefault(blessings); err != nil { |
Ankur | 1d46f55 | 2014-10-09 12:13:31 -0700 | [diff] [blame] | 602 | return fmt.Errorf("failed to set blessings %v as default: %v", blessings, err) |
| 603 | } |
| 604 | } |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 605 | if pattern := security.BlessingPattern(flagSeekBlessingsForPeer); len(pattern) > 0 { |
Matt Rosencrantz | f1c3b44 | 2015-01-12 17:53:08 -0800 | [diff] [blame] | 606 | if _, err := p.BlessingStore().Set(blessings, pattern); err != nil { |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 607 | return fmt.Errorf("failed to set blessings %v for peers %v: %v", blessings, pattern, err) |
| 608 | } |
| 609 | } |
| 610 | if flagAddToRoots { |
Matt Rosencrantz | f1c3b44 | 2015-01-12 17:53:08 -0800 | [diff] [blame] | 611 | if err := p.AddToRoots(blessings); err != nil { |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 612 | return fmt.Errorf("AddToRoots failed: %v", err) |
| 613 | } |
Ankur | 1d46f55 | 2014-10-09 12:13:31 -0700 | [diff] [blame] | 614 | } |
Asim Shankar | 3f9bbab | 2015-02-15 13:51:37 -0800 | [diff] [blame] | 615 | fmt.Fprintf(cmd.Stdout(), "Received blessings: %v\n", blessings) |
Jiri Simsa | 37b0a09 | 2015-02-13 09:32:39 -0800 | [diff] [blame] | 616 | return nil |
Ankur | 1d46f55 | 2014-10-09 12:13:31 -0700 | [diff] [blame] | 617 | }, |
| 618 | } |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 619 | |
| 620 | cmdRecvBlessings = &cmdline.Command{ |
| 621 | Name: "recvblessings", |
| 622 | Short: "Receive blessings sent by another principal and use them as the default", |
| 623 | Long: ` |
| 624 | Allow another principal (likely a remote process) to bless this one. |
| 625 | |
| 626 | This command sets up the invoker (this process) to wait for a blessing |
| 627 | from another invocation of this tool (remote process) and prints out the |
| 628 | command to be run as the remote principal. |
| 629 | |
Ankur | e548f39 | 2014-12-08 18:42:41 -0800 | [diff] [blame] | 630 | The received blessings are set as default, unless the --set_default flag is |
| 631 | set to true, and are also set for sharing with all peers, unless a more |
| 632 | specific peer pattern is provided using the --for_peer flag. |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 633 | |
| 634 | TODO(ashankar,cnicolaou): Make this next paragraph possible! Requires |
| 635 | the ability to obtain the proxied endpoint. |
| 636 | |
| 637 | Typically, this command should require no arguments. |
| 638 | However, if the sender and receiver are on different network domains, it may |
| 639 | make sense to use the --veyron.proxy flag: |
Robin Thellend | 8fea01c | 2014-12-11 13:48:10 -0800 | [diff] [blame] | 640 | principal --veyron.proxy=proxy recvblessings |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 641 | |
| 642 | The command to be run at the sender is of the form: |
| 643 | principal bless --remote_key=KEY --remote_token=TOKEN ADDRESS |
| 644 | |
| 645 | The --remote_key flag is used to by the sender to "authenticate" the receiver, |
| 646 | ensuring it blesses the intended recipient and not any attacker that may have |
| 647 | taken over the address. |
| 648 | |
| 649 | The --remote_token flag is used by the sender to authenticate itself to the |
| 650 | receiver. This helps ensure that the receiver rejects blessings from senders |
| 651 | who just happened to guess the network address of the 'recvblessings' |
| 652 | invocation. |
| 653 | `, |
| 654 | Run: func(cmd *cmdline.Command, args []string) error { |
| 655 | if len(args) != 0 { |
| 656 | return fmt.Errorf("command accepts no arguments") |
| 657 | } |
Matt Rosencrantz | 574d5e1 | 2014-11-26 10:01:37 -0800 | [diff] [blame] | 658 | |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 659 | ctx, shutdown := veyron2.Init() |
| 660 | defer shutdown() |
Matt Rosencrantz | 574d5e1 | 2014-11-26 10:01:37 -0800 | [diff] [blame] | 661 | |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 662 | server, err := veyron2.NewServer(ctx) |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 663 | if err != nil { |
| 664 | return fmt.Errorf("failed to create server to listen for blessings: %v", err) |
| 665 | } |
| 666 | defer server.Stop() |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 667 | eps, err := server.Listen(veyron2.GetListenSpec(ctx)) |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 668 | if err != nil { |
| 669 | return fmt.Errorf("failed to setup listening: %v", err) |
| 670 | } |
| 671 | var token [24]byte |
| 672 | if _, err := rand.Read(token[:]); err != nil { |
| 673 | return fmt.Errorf("unable to generate token: %v", err) |
| 674 | } |
Matt Rosencrantz | f1c3b44 | 2015-01-12 17:53:08 -0800 | [diff] [blame] | 675 | |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 676 | p := veyron2.GetPrincipal(ctx) |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 677 | service := &recvBlessingsService{ |
Matt Rosencrantz | f1c3b44 | 2015-01-12 17:53:08 -0800 | [diff] [blame] | 678 | principal: p, |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 679 | token: base64.URLEncoding.EncodeToString(token[:]), |
| 680 | notify: make(chan error), |
| 681 | } |
| 682 | if err := server.Serve("", service, allowAnyone{}); err != nil { |
| 683 | return fmt.Errorf("failed to setup service: %v", err) |
| 684 | } |
| 685 | // Proposed name: |
| 686 | extension := fmt.Sprintf("extension%d", int(token[0])<<16|int(token[1])<<8|int(token[2])) |
| 687 | fmt.Println("Run the following command on behalf of the principal that will send blessings:") |
| 688 | fmt.Println("You may want to adjust flags affecting the caveats on this blessing, for example using") |
| 689 | fmt.Println("the --for flag, or change the extension to something more meaningful") |
| 690 | fmt.Println() |
Cosmos Nicolaou | 8bd8e10 | 2015-01-13 21:52:53 -0800 | [diff] [blame] | 691 | fmt.Printf("principal bless --remote_key=%v --remote_token=%v %v %v\n", p.PublicKey(), service.token, eps[0].Name(), extension) |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 692 | fmt.Println() |
| 693 | fmt.Println("...waiting for sender..") |
| 694 | return <-service.notify |
| 695 | }, |
| 696 | } |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 697 | ) |
| 698 | |
| 699 | func main() { |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 700 | cmdBlessSelf.Flags.DurationVar(&flagBlessSelfFor, "for", 0, "Duration of blessing validity (zero means no that the blessing is always valid)") |
Suharsh Sivakumar | 1d61f64 | 2015-02-17 20:56:14 -0800 | [diff] [blame^] | 701 | cmdBlessSelf.Flags.Var(&flagBlessSelfCaveats, "caveat", flagBlessSelfCaveats.usage()) |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 702 | |
Ankur | 77c32ac | 2014-12-18 14:18:19 -0800 | [diff] [blame] | 703 | cmdFork.Flags.BoolVar(&flagCreateOverwrite, "overwrite", false, "If true, any existing principal data in the directory will be overwritten") |
Suharsh Sivakumar | 1d61f64 | 2015-02-17 20:56:14 -0800 | [diff] [blame^] | 704 | cmdFork.Flags.Var(&flagForkCaveats, "caveat", flagForkCaveats.usage()) |
Ankur | 77c32ac | 2014-12-18 14:18:19 -0800 | [diff] [blame] | 705 | cmdFork.Flags.DurationVar(&flagForkFor, "for", 0, "Duration for which the forked blessing is valid (zero means no that the blessing is always valid)") |
| 706 | cmdFork.Flags.StringVar(&flagForkWith, "with", "", "Path to file containing blessing to extend") |
| 707 | |
Suharsh Sivakumar | 1d61f64 | 2015-02-17 20:56:14 -0800 | [diff] [blame^] | 708 | cmdBless.Flags.Var(&flagBlessCaveats, "caveat", flagBlessCaveats.usage()) |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 709 | cmdBless.Flags.DurationVar(&flagBlessFor, "for", time.Minute, "Duration of blessing validity") |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 710 | cmdBless.Flags.StringVar(&flagBlessWith, "with", "", "Path to file containing blessing to extend") |
| 711 | cmdBless.Flags.StringVar(&flagBlessRemoteKey, "remote_key", "", "Public key of the remote principal to bless (obtained from the 'recvblessings' command run by the remote principal") |
| 712 | cmdBless.Flags.StringVar(&flagBlessRemoteToken, "remote_token", "", "Token provided by principal running the 'recvblessings' command") |
| 713 | |
Robin Thellend | 8fea01c | 2014-12-11 13:48:10 -0800 | [diff] [blame] | 714 | cmdSeekBlessings.Flags.StringVar(&flagSeekBlessingsFrom, "from", "https://auth.dev.v.io:8125/google", "URL to use to begin the seek blessings process") |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 715 | cmdSeekBlessings.Flags.BoolVar(&flagSeekBlessingsSetDefault, "set_default", true, "If true, the blessings obtained will be set as the default blessing in the store") |
| 716 | cmdSeekBlessings.Flags.StringVar(&flagSeekBlessingsForPeer, "for_peer", string(security.AllPrincipals), "If non-empty, the blessings obtained will be marked for peers matching this pattern in the store") |
Suharsh Sivakumar | a76dba6 | 2014-12-22 16:00:34 -0800 | [diff] [blame] | 717 | cmdSeekBlessings.Flags.BoolVar(&flagSeekBlessingsBrowser, "browser", true, "If false, the seekblessings command will not open the browser and only print the url to visit.") |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 718 | cmdSeekBlessings.Flags.BoolVar(&flagAddToRoots, "add_to_roots", true, "If true, the root certificate of the blessing will be added to the principal's set of recognized root certificates") |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 719 | |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 720 | cmdStoreSet.Flags.BoolVar(&flagAddToRoots, "add_to_roots", true, "If true, the root certificate of the blessing will be added to the principal's set of recognized root certificates") |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 721 | |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 722 | cmdStoreSetDefault.Flags.BoolVar(&flagAddToRoots, "add_to_roots", true, "If true, the root certificate of the blessing will be added to the principal's set of recognized root certificates") |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 723 | |
Ankur | 4704f5f | 2014-10-23 12:40:54 -0700 | [diff] [blame] | 724 | cmdCreate.Flags.BoolVar(&flagCreateOverwrite, "overwrite", false, "If true, any existing principal data in the directory will be overwritten") |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 725 | |
Ankur | e548f39 | 2014-12-08 18:42:41 -0800 | [diff] [blame] | 726 | cmdRecvBlessings.Flags.BoolVar(&flagRecvBlessingsSetDefault, "set_default", true, "If true, the blessings received will be set as the default blessing in the store") |
| 727 | cmdRecvBlessings.Flags.StringVar(&flagRecvBlessingsForPeer, "for_peer", string(security.AllPrincipals), "If non-empty, the blessings received will be marked for peers matching this pattern in the store") |
| 728 | |
Asim Shankar | 66c52f9 | 2014-10-15 23:39:10 -0700 | [diff] [blame] | 729 | cmdStore := &cmdline.Command{ |
| 730 | Name: "store", |
| 731 | Short: "Manipulate and inspect the principal's blessing store", |
| 732 | Long: ` |
| 733 | Commands to manipulate and inspect the blessing store of the principal. |
| 734 | |
| 735 | All blessings are printed to stdout using base64-VOM-encoding |
| 736 | `, |
Mike Burrows | 367515e | 2014-12-02 11:30:18 -0800 | [diff] [blame] | 737 | Children: []*cmdline.Command{cmdStoreDefault, cmdStoreSetDefault, cmdStoreForPeer, cmdStoreSet, cmdStoreAddToRoots}, |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 738 | } |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 739 | |
Matt Rosencrantz | 92303e1 | 2015-01-21 09:02:42 -0800 | [diff] [blame] | 740 | root := &cmdline.Command{ |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 741 | Name: "principal", |
| 742 | Short: "Create and manage veyron principals", |
| 743 | Long: ` |
| 744 | The principal tool helps create and manage blessings and the set of trusted |
| 745 | roots bound to a principal. |
| 746 | |
| 747 | All objects are printed using base64-VOM-encoding. |
| 748 | `, |
Ankur | c24ff42 | 2014-12-16 17:59:26 -0800 | [diff] [blame] | 749 | Children: []*cmdline.Command{cmdCreate, cmdFork, cmdSeekBlessings, cmdRecvBlessings, cmdDump, cmdDumpBlessings, cmdBlessSelf, cmdBless, cmdStore}, |
Matt Rosencrantz | 92303e1 | 2015-01-21 09:02:42 -0800 | [diff] [blame] | 750 | } |
| 751 | os.Exit(root.Main()) |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 754 | func decodeBlessings(fname string) (security.Blessings, error) { |
| 755 | var wire security.WireBlessings |
| 756 | if err := decode(fname, &wire); err != nil { |
| 757 | return nil, err |
| 758 | } |
| 759 | return security.NewBlessings(wire) |
| 760 | } |
| 761 | |
| 762 | func dumpBlessings(blessings security.Blessings) error { |
| 763 | if blessings == nil { |
| 764 | return errors.New("no blessings found") |
| 765 | } |
Ankur | ee0aa81 | 2014-11-14 10:56:52 -0800 | [diff] [blame] | 766 | str, err := base64VomEncode(security.MarshalBlessings(blessings)) |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 767 | if err != nil { |
| 768 | return fmt.Errorf("base64-VOM encoding failed: %v", err) |
| 769 | } |
| 770 | fmt.Println(str) |
| 771 | return nil |
| 772 | } |
| 773 | |
| 774 | func read(fname string) (string, error) { |
| 775 | if len(fname) == 0 { |
| 776 | return "", nil |
| 777 | } |
| 778 | f := os.Stdin |
| 779 | if fname != "-" { |
| 780 | var err error |
| 781 | if f, err = os.Open(fname); err != nil { |
| 782 | return "", fmt.Errorf("failed to open %q: %v", fname, err) |
| 783 | } |
| 784 | } |
| 785 | defer f.Close() |
| 786 | var buf bytes.Buffer |
| 787 | if _, err := io.Copy(&buf, f); err != nil { |
| 788 | return "", fmt.Errorf("failed to read %q: %v", fname, err) |
| 789 | } |
| 790 | return buf.String(), nil |
| 791 | } |
| 792 | |
| 793 | func decode(fname string, val interface{}) error { |
| 794 | str, err := read(fname) |
| 795 | if err != nil { |
| 796 | return err |
| 797 | } |
Asim Shankar | b3a82ba | 2014-10-29 11:41:27 -0700 | [diff] [blame] | 798 | if err := base64VomDecode(str, val); err != nil || val == nil { |
Ankur | cf6a89f | 2014-10-06 18:33:03 -0700 | [diff] [blame] | 799 | return fmt.Errorf("failed to decode %q: %v", fname, err) |
| 800 | } |
| 801 | return nil |
| 802 | } |
| 803 | |
| 804 | func defaultBlessingName() string { |
| 805 | var name string |
| 806 | if user, _ := user.Current(); user != nil && len(user.Username) > 0 { |
| 807 | name = user.Username |
| 808 | } else { |
| 809 | name = "anonymous" |
| 810 | } |
| 811 | if host, _ := os.Hostname(); len(host) > 0 { |
| 812 | name = name + "@" + host |
| 813 | } |
| 814 | return name |
| 815 | } |
Asim Shankar | df88a2e | 2014-10-21 17:20:28 -0700 | [diff] [blame] | 816 | |
| 817 | func rootkey(chain []security.Certificate) string { |
| 818 | if len(chain) == 0 { |
| 819 | return "<empty certificate chain>" |
| 820 | } |
| 821 | key, err := security.UnmarshalPublicKey(chain[0].PublicKey) |
| 822 | if err != nil { |
| 823 | return fmt.Sprintf("<invalid PublicKey: %v>", err) |
| 824 | } |
| 825 | return fmt.Sprintf("%v", key) |
| 826 | } |
Asim Shankar | b3a82ba | 2014-10-29 11:41:27 -0700 | [diff] [blame] | 827 | |
| 828 | func base64VomEncode(i interface{}) (string, error) { |
| 829 | buf := &bytes.Buffer{} |
| 830 | closer := base64.NewEncoder(base64.URLEncoding, buf) |
Todd Wang | 3425a90 | 2015-01-21 18:43:59 -0800 | [diff] [blame] | 831 | enc, err := vom.NewBinaryEncoder(closer) |
Suharsh Sivakumar | 12b089d | 2015-01-02 14:17:12 -0800 | [diff] [blame] | 832 | if err != nil { |
| 833 | return "", err |
| 834 | } |
| 835 | if err := enc.Encode(i); err != nil { |
Asim Shankar | b3a82ba | 2014-10-29 11:41:27 -0700 | [diff] [blame] | 836 | return "", err |
| 837 | } |
| 838 | // Must close the base64 encoder to flush out any partially written |
| 839 | // blocks. |
| 840 | if err := closer.Close(); err != nil { |
| 841 | return "", err |
| 842 | } |
| 843 | return buf.String(), nil |
| 844 | } |
| 845 | |
| 846 | func base64VomDecode(s string, i interface{}) error { |
| 847 | b, err := base64.URLEncoding.DecodeString(s) |
| 848 | if err != nil { |
| 849 | return err |
| 850 | } |
Todd Wang | 3425a90 | 2015-01-21 18:43:59 -0800 | [diff] [blame] | 851 | dec, err := vom.NewDecoder(bytes.NewBuffer(b)) |
Suharsh Sivakumar | 12b089d | 2015-01-02 14:17:12 -0800 | [diff] [blame] | 852 | if err != nil { |
| 853 | return err |
| 854 | } |
| 855 | return dec.Decode(i) |
Asim Shankar | b3a82ba | 2014-10-29 11:41:27 -0700 | [diff] [blame] | 856 | } |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 857 | |
| 858 | type recvBlessingsService struct { |
| 859 | principal security.Principal |
| 860 | notify chan error |
| 861 | token string |
| 862 | } |
| 863 | |
| 864 | func (r *recvBlessingsService) Grant(call ipc.ServerCall, token string) error { |
| 865 | b := call.Blessings() |
| 866 | if b == nil { |
| 867 | return fmt.Errorf("no blessings granted by sender") |
| 868 | } |
| 869 | if len(token) != len(r.token) { |
| 870 | // A timing attack can be used to figure out the length |
| 871 | // of the token, but then again, so can looking at the |
| 872 | // source code. So, it's okay. |
| 873 | return fmt.Errorf("blessings received from unexpected sender") |
| 874 | } |
| 875 | if subtle.ConstantTimeCompare([]byte(token), []byte(r.token)) != 1 { |
| 876 | return fmt.Errorf("blessings received from unexpected sender") |
| 877 | } |
Ankur | e548f39 | 2014-12-08 18:42:41 -0800 | [diff] [blame] | 878 | if flagRecvBlessingsSetDefault { |
| 879 | if err := r.principal.BlessingStore().SetDefault(b); err != nil { |
| 880 | return fmt.Errorf("failed to set blessings %v as default: %v", b, err) |
| 881 | } |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 882 | } |
Ankur | e548f39 | 2014-12-08 18:42:41 -0800 | [diff] [blame] | 883 | if pattern := security.BlessingPattern(flagRecvBlessingsForPeer); len(pattern) > 0 { |
| 884 | if _, err := r.principal.BlessingStore().Set(b, pattern); err != nil { |
| 885 | return fmt.Errorf("failed to set blessings %v for peers %v: %v", b, pattern, err) |
| 886 | } |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 887 | } |
| 888 | if flagAddToRoots { |
| 889 | if err := r.principal.AddToRoots(b); err != nil { |
| 890 | return fmt.Errorf("failed to add blessings to recognized roots: %v", err) |
| 891 | } |
| 892 | } |
| 893 | fmt.Println("Received blessings:", b) |
| 894 | r.notify <- nil |
| 895 | return nil |
| 896 | } |
| 897 | |
| 898 | type allowAnyone struct{} |
| 899 | |
| 900 | func (allowAnyone) Authorize(security.Context) error { return nil } |
| 901 | |
| 902 | type granter struct { |
| 903 | p security.Principal |
| 904 | with security.Blessings |
| 905 | extension string |
| 906 | caveats []security.Caveat |
| 907 | serverKey string |
| 908 | } |
| 909 | |
| 910 | func (g *granter) Grant(server security.Blessings) (security.Blessings, error) { |
| 911 | if got := fmt.Sprintf("%v", server.PublicKey()); got != g.serverKey { |
| 912 | // If the granter returns an error, the IPC framework should |
| 913 | // abort the RPC before sending the request to the server. |
| 914 | // Thus, there is no concern about leaking the token to an |
| 915 | // imposter server. |
| 916 | return nil, fmt.Errorf("key mismatch: Remote end has public key %v, want %v", got, g.serverKey) |
| 917 | } |
| 918 | return g.p.Bless(server.PublicKey(), g.with, g.extension, g.caveats[0], g.caveats[1:]...) |
| 919 | } |
| 920 | func (*granter) IPCCallOpt() {} |
| 921 | |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 922 | func sendBlessings(ctx *context.T, object string, granter *granter, remoteToken string) error { |
| 923 | client := veyron2.GetClient(ctx) |
| 924 | call, err := client.StartCall(ctx, object, "Grant", []interface{}{remoteToken}, granter) |
Asim Shankar | f11b1bc | 2014-11-12 17:18:45 -0800 | [diff] [blame] | 925 | if err != nil { |
| 926 | return fmt.Errorf("failed to start RPC to %q: %v", object, err) |
| 927 | } |
| 928 | if ierr := call.Finish(&err); ierr != nil { |
| 929 | return fmt.Errorf("failed to finish RPC to %q: %v", object, ierr) |
| 930 | } |
| 931 | return err |
| 932 | } |