Skip to content
Snippets Groups Projects
Commit 9eb27a06 authored by Olgun Cengiz's avatar Olgun Cengiz :drum:
Browse files

Merge branch '9-configurable-maxmessagesize' into '8-142-implement_ca_cert'

Resolve "Configurable MaxMessageSize"

See merge request !17
parents 6d429ab5 cab1b715
No related branches found
No related tags found
3 merge requests!19Ci,!18Resolve "142-Implement_CA_cert",!17Resolve "Configurable MaxMessageSize"
......@@ -20,6 +20,9 @@ vereignCertFile: vereign_ca.cer
vereignCertKey: vereign_ca.key
caCertFile: ca.crt
# Maximum Message Size (in megabytes)
maxMessageSize: 32
# Read Certificates From Vault Server
vaultAddress: http://10.6.10.119:8200
vaultToken: 00000000-0000-0000-0000-000000000000
......
......@@ -39,7 +39,7 @@ func (s *KeyStorageServerImpl) GenerateKeyPair(ctx context.Context,
auth := s.CreateAuthentication(ctx)
client := &client.DataStorageClientImpl{}
client.SetUpClient(auth, s.DataStorageUrl, s.CertFilePath, s.KeyFilePath, s.CaCertFilePath)
client.SetUpClient(auth, s.DataStorageUrl, s.CertFilePath, s.KeyFilePath, s.CaCertFilePath, s.MaxMessageSize)
defer client.CloseClient()
generateKeyPairResponse := &api.GenerateKeyPairResponse{}
......
......@@ -40,6 +40,7 @@ type KeyStorageServerImpl struct {
CaCertFilePath string
VereignCertFilePath string
VereignPrivateKeyFilePath string
MaxMessageSize int
}
func (s *KeyStorageServerImpl) CreateAuthentication(ctx context.Context) *authentication.Authentication {
......@@ -62,7 +63,7 @@ func (s *KeyStorageServerImpl) GetKey(ctx context.Context, in *api.GetKeyRequest
auth := s.CreateAuthentication(ctx)
client := &client.DataStorageClientImpl{}
client.SetUpClient(auth, s.DataStorageUrl, s.CertFilePath, s.KeyFilePath, s.CaCertFilePath)
client.SetUpClient(auth, s.DataStorageUrl, s.CertFilePath, s.KeyFilePath, s.CaCertFilePath, s.MaxMessageSize)
defer client.CloseClient()
getKeyResponse := &api.GetKeyResponse{}
......@@ -109,7 +110,7 @@ func (s *KeyStorageServerImpl) SetKey(ctx context.Context, in *api.SetKeyRequest
auth := s.CreateAuthentication(ctx)
client := &client.DataStorageClientImpl{}
client.SetUpClient(auth, s.DataStorageUrl, s.CertFilePath, s.KeyFilePath, s.CaCertFilePath)
client.SetUpClient(auth, s.DataStorageUrl, s.CertFilePath, s.KeyFilePath, s.CaCertFilePath, s.MaxMessageSize)
defer client.CloseClient()
setKeyResponse := &api.SetKeyResponse{}
......@@ -157,7 +158,7 @@ func (s *KeyStorageServerImpl) ReserveKeyUUID(ctx context.Context, in *api.Reser
auth := s.CreateAuthentication(ctx)
client := &client.DataStorageClientImpl{}
client.SetUpClient(auth, s.DataStorageUrl, s.CertFilePath, s.KeyFilePath, s.CaCertFilePath)
client.SetUpClient(auth, s.DataStorageUrl, s.CertFilePath, s.KeyFilePath, s.CaCertFilePath, s.MaxMessageSize)
defer client.CloseClient()
reserveKeyUUIDResponse := &api.ReserveKeyUUIDResponse{}
......
......@@ -29,7 +29,7 @@ func (s *KeyStorageServerImpl) Revoke(ctx context.Context, in *api.RevokeRequest
auth := s.CreateAuthentication(ctx)
client := &client.DataStorageClientImpl{}
client.SetUpClient(auth, s.DataStorageUrl, s.CertFilePath, s.KeyFilePath, s.CaCertFilePath)
client.SetUpClient(auth, s.DataStorageUrl, s.CertFilePath, s.KeyFilePath, s.CaCertFilePath, s.MaxMessageSize)
defer client.CloseClient()
revokeResponse := &api.RevokeResponse{}
......
......@@ -45,10 +45,12 @@ func main() {
vereignCertFilePath := certDir + "/" + viper.GetString("vereignCertFile")
vereignPrivateKeyFilePath := certDir + "/" + viper.GetString("vereignCertKey")
maxMessageSize := viper.GetInt("maxMessageSize")
// fire the gRPC server in a goroutine
go func() {
err := server.StartGRPCServer(grpcAddress, certFilePath, privateKeyFilePath, caCertFilePath, vereignCertFilePath,
vereignPrivateKeyFilePath, dataStorageAddress)
vereignPrivateKeyFilePath, dataStorageAddress, maxMessageSize)
if err != nil {
log.Fatalf("failed to start gRPC server: %s", err)
}
......
......@@ -21,6 +21,8 @@ func SetConfigValues() {
viper.SetDefault("vereignCertFile", "vereign_ca.cer")
viper.SetDefault("vereignCertKey", "vereign_ca.key")
viper.SetDefault("maxMessageSize", "32")
// Read Config File
viper.SetConfigName("config")
viper.AddConfigPath(".")
......
......@@ -72,7 +72,7 @@ func authenticateClient(ctx context.Context, s *handler.KeyStorageServerImpl, in
}
sessionClient := &client.DataStorageClientImpl{}
sessionClient.SetUpClient(viamAuth, viper.GetString("dataStorageUrl"), pkgCertFile, pkgKeyFile, pkgCaCertFile)
sessionClient.SetUpClient(viamAuth, viper.GetString("dataStorageUrl"), pkgCertFile, pkgKeyFile, pkgCaCertFile, viper.GetInt("maxMessageSize"))
defer sessionClient.CloseClient()
if clientAuth.Uuid == viamAuth.Uuid {
......@@ -109,7 +109,7 @@ func unaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServ
return handler1(ctx, req)
}
func StartGRPCServer(address, certFilePath, privateKeyFilePath, caCertFilePath, vereignCertFilePath, vereignPrivateKeyFilePath, dataStorageAddress string) error {
func StartGRPCServer(address, certFilePath, privateKeyFilePath, caCertFilePath, vereignCertFilePath, vereignPrivateKeyFilePath, dataStorageAddress string, maxMessageSize int) error {
pkgCertFile = certFilePath
pkgKeyFile = privateKeyFilePath
pkgCaCertFile = caCertFilePath
......@@ -128,6 +128,7 @@ func StartGRPCServer(address, certFilePath, privateKeyFilePath, caCertFilePath,
CaCertFilePath: caCertFilePath,
VereignCertFilePath: vereignCertFilePath,
VereignPrivateKeyFilePath: vereignPrivateKeyFilePath,
MaxMessageSize: maxMessageSize,
}
// Create the TLS credentials
......@@ -137,8 +138,11 @@ func StartGRPCServer(address, certFilePath, privateKeyFilePath, caCertFilePath,
}
// Create an array of gRPC options with the credentials
opts := []grpc.ServerOption{grpc.Creds(creds),
grpc.UnaryInterceptor(unaryInterceptor)}
opts := []grpc.ServerOption{
grpc.Creds(creds),
grpc.UnaryInterceptor(unaryInterceptor),
grpc.MaxRecvMsgSize(viper.GetInt("maxMessageSize")*1024*1024),
}
// create a gRPC server object
grpcServer := grpc.NewServer(opts...)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment