-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for digital signatures + integration tests work (again) (#501)
* pdo crypto cgo wrappers for go * enclave endorsement signature generation and validation based on clean protobuf message (serialization), involved slight protobuf change of chaincode response message * Read/Write-set with (hashed) values for read-set versioning, based on slightly modifed protobufs
- Loading branch information
Showing
22 changed files
with
594 additions
and
321 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2020 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <string.h> | ||
#include "crypto.h" | ||
#include "logging.h" | ||
#include "error.h" | ||
#include "types.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
bool compute_hash(uint8_t* message, | ||
uint32_t message_len, | ||
uint8_t* hash, | ||
uint32_t max_hash_len, | ||
uint32_t* actual_hash_len) | ||
{ | ||
ByteArray ba; | ||
|
||
COND2ERR(message == NULL); | ||
|
||
ba = pdo::crypto::ComputeMessageHash(ByteArray(message, message + message_len)); | ||
COND2ERR(ba.size() > max_hash_len); | ||
|
||
memcpy(hash, ba.data(), ba.size()); | ||
*actual_hash_len = ba.size(); | ||
return true; | ||
|
||
err: | ||
return false; | ||
} | ||
|
||
bool verify_signature(uint8_t* public_key, uint32_t public_key_len, uint8_t* message, uint32_t message_len, uint8_t* signature, uint32_t signature_len) | ||
{ | ||
try | ||
{ | ||
std::string pk_string((const char*)public_key, public_key_len); | ||
ByteArray msg(message, message + message_len); | ||
ByteArray sig(signature, signature + signature_len); | ||
|
||
//deserialize public key | ||
pdo::crypto::sig::PublicKey pk(pk_string); | ||
|
||
//check signature | ||
int r = pk.VerifySignature(msg, sig); | ||
COND2ERR(r != 1); | ||
} | ||
catch(...) | ||
{ | ||
COND2ERR(true); | ||
} | ||
|
||
// verification successful | ||
return true; | ||
|
||
err: | ||
return false; | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif /* __cplusplus */ |
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,23 @@ | ||
/* | ||
* Copyright 2020 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
bool compute_hash(uint8_t* message, | ||
uint32_t message_len, | ||
uint8_t* hash, | ||
uint32_t max_hash_len, | ||
uint32_t* actual_hash_len); | ||
|
||
bool verify_signature(uint8_t* public_key, uint32_t public_key_len, uint8_t* message, uint32_t message_len, uint8_t* signature, uint32_t signature_len); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
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.