-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add AES key support for KEK bundles #25
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7522fa3
feat(aes): add CheckValue and VerifyCheckValue methods
lwschan-tw efd5229
feat(aes): add factory functions for key creation
lwschan-tw dfa644c
feat(kek): add AES key type support for KEK bundles
lwschan-tw f44b887
refactor: rename KeyType 3DES to TripleDES
lwschan-tw 9e1f997
docs: update comments to highlight deprecated methods
lwschan-tw 4faa1f6
refactor: cleanup kek_bundle
lwschan-tw ca7620d
refactor: separate merge method
lwschan-tw 209503d
docs: update comment
lwschan-tw 7bceb17
bump version to 1.12.0
lwschan-tw 9b6f97f
docs: update README
lwschan-tw df4f431
test: fix expired key used for pgp testing
lwschan-tw 44a3cca
fix comments and add more tests
lwschan-tw 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 1.11.0 | ||
| 1.12.0 |
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,49 @@ | ||
| /* | ||
| Licensed 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 aes | ||
|
|
||
| import ( | ||
| "crypto/aes" | ||
| "crypto/cipher" | ||
| "encoding/hex" | ||
| "errors" | ||
| ) | ||
|
|
||
| // CreateFromKeyBytes constructs a new AES GCM cipher using the raw key bytes provided, the raw bytes must be either 16, 24, or 32 bytes | ||
| func CreateFromKeyBytes(keyBytes []byte) (Cipher, error) { | ||
| if len(keyBytes) != 16 && len(keyBytes) != 24 && len(keyBytes) != 32 { | ||
| return Cipher{}, errors.New("AES key must be 16, 24, or 32 bytes") | ||
| } | ||
|
|
||
| aesCipher, err := aes.NewCipher(keyBytes) | ||
| if err != nil { | ||
| return Cipher{}, errors.New("invalid AES keyBlock") | ||
| } | ||
|
|
||
| gcmCipher, err := cipher.NewGCM(aesCipher) | ||
| if err != nil { | ||
| return Cipher{}, errors.New("invalid AES GCM cipher") | ||
| } | ||
|
|
||
| return Cipher{gcmCipher, keyBytes}, nil | ||
| } | ||
|
|
||
| // CreateFromKeyString constructs a new AES GCM cipher using the hex-encoded key string provided | ||
| func CreateFromKeyString(key string) (Cipher, error) { | ||
| keyBytes, err := hex.DecodeString(key) | ||
| if err != nil { | ||
| return Cipher{}, errors.New("AES key is not in correct hex format") | ||
| } | ||
| return CreateFromKeyBytes(keyBytes) | ||
| } |
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,81 @@ | ||
| /* | ||
| Licensed 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 aes | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestInvalidAESKeyStrings(t *testing.T) { | ||
| invalidKeys := []string{ | ||
| "", | ||
| "sme", | ||
| "844e5fb5-96d1-4b19-9ce0-b90f252ea370", | ||
| " naksn", | ||
| "2b7e1516", | ||
| "2b7e151628aed2a6abf71588", | ||
| } | ||
|
|
||
| for _, key := range invalidKeys { | ||
| if _, err := CreateFromKeyString(key); err == nil { | ||
| t.Errorf("Expecting AES key %s to be invalid", key) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestValidAES128KeyStrings(t *testing.T) { | ||
| validKeys := []string{ | ||
| "2b7e151628aed2a6abf7158809cf4f3c", | ||
| "000102030405060708090a0b0c0d0e0f", | ||
| } | ||
|
|
||
| for _, key := range validKeys { | ||
| if _, err := CreateFromKeyString(key); err != nil { | ||
| t.Errorf("Expecting AES-128 key %s to be valid but got %v", key, err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestValidAES192KeyStrings(t *testing.T) { | ||
| validKeys := []string{ | ||
| "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b", | ||
| } | ||
|
|
||
| for _, key := range validKeys { | ||
| if _, err := CreateFromKeyString(key); err != nil { | ||
| t.Errorf("Expecting AES-192 key %s to be valid but got %v", key, err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestValidAES256KeyStrings(t *testing.T) { | ||
| validKeys := []string{ | ||
| "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4", | ||
| } | ||
|
|
||
| for _, key := range validKeys { | ||
| if _, err := CreateFromKeyString(key); err != nil { | ||
| t.Errorf("Expecting AES-256 key %s to be valid but got %v", key, err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestInvalidAESKeyBytes(t *testing.T) { | ||
| invalidLengths := []int{0, 7, 15, 17, 23, 25, 31, 33} | ||
|
|
||
| for _, length := range invalidLengths { | ||
| keyBytes := make([]byte, length) | ||
| if _, err := CreateFromKeyBytes(keyBytes); err == nil { | ||
| t.Errorf("Expecting AES key of length %d bytes to be invalid", length) | ||
| } | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.