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