diff -crN jaramiko-109/build.xml jaramiko-new/build.xml
*** jaramiko-109/build.xml 2006-10-10 05:53:57.000000000 +1100
--- jaramiko-new/build.xml 2007-06-24 12:59:56.000000000 +1000
***************
*** 28,38 ****
!
!
--- 28,38 ----
!
!
diff -crN jaramiko-109/java/net/lag/crai/Crai.java jaramiko-new/java/net/lag/crai/Crai.java
*** jaramiko-109/java/net/lag/crai/Crai.java 2006-10-10 05:53:55.000000000 +1100
--- jaramiko-new/java/net/lag/crai/Crai.java 2007-08-30 16:03:29.000000000 +1000
***************
*** 40,46 ****
{
public CraiRandom getPRNG ();
! public CraiPrivateKey makePrivateRSAKey (BigInteger n, BigInteger d);
public CraiPrivateKey makePrivateDSAKey (BigInteger x, BigInteger p, BigInteger q, BigInteger g);
public CraiPublicKey makePublicRSAKey (BigInteger n, BigInteger e);
public CraiPublicKey makePublicDSAKey (BigInteger y, BigInteger p, BigInteger q, BigInteger g);
--- 40,46 ----
{
public CraiRandom getPRNG ();
! public CraiPrivateKey makePrivateRSAKey (BigInteger n, BigInteger d, BigInteger p, BigInteger q);
public CraiPrivateKey makePrivateDSAKey (BigInteger x, BigInteger p, BigInteger q, BigInteger g);
public CraiPublicKey makePublicRSAKey (BigInteger n, BigInteger e);
public CraiPublicKey makePublicDSAKey (BigInteger y, BigInteger p, BigInteger q, BigInteger g);
diff -crN jaramiko-109/java/net/lag/crai/CraiPrivateKey.java jaramiko-new/java/net/lag/crai/CraiPrivateKey.java
*** jaramiko-109/java/net/lag/crai/CraiPrivateKey.java 2006-10-10 05:53:55.000000000 +1100
--- jaramiko-new/java/net/lag/crai/CraiPrivateKey.java 2007-08-31 17:24:29.000000000 +1000
***************
*** 52,57 ****
--- 52,59 ----
{
public BigInteger getN();
public BigInteger getD();
+ public BigInteger getP();
+ public BigInteger getQ();
}
diff -crN jaramiko-109/java/net/lag/craijce/CraiJCE.java jaramiko-new/java/net/lag/craijce/CraiJCE.java
*** jaramiko-109/java/net/lag/craijce/CraiJCE.java 2006-10-10 05:53:55.000000000 +1100
--- jaramiko-new/java/net/lag/craijce/CraiJCE.java 2007-09-04 10:09:14.174459432 +1000
***************
*** 40,45 ****
--- 40,46 ----
import java.security.interfaces.DSAPrivateKey;
import java.security.interfaces.DSAPublicKey;
import java.security.interfaces.RSAPrivateKey;
+ import java.security.interfaces.RSAPrivateCrtKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.DSAPrivateKeySpec;
import java.security.spec.DSAPublicKeySpec;
***************
*** 86,95 ****
implements CraiPrivateKey
{
public
! JCEPrivateRSAKey (BigInteger n, BigInteger d)
{
mN = n;
mD = d;
}
public byte[]
--- 87,98 ----
implements CraiPrivateKey
{
public
! JCEPrivateRSAKey (BigInteger n, BigInteger d, BigInteger p, BigInteger q)
{
mN = n;
mD = d;
+ mP = p;
+ mQ = q;
}
public byte[]
***************
*** 121,132 ****
--- 124,145 ----
public BigInteger getD() {
return mD;
}
+
+ public BigInteger getP() {
+ return mP;
+ }
+
+ public BigInteger getQ() {
+ return mQ;
+ }
};
}
private BigInteger mN;
private BigInteger mD;
+ private BigInteger mP;
+ private BigInteger mQ;
}
***************
*** 482,490 ****
}
public CraiPrivateKey
! makePrivateRSAKey (BigInteger n, BigInteger d)
{
! return new JCEPrivateRSAKey(n, d);
}
public CraiPrivateKey
--- 495,503 ----
}
public CraiPrivateKey
! makePrivateRSAKey (BigInteger n, BigInteger d, BigInteger p, BigInteger q)
{
! return new JCEPrivateRSAKey(n, d, p, q);
}
public CraiPrivateKey
***************
*** 528,534 ****
BigInteger n = priv.getModulus();
BigInteger d = priv.getPrivateExponent();
BigInteger e = pub.getPublicExponent();
! return new CraiKeyPair(new JCEPublicRSAKey(n, e), new JCEPrivateRSAKey(n, d));
}
public CraiKeyPair
--- 541,549 ----
BigInteger n = priv.getModulus();
BigInteger d = priv.getPrivateExponent();
BigInteger e = pub.getPublicExponent();
! BigInteger p = (priv instanceof RSAPrivateCrtKey) ? ((RSAPrivateCrtKey)priv).getPrimeP() : null;
! BigInteger q = (priv instanceof RSAPrivateCrtKey) ? ((RSAPrivateCrtKey)priv).getPrimeQ() : null;
! return new CraiKeyPair(new JCEPublicRSAKey(n, e), new JCEPrivateRSAKey(n, d, p, q));
}
public CraiKeyPair
diff -crN jaramiko-109/java/net/lag/jaramiko/Channel.java jaramiko-new/java/net/lag/jaramiko/Channel.java
*** jaramiko-109/java/net/lag/jaramiko/Channel.java 2006-10-10 05:53:55.000000000 +1100
--- jaramiko-new/java/net/lag/jaramiko/Channel.java 2007-06-23 11:17:08.000000000 +1000
***************
*** 1245,1251 ****
int height = m.getInt();
int pixelWidth = m.getInt();
int pixelHeight = m.getInt();
! String modes = m.getString();
if (mServer != null) {
ok = mServer.checkChannelPTYRequest(this, term, width, height, pixelWidth, pixelHeight, modes);
} else {
--- 1245,1261 ----
int height = m.getInt();
int pixelWidth = m.getInt();
int pixelHeight = m.getInt();
! byte[] rawmodes = m.getByteString();
! Integer[] modes = new Integer[PseudoTerminal.NO_OF_MODES];
! int index = 0;
! while (index + 4 < rawmodes.length) {
! int no = rawmodes[index++] & 0xff;
! int value = (rawmodes[index++] & 0xff) << 24;
! value += (rawmodes[index++] & 0xff) << 16;
! value += (rawmodes[index++] & 0xff) << 8;
! value += rawmodes[index++] & 0xff;
! modes[no] = new Integer(value);
! }
if (mServer != null) {
ok = mServer.checkChannelPTYRequest(this, term, width, height, pixelWidth, pixelHeight, modes);
} else {
diff -crN jaramiko-109/java/net/lag/jaramiko/DSSKey.java jaramiko-new/java/net/lag/jaramiko/DSSKey.java
*** jaramiko-109/java/net/lag/jaramiko/DSSKey.java 2006-10-10 05:53:55.000000000 +1100
--- jaramiko-new/java/net/lag/jaramiko/DSSKey.java 2007-09-04 09:35:56.000000000 +1000
***************
*** 29,34 ****
--- 29,36 ----
package net.lag.jaramiko;
import java.math.BigInteger;
+ import java.io.IOException;
+ import java.io.OutputStream;
import net.lag.crai.Crai;
import net.lag.crai.CraiException;
***************
*** 167,173 ****
}
}
!
private BigInteger mP;
private BigInteger mQ;
--- 169,186 ----
}
}
! public void writePrivateKeyToStream(OutputStream os, String password) throws IOException {
! BigInteger[] nums = new BigInteger[6];
! nums[0] = new BigInteger("0");
! nums[1] = mP;
! nums[2] = mQ;
! nums[3] = mG;
! nums[4] = mY;
! nums[5] = mX;
!
! byte[] arr = Util.encodeBERSequence(nums);
! writePrivateKeyToStream("DSA", os, arr, password);
! }
private BigInteger mP;
private BigInteger mQ;
diff -crN jaramiko-109/java/net/lag/jaramiko/PKey.java jaramiko-new/java/net/lag/jaramiko/PKey.java
*** jaramiko-109/java/net/lag/jaramiko/PKey.java 2006-10-10 05:53:55.000000000 +1100
--- jaramiko-new/java/net/lag/jaramiko/PKey.java 2007-09-03 17:59:12.000000000 +1000
***************
*** 33,38 ****
--- 33,39 ----
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+ import java.io.OutputStream;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
***************
*** 321,327 ****
pkey.buildFromBER(Util.decodeBERSequence(data));
return pkey;
}
!
/**
* Given a password, passphrase, or other human-source key, scramble it
* through a secure hash into some keyworthy bytes. This specific
--- 322,351 ----
pkey.buildFromBER(Util.decodeBERSequence(data));
return pkey;
}
!
! public abstract void writePrivateKeyToStream(OutputStream os, String password) throws IOException;
!
! public void writePrivateKeyToStream(String tag, OutputStream os, byte[] data, String password) throws IOException {
! StringBuffer sb = new StringBuffer();
! sb.append("-----BEGIN " + tag + " PRIVATE KEY-----\n");
! if (password != null & password.length() > 0) {
! //XXX do something...
! }
!
! String s = Base64.encodeBytes(data, 0, data.length, Base64.DONT_BREAK_LINES);
! while (s.length() > 64) {
! sb.append(s.substring(0, 64));
! sb.append("\n");
! s = s.substring(64);
! }
! sb.append(s);
! sb.append("\n");
! //xxxx
! sb.append("-----END " + tag + " PRIVATE KEY-----\n");
!
! os.write(sb.toString().getBytes());
! }
!
/**
* Given a password, passphrase, or other human-source key, scramble it
* through a secure hash into some keyworthy bytes. This specific
diff -crN jaramiko-109/java/net/lag/jaramiko/PseudoTerminal.java jaramiko-new/java/net/lag/jaramiko/PseudoTerminal.java
*** jaramiko-109/java/net/lag/jaramiko/PseudoTerminal.java 1970-01-01 11:00:00.000000000 +1100
--- jaramiko-new/java/net/lag/jaramiko/PseudoTerminal.java 2007-06-23 11:18:46.000000000 +1000
***************
*** 0 ****
--- 1,101 ----
+ /*
+ * Copyright (C) 2007 Robert J Colquhoun
+ *
+ * This file is part of paramiko.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+ package net.lag.jaramiko;
+
+ /**
+ * Defines needed to interpret the pty mode values sent from the client
+ *
+ * Defines are from RFC 4254 Section 8
+ * http://www.ietf.org/rfc/rfc4254.txt
+ *
+ */
+ public interface PseudoTerminal {
+
+ public static final int NO_OF_MODES = 256;
+
+ public static final int TTY_OP_END = 0;
+ public static final int VINTR = 1;
+ public static final int VQUIT = 2;
+ public static final int VERASE = 3;
+ public static final int VKILL = 4;
+ public static final int VEOF = 5;
+ public static final int VEOL = 6;
+ public static final int VEOL2 = 7;
+ public static final int VSTART = 8;
+ public static final int VSTOP = 9;
+ public static final int VSUSP = 10;
+ public static final int VDSUSP = 11;
+ public static final int VREPRINT = 12;
+ public static final int VWERASE = 13;
+ public static final int VLNEXT = 14;
+ public static final int VFLUSH = 15;
+ public static final int VSWTCH = 16;
+ public static final int VSTATUS = 17;
+ public static final int VDISCARD = 18;
+
+ public static final int IGNPAR = 30;
+ public static final int PARMRK = 31;
+ public static final int INPCK = 32;
+ public static final int ISTRIP = 33;
+ public static final int INLCR = 34;
+ public static final int IGNCR = 35;
+ public static final int ICRNL = 36;
+ public static final int IUCLC = 37;
+ public static final int IXON = 38;
+ public static final int IXANY = 39;
+ public static final int IXOFF = 40;
+ public static final int IMAXBEL = 41;
+
+ public static final int ISIG = 50;
+ public static final int ICANON = 51;
+ public static final int XCASE = 52;
+ public static final int ECHO = 53;
+ public static final int ECHOE = 54;
+ public static final int ECHOK = 55;
+ public static final int ECHONL = 56;
+ public static final int NOFLSH = 57;
+ public static final int TOSTOP = 58;
+ public static final int IEXTEN = 59;
+ public static final int ECHOCTL = 60;
+ public static final int ECHOKE = 61;
+ public static final int PENDIN = 62;
+
+ public static final int OPOST = 70;
+ public static final int OLCUC = 71;
+ public static final int ONLCR = 72;
+ public static final int OCRNL = 73;
+ public static final int ONOCR = 74;
+ public static final int ONLRET = 75;
+
+ public static final int CS7 = 90;
+ public static final int CS8 = 91;
+ public static final int PARENB = 92;
+ public static final int PARODD = 93;
+
+ public static final int TTY_OP_ISPEED = 128;
+ public static final int TTY_OP_OSPEED = 129;
+
+ }
diff -crN jaramiko-109/java/net/lag/jaramiko/RSAKey.java jaramiko-new/java/net/lag/jaramiko/RSAKey.java
*** jaramiko-109/java/net/lag/jaramiko/RSAKey.java 2006-10-10 05:53:55.000000000 +1100
--- jaramiko-new/java/net/lag/jaramiko/RSAKey.java 2007-09-04 09:31:31.000000000 +1000
***************
*** 29,34 ****
--- 29,36 ----
package net.lag.jaramiko;
import java.math.BigInteger;
+ import java.io.IOException;
+ import java.io.OutputStream;
import net.lag.crai.Crai;
import net.lag.crai.CraiException;
***************
*** 52,59 ****
mD = null;
mE = null;
mN = null;
! //mP = null;
! //mQ = null;
}
public String
--- 54,61 ----
mD = null;
mE = null;
mN = null;
! mP = null;
! mQ = null;
}
public String
***************
*** 89,95 ****
throws SSHException
{
try {
! CraiPrivateKey rsa = crai.makePrivateRSAKey(mN, mD);
Message m = new Message();
m.putString(getSSHName());
m.putByteString(rsa.sign(data, 0, data.length));
--- 91,97 ----
throws SSHException
{
try {
! CraiPrivateKey rsa = crai.makePrivateRSAKey(mN, mD, mP, mQ);
Message m = new Message();
m.putString(getSSHName());
m.putByteString(rsa.sign(data, 0, data.length));
***************
*** 127,134 ****
mN = ints[1];
mE = ints[2];
mD = ints[3];
! //mP = ints[4];
! //mQ = ints[5];
}
protected void
--- 129,136 ----
mN = ints[1];
mE = ints[2];
mD = ints[3];
! mP = ints[4];
! mQ = ints[5];
}
protected void
***************
*** 162,177 ****
key.mE = pub.getE();
key.mN = pub.getN();
key.mD = priv.getD();
return key;
} catch (Exception x) {
throw new SSHException("Java publickey error: " + x);
}
}
private BigInteger mE;
private BigInteger mD;
private BigInteger mN;
! //private BigInteger mP;
! //private BigInteger mQ;
}
--- 164,197 ----
key.mE = pub.getE();
key.mN = pub.getN();
key.mD = priv.getD();
+ key.mP = priv.getP();
+ key.mQ = priv.getQ();
return key;
} catch (Exception x) {
throw new SSHException("Java publickey error: " + x);
}
}
+ public void writePrivateKeyToStream(OutputStream os, String password) throws IOException {
+ BigInteger[] nums = new BigInteger[9];
+ nums[0] = new BigInteger("0");
+ nums[1] = mN;
+ nums[2] = mE;
+ nums[3] = mD;
+ nums[4] = mP;
+ nums[5] = mQ;
+ BigInteger one = new BigInteger("1");
+ nums[6] = mD.mod(mP.subtract(one));
+ nums[7] = mD.mod(mQ.subtract(one));
+ nums[8] = mQ.modInverse(mP);
+
+ byte[] arr = Util.encodeBERSequence(nums);
+ writePrivateKeyToStream("RSA", os, arr, password);
+ }
private BigInteger mE;
private BigInteger mD;
private BigInteger mN;
! private BigInteger mP;
! private BigInteger mQ;
}
diff -crN jaramiko-109/java/net/lag/jaramiko/ServerInterface.java jaramiko-new/java/net/lag/jaramiko/ServerInterface.java
*** jaramiko-109/java/net/lag/jaramiko/ServerInterface.java 2006-10-10 05:53:55.000000000 +1100
--- jaramiko-new/java/net/lag/jaramiko/ServerInterface.java 2007-06-23 11:20:58.000000000 +1000
***************
*** 195,202 ****
* @return true if the pty has been allocated; false otherwise
*/
public boolean
! checkChannelPTYRequest (Channel c, String term, int width, int height, int pixelWidth, int pixelHeight,
! String modes);
/**
* Determine if a shell will be provided to the client on the given
--- 195,201 ----
* @return true if the pty has been allocated; false otherwise
*/
public boolean
! checkChannelPTYRequest (Channel c, String term, int width, int height, int pixelWidth, int pixelHeight, Integer[] modes);
/**
* Determine if a shell will be provided to the client on the given
diff -crN jaramiko-109/java/net/lag/jaramiko/Util.java jaramiko-new/java/net/lag/jaramiko/Util.java
*** jaramiko-109/java/net/lag/jaramiko/Util.java 2006-10-10 05:53:55.000000000 +1100
--- jaramiko-new/java/net/lag/jaramiko/Util.java 2007-09-04 10:07:24.460138544 +1000
***************
*** 28,33 ****
--- 28,34 ----
package net.lag.jaramiko;
+ import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.math.BigInteger;
***************
*** 223,226 ****
--- 224,296 ----
return (BigInteger[]) nums.toArray(new BigInteger[0]);
}
+
+ public static byte[]
+ encodeBERSequence (BigInteger[] nums) {
+
+ final byte BER_MAGIC = 0x30;
+ final byte BER_MAGIC2 = 0x02;
+
+ byte[][] lens = new byte[nums.length][];
+ byte[][] nums2 = new byte[nums.length][];
+ int totallen = 0;
+ for (int i = 0; i < nums.length; i++) {
+ byte[] num = nums[i].toByteArray();
+ int len = num.length;
+ int metalen = 0;
+ if (len != (len & 0x7f)) {
+ while (len > 0) {
+ len >>= 8;
+ metalen++;
+ }
+ }
+ lens[i] = new byte[metalen + 2];
+ lens[i][0] = BER_MAGIC2;
+ len = num.length;
+ if (metalen > 0) {
+ //assume metalen is one byte
+ lens[i][1] = (byte)(0x80 | metalen);
+ for (int j = metalen + 1; j > 1; j--) {
+ lens[i][j] = (byte)(len & 0xff);
+ len >>= 8;
+ }
+ } else {
+ lens[i][1] = (byte)(len & 0x7f);
+ }
+ nums2[i] = num;
+ totallen += lens[i].length + nums2[i].length;
+ }
+
+ byte[] b;
+ int index = 0;
+ if (totallen != (totallen & 0x7f)) {
+ int metalen = 0;
+ int len = totallen;
+ while (len > 0) {
+ len >>= 8;
+ metalen++;
+ }
+ b = new byte[totallen + metalen + 2];
+ b[index++] = BER_MAGIC;
+ len = totallen;
+ //assumes metalen is one byte
+ b[index++] = (byte)(0x80 | metalen);
+ for (int j = metalen + 1; j > 1; j--) {
+ b[j] = (byte)(len & 0xff);
+ len >>= 8;
+ }
+ index += metalen;
+ } else {
+ b = new byte[totallen + 2];
+ b[index++] = BER_MAGIC;
+ b[index++] = (byte)(totallen & 0x7f);
+ }
+ for (int i = 0; i < nums.length; i++) {
+ System.arraycopy(lens[i], 0, b, index, lens[i].length);
+ index += lens[i].length;
+ System.arraycopy(nums2[i], 0, b, index, nums2[i].length);
+ index += nums2[i].length;
+ }
+ return b;
+ }
}