summaryrefslogtreecommitdiff
path: root/scard/Ssh.java
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2001-09-15 20:58:46 +1000
committerDamien Miller <djm@mindrot.org>2001-09-15 20:58:46 +1000
commit69e00a18a5dbbdf7a79561f040ce68de832289a2 (patch)
tree2e3748d27c4d26f6ea601082d7c52d1ff82d2bd7 /scard/Ssh.java
parent599d8eba16e295fd6a1727fbc1f4a17f67075900 (diff)
- (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 @@
1/* 1// $Id: Ssh.java,v 1.2 2001/09/15 10:58:47 djm Exp $
2 * copyright 1997, 2000 2//
3 * the regents of the university of michigan 3// Ssh.java
4 * all rights reserved 4// SSH / smartcard integration project, smartcard side
5 * 5//
6 * permission is granted to use, copy, create derivative works 6// Tomoko Fukuzawa, created, Feb., 2000
7 * and redistribute this software and such derivative works 7//
8 * for any purpose, so long as the name of the university of 8// Naomaru Itoi, modified, Apr., 2000
9 * michigan is not used in any advertising or publicity 9//
10 * pertaining to the use or distribution of this software 10
11 * without specific, written prior authorization. if the 11// copyright 2000
12 * above copyright notice or any other identification of the 12// the regents of the university of michigan
13 * university of michigan is included in any copy of any 13// all rights reserved
14 * portion of this software, then the disclaimer below must 14//
15 * also be included. 15// permission is granted to use, copy, create derivative works
16 * 16// and redistribute this software and such derivative works
17 * this software is provided as is, without representation 17// for any purpose, so long as the name of the university of
18 * from the university of michigan as to its fitness for any 18// michigan is not used in any advertising or publicity
19 * purpose, and without warranty by the university of 19// pertaining to the use or distribution of this software
20 * michigan of any kind, either express or implied, including 20// without specific, written prior authorization. if the
21 * without limitation the implied warranties of 21// above copyright notice or any other identification of the
22 * merchantability and fitness for a particular purpose. the 22// university of michigan is included in any copy of any
23 * regents of the university of michigan shall not be liable 23// portion of this software, then the disclaimer below must
24 * for any damages, including special, indirect, incidental, or 24// also be included.
25 * consequential damages, with respect to any claim arising 25//
26 * out of or in connection with the use of the software, even 26// this software is provided as is, without representation
27 * if it has been or is hereafter advised of the possibility of 27// from the university of michigan as to its fitness for any
28 * such damages. 28// purpose, and without warranty by the university of
29 * 29// michigan of any kind, either express or implied, including
30 * SSH / smartcard integration project, smartcard side 30// without limitation the implied warranties of
31 * 31// merchantability and fitness for a particular purpose. the
32 * Tomoko Fukuzawa, created, Feb., 2000 32// regents of the university of michigan shall not be liable
33 * Naomaru Itoi, modified, Apr., 2000 33// for any damages, including special, indirect, incidental, or
34 */ 34// consequential damages, with respect to any claim arising
35// out of or in connection with the use of the software, even
36// if it has been or is hereafter advised of the possibility of
37// such damages.
35 38
36import javacard.framework.*; 39import javacard.framework.*;
37import javacardx.framework.*; 40import javacardx.framework.*;
38import javacardx.crypto.*; 41import javacardx.crypto.*;
39 42
40public class Ssh extends javacard.framework.Applet 43public class Ssh extends javacard.framework.Applet
41{ 44{
42 /* constants declaration */ 45 /* constants declaration */
43 // code of CLA byte in the command APDU header 46 // code of CLA byte in the command APDU header
44 private final byte Ssh_CLA =(byte)0x05; 47 static final byte Ssh_CLA =(byte)0x05;
45 48
46 // codes of INS byte in the command APDU header 49 // codes of INS byte in the command APDU header
47 private final byte DECRYPT = (byte) 0x10; 50 static final byte DECRYPT = (byte) 0x10;
48 private final byte GET_KEYLENGTH = (byte) 0x20; 51 static final byte GET_KEYLENGTH = (byte) 0x20;
49 private final byte GET_PUBKEY = (byte) 0x30; 52 static final byte GET_PUBKEY = (byte) 0x30;
50 private final byte GET_RESPONSE = (byte) 0xc0; 53 static final byte GET_RESPONSE = (byte) 0xc0;
51 54
52 /* instance variables declaration */ 55 /* instance variables declaration */
53 private final short keysize = 1024; 56 static final short keysize = 1024;
54 57
55 //RSA_CRT_PrivateKey rsakey; 58 //RSA_CRT_PrivateKey rsakey;
56 AsymKey rsakey; 59 AsymKey rsakey;
57 CyberflexFile file; 60 CyberflexFile file;
58 CyberflexOS os; 61 CyberflexOS os;
59 62
60 byte buffer[]; 63 byte buffer[];
61 //byte pubkey[];
62 64
63 static byte[] keyHdr = {(byte)0xC2, (byte)0x01, (byte)0x05}; 65 static byte[] keyHdr = {(byte)0xC2, (byte)0x01, (byte)0x05};
64 66
@@ -66,64 +68,64 @@ public class Ssh extends javacard.framework.Applet
66 { 68 {
67 file = new CyberflexFile(); 69 file = new CyberflexFile();
68 os = new CyberflexOS(); 70 os = new CyberflexOS();
69 71
70 rsakey = new RSA_CRT_PrivateKey (keysize); 72 rsakey = new RSA_CRT_PrivateKey (keysize);
71 rsakey.setKeyInstance ((short)0xc8, (short)0x10);
72 73
73 if ( ! rsakey.isSupportedLength (keysize) ) 74 if ( ! rsakey.isSupportedLength (keysize) )
74 ISOException.throwIt (ISO.SW_WRONG_LENGTH); 75 ISOException.throwIt (ISO.SW_WRONG_LENGTH);
75 76
76 /* 77 register();
77 pubkey = new byte[keysize/8]; 78 } // end of the constructor
78 file.selectFile((short)(0x3f<<8)); // select root 79
79 file.selectFile((short)(('s'<<8)|'h')); // select public key file 80 public boolean select() {
80 os.readBinaryFile (pubkey, (short)0, (short)0, (short)(keysize/8)); 81 if (!rsakey.isInitialized())
81 */ 82 rsakey.setKeyInstance ((short)0xc8, (short)0x10);
82 register(); 83
83 } // end of the constructor 84 return true;
85 }
84 86
85 public static void install(APDU apdu) 87 public static void install(APDU apdu)
86 { 88 {
87 new Ssh(); // create a Ssh applet instance (card) 89 new Ssh(); // create a Ssh applet instance (card)
88 } // end of install method 90 } // end of install method
89 91
92 public static void main(String args[]) {
93 ISOException.throwIt((short) 0x9000);
94 }
95
90 public void process(APDU apdu) 96 public void process(APDU apdu)
91 { 97 {
92 // APDU object carries a byte array (buffer) to 98 // APDU object carries a byte array (buffer) to
93 // transfer incoming and outgoing APDU header 99 // transfer incoming and outgoing APDU header
94 // and data bytes between card and CAD 100 // and data bytes between card and CAD
95 buffer = apdu.getBuffer(); 101 buffer = apdu.getBuffer();
96 102
97 // verify that if the applet can accept this 103 // verify that if the applet can accept this
98 // APDU message 104 // APDU message
99 // NI: change suggested by Wayne Dyksen, Purdue 105 // NI: change suggested by Wayne Dyksen, Purdue
100 if (buffer[ISO.OFFSET_INS] == ISO.INS_SELECT) 106 if (buffer[ISO.OFFSET_INS] == ISO.INS_SELECT)
101 ISOException.throwIt(ISO.SW_NO_ERROR); 107 ISOException.throwIt(ISO.SW_NO_ERROR);
102 108
103 switch (buffer[ISO.OFFSET_INS]) { 109 switch (buffer[ISO.OFFSET_INS]) {
104 case DECRYPT: 110 case DECRYPT:
105 if (buffer[ISO.OFFSET_CLA] != Ssh_CLA) 111 if (buffer[ISO.OFFSET_CLA] != Ssh_CLA)
106 ISOException.throwIt(ISO.SW_CLA_NOT_SUPPORTED); 112 ISOException.throwIt(ISO.SW_CLA_NOT_SUPPORTED);
107 //decrypt (apdu); 113 //decrypt (apdu);
108 short size = (short) (buffer[ISO.OFFSET_LC] & 0x00FF); 114 short size = (short) (buffer[ISO.OFFSET_LC] & 0x00FF);
109 115
110 if (apdu.setIncomingAndReceive() != size) 116 if (apdu.setIncomingAndReceive() != size)
111 ISOException.throwIt (ISO.SW_WRONG_LENGTH); 117 ISOException.throwIt (ISO.SW_WRONG_LENGTH);
112 118
113 rsakey.cryptoUpdate (buffer, (short) ISO.OFFSET_CDATA, size, 119 rsakey.cryptoUpdate (buffer, (short) ISO.OFFSET_CDATA, size,
114 buffer, (short) ISO.OFFSET_CDATA); 120 buffer, (short) ISO.OFFSET_CDATA);
121
115 apdu.setOutgoingAndSend ((short) ISO.OFFSET_CDATA, size); 122 apdu.setOutgoingAndSend ((short) ISO.OFFSET_CDATA, size);
116 return; 123 return;
117 case GET_PUBKEY: 124 case GET_PUBKEY:
118 file.selectFile((short)(0x3f<<8)); // select root 125 file.selectFile((short)(0x3f<<8)); // select root
119 file.selectFile((short)(('s'<<8)|'h')); // select public key file 126 file.selectFile((short)(('s'<<8)|'h')); // select public key file
120 os.readBinaryFile (buffer, (short)0, (short)0, (short)(keysize/8)); 127 os.readBinaryFile (buffer, (short)0, (short)0, (short)(keysize/8));
121 apdu.setOutgoingAndSend((short)0, (short)(keysize/8)); 128 apdu.setOutgoingAndSend((short)0, (short)(keysize/8));
122 /*
123 apdu.setOutgoing();
124 apdu.setOutgoingLength((short)(keysize/8));
125 apdu.sendBytesLong(pubkey, (short)0, (short)(keysize/8));
126 */
127 return; 129 return;
128 case GET_KEYLENGTH: 130 case GET_KEYLENGTH:
129 buffer[0] = (byte)((keysize >> 8) & 0xff); 131 buffer[0] = (byte)((keysize >> 8) & 0xff);
@@ -133,24 +135,9 @@ public class Ssh extends javacard.framework.Applet
133 case GET_RESPONSE: 135 case GET_RESPONSE:
134 return; 136 return;
135 default: 137 default:
136 ISOException.throwIt (ISO.SW_INS_NOT_SUPPORTED); 138 ISOException.throwIt (ISO.SW_INS_NOT_SUPPORTED);
137 } 139 }
138 140
139 } // end of process method 141 } // end of process method
140 142
141 /* 143} // end of class Ssh
142 private void decrypt (APDU apdu)
143 {
144 short size = (short) (buffer[ISO.OFFSET_LC] & 0x00FF);
145
146 if (apdu.setIncomingAndReceive() != size)
147 ISOException.throwIt (ISO.SW_WRONG_LENGTH);
148
149 //short offset = (short) ISO.OFFSET_CDATA;
150
151 rsakey.cryptoUpdate (buffer, (short) ISO.OFFSET_CDATA, size, buffer,
152 (short) ISO.OFFSET_CDATA);
153 apdu.setOutgoingAndSend ((short) ISO.OFFSET_CDATA, size);
154 }
155 */
156} // end of class Ssh