Fix null check for public key parameter.#944
Open
dkocher wants to merge 1 commit intohierynomus:masterfrom
Open
Fix null check for public key parameter.#944dkocher wants to merge 1 commit intohierynomus:masterfrom
dkocher wants to merge 1 commit intohierynomus:masterfrom
Conversation
Owner
|
Actually the null check is not for the parameter, but was once meant to only ensure that a subsequent call to |
|
This has been blocked for ages. Here is my dirty solution for at least 1 init() call: package com.hierynomus.sshj.userauth.keyprovider;
import lombok.val;
import java.security.PublicKey;
/**
* This class fixes a bug with init() checking for pubKey != null, which causes publicKey (its argument) to never initialize...
* <a href="https://github.com/hierynomus/sshj/pull/944">This Github pull request will be merged some day...</a>
*/
public class OpenSSHKeyV1KeyFileHacked extends OpenSSHKeyV1KeyFile {
private class DummyPublicKey implements PublicKey {
@Override
public String getAlgorithm() {
return "";
}
@Override
public String getFormat() {
return "";
}
@Override
public byte[] getEncoded() {
return new byte[0];
}
}
@Override
public void init(String privateKey, String publicKey) {
// Make sure we only prepare loading the publicKey when its not null, as it'd otherwise throw a NullPointerException later.
if (publicKey != null) {
try {
val field = OpenSSHKeyV1KeyFile.class.getDeclaredField("pubKey");
field.setAccessible(true);
field.set(this, new DummyPublicKey());
} catch (Exception e) {
throw new RuntimeException("Unable to hack pubKey field", e);
}
}
super.init(privateKey, publicKey);
}
} |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addendum for #908 as discussed in 1. Resolves #907.
Footnotes
https://github.com/hierynomus/sshj/pull/908/files#r1600044608 ↩