GODT-1847: add option to export TLS Certificates in GUI.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -56,6 +56,7 @@ service Bridge {
|
||||
rpc ColorSchemeName(google.protobuf.Empty) returns (google.protobuf.StringValue); // TODO Color scheme should probably entirely be managed by the client.
|
||||
rpc CurrentEmailClient(google.protobuf.Empty) returns (google.protobuf.StringValue);
|
||||
rpc ReportBug(ReportBugRequest) returns (google.protobuf.Empty);
|
||||
rpc ExportTLSCertificates(google.protobuf.StringValue) returns (google.protobuf.Empty);
|
||||
rpc ForceLauncher(google.protobuf.StringValue) returns (google.protobuf.Empty);
|
||||
rpc SetMainExecutable(google.protobuf.StringValue) returns (google.protobuf.Empty);
|
||||
|
||||
@ -223,6 +224,7 @@ message StreamEvent {
|
||||
KeychainEvent keychain = 6;
|
||||
MailEvent mail = 7;
|
||||
UserEvent user = 8;
|
||||
GenericErrorEvent genericError = 9;
|
||||
}
|
||||
}
|
||||
|
||||
@ -453,3 +455,15 @@ message UserChangedEvent {
|
||||
string userID = 1;
|
||||
}
|
||||
|
||||
//**********************************************************
|
||||
// Generic errors
|
||||
//**********************************************************
|
||||
enum ErrorCode {
|
||||
UNKNOWN_ERROR = 0;
|
||||
TLS_CERT_EXPORT_ERROR = 1;
|
||||
TLS_KEY_EXPORT_ERROR = 2;
|
||||
}
|
||||
|
||||
message GenericErrorEvent {
|
||||
ErrorCode code = 1;
|
||||
}
|
||||
@ -8,7 +8,6 @@ package grpc
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
@ -52,6 +51,7 @@ type BridgeClient interface {
|
||||
ColorSchemeName(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*wrapperspb.StringValue, error)
|
||||
CurrentEmailClient(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*wrapperspb.StringValue, error)
|
||||
ReportBug(ctx context.Context, in *ReportBugRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
|
||||
ExportTLSCertificates(ctx context.Context, in *wrapperspb.StringValue, opts ...grpc.CallOption) (*emptypb.Empty, error)
|
||||
ForceLauncher(ctx context.Context, in *wrapperspb.StringValue, opts ...grpc.CallOption) (*emptypb.Empty, error)
|
||||
SetMainExecutable(ctx context.Context, in *wrapperspb.StringValue, opts ...grpc.CallOption) (*emptypb.Empty, error)
|
||||
// login
|
||||
@ -332,6 +332,15 @@ func (c *bridgeClient) ReportBug(ctx context.Context, in *ReportBugRequest, opts
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *bridgeClient) ExportTLSCertificates(ctx context.Context, in *wrapperspb.StringValue, opts ...grpc.CallOption) (*emptypb.Empty, error) {
|
||||
out := new(emptypb.Empty)
|
||||
err := c.cc.Invoke(ctx, "/grpc.Bridge/ExportTLSCertificates", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *bridgeClient) ForceLauncher(ctx context.Context, in *wrapperspb.StringValue, opts ...grpc.CallOption) (*emptypb.Empty, error) {
|
||||
out := new(emptypb.Empty)
|
||||
err := c.cc.Invoke(ctx, "/grpc.Bridge/ForceLauncher", in, out, opts...)
|
||||
@ -647,6 +656,7 @@ type BridgeServer interface {
|
||||
ColorSchemeName(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error)
|
||||
CurrentEmailClient(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error)
|
||||
ReportBug(context.Context, *ReportBugRequest) (*emptypb.Empty, error)
|
||||
ExportTLSCertificates(context.Context, *wrapperspb.StringValue) (*emptypb.Empty, error)
|
||||
ForceLauncher(context.Context, *wrapperspb.StringValue) (*emptypb.Empty, error)
|
||||
SetMainExecutable(context.Context, *wrapperspb.StringValue) (*emptypb.Empty, error)
|
||||
// login
|
||||
@ -768,6 +778,9 @@ func (UnimplementedBridgeServer) CurrentEmailClient(context.Context, *emptypb.Em
|
||||
func (UnimplementedBridgeServer) ReportBug(context.Context, *ReportBugRequest) (*emptypb.Empty, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ReportBug not implemented")
|
||||
}
|
||||
func (UnimplementedBridgeServer) ExportTLSCertificates(context.Context, *wrapperspb.StringValue) (*emptypb.Empty, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ExportTLSCertificates not implemented")
|
||||
}
|
||||
func (UnimplementedBridgeServer) ForceLauncher(context.Context, *wrapperspb.StringValue) (*emptypb.Empty, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ForceLauncher not implemented")
|
||||
}
|
||||
@ -1336,6 +1349,24 @@ func _Bridge_ReportBug_Handler(srv interface{}, ctx context.Context, dec func(in
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Bridge_ExportTLSCertificates_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(wrapperspb.StringValue)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(BridgeServer).ExportTLSCertificates(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/grpc.Bridge/ExportTLSCertificates",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(BridgeServer).ExportTLSCertificates(ctx, req.(*wrapperspb.StringValue))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Bridge_ForceLauncher_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(wrapperspb.StringValue)
|
||||
if err := dec(in); err != nil {
|
||||
@ -1972,6 +2003,10 @@ var Bridge_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "ReportBug",
|
||||
Handler: _Bridge_ReportBug_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ExportTLSCertificates",
|
||||
Handler: _Bridge_ExportTLSCertificates_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ForceLauncher",
|
||||
Handler: _Bridge_ForceLauncher_Handler,
|
||||
|
||||
@ -173,6 +173,10 @@ func NewUserChangedEvent(userID string) *StreamEvent {
|
||||
return userEvent(&UserEvent{Event: &UserEvent_UserChanged{UserChanged: &UserChangedEvent{UserID: userID}}})
|
||||
}
|
||||
|
||||
func NewGenericErrorEvent(errorCode ErrorCode) *StreamEvent {
|
||||
return genericErrorEvent(&GenericErrorEvent{Code: errorCode})
|
||||
}
|
||||
|
||||
// Event category factory functions.
|
||||
|
||||
func appEvent(appEvent *AppEvent) *StreamEvent {
|
||||
@ -206,3 +210,7 @@ func mailEvent(event *MailEvent) *StreamEvent {
|
||||
func userEvent(event *UserEvent) *StreamEvent {
|
||||
return &StreamEvent{Event: &StreamEvent_User{User: event}}
|
||||
}
|
||||
|
||||
func genericErrorEvent(event *GenericErrorEvent) *StreamEvent {
|
||||
return &StreamEvent{Event: &StreamEvent_GenericError{GenericError: event}}
|
||||
}
|
||||
|
||||
@ -21,6 +21,8 @@ import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/Masterminds/semver/v3"
|
||||
@ -348,6 +350,26 @@ func (s *Service) ReportBug(ctx context.Context, report *ReportBugRequest) (*emp
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
||||
func (s *Service) ExportTLSCertificates(_ context.Context, folderPath *wrapperspb.StringValue) (*emptypb.Empty, error) {
|
||||
s.log.WithField("folderPath", folderPath).Info("ExportTLSCertificates")
|
||||
|
||||
go func() {
|
||||
defer s.panicHandler.HandlePanic()
|
||||
|
||||
cert, key := s.bridge.GetBridgeTLSCert()
|
||||
|
||||
if err := os.WriteFile(filepath.Join(folderPath.Value, "cert.pem"), cert, 0o600); err != nil {
|
||||
_ = s.SendEvent(NewGenericErrorEvent(ErrorCode_TLS_CERT_EXPORT_ERROR))
|
||||
}
|
||||
|
||||
if err := os.WriteFile(filepath.Join(folderPath.Value, "key.pem"), key, 0o600); err != nil {
|
||||
_ = s.SendEvent(NewGenericErrorEvent(ErrorCode_TLS_KEY_EXPORT_ERROR))
|
||||
}
|
||||
}()
|
||||
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
||||
func (s *Service) ForceLauncher(ctx context.Context, launcher *wrapperspb.StringValue) (*emptypb.Empty, error) {
|
||||
s.log.WithField("launcher", launcher.Value).Debug("ForceLauncher")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user