04.01.2013 Views

DoD Implementation Guide for CAC PIV End-Point - Common ...

DoD Implementation Guide for CAC PIV End-Point - Common ...

DoD Implementation Guide for CAC PIV End-Point - Common ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>DoD</strong> <strong>Implementation</strong> <strong>Guide</strong> <strong>for</strong> <strong>CAC</strong> <strong>PIV</strong> <strong>End</strong>-<strong>Point</strong><br />

* Java (smartcardio) smart card connection/communication setup<br />

*/<br />

public static void smartIoApiEx() throws CardException{<br />

//the AID <strong>for</strong> <strong>PIV</strong> Application<br />

byte[] aid = {(byte)0xA0, 0x00, 0x00, 0x03, 0x08, 0x00, 0x00, 0x10,<br />

0x00};<br />

// Response buffer.<br />

String response;<br />

}<br />

//show the list of available terminals<br />

TerminalFactory factory = TerminalFactory.getDefault();<br />

List terminals = factory.terminals().list();<br />

System.out.println(" ------------------------------" );<br />

System.out.println("Terminals: " + terminals);<br />

//get the first terminal<br />

System.out.println("Obtaining terminal 0");<br />

CardTerminal terminal = terminals.get(0);<br />

//establish a connection with the card<br />

System.out.println(" ------------------------------" );<br />

System.out.println("Connecting to card");<br />

Card card = terminal.connect("T=0");<br />

System.out.println("card: " + card);<br />

CardChannel channel = card.getBasicChannel();<br />

//execute command APDUs to attain CHUID<br />

getChuid(aid, channel);<br />

//disconnect<br />

card.disconnect(false);<br />

return;<br />

/*<br />

* Obtain the CHUID using the <strong>PIV</strong> Interface<br />

*/<br />

private static void getChuid(byte[] cert, CardChannel channel)<br />

throws CardException{<br />

ResponseAPDU res;<br />

int nr = 0;<br />

// select the app<br />

select(channel, cert);<br />

// get the data<br />

res = getData(channel);<br />

//output data (e.g. console, file, etc.)<br />

System.out.println(" ------------------------------" );<br />

System.out.println("CHUID: ");<br />

nr = res.getNr();<br />

try{<br />

System.out.print(toString(res.getBytes(), nr));<br />

}catch(UnsupportedEncodingException e){<br />

System.out.println("Unsupported Encoding Error");<br />

}<br />

35

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!