OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package main | |
6 | |
7 import ( | |
8 "fmt" | |
9 "strings" | |
10 ) | |
11 | |
12 const chainSeparator = "/" | |
ashankar
2015/10/30 02:24:13
Can't we use the constant defined in the mojom fil
ataly
2015/11/04 00:24:30
I tried to do that but for some reason the constan
ashankar
2015/11/04 00:37:10
Add a TODO about this - we should be able to remov
ataly
2015/11/04 21:22:51
Done.
| |
13 | |
14 // TODO(ataly): This is a hack! We should implement the security.BlessingNames | |
15 // function from the Vanadium API. | |
ashankar
2015/10/30 02:24:13
Not for this CL, but now that the Vanadium code is
ataly
2015/11/04 00:24:30
Yes this is one of the things we need to do. Will
| |
16 func name(chain []certificate) string { | |
17 if len(chain) == 0 { | |
18 return "" | |
19 } | |
20 name := chain[0].Extension | |
21 for i := 1; i < len(chain); i++ { | |
22 name = name + chainSeparator + chain[i].Extension | |
23 } | |
24 return name | |
25 } | |
26 | |
27 // emailFromBlessing returns the email address from a user | |
28 // blessing chain in 'b', or nil if no such blessing chain exists. | |
29 func emailFromBlessings(b *wireBlessings) (string, error) { | |
30 var rejected []string | |
31 for _, chain := range b.CertificateChains { | |
32 n := name(chain) | |
33 // n is valid OAuth2 token based blessing name iff | |
34 // n is of the form "dev.v.io/u/<clientID>/<email>" | |
35 parts := strings.Split(n, chainSeparator) | |
36 if len(parts) != 4 { | |
ashankar
2015/10/30 02:24:13
We don't want "==4", but >=4, right?
So:
if len(pa
ataly
2015/11/04 00:24:30
Done.
| |
37 rejected = append(rejected, n) | |
38 continue | |
39 } | |
40 if (parts[0] != "dev.v.io") || (parts[1] != "u") { | |
ashankar
2015/10/30 02:24:13
Should we have a TODO about the notion of an ident
ataly
2015/11/04 00:24:30
I have a TODO about specifying the identity provid
| |
41 rejected = append(rejected, n) | |
42 continue | |
43 } | |
44 // We assume that parts[2] must be the OAuth2 ClientID of | |
45 // this service, and parts[3] must be the user's email. | |
46 return parts[3], nil | |
47 } | |
48 return "", fmt.Errorf("the set of blessings (%v) obtained from the Vanad ium identity provider does not contain any user blessing chain", rejected) | |
49 } | |
OLD | NEW |