Skip to content
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

Improve Android compatibility #636

Merged
merged 2 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/main/java/net/schmizz/sshj/common/SecurityUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,14 @@ public static synchronized Signature getSignature(String algorithm)
*/
public static synchronized boolean isBouncyCastleRegistered() {
register();
return BOUNCY_CASTLE.equals(securityProvider) || SPONGY_CASTLE.equals(securityProvider);
Provider[] providers = Security.getProviders();
for (Provider provider : providers) {
String name = provider.getName();
if (BOUNCY_CASTLE.equals(name) || SPONGY_CASTLE.equals(name)) {
return true;
}
}
return false;
}

public static synchronized void setRegisterBouncyCastle(boolean registerBouncyCastle) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/schmizz/sshj/transport/kex/ECDHNistP.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import net.schmizz.sshj.transport.digest.SHA256;
import net.schmizz.sshj.transport.digest.SHA384;
import net.schmizz.sshj.transport.digest.SHA512;
import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec;

import java.security.GeneralSecurityException;
import java.security.spec.ECGenParameterSpec;

public class ECDHNistP extends AbstractDHG {

Expand All @@ -33,7 +33,7 @@ public static class Factory521

@Override
public KeyExchange create() {
return new ECDHNistP("P-521", new SHA512());
return new ECDHNistP("secp521r1", new SHA512());
}

@Override
Expand All @@ -48,7 +48,7 @@ public static class Factory384

@Override
public KeyExchange create() {
return new ECDHNistP("P-384", new SHA384());
return new ECDHNistP("secp384r1", new SHA384());
}

@Override
Expand All @@ -63,7 +63,7 @@ public static class Factory256

@Override
public KeyExchange create() {
return new ECDHNistP("P-256", new SHA256());
return new ECDHNistP("secp256r1", new SHA256());
}

@Override
Expand All @@ -79,7 +79,7 @@ public ECDHNistP(String curve, Digest digest) {

@Override
protected void initDH(DHBase dh) throws GeneralSecurityException {
dh.init(new ECNamedCurveGenParameterSpec(curve), trans.getConfig().getRandomFactory());
dh.init(new ECGenParameterSpec(curve), trans.getConfig().getRandomFactory());
}

}