Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add overloaded init methods that take the public key from a stream an…
Browse files Browse the repository at this point in the history
…d properly initialize. Resolves hierynomus#907.
dkocher committed Oct 23, 2023
1 parent b7dc869 commit 5e39fe9
Showing 4 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@
import net.schmizz.sshj.userauth.keyprovider.BaseFileKeyProvider;
import net.schmizz.sshj.userauth.keyprovider.FileKeyProvider;
import net.schmizz.sshj.userauth.keyprovider.KeyFormat;
import net.schmizz.sshj.userauth.password.PasswordFinder;
import org.bouncycastle.asn1.nist.NISTNamedCurves;
import org.bouncycastle.asn1.x9.X9ECParameters;
import org.bouncycastle.jce.spec.ECNamedCurveSpec;
@@ -118,6 +119,16 @@ public void init(File location) {
super.init(location);
}

@Override
public void init(Reader privateKey, Reader publicKey) {
try {
initPubKey(publicKey);
} catch (IOException e) {
log.warn("Error reading public key file: {}", e.toString());
}
super.init(privateKey, (Reader) null);
}

@Override
protected KeyPair readKeyPair() throws IOException {
final BufferedReader reader = new BufferedReader(resource.getReader());
Original file line number Diff line number Diff line change
@@ -44,6 +44,19 @@ public void init(Reader location, PasswordFinder pwdf) {
this.pwdf = pwdf;
}

@Override
public void init(Reader privateKey, Reader publicKey) {
assert publicKey == null;
init(privateKey);
}

@Override
public void init(Reader privateKey, Reader publicKey, PasswordFinder pwdf) {
assert publicKey == null;
init(privateKey, publicKey);
this.pwdf = pwdf;
}

@Override
public void init(File location) {
assert location != null;
Original file line number Diff line number Diff line change
@@ -30,6 +30,10 @@ public interface FileKeyProvider

void init(Reader location);

void init(Reader privateKey, Reader publicKey);

void init(Reader privateKey, Reader publicKey, PasswordFinder pwdf);

void init(Reader location, PasswordFinder pwdf);

void init(String privateKey, String publicKey);
Original file line number Diff line number Diff line change
@@ -80,6 +80,19 @@ public void init(String privateKey, String publicKey) {
super.init(privateKey, null);
}

@Override
public void init(Reader privateKey, Reader publicKey) {
if (publicKey != null) {
try {
initPubKey(publicKey);
} catch (IOException e) {
// let super provide both public & private key
log.warn("Error reading public key: {}", e.toString());
}
}
super.init(privateKey, (Reader) null);
}

/**
* Read and store the separate public key provided alongside the private key
*

0 comments on commit 5e39fe9

Please sign in to comment.