-
Notifications
You must be signed in to change notification settings - Fork 1.7k
SecretStore: generating and retrieving decryption keys via service contract #8029
Conversation
…c_key_via_contract
Found some issue with shutdown => marking as gotissues |
SS-related issue is fixed in previous commit, but there's still some issue, which results in |
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 have only reviewed this for style/readability and that I can understand roughly what's going on. Have not reviewed any of the logic in-depth. But at this point I think that's the best anyone can do since I don't think anyone understands this system in depth except the author ^^
I will be digging into this code more to try to understand it at this level but I will need some time and I'm fine with merging this in the meantime since it's behind a compiler flag anyway.
Box::new(request_logs.into_iter() | ||
.filter_map(|log| { | ||
let raw_log: RawLog = (log.entry.topics.into_iter().map(|t| t.0.into()).collect(), log.entry.data).into(); | ||
if raw_log.topics[0] == *SERVER_KEY_GENERATION_REQUESTED_EVENT_NAME_HASH { |
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.
Can we make this a match statement for better readability?
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.
Not sure :) These are not actually a constant expressions, but Deref
calls (it is lazy_static
'consts'). I could replace with match topics[0] { x if x == *SERVER_KEY... }
, but that's definitely not better :)
// ignore result - the only thing that we can do is to log the error | ||
let session_id = session.id(); | ||
let server_key_id = session_id.id; | ||
if let Some(requester) = session.requester().and_then(|r| r.address(&server_key_id).ok()) { |
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.
Couldn't you concatenate all the 3 lines below into 1 if let
statement? Since they don't depend on the previous value. So like if let (Some(x), Some(y)) = (session.requester()[..], session.origin())
?
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.
Merged two lines into 1. Not sure this improves readability, though :) 3rd line has side effects => do not want to depend on evaluation order => left separate if let
@@ -1405,7 +1405,7 @@ pub mod tests { | |||
// run session to completion | |||
let session_id = SessionId::default(); | |||
let session = clusters[0].client().new_generation_session(session_id, Default::default(), Default::default(), threshold).unwrap(); | |||
loop_until(&mut core, time::Duration::from_millis(1000), || session.joint_public_and_secret().is_some()); | |||
loop_until(&mut core, Duration::from_millis(1000), || session.joint_public_and_secret().is_some()); |
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.
change to const
?
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.
done :)
on top of #7887
Updated contract(s) PR: https://github.com/paritytech/contracts/pull/108
New service contract APIs
Server Key generation API has been changed
This is what already was a part of SecretStoreService.
But I've changed how it works to support wider range of usage cases:
generateServerKey(key_id, threshold)
methodServerKeyGenerated(key_id, key_public)
eventServerKeyGenerationError(key_id)
event (previousy we were returning previously generated server key if generation of the same key has been requested)threshold+1
confirmations)Server Key retrieval API has been splitted from Server key generation API
Retrieval was possible previously just by calling generation with the same key id. Now it is a separate API:
retrieveServerKey(key_id)
methodServerKeyRetrieved(key_id, key_public)
eventServerKeyRetrievalError(key_id)
event4.1) we're waiting for same-threshold confirmations from
50%+1
key servers4.2) once we know the threshold, we're waiting for
threshold+1
confirmations of the samekey_public
Document Key store API has been added
After server key is generated, the author of server key entry (the one who has sent
generateServerKey
transaction), can generate document key shadow usingsecretstore_generateDocumentKey
RPC (see #7864). After generating, he can use service contract API to store generated key in SS:storeDocumentKey(key_id, common_point, encrypted_point)
methodDocumentKeyStored(key_id)
eventDocumentKeyStoreError(key_id)
event100%
key serversDocument Key shadow retrieval API has been added
retrieveDocumentKeyShadow(key_id, requester_public)
method (tx author must be the owner ofrequester_public
key)2.1) we're waiting for same
threshold
andcomon_point
from50%+1
key servers. Once there are enough confirmations these values are reported viaDocumentKeyCommonRetrieved(key_id, requester_address, common_point, threshold)
2.2) once requester sees
DocumentKeyCommonRetrieved
event, it must start waiting forthreshold+1
DocumentKeyPersonalRetrieved(key_id, requester_address, decrypted_secret, shadow)
. After all data is collected, he can usesecretstore_shadowDecrypt
method to decrypt documentDocumentKeyShadowRetrievalError(key_id, requester_address)
can be raised, signalling that retrieval has failedOther changes to service contract
service_contract_srv_gen
,service_contract_srv_retr
,service_contract_doc_store
,service_contract_doc_sretr
) and also 'backup' option for all-in-one contract (service_contract
)ClientApi
interfaces), for key servers (KeyServerApi
) and administrative methods (they're here for test period and possbily be changed/removed later).Important TODOs left