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 "log" |
| 9 |
| 10 "golang.org/x/mobile/app" |
| 11 |
| 12 "mojo/public/go/application" |
| 13 "mojo/public/go/bindings" |
| 14 "mojo/public/go/system" |
| 15 "mojo/services/vanadium/security/public/interfaces/principal" |
| 16 ) |
| 17 |
| 18 //#include "mojo/public/c/system/types.h" |
| 19 import "C" |
| 20 |
| 21 type PrincipalServiceImpl struct { |
| 22 defaultBlessing *principal.Blessing |
| 23 } |
| 24 |
| 25 func (p *PrincipalServiceImpl) Login() (b *principal.Blessing, err error) { |
| 26 return p.defaultBlessing, nil |
| 27 } |
| 28 |
| 29 func (p *PrincipalServiceImpl) Logout() (err error) { |
| 30 return nil |
| 31 } |
| 32 |
| 33 func (p *PrincipalServiceImpl) Sign(msg []byte) (s *principal.Signature, err err
or) { |
| 34 return nil, nil |
| 35 } |
| 36 |
| 37 func (p *PrincipalServiceImpl) GetUserBlessing(app principal.AppName) (b *princi
pal.Blessing, err error) { |
| 38 return p.defaultBlessing, nil |
| 39 } |
| 40 |
| 41 type PrincipalServiceDelegate struct { |
| 42 psImpl *PrincipalServiceImpl |
| 43 stubs []*bindings.Stub |
| 44 } |
| 45 |
| 46 func (d *PrincipalServiceDelegate) Initialize(context application.Context) { |
| 47 defaultCertChain := []principal.Certificate{principal.Certificate{Extension
:"default"}} |
| 48 d.psImpl = &PrincipalServiceImpl{&principal.Blessing{defaultCertChain}} |
| 49 } |
| 50 |
| 51 func (d *PrincipalServiceDelegate) Create(r principal.PrincipalService_Request)
{ |
| 52 stub := principal.NewPrincipalServiceStub(r, d.psImpl, bindings.GetAsync
Waiter()) |
| 53 d.stubs = append(d.stubs, stub) |
| 54 go func() { |
| 55 for { |
| 56 if err := stub.ServeRequest(); err != nil { |
| 57 connectionError, ok := err.(*bindings.Connection
Error) |
| 58 if !ok || !connectionError.Closed() { |
| 59 log.Println(err) |
| 60 } |
| 61 break |
| 62 } |
| 63 } |
| 64 }() |
| 65 } |
| 66 |
| 67 func (d *PrincipalServiceDelegate) AcceptConnection(connection *application.Conn
ection) { |
| 68 connection.ProvideServices(&principal.PrincipalService_ServiceFactory{d}
) |
| 69 } |
| 70 |
| 71 func (d *PrincipalServiceDelegate) Quit() { |
| 72 for _, stub := range d.stubs { |
| 73 stub.Close() |
| 74 } |
| 75 } |
| 76 |
| 77 //export MojoMain |
| 78 func MojoMain(handle C.MojoHandle) C.MojoResult { |
| 79 application.Run(&PrincipalServiceDelegate{}, system.MojoHandle(handle)) |
| 80 return C.MOJO_RESULT_OK |
| 81 } |
| 82 |
| 83 func main() { |
| 84 app.Run(app.Callbacks{}) |
| 85 } |
OLD | NEW |