-
Notifications
You must be signed in to change notification settings - Fork 54
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
Persisting rln credentials #1037
Conversation
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.
🎉 on your first nwaku
PR :).
What are the security implications of printing / persisting the membership key in the clear?
Also, I left some nit comments inline.
@kaiserd Since the files are stored as a raw text file, it is highly susceptible to theft. The files needs some encryption to resolve this. With regards to printing the keys, it is purely for debugging purposes so that the user becomes explicitly aware of the current keys in use when nwaku is started. Note that this is only until the RLN contract being used is the one deployed on Goerli testnet. These prints need to omitted once RLN contract is deployed on Ethereum mainnet and using valuable funds for staking. |
Thank you for the clarification :).
|
Security warning incorporated as comments within code base. |
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.
Congrats for your first nwaku PR! Overall good, I left some comments.
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.
Thanks, @kgrgpg! Left some comments on Nim styling and abstracting the file-specific logic and magic constants - if this is to be short-lived until we have a proper keystore, the reading/writing and file types should not be in line with the main logic of the code but abstracted to modular procs.
@@ -818,7 +833,7 @@ proc mountRlnRelayDynamic*(node: WakuNode, | |||
node.wakuRlnRelay = rlnPeer | |||
|
|||
|
|||
proc mountRlnRelay*(node: WakuNode, conf: WakuNodeConf) {.raises: [Defect, ValueError, IOError, CatchableError].} = | |||
proc mountRlnRelay*(node: WakuNode, conf: WakuNodeConf) {.raises: [Defect, ValueError, IOError, CatchableError, Exception].} = |
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.
Where is the Exception
raised from? Couldn't we find the exact type of Exception being raised and catch it here? Now we have a list of Defect
, CatchableError
and Exception
which just means "everything". I know it's not always easy to catch specific exceptions from submodules. Also see: https://status-im.github.io/nim-style-guide/errors.exceptions.html
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.
This has been opened as a new issue. See #1045
So far it seems like an OSError but raising it is still giving error that appropriate exception is not raised.
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 are a few function calls in this proc that can potentially raise an exception, i.e., readFile
, parseJson
and
to(jsonObject, R andlnMembershipCredentials)
, have you inspected those to see what they raise?
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.
Moving all discussions related to Exception handling to the new issue. Review this PR on persistence primarily. @staheri14 Your comment is linked in new issue. #1045 (comment)
@@ -861,8 +876,32 @@ proc mountRlnRelay*(node: WakuNode, conf: WakuNodeConf) {.raises: [Defect, Value | |||
let memKeyPair = keyPair.toMembershipKeyPairs()[0] | |||
# mount the rln relay protocol in the on-chain/dynamic mode | |||
waitFor node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress, ethClientAddr = ethClientAddr, memKeyPair = some(memKeyPair), memIndex = some(rlnRelayIndex), ethAccAddr = ethAccountAddr, ethAccountPrivKey = ethAccountPrivKey, pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic) | |||
elif fileExists("keyPair.txt") and fileExists("rlnIndex.txt"): |
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 may not understand the exact context, but if the idea is simply for this "write to cleartext file" to be a temporary stopgap until we have an integrated keystore, the logic should be abstracted to separate functions with no magic references to the .txt files in the main logic.
In other words, instead of having an elif fileExists(...
here, it should be something like elif usePersistentKeys()
where usePersistentKeys()
are implemented elsewhere. And instead of having the logic to read the keys from the files here it should be abstracted to a readKeys()
proc, etc.
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.
Suggestion incorporated. Refer to 6236dd6
Jenkins BuildsClick to see older builds (6)
|
dc61be0
to
5a15930
Compare
Co-authored-by: Daniel Kaiser <[email protected]>
Co-authored-by: Daniel Kaiser <[email protected]>
Co-authored-by: Hanno Cornelius <[email protected]>
5a15930
to
b375418
Compare
Reading credentials from file abstracted away.
39a30ec
to
6236dd6
Compare
@kgrgpg Note that tests fail and there exist some conflicts that has to be addressed before merging
Please ping reviewers when ready. |
Abstrated writePersistentRlnCredentials usage causing error, with readPersistentRlnCredentials
@s1fr0 Usage of When I reverted to a direct call to Now I am perplexed, why this is the case. I read at https://nim-lang.org/docs/io.html#writeFile%2Cstring%2Cstring that writeFile closes the file after the operation is complete. I am wondering if this is failing for some reason when contained inside the abstracted function |
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.
Do not push commits related to vendor (so revert this). Regularly run make update
to update submodules.
This reverts commit 3f4dba1.
Thanks for this info. Make update resulted in new checkout for dnsclient. Concerned commit reverted. |
..persiting credential
The abstract proc |
let jsonObject = parseJson(entireRlnCredentialsFile) | ||
let deserializedRlnCredentials = to(jsonObject, RlnMembershipCredentials) | ||
|
||
debug "Deserialized Rln credentials", rlnCredentials=deserializedRlnCredentials |
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 would prefer that we do not dump the content of the credentials through the stdout
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.
Refer to #1037 (comment)
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.
LGTM ✅
Congrats on you first contribution 😁
IMHO We need to do an overall code review for the RLN part before it becomes hard to maintain (e.g. @s1fr0 has already experienced issues with the Zerokit integration). Right now I am fully focused on the Waku Store issue, but let's see if we can find a slot after the next nwaku's release to improve the code maintainability. |
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.
@kgrgpg If the work in this PR is finished, could you rebase, solve the conflicts and merge the PR into |
This code implements the persistence of MembershipKeyPair and MembershipIndex to the RLN membership contract. This is done by storing raw unencrypted JSON text in the files keyPair.txt and rlnIndex.txt when the first registration takes place. At a later stage, these credentials need to be stored in an encrypted format. One of the ways to implement that encryption could be similar to how keystore is implemented in Nimbus. But for now this should serve the purpose of credentials persistence saving user funds.