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 // TODO(ataly, ashankar): This constant is declared in the Mojom however it neve
r |
| 13 // makes it to the Go generated code. We should fix this. |
| 14 const chainSeparator = "/" |
| 15 |
| 16 // TODO(ataly): This is a hack! We should implement the security.BlessingNames |
| 17 // function from the Vanadium API. |
| 18 func name(chain []certificate) string { |
| 19 if len(chain) == 0 { |
| 20 return "" |
| 21 } |
| 22 name := chain[0].Extension |
| 23 for i := 1; i < len(chain); i++ { |
| 24 name = name + chainSeparator + chain[i].Extension |
| 25 } |
| 26 return name |
| 27 } |
| 28 |
| 29 // emailFromBlessing returns the email address from a user |
| 30 // blessing chain in 'b', or nil if no such blessing chain exists. |
| 31 // This function relies on the Vanadium identity provider employing |
| 32 // the following convention for blessings returned in exchange for |
| 33 // OAuth2 tokens: All blessings must be of the form |
| 34 // dev.v.io/u/<OAuth2 ClientID>/<user email>. |
| 35 // See Also: https://godoc.org/v.io/v23/conventions |
| 36 // TODO(ataly): Import "v23/conventions" here rather than duplicating |
| 37 // the code. |
| 38 func emailFromBlessings(b *wireBlessings) (string, error) { |
| 39 var rejected []string |
| 40 for _, chain := range b.CertificateChains { |
| 41 n := name(chain) |
| 42 // n is valid OAuth2 token based blessing name iff |
| 43 // n is of the form "dev.v.io/u/<clientID>/<email>" |
| 44 parts := strings.Split(n, chainSeparator) |
| 45 if len(parts) < 4 { |
| 46 rejected = append(rejected, n) |
| 47 continue |
| 48 } |
| 49 if (parts[0] != "dev.v.io") || (parts[1] != "u") { |
| 50 rejected = append(rejected, n) |
| 51 continue |
| 52 } |
| 53 // We assume that parts[2] must be the OAuth2 ClientID of |
| 54 // this service, and parts[3] must be the user's email. |
| 55 return parts[3], nil |
| 56 } |
| 57 return "", fmt.Errorf("the set of blessings (%v) obtained from the Vanad
ium identity provider does not contain any user blessing chain", rejected) |
| 58 } |
OLD | NEW |