29 September 2010

Near Field Community testlibusb-win.exe

Near Field Community

libnfc
libnfc depends on libusb?
_____________________________________________________________

testlibusb-win.exe
works on Snapper Feeder
DLL version: 1.2.1.0
Driver version: 1.2.1.0


bus/device idVendor/idProduct
bus-0/\\.\libusb0-0001--0x04cc-0x0531 04CC/0531
- Manufacturer : Philips
- Product : USB TAMA
wTotalLength: 32
bNumInterfaces: 1
bConfigurationValue: 1
iConfiguration: 0
bmAttributes: a0h
MaxPower: 50
bInterfaceNumber: 0
bAlternateSetting: 0
bNumEndpoints: 2
bInterfaceClass: 255
bInterfaceSubClass: 255
bInterfaceProtocol: 255
iInterface: 0
bEndpointAddress: 04h
bmAttributes: 02h
wMaxPacketSize: 64
bInterval: 4
bRefresh: 0
bSynchAddress: 0
bEndpointAddress: 84h
bmAttributes: 02h
wMaxPacketSize: 64
bInterval: 4
bRefresh: 0
bSynchAddress: 0

As Xiaofan says: re Java problems
This is not a libusb-win32 problem but your JAVA USB wrapper problem.
The test program for libusb-win32 is testlibusb-win.exe. Is that working?

If that is working, you have to contact the author of the JAVA wrapper.

___________________________________________________
smartcardsource
easymifare (v1) - mifare / desfire read / write utility for only (!) $400
___________________________________________________



from 2006
Although the Universal Serial Bus (USB) is an integral part of many computers, Java does not officially support USB. Getting your Java programs to interact with arbitrary USB devices thus requires either a third-party Java/USB API or your own Java/USB API. This article introduces two third-party APIs and my own API, which provides a partial USB interaction.
today.java
___________________________________________________
mcuee
Xiaofan's Blog

Blog on IT and Electronics and more, especially Linux and microcontroller related issues
-points to
sourceforge
____________________________________________________

proxmark
a famous reader



_____________________________________________________________

An Introduction to Near-Field Communication and the Contactless Communication API
2008 low level API?
javax.microedition.contactless

sun

27 September 2010

libusb, favicon

Snapper Feeder does not show as a PC/SC Readers ( javax.smartcardio.Card;)Wth "mysnapper" drivers
windows\system32\drivers\libusb0.sys
system3libusb0.dll
are installed

I obtained
Java libusb/libusb-win32 wrapper
sourceforge
and tried to build UsbView
but sadly:
..\UsbView.java:177: fireTreeStructureChanged(ch.ntb.usb.Usb_Bus) has protected access in ch.ntb.usb.usbView.UsbTreeModel
treeModel.fireTreeStructureChanged(bus);
sourceforge forum
- this looks like it is nothing to do with USB!
hopefully I will get a bitter reply on sourceforge telling me the obvious thing I havent done
- more likely a bitter reply telling me a) its the wrong forum b) this was answered years ago, zombie etc etc
- but seriously folks, forums are great - couldnt live without them

I got something called ReadWrite.java
from
* Java libusb wrapper
* Copyright (c) 2005-2006 Andreas Schläpfer
*


which gave a run error of
java.lang.UnsatisfiedLinkError: no LibusbJava in java.library.path
which looks much more amenable to fixing
I found a LibusbJava.dll which I put in the path, but that didnt work .... way to easy, simple and obvious to act in a Jaa World!
actually the guys here at work, who have the answers, are away for a while, so I guess I'll just have to wait to eat humble pie upon their return



___________________________________________________
Snapper cards now do Taxis in Wgtn scoop
___________________________________________________
Tried to put gold contacts as my favicon, with very minimal success
blogspot old template was so grand!
(eg the "preview" now does not look like the post...


20 September 2010

HDMI Key, Utils

Master HDCP Key Cracked
From Bruce

The master key for the High-Bandwidth Digital Content Protection standard -- that's what encrypts digital television between set-top boxes and digital televisions -- has been cracked and published. (Intel confirmed that the key is real.) The ramifications are unclear:

    But even if the code is real, it might not immediately foster piracy as the cracking of CSS on DVDs did more than a decade ago. Unlike CSS, which could be implemented in software, HDCP requires custom hardware. The threat model for Hollywood, then, isn't that a hacker could use the master key to generate a DeCSS-like program for HD, but that shady hardware makers, perhaps in China, might eventually create and sell black-market HDCP cards that would allow the free copying of protected high-def content.
schneier

A comment there:
We generally refer to this as security theater. The cryptographic security has been illusory all along.
...
________________________________________________________
/**  Some utils
 *~
 * @author chris.skinner  July 2010
 */
package nz.here.there.everywhere;

import java.security.Provider;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;


public class SomeCipher {
  public  static String serrcode ( int err) {
    String s = "?";
    String se = Integer.toHexString(err);
        for (String ss : errs){
          if(ss.contains(se)) {
            s = ss;
            break;
          }
        }
    se = Integer.toHexString(err).toUpperCase();

        for ( String st : errs){
          if(st.contains(se)) {
            s = st;
            break;
          }
        }
      return s;
  }//================

public static long by2long (byte[] b) {
    //java.lang.Byte wrapper provides longValue(),
    long value = 0;
    for (byte byt:b)
       value = (value << 8) + (byt & 0xff);
 return value;
}
public static byte[] longtohex( long g) { // long to byte array nb only 4 bytes
    // java long is 8 bytes, but our maths is 4 bytes only...
    byte[] bout = new byte[4];
    for (int j = 3 ; j >= 0; j--){
            bout[j] = (byte)(  g & 0x00000000000000FFL);
            g = g >> 8;
    }
    return bout;
}
public static byte[] inc(byte[] val){   // add 1 to a byte array
    return longtohex(by2long(val)+1);

}

public static byte[] sub (byte[] ba, byte[] bb){   // ba = ba - bb
    return (longtohex(by2long(ba) - by2long(bb)));

}
public static byte[] add ( byte[] bb, byte[] bc){   // ba = bb + bc
    return (longtohex(by2long(bb) + by2long(bc)));
}

public static String by2String (byte b) {
    String s = "";  // seems to need this for static include...
    s =  String.format("%02X", b);
    return s;
}

public static byte[] pad(byte[] plain)  {  // pad but NOT if 0 mod 8
        byte[] padded = null;
        int z = plain.length;
        int x = (z & 0x0007) ;
        try
        {
            if ((x) != 0)
            {
                x = 8 - x;
                padded = new byte[z+x];
         //       java.util.Arrays.fill (padded, 0, z, (byte)0x77);  // z not really "to" index but +1
                padded[z] = (byte)0x80;
                System.arraycopy(plain,          0, padded, 0,     z);
                java.util.Arrays.fill (padded, z+1,    z+x, (byte)0x00);  // done by default 00
                return (padded);
            }
            else
            {
                return plain;
            }
        }
        catch (Exception ex)
        {
                System.out.println("pad error  " + ex.getMessage() ) ;
                return plain;

        }  // catch
    }// pad   KSCC maybe

public static byte[] padm(byte[] plain)  {   // for gp authentication, always add 1 80
        byte[] padded = null;
        int z = plain.length + 1 ;
        int x = (z & 0x0007) ;
        if (x != 0)
            x = 8 -x;
//        System.out.println("\n plain.length " + plain.length +  " x " + x ) ;
        padded = new byte[z + x];
        padded[z-1] = (byte)0x80;
        try {
                System.arraycopy(plain,          0, padded, 0,     z-1);
                java.util.Arrays.fill (padded, z+1,    z+x, (byte)0x00);  // done by default 00
                return (padded);
            }
        catch (Exception ex)
        {
                System.out.println("pad error  " + ex.getMessage() ) ;
        }  // catch
    return (padded);
}// pad at least 1 GP


public static byte[] appendt (  List<byte[]> pb) {  //new append method  with pad
    byte[] bout = append(  pb);
    return pad(bout);
}
public static byte[] append (  List<byte[]> pb) {  //new append method  without pad
// actually a concatente, not append...
    int sz = 0;
    for (byte[] bd : pb) {
        sz+= bd.length; }
    byte[] bout = new byte[sz];
    sz = 0;
    for (byte[] bc:pb) {
        System.arraycopy(bc,     0,    bout, sz,           bc.length);
        sz+= bc.length;
    }
    return bout;
    }



    public static SecretKey makey16( byte[]   b, Provider prov)  {    // CARE input MUST be the final 16 bytes of ciphertext
        byte[] raw = new byte[16];
        SecretKey s = null;
           if (b.length < 16)       {
            System.out.println(" key bytes too short for factory");
            System.exit(79);  //formalise these...throw exception???
        }
        System.arraycopy(b, b.length-16, raw,      0, 16);
        s = makey(raw,prov);
        return s;
    }  //makey16

    public static SecretKey makey( byte[]   b, Provider prov)  {  
    // make a 24 byte DESede key from 16 bytes
    SecretKey s = null;
    byte[] b24 = new byte[24];
    try    {
           if (b.length < 16)       {
                System.out.println(" key bytes too short for factory");
            System.exit(77);  //formalise these...throw exception???
        }
        else        {
            System.arraycopy(b, 0, b24,      0, 16);      // replicate the first 8 to the last 8
            System.arraycopy(b, 0, b24,     16,  8);
            DESedeKeySpec    desEdeKeySpec = new DESedeKeySpec(b24);
            SecretKeyFactory desEdeKeyFact = SecretKeyFactory.getInstance("DESede",prov);
            s =  desEdeKeyFact.generateSecret(desEdeKeySpec);
//            byte[] rawkey = desEdeKeySpec.getKey();  // get the raw bytes back...
//            System.out.print ("\n  isparity adjusted      " + desEdeKeySpec.isParityAdjusted(rawkey, 0)) ;
        }
    }
    catch (NullPointerException npe) {
        System.out.println(" key bytes null");
        System.exit(78);  //formalise these...???

    }
    catch (Exception ex)    {
        System.exit(77);  //formalise these...
        ex.printStackTrace();
    }
    return (s);
} // makey\\

    public static String  Hex2String(byte[] b) {  // convert array of bytes to string
        String result="";
        for (byte by:b)
            result+= String.format("%02X", by);
        return result;
}
    public static String  Hex2String(byte[] b, int size) {
        if (size > b.length)
            return Hex2String(b);
        byte[] bin = new byte[size];
        System.arraycopy(b,0,bin,0,size);
        String result="";
        for (byte by:bin)
            result+= String.format("%02X", by);
        return result;
}
    public static String stripGarbage(String s) {
    String good =
      "ABCDEF0123456789";
    String result = "";
    for ( int i = 0; i < s.length(); i++ ) {
        if ( good.indexOf(s.charAt(i)) >= 0 )
           result += s.charAt(i);  //stringbuilder might be better
        }
    return result;
    }//______________________________________________

    public static byte[] String2Hex(String sin){
        sin = sin.toUpperCase();
        sin = stripGarbage(sin);
        byte[] bout = new byte[sin.length() / 2];  // sz must be even...
        if ((sin.length() & 1) != 0)
            return bout;
        try {
            for (int j = 0; j < sin.length()-1; j+=2) {
                bout[j/2] = (byte)(Integer.parseInt(sin.substring(j,j+2),16));
            } // for
        } // try
        catch (Exception ex) {
            print(" String2Hex " + ex.getMessage() );
        }
        return bout;
    }//_______________________
public static void print (String s) {  // one stop stop print
    System.out.print(s);
    }//_____________________

  static List<String> errs = Arrays.asList(  // there are lots more
              //"0x9000       SW_NO_ERROR",                       //  ,  //response status : No Error   ,
            "0x6100       SW_BYTES_REMAINING_00",             // ,
            "0x6700       SW_WRONG_LENGTH",                   // ,
            "0x6982       SW_SECURITY_STATUS_NOT_SATISFIED",  // ,  new 9171
            "0x6983       SW_FILE_INVALID",                   // ,
            "0x6984       SW_DATA_INVALID",                   // ,
            "0x6985       SW_CONDITIONS_NOT_SATISFIED",       // ,
            "0x6986       SW_COMMAND_NOT_ALLOWED",            //     ,//no current EF) = // 0x6986
            "0x6999       SW_APPLET_SELECT_FAILED",           // ,
            "0x6A80       SW_WRONG_DATA",                     // ,
            "0x6A81       SW_FUNC_NOT_SUPPORTED",             // ,
            "0x6A82       SW_FILE_NOT_FOUND",                 // ,
            "0x6A83       SW_RECORD_NOT_FOUND",               // ,
            "0x6A86       SW_INCORRECT_P1P2",                 //  ,// Incorrect parameters (P1,P2)
            "0x6B00       SW_WRONG_P1P2",                     // ,
            "0x6C00       SW_CORRECT_LENGTH_00",              //  ,//   Correct Expected Length (Le)
            "0x6D00       SW_INS_NOT_SUPPORTED",              //  ,//  INS value not supported
            "0x6E00       SW_CLA_NOT_SUPPORTED",              //  ,//  CLA value not supported  CLASS
            "0x6F00       SW_UNKNOWN",                        //  ,//  No precise diagnosis
            "0x6A84       SW_FILE_FULL",                     // //  Not enough memory space in the file
            "9172         TC cert fail new   ",          //
            );    

} //Classssssssssssssssssssssssssssssssss
_____________________________________________________________________

Some acronyms Acronyms defined:
FICAM–Federal Identity, Credential, and Access Management
NSTIC–National Strategy for Trusted Identities in Cyberspace
NHIN–Nationwide Health Information Network
TWIC–Transportation Worker Identification Credential
smartcardalliance
_____________________________
Sad Java
How sad that Java failed to conquer the internet, and that Adobe rules

Shocking example of Java decrepitude:
Serial ports are not supported

it is possible to find an ancient (c) 1998 copy of javax.comm

In typiclalJava fashion, installation is a Bitch. Even after you have set classpath (does Flash ever ask this?)
you see this:

Several serial port sample applications are provided with this release. One of them is BlackBox. To run BlackBox, first add BlackBox.jar to your classpath:

C:\>set CLASSPATH=c:\commapi\samples\Blackbox\BlackBox.jar;%CLASSPATH%

Now you can run BlackBox:
BUT YOU CANNOT

+java BlackBox
Exception in thread "main" java.lang.NoClassDefFoundError: javax/comm/CommPort
Caused by: java.lang.ClassNotFoundException: javax.comm.CommPort
        at java.net.URLClassLoader$1.run(Unknown Source)
       
        etc etc
So either we have to do some more absurd tinkering with classpath
OR the code does not vin fact hava a CommPort class
- the vast majority of the Human race has by now switched off....

I am stunned Years ago, last time I used serial ports, they were a couple of lines in BASIC
ps:
SerialPortDisplay[]  is not found in javax.comm so their very first Demo doesnt run OR compile...


       
      

15 September 2010

Snapper Feeder, SCARD_W_RESET_CARD, Driver annoyance,

Snapper Feeder (Wellington NZ) is still regarded as the smallest/cheapest USB reader
highly regarded by hackers worldwide.
now NZD$40. there are only 5000 left , they dont make them any more...
snapper
qwandor
youtube
aaa
________________________________________________________________

.. Nephsystem ...new 13.56 MHz contactles reader/writer, .. one of the smallest ..15 grams, the N330 also features wireless communication capabilities via Bluetooth, USB interface and is compatible with all the 13.56MHz protocols, including ISO 15693, I-code SLI, ISO 18000-3, ISO 14443A/B/C, Mifare, Ultralight, INSIDE PicoTag, Sony Felica, KSW VarioSens..

prlog
_________________________________________________________


Also, at 7g in the SD Slot::
prlog

NephSystem N360 SDIO interfaced 13.56MHz RFID reader/writer is an Plug&Play Secure-Digital RFID Reader/Writer that combines the contactless 13.56MHz High Frequency RFID technology with the Secure-Digital (SD slot)aaa

_________________________________________________________
Irritants:
SCARD_W_RESET_CARD error message.
Some say this is a Windows bug
Seems I have to trap this error and reconnect to the readers (Wired, not CL)
every time this happens, which is often. Possibly Netbeans multiple tasks?
Trust this doesnt happen in the real world!

____________________________________
Windows & persistant annoying "Can't load Driver" messages:
These refer to the Card, not the Reader
Remedy:
run gpedit.msc

1. Click Start, type gpedit.msc in the Search programs and files box, and then press ENTER.
2. In the console tree under Computer Configuration, click Administrative Templates.
3. In the details pane, double-click Windows Components, and then double-click Smart Card.
4. Right-click Turn on Smart Card Plug and Play service, and then click Edit.
5. Click Disabled, and then click OK.
________________________________

08 September 2010

Java Card bits, ePassporte

Java Cards the wheel turns:
each generation of devices looks like an ancient form. ie restricted memory etc
On our Java Card, we are packing data into bit arrays, NOT on byte boundaries
ie Bits into Byte Arrays


     static long extractbits (int a, int b, byte[] bin) {      // a = start bit, b = last bit(zero based)
      // extract bits from a byte array
      int byta = a >> 3; // 1st byte
      int bytb = b >> 3; // last byte
           int bytz = bytb -byta + 1; // number of bytes
        byte[] block = new byte[bytz];
        System.arraycopy(bin, byta, block,0, bytz);
        int p = 8 - (a & 7); // # of bits in mask
        block[0] = (byte) (block[0] & ((1<<p) - 1));


        return ((by2long (block)) >> (7 - (b & 7)));
    }//_________________________________________________________________________

...........................

     static byte[] insertbits (int a, int b, long g, byte[] bin) {
        //inset bits from a long into a byte array a=startbit b=lastbit zero based
        byte[] bout = new byte[bin.length];
        // how many bytes does the long require // care we assume 1..4 not 0..8
        int byta = a >> 3; // 1st byte we are altering
        int bytb = b >> 3; // last byte we are altering
        int bytz = bytb -byta + 1; // number of bytes we are working on
        System.arraycopy(bin,0,bout,0,bin.length); // make a copy
        g = g << (7 - (b&7)); // shift g left acording to b      
        byte[] b4 = longtohex(g); // 4 bytes max.. maximum is FF FF FF FF FF ???         // OR b4 onto bout... this assumes bout target area is zeros , else we need a prior NAND     
        int k = 3; // OR bytes 3..2..1..0 ..actually only 2???0     
        byte bc;
        for (int j=bytb ; j>= byta ; j--) {
            bc = b4[k--]; //why is bc needed???
            bout[j] = (byte)(bout[j] | bc);
            // ie bout[j] = (byte)(bout[j] | b4[k--]); does NOT work
        }
        return bout;
     }//_________________________


     public static long by2long (byte[] b) {
        //java.lang.Byte wrapper provides longValue(),
        long value = 0;
        for (byte byt:b)
             value = (value << 8) + (byt & 0xff);     
        return value;      }
//_________________________________________   
    public static byte[] longtohex( long g) { // long to byte array nb only 4 bytes         
// java long is 8 bytes, but our maths is 4 bytes only...       
        byte[] bout = new byte[4];    
        for (int j = 3 ; j >= 0; j--){
            bout[j] = (byte)( g & 0x00000000000000FF);
            g = g >> 8;
        }
        return bout;
     }//___________________________________________

News:
ePassporte
From the department of un-reassuring reassurances:

"The ePassporte e-Wallet program continues to be up and running, except funds cannot be transferred between your Visa account and your e-Wallet," Mallick said.
ecommerce

Customers cannot shop online and pay with their virtual debit card. Nor they can transfer their funds on the card back to their wallets. The issue is not just US-wide, it is everywhere in the world. Any user in any country who has a Visa debit card from ePassporte cannot use it and at the moment it is just a piece of plastic.