PC - SC Sample in Smart Card Connector On Chromebook
PC - SC Sample in Smart Card Connector On Chromebook
更多 下一个博客» 创建博客 登录
To continue the list of PC/SC wrappers initiated in 2010 with "PC/SC sample in different languages" I now Follow
present a sample in Smart Card Connector on Chromebook (or Chrome browser).
You should see the "Smart Card Connector" application in your chrome://apps/. Gemalto IDBridge K30, K50,
CT30 and Zero Length Pa...
PC/SC sample in Rust
ATR statistics: TC2 Specific to
T=0
PC/SC sample in Smart Card
Connector on
Chromebook...
macOS Sierra bug:
SCardTransmit() silently
truncat...
If you click on the application icon you should see something like:
► February (4)
► January (6)
► 2016 (49)
► 2015 (51)
► 2014 (61)
► 2013 (38)
► 2012 (27)
► 2011 (46)
► 2010 (55)
Search
Subscribe To
Posts
Comments
Google+ Followers
https://ludovicrousseau.blogspot.jp/2017/03/pcscsampleinsmartcardconnectoron.html 1/6
12/14/2017 Ludovic Rousseau's blog: PC/SC sample in Smart Card Connector on Chromebook
Ludovic Rousseau b…
Follow
Since the "Smart Card Connector" application completely replaces pcsclite and the CCID driver the normal
pcsclite provided by the system must be stopped. See "Troubleshooting Apps under desktop OSes" to know
how to stop pcscd.
Sample application
I created a simple test application for ChromeOS. The application is available from googlesmartcardclient
libraryhelloworld.
You need to fetch a client library google‐smart‐card‐client‐library.js from Google and also jQuery. Just
follow the Building instructions.
My sample application is greatly inspired from the Hello World Chrome application and Example JavaScript
Smart Card Client app. My contribution is (mainly) the last 4 JavaScript functions.
/** @license
* Copyright 2017 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE‐2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Entry point of the Smart Card Client App background script (see
* <https://developer.chrome.com/apps/event_pages>).
*/
/**
* Client title for the connection to the server App.
https://ludovicrousseau.blogspot.jp/2017/03/pcscsampleinsmartcardconnectoron.html 2/6
12/14/2017 Ludovic Rousseau's blog: PC/SC sample in Smart Card Connector on Chromebook
*
* Currently this is only used for the debug logs produced by the server App.
* @const
*/
var CLIENT_TITLE = 'example_js_client_app';
/**
* Context for talking to the Smart Card Connector app for making PC/SC API
* requests.
* @type {GoogleSmartCard.PcscLiteClient.Context}
*/
var apiContext = null;
/**
* Object that allows to make PC/SC API requests to the Smart Card Connector
* app.
* @type {GoogleSmartCard.PcscLiteClient.API}
*/
var api = null;
/**
* PC/SC‐Lite SCard context.
* @type {int}
*/
var sCardContext = null;
function initialize() {
myLog('Establishing connection to the Connector app...');
console.log('Establishing connection to the Connector app...');
apiContext = new GoogleSmartCard.PcscLiteClient.Context(CLIENT_TITLE);
apiContext.addOnInitializedCallback(onInitializationSucceeded);
apiContext.addOnDisposeCallback(contextDisposedListener);
apiContext.initialize();
}
function onInitializationSucceeded(constructedApi) {
myLog('Successfully connected to the Connector app');
console.log('Successfully connected to the Connector app');
api = constructedApi;
establishContext();
}
function establishContext() {
myLog('Establishing PC/SC‐Lite context...');
console.log('Establishing PC/SC‐Lite context...');
api.SCardEstablishContext(
GoogleSmartCard.PcscLiteClient.API.SCARD_SCOPE_SYSTEM, null, null).then(
function(result) {
result.get(onContextEstablished, onPcscLiteError);
}, onRequestFailed);
}
function listReaders() {
myLog('Obtaining list of PC/SC‐lite readers...');
console.log('Obtaining list of PC/SC‐lite readers...');
api.SCardListReaders(sCardContext, null).then(function(result) {
result.get(onReadersListed, onPcscLiteError);
}, onRequestFailed);
}
https://ludovicrousseau.blogspot.jp/2017/03/pcscsampleinsmartcardconnectoron.html 3/6
12/14/2017 Ludovic Rousseau's blog: PC/SC sample in Smart Card Connector on Chromebook
myCode(reader);
}
function contextDisposedListener() {
myLog('Connection to the server app was shut down');
console.warn('Connection to the server app was shut down');
sCardContext = null;
api = null;
apiContext = null;
}
/** @param {*} error The exception that happened during the request. */
function onRequestFailed(error) {
myLog('Failed to perform request to the Smart Card Connector app: ' +
error);
console.warn('Failed to perform request to the Smart Card Connector app: ' +
error);
}
function myLog(text)
{
$("#logs").append($("<li>").text(text));
}
function myCode(readerName)
{
myLog('Connect to the reader: ' + readerName);
api.SCardConnect(sCardContext,
readerName,
API.SCARD_SHARE_SHARED,
API.SCARD_PROTOCOL_ANY).then(function(result) {
result.get(onConnected, onPcscLiteError);
}, onRequestFailed);
}
https://ludovicrousseau.blogspot.jp/2017/03/pcscsampleinsmartcardconnectoron.html 4/6
12/14/2017 Ludovic Rousseau's blog: PC/SC sample in Smart Card Connector on Chromebook
APDU_COMMAND = [0x00, 0x00, 0x00, 0x00];
myLog('Sending ' + dump(APDU_COMMAND));
api.SCardTransmit(
cardHandle,
protocol == API.SCARD_PROTOCOL_T0 ?
API.SCARD_PCI_T0 : API.SCARD_PCI_T1,
APDU_COMMAND).then(function(result) {
result.get(function(ioRecvPci, response) {
myLog('response: ' + dump(response));
function dump(bytes)
{
return (bytes.map(function (x) {
return ('00' + x.toString(16).toUpperCase()).substr(‐2)
})).join(" ");
}
window.onload = initialize;
Remarks
This API is very verbose and low level. You can compare it to the nodepcsclite project API, also in
JavaScript, I used in a previous article "PCSC sample in JavaScript (Node.js)".
The API uses a lot of call back functions. But that is not surprising for a JavaScript code.
Installation
To install the application in Chrome go to chrome://extensions/ and click on the "Load non packaged
extension" button (label translated from French so the real English text may be different) and select the root
directory of the sample application.
You should then see a new "Hello World PC/SC" extension in the list. Click on the "Run" link to start the
extension. A new window should be created as displayed in the Output section bellow.
Output
https://ludovicrousseau.blogspot.jp/2017/03/pcscsampleinsmartcardconnectoron.html 5/6
12/14/2017 Ludovic Rousseau's blog: PC/SC sample in Smart Card Connector on Chromebook
Conclusion
This API is useful mainly/only on Chromebook computers. I guess it is the only smart card interface for this
kind of computer.
If you know a PC/SC wrapper that is not yet in my list then please contact me.
Labels: code
Bitcoin
License: byncsa
This blog by Ludovic Rousseau is licensed under a Creative Commons AttributionNonCommercialShareAlike 3.0 Unported License.
https://ludovicrousseau.blogspot.jp/2017/03/pcscsampleinsmartcardconnectoron.html 6/6