summaryrefslogtreecommitdiffstats
path: root/scard/Ssh.java
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2001-09-15 12:58:46 +0200
committerDamien Miller <djm@mindrot.org>2001-09-15 12:58:46 +0200
commit69e00a18a5dbbdf7a79561f040ce68de832289a2 (patch)
tree2e3748d27c4d26f6ea601082d7c52d1ff82d2bd7 /scard/Ssh.java
parent - (djm) Make do_pre_login static to avoid prototype #ifdef hell (diff)
downloadopenssh-69e00a18a5dbbdf7a79561f040ce68de832289a2.tar.xz
openssh-69e00a18a5dbbdf7a79561f040ce68de832289a2.zip
- (djm) Sync scard/ stuff
Diffstat (limited to 'scard/Ssh.java')
-rw-r--r--scard/Ssh.java165
1 files changed, 76 insertions, 89 deletions
diff --git a/scard/Ssh.java b/scard/Ssh.java
index 05e2b4872..9ca6da385 100644
--- a/scard/Ssh.java
+++ b/scard/Ssh.java
@@ -1,64 +1,66 @@
-/*
- * copyright 1997, 2000
- * the regents of the university of michigan
- * all rights reserved
- *
- * permission is granted to use, copy, create derivative works
- * and redistribute this software and such derivative works
- * for any purpose, so long as the name of the university of
- * michigan is not used in any advertising or publicity
- * pertaining to the use or distribution of this software
- * without specific, written prior authorization. if the
- * above copyright notice or any other identification of the
- * university of michigan is included in any copy of any
- * portion of this software, then the disclaimer below must
- * also be included.
- *
- * this software is provided as is, without representation
- * from the university of michigan as to its fitness for any
- * purpose, and without warranty by the university of
- * michigan of any kind, either express or implied, including
- * without limitation the implied warranties of
- * merchantability and fitness for a particular purpose. the
- * regents of the university of michigan shall not be liable
- * for any damages, including special, indirect, incidental, or
- * consequential damages, with respect to any claim arising
- * out of or in connection with the use of the software, even
- * if it has been or is hereafter advised of the possibility of
- * such damages.
- *
- * SSH / smartcard integration project, smartcard side
- *
- * Tomoko Fukuzawa, created, Feb., 2000
- * Naomaru Itoi, modified, Apr., 2000
- */
+// $Id: Ssh.java,v 1.2 2001/09/15 10:58:47 djm Exp $
+//
+// Ssh.java
+// SSH / smartcard integration project, smartcard side
+//
+// Tomoko Fukuzawa, created, Feb., 2000
+//
+// Naomaru Itoi, modified, Apr., 2000
+//
+
+// copyright 2000
+// the regents of the university of michigan
+// all rights reserved
+//
+// permission is granted to use, copy, create derivative works
+// and redistribute this software and such derivative works
+// for any purpose, so long as the name of the university of
+// michigan is not used in any advertising or publicity
+// pertaining to the use or distribution of this software
+// without specific, written prior authorization. if the
+// above copyright notice or any other identification of the
+// university of michigan is included in any copy of any
+// portion of this software, then the disclaimer below must
+// also be included.
+//
+// this software is provided as is, without representation
+// from the university of michigan as to its fitness for any
+// purpose, and without warranty by the university of
+// michigan of any kind, either express or implied, including
+// without limitation the implied warranties of
+// merchantability and fitness for a particular purpose. the
+// regents of the university of michigan shall not be liable
+// for any damages, including special, indirect, incidental, or
+// consequential damages, with respect to any claim arising
+// out of or in connection with the use of the software, even
+// if it has been or is hereafter advised of the possibility of
+// such damages.
import javacard.framework.*;
import javacardx.framework.*;
import javacardx.crypto.*;
public class Ssh extends javacard.framework.Applet
-{
- /* constants declaration */
- // code of CLA byte in the command APDU header
- private final byte Ssh_CLA =(byte)0x05;
-
+{
+ /* constants declaration */
+ // code of CLA byte in the command APDU header
+ static final byte Ssh_CLA =(byte)0x05;
+
// codes of INS byte in the command APDU header
- private final byte DECRYPT = (byte) 0x10;
- private final byte GET_KEYLENGTH = (byte) 0x20;
- private final byte GET_PUBKEY = (byte) 0x30;
- private final byte GET_RESPONSE = (byte) 0xc0;
+ static final byte DECRYPT = (byte) 0x10;
+ static final byte GET_KEYLENGTH = (byte) 0x20;
+ static final byte GET_PUBKEY = (byte) 0x30;
+ static final byte GET_RESPONSE = (byte) 0xc0;
/* instance variables declaration */
- private final short keysize = 1024;
+ static final short keysize = 1024;
//RSA_CRT_PrivateKey rsakey;
AsymKey rsakey;
CyberflexFile file;
CyberflexOS os;
-
+
byte buffer[];
- //byte pubkey[];
static byte[] keyHdr = {(byte)0xC2, (byte)0x01, (byte)0x05};
@@ -66,64 +68,64 @@ public class Ssh extends javacard.framework.Applet
{
file = new CyberflexFile();
os = new CyberflexOS();
-
+
rsakey = new RSA_CRT_PrivateKey (keysize);
- rsakey.setKeyInstance ((short)0xc8, (short)0x10);
if ( ! rsakey.isSupportedLength (keysize) )
ISOException.throwIt (ISO.SW_WRONG_LENGTH);
- /*
- pubkey = new byte[keysize/8];
- file.selectFile((short)(0x3f<<8)); // select root
- file.selectFile((short)(('s'<<8)|'h')); // select public key file
- os.readBinaryFile (pubkey, (short)0, (short)0, (short)(keysize/8));
- */
- register();
- } // end of the constructor
+ register();
+ } // end of the constructor
+
+ public boolean select() {
+ if (!rsakey.isInitialized())
+ rsakey.setKeyInstance ((short)0xc8, (short)0x10);
+
+ return true;
+ }
public static void install(APDU apdu)
{
- new Ssh(); // create a Ssh applet instance (card)
+ new Ssh(); // create a Ssh applet instance (card)
} // end of install method
+ public static void main(String args[]) {
+ ISOException.throwIt((short) 0x9000);
+ }
+
public void process(APDU apdu)
- {
- // APDU object carries a byte array (buffer) to
- // transfer incoming and outgoing APDU header
+ {
+ // APDU object carries a byte array (buffer) to
+ // transfer incoming and outgoing APDU header
// and data bytes between card and CAD
- buffer = apdu.getBuffer();
+ buffer = apdu.getBuffer();
// verify that if the applet can accept this
- // APDU message
+ // APDU message
// NI: change suggested by Wayne Dyksen, Purdue
if (buffer[ISO.OFFSET_INS] == ISO.INS_SELECT)
ISOException.throwIt(ISO.SW_NO_ERROR);
-
+
switch (buffer[ISO.OFFSET_INS]) {
case DECRYPT:
if (buffer[ISO.OFFSET_CLA] != Ssh_CLA)
ISOException.throwIt(ISO.SW_CLA_NOT_SUPPORTED);
//decrypt (apdu);
short size = (short) (buffer[ISO.OFFSET_LC] & 0x00FF);
-
+
if (apdu.setIncomingAndReceive() != size)
ISOException.throwIt (ISO.SW_WRONG_LENGTH);
-
+
rsakey.cryptoUpdate (buffer, (short) ISO.OFFSET_CDATA, size,
buffer, (short) ISO.OFFSET_CDATA);
+
apdu.setOutgoingAndSend ((short) ISO.OFFSET_CDATA, size);
return;
case GET_PUBKEY:
file.selectFile((short)(0x3f<<8)); // select root
file.selectFile((short)(('s'<<8)|'h')); // select public key file
os.readBinaryFile (buffer, (short)0, (short)0, (short)(keysize/8));
- apdu.setOutgoingAndSend((short)0, (short)(keysize/8));
- /*
- apdu.setOutgoing();
- apdu.setOutgoingLength((short)(keysize/8));
- apdu.sendBytesLong(pubkey, (short)0, (short)(keysize/8));
- */
+ apdu.setOutgoingAndSend((short)0, (short)(keysize/8));
return;
case GET_KEYLENGTH:
buffer[0] = (byte)((keysize >> 8) & 0xff);
@@ -133,24 +135,9 @@ public class Ssh extends javacard.framework.Applet
case GET_RESPONSE:
return;
default:
- ISOException.throwIt (ISO.SW_INS_NOT_SUPPORTED);
- }
+ ISOException.throwIt (ISO.SW_INS_NOT_SUPPORTED);
+ }
} // end of process method
- /*
- private void decrypt (APDU apdu)
- {
- short size = (short) (buffer[ISO.OFFSET_LC] & 0x00FF);
-
- if (apdu.setIncomingAndReceive() != size)
- ISOException.throwIt (ISO.SW_WRONG_LENGTH);
-
- //short offset = (short) ISO.OFFSET_CDATA;
-
- rsakey.cryptoUpdate (buffer, (short) ISO.OFFSET_CDATA, size, buffer,
- (short) ISO.OFFSET_CDATA);
- apdu.setOutgoingAndSend ((short) ISO.OFFSET_CDATA, size);
- }
- */
-} // end of class Ssh
+} // end of class Ssh