Skip to content
Snippets Groups Projects
Commit 260de7e1 authored by Gospodin Bodurov's avatar Gospodin Bodurov
Browse files

Merge branch 'smime-reflector' into 'master'

Smime reflector

See merge request !54
parents 63650b63 e5f71b24
Branches
Tags 1.0 1.0-rc1
1 merge request!54Smime reflector
...@@ -25,6 +25,8 @@ var CaCertificatePEM []byte ...@@ -25,6 +25,8 @@ var CaCertificatePEM []byte
var VereignCaCertificatePEM []byte var VereignCaCertificatePEM []byte
var VereignCaKeyPEM []byte var VereignCaKeyPEM []byte
var ReplaceKey bool
var MaxMessageSize int var MaxMessageSize int
var GrpcListenAddress string var GrpcListenAddress string
...@@ -42,6 +44,8 @@ func SetConfigValues(configFile, etcdURL string) { ...@@ -42,6 +44,8 @@ func SetConfigValues(configFile, etcdURL string) {
viper.SetDefault("dataStorageUrl", "data-storage-agent:7777") viper.SetDefault("dataStorageUrl", "data-storage-agent:7777")
viper.SetDefault("entitiesManagerUrl", "entities-management-agent:7779") viper.SetDefault("entitiesManagerUrl", "entities-management-agent:7779")
viper.SetDefault("replaceKey", false)
viper.SetDefault("viamUUID", "viam-system") viper.SetDefault("viamUUID", "viam-system")
viper.SetDefault("viamSession", "viam-session") viper.SetDefault("viamSession", "viam-session")
...@@ -127,6 +131,8 @@ func SetConfigValues(configFile, etcdURL string) { ...@@ -127,6 +131,8 @@ func SetConfigValues(configFile, etcdURL string) {
DataStorageUrl = viper.GetString("dataStorageUrl") DataStorageUrl = viper.GetString("dataStorageUrl")
EntitiesManagerUrl = viper.GetString("entitiesManagerUrl") EntitiesManagerUrl = viper.GetString("entitiesManagerUrl")
ReplaceKey = viper.GetBool("replaceKey")
SystemAuth.Uuid = viper.GetString("viamUUID") SystemAuth.Uuid = viper.GetString("viamUUID")
SystemAuth.Session = viper.GetString("viamSession") SystemAuth.Session = viper.GetString("viamSession")
......
...@@ -22,8 +22,10 @@ import ( ...@@ -22,8 +22,10 @@ import (
"errors" "errors"
"log" "log"
"strings" "strings"
"code.vereign.com/code/viam-apis/clientutils" "code.vereign.com/code/viam-apis/clientutils"
"code.vereign.com/code/key-storage-agent/config"
keyutils "code.vereign.com/code/key-storage-agent/utils" keyutils "code.vereign.com/code/key-storage-agent/utils"
"code.vereign.com/code/viam-apis/authentication" "code.vereign.com/code/viam-apis/authentication"
"code.vereign.com/code/viam-apis/key-storage-agent/api" "code.vereign.com/code/viam-apis/key-storage-agent/api"
...@@ -94,7 +96,7 @@ func (s *KeyStorageServerImpl) GetKey(ctx context.Context, in *api.GetKeyRequest ...@@ -94,7 +96,7 @@ func (s *KeyStorageServerImpl) GetKey(ctx context.Context, in *api.GetKeyRequest
if in.KeyType == api.KeyType_KT_EMPTY { if in.KeyType == api.KeyType_KT_EMPTY {
getKeyResponse.StatusList = utils.AddStatus(getKeyResponse.StatusList, getKeyResponse.StatusList = utils.AddStatus(getKeyResponse.StatusList,
"400", api.StatusType_ERROR, "KeyType cannot be empty") "400", api.StatusType_ERROR, "KeyType cannot be empty")
return getKeyResponse, nil return getKeyResponse, errors.New("KeyType cannot be empty")
} }
key := &api.Key{} key := &api.Key{}
...@@ -105,21 +107,22 @@ func (s *KeyStorageServerImpl) GetKey(ctx context.Context, in *api.GetKeyRequest ...@@ -105,21 +107,22 @@ func (s *KeyStorageServerImpl) GetKey(ctx context.Context, in *api.GetKeyRequest
getKeyResponse.Key = nil getKeyResponse.Key = nil
getKeyResponse.StatusList = utils.AddStatus(getKeyResponse.StatusList, getKeyResponse.StatusList = utils.AddStatus(getKeyResponse.StatusList,
"500", api.StatusType_ERROR, err.Error()) "500", api.StatusType_ERROR, err.Error())
return getKeyResponse, nil return getKeyResponse, err
} }
if errorsString != "" { if errorsString != "" {
getKeyResponse.Key = nil getKeyResponse.Key = nil
getKeyResponse.StatusList = utils.AddStatus(getKeyResponse.StatusList, getKeyResponse.StatusList = utils.AddStatus(getKeyResponse.StatusList,
"500", api.StatusType_ERROR, errorsString) "500", api.StatusType_ERROR, errorsString)
return nil, errors.New(errorsString)
} }
if !hasData { if !hasData {
log.Println("No such key " + in.Uuid) log.Println("No such key " + in.Uuid)
getKeyResponse.Key = nil getKeyResponse.Key = nil
getKeyResponse.StatusList = utils.AddStatus(getKeyResponse.StatusList, getKeyResponse.StatusList = utils.AddStatus(getKeyResponse.StatusList,
"500", api.StatusType_ERROR, err.Error()) "500", api.StatusType_ERROR, err.Error())
return getKeyResponse, nil return getKeyResponse, err
} }
getKeyResponse.Key = key getKeyResponse.Key = key
...@@ -138,29 +141,31 @@ func (s *KeyStorageServerImpl) SetKey(ctx context.Context, in *api.SetKeyRequest ...@@ -138,29 +141,31 @@ func (s *KeyStorageServerImpl) SetKey(ctx context.Context, in *api.SetKeyRequest
if in.Uuid == "root" { if in.Uuid == "root" {
setKeyResponse.StatusList = utils.AddStatus(setKeyResponse.StatusList, setKeyResponse.StatusList = utils.AddStatus(setKeyResponse.StatusList,
"400", api.StatusType_ERROR, "Can not set root CA keys") "400", api.StatusType_ERROR, "Can not set root CA keys")
return setKeyResponse, nil return setKeyResponse, errors.New("Can not set root CA keys")
} }
if in.KeyType == api.KeyType_KT_EMPTY { if in.KeyType == api.KeyType_KT_EMPTY {
setKeyResponse.StatusList = utils.AddStatus(setKeyResponse.StatusList, setKeyResponse.StatusList = utils.AddStatus(setKeyResponse.StatusList,
"400", api.StatusType_ERROR, "KeyType cannot be empty") "400", api.StatusType_ERROR, "KeyType cannot be empty")
return setKeyResponse, nil return setKeyResponse, errors.New("KeyType cannot be empty")
} }
key := &api.Key{} key := &api.Key{}
_, _, err := client.GetData("keys", in.Uuid+"/"+api.KeyType.String(in.KeyType), key) if config.ReplaceKey == false {
if err != nil { _, _, err := client.GetData("keys", in.Uuid+"/"+api.KeyType.String(in.KeyType), key)
log.Printf("grpc call GetData to DataStorage failed: %s", err) if err != nil {
setKeyResponse.StatusList = utils.AddStatus(setKeyResponse.StatusList, log.Printf("grpc call GetData to DataStorage failed: %s", err)
"500", api.StatusType_ERROR, err.Error()) setKeyResponse.StatusList = utils.AddStatus(setKeyResponse.StatusList,
return setKeyResponse, nil "500", api.StatusType_ERROR, err.Error())
} return setKeyResponse, err
}
if len(key.Content) > 0 { if len(key.Content) > 0 {
setKeyResponse.StatusList = utils.AddStatus(setKeyResponse.StatusList, setKeyResponse.StatusList = utils.AddStatus(setKeyResponse.StatusList,
"400", api.StatusType_ERROR, "Key is already set") "400", api.StatusType_ERROR, "Key is already set")
return setKeyResponse, nil return setKeyResponse, errors.New("Key is already set")
}
} }
result, errors, err := client.PutData("keys", in.Uuid+"/"+api.KeyType.String(in.KeyType), in.Key) result, errors, err := client.PutData("keys", in.Uuid+"/"+api.KeyType.String(in.KeyType), in.Key)
...@@ -268,7 +273,7 @@ func (s *KeyStorageServerImpl) GetKeyId(ctx context.Context, in *api.GetKeyIdByK ...@@ -268,7 +273,7 @@ func (s *KeyStorageServerImpl) GetKeyId(ctx context.Context, in *api.GetKeyIdByK
log.Printf("Error: %s", errorsString) log.Printf("Error: %s", errorsString)
return nil, errors.New(errorsString) return nil, errors.New(errorsString)
} }
if !hasData { if !hasData {
log.Println("No such checkID " + checkID) log.Println("No such checkID " + checkID)
return nil, errors.New("No such checkID " + checkID) return nil, errors.New("No such checkID " + checkID)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment