- (djm) Sync scard/ stuff

This commit is contained in:
Damien Miller 2001-09-15 20:58:46 +10:00
parent 599d8eba16
commit 69e00a18a5
3 changed files with 91 additions and 104 deletions

View File

@ -1,5 +1,6 @@
20010915 20010915
- (djm) Make do_pre_login static to avoid prototype #ifdef hell - (djm) Make do_pre_login static to avoid prototype #ifdef hell
- (djm) Sync scard/ stuff
20010914 20010914
- (bal) OpenBSD CVS Sync - (bal) OpenBSD CVS Sync
@ -6431,4 +6432,4 @@
- Wrote replacements for strlcpy and mkdtemp - Wrote replacements for strlcpy and mkdtemp
- Released 1.0pre1 - Released 1.0pre1
$Id: ChangeLog,v 1.1515 2001/09/15 02:25:53 djm Exp $ $Id: ChangeLog,v 1.1516 2001/09/15 10:58:46 djm Exp $

View File

@ -1,17 +1,16 @@
begin 644 Ssh.bin begin 644 Ssh.bin
M`P)!#``:01\`A``!`F@"`$$,014!_F#P!0!!#$$?`4$,01X!00Q!'0%!#$$< M`P)!%P`501P`;``!`C@"`/Y@\`4`_J'P!0!!%T$;`?Z@\`4`01=!&@'^>/,!
M`4$,01L!00Q!&@'^H?`%`$$,01@!_J#P!0!!#$$7`?YX\P$!00Q!&0'^<]4` M`4$701P!_G#S%P'^0],1`?Y@\!0`_G/S'0#^<]4``D$7L`4`_F'3``!!%T$9
M`OYP\Q<!_D/3$0'^8/`4`$$,L`4`_F'3``!!#$$6`?YATP4`_G/5"P7^8=,' M`?YATP4`_G/5"P7^8=,'`OZAT`$!_J#0$@1!%T$8`0```$$7!`$&`/Y@`;@`
M`OZAT`$!_J#0$@0``$$,"@$$`/Y@`=```$$5\`H(`$$6\`H``$$7\@\``$$8 M`$$8\`H(`$$9\`H``$$:\@\``$$;\B$``$$<\A```/`&__(```0(`!8```9C
M\B$``$$9\A```$$:__0"`$$;__8"`$$<__8"`$$=__8"`$$>__8"`$$?__8" M""T#"<(H+00$*"T%""A;`&19``#P$/_R`P(&`0#(```38`!!70!&$UP`1@09
M`/`0__(#`@8!`,H``!-@`%]=`&037`!D!!D)I$L`"0J0`&``4!-<`&0$&58` M":1+``D*D`!@`"@37`!&!!E6`````*(````$____P````*$````0````*@``
M````H@````3____`````H0```!`````J````(````(T````P````:A-<`&0# M`"````"-````,````&H37`!&`QD(2@`)"FX`8``H$UP`1@<9"@#_/2!@`$L1
M&0A*``D*;@!@`%`37`!D!QD*`/\](&``:1%*``D*9P!@`%`37`!!$UP`9`@1 M2@`)"F<`8``H$UP`'A-<`$8($1-<`$8(7@!0"!%@`%59"C\`8`!:*PIS:&``
M$UP`9`A>`&X($6``<UD*/P!@`'@K"G-H8`!X*Q-<`&0#`PH`@&``?2L#"@"` M6BL37`!&`P,*`(!@`%\K`PH`@&``55D37`!&`P<H$UP`1@0#*`,%8`!565D*
M8`!S61-<`&0#!R@37`!D!`,H`P5@`'-960IM`&``4%D```#P$__R`0$!"0`( M;0!@`"A9`/`"__(!`0$)``@```J0`&``*%D`\!/_\@$!`@D`#```8D$7+5\`
M``!B00Q?`%I9`+`%__(!`00"`&P``!-?``43"%T`"A,)$%T`#Q,)(%T`%!,) M/"M9````\!+_]@$!`P$`&```$UP`'EX`,D4`#Q-<`!X*`,@)$%X`-P17L`7_
M,%T`&1,)P%T`'A,*!`!=`",38OZA+5\`*%T`+1-B_J`M7P`R70`W$V+^>"T* M\@$!!`(`/```$U\``!-B_J$M7P`%70`*$V+^H"U?``]=`!038OYX+0H$`%\`
M!`!?`#Q=`$$37`!!"@#("1!>`$8*!`!@`$M%``D*9P!@`%`37@!56?`&__(` <&5T`'@H$`&``(T4`"0IG`&``*!->`"U9````````
?``0(`!0```9C""T#"<(H+00$*"T%""A;``!9``````!@
` `
end end

View File

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