-
Notifications
You must be signed in to change notification settings - Fork 143
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
Symmetric keygen: high-level wrappers #561
Merged
ilammy
merged 13 commits into
cossacklabs:master
from
ilammy:themis_gen_sym_key/wrappers
Dec 11, 2019
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9637896
Symmetric keygen: ThemisPP
ilammy 2a7d3a8
Symmetric keygen: WasmThemis
ilammy d7bbef3
Symmetric keygen: GoThemis
ilammy b4ce8bd
Symmetric keygen: ObjCThemis and SwiftThemis
ilammy f72c0e1
Symmetric keygen: PHPThemis
ilammy c0cc339
Symmetric keygen: PyThemis
ilammy 971c2b2
Symmetric keygen: RbThemis
ilammy c5c3e80
Symmetric keygen: RustThemis
ilammy 87ea19a
Stricter length tests
ilammy a00dbf0
More empty buffer checks
ilammy 62ade93
fixup! Stricter length tests
ilammy 748664d
fixup! Symmetric keygen: ObjCThemis and SwiftThemis
ilammy 5922a4f
More instance tests for PHP
ilammy 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 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 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,46 @@ | ||
package keys | ||
|
||
/* | ||
#cgo LDFLAGS: -lthemis | ||
|
||
#include <stdbool.h> | ||
#include <themis/themis.h> | ||
|
||
static bool get_sym_key_size(size_t *key_len) | ||
{ | ||
return themis_gen_sym_key(NULL, key_len) == THEMIS_BUFFER_TOO_SMALL; | ||
} | ||
|
||
static bool gen_sym_key(void *key, size_t key_len) | ||
{ | ||
return themis_gen_sym_key(key, &key_len) == THEMIS_SUCCESS; | ||
} | ||
|
||
*/ | ||
import "C" | ||
|
||
import ( | ||
"unsafe" | ||
|
||
"github.com/cossacklabs/themis/gothemis/errors" | ||
) | ||
|
||
// SymmetricKey stores a master key for Secure Cell. | ||
type SymmetricKey struct { | ||
Value []byte | ||
} | ||
|
||
// NewSymmetricKey generates a new random symmetric key. | ||
func NewSymmetricKey() (*SymmetricKey, error) { | ||
var len C.size_t | ||
if !bool(C.get_sym_key_size(&len)) { | ||
return nil, errors.New("Failed to get symmetric key size") | ||
} | ||
|
||
key := make([]byte, int(len), int(len)) | ||
if !bool(C.gen_sym_key(unsafe.Pointer(&key[0]), len)) { | ||
return nil, errors.New("Failed to generate symmetric key") | ||
} | ||
|
||
return &SymmetricKey{Value: key}, nil | ||
} |
This file contains 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,17 @@ | ||
package keys | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
const defaultLength = 32 | ||
|
||
func TestNewSymmetricKey(t *testing.T) { | ||
key, err := NewSymmetricKey() | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if len(key.Value) != defaultLength { | ||
t.Error("invalid key.Value") | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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 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 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
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.
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.
Also, let's add tests here: https://github.com/cossacklabs/themis/tree/master/tests/objcthemis/objthemisFound tests :)
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.
I'd think this will be excessive when these suggestion is implemented in Themis Core. It will ensure that if themis_gen_sym_key() fails then output buffer does not contain anything useful or sensitive. That way we will not need to add additional wiping to every single wrapper individually.
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.
agree.
another reason I suggested it for iOS only – I don't know how to zeroing bytes in every other language :D