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

Merge branch '8-142-implement_ca_cert' into 'ci'

Resolve "142-Implement_CA_cert"

See merge request !18
parents 118781a2 84eeccc5
Branches ci
Tags
2 merge requests!19Ci,!18Resolve "142-Implement_CA_cert"
[[constraint]] [[constraint]]
branch = "142-Implement_CA_cert" branch = "ci"
name = "code.vereign.com/code/viam-apis" name = "code.vereign.com/code/viam-apis"
[[constraint]] [[constraint]]
......
...@@ -20,6 +20,9 @@ vereignCertFile: vereign_ca.cer ...@@ -20,6 +20,9 @@ vereignCertFile: vereign_ca.cer
vereignCertKey: vereign_ca.key vereignCertKey: vereign_ca.key
caCertFile: ca.crt caCertFile: ca.crt
# Maximum Message Size (in megabytes)
maxMessageSize: 32
# Read Certificates From Vault Server # Read Certificates From Vault Server
vaultAddress: http://10.6.10.119:8200 vaultAddress: http://10.6.10.119:8200
vaultToken: 00000000-0000-0000-0000-000000000000 vaultToken: 00000000-0000-0000-0000-000000000000
......
...@@ -39,7 +39,7 @@ func (s *KeyStorageServerImpl) GenerateKeyPair(ctx context.Context, ...@@ -39,7 +39,7 @@ func (s *KeyStorageServerImpl) GenerateKeyPair(ctx context.Context,
auth := s.CreateAuthentication(ctx) auth := s.CreateAuthentication(ctx)
client := &client.DataStorageClientImpl{} 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() defer client.CloseClient()
generateKeyPairResponse := &api.GenerateKeyPairResponse{} generateKeyPairResponse := &api.GenerateKeyPairResponse{}
......
...@@ -40,6 +40,7 @@ type KeyStorageServerImpl struct { ...@@ -40,6 +40,7 @@ type KeyStorageServerImpl struct {
CaCertFilePath string CaCertFilePath string
VereignCertFilePath string VereignCertFilePath string
VereignPrivateKeyFilePath string VereignPrivateKeyFilePath string
MaxMessageSize int
} }
func (s *KeyStorageServerImpl) CreateAuthentication(ctx context.Context) *authentication.Authentication { func (s *KeyStorageServerImpl) CreateAuthentication(ctx context.Context) *authentication.Authentication {
...@@ -62,7 +63,7 @@ func (s *KeyStorageServerImpl) GetKey(ctx context.Context, in *api.GetKeyRequest ...@@ -62,7 +63,7 @@ func (s *KeyStorageServerImpl) GetKey(ctx context.Context, in *api.GetKeyRequest
auth := s.CreateAuthentication(ctx) auth := s.CreateAuthentication(ctx)
client := &client.DataStorageClientImpl{} 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() defer client.CloseClient()
getKeyResponse := &api.GetKeyResponse{} getKeyResponse := &api.GetKeyResponse{}
...@@ -109,7 +110,7 @@ func (s *KeyStorageServerImpl) SetKey(ctx context.Context, in *api.SetKeyRequest ...@@ -109,7 +110,7 @@ func (s *KeyStorageServerImpl) SetKey(ctx context.Context, in *api.SetKeyRequest
auth := s.CreateAuthentication(ctx) auth := s.CreateAuthentication(ctx)
client := &client.DataStorageClientImpl{} 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() defer client.CloseClient()
setKeyResponse := &api.SetKeyResponse{} setKeyResponse := &api.SetKeyResponse{}
...@@ -157,7 +158,7 @@ func (s *KeyStorageServerImpl) ReserveKeyUUID(ctx context.Context, in *api.Reser ...@@ -157,7 +158,7 @@ func (s *KeyStorageServerImpl) ReserveKeyUUID(ctx context.Context, in *api.Reser
auth := s.CreateAuthentication(ctx) auth := s.CreateAuthentication(ctx)
client := &client.DataStorageClientImpl{} 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() defer client.CloseClient()
reserveKeyUUIDResponse := &api.ReserveKeyUUIDResponse{} reserveKeyUUIDResponse := &api.ReserveKeyUUIDResponse{}
......
...@@ -29,7 +29,7 @@ func (s *KeyStorageServerImpl) Revoke(ctx context.Context, in *api.RevokeRequest ...@@ -29,7 +29,7 @@ func (s *KeyStorageServerImpl) Revoke(ctx context.Context, in *api.RevokeRequest
auth := s.CreateAuthentication(ctx) auth := s.CreateAuthentication(ctx)
client := &client.DataStorageClientImpl{} 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() defer client.CloseClient()
revokeResponse := &api.RevokeResponse{} revokeResponse := &api.RevokeResponse{}
......
...@@ -45,10 +45,12 @@ func main() { ...@@ -45,10 +45,12 @@ func main() {
vereignCertFilePath := certDir + "/" + viper.GetString("vereignCertFile") vereignCertFilePath := certDir + "/" + viper.GetString("vereignCertFile")
vereignPrivateKeyFilePath := certDir + "/" + viper.GetString("vereignCertKey") vereignPrivateKeyFilePath := certDir + "/" + viper.GetString("vereignCertKey")
maxMessageSize := viper.GetInt("maxMessageSize")
// fire the gRPC server in a goroutine // fire the gRPC server in a goroutine
go func() { go func() {
err := server.StartGRPCServer(grpcAddress, certFilePath, privateKeyFilePath, caCertFilePath, vereignCertFilePath, err := server.StartGRPCServer(grpcAddress, certFilePath, privateKeyFilePath, caCertFilePath, vereignCertFilePath,
vereignPrivateKeyFilePath, dataStorageAddress) vereignPrivateKeyFilePath, dataStorageAddress, maxMessageSize)
if err != nil { if err != nil {
log.Fatalf("failed to start gRPC server: %s", err) log.Fatalf("failed to start gRPC server: %s", err)
} }
......
...@@ -21,10 +21,19 @@ func SetConfigValues() { ...@@ -21,10 +21,19 @@ func SetConfigValues() {
viper.SetDefault("vereignCertFile", "vereign_ca.cer") viper.SetDefault("vereignCertFile", "vereign_ca.cer")
viper.SetDefault("vereignCertKey", "vereign_ca.key") viper.SetDefault("vereignCertKey", "vereign_ca.key")
viper.SetDefault("maxMessageSize", "32")
// Read Config File // Read Config File
viper.SetConfigName("config") viper.SetConfigName("config")
viper.AddConfigPath(".") viper.AddConfigPath(".")
if err := viper.ReadInConfig(); err != nil { if err := viper.ReadInConfig(); err != nil {
log.Printf("can't read config: %s, will use default values", err) log.Printf("can't read config: %s, will use default values", err)
} }
// Print all config values to log file
log.Printf("All Settings From Config:")
as := viper.AllSettings()
for key, _ := range as {
log.Printf("%s => %s", key, viper.GetString(key))
}
} }
\ No newline at end of file
...@@ -72,7 +72,7 @@ func authenticateClient(ctx context.Context, s *handler.KeyStorageServerImpl, in ...@@ -72,7 +72,7 @@ func authenticateClient(ctx context.Context, s *handler.KeyStorageServerImpl, in
} }
sessionClient := &client.DataStorageClientImpl{} 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() defer sessionClient.CloseClient()
if clientAuth.Uuid == viamAuth.Uuid { if clientAuth.Uuid == viamAuth.Uuid {
...@@ -109,7 +109,7 @@ func unaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServ ...@@ -109,7 +109,7 @@ func unaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServ
return handler1(ctx, req) 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 pkgCertFile = certFilePath
pkgKeyFile = privateKeyFilePath pkgKeyFile = privateKeyFilePath
pkgCaCertFile = caCertFilePath pkgCaCertFile = caCertFilePath
...@@ -128,6 +128,7 @@ func StartGRPCServer(address, certFilePath, privateKeyFilePath, caCertFilePath, ...@@ -128,6 +128,7 @@ func StartGRPCServer(address, certFilePath, privateKeyFilePath, caCertFilePath,
CaCertFilePath: caCertFilePath, CaCertFilePath: caCertFilePath,
VereignCertFilePath: vereignCertFilePath, VereignCertFilePath: vereignCertFilePath,
VereignPrivateKeyFilePath: vereignPrivateKeyFilePath, VereignPrivateKeyFilePath: vereignPrivateKeyFilePath,
MaxMessageSize: maxMessageSize,
} }
// Create the TLS credentials // Create the TLS credentials
...@@ -137,8 +138,11 @@ func StartGRPCServer(address, certFilePath, privateKeyFilePath, caCertFilePath, ...@@ -137,8 +138,11 @@ func StartGRPCServer(address, certFilePath, privateKeyFilePath, caCertFilePath,
} }
// Create an array of gRPC options with the credentials // Create an array of gRPC options with the credentials
opts := []grpc.ServerOption{grpc.Creds(creds), opts := []grpc.ServerOption{
grpc.UnaryInterceptor(unaryInterceptor)} grpc.Creds(creds),
grpc.UnaryInterceptor(unaryInterceptor),
grpc.MaxRecvMsgSize(viper.GetInt("maxMessageSize")*1024*1024),
}
// create a gRPC server object // create a gRPC server object
grpcServer := grpc.NewServer(opts...) grpcServer := grpc.NewServer(opts...)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment