-
Notifications
You must be signed in to change notification settings - Fork 148
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
fix(739) SignatureECDSAN destroying private key #740
Conversation
fixes: #739 |
No, I very much oppose this. |
PR updated to always perform a copy of the array instead of not 0-ing it |
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 seems acceptable to me by best limiting any potential impact.
@@ -351,7 +351,8 @@ public byte[] getSignature(byte[] data) { | |||
.asSubclass(SignatureECDSA.class); | |||
SignatureECDSA ecdsa = c.getDeclaredConstructor().newInstance(); | |||
ecdsa.init(); | |||
ecdsa.setPrvKey(prv_array); | |||
// issue 730: prv_array could be destroyed by ecdsa signing process if its first bit is 1 |
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 you fix this to correctly point to issue 739 and not issue 730 (which is unrelated).
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, I would prefer if we included a full link to https://github.com/mwiede/jsch/issues/739
in the comment text, so that future readers don't have to figure out what issue 739
means.
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.
Sorry. don't know how I did that
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.
made me realize 2 things:
This copy of the private key has to be cleaned... as we don't know if ecdsa signing will clean it...
So I need Util.bzero to be changed to public.
Would you prefer then:
byte[] keyCopy = Arrays.copyOf(prv_array, prv_array.length);
ecdsa.setPrvKey(keyCopy);
Util.bzero(keyCopy);
I also need to change the caller of setPubKey with the same fix :(
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 pushed a new secured fixed regarding cleaning the key copy.
The resulting code starts to get ugly because of that unneeded copy...
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.
Please revert those changes and simply constrain this change to making a copy of prv_array
that is passed to ecdsa.setPrvKey()
.
The whole point of what I am asking you to do is to make as minimally invasive changes as possible to fix the issue you reported.
That way we reduce the chance of introducing any sort of regression or any sort of new vulnerability as much as possible.
The JSch codebase is very old and extremely fragile, and we try to minimize risk as much as possible.
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.
made me realize 2 things: This copy of the private key has to be cleaned... as we don't know if ecdsa signing will clean it... So I need Util.bzero to be changed to public. Would you prefer then:
byte[] keyCopy = Arrays.copyOf(prv_array, prv_array.length); ecdsa.setPrvKey(keyCopy); Util.bzero(keyCopy);
I also need to change the caller of setPubKey with the same fix :(
There is zero reason to zero the public key, as that is not sensitive data.
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.
ok, just pushed a fix only for private key, adding a cleaning to the copy for security purpose
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.
Please revert the unnecessary changes to src/main/java/com/jcraft/jsch/jce/Util.java
.
@@ -351,7 +351,8 @@ public byte[] getSignature(byte[] data) { | |||
.asSubclass(SignatureECDSA.class); | |||
SignatureECDSA ecdsa = c.getDeclaredConstructor().newInstance(); | |||
ecdsa.init(); | |||
ecdsa.setPrvKey(prv_array); | |||
// issue 739: prv_array could be destroyed by ecdsa signing process if its first bit is 1 |
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 you change this to point at https://github.com/mwiede/jsch/issues/739
instead of issue 739
?
That way future readers don't have to figure out how to find what issue 739
means.
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
c8324cc
to
25a0496
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.
Please revert all these changes back to the minimally invasive change you had originally, which was to simply to call escda.setPrvKey(Arrays.copyOf(prv_array, prv_array.length));
.
The whole point of this is to minimize risk as much as possible (both for any regressions as well as any newly introduced vulnerabilities) whilst fixing the issue you originally reported, which is that you were unable to create multiple sessions from a single JSch object instance.
1d013ef
to
dd77694
Compare
@@ -26,8 +26,8 @@ | |||
|
|||
package com.jcraft.jsch.jce; | |||
|
|||
class Util { | |||
static void bzero(byte[] foo) { | |||
public class Util { |
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 is no reason for this class to be made public.
Please revert this change.
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.
needed to clean the copy
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 change is unneeded though to accomplish what you have proposed.
src/main/java/com/jcraft/jsch/KeyPairECDSA.java
will be utilizing the class src/main/java/com/jcraft/jsch/Util.java
, not src/main/java/com/jcraft/jsch/jce/Util.java
.
Therefore there is no need for the changes to make src/main/java/com/jcraft/jsch/jce/Util.java
public.
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.
Right, I was unaware of this duplicate code... fixed.
This is not acceptable as the copy array might stay in memory without cleaning in case of a positive number, thus setPrvKey won't clean it. |
I'll agree to keeping the introduction of |
Ok, pushed that. Copy of public key do not get cleaned. |
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.
Please execute mvn formatter:format
so that your changes are properly formatted and allow the Maven build to succeed.
Quality Gate passedIssues Measures |
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 am good with these changes now.
fix for bug 739