You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2019/12/11 01:48:07 UTC
[GitHub] [servicecomb-kie] threeq commented on a change in pull request #55:
SCB-1563: Support for encrypting values
threeq commented on a change in pull request #55: SCB-1563: Support for encrypting values
URL: https://github.com/apache/servicecomb-kie/pull/55#discussion_r356368500
##########
File path: server/service/crypto_service.go
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package service
+
+import (
+ "context"
+ "github.com/apache/servicecomb-kie/pkg/model"
+ "github.com/apache/servicecomb-kie/server/config"
+ "github.com/apache/servicecomb-kie/server/crypto"
+)
+
+// CryptoInit init crypto config
+func CryptoInit() error {
+ if config.GetCrypto().Name == "" {
+ return nil
+ }
+ if KVService != nil {
+ KVService = newCryptoKV(KVService)
+ }
+ if HistoryService != nil {
+ HistoryService = newCryptoHistory(HistoryService)
+ }
+
+ return nil
+}
+
+func newCryptoHistory(service History) History {
+ return &cryptoHistory{service: service}
+}
+
+func newCryptoKV(service KV) KV {
+ return &cryptoKV{service: service}
+}
+
+// lookup Crypto
+func lookupCrypto(kv *model.KVDoc) crypto.Cipher {
+ return crypto.Lookup(config.GetCrypto().Name)
+}
+
+// History service security proxy
+type cryptoHistory struct {
+ service History
+}
+
+func (history *cryptoHistory) GetHistory(ctx context.Context, labelID string, options ...FindOption) ([]*model.LabelRevisionDoc, error) {
+ res, err := history.service.GetHistory(ctx, labelID, options...)
+
+ cipher := lookupCrypto(nil)
+
+ for i := 0; i < len(res); i++ {
+ doc := res[i]
+ for j := 0; j < len(doc.KVs); j++ {
+ kv := doc.KVs[j]
+ val, err := cipher.Decrypt(kv.Value)
+ if err != nil {
+ return nil, err
+ }
+ kv.Value = val
+ }
+ }
+
+ return res, err
+}
+
+// KV service security proxy
+type cryptoKV struct {
+ service KV
+}
+
+func (ckv *cryptoKV) CreateOrUpdate(ctx context.Context, kv *model.KVDoc) (*model.KVDoc, error) {
Review comment:
这样就需要写到两个具体实现里面,
github-projs/servicecomb-kie/server/service/mongo/history/service.go
github-projs/servicecomb-kie/server/service/mongo/kv/kv_service.go
这样如果后面换了存储实现(比如 consul,mysql 等),再次实现这个 service 的时候也需要加上加密的相关实现,这样会增加和底层 service 的耦合度及其实现难度。所以我建议对加密形成一个中间代理层,这个代理层里面的对加密的实现其实和底层的存储无关
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services