-
Notifications
You must be signed in to change notification settings - Fork 69
SCB-1563: Support for encrypting values #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
threeq
wants to merge
10
commits into
apache:master
Choose a base branch
from
threeq:encryption
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
460a838
Merge pull request #1 from apache/master
threeq 3fd9374
SCB-1563: Support for encrypting values proxy service
threeq a0208f7
SCB-1563: Optimize &namednoop{} object creation
threeq d3b4fca
SCB-1563: add unit test
threeq 75b2d91
SCB-1563: code format
threeq 8c234e1
SCB-1563: fixed GoLint warnings
threeq bf0c31f
SCB-1563: code format
threeq 5de3523
SCB-1563: fixed bug for code review
threeq 8d5b918
SCB-1563: add unit test
threeq e2218b0
SCB-1563: code format
threeq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * 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 cipher | ||
|
|
||
| import ( | ||
| "github.com/apache/servicecomb-kie/server/config" | ||
| "github.com/apache/servicecomb-kie/server/service" | ||
| "github.com/go-chassis/foundation/security" | ||
| ) | ||
|
|
||
| //See https://github.com/go-chassis/foundation/blob/master/security/cipher.go | ||
| var ciphers map[string]security.Cipher | ||
|
|
||
| // Register is register crypto | ||
| func Register(name string, c security.Cipher) { | ||
| if ciphers == nil { | ||
| ciphers = make(map[string]security.Cipher) | ||
| } | ||
| ciphers[name] = c | ||
| } | ||
|
|
||
| // Lookup is lookup crypto | ||
| func Lookup(name string) security.Cipher { | ||
| cipher, ok := ciphers[name] | ||
| if !ok { | ||
| cipher = &namedNoop{Name: name} | ||
| ciphers[name] = cipher | ||
| } | ||
|
|
||
| return cipher | ||
| } | ||
|
|
||
| // Init init crypto config | ||
| func Init() error { | ||
| if config.GetCrypto().Name == "" { | ||
| return nil | ||
| } | ||
| if service.KVService != nil { | ||
| service.KVService = newCipherKV(service.KVService) | ||
| } | ||
| if service.HistoryService != nil { | ||
| service.HistoryService = newCipherHistory(service.HistoryService) | ||
| } | ||
|
|
||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * 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 cipher | ||
|
|
||
| import ( | ||
| "reflect" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestLookup(t *testing.T) { | ||
| type args struct { | ||
| name string | ||
| value string | ||
| } | ||
| tests := []struct { | ||
| name string | ||
| args args | ||
| want string | ||
| }{ | ||
| {"noop", args{"noop", "123"}, "123"}, | ||
| {"namedNoop", args{"not_implemented", "123"}, "123"}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| gotCipher := Lookup(tt.args.name) | ||
| expect, _ := gotCipher.Encrypt(tt.args.value) | ||
| if !reflect.DeepEqual(expect, tt.want) { | ||
| t.Errorf("Lookup() = %v, want %v", expect, tt.want) | ||
| } | ||
|
|
||
| expect, _ = gotCipher.Decrypt(tt.args.value) | ||
| if !reflect.DeepEqual(expect, tt.want) { | ||
| t.Errorf("Lookup() = %v, want %v", expect, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| type testCipher struct{} | ||
|
|
||
| func (*testCipher) Encrypt(src string) (string, error) { | ||
| return src, nil | ||
| } | ||
|
|
||
| func (*testCipher) Decrypt(src string) (string, error) { | ||
| return src, nil | ||
| } | ||
|
|
||
| func TestRegister(t *testing.T) { | ||
| test := &testCipher{} | ||
| noop2 := &namedNoop{} | ||
| Register("test", test) | ||
| Register("noop2", noop2) | ||
|
|
||
| act := Lookup("test") | ||
| if !reflect.DeepEqual(test, act) { | ||
| t.Errorf("Register() = %v, want %v", test, act) | ||
| } | ||
| act = Lookup("noop2") | ||
| if !reflect.DeepEqual(noop2, act) { | ||
| t.Errorf("Register() = %v, want %v", noop2, act) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * 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 cipher | ||
|
|
||
| func init() { | ||
| Register("noop", &Noop{}) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * 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 cipher | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "github.com/go-mesh/openlogging" | ||
| ) | ||
|
|
||
| // Noop is none implement | ||
| type Noop struct { | ||
| } | ||
|
|
||
| // Encrypt implement | ||
| func (*Noop) Encrypt(src string) (string, error) { | ||
| return src, nil | ||
| } | ||
|
|
||
| // Decrypt implement | ||
| func (*Noop) Decrypt(src string) (string, error) { | ||
| return src, nil | ||
| } | ||
|
|
||
| type namedNoop struct { | ||
| Name string | ||
| } | ||
|
|
||
| func (nn *namedNoop) Encrypt(src string) (string, error) { | ||
| openlogging.Warn(fmt.Sprintf("security name [%s] not implemented.", nn.Name)) | ||
| return src, nil | ||
| } | ||
|
|
||
| func (nn *namedNoop) Decrypt(src string) (string, error) { | ||
| openlogging.Warn(fmt.Sprintf("security name [%s] not implemented.", nn.Name)) | ||
| return src, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| /* | ||
| * 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 cipher | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestNoop_Encrypt(t *testing.T) { | ||
| type args struct { | ||
| src string | ||
| } | ||
| tests := []struct { | ||
| name string | ||
| args args | ||
| want string | ||
| wantErr bool | ||
| }{ | ||
| {"empty", args{""}, "", false}, | ||
| {"123", args{"123"}, "123", false}, | ||
| {"nil", args{}, "", false}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| n := &Noop{} | ||
| got, err := n.Encrypt(tt.args.src) | ||
| if (err != nil) != tt.wantErr { | ||
| t.Errorf("Noop.Encrypt() error = %v, wantErr %v", err, tt.wantErr) | ||
| return | ||
| } | ||
| if got != tt.want { | ||
| t.Errorf("Noop.Encrypt() = %v, want %v", got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestNoop_Decrypt(t *testing.T) { | ||
| type args struct { | ||
| src string | ||
| } | ||
| tests := []struct { | ||
| name string | ||
| args args | ||
| want string | ||
| wantErr bool | ||
| }{ | ||
| {"empty", args{""}, "", false}, | ||
| {"123", args{"123"}, "123", false}, | ||
| {"nil", args{}, "", false}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| n := &Noop{} | ||
| got, err := n.Decrypt(tt.args.src) | ||
| if (err != nil) != tt.wantErr { | ||
| t.Errorf("Noop.Decrypt() error = %v, wantErr %v", err, tt.wantErr) | ||
| return | ||
| } | ||
| if got != tt.want { | ||
| t.Errorf("Noop.Decrypt() = %v, want %v", got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func Test_namedNoop_Encrypt(t *testing.T) { | ||
| type args struct { | ||
| src string | ||
| } | ||
| tests := []struct { | ||
| name string | ||
| args args | ||
| want string | ||
| wantErr bool | ||
| }{ | ||
| {"empty", args{""}, "", false}, | ||
| {"123", args{"123"}, "123", false}, | ||
| {"nil", args{}, "", false}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| nn := &namedNoop{ | ||
| Name: "any", | ||
| } | ||
| got, err := nn.Encrypt(tt.args.src) | ||
| if (err != nil) != tt.wantErr { | ||
| t.Errorf("namedNoop.Encrypt() error = %v, wantErr %v", err, tt.wantErr) | ||
| return | ||
| } | ||
| if got != tt.want { | ||
| t.Errorf("namedNoop.Encrypt() = %v, want %v", got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func Test_namedNoop_Decrypt(t *testing.T) { | ||
|
|
||
| type args struct { | ||
| src string | ||
| } | ||
| tests := []struct { | ||
| name string | ||
| args args | ||
| want string | ||
| wantErr bool | ||
| }{ | ||
| {"empty", args{""}, "", false}, | ||
| {"123", args{"123"}, "123", false}, | ||
| {"nil", args{}, "", false}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| nn := &namedNoop{ | ||
| Name: "any", | ||
| } | ||
| got, err := nn.Decrypt(tt.args.src) | ||
| if (err != nil) != tt.wantErr { | ||
| t.Errorf("namedNoop.Decrypt() error = %v, wantErr %v", err, tt.wantErr) | ||
| return | ||
| } | ||
| if got != tt.want { | ||
| t.Errorf("namedNoop.Decrypt() = %v, want %v", got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要提交ca上来
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
主分支已经存在,是 #20 合并进来的,确定要删除吗?