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 vpkg "mojo/services/vanadium/security/interfaces/principal" |
| 12 ) |
| 13 |
| 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 // userFromBlessing returns a vpkg.User object constructed from a user |
| 30 // blessing chain in 'b', or nil if no such blessing chain exists. |
| 31 func userFromBlessings(b *wireBlessings) (vpkg.User, error) { |
| 32 var ( |
| 33 rejected []string |
| 34 empty vpkg.User |
| 35 ) |
| 36 for _, chain := range b.CertificateChains { |
| 37 n := name(chain) |
| 38 // n is valid OAuth2 token based blessing name iff |
| 39 // n is of the form "dev.v.io/u/<clientID>/<email>" |
| 40 parts := strings.Split(n, chainSeparator) |
| 41 if len(parts) != 4 { |
| 42 rejected = append(rejected, n) |
| 43 continue |
| 44 } |
| 45 if (parts[0] != "dev.v.io") || (parts[1] != "u") { |
| 46 rejected = append(rejected, n) |
| 47 continue |
| 48 } |
| 49 // We assume that parts[2] must be the OAuth2 ClientID of |
| 50 // this service, and parts[3] must be the user's email. |
| 51 return vpkg.User{Email: parts[3]}, nil |
| 52 } |
| 53 return empty, fmt.Errorf("the set of blessings (%v) obtained from the Va
nadium identity provider does not contain any user blessing chain", rejected) |
| 54 } |
OLD | NEW |