-
Notifications
You must be signed in to change notification settings - Fork 152
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
Added Key derivation using Scrypt. #654
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.
Scrypt require some criteria for parameters. Which exception should I fire for this?
Validating these parameters should be in the Scrypt()
constructor, as any instance of Scrypt
with invalid parameters cannot be made from the very first. According to .NET convention, you could use ArgumentOutOfRangeException
. FYI its constructor takes a paramName
and this parameter is usually used together with nameof()
operator.
Plus, currently ProtectedPrivateKey.FromJson()
method does not catch any exceptions during making an IKdf
instance, but it would be good if we catch all ArgumentException
s there and then throw them again by wrapping them with InvalidKeyJsonException
. (Or it might be better to have another KeyJsonException
subclass like InvalidKeyJsonParametersException
?)
libplanet/Libplanet/KeyStore/ProtectedPrivateKey.cs
Lines 284 to 298 in 98aafe1
switch (kdfType) | |
{ | |
case "pbkdf2": | |
kdf = Pbkdf2.FromJson(kdfParamsElement); | |
break; | |
case "scrypt": | |
kdf = Scrypt.FromJson(kdfParamsElement); | |
break; | |
default: | |
throw new UnsupportedKeyJsonException( | |
$"Unsupported cipher type: \"{kdfType}\"." | |
); | |
} |
|
98aafe1
to
c582402
Compare
Codecov Report
@@ Coverage Diff @@
## master #654 +/- ##
==========================================
- Coverage 88.21% 85.96% -2.25%
==========================================
Files 216 194 -22
Lines 17127 16944 -183
==========================================
- Hits 15108 14566 -542
- Misses 1138 1326 +188
- Partials 881 1052 +171
|
93fd642
to
84deb7b
Compare
84deb7b
to
0c7cd86
Compare
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 for your contribution! I left some comments.
@@ -310,7 +406,7 @@ public void FromJsonInvalidCases() | |||
|
|||
Assert.Throws<InvalidKeyJsonException>(() => | |||
load(@"{ | |||
""address"": ""d80d933db45cc0cf69e9632090f8aaff635dc8e50"", // Invalid length | |||
""address"": ""d80d933db45cc0cf69e9632090f8aaff635dc8e500"", // Invalid length |
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.
What is this change for?
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 tried to increase the coverage of ProtectedPrivateKey.FromJson()
's address validation logic.
GetHexProperty()
calledByteUtil.ParseHex()
internallyByteUtil.ParseHex()
checked the length of input are even, if not throwArgumentOutOfRangeException
- when
GetHexProperty()
metException
, rethrow it asInvalidKeyJsonException
- and
InvalidKeyJsonException
wasn't covered withtry {} catch (ArgumentException e) {}
9d0ddb0
to
0e22741
Compare
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, I left some trivial comments.
That seems a good idea. How about having an optional parameter |
0e22741
to
8afb2b0
Compare
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.
LGTM!
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.
@minhoryang Would you add the IKdf kdf
optional parameter to ProtectedPrivateKey.Protect()
method in another pull request?
@dahlia I'm totally agreed to finish this PR without |
Related: #642
TODO:
Questions:
Scrypt require some criteria for parameters. Which exception should I fire for this?Current implementation of ProtectedPrivateKey.Protect() use Pbkdf2 only. Do we add the option or selector for Scrypt?