summaryrefslogtreecommitdiff
path: root/usr.bin/ssh/scard
diff options
context:
space:
mode:
authorJim Rees <rees@cvs.openbsd.org>2001-07-30 20:08:15 +0000
committerJim Rees <rees@cvs.openbsd.org>2001-07-30 20:08:15 +0000
commit65d8441866cb4f0b73695e403690e8353194c4d7 (patch)
tree768979657c14a419428cac61090d48c4bd6c1754 /usr.bin/ssh/scard
parent2bd77acf13839a9c83622327fba8811b0b798845 (diff)
initialize key in select method, not Constructor
Diffstat (limited to 'usr.bin/ssh/scard')
-rw-r--r--usr.bin/ssh/scard/Ssh.bin.uu26
-rw-r--r--usr.bin/ssh/scard/Ssh.java165
2 files changed, 89 insertions, 102 deletions
diff --git a/usr.bin/ssh/scard/Ssh.bin.uu b/usr.bin/ssh/scard/Ssh.bin.uu
index 24e22a09cce..1062e21d68c 100644
--- a/usr.bin/ssh/scard/Ssh.bin.uu
+++ b/usr.bin/ssh/scard/Ssh.bin.uu
@@ -1,16 +1,16 @@
begin 644 Ssh.bin
-M`P)!$P`401X`9``!`B@"`/Y@\`4`_J'P!0!!$T$7`?Z@\`4`01-!%@'^>/,!
-M`4$301@!_G/5``+^</,7`?Y#TQ$!_F#P%`!!$[`%`/YATP``01-!%0'^8=,%
-M`/YSU0L%_F'3!P+^H=`!`?Z@T!($01-!%`%!$PH!!`#^8`&P``!!%/`*"`!!
-M%?`*``!!%O(/``!!%_(A``!!&/(0``!!&?_T`@!!&O_V`@!!&__V`@!!'/_V
-M`@!!'?_V`@!!'O_V`@#P!O_R```$"``6```&8P@M`PG"*"T$!"@M!0@H6P!?
-M60``\!#_\@,"!@$`R```$V``/%T`01-<`$$$&0FD2P`)"I``8``M$UP`0009
-M5@````"B````!/___\````"A````$````"H````@````C0```#````!J$UP`
-M00,9"$H`"0IN`&``+1-<`$$'&0H`_ST@8`!&$4H`"0IG`&``+1-<`!X37`!!
-M"!$37`!!"%X`2P@18`!060H_`&``52L*<VA@`%4K$UP`00,#"@"`8`!:*P,*
-M`(!@`%!9$UP`00,'*!-<`$$$`R@#!6``4%E9"FT`8``M60#P$__R`0$""0`,
-M``!B01,M7P`W*UD```"P!?_R`0$$`@!(```37P``$V+^H2U?``5=``H38OZ@
-M+5\`#UT`%!-B_G@M"@0`7P`970`>$UP`'@H`R`D07@`C"@0`8``H10`)"F<`
-,8``M$UX`,ED`````
+M`P)!%P`501P`;``!`C@"`/Y@\`4`_J'P!0!!%T$;`?Z@\`4`01=!&@'^>/,!
+M`4$701P!_G#S%P'^0],1`?Y@\!0`_G/S'0#^<]4``D$7L`4`_F'3``!!%T$9
+M`?YATP4`_G/5"P7^8=,'`OZAT`$!_J#0$@1!%T$8`0```$$7!`$&`/Y@`;@`
+M`$$8\`H(`$$9\`H``$$:\@\``$$;\B$``$$<\A```/`&__(```0(`!8```9C
+M""T#"<(H+00$*"T%""A;`&19``#P$/_R`P(&`0#(```38`!!70!&$UP`1@09
+M":1+``D*D`!@`"@37`!&!!E6`````*(````$____P````*$````0````*@``
+M`"````"-````,````&H37`!&`QD(2@`)"FX`8``H$UP`1@<9"@#_/2!@`$L1
+M2@`)"F<`8``H$UP`'A-<`$8($1-<`$8(7@!0"!%@`%59"C\`8`!:*PIS:&``
+M6BL37`!&`P,*`(!@`%\K`PH`@&``55D37`!&`P<H$UP`1@0#*`,%8`!565D*
+M;0!@`"A9`/`"__(!`0$)``@```J0`&``*%D`\!/_\@$!`@D`#```8D$7+5\`
+M/"M9````\!+_]@$!`P$`&```$UP`'EX`,D4`#Q-<`!X*`,@)$%X`-P17L`7_
+M\@$!!`(`/```$U\``!-B_J$M7P`%70`*$V+^H"U?``]=`!038OYX+0H$`%\`
+<&5T`'@H$`&``(T4`"0IG`&``*!->`"U9````````
`
end
diff --git a/usr.bin/ssh/scard/Ssh.java b/usr.bin/ssh/scard/Ssh.java
index 05e2b487283..3692b9bbb4f 100644
--- a/usr.bin/ssh/scard/Ssh.java
+++ b/usr.bin/ssh/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/07/30 20:08:14 rees 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