diff options
author | Kenny Root <kenny@the-b.org> | 2014-10-01 23:04:51 +0100 |
---|---|---|
committer | Kenny Root <kenny@the-b.org> | 2014-10-01 12:48:19 +0100 |
commit | 49b779dcaf03e3598d2709b321e20ea029b25163 (patch) | |
tree | 05af547b1f1433d7dd6f7373d0b25a455e053a03 /src/com/trilead/ssh2/crypto/dh/EcDhExchange.java | |
parent | d64786d9197090c74072b648e487e3d34817bb57 (diff) | |
download | connectbot-49b779dcaf03e3598d2709b321e20ea029b25163.tar.gz connectbot-49b779dcaf03e3598d2709b321e20ea029b25163.tar.bz2 connectbot-49b779dcaf03e3598d2709b321e20ea029b25163.zip |
Convert to gradle build system
Diffstat (limited to 'src/com/trilead/ssh2/crypto/dh/EcDhExchange.java')
-rw-r--r-- | src/com/trilead/ssh2/crypto/dh/EcDhExchange.java | 106 |
1 files changed, 0 insertions, 106 deletions
diff --git a/src/com/trilead/ssh2/crypto/dh/EcDhExchange.java b/src/com/trilead/ssh2/crypto/dh/EcDhExchange.java deleted file mode 100644 index 43d31ad..0000000 --- a/src/com/trilead/ssh2/crypto/dh/EcDhExchange.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * - */ -package com.trilead.ssh2.crypto.dh; - -import java.io.IOException; -import java.math.BigInteger; -import java.security.InvalidAlgorithmParameterException; -import java.security.InvalidKeyException; -import java.security.KeyFactory; -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.NoSuchAlgorithmException; -import java.security.interfaces.ECPrivateKey; -import java.security.interfaces.ECPublicKey; -import java.security.spec.ECParameterSpec; -import java.security.spec.ECPoint; -import java.security.spec.ECPublicKeySpec; -import java.security.spec.InvalidKeySpecException; - -import javax.crypto.KeyAgreement; - -import com.trilead.ssh2.signature.ECDSASHA2Verify; - -/** - * @author kenny - * - */ -public class EcDhExchange extends GenericDhExchange { - private ECPrivateKey clientPrivate; - private ECPublicKey clientPublic; - private ECPublicKey serverPublic; - - @Override - public void init(String name) throws IOException { - final ECParameterSpec spec; - - if ("ecdh-sha2-nistp256".equals(name)) { - spec = ECDSASHA2Verify.EllipticCurves.nistp256; - } else if ("ecdh-sha2-nistp384".equals(name)) { - spec = ECDSASHA2Verify.EllipticCurves.nistp384; - } else if ("ecdh-sha2-nistp521".equals(name)) { - spec = ECDSASHA2Verify.EllipticCurves.nistp521; - } else { - throw new IllegalArgumentException("Unknown EC curve " + name); - } - - KeyPairGenerator kpg; - try { - kpg = KeyPairGenerator.getInstance("EC"); - kpg.initialize(spec); - KeyPair pair = kpg.generateKeyPair(); - clientPrivate = (ECPrivateKey) pair.getPrivate(); - clientPublic = (ECPublicKey) pair.getPublic(); - } catch (NoSuchAlgorithmException e) { - throw (IOException) new IOException("No DH keypair generator").initCause(e); - } catch (InvalidAlgorithmParameterException e) { - throw (IOException) new IOException("Invalid DH parameters").initCause(e); - } - } - - @Override - public byte[] getE() { - return ECDSASHA2Verify.encodeECPoint(clientPublic.getW(), clientPublic.getParams() - .getCurve()); - } - - @Override - protected byte[] getServerE() { - return ECDSASHA2Verify.encodeECPoint(serverPublic.getW(), serverPublic.getParams() - .getCurve()); - } - - @Override - public void setF(byte[] f) throws IOException { - - if (clientPublic == null) - throw new IllegalStateException("DhDsaExchange not initialized!"); - - final KeyAgreement ka; - try { - KeyFactory kf = KeyFactory.getInstance("EC"); - ECParameterSpec params = clientPublic.getParams(); - ECPoint serverPoint = ECDSASHA2Verify.decodeECPoint(f, params.getCurve()); - this.serverPublic = (ECPublicKey) kf.generatePublic(new ECPublicKeySpec(serverPoint, - params)); - - ka = KeyAgreement.getInstance("ECDH"); - ka.init(clientPrivate); - ka.doPhase(serverPublic, true); - } catch (NoSuchAlgorithmException e) { - throw (IOException) new IOException("No ECDH key agreement method").initCause(e); - } catch (InvalidKeyException e) { - throw (IOException) new IOException("Invalid ECDH key").initCause(e); - } catch (InvalidKeySpecException e) { - throw (IOException) new IOException("Invalid ECDH key").initCause(e); - } - - sharedSecret = new BigInteger(ka.generateSecret()); - } - - @Override - public String getHashAlgo() { - return ECDSASHA2Verify.getDigestAlgorithmForParams(clientPublic.getParams()); - } -} |