/
linux_host_tao_rpc.go
186 lines (167 loc) · 5.48 KB
/
linux_host_tao_rpc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// Copyright (c) 2014, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package tao
// This provides a server stub for LinuxHost's Tao RPC interface. This code is
// (mostly) extremely dull and, ideally, would be generated automatically. The
// only mildly interesting thing it does is hold some state associated with each
// connection, and pass that as a parameter to each server function.
import (
"errors"
"io"
"net/rpc"
"github.com/golang/protobuf/proto"
"github.com/jlmucb/cloudproxy/go/tao/auth"
"github.com/jlmucb/cloudproxy/go/util/protorpc"
)
// LinuxHostTaoServer is a server stub for LinuxHost's Tao RPC interface.
type LinuxHostTaoServer struct {
lh *LinuxHost
child *LinuxHostChild
}
type linuxHostTaoServerStub LinuxHostTaoServer
// NewLinuxHostTaoServer returns a new server stub for LinuxHost's Tao RPC
// interface.
func NewLinuxHostTaoServer(host *LinuxHost, child *LinuxHostChild) LinuxHostTaoServer {
return LinuxHostTaoServer{host, child}
}
// Serve listens on sock for new connections and services them.
func (server LinuxHostTaoServer) Serve(conn io.ReadWriteCloser) error {
s := rpc.NewServer()
err := s.RegisterName("Tao", linuxHostTaoServerStub(server))
if err != nil {
return err
}
s.ServeCodec(protorpc.NewServerCodec(conn))
return nil
}
// GetTaoName is the server stub for Tao.GetTaoName.
func (server linuxHostTaoServerStub) GetTaoName(r *RPCRequest, s *RPCResponse) error {
s.Data = auth.Marshal(server.lh.GetTaoName(server.child))
return nil
}
// ExtendTaoName is the server stub for Tao.ExtendTaoName.
func (server linuxHostTaoServerStub) ExtendTaoName(r *RPCRequest, s *RPCResponse) error {
ext, err := auth.UnmarshalSubPrin(r.Data)
if err != nil {
return err
}
return server.lh.ExtendTaoName(server.child, ext)
}
// GetRandomBytes is the server stub for Tao.GetRandomBytes.
func (server linuxHostTaoServerStub) GetRandomBytes(r *RPCRequest, s *RPCResponse) error {
if r.Size == nil || *r.Size <= 0 {
return newError("invalid size")
}
data, err := server.lh.GetRandomBytes(server.child, int(*r.Size))
s.Data = data
return err
}
// GetSharedSecret is the server stub for Tao.GetSharedSecret.
func (server linuxHostTaoServerStub) GetSharedSecret(r *RPCRequest, s *RPCResponse) error {
if r.Size == nil || *r.Size <= 0 {
return newError("invalid size")
}
if r.Policy == nil {
return newError("missing policy")
}
data, err := server.lh.GetSharedSecret(server.child, int(*r.Size), *r.Policy)
s.Data = data
return err
}
// Seal is the server stub for Tao.Seal.
func (server linuxHostTaoServerStub) Seal(r *RPCRequest, s *RPCResponse) error {
if r.Policy == nil {
return newError("missing policy")
}
data, err := server.lh.Seal(server.child, r.Data, *r.Policy)
s.Data = data
return err
}
// Unseal is the server stub for Tao.Unseal.
func (server linuxHostTaoServerStub) Unseal(r *RPCRequest, s *RPCResponse) error {
data, policy, err := server.lh.Unseal(server.child, r.Data)
s.Data = data
s.Policy = proto.String(policy)
return err
}
// Attest is the server stub for Tao.Attest.
func (server linuxHostTaoServerStub) Attest(r *RPCRequest, s *RPCResponse) error {
stmt, err := auth.UnmarshalForm(r.Data)
if err != nil {
return err
}
var issuer *auth.Prin
if r.Issuer != nil {
p, err := auth.UnmarshalPrin(r.Issuer)
if err != nil {
return err
}
issuer = &p
}
a, err := server.lh.Attest(server.child, issuer, r.Time, r.Expiration, stmt)
if err != nil {
return err
}
s.Data, err = proto.Marshal(a)
return err
}
// InitCounter initializes counter.
func (server linuxHostTaoServerStub) InitCounter(r *RPCRequest, s *RPCResponse) error {
// fmt.Printf("linuxHostTaoServerStub.InitCounter called %s\n", server.child.ChildSubprin.String()) // REMOVE
if r.Label == nil || r.Counter == nil {
return errors.New("Label or counter unspecified")
}
err := server.lh.InitCounter(server.child, *r.Label, *r.Counter)
return err
}
// GetCounter gets counter
func (server linuxHostTaoServerStub) GetCounter(r *RPCRequest, s *RPCResponse) error {
if r.Label == nil {
return errors.New("Label unspecified")
}
c, err := server.lh.GetCounter(server.child, *r.Label)
if err != nil {
return err
}
s.Counter = &c
return err
}
// RollbackProtectedSeal does a rollback protected seal
func (server linuxHostTaoServerStub) RollbackProtectedSeal(r *RPCRequest, s *RPCResponse) error {
if r.Label == nil {
return errors.New("Label unspecified")
}
if r.Policy == nil {
return errors.New("Policy unspecified")
}
sealed, err := server.lh.RollbackProtectedSeal(server.child, *r.Label, r.Data, *r.Policy)
if err != nil {
return err
}
s.Data = sealed
return err
}
// RollbackProtectedUnseal does a rollback protected Unseal
func (server linuxHostTaoServerStub) RollbackProtectedUnseal(r *RPCRequest, s *RPCResponse) error {
if r.Data == nil {
return errors.New("Data unspecified")
}
data, policy, err := server.lh.RollbackProtectedUnseal(server.child, r.Data)
if err != nil {
return err
}
s.Data = data
s.Policy = &policy
return nil
}