New blog

•29/09/2010 • Leave a Comment

I’ve set up a new blog, with a new domain, so from now on this blog will no longer be updated.

I hope you like all the information, but if you need to contact me, you can at

peter@lavamunky.com

or just catch my new blog: http://www.lavamunky.com

The importance of Twitter to an information security newcomer

•31/05/2010 • Leave a Comment

I’ll be the first to admit I’m very new to this field but will try my hardest to forge a career within industry with the general term ‘information security’.

I’ve been on twitter for a fair while now but I’ve found it practically invaluable with first of all finding people within the industry and secondly finding information on new things happening in the industry.

I recently saw this in a video presented by Marisa Fagan (@dewzi) on what you should be trying to do in order to get into the industry (found here) and she also keeps reiterating the importance of having a blog and being on twitter. And I will admit now that even though I subscribed to a fair few blogs etc, until I started to find security people on twitter, I was barely scratching the surface of the new things that are constantly being discovered and exploited.

If you too are just trying to get into this industry, whether you’re at university like myself or just interested from moving from another area of computing, I urge you to join twitter as it’s the best resource I’ve found for integrating with the (generally nice and helpful) people in the information security community.

Communicating between a phone & Java Card emulator

•31/05/2010 • Leave a Comment

This is just the building blocks to running your own applications, and here I will be using code free on the internet and with the samples included with the Java Card installation.

I will also be using the setup used as shown in this post here.

So to start off with we want to create a new Project in Netbeans and select ‘Java ME’ and ‘Mobile Application’ from the right hand side.

From here make sure the ‘Set as Main Project’ box is ticked and the ‘Create Hello MIDlet’ box is unticked. And that the Emulator platform is Sun Java Wireless Toolkit. It’s also best to make sure the Device Configuration is CLDC-1.1 and the Device Profile is MIDP-2.1. Though 2.0 should do fine as well.

Now you need to create a new MIDlet Now call this APDUMIDlet and copy in the APDUMIDlet class from here.

Now you can either follow the instructions at the top of that website, or you can follow on to find out how to compile and run your own Java Card program.

First you need to change the package name at the top to whatever yours is called. Then go down to the first initialised variable, kPurseSlot0.

private final String kPurseSlot0 = "apdu:0;target=a0.00.00.00.62.03.01.0c.02.01";

The apdu slot can stay the same at 0 (which refers to port 9025 from last post), but for ease we will change the target to

target=01.02.03.04.05.06.07.08.09.00.01

Then you want to comment out the next 2 lines so that they look like

//private final String kPurseSlot1 = "apdu:1;target=a0.00.00.00.62.03.01.0c.02.01";
//private final String kWalletSlot0 = "apdu:0;target=a0.00.00.00.62.03.01.0c.06.01";

And also the lines referring to these further down should be commented out

/*
setProgress("Opening purse slot 1");
mPurseConnection1 = (APDUConnection)Connector.open(kPurseSlot1);
setProgress("Opening wallet slot 0");
mWalletConnection = (APDUConnection)Connector.open(kWalletSlot0);
*/

And then again comment out the code that has these  Connections doing anything

/*setProgress("Exchanging APDUs with wallet");
      for (int i = 0; i < kWalletAPDUs.length; i++) {
        byte[] apdu = kWalletAPDUs[i];
        byte[] response = mWalletConnection.exchangeAPDU(apdu);
        // Process response.
      }
      
      setProgress("Closing wallet");
      mWalletConnection.close();

      setProgress("Exchanging APDUs with purse slot 1");
      for (int i = 0; i < kPurseAPDUs.length; i++) {
        byte[] apdu = kPurseAPDUs[i];
        byte[] response = mPurseConnection1.exchangeAPDU(apdu);
        // Process response.
      }
      
      setProgress("Closing purse slot 1");
      mPurseConnection1.close();

And again the 2 try statements for closing the Connections need to be commented out

//try { mPurseConnection1.close(); } catch (Throwable t) {}
//try { mWalletConnection.close(); } catch (Throwable t) {}

Now the code is fine for our purposes. As there is only connections on the one slot and we are simply trying to have programs where the programs communicate.

We are going to be using HelloWorld program that simply takes in bytes and returns them.

This can be found within the Java Card installation directories. All you need to do is open this in your preferred editor and change the package name to the same as your Java ME package name. Then save this to a new directory, for instance:

%USER%\newProg\

(%USER% being your home directory. It is often a system variable in Windows, %USERPROFILE% also used)

How to compile and run in a lot of detail is explained here. But for everyone else who doesn’t want too much detail, here is the much shorter version (comments :

So your HelloWorld.java program is in this file (above) and now you need to create a new folder in here with the same package name you have. For example using the package name ‘prototype’ you would do

mkdir prototype

Now you need to compile the program like this

javac -g -d prototype -classpath “.;%JC_HOME%\lib\api.jar” HelloWorld.java

using the package prototype and program file HelloWorld.java. And now you need to convert the Java Card applet into a .cap file by doing

converter -applet 0×01:0×02:0×03:0×04:0×05:0×06:0×07:0×08:0×09:0×00:0×00 prototype.HelloWorld -classdir prototype -exportpath %JC_HOME%\api_export_files prototype 0×01:0×02:0×03:0×04:0×05:0×06:0×07:0×08:0×09:0×00 1.0

This has the unique ID for this applet (which is what the Java ME program connects to) which is why we changed target to 01.02.03.04.05.06.06.08.09.00.01 earlier.

And you have to put the -classdir parameter of where the .class file is (inside the prototype folder we created earlier). Then we use the say the export path (always the same) and state the package name, the package unique ID (I’ve just used the same as the Applet ID except leaving off the final byte 0x01). And the Major Version.Minor Version (if you don’t understand just put 1.0 every time).

Now the scripts have to be generated from the .cap file which is what will go onto the Java card.

scriptgen -o HelloWorld.scr prototype\prototype\javacard\protoytpe.cap

if you look at your file system, it creates directories in a strange way so instead of your .cap file just being in prototype/javacard/prototype.cap it will have created another inside the folder you already created. But if you don’t create the folder before you cannot create the .cap file (thus the hacky process of creating a folder)

Now you will have a script called HelloWorld.scr. Open this in your preferred editor and you need to make some changes for this. First of all add a line to the top of the script and just put in:

powerup;

Now you need to add in a line of bytes which will always be the same:

0×00 0xA4 0×04 0×00 0×09 0xa0 0×00 0×00 0×00 0×62 0×03 0×01 0×08 0×01 0x7F;

Now you need to add lines which will create and select the Applet (I often put in comments to remind me):

// create Applet

0×80 0xB8 0×00 0×00 0x0d 0x0b 0×01 0×02 0×03 0×04 0×05 0×6 0×07 0×08 0×09 0×00 0×01 0×00 0x7F;

// Select Applet

0×00 0xa4 0×04 0×00 0x0b 0×01 0×02 0×03 0×04 0×05 0×6 0×07 0×08 0×09 0×00 0×01 0x7F;

Now you can see the 2 part in italic are exactly the same. This is also the Applet ID (AID). The 0x0b is the length of the AID in hexadecimal. And in the create applet command it also has an extra 0x00 after the AID and before 0x7F. This means the length (before the AID in the create applet command) there is another byte 0x0d which is length here. Then you simply need to add at the end:

powerdown;

And open up a terminal window and type

start cref -o HelloWorld.eeprom

which will open a new terminal window and run the command, then in the first window type

apdutool HelloWorld.scr

and this will show a big print out. This is the debugging of everything, and all you have to look at is the last 2 returned bytes of each line (looking at the last 4 lines will suffice)

if SW1: 90 and SW2: 00 then it is fine, and has gone onto the card correctly and is ready to be run. Type

start cref -e -p 9025 -i HelloWorld.eeprom

And leave this running. Now go back to netbeans and run the program. Click through the emulator and it will work.

You can also look at the network monitor to see the bytes being sent back and forth.

The phone emulator screen should say something like this:

The output of the 2 programs communicating

And you can see the bytes sent in the APDU tab of the network monitor:

Bytes sent between card and emulator

As you can see it has the right target and it’s first establishing a connection to the card. And the different bytes being sent back and forth, where the arrow going left to right is phone to smart card and vice versa.

This is a good way to find out errors occurring in your own programs.

If you have any problems or another question, feel free to comment.

Installing Java Card (Windows)

•24/05/2010 • 2 Comments

Originally there was going to be a video to show the process of actually installing Java Card along with everything else to get an application running but due to the fact that I couldn’t upload it to youtube (after major editing it was still 40 minutes long), I have decided to put it in a series of blog posts.

The first blog (this one) will be of physically installing Java Card and netbeans onto Windows. (There will probably also be another for Linux – not supported for Mac OS).

The second will be simply running a program to get the 2 bits of software communicating with each other in a program.

Just a note beforehand though, I am using Java Card 2.2.1, though the newest release is 3.0.2. This has a lot more features but couldn’t get it working for the purposes I needed (communicating with a J2ME phone application). I also tried using Java Card 2.2.2, but also due to the requirements I needed for my project I couldn’t use this. So all these posts will be using Java Card 2.2.1, and using newer versions may not work the same.

But onto the real installation:

Step 1: Install Java SDK 1.3

Now you may be asking “Why do I have to use such an old SDK like 1.3?” (Well if you’re not you should be).

This is because Java Card 2.2.1 and Sun’s Wireless Toolkit do not work with any newer version, otherwise they would have been used, since Java SDK 1.3 isn’t even supported anymore. (In fact I think 1.4 isn’t supported anymore, thus really showing its age).

Now you need to go to here to download the old SDK.

This is where you download Java SDK 1.3

Now simply click on “DOWNLOAD” beneath SDK to take you to another page where you can download the file.

Save the file to where ever you want and then you have to do a normal installation EXCEPT when you decide where to save the program, change it to a new folder where there are NO spaces in the entire directory.

So where it is usually saved to somewhere like C:\Program Files\j2sdk1.3\ you want it saved to a directory such as C:\jdk1.3\ or C:\Java\ as you can see here:

You need to save the SDK to a directory with no spaces

If yours has spaces, just go to browse then C:\ and save it there, or (preferably) create a new folder and save it in there, which in this instance is jdk1.3_20 this is for a reason that I will go into detail later.

Step 2: Install Java Card

The Java Card development kit we want (2.2.1) can be found here. You need to to go to the bottom of the page and click on Java Card Development Kit 2.2.1

We are using Java Card 2.2.1

From here you go to another page, choose Windows from the drop down box and download the .zip file.

Then extract this, again to a directory with no spaces in. And it’s probably best not to have it in the same folder as the Java, but something easy to locate, for example C:\JavaCard221\

In these files you will see a file called bin. This is the file that has all the batch files that Java Card uses.

Now you need to make the variables to be used by Java Card and the wireless toolkit, and you for general ease.

To do this go to Start -> My Computer then as you can see here it will be on the left and click on “View System information” (in Windows XP home for Vista or 7 just type in “system information” or “system properties” without quotes into the start menu search box)

This will then take you to another screen. You need to click on the “advanced” tab at the top

You need to click on the "advanced" tab

Then in the advanced tab you need to click the “environment variables” button. This will make this screen appear:

Now to change the environment variables

Now you need to click the bottom “New” button of the 2 onscreen. Then create an environment variable with name JAVA_HOME (must to be capitals and with an underscore) and variable value C:\Java\jdk1.3 or where ever you installed Java SDK 1.3. Make sure to NOT put a \ at the end. Then click OK. Now you also need to make another variable, named JC_HOME (must be exact again) with variable value of the directory where you extracted the Java Card zip to.

You can check both these are here as they will be in the list of System Variables. Now you need to scroll down this list until you find a variable called Path. Click Edit.

If there is not a ; at the end of the value, then add one. Now you need to leave what is in the value as it is and add to the end of path

%JAVA_HOME%; %JAVA_HOME%\bin; %JC_HOME%; %JC_HOME%\bin;

then click OK. And click OK on the environment variables box, and OK on the system properties box.

To check this has worked, go to start -> run and put in cmd and click OK

Start -> run cmd

This will then open a command prompt window. And check that the path variables are set by typing dir %JAVA_HOME% and hitting enter. It should show something like this:

You can see that it says “Directory of ” and then the folder you set the variable to. If it just appeared with something like “variable not found” or “unknown command” then close the command prompt window and go back to the section about environment variables and make sure they have all been done correctly. It’s also best to do dir %JC_HOME% as well to make sure there are no errors.

NOTE: If you just want to install the Java Card toolkit, you are now done. For all the rest that need to communicate with an emulator carry on to the next step.

Step 3: Installing Sun’s Java Wireless Toolkit

I was using the Java Wireless Toolkit 2.5.2 for CLDC, which can be downloaded from here.

Just scroll down and there’s a link to download it, again choosing Windows from the drop down box and download the file. This can just be installed to a directory with no spaces and there are no variables that have to be created for this. The wireless toolkit has some handy utilities I used though they could just be used directly from netbeans, but either way the wireless toolkit has to be installed. So now onto….

Step 4: Installing netbeans

The version you need for this is Netbeans 6.7.1, and a version that can work with Java ME. This is because the newer versions don’t work with versions of Java Card this old, but the wireless toolkit doesn’t work with newer versions of Java Card, so until the wireless toolkit is updated, you have to use all these old versions of everything else.

But back to the installing netbeans. The link is here. You need to choose a version that supports Java ME

You can see only the Java and All editions supports Java ME

Clearly only 2 versions, Java and All technologies bundles, support Java ME. So download one of these (best to just download All if you think you might need it again for C/C++ or something).

Then do a normal Windows install like any other program, netbeans can even be installed to the ‘Program Files’ folder. Except you can do a customised installation if you don’t want to install things like the enterprise server bundles.

Once all this is installed you may have to go to new project and create a Java ME project to simply initialise J2ME on netbeans. But after this is done go to Tools (at the top) -> Java Platforms and the Java Platform manager will appear and if Sun Java Wireless Toolkit isn’t in the J2ME folder, you need to click on “Add Platform…” at the bottom, then click on “Java ME MIDP Platform emulator” as Platform type

Click the one second from the top

And then it will search for all Java ME platforms. When the directory for the wireless toolkit appears, make sure there is a tick next to it and click next and install.

Now you need to double click Sun Java Wireless toolkit in the left hand column of the Java Platform Manager and go to the Tools & Extensions tab here and click on “Open Preferences”

Go to tools & extensions then click open preferences

In Preferences you can choose which phone you want the emulator to look like. Then click Monitor in the left column and make sure “Enable Network Monitor” is checked as shown here:

Make sure you enable network monitoring

This will enable you to clearly see communication between the emulators to see for errors or just out of curiousity.

Now go to SATSA (on the left) and make sure slots 0 and 1 are 9025 and 9026 respectively.

And now everything is installed and ready to make a program (Next post) =D

Java Card APDU format

•28/03/2010 • 2 Comments

My last post, about Java Card (the reason I’ve been so busy of late – spending 3 times as much work on my team project as most others, including many nights sleep lost) basically didn’t go over very well the whole format of the commands that you have to put into your script.

This will be base knowledge you will need to know if you are going to be programming java Card and any program which may be interacting with some java card program.

(By the way, if you hadn’t already looked, APDU stands for Application Protocol Data Unit)

Basically the bytes are set up in the format:

CLA INS P1 P2 Lc Datafield Le

CLA: Class byte – this often refers to the actual application

INS: instruction byte – indicates the instruction code associated with the one in the java card program.

P1 & P2 – parameters-  if needed for certain things, for instance with verification on a mobile phone, you can have a PIN and then a PUK if locked out. Having the same INS byte and a different parameter would make sense.

Lc- says how many bytes in the data field of the APDU command.

Le- the expected Lc of the response APDU command.

This is pretty easy stuff but you just have to remember it. But it will mean people who don’t know this will give you strange looks if you just tell them about it.

There is probably a lot you need to learn in a (more often than not) short space of time, and I know it sucks, but just get on with it.

I’m just trying to lend some help in this not too well documented programming language, and I personally had a lot of problems just setting up the environments with 2 postgraduates at hand for quite a while.

Hopefully I should be uploading a video soon of setting it up/running a quick program.

I’ve already made the video, but sound/text needs to be added, but it will be in depth, so will be around 20/30 mins long

Anyway, again, if you have any questions, just submit a comment.

Lavamunky

Java Card program compilation and running for new comers (newbies)

•28/03/2010 • 3 Comments

(FOR QUICKREF COMMANDS GO TO BOTTOM)

Now you may have not even heard of Java Card, but if you have it might be because you were thrown into the same situation that I was thrown into, an unfortunate one where it was tasked to you as part of a university project along with 8 other people.

If you haven’t, basically it’s a version of Java that is very, very small and is designed to work on smart cards, like a SIM card or a smart card chip in a chip and PIN card. (Although in my case it only had to work on an emulator)

I know a big group, though unfortunately it was just myself and 2 others doing the programming parts of it, and we really underestimated the difficulty of getting Java Card working.

Well I’ll give you a little background of the project that made it so difficult.

We weren’t just tasked with creating something in Java Card, that is easy, and we set up the environments for this quite easily, with using eclipse and a plugin called JCDE which can be found here and it actually has pretty good instructions with it to set up the environment and get a program running. Though we had to have a system where the Java Card interacted with a mobile phone application, programmed in J2ME (which we hadn’t used either – a sign of good things to come) using the Sun Java Wireless Toolkit. Now we thought this was fine, we already had an IDE set up that we presumed was compiling a Java Card program correctly. We had only heard bad things about trying to run J2ME programs in eclipse, so we went with the suggestion of a postgraduate and use netbeans for the J2ME code (I didn’t particularly want to use 2 different IDEs, but if need be).

This too, wasn’t too difficult, but then we ran into a problem. Actually running the 2 programs together, with netbeans running a phone emulator and Java Card running whatever it ran (we didn’t know exactly what we had to do at the time, I know now that the way it was running, eclipse stopped running the CREF – which I will come to later, and so it couldn’t be done easily, but that wasn’t the main problem).

Basically after a massive amount of time I spent with 2 postgraduates that know a lot about the 2 programming languages separately, we basically got something working. It turned out the problem was that we were using Java Card 2.2.2 in eclipse (as the JCDE plugin only accepts this version and after) and the wireless toolkit on netbeans, which only uses Java Card 2.2.1. And there are compatibility problems to do with the smart card emulator that means they cannot work together.

I said fine, and since I’m fairly competent on command line, I thought I would give it a try on there. This eventually worked, but as you will find out if you need to try and find out about Java Card, it isn’t too easy to simply find out these.

(NOTE: I’m giving you a MASSIVE tip here, if you have Java Card problem, don’t Google it like you normally would. Go to the Sun Java forums here. The help here is far beyond any help I ever got simply Googling my problems to do with Java Card)

Now I’m only going to tell you here how the Java Card compilation occurs of Java Card 2.2.1 (I think it’s the same for 2.2.2, but not sure about the newer versions of 3.*)

I’m going to give the commands for Windows, though on Linux (Java Card isn’t available on Mac) the commands are the same for the linux command constraints, i.e. \ becomes / and in like -classpath “.;%WHATEVER%;” would become -classpath “.:$WHATEVER:”. Though I warn you now – if you want to install Java Card on a Linux machine, it can be done, though it is a massive struggle to eventually get there. There’s lots of fiddling, and although I’ve been using *nix machines for a while, I still actually found it a great deal easier to install on Windows XP.

Ok so say you are in a directory (I’m using Windows XP equivalent here, just adapt to your system again) with a java card program Java_card_prog.java. So it’s directory would be this:

C:\Documents and Settings\User\Java_card_prog.java

Ok, so first you need to create a directory of the name of the programs package. So each java card program would belong to a package. So I’m going to call the package of this one test.

so do: mkdir test

Now you need to do the first command to actually. Don’t bother cd-ing into the package directory, there is no point.

Now do

javac -g -d test -classpath “.;%JC_HOME%\lib\api.jar” Java_card_prog.java

(you need to make sure all you’re environment variables are up to scratch – I’ll be making a video of the whole process of installing on Windows and running your first program to run working with a mobile phone application)

Now this last command basically compiles the java card program. I tried without the -d with the package directory, but couldn’t get commands after to work.

Now you will notice if you look this doesn’t actually make the class files in the directory test, but in test\test\ which is a little odd and I don’t know why, but it likes to do this, though it doesn’t change how it works overall, so it doesn’t matter in the end.

Next of all you need to convert the class files into a .CAP file. This is the file that can be used with scripts to load onto the smart card (emulator in this case). We do this with:

converter -applet 0x01:0x02:0x03:0x04:0x05:0x06:0x07:0x08:0x09:0x00:0x00 test.Java_card_prog -classdir test -exportpath %JC_HOME%\api_export_files test 0x01:0x02:0x03:0x04:0x05:0x06:0x07:0x08:0x09:0x00 1.0

Now I know this is a big command and that’s because it needs to be, basically. With -applet you define the applet ID (AID) and the package.Program, then you need to put in the directory where you put the class files (test) and you MUST put in -exportpath %JC_HOME%\api_export_files for this to work. Then you put the package name again, and the package ID (also AID) and then have minor version.major version. If you don’t understand this, just put 1.0 every time.

Now a .CAP and .EXP file are made (.EXP not needed but we didn’t state in the last command, so just done by default), and they will be in test\test\javacard\

Now you need to create the scripts with

scriptgen -o Java_card_prog.scr test\test\javacard\test.cap

this outputs the script into a file called Java_card_prog.scr, from here you need to change the script, so open it up in your favourite text editor, for instance notepad or notepad++ (personal preference).

You need to add the line at the start of the file powerup;

then it needs to have the line

// Select the installer applet
0x00 0xA4 0x04 0x00 0x09 0xa0 0x00 0x00 0x00 0x62 0x03 0x01 0x08 0x01 0x7F;

This will possibly be in there already, but wasn’t in my cases. You don’t need the comments, but they helped me a lot to start off with.

Then it will load the .CAP file parts into it, starting 0x80 0xB0 0x00 0x00 0x00 0x7F;

and ending at the end 0x80 0xBA 0x00 0x00 0x00 0x7F;

Now you need to create the Applet and select it.

// create Applet

0x80 0xB8 0x00 0x00 0x0d 0x0b 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x00 0x00 0x00 0x7F;

// Select Applet

0x00 0xa4 0x04 0x00 0x0b 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x00 0x00 0x7F;

Now these will have to be changed to accord with yours. As you can see in ‘select applet’ command, it starts 0x00 0xa4 0x04 0x00 as it always will. Then it has 0x0b, the LC bit, which shows length of the CDATA being sent. In hexadecimal, 11 is B, so 0x0b or just 0xb would do. If you count the data, it is the next 11 bytes (every piece of hex before the end bit 0x7F;). The CDATA to select the applet is, of course the Applet ID. And there is a correlation between this and the create applet command you may see.

Basically the create applet has the LC of the AID and the AID as the CDATA for select applet with 0x00 added onto the end. And then the length of this is worked out (number of LC of select + another byte at end + actual LC byte = LC + 2) so oxod.

The final command to be added is simply powerdown;

If you do this then save the script. Go back to the command prompt (or terminal, or whatever), and put in

start cref -o Java_card_prog.eeprom

(in linux – you will have to open another terminal – start won’t work)

This command will open another command prompt which will be listening on a port to be fed in the script which it can then install to the card

Then in the first command prompt, type apdutool Java_card_prog.scr

You will see lots of lines of data come up, which will help you debug.

If you look at the last 2 bytes that are sent back, these are the only ones that count. The SW1: and SW2: or the second may be called something different, but it’s always the last 2 bytes of each line.

If SW1: 90 or 0x90 and SW2: 00 or 0x00 this means the command it OK. Which is good. Each line has this and you could go through every line. Basically as long as there haven’t been any errors so far, then it is fine and you just need to check the last 2 lines, which is the create and select applet commands, respectively.

If there is something wrong with either of these, first go back to the first line and make sure the whole applet installed properly, if it did look at this in the script – there will most probably be a problem here. If not then look in the script at the last 2 command to make sure they are completely correct (i.e. corresponding AID’s to what you compiled it with) – if they are fine then there is something with your code. Probably in the Select (for select) or a constructor or start method for creation. However you may have nothing in your select method but this is the only thing giving an error. Sometimes the select error is also for creating a constructor.

If you want to then run this when it’s fine with an emulator running in netbeans or just the wireless toolkit on it’s own, you simply run the command

cref -p 9025 -i Java_card_prog.eeprom

which opens the cref on port 9025 (standard cref port) and takes in the file Java_card_prog.eeprom (eeprom was initially used as it would be the actual EEPROM in a real smart card – if you don’t know you should look up smart card internal designs).

If anyone needs help or didn’t understand anything, I’m going to be putting up a post of how to install everything and run a simple program, there may be a video, which I’ve already done for installing on Windows XP. But haven’t uploaded yet to youtube or anywhere. This will explain everything, but if you have comments before then, feel free to ask. There is also a synopsis of all the commands and such at the bottom, for quick reference which you can save into a folder/make a batch script from etc)

-lavamunky

making java card work:

from %USER%\workspace\Prototype\src\prototype\

javac -g -d prototype -classpath “.;%JC_HOME%\lib\api.jar” prog.java

converter -applet 0x01:0x02:0x03:0x04:0x05:0x06:0x07:0x08:0x09:0x00:0x00 prototype.Prog -classdir prototype -exportpath %JC_HOME%\api_export_files prototype 0x01:0x02:0x03:0x04:0x05:0x06:0x07:0x08:0x09:0x00 1.0

scriptgen -o Prog.scr prototype\prototype\javacard\protoytpe.cap

use eclipse to create script files

//Step 3: Edit the output of step 2 (the scr-file):

//This must be the first statement in the scr-file!

powerup;

// Select the installer applet (I think this already exist in .scr-file — not in mine)

0x00 0xA4 0x04 0x00 0x09 0xa0 0x00 0x00 0x00 0x62 0x03 0x01 0x08 0x01 0x7F;

//CAP begin (this already exists in your cap-file)

0x80 0xB0 0x00 0x00 0x00 0x7F;

//Place the Generated CAP-stuff here

//CAP end (Also exists in your cap-file)

0x80 0xBA 0x00 0x00 0x00 0x7F;

// create Applet

0x80 0xB8 0x00 0x00 0x0d 0x0b 0x01 0x02 0x03 0x04 0x05 0x6 0x07 0x08 0x09 0x00 0x00 0x00 0x7F;

// Select Applet

0x00 0xa4 0x04 0x00 0x0b 0x01 0x02 0x03 0x04 0x05 0x6 0x07 0x08 0x09 0x00 0x00 0x7F;

powerdown;

start cref -o safetex.eeprom

//opens new window

apdutool safetex.scr

//if SW1: 90 and SW2: 00 – last 2 bits of last few lines then is correct

start cref -e -p 9025 -i safetex.eeprom

Mac OS X Terminal

•14/02/2010 • Leave a Comment

Now this post is mostly out of procrastination of more important work, however I am here to talk about a very very important topic on Mac OS X and basically anything Unix based (so mainly OS X and linux). Of course, by the title you can see this is the Terminal.

You may be wondering but why does everyone say that it is so important (or rather if you don’t see that everyone is saying this, you are talking to the wrong people and looking at the wrong things about Mac). Basically the Terminal is a piece of software which gives you a Command Line Interface (CLI) which in turn means you can do practically anything with your system.

Due to the fact that in a terminal, it simply shows commands and text, there is no graphical (or practically no) graphical rendering that has to be done. This means that it runs a lot quicker than if you are using a GUI (Graphical User Interface). Now you may not notice much difference if you are using a brand new Mac, with a lightning fast processor and a huge amount of RAM, with a great graphics card, but you would eventually. And if something goes wrong with anything, there is nearly always a way of sorting it through a terminal. So really, you would be better off using it sooner rather than later.

Basically everything you need to know about the terminal can be found on the internet, but the first place you should go for anything our the man pages. Now these are manual pages for all the different commands on the system. (Note now: Unix terminals are case sensitive, so Man is not the same as man)

Now should you ever need to know what a command does and need a fair bit of information about it, you can look in the man pages, or if you want a quick lookup for a command you can always use whatis for instance. You can remember the command grep but you’re not sure what it does, you don’t have to do man grep and get a huge list of all the things you can do. Instead you can just type whatis grep. Now this will show up a few results sometimes, but then you see just find your result and it tells you exactly what it does in a short description

Now grep is a very powerful command, and I will discuss it more in a later post, as I will also need to describe piping. But for now just some command things and commands in a terminal. One of the most basic command in a Unix terminal is ls. This lists the directory contents. Note: You may directories more as folders, but in terms of the whole system and using terminal they are more often referred to as directories.

If you go into the man page for ls it will show you everything you need to be able to use ls. My main arguments for ls are -l and -a

-l lists the directories and files inside your current directory with information about them, such as the owner, the group the file belongs to, the permissions for the files/directories, size and lots more.

-a shows all files, including system and hidden files/directories.

Also unlike command prompt in Windows, you can put arguments together in Unix, so where in Windows to remove a directory in command prompt you would have to type rmdir /q /s in Unix you can just type rm -rf folderName instead of rm -r -f folderName

But what if you want to go through to different directories. Then you have to use, I would say, the most common used command in any Terminal. This is cd, which stands for change directory (see why I kept saying directory instead of folder). Now cd is basically used all the time and all you have to do is type cd and the directory name you want to change to. Now you can either change to a directory by putting in the whole thing, or you can do it relative to your position.

If you type in pwd this shows the directory you are currently in. If you have just opened the terminal, type pwd and it should be something like /Users/username (your home directory) where ‘username’ is the username you use on the computer. Basically in the file system, everything starts from root, / and then they go down from here. So in /Users/username this has actually gone to root / then looked through to Users, then looked through here and changed the directory to username and that’s where you are now. But relative addresses are relative to where you are in the file system. So if you want to get to your Documents directory you could type cd /Users/username/Documents but if you are already in your home directory you could simply type cd Documents. But because it was recognised how often people would have to go to their home directory, to get back to it, you can either type it out in full or type cd on its own, or cd ~ (tilda) and tilda also works relatively. So If you are at root (/) and want to get to your Documents, you could cd through the other directories, or you could simply type cd ~/Documents and it’s easy as that. And if you want to go back to the containing directory, you can type cd .. and cd . just keeps you in the same directory (this is why you see . and .. when you type ls -a). A quick tip is that if you are in a directory and accidentally just do something like cd on it’s own, you can just type ‘cd -‘ to go back to the directory you were in before.

Also another commonly used command in a terminal on Mac OS X is open. If you want to open a pdf etc, you can just type open file.pdf. However if you want to open something like a full program like iTunes, you can type open -a iTunes otherwise, you have to type in the path (full directory) for the application and even then it might not just be called ‘iTunes’

Basically this will end up as a few posts because even as a quick-start guide, there is just too much to say

 
Follow

Get every new post delivered to your Inbox.