commit 751e3128623c39d634e712244cf4466695f422ec Author: Michael Crosby Date: Wed Jul 10 20:59:43 2019 +0000 Init create and delete workflow diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..13e36d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +guard diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..121f96c --- /dev/null +++ b/Makefile @@ -0,0 +1,31 @@ +# Copyright (c) 2019 @crosbymichael + +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, copy, +# modify, merge, publish, distribute, sublicense, and/or sell copies +# of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, +# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, +# DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH +# THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +PACKAGES=$(shell go list ./... | grep -v /vendor/) +REVISION=$(shell git rev-parse HEAD) + +protos: + protobuild --quiet ${PACKAGES} + diff --git a/Protobuild.toml b/Protobuild.toml new file mode 100644 index 0000000..e3b28e0 --- /dev/null +++ b/Protobuild.toml @@ -0,0 +1,28 @@ +version = "unstable" +generator = "gogoctrd" +plugins = ["grpc"] + +# Control protoc include paths. Below are usually some good defaults, but feel +# free to try it without them if it works for your project. +[includes] + # Paths that should be treated as include roots in relation to the vendor + # directory. These will be calculated with the vendor directory nearest the + # target package. + packages = ["github.com/gogo/protobuf", "github.com/gogo/googleapis"] + + # Paths that will be added untouched to the end of the includes. We use + # `/usr/local/include` to pickup the common install location of protobuf. + # This is the default. + after = ["/usr/local/include"] + +# This section maps protobuf imports to Go packages. These will become +# `-M` directives in the call to the go protobuf generator. +[packages] + "gogoproto/gogo.proto" = "github.com/gogo/protobuf/gogoproto" + "google/protobuf/any.proto" = "github.com/gogo/protobuf/types" + "google/protobuf/empty.proto" = "github.com/gogo/protobuf/types" + "google/protobuf/descriptor.proto" = "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" + "google/protobuf/field_mask.proto" = "github.com/gogo/protobuf/types" + "google/protobuf/timestamp.proto" = "github.com/gogo/protobuf/types" + "google/protobuf/duration.proto" = "github.com/gogo/protobuf/types" + "google/rpc/status.proto" = "github.com/gogo/googleapis/google/rpc" diff --git a/api/v1/doc.go b/api/v1/doc.go new file mode 100644 index 0000000..0737730 --- /dev/null +++ b/api/v1/doc.go @@ -0,0 +1,28 @@ +/* + Copyright (c) 2019 @crosbymichael + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, copy, + modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, + INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH + THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package v1 diff --git a/api/v1/guard.pb.go b/api/v1/guard.pb.go new file mode 100644 index 0000000..70ecef4 --- /dev/null +++ b/api/v1/guard.pb.go @@ -0,0 +1,2145 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: github.com/crosbymichael/guard/api/v1/guard.proto + +package v1 + +import ( + context "context" + fmt "fmt" + proto "github.com/gogo/protobuf/proto" + types "github.com/gogo/protobuf/types" + grpc "google.golang.org/grpc" + io "io" + math "math" + reflect "reflect" + strings "strings" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package + +type CreateRequest struct { + ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + ListenPort uint32 `protobuf:"varint,2,opt,name=listen_port,json=listenPort,proto3" json:"listen_port,omitempty"` + Address string `protobuf:"bytes,3,opt,name=address,proto3" json:"address,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateRequest) Reset() { *m = CreateRequest{} } +func (*CreateRequest) ProtoMessage() {} +func (*CreateRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ebe0601dd3932458, []int{0} +} +func (m *CreateRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CreateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CreateRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *CreateRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateRequest.Merge(m, src) +} +func (m *CreateRequest) XXX_Size() int { + return m.Size() +} +func (m *CreateRequest) XXX_DiscardUnknown() { + xxx_messageInfo_CreateRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateRequest proto.InternalMessageInfo + +type CreateResponse struct { + Tunnel *Tunnel `protobuf:"bytes,1,opt,name=tunnel,proto3" json:"tunnel,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateResponse) Reset() { *m = CreateResponse{} } +func (*CreateResponse) ProtoMessage() {} +func (*CreateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ebe0601dd3932458, []int{1} +} +func (m *CreateResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CreateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CreateResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *CreateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateResponse.Merge(m, src) +} +func (m *CreateResponse) XXX_Size() int { + return m.Size() +} +func (m *CreateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_CreateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateResponse proto.InternalMessageInfo + +type DeleteRequest struct { + ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } +func (*DeleteRequest) ProtoMessage() {} +func (*DeleteRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ebe0601dd3932458, []int{2} +} +func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DeleteRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DeleteRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DeleteRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleteRequest.Merge(m, src) +} +func (m *DeleteRequest) XXX_Size() int { + return m.Size() +} +func (m *DeleteRequest) XXX_DiscardUnknown() { + xxx_messageInfo_DeleteRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_DeleteRequest proto.InternalMessageInfo + +type ListResponse struct { + Tunnels []*Tunnel `protobuf:"bytes,1,rep,name=tunnels,proto3" json:"tunnels,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListResponse) Reset() { *m = ListResponse{} } +func (*ListResponse) ProtoMessage() {} +func (*ListResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ebe0601dd3932458, []int{3} +} +func (m *ListResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ListResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ListResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ListResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListResponse.Merge(m, src) +} +func (m *ListResponse) XXX_Size() int { + return m.Size() +} +func (m *ListResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ListResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ListResponse proto.InternalMessageInfo + +type Tunnel struct { + ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + PrivateKey string `protobuf:"bytes,2,opt,name=private_key,json=privateKey,proto3" json:"private_key,omitempty"` + ListenPort uint32 `protobuf:"varint,3,opt,name=listen_port,json=listenPort,proto3" json:"listen_port,omitempty"` + Address string `protobuf:"bytes,4,opt,name=address,proto3" json:"address,omitempty"` + DNS string `protobuf:"bytes,5,opt,name=dns,proto3" json:"dns,omitempty"` + Peers []*Peer `protobuf:"bytes,6,rep,name=peers,proto3" json:"peers,omitempty"` + Masquerade *Masquerade `protobuf:"bytes,7,opt,name=masquerade,proto3" json:"masquerade,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Tunnel) Reset() { *m = Tunnel{} } +func (*Tunnel) ProtoMessage() {} +func (*Tunnel) Descriptor() ([]byte, []int) { + return fileDescriptor_ebe0601dd3932458, []int{4} +} +func (m *Tunnel) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Tunnel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Tunnel.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Tunnel) XXX_Merge(src proto.Message) { + xxx_messageInfo_Tunnel.Merge(m, src) +} +func (m *Tunnel) XXX_Size() int { + return m.Size() +} +func (m *Tunnel) XXX_DiscardUnknown() { + xxx_messageInfo_Tunnel.DiscardUnknown(m) +} + +var xxx_messageInfo_Tunnel proto.InternalMessageInfo + +type Peer struct { + PublicKey string `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` + AllowedIPs []string `protobuf:"bytes,2,rep,name=allowed_ips,json=allowedIps,proto3" json:"allowed_ips,omitempty"` + Endpoint string `protobuf:"bytes,3,opt,name=endpoint,proto3" json:"endpoint,omitempty"` + PersistentKeepalive uint32 `protobuf:"varint,4,opt,name=persistent_keepalive,json=persistentKeepalive,proto3" json:"persistent_keepalive,omitempty"` + Comment string `protobuf:"bytes,5,opt,name=comment,proto3" json:"comment,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Peer) Reset() { *m = Peer{} } +func (*Peer) ProtoMessage() {} +func (*Peer) Descriptor() ([]byte, []int) { + return fileDescriptor_ebe0601dd3932458, []int{5} +} +func (m *Peer) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Peer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Peer.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Peer) XXX_Merge(src proto.Message) { + xxx_messageInfo_Peer.Merge(m, src) +} +func (m *Peer) XXX_Size() int { + return m.Size() +} +func (m *Peer) XXX_DiscardUnknown() { + xxx_messageInfo_Peer.DiscardUnknown(m) +} + +var xxx_messageInfo_Peer proto.InternalMessageInfo + +type Masquerade struct { + Interface string `protobuf:"bytes,1,opt,name=interface,proto3" json:"interface,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Masquerade) Reset() { *m = Masquerade{} } +func (*Masquerade) ProtoMessage() {} +func (*Masquerade) Descriptor() ([]byte, []int) { + return fileDescriptor_ebe0601dd3932458, []int{6} +} +func (m *Masquerade) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Masquerade) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Masquerade.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Masquerade) XXX_Merge(src proto.Message) { + xxx_messageInfo_Masquerade.Merge(m, src) +} +func (m *Masquerade) XXX_Size() int { + return m.Size() +} +func (m *Masquerade) XXX_DiscardUnknown() { + xxx_messageInfo_Masquerade.DiscardUnknown(m) +} + +var xxx_messageInfo_Masquerade proto.InternalMessageInfo + +func init() { + proto.RegisterType((*CreateRequest)(nil), "com.crosbymichael.guard.v1.CreateRequest") + proto.RegisterType((*CreateResponse)(nil), "com.crosbymichael.guard.v1.CreateResponse") + proto.RegisterType((*DeleteRequest)(nil), "com.crosbymichael.guard.v1.DeleteRequest") + proto.RegisterType((*ListResponse)(nil), "com.crosbymichael.guard.v1.ListResponse") + proto.RegisterType((*Tunnel)(nil), "com.crosbymichael.guard.v1.Tunnel") + proto.RegisterType((*Peer)(nil), "com.crosbymichael.guard.v1.Peer") + proto.RegisterType((*Masquerade)(nil), "com.crosbymichael.guard.v1.Masquerade") +} + +func init() { + proto.RegisterFile("github.com/crosbymichael/guard/api/v1/guard.proto", fileDescriptor_ebe0601dd3932458) +} + +var fileDescriptor_ebe0601dd3932458 = []byte{ + // 607 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xc1, 0x6e, 0xd3, 0x40, + 0x10, 0xad, 0x93, 0x36, 0x21, 0x53, 0xd2, 0xc3, 0x52, 0x55, 0xc6, 0x40, 0x12, 0xf9, 0x00, 0xa1, + 0x07, 0x5b, 0x29, 0x12, 0x07, 0xe0, 0x42, 0x28, 0x88, 0xaa, 0x05, 0x55, 0x06, 0x09, 0xc4, 0x25, + 0x72, 0xec, 0x69, 0xba, 0xaa, 0xed, 0x75, 0x77, 0xd7, 0x41, 0xb9, 0x21, 0xf1, 0x11, 0x7c, 0x0e, + 0xd7, 0x1e, 0x39, 0x72, 0xaa, 0xa8, 0xbf, 0x04, 0x79, 0x37, 0x4e, 0x1b, 0xa4, 0x9a, 0xde, 0x32, + 0x33, 0x6f, 0xf6, 0xe5, 0xbd, 0xcc, 0x0b, 0x0c, 0x26, 0x54, 0x1e, 0x67, 0x63, 0x27, 0x60, 0xb1, + 0x1b, 0x70, 0x26, 0xc6, 0xb3, 0x98, 0x06, 0xc7, 0x3e, 0x46, 0xee, 0x24, 0xf3, 0x79, 0xe8, 0xfa, + 0x29, 0x75, 0xa7, 0x03, 0x5d, 0x38, 0x29, 0x67, 0x92, 0x11, 0x2b, 0x60, 0xb1, 0xb3, 0x84, 0x75, + 0xf4, 0x78, 0x3a, 0xb0, 0x36, 0x27, 0x6c, 0xc2, 0x14, 0xcc, 0x2d, 0x3e, 0xe9, 0x0d, 0xeb, 0xde, + 0x84, 0xb1, 0x49, 0x84, 0xae, 0xaa, 0xc6, 0xd9, 0x91, 0x8b, 0x71, 0x2a, 0x67, 0x7a, 0x68, 0x8f, + 0xa1, 0xfd, 0x8a, 0xa3, 0x2f, 0xd1, 0xc3, 0xd3, 0x0c, 0x85, 0x24, 0x5b, 0x50, 0xa3, 0xa1, 0x69, + 0xf4, 0x8c, 0x7e, 0x6b, 0xd8, 0xc8, 0xcf, 0xbb, 0xb5, 0xbd, 0x5d, 0xaf, 0x46, 0x43, 0xd2, 0x85, + 0xf5, 0x88, 0x0a, 0x89, 0xc9, 0x28, 0x65, 0x5c, 0x9a, 0xb5, 0x9e, 0xd1, 0x6f, 0x7b, 0xa0, 0x5b, + 0x87, 0x8c, 0x4b, 0x62, 0x42, 0xd3, 0x0f, 0x43, 0x8e, 0x42, 0x98, 0xf5, 0x62, 0xdb, 0x2b, 0x4b, + 0xfb, 0x00, 0x36, 0x4a, 0x0e, 0x91, 0xb2, 0x44, 0x20, 0x79, 0x06, 0x0d, 0x99, 0x25, 0x09, 0x46, + 0x8a, 0x68, 0x7d, 0xc7, 0x76, 0xae, 0x57, 0xe5, 0x7c, 0x54, 0x48, 0x6f, 0xbe, 0x61, 0x3f, 0x82, + 0xf6, 0x2e, 0x46, 0xf8, 0xdf, 0x6f, 0x6c, 0x1f, 0xc0, 0xed, 0x03, 0x2a, 0xe4, 0x82, 0xf4, 0x05, + 0x34, 0xf5, 0x13, 0xc2, 0x34, 0x7a, 0xf5, 0x1b, 0xb2, 0x96, 0x2b, 0xf6, 0x8f, 0x1a, 0x34, 0x74, + 0xaf, 0xca, 0xa2, 0x94, 0xd3, 0xa9, 0x2f, 0x71, 0x74, 0x82, 0x33, 0x65, 0x51, 0xcb, 0x83, 0x79, + 0x6b, 0x1f, 0x67, 0xff, 0x7a, 0x58, 0xaf, 0xf2, 0x70, 0x75, 0xc9, 0x43, 0x72, 0x17, 0xea, 0x61, + 0x22, 0xcc, 0x35, 0x45, 0xda, 0xcc, 0xcf, 0xbb, 0xf5, 0xdd, 0xf7, 0x1f, 0xbc, 0xa2, 0x47, 0x9e, + 0xc2, 0x5a, 0x8a, 0xc8, 0x85, 0xd9, 0x50, 0xaa, 0x7a, 0x55, 0xaa, 0x0e, 0x11, 0xb9, 0xa7, 0xe1, + 0xe4, 0x0d, 0x40, 0xec, 0x8b, 0xd3, 0x0c, 0xb9, 0x1f, 0xa2, 0xd9, 0x54, 0x3f, 0xc4, 0xc3, 0xaa, + 0xe5, 0x77, 0x0b, 0xb4, 0x77, 0x65, 0xd3, 0xfe, 0x69, 0xc0, 0x6a, 0xf1, 0x2e, 0x79, 0x00, 0x90, + 0x66, 0xe3, 0x88, 0x06, 0x4a, 0xbe, 0xf2, 0xc7, 0x6b, 0xe9, 0x4e, 0xa1, 0xde, 0x85, 0x75, 0x3f, + 0x8a, 0xd8, 0x57, 0x0c, 0x47, 0x34, 0x15, 0x66, 0xad, 0x57, 0xef, 0xb7, 0x86, 0x1b, 0xf9, 0x79, + 0x17, 0x5e, 0xea, 0xf6, 0xde, 0xa1, 0xf0, 0x60, 0x0e, 0xd9, 0x4b, 0x05, 0xb1, 0xe0, 0x16, 0x26, + 0x61, 0xca, 0x68, 0x22, 0xe7, 0x27, 0xb5, 0xa8, 0xc9, 0x00, 0x36, 0x53, 0xe4, 0x42, 0x59, 0x27, + 0x47, 0x27, 0x88, 0xa9, 0x1f, 0xd1, 0x29, 0x2a, 0xdb, 0xda, 0xde, 0x9d, 0xcb, 0xd9, 0x7e, 0x39, + 0x2a, 0xcc, 0x0d, 0x58, 0x1c, 0x63, 0x22, 0xb5, 0x8d, 0x5e, 0x59, 0xda, 0xdb, 0x00, 0x97, 0xda, + 0xc8, 0x7d, 0x68, 0xd1, 0x44, 0x22, 0x3f, 0xf2, 0x03, 0x2c, 0x55, 0x2c, 0x1a, 0x3b, 0xdf, 0x6b, + 0xd0, 0xfa, 0x44, 0x39, 0x2a, 0x57, 0xc8, 0x08, 0x1a, 0xfa, 0xb4, 0xc9, 0xe3, 0x2a, 0xe7, 0x96, + 0x22, 0x66, 0x6d, 0xdf, 0x04, 0x3a, 0x3f, 0xda, 0x7d, 0x68, 0xe8, 0x6b, 0xaf, 0x26, 0x58, 0x4a, + 0x84, 0xb5, 0xe5, 0xe8, 0xc8, 0x3b, 0x65, 0xe4, 0x9d, 0xd7, 0x45, 0xe4, 0xc9, 0x5b, 0x58, 0x2d, + 0x12, 0x41, 0xae, 0x99, 0x5b, 0xfd, 0x2a, 0x8a, 0xab, 0x59, 0x1a, 0x0e, 0xcf, 0x2e, 0x3a, 0x2b, + 0xbf, 0x2f, 0x3a, 0x2b, 0xdf, 0xf2, 0x8e, 0x71, 0x96, 0x77, 0x8c, 0x5f, 0x79, 0xc7, 0xf8, 0x93, + 0x77, 0x8c, 0x2f, 0xfd, 0x1b, 0xfd, 0xa5, 0x3d, 0x9f, 0x0e, 0x3e, 0xaf, 0x8c, 0x1b, 0x8a, 0xff, + 0xc9, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xbf, 0xdb, 0xd1, 0x20, 0x07, 0x05, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// WireguardClient is the client API for Wireguard service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type WireguardClient interface { + Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) + Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*types.Empty, error) + List(ctx context.Context, in *types.Empty, opts ...grpc.CallOption) (*ListResponse, error) +} + +type wireguardClient struct { + cc *grpc.ClientConn +} + +func NewWireguardClient(cc *grpc.ClientConn) WireguardClient { + return &wireguardClient{cc} +} + +func (c *wireguardClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) { + out := new(CreateResponse) + err := c.cc.Invoke(ctx, "/com.crosbymichael.guard.v1.Wireguard/Create", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *wireguardClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*types.Empty, error) { + out := new(types.Empty) + err := c.cc.Invoke(ctx, "/com.crosbymichael.guard.v1.Wireguard/Delete", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *wireguardClient) List(ctx context.Context, in *types.Empty, opts ...grpc.CallOption) (*ListResponse, error) { + out := new(ListResponse) + err := c.cc.Invoke(ctx, "/com.crosbymichael.guard.v1.Wireguard/List", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// WireguardServer is the server API for Wireguard service. +type WireguardServer interface { + Create(context.Context, *CreateRequest) (*CreateResponse, error) + Delete(context.Context, *DeleteRequest) (*types.Empty, error) + List(context.Context, *types.Empty) (*ListResponse, error) +} + +func RegisterWireguardServer(s *grpc.Server, srv WireguardServer) { + s.RegisterService(&_Wireguard_serviceDesc, srv) +} + +func _Wireguard_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WireguardServer).Create(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/com.crosbymichael.guard.v1.Wireguard/Create", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WireguardServer).Create(ctx, req.(*CreateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Wireguard_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WireguardServer).Delete(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/com.crosbymichael.guard.v1.Wireguard/Delete", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WireguardServer).Delete(ctx, req.(*DeleteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Wireguard_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(types.Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WireguardServer).List(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/com.crosbymichael.guard.v1.Wireguard/List", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WireguardServer).List(ctx, req.(*types.Empty)) + } + return interceptor(ctx, in, info, handler) +} + +var _Wireguard_serviceDesc = grpc.ServiceDesc{ + ServiceName: "com.crosbymichael.guard.v1.Wireguard", + HandlerType: (*WireguardServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Create", + Handler: _Wireguard_Create_Handler, + }, + { + MethodName: "Delete", + Handler: _Wireguard_Delete_Handler, + }, + { + MethodName: "List", + Handler: _Wireguard_List_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "github.com/crosbymichael/guard/api/v1/guard.proto", +} + +func (m *CreateRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CreateRequest) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.ID) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintGuard(dAtA, i, uint64(len(m.ID))) + i += copy(dAtA[i:], m.ID) + } + if m.ListenPort != 0 { + dAtA[i] = 0x10 + i++ + i = encodeVarintGuard(dAtA, i, uint64(m.ListenPort)) + } + if len(m.Address) > 0 { + dAtA[i] = 0x1a + i++ + i = encodeVarintGuard(dAtA, i, uint64(len(m.Address))) + i += copy(dAtA[i:], m.Address) + } + if m.XXX_unrecognized != nil { + i += copy(dAtA[i:], m.XXX_unrecognized) + } + return i, nil +} + +func (m *CreateResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CreateResponse) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.Tunnel != nil { + dAtA[i] = 0xa + i++ + i = encodeVarintGuard(dAtA, i, uint64(m.Tunnel.Size())) + n1, err := m.Tunnel.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n1 + } + if m.XXX_unrecognized != nil { + i += copy(dAtA[i:], m.XXX_unrecognized) + } + return i, nil +} + +func (m *DeleteRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DeleteRequest) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.ID) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintGuard(dAtA, i, uint64(len(m.ID))) + i += copy(dAtA[i:], m.ID) + } + if m.XXX_unrecognized != nil { + i += copy(dAtA[i:], m.XXX_unrecognized) + } + return i, nil +} + +func (m *ListResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ListResponse) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Tunnels) > 0 { + for _, msg := range m.Tunnels { + dAtA[i] = 0xa + i++ + i = encodeVarintGuard(dAtA, i, uint64(msg.Size())) + n, err := msg.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n + } + } + if m.XXX_unrecognized != nil { + i += copy(dAtA[i:], m.XXX_unrecognized) + } + return i, nil +} + +func (m *Tunnel) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Tunnel) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.ID) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintGuard(dAtA, i, uint64(len(m.ID))) + i += copy(dAtA[i:], m.ID) + } + if len(m.PrivateKey) > 0 { + dAtA[i] = 0x12 + i++ + i = encodeVarintGuard(dAtA, i, uint64(len(m.PrivateKey))) + i += copy(dAtA[i:], m.PrivateKey) + } + if m.ListenPort != 0 { + dAtA[i] = 0x18 + i++ + i = encodeVarintGuard(dAtA, i, uint64(m.ListenPort)) + } + if len(m.Address) > 0 { + dAtA[i] = 0x22 + i++ + i = encodeVarintGuard(dAtA, i, uint64(len(m.Address))) + i += copy(dAtA[i:], m.Address) + } + if len(m.DNS) > 0 { + dAtA[i] = 0x2a + i++ + i = encodeVarintGuard(dAtA, i, uint64(len(m.DNS))) + i += copy(dAtA[i:], m.DNS) + } + if len(m.Peers) > 0 { + for _, msg := range m.Peers { + dAtA[i] = 0x32 + i++ + i = encodeVarintGuard(dAtA, i, uint64(msg.Size())) + n, err := msg.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n + } + } + if m.Masquerade != nil { + dAtA[i] = 0x3a + i++ + i = encodeVarintGuard(dAtA, i, uint64(m.Masquerade.Size())) + n2, err := m.Masquerade.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n2 + } + if m.XXX_unrecognized != nil { + i += copy(dAtA[i:], m.XXX_unrecognized) + } + return i, nil +} + +func (m *Peer) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Peer) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.PublicKey) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintGuard(dAtA, i, uint64(len(m.PublicKey))) + i += copy(dAtA[i:], m.PublicKey) + } + if len(m.AllowedIPs) > 0 { + for _, s := range m.AllowedIPs { + dAtA[i] = 0x12 + i++ + l = len(s) + for l >= 1<<7 { + dAtA[i] = uint8(uint64(l)&0x7f | 0x80) + l >>= 7 + i++ + } + dAtA[i] = uint8(l) + i++ + i += copy(dAtA[i:], s) + } + } + if len(m.Endpoint) > 0 { + dAtA[i] = 0x1a + i++ + i = encodeVarintGuard(dAtA, i, uint64(len(m.Endpoint))) + i += copy(dAtA[i:], m.Endpoint) + } + if m.PersistentKeepalive != 0 { + dAtA[i] = 0x20 + i++ + i = encodeVarintGuard(dAtA, i, uint64(m.PersistentKeepalive)) + } + if len(m.Comment) > 0 { + dAtA[i] = 0x2a + i++ + i = encodeVarintGuard(dAtA, i, uint64(len(m.Comment))) + i += copy(dAtA[i:], m.Comment) + } + if m.XXX_unrecognized != nil { + i += copy(dAtA[i:], m.XXX_unrecognized) + } + return i, nil +} + +func (m *Masquerade) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Masquerade) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Interface) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintGuard(dAtA, i, uint64(len(m.Interface))) + i += copy(dAtA[i:], m.Interface) + } + if m.XXX_unrecognized != nil { + i += copy(dAtA[i:], m.XXX_unrecognized) + } + return i, nil +} + +func encodeVarintGuard(dAtA []byte, offset int, v uint64) int { + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return offset + 1 +} +func (m *CreateRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ID) + if l > 0 { + n += 1 + l + sovGuard(uint64(l)) + } + if m.ListenPort != 0 { + n += 1 + sovGuard(uint64(m.ListenPort)) + } + l = len(m.Address) + if l > 0 { + n += 1 + l + sovGuard(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *CreateResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Tunnel != nil { + l = m.Tunnel.Size() + n += 1 + l + sovGuard(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *DeleteRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ID) + if l > 0 { + n += 1 + l + sovGuard(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *ListResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Tunnels) > 0 { + for _, e := range m.Tunnels { + l = e.Size() + n += 1 + l + sovGuard(uint64(l)) + } + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *Tunnel) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ID) + if l > 0 { + n += 1 + l + sovGuard(uint64(l)) + } + l = len(m.PrivateKey) + if l > 0 { + n += 1 + l + sovGuard(uint64(l)) + } + if m.ListenPort != 0 { + n += 1 + sovGuard(uint64(m.ListenPort)) + } + l = len(m.Address) + if l > 0 { + n += 1 + l + sovGuard(uint64(l)) + } + l = len(m.DNS) + if l > 0 { + n += 1 + l + sovGuard(uint64(l)) + } + if len(m.Peers) > 0 { + for _, e := range m.Peers { + l = e.Size() + n += 1 + l + sovGuard(uint64(l)) + } + } + if m.Masquerade != nil { + l = m.Masquerade.Size() + n += 1 + l + sovGuard(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *Peer) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.PublicKey) + if l > 0 { + n += 1 + l + sovGuard(uint64(l)) + } + if len(m.AllowedIPs) > 0 { + for _, s := range m.AllowedIPs { + l = len(s) + n += 1 + l + sovGuard(uint64(l)) + } + } + l = len(m.Endpoint) + if l > 0 { + n += 1 + l + sovGuard(uint64(l)) + } + if m.PersistentKeepalive != 0 { + n += 1 + sovGuard(uint64(m.PersistentKeepalive)) + } + l = len(m.Comment) + if l > 0 { + n += 1 + l + sovGuard(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *Masquerade) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Interface) + if l > 0 { + n += 1 + l + sovGuard(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func sovGuard(x uint64) (n int) { + for { + n++ + x >>= 7 + if x == 0 { + break + } + } + return n +} +func sozGuard(x uint64) (n int) { + return sovGuard(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *CreateRequest) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&CreateRequest{`, + `ID:` + fmt.Sprintf("%v", this.ID) + `,`, + `ListenPort:` + fmt.Sprintf("%v", this.ListenPort) + `,`, + `Address:` + fmt.Sprintf("%v", this.Address) + `,`, + `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, + `}`, + }, "") + return s +} +func (this *CreateResponse) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&CreateResponse{`, + `Tunnel:` + strings.Replace(fmt.Sprintf("%v", this.Tunnel), "Tunnel", "Tunnel", 1) + `,`, + `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, + `}`, + }, "") + return s +} +func (this *DeleteRequest) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&DeleteRequest{`, + `ID:` + fmt.Sprintf("%v", this.ID) + `,`, + `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, + `}`, + }, "") + return s +} +func (this *ListResponse) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ListResponse{`, + `Tunnels:` + strings.Replace(fmt.Sprintf("%v", this.Tunnels), "Tunnel", "Tunnel", 1) + `,`, + `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, + `}`, + }, "") + return s +} +func (this *Tunnel) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Tunnel{`, + `ID:` + fmt.Sprintf("%v", this.ID) + `,`, + `PrivateKey:` + fmt.Sprintf("%v", this.PrivateKey) + `,`, + `ListenPort:` + fmt.Sprintf("%v", this.ListenPort) + `,`, + `Address:` + fmt.Sprintf("%v", this.Address) + `,`, + `DNS:` + fmt.Sprintf("%v", this.DNS) + `,`, + `Peers:` + strings.Replace(fmt.Sprintf("%v", this.Peers), "Peer", "Peer", 1) + `,`, + `Masquerade:` + strings.Replace(fmt.Sprintf("%v", this.Masquerade), "Masquerade", "Masquerade", 1) + `,`, + `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, + `}`, + }, "") + return s +} +func (this *Peer) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Peer{`, + `PublicKey:` + fmt.Sprintf("%v", this.PublicKey) + `,`, + `AllowedIPs:` + fmt.Sprintf("%v", this.AllowedIPs) + `,`, + `Endpoint:` + fmt.Sprintf("%v", this.Endpoint) + `,`, + `PersistentKeepalive:` + fmt.Sprintf("%v", this.PersistentKeepalive) + `,`, + `Comment:` + fmt.Sprintf("%v", this.Comment) + `,`, + `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, + `}`, + }, "") + return s +} +func (this *Masquerade) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Masquerade{`, + `Interface:` + fmt.Sprintf("%v", this.Interface) + `,`, + `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, + `}`, + }, "") + return s +} +func valueToStringGuard(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *CreateRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CreateRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CreateRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGuard + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGuard + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ListenPort", wireType) + } + m.ListenPort = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ListenPort |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGuard + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGuard + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGuard(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGuard + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGuard + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *CreateResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CreateResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CreateResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Tunnel", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGuard + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGuard + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Tunnel == nil { + m.Tunnel = &Tunnel{} + } + if err := m.Tunnel.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGuard(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGuard + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGuard + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DeleteRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DeleteRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DeleteRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGuard + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGuard + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGuard(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGuard + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGuard + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ListResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ListResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ListResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Tunnels", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGuard + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGuard + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Tunnels = append(m.Tunnels, &Tunnel{}) + if err := m.Tunnels[len(m.Tunnels)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGuard(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGuard + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGuard + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Tunnel) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Tunnel: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Tunnel: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGuard + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGuard + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrivateKey", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGuard + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGuard + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PrivateKey = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ListenPort", wireType) + } + m.ListenPort = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ListenPort |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGuard + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGuard + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DNS", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGuard + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGuard + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DNS = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Peers", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGuard + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGuard + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Peers = append(m.Peers, &Peer{}) + if err := m.Peers[len(m.Peers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Masquerade", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGuard + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGuard + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Masquerade == nil { + m.Masquerade = &Masquerade{} + } + if err := m.Masquerade.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGuard(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGuard + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGuard + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Peer) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Peer: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Peer: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PublicKey", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGuard + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGuard + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PublicKey = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AllowedIPs", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGuard + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGuard + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AllowedIPs = append(m.AllowedIPs, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Endpoint", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGuard + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGuard + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Endpoint = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PersistentKeepalive", wireType) + } + m.PersistentKeepalive = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PersistentKeepalive |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Comment", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGuard + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGuard + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Comment = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGuard(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGuard + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGuard + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Masquerade) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Masquerade: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Masquerade: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Interface", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGuard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGuard + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGuard + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Interface = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGuard(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGuard + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGuard + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGuard(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGuard + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGuard + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + return iNdEx, nil + case 1: + iNdEx += 8 + return iNdEx, nil + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGuard + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGuard + } + iNdEx += length + if iNdEx < 0 { + return 0, ErrInvalidLengthGuard + } + return iNdEx, nil + case 3: + for { + var innerWire uint64 + var start int = iNdEx + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGuard + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + innerWire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + innerWireType := int(innerWire & 0x7) + if innerWireType == 4 { + break + } + next, err := skipGuard(dAtA[start:]) + if err != nil { + return 0, err + } + iNdEx = start + next + if iNdEx < 0 { + return 0, ErrInvalidLengthGuard + } + } + return iNdEx, nil + case 4: + return iNdEx, nil + case 5: + iNdEx += 4 + return iNdEx, nil + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + } + panic("unreachable") +} + +var ( + ErrInvalidLengthGuard = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGuard = fmt.Errorf("proto: integer overflow") +) diff --git a/api/v1/guard.proto b/api/v1/guard.proto new file mode 100644 index 0000000..a800cba --- /dev/null +++ b/api/v1/guard.proto @@ -0,0 +1,54 @@ +syntax = "proto3"; + +package com.crosbymichael.guard.v1; + +import weak "gogoproto/gogo.proto"; +import "google/protobuf/empty.proto"; + +option go_package = "github.com/crosbymichael/guard/api/v1;v1"; + +service Wireguard { + rpc Create(CreateRequest) returns (CreateResponse); + rpc Delete(DeleteRequest) returns (google.protobuf.Empty); + rpc List(google.protobuf.Empty) returns (ListResponse); +} + +message CreateRequest { + string id = 1 [(gogoproto.customname) = "ID"]; + uint32 listen_port = 2; + string address = 3; +} + +message CreateResponse { + Tunnel tunnel = 1; +} + +message DeleteRequest { + string id = 1 [(gogoproto.customname) = "ID"]; +} + +message ListResponse { + repeated Tunnel tunnels = 1; +} + +message Tunnel { + string id = 1 [(gogoproto.customname) = "ID"]; + string private_key = 2; + uint32 listen_port = 3; + string address = 4; + string dns = 5 [(gogoproto.customname) = "DNS"]; + repeated Peer peers = 6; + Masquerade masquerade = 7; +} + +message Peer { + string public_key = 1; + repeated string allowed_ips = 2 [(gogoproto.customname) = "AllowedIPs"]; + string endpoint = 3; + uint32 persistent_keepalive = 4; + string comment = 5; +} + +message Masquerade { + string interface = 1; +} diff --git a/api/v1/tunnel.go b/api/v1/tunnel.go new file mode 100644 index 0000000..77c0638 --- /dev/null +++ b/api/v1/tunnel.go @@ -0,0 +1,74 @@ +/* + Copyright (c) 2019 @crosbymichael + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, copy, + modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, + INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH + THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package v1 + +import ( + "io" + "strings" + "text/template" + + "github.com/pkg/errors" +) + +const confFmt = `[Interface] +PrivateKey = {{.PrivateKey}} +{{if gt .ListenPort 0}}ListenPort = {{.ListenPort}}{{end}} +Address = {{.Address}} +{{if .DNS }}DNS = {{.DNS}}{{end}} + +{{if .Masquerade}} +PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o {{.Masquerade.Interface}} -j MASQUERADE +PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o {{.Masquerade.Interface}} -j MASQUERADE +{{end}} + +{{range $peer := .Peers -}} +# {{$peer.Comment}} +[Peer] +PublicKey = {{$peer.PublicKey}} +AllowedIPs = {{joinIPs $peer.AllowedIPs}} +{{if .Endpoint}}Endpoint = {{.Endpoint}}{{end}} +{{if .PersistentKeepalive}}PersistentKeepalive = {{.PersistentKeepalive}}{{end}} +{{end}} +` + +func (t *Tunnel) Render(w io.Writer) error { + tmp, err := template.New("wireguard").Funcs(template.FuncMap{ + "joinIPs": joinIPs, + }).Parse(confFmt) + if err != nil { + return errors.Wrap(err, "parse template") + } + if err := tmp.Execute(w, t); err != nil { + return errors.Wrap(err, "execute template") + } + return nil +} + +func joinIPs(ips []string) string { + return strings.Join(ips, ", ") +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..1fed961 --- /dev/null +++ b/main.go @@ -0,0 +1,221 @@ +/* + Copyright (c) 2019 @crosbymichael + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, copy, + modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, + INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH + THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package main + +import ( + "context" + "encoding/json" + "fmt" + "net" + "os" + "os/signal" + "syscall" + + v1 "github.com/crosbymichael/guard/api/v1" + "github.com/getsentry/raven-go" + grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" + "github.com/urfave/cli" + "google.golang.org/grpc" +) + +func main() { + app := cli.NewApp() + app.Name = "guard" + app.Version = "1" + app.Usage = "Wireguard grpc server" + app.Flags = []cli.Flag{ + cli.BoolFlag{ + Name: "debug", + Usage: "enable debug output in the logs", + }, + cli.StringFlag{ + Name: "address,a", + Usage: "grpc address", + Value: "127.0.0.1:10100", + }, + cli.StringFlag{ + Name: "sentry-dsn", + Usage: "sentry DSN", + EnvVar: "SENTRY_DSN", + }, + } + app.Before = func(clix *cli.Context) error { + if clix.GlobalBool("debug") { + logrus.SetLevel(logrus.DebugLevel) + } + if dsn := clix.GlobalString("sentry-dsn"); dsn != "" { + raven.SetDSN(dsn) + raven.DefaultClient.SetRelease(app.Version) + } + return nil + } + app.Commands = []cli.Command{ + createCommand, + deleteCommand, + serverCommand, + } + if err := app.Run(os.Args); err != nil { + fmt.Fprintln(os.Stderr, err) + raven.CaptureErrorAndWait(err, nil) + os.Exit(1) + } +} + +var serverCommand = cli.Command{ + Name: "server", + Description: "run the wireguard grpc server", + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "dir", + Usage: "wireguard configuration directory", + Value: defaultWireguardDir, + }, + }, + Action: func(clix *cli.Context) error { + if os.Geteuid() != 0 { + return errors.New("grpc server must run as root") + } + wg, err := newServer(clix.String("dir")) + if err != nil { + return err + } + server := newGRPC() + + v1.RegisterWireguardServer(server, wg) + + signals := make(chan os.Signal, 32) + signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT) + go func() { + <-signals + server.Stop() + }() + l, err := net.Listen("tcp", clix.GlobalString("address")) + if err != nil { + return errors.Wrap(err, "listen tcp") + } + defer l.Close() + return server.Serve(l) + }, +} + +var createCommand = cli.Command{ + Name: "create", + Description: "create a new tunnel", + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "address,a", + Usage: "cidr for the tunnel address", + }, + cli.UintFlag{ + Name: "port,p", + Usage: "listen port for the tunnel", + }, + }, + Action: func(clix *cli.Context) error { + conn, err := grpc.Dial(clix.GlobalString("address"), grpc.WithInsecure()) + if err != nil { + return errors.Wrap(err, "dial server") + } + defer conn.Close() + + var ( + ctx = cancelContext() + client = v1.NewWireguardClient(conn) + ) + + r, err := client.Create(ctx, &v1.CreateRequest{ + ID: clix.Args().First(), + Address: clix.String("address"), + ListenPort: uint32(clix.Uint("port")), + }) + if err != nil { + return err + } + return json.NewEncoder(os.Stdout).Encode(r.Tunnel) + }, +} + +var deleteCommand = cli.Command{ + Name: "delete", + Description: "delete a tunnel", + Action: func(clix *cli.Context) error { + conn, err := grpc.Dial(clix.GlobalString("address"), grpc.WithInsecure()) + if err != nil { + return errors.Wrap(err, "dial server") + } + defer conn.Close() + + var ( + ctx = cancelContext() + client = v1.NewWireguardClient(conn) + ) + if _, err := client.Delete(ctx, &v1.DeleteRequest{ + ID: clix.Args().First(), + }); err != nil { + return err + } + return nil + }, +} + +func newGRPC() *grpc.Server { + s := grpc.NewServer( + grpc.UnaryInterceptor(unary), + grpc.StreamInterceptor(stream), + ) + return s +} + +func unary(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) { + r, err := grpc_prometheus.UnaryServerInterceptor(ctx, req, info, handler) + if err != nil { + raven.CaptureError(err, nil) + } + return r, err +} + +func stream(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { + err := grpc_prometheus.StreamServerInterceptor(srv, ss, info, handler) + if err != nil { + raven.CaptureError(err, nil) + } + return err +} + +func cancelContext() context.Context { + ctx, cancel := context.WithCancel(context.Background()) + s := make(chan os.Signal) + signal.Notify(s, syscall.SIGTERM, syscall.SIGINT) + go func() { + <-s + cancel() + }() + return ctx +} diff --git a/server.go b/server.go new file mode 100644 index 0000000..a61c879 --- /dev/null +++ b/server.go @@ -0,0 +1,177 @@ +/* + Copyright (c) 2019 @crosbymichael + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, copy, + modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, + INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH + THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + "os/exec" + "path/filepath" + + v1 "github.com/crosbymichael/guard/api/v1" + "github.com/gogo/protobuf/types" + "github.com/pkg/errors" +) + +var empty = &types.Empty{} + +const defaultWireguardDir = "/etc/wireguard" + +func newServer(dir string) (*server, error) { + if err := os.MkdirAll(defaultWireguardDir, 0700); err != nil { + return nil, errors.Wrap(err, "create wireguard dir") + } + return &server{ + dir: dir, + }, nil +} + +type server struct { + dir string +} + +func (s *server) Create(ctx context.Context, r *v1.CreateRequest) (*v1.CreateResponse, error) { + if r.ID == "" { + return nil, errors.New("tunnel id cannot be empty") + } + if r.Address == "" { + return nil, errors.New("address cannot be empty") + } + if r.ListenPort == 0 { + return nil, errors.New("listen port cannot be 0") + } + path := filepath.Join(s.dir, r.ID) + if err := os.Mkdir(path, 0700); err != nil { + if os.IsExist(err) { + return nil, errors.New("tunnel already exists") + } + return nil, errors.Wrap(err, "create tunnel directory") + } + key, err := newPrivateKey(ctx) + if err != nil { + return nil, err + } + t := v1.Tunnel{ + ID: r.ID, + ListenPort: r.ListenPort, + Address: r.Address, + PrivateKey: key, + } + + dataPath := filepath.Join(path, "tunnel.json") + if err := saveTunnel(dataPath, &t); err != nil { + return nil, err + } + if err := s.saveConf(&t); err != nil { + os.RemoveAll(path) + + return nil, err + } + if err := wgquick(ctx, "enable", t.ID); err != nil { + return nil, errors.Wrap(err, "enable tunnel") + } + if err := wgquick(ctx, "start", t.ID); err != nil { + return nil, errors.Wrap(err, "start tunnel") + } + return &v1.CreateResponse{ + Tunnel: &t, + }, nil +} + +func (s *server) Delete(ctx context.Context, r *v1.DeleteRequest) (*types.Empty, error) { + if r.ID == "" { + return nil, errors.New("tunnel id cannot be empty") + } + path := filepath.Join(s.dir, r.ID) + if err := wgquick(ctx, "disable", r.ID); err != nil { + return nil, errors.Wrap(err, "disable tunnel") + } + if err := wgquick(ctx, "stop", r.ID); err != nil { + return nil, errors.Wrap(err, "stop tunnel") + } + if err := os.RemoveAll(path); err != nil { + return nil, errors.Wrap(err, "remove data path") + } + if err := os.Remove(filepath.Join(s.dir, fmt.Sprintf("%s.conf", r.ID))); err != nil { + return nil, errors.Wrap(err, "remove configuration") + } + return empty, nil +} + +func (s *server) List(ctx context.Context, _ *types.Empty) (*v1.ListResponse, error) { + return nil, nil +} + +func (s *server) saveConf(t *v1.Tunnel) error { + path := filepath.Join(s.dir, fmt.Sprintf("%s.conf", t.ID)) + f, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600) + if err != nil { + return errors.Wrapf(err, "create tunnel conf %s", path) + } + defer f.Close() + if err := t.Render(f); err != nil { + return errors.Wrap(err, "render tunnel to config") + } + return nil +} + +func saveTunnel(path string, t *v1.Tunnel) error { + f, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600) + if err != nil { + return errors.Wrap(err, "create data.json") + } + defer f.Close() + if err := json.NewEncoder(f).Encode(t); err != nil { + return errors.Wrap(err, "encode tunnel") + } + return nil +} + +func newPrivateKey(ctx context.Context) (string, error) { + data, err := wireguard(ctx, "genkey") + if err != nil { + return "", errors.Wrapf(err, "%s", data) + } + return string(data), nil +} + +func wireguard(ctx context.Context, args ...string) ([]byte, error) { + cmd := exec.CommandContext(ctx, "wg", args...) + return cmd.CombinedOutput() +} + +func wgquick(ctx context.Context, action, name string) error { + cmd := exec.CommandContext(ctx, "systemctl", action, fmt.Sprintf("wg-quick@%s", name)) + out, err := cmd.CombinedOutput() + if err != nil { + return errors.Wrapf(err, "%s", out) + } + return nil +} diff --git a/template.go b/template.go new file mode 100644 index 0000000..0a6ad8b --- /dev/null +++ b/template.go @@ -0,0 +1,28 @@ +/* + Copyright (c) 2019 @crosbymichael + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, copy, + modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, + INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH + THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package main