Check-in [c3e0c9025e]
Overview
SHA1:c3e0c9025e3d68182983b150b56d0c1d58d94e1e
Date: 2016-04-14 17:07:11
User: rkeene
Comment:Updated to use NaCl libpcsc (in progress)
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2016-04-14
18:16
[357cf7b22f] Upgraded to latest nacl-libpcsc and started using the sightly cleaner interfaces (user: rkeene, tags: trunk)
17:07
[c3e0c9025e] Updated to use NaCl libpcsc (in progress) (user: rkeene, tags: trunk)
2016-03-15
17:57
[899318c012] Updated to parse X.509v1 implied version certificates (user: rkeene, tags: trunk)
Changes

Modified build/chrome/Makefile from [7468d6c1f8] to [44984e905a].

     3      3   AR       = pnacl-ar
     4      4   RANLIB   = pnacl-ranlib
     5      5   FINALIZE = pnacl-finalize
     6      6   
     7      7   CACKEY_LIBS = -Llib -lcackey -lz
     8      8   PCSC_LIBS   = -Llib -lpcsc -L${NACL_SDK_ROOT}/lib/pnacl/Release -lppapi -lppapi_cpp
     9      9   LIBS        = $(CACKEY_LIBS) $(PCSC_LIBS)
    10         -CFLAGS      = -Wall -I${NACL_SDK_ROOT}/include -I../../pkcs11 -Iinclude/PCSC
           10  +CFLAGS      = -Wall -I${NACL_SDK_ROOT}/include -I../../pkcs11 -Iinclude
    11     11   CXXFLAGS    = $(CFLAGS) -std=gnu++11
    12     12   
    13     13   CACKEY_DEBUG = 0
    14     14   ifeq (1,$(CACKEY_DEBUG))
    15     15   CACKEY_LIBNAME     = libcackey_g
    16     16   CACKEY_EXECUTABLES = cackey.pexe cackey.bc
    17     17   CFLAGS             += -g3 -ggdb3
................................................................................
    68     68   	mkdir -p lib
    69     69   	rm -f lib/libz.a
    70     70   	cd lib && ln -s ../workdir-*.inst/lib/libz.a .
    71     71   	touch lib/libz.a
    72     72   
    73     73   google-pcsc.js: lib/libcackey.a
    74     74   	rm -f google-pcsc.js google-pcsc.js.new
    75         -	cat workdir-*.inst/js/scope.js > google-pcsc.js.new
    76         -	echo 'GoogleSmartCard.IS_DEBUG_BUILD = $(CACKEY_DEBUG);' >> google-pcsc.js.new
    77         -	cat workdir-*.inst/js/{logging,pcsc,pcsc-nacl}.js >> google-pcsc.js.new
           75  +	cat workdir-*.inst/js/libpcsc.js > google-pcsc.js.new
    78     76   	mv google-pcsc.js.new google-pcsc.js
    79     77   
    80         -include/PCSC/pcsc-nacl.h: lib/libcackey.a
    81         -	mkdir -p include/PCSC
    82         -	rm -f include/PCSC/pcsc-nacl.h.new include/PCSC/pcsc-nacl.h
    83         -	cd include/PCSC && ln -s ../../workdir-*.inst/include/PCSC/pcsc-nacl.h pcsc-nacl.h.new
    84         -	touch include/PCSC/pcsc-nacl.h.new
    85         -	mv include/PCSC/pcsc-nacl.h.new include/PCSC/pcsc-nacl.h
           78  +include/libpcsc.h: lib/libcackey.a
           79  +	mkdir -p include
           80  +	rm -f include/libpcsc.h.new include/libpcsc.h
           81  +	cd include && ln -s ../workdir-*.inst/include/libpcsc.h libpcsc.h.new
           82  +	touch include/libpcsc.h.new
           83  +	mv include/libpcsc.h.new include/libpcsc.h
    86     84   
    87     85   manifest.json: manifest.json.in ../../configure.ac
    88     86   	rm -f manifest.json.new
    89     87   	sed 's/@PACKAGE_VERSION@/$(shell sed '/^AC_INIT/ {s@.*, @@;s@[^0-9\.].@@g;p};d' ../../configure.ac)/g' manifest.json.in > manifest.json.new
    90     88   	mv manifest.json.new manifest.json
    91     89   
    92     90   jsrsasign.js:
................................................................................
    94     92   	test "`openssl sha256 jsrsasign.js.new | sed 's@.*= *@@'`" = '99b041bccc846f03623ce52f5932bd3ff282a064e7077a4ad1c600fc70c1176b'
    95     93   	mv jsrsasign.js.new jsrsasign.js
    96     94   
    97     95   test: cackey-chrome-pkcs11.c cackey-chrome-test.c ../../cackey.c Makefile
    98     96   	gcc -g3 -ggdb3 -Wall -I. -I../../pkcs11 -I/opt/appfs/core.appfs.rkeene.org/zlib/platform/latest/include -I/opt/appfs/rkeene.org/pcsc-lite/platform/latest/include/PCSC -DHAVE_WINTYPES_H=1 -DHAVE_PCSCLITE_H=1 -DHAVE_WINSCARD_H=1 -DHAVE_STDINT_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDLIB_H=1 -DHAVE_UNISTD_H=1 -DHAVE_STRING_H=1 -DHAVE_PTHREAD_H=1 -DHAVE_LIMITS_H=1 -DHAVE_STDIO_H=1 -DHAVE_ZLIB_H -DHAVE_LIBZ -DCACKEY_DEBUG=1 -o test cackey-chrome-pkcs11.c cackey-chrome-test.c ../../cackey.c -L/opt/appfs/core.appfs.rkeene.org/zlib/platform/latest/lib -lz -L/opt/appfs/rkeene.org/pcsc-lite/platform/latest/lib -lpcsclite -L/opt/appfs/core.appfs.rkeene.org/glibc/platform/latest/lib -lc -lpthread -Wl,-R,/opt/appfs/core.appfs.rkeene.org/zlib/platform/latest/lib -Wl,-R,/opt/appfs/rkeene.org/pcsc-lite/platform/latest/lib -Wl,-R,/opt/appfs/core.appfs.rkeene.org/glibc/platform/latest/lib -Wl,-dynamic-linker,/opt/appfs/core.appfs.rkeene.org/glibc/platform/latest/lib/ld-linux-x86-64.so.2
    99     97   
   100     98   cackey-chrome-pkcs11.o: cackey-chrome-pkcs11.c cackey-chrome.h
   101         -cackey-chrome-plugin.o: cackey-chrome-plugin.cc cackey-chrome.h include/PCSC/pcsc-nacl.h
           99  +cackey-chrome-plugin.o: cackey-chrome-plugin.cc cackey-chrome.h include/libpcsc.h
   102    100   
   103    101   clean:
   104    102   	rm -f cackey-chrome-pkcs11.o cackey-chrome-plugin.o
   105    103   	rm -f cackey.pexe cackey.bc
   106    104   	rm -f cackey.zip cackey.nmf
   107    105   	rm -f manifest.json manifest.json.new
   108    106   	rm -f test
   109    107   
   110    108   distclean: clean
   111    109   	rm -f lib/libcackey.a lib/libpcsc.a lib/libz.a
   112    110   	-rmdir lib
   113         -	rm -f include/PCSC/pcsc-nacl.h
          111  +	rm -f include/libpcsc.h
   114    112   	-rmdir include/PCSC
   115    113   	-rmdir include
   116    114   	rm -f google-pcsc.js
   117    115   	rm -rf workdir-*
   118    116   	rm -f jsrsasign.js jsrsasign.js.new
   119    117   
   120    118   .PHONY: all clean distclean

Modified build/chrome/build-deps from [dd6eb9c6ce] to [faff128b75].

    71     71   	rm -f "${file}.new"
    72     72   	wget --header "X-Cache-URL: ${url}" -O "${file}.new" "http://hashcache.rkeene.org/${hashMethod}/${hash}" || \
    73     73   		wget -O "${file}.new" "${url}" || \
    74     74   		return 1
    75     75   
    76     76   	chkHash="$(openssl "${hashMethod}" "${file}.new" | sed 's@.*= *@@')"
    77     77   
    78         -	if [ "${chkHash}" != "${hash}" ]; then
           78  +	if [ "${chkHash}" != "${hash}" -a "${hash}" != '-' ]; then
    79     79   		echo "error: Checksum mismatch: Got: ${chkHash}; Expected: ${hash}" >&2
    80     80   
    81     81   		return 1
    82     82   	fi
    83     83   
    84     84   	mv "${file}.new" "${file}"
    85     85   
................................................................................
   166    166   	) || return 1
   167    167   
   168    168   	rm -rf "${workdir}"
   169    169   
   170    170   	return 0
   171    171   }
   172    172   
   173         -# Build "boost"
   174         -function buildBoost() {
          173  +# Build the libpcsc we need
          174  +function buildPCSC() {
   175    175   	local version url pkg sha256 configure_extra
   176    176   	local archive workdir
   177    177   
   178         -	pkg='boost'
   179         -	version='1.57.0'
   180         -	url="http://downloads.sourceforge.net/project/boost/boost/${version}/boost_`echo ${version} | sed 's_\._\__g'`.tar.bz2"
   181         -	sha256='910c8c022a33ccec7f088bd65d4f14b466588dda94ba2124e78b8c57db264967'
          178  +	pkg='nacl-libpcsc'
          179  +	version='179983e00b5ed8a8fead5d2f9bb35f5304716041'
          180  +	url="https://chiselapp.com/user/rkeene/repository/nacl-libpcsc/tarball/nacl-libpcsc-${version}.tar.gz?uuid=${version}"
          181  +	sha256='-'
   182    182   
   183         -	archive="archive/${pkg}-${version}.tar.bz2"
          183  +	archive="archive/${pkg}-${version}.tar.gz"
   184    184   	workdir="workdir-${RANDOM}${RANDOM}${RANDOM}${RANDOM}.build"
   185    185   
   186    186   	download "${url}" "${archive}" "${sha256}" || return 1
   187    187   	extract "${archive}" "${workdir}" || return 1
   188    188   
   189    189   	(
   190    190   		cd "${workdir}" || exit 1
   191    191   
   192         -		./bootstrap.sh --prefix="${instdir}" --with-python=false --show-libraries
   193         -
   194         -		./bootstrap.sh --prefix="${instdir}" --with-python=false --without-libraries='atomic,chrono,container,context,coroutine,date_time,exception,filesystem,graph,graph_parallel,iostreams,locale,log,math,mpi,program_options,python,random,regex,serialization,signals,system,test,thread,timer,wave' || exit 1
   195         -
   196         -		echo "using gcc : pnacl : ${CXX} ;" >> project-config.jam
   197         -
   198         -		./b2 --debug-configuration toolset=gcc-pnacl target-os=linux link=static runtime-link=static || exit 1
   199         -
   200         -		./bjam install | grep -v '^common.copy '
   201         -
   202         -		exit 0
          192  +		if [ ! -d pcsc/src ]; then
          193  +			./build/assemble-source-from-google.sh || exit 1
          194  +		fi
   203    195   	) || return 1
   204    196   
   205         -	rm -rf "${workdir}"
   206         -
   207         -	return 0
   208         -}
   209         -
   210         -# Build the libpcsc we need
   211         -function buildPCSC() {
   212         -	local version url pkg sha256 configure_extra
   213         -	local archive workdir
   214         -
   215         -	buildBoost || return 1
   216         -
   217         -	pkg='smart-card-client-c-example-app-sources'
   218         -	version='0.0.0'
   219         -	sha256='68970c6dc4b55d24a453bcfe5768af2b877f553a92a390be7f935db6223d4bc5'
   220         -
   221         -	archive="archive/${pkg}.zip"
   222         -	workdir="workdir-${RANDOM}${RANDOM}${RANDOM}${RANDOM}.build"
   223         -
   224         -	extract "${archive}" "${workdir}" || return 1
   225         -
   226         -	(
   227         -		cd "${workdir}" || exit 1
   228         -
   229         -		# Copy out PC/SC headers for later use
   230         -		mkdir -p "${instdir}/include/PCSC" || exit 1
   231         -		cp third_party/pcsc-lite/src/src/PCSC/*.h "${instdir}/include/PCSC" || exit 1
   232         -
   233         -		# Copy out extra headers
   234         -		cat << \_EOF_ > "${instdir}/include/PCSC/pcsc-nacl.h"
   235         -#ifndef PCSC_NACL_H
   236         -#define PCSC_NACL_H 1
   237         -#ifdef __cplusplus
   238         -#include <ppapi/cpp/core.h>
   239         -#include <ppapi/cpp/instance.h>
   240         -
   241         -void pcscNaClInit(pp::Instance *instance, pp::Core *core, const char *smartcardManagerAppId, const char *clientId);
   242         -bool pcscNaClHandleMessage(const pp::Var &message);
   243         -
   244         -#endif
   245         -#endif
   246         -_EOF_
   247         -
   248         -		# Copy out JavaScript files for later use
   249         -		mkdir "${instdir}/js" || exit 1
   250         -		cp common-utils/*.js "${instdir}/js" || exit 1
   251         -		cp third_party/pcsc-lite/client-side/*.js "${instdir}/js" || exit 1
   252         -
   253         -		# Build libpcsc
   254         -		## Assemble all the files into a single tree
   255         -		for file in logging.h scard_structs_serialization.h dom_requests_manager.h thread_safe_string_pool.h \
   256         -		    pp_var_utils.cc pp_var_utils.h scard_structs_serialization.cc dom_requests_manager.cc logging.cc; do
   257         -			find . -type f -name "${file}" -exec cp '{}' third_party/pcsc-lite/client-side/ ';'
   258         -		done
   259         -
   260         -		## Create Makefile
   261         -		cat << \_EOF_ > third_party/pcsc-lite/client-side/Makefile || exit 1
   262         -CFLAGS   += -Wall -std=gnu++11 -g3 -ggdb3
   263         -CXXFLAGS += -Wall -std=gnu++11 -g3 -ggdb3
   264         -CPPFLAGS += -I../src/src/PCSC
   265         -
   266         -OBJS = pcsc_nacl.o pcsc_nacl_global.o scard_structs_serialization.o pp_var_utils.o logging.o dom_requests_manager.o pcsc_nacl_init.o
   267         -
   268         -all: libpcsc.a
   269         -
   270         -libpcsc.a: $(OBJS)
   271         -	rm -f libpcsc.a
   272         -	$(AR) rc libpcsc.a $(OBJS)
   273         -	-$(RANLIB) libpcsc.a
   274         -
   275         -pcsc_nacl_init.o: pcsc_nacl_init.cc pcsc_nacl_global.h dom_requests_manager.h pcsc_nacl.h
   276         -
   277         -pcsc_nacl.o: pcsc_nacl.cc pcsc_nacl.h logging.h pp_var_utils.h scard_structs_serialization.h
   278         -pcsc_nacl.h: dom_requests_manager.h thread_safe_string_pool.h
   279         -
   280         -pcsc_nacl_global.o: pcsc_nacl_global.cc pcsc_nacl_global.h logging.h
   281         -pcsc_nacl_global.h: pcsc_nacl.h
   282         -
   283         -pp_var_utils.o: pp_var_utils.cc pp_var_utils.h logging.h
   284         -pp_var_utils.h: logging.h
   285         -
   286         -scard_structs_serialization.o: scard_structs_serialization.cc scard_structs_serialization.h pp_var_utils.h
   287         -scard_structs_serialization.h: pp_var_utils.h
   288         -
   289         -dom_requests_manager.o: dom_requests_manager.cc dom_requests_manager.h logging.h pp_var_utils.h
   290         -
   291         -logging.o: logging.cc logging.h
   292         -
   293         -clean:
   294         -	rm -f $(OBJS)
   295         -	rm -f libpcsc.a
   296         -
   297         -distclean: clean
   298         -
   299         -.PHONY: all clean distclean
   300         -_EOF_
   301         -
   302         -		## Create initialization procedure, since it lacks one
   303         -		cat << \_EOF_ > third_party/pcsc-lite/client-side/pcsc_nacl_init.cc
   304         -#include <ppapi/cpp/core.h>
   305         -#include <ppapi/cpp/instance.h>
   306         -
   307         -#include <unistd.h>
   308         -
   309         -#include "pcsc_nacl_global.h"
   310         -#include "dom_requests_manager.h"
   311         -#include "pcsc_nacl.h"
   312         -
   313         -static DomRequestsManager *pcscNaClDRM = NULL;
   314         -
   315         -void pcscNaClInit(pp::Instance *instance, pp::Core *core, const char *smartcardManagerAppId, const char *clientId) {
   316         -	DomRequestsManager::PpDelegateImpl *drmDelegateImpl;
   317         -	PcscNacl *pcsc_nacl;
   318         -
   319         -	if (smartcardManagerAppId == NULL) {
   320         -		smartcardManagerAppId = "khpfeaanjngmcnplbdlpegiifgpfgdco";
   321         -	}
   322         -
   323         -	if (clientId == NULL) {
   324         -		clientId = "UNKNOWN";
   325         -	}
   326         -
   327         -	if (pcscNaClDRM == NULL) {
   328         -		drmDelegateImpl = new DomRequestsManager::PpDelegateImpl(instance, core);
   329         -	
   330         -		pcscNaClDRM = new DomRequestsManager("pcsc-nacl", drmDelegateImpl);
   331         -	}
   332         -
   333         -	pcsc_nacl = new PcscNacl(pcscNaClDRM, smartcardManagerAppId, clientId);
   334         -
   335         -	if (!pcsc_nacl->Initialize()) {
   336         -		return;
   337         -	}
   338         -
   339         -	SetPcscNaclGlobalInstance(pcsc_nacl);
   340         -
   341         -	return;
   342         -}
   343         -
   344         -bool pcscNaClHandleMessage(const pp::Var &message) {
   345         -	return(pcscNaClDRM->HandleMessage(message));
   346         -}
   347         -_EOF_
   348         -
   349         -		## Make it
   350         -		make -C third_party/pcsc-lite/client-side || exit 1
   351         -
   352         -		# Install the built libpcsc
   353         -		mkdir -p "${instdir}/lib" || exit 1
   354         -		cp third_party/pcsc-lite/client-side/libpcsc.a "${instdir}/lib" || exit 1
   355         -	) || return 1
          197  +	make -C "${workdir}" prefix="${instdir}" install || return 1
   356    198   
   357    199   	rm -rf "${workdir}"
   358    200   
   359    201   	return 0
   360    202   }
   361    203   
   362    204   # Build our CACKey

Modified build/chrome/cackey-chrome-plugin.cc from [cf6e270a5f] to [06cf85fd98].

    13     13   #include <ppapi/cpp/var_dictionary.h>
    14     14   #include <ppapi/cpp/var_array.h>
    15     15   #include <ppapi/cpp/var_array_buffer.h>
    16     16   
    17     17   #include <string.h>
    18     18   #include <stdlib.h>
    19     19   
    20         -#include "pcsc-nacl.h"
           20  +#include "libpcsc.h"
    21     21   #include "cackey-chrome.h"
    22     22   
    23     23   class CACKeyInstance : public pp::Instance {
    24     24   	private:
    25     25   		pp::Core *corePointer;
    26     26   	public:
    27     27   		explicit CACKeyInstance(PP_Instance instance, pp::Core *core) : pp::Instance(instance) {

Modified build/chrome/cackey.js from [cc6681845c] to [94fd0f8405].

   186    186    *
   187    187    * If an error occured, invoke the callback with no arguments.
   188    188    */
   189    189   function cackeyMessageIncoming(messageEvent) {
   190    190   	var nextFunction = null;
   191    191   	var chromeCallback = null;
   192    192   
          193  +		console.log("START MESSAGE");
          194  +		console.log(messageEvent.data);
          195  +		console.log("END MESSAGE");
   193    196   	if (messageEvent.data.target != "cackey") {
   194    197   		return;
   195    198   	}
   196    199   
   197    200   	if (GoogleSmartCard.IS_DEBUG_BUILD) {
   198    201   		console.log("START MESSAGE");
   199    202   		console.log(messageEvent.data);
................................................................................
   719    722   			"smartcardManagerAppId": "khpfeaanjngmcnplbdlpegiifgpfgdco"
   720    723   		}
   721    724   	);
   722    725   
   723    726   	/*
   724    727   	 * Initialize the PCSC NaCl interface
   725    728   	 */
   726         -	cackeyPCSCHandle = new GoogleSmartCard.PcscNacl(cackeyHandle);
          729  +	new GoogleSmartCard.NaclModule(cackeyHandle);
          730  +	cackeyPCSCHandle = new GoogleSmartCard.PcscLiteClient.NaclClientBackend(cackeyHandle.messageChannel, "CACKey", "khpfeaanjngmcnplbdlpegiifgpfgdco"); 
   727    731   
   728    732   	console.log("[cackey] cackeyInitPCSC() complete");
   729    733   
   730    734   	return;
   731    735   }
   732    736   
   733    737   /*
................................................................................
   812    816   	chrome.app.runtime.onLaunched.addListener(function() {
   813    817   		chrome.app.window.create('ui.html', {
   814    818   			"id": "cackeyUI",
   815    819   			"focused": true,
   816    820   			"innerBounds": {
   817    821   				"width": 350,
   818    822   				"minWidth": 350,
   819         -				"height": 135,
          823  +				"height": 136,
          824  +
   820    825   				"minHeight": 135
   821    826   			}
   822    827   		}, function(uiWindow) {
   823    828   			if (!uiWindow) {
   824    829   				return;
   825    830   			}
   826    831   
   827    832   			uiWindow.contentWindow.parentWindow = window;
   828    833   		});
   829    834   	});
   830    835   
   831         -	/*
   832         -	 * Register a handler for dealing with the PCSC port being disconnected
   833         -	 */
   834         -	oldOnPortDisconnectedFunction = GoogleSmartCard.Pcsc.prototype.onPortDisconnected_;
   835         -	GoogleSmartCard.Pcsc.prototype.onPortDisconnected_ = function() {
   836         -		oldOnPortDisconnectedFunction.apply(this);
   837         -
   838         -		cackeyInitPCSCCompleted("failure");
   839         -
   840         -		cackeyRestart();
   841         -
   842         -		return;
   843         -	};
   844         -
   845         -	/*
   846         -	 * Register a handler for dealing with the PCSC port being available
   847         -	 */
   848         -	oldPCSCInitializationCallback = GoogleSmartCard.PcscNacl.prototype.pcscInitializationCallback_;
   849         -	GoogleSmartCard.PcscNacl.prototype.pcscInitializationCallback_ = function(requestId, instanceId, instance, error) {
   850         -		oldPCSCInitializationCallback.apply(this, [requestId, instanceId, instance, error]);
   851         -
   852         -		return;
   853         -	};
   854         -
          836  +// Google got rid of all of the code we were using to interface with PCSC... 
          837  +// This needs to be rewritten to use the new interface
          838  +//
          839  +//	/*
          840  +//	 * Register a handler for dealing with the PCSC port being disconnected
          841  +//	 */
          842  +//	oldOnPortDisconnectedFunction = GoogleSmartCard.Pcsc.prototype.onPortDisconnected_;
          843  +//	GoogleSmartCard.Pcsc.prototype.onPortDisconnected_ = function() {
          844  +//		oldOnPortDisconnectedFunction.apply(this);
          845  +//
          846  +//		cackeyInitPCSCCompleted("failure");
          847  +//
          848  +//		cackeyRestart();
          849  +//
          850  +//		return;
          851  +//	};
          852  +//
          853  +//	/*
          854  +//	 * Register a handler for dealing with the PCSC port being available
          855  +//	 */
          856  +//	oldPCSCInitializationCallback = GoogleSmartCard.PcscNacl.prototype.pcscInitializationCallback_;
          857  +//	GoogleSmartCard.PcscNacl.prototype.pcscInitializationCallback_ = function(requestId, instanceId, instance, error) {
          858  +//		oldPCSCInitializationCallback.apply(this, [requestId, instanceId, instance, error]);
          859  +//
          860  +//		return;
          861  +//	};
          862  +//
   855    863   	/*
   856    864   	 * Initialize global state
   857    865   	 */
   858    866   	cackeyInitGlobalState();
   859    867   
   860    868   	return;
   861    869   }
   862    870   
   863    871   /* Initialize CACKey */
   864    872   cackeyAppInit();
   865    873   cackeyInit();