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