Comment: | Merged in trunk |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | require-login-if-needed |
Files: | files | file ages | folders |
SHA1: | 6938f7a82c23de8466800def37c72892bd70d981 |
User & Date: | rkeene on 2015-05-04 16:02:33 |
Other Links: | manifest | tags |
2015-07-15
| ||
20:10 | Merged in trunk Leaf check-in: 38771da1e8 user: rkeene tags: require-login-if-needed | |
2015-05-04
| ||
16:02 | Merged in trunk check-in: 6938f7a82c user: rkeene tags: require-login-if-needed | |
2015-03-22
| ||
06:25 | Updated with latest set of DoD and Federal certs check-in: 133c2dbd45 user: rkeene tags: trunk | |
2012-07-24
| ||
15:55 | Added basic stub for adding support for checking if LOGIN_REQUIRED is needed check-in: 6db637b204 user: rkeene tags: require-login-if-needed | |
Modified asn1-x509.c from [e21185aa9d] to [f9aa197383].
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
...
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
}
static int asn1_x509_read_object(unsigned char *buf, size_t buflen, struct x509_object *outbuf) {
int read_ret;
read_ret = asn1_x509_read_asn1_object(buf, buflen, &outbuf->wholething, NULL);
if (read_ret != 0) {
return(-1);
}
read_ret = asn1_x509_read_asn1_object(outbuf->wholething.contents, outbuf->wholething.size, &outbuf->certificate, NULL);
if (read_ret != 0) {
return(-1);
}
read_ret = asn1_x509_read_asn1_object(outbuf->certificate.contents, outbuf->certificate.size, &outbuf->version, &outbuf->serial_number, &outbuf->signature_algo, &outbuf->issuer, &outbuf->validity, &outbuf->subject, &outbuf->pubkeyinfo, NULL);
if (read_ret != 0) {
return(-1);
}
read_ret = asn1_x509_read_asn1_object(outbuf->pubkeyinfo.contents, outbuf->pubkeyinfo.size, &outbuf->pubkey_algoid, &outbuf->pubkey, NULL);
if (read_ret != 0) {
return(-1);
}
return(0);
}
ssize_t x509_to_issuer(void *x509_der_buf, size_t x509_der_buf_len, void **outbuf) {
................................................................................
static ssize_t x509_to_serial(void *x509_der_buf, size_t x509_der_buf_len, void **outbuf) {
struct x509_object x509;
int read_ret;
read_ret = asn1_x509_read_object(x509_der_buf, x509_der_buf_len, &x509);
if (read_ret != 0) {
return(-1);
}
if (outbuf) {
*outbuf = x509.serial_number.asn1rep;
}
|
>
>
>
>
>
>
>
>
>
>
>
|
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
...
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
} static int asn1_x509_read_object(unsigned char *buf, size_t buflen, struct x509_object *outbuf) { int read_ret; read_ret = asn1_x509_read_asn1_object(buf, buflen, &outbuf->wholething, NULL); if (read_ret != 0) { CACKEY_DEBUG_PRINTF("Failed at reading the contents from the wrapper") return(-1); } read_ret = asn1_x509_read_asn1_object(outbuf->wholething.contents, outbuf->wholething.size, &outbuf->certificate, NULL); if (read_ret != 0) { CACKEY_DEBUG_PRINTF("Failed at reading the certificate from the contents"); return(-1); } read_ret = asn1_x509_read_asn1_object(outbuf->certificate.contents, outbuf->certificate.size, &outbuf->version, &outbuf->serial_number, &outbuf->signature_algo, &outbuf->issuer, &outbuf->validity, &outbuf->subject, &outbuf->pubkeyinfo, NULL); if (read_ret != 0) { CACKEY_DEBUG_PRINTF("Failed at reading the certificate components from the certificate"); return(-1); } read_ret = asn1_x509_read_asn1_object(outbuf->pubkeyinfo.contents, outbuf->pubkeyinfo.size, &outbuf->pubkey_algoid, &outbuf->pubkey, NULL); if (read_ret != 0) { CACKEY_DEBUG_PRINTF("Failed at reading the public key from the certificate components"); return(-1); } return(0); } ssize_t x509_to_issuer(void *x509_der_buf, size_t x509_der_buf_len, void **outbuf) { ................................................................................ static ssize_t x509_to_serial(void *x509_der_buf, size_t x509_der_buf_len, void **outbuf) { struct x509_object x509; int read_ret; read_ret = asn1_x509_read_object(x509_der_buf, x509_der_buf_len, &x509); if (read_ret != 0) { CACKEY_DEBUG_PRINTF("Unable to read serial number from a %lu byte buffer", x509_der_buf_len); CACKEY_DEBUG_PRINTBUF("X.509 DER:", x509_der_buf, x509_der_buf_len); return(-1); } if (outbuf) { *outbuf = x509.serial_number.asn1rep; } |
Modified autogen.sh from [c540dfc874] to [daf2ac0fe1].
2 3 4 5 6 7 8 |
rm -f aclocal.m4 ${MAKE:-make} -C aclocal autoconf; autoheader rm -rf autom4te.cache/ |
> > > > > > > > > > > > |
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
rm -f aclocal.m4 ${MAKE:-make} -C aclocal autoconf; autoheader rm -rf autom4te.cache/ for basefile in install-sh config.sub config.guess; do for path in /usr/share/automake-*; do file="${path}/${basefile}" if [ -f "${file}" ]; then cp "${file}" . chmod 755 "./${basefile}" break fi done done |
Modified build/build.sh from [fc56094904] to [48fe009c68].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
#! /bin/sh find . -type f -name '.*.sw?' | xargs rm -f find . -type f -name '.nfs*' | xargs rm -f if [ "${SNAPSHOT}" = "1" ]; then sed "s@\(AC_INIT([^)]*\))@\1.${VERS})@" configure.ac > configure.ac.new cat configure.ac.new > configure.ac rm -f configure.ac.new fi ./autogen.sh || exit 1 if [ ! -x configure ]; then exit 1 fi for basefile in install-sh config.sub config.guess; do for path in /usr/share/automake-*; do file="${path}/${basefile}" if [ -f "${file}" ]; then cp "${file}" . chmod 755 "./${basefile}" break fi done done if [ "${SNAPSHOT}" != "1" ]; then mv build build_delete mkdir build || exit 1 cp -rp build_delete/cackey_win32_build build/ fi exit 0 |
> < < < < < < < < < < < < > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#! /bin/sh find . -type f -name '.*.sw?' | xargs rm -f find . -type f -name '.nfs*' | xargs rm -f find . -type f -name '*~' | xargs rm -f if [ "${SNAPSHOT}" = "1" ]; then sed "s@\(AC_INIT([^)]*\))@\1.${VERS})@" configure.ac > configure.ac.new cat configure.ac.new > configure.ac rm -f configure.ac.new fi ./autogen.sh || exit 1 if [ ! -x configure ]; then exit 1 fi if [ "${SNAPSHOT}" != "1" ]; then mv build build_delete mkdir build || exit 1 cp -rp build_delete/cackey_win32_build build/ cp -rp build_delete/cackey_win64_build build/ fi exit 0 |
Modified build/cackey_osx_build/Template_pmbuild/index.xml.in from [9543623cb4] to [6d6f116270].
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
..
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
{\fonttbl\f0\fnil\fcharset0 LucidaGrande;} {\colortbl;\red255\green255\blue255;} \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural \f0\fs26 \cf0 Release information:\ pkg: CACKey\ author: US Army Corps of Engineers\ Mac build contact: Kenneth Van Alstyne <kenneth.vanalstyne@hq.dhs.gov>\ US Department of Homeland Security\ contact: Roy Keene <roy.s.keene@usace.army.mil>\ ------------------------------------------------\ \ The PKCS11.tokend connector module included in this package is licensed under\ the APSL. See: http://devel.kvanals.org/PKCS11_Tokend\ \ The following files in the source directory are the intellectual property of the\ Free Software Foundation and are licensed under the terms of the GNU General\ Public License (GPL):\ config.guess, config.sub, install-sh\ \ The files in the source directory and the "leakcheck" directory are the intellectual\ property of the United States Government. It is not clear which, if any,\ license is made on them. In addition, as of 07-JUN-2010 they have not be\ cleared for public release.\ \ The files in the "pkcs11/" directory are licensed under the terms of the\ following licenses:\ mypkcs11.h : GNU General Public License 2.1.\ pkcs11.h : GNU General Public License 2.1.\ pkcs11f.h : GNU General Public License 2.1.\ pkcs11n.h : Mozilla Public License or GNU General Public License\ ................................................................................ To use, be sure to import the certificate authorities into Keychain Access.\ \ A debug version, /Library/CACKey/libcackey_g.dylib is provided if debug output is necessary.}]]> </resource> </locale> </resources> <requirements> <requirement id="tosv" operator="lt" value="'@@NEXTOSXVER@@'"> <message>This CACKey release requires Mac OS X @@CUROSXVER@@.</message> </requirement> <requirement id="tosv" operator="ge" value="'@@CUROSXVER@@'"> <message>This CACKey release requires Mac OS X @@CUROSXVER@@.</message> </requirement> </requirements> <flags/> <item type="file">01libcackey.xml</item> <item type="file">02libcackey.xml</item> |
|
|
|
|
|
<
<
<
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
..
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
{\fonttbl\f0\fnil\fcharset0 LucidaGrande;} {\colortbl;\red255\green255\blue255;} \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural \f0\fs26 \cf0 Release information:\ pkg: CACKey\ author: US Army Corps of Engineers\ Mac build contact: Kenneth Van Alstyne <kenny@coreadaptive.com>\ Core Adaptive, LLC\ contact: Roy Keene <rkeene@coreadaptive.com>\ ------------------------------------------------\ \ The PKCS11.tokend connector module included in this package is licensed under\ the APSL. See: http://devel.kvanals.org/PKCS11_Tokend\ \ The following files in the source directory are the intellectual property of the\ Free Software Foundation and are licensed under the terms of the GNU General\ Public License (GPL):\ config.guess, config.sub, install-sh\ \ The files in the source directory and the "leakcheck" directory are the intellectual\ property of the United States Government. It is not clear which, if any,\ license is made on them. In addition, as of 07-JUN-2010 they have not\ been cleared for public release.\ \ The files in the "pkcs11/" directory are licensed under the terms of the\ following licenses:\ mypkcs11.h : GNU General Public License 2.1.\ pkcs11.h : GNU General Public License 2.1.\ pkcs11f.h : GNU General Public License 2.1.\ pkcs11n.h : Mozilla Public License or GNU General Public License\ ................................................................................ To use, be sure to import the certificate authorities into Keychain Access.\ \ A debug version, /Library/CACKey/libcackey_g.dylib is provided if debug output is necessary.}]]> </resource> </locale> </resources> <requirements> <requirement id="tosv" operator="ge" value="'@@CUROSXVER@@'"> <message>This CACKey release requires Mac OS X @@CUROSXVER@@.</message> </requirement> </requirements> <flags/> <item type="file">01libcackey.xml</item> <item type="file">02libcackey.xml</item> |
Modified build/cackey_osx_build/build_osx.sh from [b98bcd81f7] to [353b3acaa2].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 .. 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 .. 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 ... 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 ... 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
#!/bin/bash # Shell Script to make Mac OS X Releases of CACKey # Kenneth Van Alstyne # kenneth.l.vanalstyne@usace.army.mil CACKEY_VERSION=`cat configure.ac | grep AC_INIT | cut -d " " -f 2 | sed 's_)__'` # Check to see if we're building on Mac OS X 10.7 "Lion" if [ "`uname -r | cut -d . -f 1`" = "11" ]; then LIONBUILD=1 fi # Usage function usage() { echo "Usage: build_osx.sh <target>" echo Where target is one of: echo " leopard - (Builds Universal 10.5 Library for PPCG4/i386)" echo " snowleopard - (Builds Universal 10.6 Library for i386/x86_64)" echo " lion - (Builds Universal 10.7 Library for i386/x86_64)" echo " all - (Builds for all supported targets)" echo " clean - (Cleans up)" echo "Run from CACKey Build Root." exit $? } # Clean up function clean() { rm -f build/cackey_osx_build/cackey.dylib rm -rf build/cackey_osx_build/PKCS11.tokend ................................................................................ LIBTOOLDIR=/Developer/usr/share/libtool else LIBTOOLDIR=/Developer/usr/share/libtool/config fi if [ ! -d macbuild ]; then mkdir macbuild mkdir macbuild/Leopard mkdir macbuild/Snowleopard mkdir macbuild/Lion mkdir macbuild/pkg fi if [ ! -f config.guess ]; then cp ${LIBTOOLDIR}/config.guess . fi if [ ! -f config.sub ]; then cp ${LIBTOOLDIR}/config.sub . ................................................................................ LIBRARY=/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/PCSC.framework/PCSC LIB="" ARCHLIST="" DLIB="" DARCHLIST="" OSX=Leopard PKTARGETOS=3 NEXTOSXVER=10.6 CUROSXVER=10.5 for HOST in powerpc-apple-darwin9 i386-apple-darwin9; do genbuild done libbuild pkgbuild } # Build function for Snow Leopard snowleopard() { makedir HEADERS=/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/PCSC.framework/Versions/A/Headers/ LIBRARY=/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/PCSC.framework/PCSC LIB="" ARCHLIST="" DLIB="" DARCHLIST="" OSX=Snowleopard PKTARGETOS=3 NEXTOSXVER=10.7 CUROSXVER=10.6 for HOST in i386-apple-darwin10 x86_64-apple-darwin10; do genbuild done libbuild pkgbuild } # Build function for Lion lion() { makedir HEADERS=/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/PCSC.framework/Versions/A/Headers/ LIBRARY=/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/PCSC.framework/PCSC LIB="" ARCHLIST="" DLIB="" DARCHLIST="" OSX=Lion PKTARGETOS=3 NEXTOSXVER=10.8 CUROSXVER=10.7 for HOST in i386-apple-darwin11 x86_64-apple-darwin11; do genbuild done libbuild pkgbuild } # Generic build function genbuild() { make distclean ARCH=`echo ${HOST} | cut -d "-" -f 1` if [ ${ARCH} == "powerpc" ]; then if [ ${OSX} == "Leopard" ]; then ARCH="ppc -mcpu=G4" else ARCH="ppc -mcpu=G3" fi fi if [ "${LIONBUILD}" = 1 ]; then if [ "${ARCH}" == "ppc -mcpu=G4" ]; then CC=powerpc-apple-darwin11-gcc-4.2.1 CPP=powerpc-apple-darwin11-cpp-4.2.1 CFLAGS="-m32 -I/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/gcc/powerpc-apple-darwin10/4.2.1/include -isysroot /Developer/SDKs/MacOSX10.5.sdk" CPPFLAGS="-D_LIBC_LIMITS_H_" ./configure --with-pcsc-headers=${HEADERS} --with-pcsc-libs=${LIBRARY} --host=${HOST} else CFLAGS="-arch ${ARCH}" ./configure --with-pcsc-headers=${HEADERS} --with-pcsc-libs=${LIBRARY} --host=${HOST} fi else CFLAGS="-arch ${ARCH}" ./configure --with-pcsc-headers=${HEADERS} --with-pcsc-libs=${LIBRARY} --host=${HOST} fi make cp libcackey.dylib macbuild/${OSX}/libcackey.dylib.`echo ${ARCH} | cut -d ' ' -f 1` cp libcackey_g.dylib macbuild/${OSX}/libcackey_g.dylib.`echo ${ARCH} | cut -d ' ' -f 1` } # Library build function ................................................................................ rm -rf build/cackey_osx_build/PKCS11.tokend if [ "${LIONBUILD}" = 1 ]; then TAR=gnutar else TAR=tar fi if [ "${OSX}" = "Leopard" ]; then curl http://devel.kvanals.org/PKCS11_Tokend/PKCS11_tokend-latest.tar.gz | ${TAR} --strip-components 3 --wildcards -x -z -f - "PKCS11_tokend-*/prebuilt/leopard/PKCS11.tokend" mv PKCS11.tokend build/cackey_osx_build/PKCS11.tokend else curl http://devel.kvanals.org/PKCS11_Tokend/PKCS11_tokend-latest.tar.gz | ${TAR} --strip-components 3 --wildcards -x -z -f - "PKCS11_tokend-*/prebuilt/snowleopard/PKCS11.tokend" mv PKCS11.tokend build/cackey_osx_build/PKCS11.tokend fi for PMDOC in build/cackey_osx_build/Template_pmbuild/*.in; do PMDOC="`echo "${PMDOC}" | sed 's|l.in|l|g' | sed 's|build/cackey_osx_build/Template_pmbuild/||g'`" UUID="`python -c 'import uuid; print uuid.uuid1()' | dd conv=ucase 2>/dev/null`" mkdir -p build/cackey_osx_build/${OSX}_pmbuild.pmdoc sed "s|@@BUILDROOTDIR@@|$(pwd)|g" build/cackey_osx_build/Template_pmbuild/${PMDOC}.in > build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC} sed "s|@@OSXVERSION@@|${OSX}|g" build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC} > build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC}.1 sed "s|@@UUID@@|${UUID}|g" build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC}.1 > build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC} sed "s|@@TARGETOS@@|${PKTARGETOS}|g" build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC} > build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC}.1 sed "s|@@NEXTOSXVER@@|${NEXTOSXVER}|g" build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC}.1 > build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC} sed "s|@@CUROSXVER@@|${CUROSXVER}|g" build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC} > build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC}.1 sed "s|@@LIBCACKEYG@@|${LIBCACKEYG}|g" build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC}.1 > build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC} cp build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC} build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC}.1 mv build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC}.1 build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC} done EXT=pkg if [ ${OSX} == "Snowleopard" ]; then cat build/cackey_osx_build/${OSX}_pmbuild.pmdoc/index.xml | sed 's|for Mac OS X Snowleopard|for Mac OS X SnowLeopard|g' > build/cackey_osx_build/${OSX}_pmbuild.pmdoc/index.xml.new mv build/cackey_osx_build/${OSX}_pmbuild.pmdoc/index.xml.new build/cackey_osx_build/${OSX}_pmbuild.pmdoc/index.xml fi /Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker -d build/cackey_osx_build/${OSX}_pmbuild.pmdoc -o macbuild/pkg/CACKey_${CACKEY_VERSION}_${OSX}.${EXT} tar --create --directory macbuild/pkg/ --file macbuild/pkg/CACKey_${CACKEY_VERSION}_${OSX}.${EXT}.tar CACKey_${CACKEY_VERSION}_${OSX}.${EXT} gzip -9 macbuild/pkg/CACKey_${CACKEY_VERSION}_${OSX}.${EXT}.tar rm -rf macbuild/pkg/CACKey_${CACKEY_VERSION}_${OSX}.${EXT} rm -f build/cackey_osx_build/cackey.dylib ................................................................................ "leopard") ./autogen.sh leopard exit $? ;; "snowleopard") ./autogen.sh snowleopard exit $? ;; "lion") ./autogen.sh lion exit $? ;; "all") ./autogen.sh leopard snowleopard lion echo "" echo "All builds complete." exit $? ;; "clean") clean |
| | | | < > > > > > > < | < | | | < < < < < < < < < < < < < < < < < < < < < < | < < < | | | | | < | | | | < < < < < < | < |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 .. 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 .. 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 ... 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 ... 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
#!/bin/bash # Shell Script to make Mac OS X Releases of CACKey # Kenneth Van Alstyne # kenny@coreadaptive.com CACKEY_VERSION=`cat configure.ac | grep AC_INIT | cut -d " " -f 2 | sed 's_)__'` # Check to see if we're building on Mac OS X 10.7 "Lion" or newer if [ "`uname -r | cut -d . -f 1`" -ge "11" ]; then LIONBUILD=1 fi # Usage function usage() { echo "Usage: build_osx.sh <target>" echo Where target is one of: echo " leopard - (Builds Universal 10.5 Library for PPCG4/i386)" echo " sltoyos - (Builds Universal 10.6/10.7/10.8/10.9/10.10 Library for i386/x86_64)" echo " all - (Builds for all supported targets)" echo " clean - (Cleans up)" echo "Run from CACKey Build Root." echo "" echo "NOTE: Leopard build requires legacy XCode 3 components in" echo " /Developer because of PowerPC support." echo " All builds require gnutar, automake, and autoconf." echo " If your newer release of XCode does not include these" echo " components, I recommend installing them from MacPorts." exit $? } # Clean up function clean() { rm -f build/cackey_osx_build/cackey.dylib rm -rf build/cackey_osx_build/PKCS11.tokend ................................................................................ LIBTOOLDIR=/Developer/usr/share/libtool else LIBTOOLDIR=/Developer/usr/share/libtool/config fi if [ ! -d macbuild ]; then mkdir macbuild mkdir macbuild/Leopard mkdir macbuild/Sltoyos mkdir macbuild/pkg fi if [ ! -f config.guess ]; then cp ${LIBTOOLDIR}/config.guess . fi if [ ! -f config.sub ]; then cp ${LIBTOOLDIR}/config.sub . ................................................................................ LIBRARY=/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/PCSC.framework/PCSC LIB="" ARCHLIST="" DLIB="" DARCHLIST="" OSX=Leopard PKTARGETOS=3 CUROSXVER=10.5 for HOST in powerpc-apple-darwin9 i386-apple-darwin9; do genbuild done libbuild pkgbuild } # Build function for Snow Leopard/Lion/Mountain Lion/Mavericks/Yosemite sltoyos() { makedir HEADERS=/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/PCSC.framework/Versions/A/Headers/ LIBRARY=/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/PCSC.framework/PCSC LIB="" ARCHLIST="" DLIB="" DARCHLIST="" OSX=Sltoyos PKTARGETOS=3 CUROSXVER=10.6 for HOST in i386-apple-darwin10 x86_64-apple-darwin10; do genbuild done libbuild pkgbuild } # Generic build function genbuild() { make distclean ARCH=`echo ${HOST} | cut -d "-" -f 1` if [ ${ARCH} == "powerpc" ]; then ARCH="ppc -mcpu=G4" fi if [ "${LIONBUILD}" = 1 ]; then if [ "${ARCH}" == "ppc -mcpu=G4" ]; then CC=/Developer/usr/bin/powerpc-apple-darwin10-gcc-4.2.1 CXX=/Developer/usr/bin/powerpc-apple-darwin10-g++-4.2.1 CFLAGS="-m32 -mcpu=G4 -I/Developer/usr/lib/gcc/powerpc-apple-darwin10/4.2.1/include -isysroot /Developer/SDKs/MacOSX10.5.sdk" CPPFLAGS="-D_LIBC_LIMITS_H_" ./configure --with-pcsc-headers=${HEADERS} --with-pcsc-libs=${LIBRARY} --host=${HOST} --enable-dod-certs-on-hw-slots else CFLAGS="-arch ${ARCH}" ./configure --with-pcsc-headers=${HEADERS} --with-pcsc-libs=${LIBRARY} --host=${HOST} --enable-dod-certs-on-hw-slots fi else CFLAGS="-arch ${ARCH}" ./configure --with-pcsc-headers=${HEADERS} --with-pcsc-libs=${LIBRARY} --host=${HOST} --enable-dod-certs-on-hw-slots fi make cp libcackey.dylib macbuild/${OSX}/libcackey.dylib.`echo ${ARCH} | cut -d ' ' -f 1` cp libcackey_g.dylib macbuild/${OSX}/libcackey_g.dylib.`echo ${ARCH} | cut -d ' ' -f 1` } # Library build function ................................................................................ rm -rf build/cackey_osx_build/PKCS11.tokend if [ "${LIONBUILD}" = 1 ]; then TAR=gnutar else TAR=tar fi if [ "${OSX}" = "Leopard" ]; then curl http://devel.kvanals.org/PKCS11_Tokend/PKCS11_tokend-latest.tar.gz | gzip -d -c | ${TAR} --strip-components 3 --wildcards -x -f - "PKCS11_tokend-*/prebuilt/leopard/PKCS11.tokend" mv PKCS11.tokend build/cackey_osx_build/PKCS11.tokend else curl http://devel.kvanals.org/PKCS11_Tokend/PKCS11_tokend-latest.tar.gz | gzip -d -c | ${TAR} --strip-components 3 --wildcards -x -f - "PKCS11_tokend-*/prebuilt/snowleopard/PKCS11.tokend" mv PKCS11.tokend build/cackey_osx_build/PKCS11.tokend fi for PMDOC in build/cackey_osx_build/Template_pmbuild/*.in; do PMDOC="`echo "${PMDOC}" | sed 's|l.in|l|g' | sed 's|build/cackey_osx_build/Template_pmbuild/||g'`" UUID="`python -c 'import uuid; print uuid.uuid1()' | dd conv=ucase 2>/dev/null`" mkdir -p build/cackey_osx_build/${OSX}_pmbuild.pmdoc sed "s|@@BUILDROOTDIR@@|$(pwd)|g" build/cackey_osx_build/Template_pmbuild/${PMDOC}.in > build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC} sed "s|@@OSXVERSION@@|${OSX}|g" build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC} > build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC}.1 sed "s|@@UUID@@|${UUID}|g" build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC}.1 > build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC} sed "s|@@TARGETOS@@|${PKTARGETOS}|g" build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC} > build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC}.1 sed "s|@@CUROSXVER@@|${CUROSXVER}|g" build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC} > build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC}.1 sed "s|@@LIBCACKEYG@@|${LIBCACKEYG}|g" build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC}.1 > build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC} cp build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC} build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC}.1 mv build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC}.1 build/cackey_osx_build/${OSX}_pmbuild.pmdoc/${PMDOC} done EXT=pkg if [ ${OSX} == "Sltoyos" ]; then cat build/cackey_osx_build/${OSX}_pmbuild.pmdoc/index.xml | sed 's|for Mac OS X Sltoyos|for Mac OS X SLtoYos|g' > build/cackey_osx_build/${OSX}_pmbuild.pmdoc/index.xml.new mv build/cackey_osx_build/${OSX}_pmbuild.pmdoc/index.xml.new build/cackey_osx_build/${OSX}_pmbuild.pmdoc/index.xml fi /Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker -d build/cackey_osx_build/${OSX}_pmbuild.pmdoc -o macbuild/pkg/CACKey_${CACKEY_VERSION}_${OSX}.${EXT} tar --create --directory macbuild/pkg/ --file macbuild/pkg/CACKey_${CACKEY_VERSION}_${OSX}.${EXT}.tar CACKey_${CACKEY_VERSION}_${OSX}.${EXT} gzip -9 macbuild/pkg/CACKey_${CACKEY_VERSION}_${OSX}.${EXT}.tar rm -rf macbuild/pkg/CACKey_${CACKEY_VERSION}_${OSX}.${EXT} rm -f build/cackey_osx_build/cackey.dylib ................................................................................ "leopard") ./autogen.sh leopard exit $? ;; "sltoyos") ./autogen.sh sltoyos exit $? ;; "all") ./autogen.sh leopard sltoyos echo "" echo "All builds complete." exit $? ;; "clean") clean |
Modified build/cackey_win32_build/build.sh from [ad50b00270] to [fbfa3a5bbe].
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#! /bin/bash make distclean cp "./build/cackey_win32_build/lib/winscard.dll" "./build/cackey_win32_build/lib/WinSCard.dll" ./configure --with-pcsc-headers="$(pwd)/build/cackey_win32_build/include" --with-pcsc-libs="-L$(pwd)/build/cackey_win32_build/lib -lwinscard" --host=i586-mingw32msvc CPPFLAGS="-I$(pwd)/build/cackey_win32_build/include" || exit 1 make || exit 1 rm -f "./build/cackey_win32_build/lib/WinSCard.dll" exit 0 |
< < | < < |
1 2 3 4 5 6 7 8 9 |
#! /bin/bash
make distclean
./configure --with-pcsc-headers="$(pwd)/build/cackey_win32_build/include" --with-pcsc-libs="-L$(pwd)/build/cackey_win32_build/lib -lwinscard" --host=i586-mingw32msvc CPPFLAGS="-I$(pwd)/build/cackey_win32_build/include" "$@" || exit 1
make || exit 1
exit 0
|
Deleted build/cackey_win32_build/include/SCardErr.h version [969de80f85].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 |
/* scarderr.mc Error message codes from the Smart Card Resource Manager These messages must be reconciled with winerror.w They exist here to provide error messages on pre-Win2K systems. */ #ifndef SCARD_S_SUCCESS // // ============================= // Facility SCARD Error Messages // ============================= // #define SCARD_S_SUCCESS NO_ERROR // // Values are 32 bit values laid out as follows: // // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 // +---+-+-+-----------------------+-------------------------------+ // |Sev|C|R| Facility | Code | // +---+-+-+-----------------------+-------------------------------+ // // where // // Sev - is the severity code // // 00 - Success // 01 - Informational // 10 - Warning // 11 - Error // // C - is the Customer code flag // // R - is a reserved bit // // Facility - is the facility code // // Code - is the facility's status code // // // Define the facility codes // #define FACILITY_SYSTEM 0x0 #define FACILITY_SCARD 0x10 // // Define the severity codes // #define STATUS_SEVERITY_WARNING 0x2 #define STATUS_SEVERITY_INFORMATIONAL 0x1 #define STATUS_SEVERITY_ERROR 0x3 // // MessageId: SCARD_F_INTERNAL_ERROR // // MessageText: // // An internal consistency check failed. // #define SCARD_F_INTERNAL_ERROR ((DWORD)0x80100001L) // // MessageId: SCARD_E_CANCELLED // // MessageText: // // The action was cancelled by an SCardCancel request. // #define SCARD_E_CANCELLED ((DWORD)0x80100002L) // // MessageId: SCARD_E_INVALID_HANDLE // // MessageText: // // The supplied handle was invalid. // #define SCARD_E_INVALID_HANDLE ((DWORD)0x80100003L) // // MessageId: SCARD_E_INVALID_PARAMETER // // MessageText: // // One or more of the supplied parameters could not be properly interpreted. // #define SCARD_E_INVALID_PARAMETER ((DWORD)0x80100004L) // // MessageId: SCARD_E_INVALID_TARGET // // MessageText: // // Registry startup information is missing or invalid. // #define SCARD_E_INVALID_TARGET ((DWORD)0x80100005L) // // MessageId: SCARD_E_NO_MEMORY // // MessageText: // // Not enough memory available to complete this command. // #define SCARD_E_NO_MEMORY ((DWORD)0x80100006L) // // MessageId: SCARD_F_WAITED_TOO_LONG // // MessageText: // // An internal consistency timer has expired. // #define SCARD_F_WAITED_TOO_LONG ((DWORD)0x80100007L) // // MessageId: SCARD_E_INSUFFICIENT_BUFFER // // MessageText: // // The data buffer to receive returned data is too small for the returned data. // #define SCARD_E_INSUFFICIENT_BUFFER ((DWORD)0x80100008L) // // MessageId: SCARD_E_UNKNOWN_READER // // MessageText: // // The specified reader name is not recognized. // #define SCARD_E_UNKNOWN_READER ((DWORD)0x80100009L) // // MessageId: SCARD_E_TIMEOUT // // MessageText: // // The user-specified timeout value has expired. // #define SCARD_E_TIMEOUT ((DWORD)0x8010000AL) // // MessageId: SCARD_E_SHARING_VIOLATION // // MessageText: // // The smart card cannot be accessed because of other connections outstanding. // #define SCARD_E_SHARING_VIOLATION ((DWORD)0x8010000BL) // // MessageId: SCARD_E_NO_SMARTCARD // // MessageText: // // The operation requires a Smart Card, but no Smart Card is currently in the device. // #define SCARD_E_NO_SMARTCARD ((DWORD)0x8010000CL) // // MessageId: SCARD_E_UNKNOWN_CARD // // MessageText: // // The specified smart card name is not recognized. // #define SCARD_E_UNKNOWN_CARD ((DWORD)0x8010000DL) // // MessageId: SCARD_E_CANT_DISPOSE // // MessageText: // // The system could not dispose of the media in the requested manner. // #define SCARD_E_CANT_DISPOSE ((DWORD)0x8010000EL) // // MessageId: SCARD_E_PROTO_MISMATCH // // MessageText: // // The requested protocols are incompatible with the protocol currently in use with the smart card. // #define SCARD_E_PROTO_MISMATCH ((DWORD)0x8010000FL) // // MessageId: SCARD_E_NOT_READY // // MessageText: // // The reader or smart card is not ready to accept commands. // #define SCARD_E_NOT_READY ((DWORD)0x80100010L) // // MessageId: SCARD_E_INVALID_VALUE // // MessageText: // // One or more of the supplied parameters values could not be properly interpreted. // #define SCARD_E_INVALID_VALUE ((DWORD)0x80100011L) // // MessageId: SCARD_E_SYSTEM_CANCELLED // // MessageText: // // The action was cancelled by the system, presumably to log off or shut down. // #define SCARD_E_SYSTEM_CANCELLED ((DWORD)0x80100012L) // // MessageId: SCARD_F_COMM_ERROR // // MessageText: // // An internal communications error has been detected. // #define SCARD_F_COMM_ERROR ((DWORD)0x80100013L) // // MessageId: SCARD_F_UNKNOWN_ERROR // // MessageText: // // An internal error has been detected, but the source is unknown. // #define SCARD_F_UNKNOWN_ERROR ((DWORD)0x80100014L) // // MessageId: SCARD_E_INVALID_ATR // // MessageText: // // An ATR obtained from the registry is not a valid ATR string. // #define SCARD_E_INVALID_ATR ((DWORD)0x80100015L) // // MessageId: SCARD_E_NOT_TRANSACTED // // MessageText: // // An attempt was made to end a non-existent transaction. // #define SCARD_E_NOT_TRANSACTED ((DWORD)0x80100016L) // // MessageId: SCARD_E_READER_UNAVAILABLE // // MessageText: // // The specified reader is not currently available for use. // #define SCARD_E_READER_UNAVAILABLE ((DWORD)0x80100017L) // // MessageId: SCARD_P_SHUTDOWN // // MessageText: // // The operation has been aborted to allow the server application to exit. // #define SCARD_P_SHUTDOWN ((DWORD)0x80100018L) // // MessageId: SCARD_E_PCI_TOO_SMALL // // MessageText: // // The PCI Receive buffer was too small. // #define SCARD_E_PCI_TOO_SMALL ((DWORD)0x80100019L) // // MessageId: SCARD_E_READER_UNSUPPORTED // // MessageText: // // The reader driver does not meet minimal requirements for support. // #define SCARD_E_READER_UNSUPPORTED ((DWORD)0x8010001AL) // // MessageId: SCARD_E_DUPLICATE_READER // // MessageText: // // The reader driver did not produce a unique reader name. // #define SCARD_E_DUPLICATE_READER ((DWORD)0x8010001BL) // // MessageId: SCARD_E_CARD_UNSUPPORTED // // MessageText: // // The smart card does not meet minimal requirements for support. // #define SCARD_E_CARD_UNSUPPORTED ((DWORD)0x8010001CL) // // MessageId: SCARD_E_NO_SERVICE // // MessageText: // // The Smart card resource manager is not running. // #define SCARD_E_NO_SERVICE ((DWORD)0x8010001DL) // // MessageId: SCARD_E_SERVICE_STOPPED // // MessageText: // // The Smart card resource manager has shut down. // #define SCARD_E_SERVICE_STOPPED ((DWORD)0x8010001EL) // // MessageId: SCARD_E_UNEXPECTED // // MessageText: // // An unexpected card error has occurred. // #define SCARD_E_UNEXPECTED ((DWORD)0x8010001FL) // // MessageId: SCARD_E_ICC_INSTALLATION // // MessageText: // // No Primary Provider can be found for the smart card. // #define SCARD_E_ICC_INSTALLATION ((DWORD)0x80100020L) // // MessageId: SCARD_E_ICC_CREATEORDER // // MessageText: // // The requested order of object creation is not supported. // #define SCARD_E_ICC_CREATEORDER ((DWORD)0x80100021L) // // MessageId: SCARD_E_UNSUPPORTED_FEATURE // // MessageText: // // This smart card does not support the requested feature. // #define SCARD_E_UNSUPPORTED_FEATURE ((DWORD)0x80100022L) // // MessageId: SCARD_E_DIR_NOT_FOUND // // MessageText: // // The identified directory does not exist in the smart card. // #define SCARD_E_DIR_NOT_FOUND ((DWORD)0x80100023L) // // MessageId: SCARD_E_FILE_NOT_FOUND // // MessageText: // // The identified file does not exist in the smart card. // #define SCARD_E_FILE_NOT_FOUND ((DWORD)0x80100024L) // // MessageId: SCARD_E_NO_DIR // // MessageText: // // The supplied path does not represent a smart card directory. // #define SCARD_E_NO_DIR ((DWORD)0x80100025L) // // MessageId: SCARD_E_NO_FILE // // MessageText: // // The supplied path does not represent a smart card file. // #define SCARD_E_NO_FILE ((DWORD)0x80100026L) // // MessageId: SCARD_E_NO_ACCESS // // MessageText: // // Access is denied to this file. // #define SCARD_E_NO_ACCESS ((DWORD)0x80100027L) // // MessageId: SCARD_E_WRITE_TOO_MANY // // MessageText: // // The smartcard does not have enough memory to store the information. // #define SCARD_E_WRITE_TOO_MANY ((DWORD)0x80100028L) // // MessageId: SCARD_E_BAD_SEEK // // MessageText: // // There was an error trying to set the smart card file object pointer. // #define SCARD_E_BAD_SEEK ((DWORD)0x80100029L) // // MessageId: SCARD_E_INVALID_CHV // // MessageText: // // The supplied PIN is incorrect. // #define SCARD_E_INVALID_CHV ((DWORD)0x8010002AL) // // MessageId: SCARD_E_UNKNOWN_RES_MNG // // MessageText: // // An unrecognized error code was returned from a layered component. // #define SCARD_E_UNKNOWN_RES_MNG ((DWORD)0x8010002BL) // // MessageId: SCARD_E_NO_SUCH_CERTIFICATE // // MessageText: // // The requested certificate does not exist. // #define SCARD_E_NO_SUCH_CERTIFICATE ((DWORD)0x8010002CL) // // MessageId: SCARD_E_CERTIFICATE_UNAVAILABLE // // MessageText: // // The requested certificate could not be obtained. // #define SCARD_E_CERTIFICATE_UNAVAILABLE ((DWORD)0x8010002DL) // // MessageId: SCARD_E_NO_READERS_AVAILABLE // // MessageText: // // Cannot find a smart card reader. // #define SCARD_E_NO_READERS_AVAILABLE ((DWORD)0x8010002EL) // // MessageId: SCARD_E_COMM_DATA_LOST // // MessageText: // // A communications error with the smart card has been detected. Retry the operation. // #define SCARD_E_COMM_DATA_LOST ((DWORD)0x8010002FL) // // MessageId: SCARD_E_NO_KEY_CONTAINER // // MessageText: // // The requested key container does not exist on the smart card. // #define SCARD_E_NO_KEY_CONTAINER ((DWORD)0x80100030L) // // MessageId: SCARD_E_SERVER_TOO_BUSY // // MessageText: // // The Smart card resource manager is too busy to complete this operation. // #define SCARD_E_SERVER_TOO_BUSY ((DWORD)0x80100031L) // // MessageId: SCARD_E_PIN_CACHE_EXPIRED // // MessageText: // // The smart card PIN cache has expired. // #define SCARD_E_PIN_CACHE_EXPIRED ((DWORD)0x80100032L) // // MessageId: SCARD_E_NO_PIN_CACHE // // MessageText: // // The smart card PIN cannot be cached. // #define SCARD_E_NO_PIN_CACHE ((DWORD)0x80100033L) // // MessageId: SCARD_E_READ_ONLY_CARD // // MessageText: // // The smart card is read only and cannot be written to. // #define SCARD_E_READ_ONLY_CARD ((DWORD)0x80100034L) // // These are warning codes. // // // MessageId: SCARD_W_UNSUPPORTED_CARD // // MessageText: // // The reader cannot communicate with the smart card, due to ATR configuration conflicts. // #define SCARD_W_UNSUPPORTED_CARD ((DWORD)0x80100065L) // // MessageId: SCARD_W_UNRESPONSIVE_CARD // // MessageText: // // The smart card is not responding to a reset. // #define SCARD_W_UNRESPONSIVE_CARD ((DWORD)0x80100066L) // // MessageId: SCARD_W_UNPOWERED_CARD // // MessageText: // // Power has been removed from the smart card, so that further communication is not possible. // #define SCARD_W_UNPOWERED_CARD ((DWORD)0x80100067L) // // MessageId: SCARD_W_RESET_CARD // // MessageText: // // The smart card has been reset, so any shared state information is invalid. // #define SCARD_W_RESET_CARD ((DWORD)0x80100068L) // // MessageId: SCARD_W_REMOVED_CARD // // MessageText: // // The smart card has been removed, so that further communication is not possible. // #define SCARD_W_REMOVED_CARD ((DWORD)0x80100069L) // // MessageId: SCARD_W_SECURITY_VIOLATION // // MessageText: // // Access was denied because of a security violation. // #define SCARD_W_SECURITY_VIOLATION ((DWORD)0x8010006AL) // // MessageId: SCARD_W_WRONG_CHV // // MessageText: // // The card cannot be accessed because the wrong PIN was presented. // #define SCARD_W_WRONG_CHV ((DWORD)0x8010006BL) // // MessageId: SCARD_W_CHV_BLOCKED // // MessageText: // // The card cannot be accessed because the maximum number of PIN entry attempts has been reached. // #define SCARD_W_CHV_BLOCKED ((DWORD)0x8010006CL) // // MessageId: SCARD_W_EOF // // MessageText: // // The end of the smart card file has been reached. // #define SCARD_W_EOF ((DWORD)0x8010006DL) // // MessageId: SCARD_W_CANCELLED_BY_USER // // MessageText: // // The action was cancelled by the user. // #define SCARD_W_CANCELLED_BY_USER ((DWORD)0x8010006EL) // // MessageId: SCARD_W_CARD_NOT_AUTHENTICATED // // MessageText: // // No PIN was presented to the smart card. // #define SCARD_W_CARD_NOT_AUTHENTICATED ((DWORD)0x8010006FL) // // MessageId: SCARD_W_CACHE_ITEM_NOT_FOUND // // MessageText: // // The requested item could not be found in the cache. // #define SCARD_W_CACHE_ITEM_NOT_FOUND ((DWORD)0x80100070L) // // MessageId: SCARD_W_CACHE_ITEM_STALE // // MessageText: // // The requested cache item is too old and was deleted from the cache. // #define SCARD_W_CACHE_ITEM_STALE ((DWORD)0x80100071L) // // MessageId: SCARD_W_CACHE_ITEM_TOO_BIG // // MessageText: // // The new cache item exceeds the maximum per-item size defined for the cache. // #define SCARD_W_CACHE_ITEM_TOO_BIG ((DWORD)0x80100072L) #endif // SCARD_S_SUCCESS |
< < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted build/cackey_win32_build/include/winscard.h version [09d1252d26].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 |
/*++ Copyright (c) 1996 Microsoft Corporation Module Name: WinSCard Abstract: This header file provides the definitions and symbols necessary for an Application or Smart Card Service Provider to access the Smartcard Subsystem. Environment: Win32 Notes: --*/ #ifndef _WINSCARD_H_ #define _WINSCARD_H_ #if defined (_MSC_VER) && (_MSC_VER >= 1020) #pragma once #endif #include <windows.h> #include <wtypes.h> #include <winioctl.h> #include "winsmcrd.h" #ifndef SCARD_S_SUCCESS #include "SCardErr.h" #endif #ifdef __cplusplus extern "C" { #endif #if 1 /* jkm */ #ifndef __LPCGUID_DEFINED__ #define __LPCGUID_DEFINED__ typedef const GUID *LPCGUID; #endif #endif #ifndef _LPCBYTE_DEFINED #define _LPCBYTE_DEFINED typedef const BYTE *LPCBYTE; #endif #ifndef _LPCVOID_DEFINED #define _LPCVOID_DEFINED typedef const VOID *LPCVOID; #endif #ifndef WINSCARDAPI #define WINSCARDAPI #endif #ifndef WINSCARDDATA #define WINSCARDDATA __declspec(dllimport) #endif /* In clr:pure we cannot mark data export with dllimport. * We should add small functions which returns the value of * the global. */ #if !defined(_M_CEE_PURE) static const SCARD_IO_REQUEST static_g_rgSCardT0Pci = { SCARD_PROTOCOL_T0, 8 }; static const SCARD_IO_REQUEST static_g_rgSCardT1Pci = { SCARD_PROTOCOL_T1, 8 }; WINSCARDDATA extern const SCARD_IO_REQUEST g_rgSCardT0Pci, g_rgSCardT1Pci, g_rgSCardRawPci; #define SCARD_PCI_T0 (&static_g_rgSCardT0Pci) #define SCARD_PCI_T1 (&static_g_rgSCardT1Pci) #define SCARD_PCI_RAW (&g_rgSCardRawPci) #endif // //////////////////////////////////////////////////////////////////////////////// // // Service Manager Access Services // // The following services are used to manage user and terminal contexts for // Smart Cards. // typedef ULONG_PTR SCARDCONTEXT; typedef SCARDCONTEXT *PSCARDCONTEXT, *LPSCARDCONTEXT; typedef ULONG_PTR SCARDHANDLE; typedef SCARDHANDLE *PSCARDHANDLE, *LPSCARDHANDLE; #define SCARD_AUTOALLOCATE (DWORD)(-1) #define SCARD_SCOPE_USER 0 // The context is a user context, and any // database operations are performed within the // domain of the user. #define SCARD_SCOPE_TERMINAL 1 // The context is that of the current terminal, // and any database operations are performed // within the domain of that terminal. (The // calling application must have appropriate // access permissions for any database actions.) #define SCARD_SCOPE_SYSTEM 2 // The context is the system context, and any // database operations are performed within the // domain of the system. (The calling // application must have appropriate access // permissions for any database actions.) extern WINSCARDAPI LONG WINAPI SCardEstablishContext( DWORD dwScope, LPCVOID pvReserved1, LPCVOID pvReserved2, LPSCARDCONTEXT phContext); extern WINSCARDAPI LONG WINAPI SCardReleaseContext( SCARDCONTEXT hContext); extern WINSCARDAPI LONG WINAPI SCardIsValidContext( SCARDCONTEXT hContext); // //////////////////////////////////////////////////////////////////////////////// // // Smart Card Database Management Services // // The following services provide for managing the Smart Card Database. // #define SCARD_ALL_READERS TEXT("SCard$AllReaders\000") #define SCARD_DEFAULT_READERS TEXT("SCard$DefaultReaders\000") #define SCARD_LOCAL_READERS TEXT("SCard$LocalReaders\000") #define SCARD_SYSTEM_READERS TEXT("SCard$SystemReaders\000") #define SCARD_PROVIDER_PRIMARY 1 // Primary Provider Id #define SCARD_PROVIDER_CSP 2 // Crypto Service Provider Id #define SCARD_PROVIDER_KSP 3 // Key Storage Provider Id // // Database Reader routines // extern WINSCARDAPI LONG WINAPI SCardListReaderGroupsA( SCARDCONTEXT hContext, LPSTR mszGroups, LPDWORD pcchGroups); extern WINSCARDAPI LONG WINAPI SCardListReaderGroupsW( SCARDCONTEXT hContext, LPWSTR mszGroups, LPDWORD pcchGroups); #ifdef UNICODE #define SCardListReaderGroups SCardListReaderGroupsW #else #define SCardListReaderGroups SCardListReaderGroupsA #endif // !UNICODE extern WINSCARDAPI LONG WINAPI SCardListReadersA( SCARDCONTEXT hContext, LPCSTR mszGroups, LPSTR mszReaders, LPDWORD pcchReaders); extern WINSCARDAPI LONG WINAPI SCardListReadersW( SCARDCONTEXT hContext, LPCWSTR mszGroups, LPWSTR mszReaders, LPDWORD pcchReaders); #ifdef UNICODE #define SCardListReaders SCardListReadersW #else #define SCardListReaders SCardListReadersA #endif // !UNICODE extern WINSCARDAPI LONG WINAPI SCardListCardsA( SCARDCONTEXT hContext, LPCBYTE pbAtr, LPCGUID rgquidInterfaces, DWORD cguidInterfaceCount, LPSTR mszCards, LPDWORD pcchCards); extern WINSCARDAPI LONG WINAPI SCardListCardsW( SCARDCONTEXT hContext, LPCBYTE pbAtr, LPCGUID rgquidInterfaces, DWORD cguidInterfaceCount, LPWSTR mszCards, LPDWORD pcchCards); #ifdef UNICODE #define SCardListCards SCardListCardsW #else #define SCardListCards SCardListCardsA #endif // !UNICODE // // NOTE: The routine SCardListCards name differs from the PC/SC definition. // It should be: // // extern WINSCARDAPI LONG WINAPI // SCardListCardTypes( // SCARDCONTEXT hContext, // LPCBYTE pbAtr, // LPCGUID rgquidInterfaces, // DWORD cguidInterfaceCount, // LPTSTR mszCards, // out LPDWORD pcchCards); // // Here's a work-around MACRO: #define SCardListCardTypes SCardListCards extern WINSCARDAPI LONG WINAPI SCardListInterfacesA( SCARDCONTEXT hContext, LPCSTR szCard, LPGUID pguidInterfaces, LPDWORD pcguidInterfaces); extern WINSCARDAPI LONG WINAPI SCardListInterfacesW( SCARDCONTEXT hContext, LPCWSTR szCard, LPGUID pguidInterfaces, LPDWORD pcguidInterfaces); #ifdef UNICODE #define SCardListInterfaces SCardListInterfacesW #else #define SCardListInterfaces SCardListInterfacesA #endif // !UNICODE extern WINSCARDAPI LONG WINAPI SCardGetProviderIdA( SCARDCONTEXT hContext, LPCSTR szCard, LPGUID pguidProviderId); extern WINSCARDAPI LONG WINAPI SCardGetProviderIdW( SCARDCONTEXT hContext, LPCWSTR szCard, LPGUID pguidProviderId); #ifdef UNICODE #define SCardGetProviderId SCardGetProviderIdW #else #define SCardGetProviderId SCardGetProviderIdA #endif // !UNICODE // // NOTE: The routine SCardGetProviderId in this implementation uses GUIDs. // The PC/SC definition uses BYTEs. // extern WINSCARDAPI LONG WINAPI SCardGetCardTypeProviderNameA( SCARDCONTEXT hContext, LPCSTR szCardName, DWORD dwProviderId, LPSTR szProvider, LPDWORD pcchProvider); extern WINSCARDAPI LONG WINAPI SCardGetCardTypeProviderNameW( SCARDCONTEXT hContext, LPCWSTR szCardName, DWORD dwProviderId, LPWSTR szProvider, LPDWORD pcchProvider); #ifdef UNICODE #define SCardGetCardTypeProviderName SCardGetCardTypeProviderNameW #else #define SCardGetCardTypeProviderName SCardGetCardTypeProviderNameA #endif // !UNICODE // // NOTE: This routine is an extension to the PC/SC definitions. // // // Database Writer routines // extern WINSCARDAPI LONG WINAPI SCardIntroduceReaderGroupA( SCARDCONTEXT hContext, LPCSTR szGroupName); extern WINSCARDAPI LONG WINAPI SCardIntroduceReaderGroupW( SCARDCONTEXT hContext, LPCWSTR szGroupName); #ifdef UNICODE #define SCardIntroduceReaderGroup SCardIntroduceReaderGroupW #else #define SCardIntroduceReaderGroup SCardIntroduceReaderGroupA #endif // !UNICODE extern WINSCARDAPI LONG WINAPI SCardForgetReaderGroupA( SCARDCONTEXT hContext, LPCSTR szGroupName); extern WINSCARDAPI LONG WINAPI SCardForgetReaderGroupW( SCARDCONTEXT hContext, LPCWSTR szGroupName); #ifdef UNICODE #define SCardForgetReaderGroup SCardForgetReaderGroupW #else #define SCardForgetReaderGroup SCardForgetReaderGroupA #endif // !UNICODE extern WINSCARDAPI LONG WINAPI SCardIntroduceReaderA( SCARDCONTEXT hContext, LPCSTR szReaderName, LPCSTR szDeviceName); extern WINSCARDAPI LONG WINAPI SCardIntroduceReaderW( SCARDCONTEXT hContext, LPCWSTR szReaderName, LPCWSTR szDeviceName); #ifdef UNICODE #define SCardIntroduceReader SCardIntroduceReaderW #else #define SCardIntroduceReader SCardIntroduceReaderA #endif // !UNICODE extern WINSCARDAPI LONG WINAPI SCardForgetReaderA( SCARDCONTEXT hContext, LPCSTR szReaderName); extern WINSCARDAPI LONG WINAPI SCardForgetReaderW( SCARDCONTEXT hContext, LPCWSTR szReaderName); #ifdef UNICODE #define SCardForgetReader SCardForgetReaderW #else #define SCardForgetReader SCardForgetReaderA #endif // !UNICODE extern WINSCARDAPI LONG WINAPI SCardAddReaderToGroupA( SCARDCONTEXT hContext, LPCSTR szReaderName, LPCSTR szGroupName); extern WINSCARDAPI LONG WINAPI SCardAddReaderToGroupW( SCARDCONTEXT hContext, LPCWSTR szReaderName, LPCWSTR szGroupName); #ifdef UNICODE #define SCardAddReaderToGroup SCardAddReaderToGroupW #else #define SCardAddReaderToGroup SCardAddReaderToGroupA #endif // !UNICODE extern WINSCARDAPI LONG WINAPI SCardRemoveReaderFromGroupA( SCARDCONTEXT hContext, LPCSTR szReaderName, LPCSTR szGroupName); extern WINSCARDAPI LONG WINAPI SCardRemoveReaderFromGroupW( SCARDCONTEXT hContext, LPCWSTR szReaderName, LPCWSTR szGroupName); #ifdef UNICODE #define SCardRemoveReaderFromGroup SCardRemoveReaderFromGroupW #else #define SCardRemoveReaderFromGroup SCardRemoveReaderFromGroupA #endif // !UNICODE extern WINSCARDAPI LONG WINAPI SCardIntroduceCardTypeA( SCARDCONTEXT hContext, LPCSTR szCardName, LPCGUID pguidPrimaryProvider, LPCGUID rgguidInterfaces, DWORD dwInterfaceCount, LPCBYTE pbAtr, LPCBYTE pbAtrMask, DWORD cbAtrLen); extern WINSCARDAPI LONG WINAPI SCardIntroduceCardTypeW( SCARDCONTEXT hContext, LPCWSTR szCardName, LPCGUID pguidPrimaryProvider, LPCGUID rgguidInterfaces, DWORD dwInterfaceCount, LPCBYTE pbAtr, LPCBYTE pbAtrMask, DWORD cbAtrLen); #ifdef UNICODE #define SCardIntroduceCardType SCardIntroduceCardTypeW #else #define SCardIntroduceCardType SCardIntroduceCardTypeA #endif // !UNICODE // // NOTE: The routine SCardIntroduceCardType's parameters' order differs from // the PC/SC definition. It should be: // // extern WINSCARDAPI LONG WINAPI // SCardIntroduceCardType( // SCARDCONTEXT hContext, // LPCTSTR szCardName, // LPCBYTE pbAtr, // LPCBYTE pbAtrMask, // DWORD cbAtrLen, // LPCGUID pguidPrimaryProvider, // LPCGUID rgguidInterfaces, // DWORD dwInterfaceCount); // // Here's a work-around MACRO: #define PCSCardIntroduceCardType(hContext, szCardName, pbAtr, pbAtrMask, cbAtrLen, pguidPrimaryProvider, rgguidInterfaces, dwInterfaceCount) \ SCardIntroduceCardType(hContext, szCardName, pguidPrimaryProvider, rgguidInterfaces, dwInterfaceCount, pbAtr, pbAtrMask, cbAtrLen) extern WINSCARDAPI LONG WINAPI SCardSetCardTypeProviderNameA( SCARDCONTEXT hContext, LPCSTR szCardName, DWORD dwProviderId, LPCSTR szProvider); extern WINSCARDAPI LONG WINAPI SCardSetCardTypeProviderNameW( SCARDCONTEXT hContext, LPCWSTR szCardName, DWORD dwProviderId, LPCWSTR szProvider); #ifdef UNICODE #define SCardSetCardTypeProviderName SCardSetCardTypeProviderNameW #else #define SCardSetCardTypeProviderName SCardSetCardTypeProviderNameA #endif // !UNICODE // // NOTE: This routine is an extention to the PC/SC specifications. // extern WINSCARDAPI LONG WINAPI SCardForgetCardTypeA( SCARDCONTEXT hContext, LPCSTR szCardName); extern WINSCARDAPI LONG WINAPI SCardForgetCardTypeW( SCARDCONTEXT hContext, LPCWSTR szCardName); #ifdef UNICODE #define SCardForgetCardType SCardForgetCardTypeW #else #define SCardForgetCardType SCardForgetCardTypeA #endif // !UNICODE // //////////////////////////////////////////////////////////////////////////////// // // Service Manager Support Routines // // The following services are supplied to simplify the use of the Service // Manager API. // extern WINSCARDAPI LONG WINAPI SCardFreeMemory( SCARDCONTEXT hContext, LPCVOID pvMem); #if (NTDDI_VERSION >= NTDDI_WINXP) extern WINSCARDAPI HANDLE WINAPI SCardAccessStartedEvent(void); extern WINSCARDAPI void WINAPI SCardReleaseStartedEvent(void); #endif // (NTDDI_VERSION >= NTDDI_WINXP) // //////////////////////////////////////////////////////////////////////////////// // // Reader Services // // The following services supply means for tracking cards within readers. // typedef struct { LPCSTR szReader; // reader name LPVOID pvUserData; // user defined data DWORD dwCurrentState; // current state of reader at time of call DWORD dwEventState; // state of reader after state change DWORD cbAtr; // Number of bytes in the returned ATR. BYTE rgbAtr[36]; // Atr of inserted card, (extra alignment bytes) } SCARD_READERSTATEA, *PSCARD_READERSTATEA, *LPSCARD_READERSTATEA; typedef struct { LPCWSTR szReader; // reader name LPVOID pvUserData; // user defined data DWORD dwCurrentState; // current state of reader at time of call DWORD dwEventState; // state of reader after state change DWORD cbAtr; // Number of bytes in the returned ATR. BYTE rgbAtr[36]; // Atr of inserted card, (extra alignment bytes) } SCARD_READERSTATEW, *PSCARD_READERSTATEW, *LPSCARD_READERSTATEW; #ifdef UNICODE typedef SCARD_READERSTATEW SCARD_READERSTATE; typedef PSCARD_READERSTATEW PSCARD_READERSTATE; typedef LPSCARD_READERSTATEW LPSCARD_READERSTATE; #else typedef SCARD_READERSTATEA SCARD_READERSTATE; typedef PSCARD_READERSTATEA PSCARD_READERSTATE; typedef LPSCARD_READERSTATEA LPSCARD_READERSTATE; #endif // UNICODE // Backwards compatibility macros #define SCARD_READERSTATE_A SCARD_READERSTATEA #define SCARD_READERSTATE_W SCARD_READERSTATEW #define PSCARD_READERSTATE_A PSCARD_READERSTATEA #define PSCARD_READERSTATE_W PSCARD_READERSTATEW #define LPSCARD_READERSTATE_A LPSCARD_READERSTATEA #define LPSCARD_READERSTATE_W LPSCARD_READERSTATEW #define SCARD_STATE_UNAWARE 0x00000000 // The application is unaware of the // current state, and would like to // know. The use of this value // results in an immediate return // from state transition monitoring // services. This is represented by // all bits set to zero. #define SCARD_STATE_IGNORE 0x00000001 // The application requested that // this reader be ignored. No other // bits will be set. #define SCARD_STATE_CHANGED 0x00000002 // This implies that there is a // difference between the state // believed by the application, and // the state known by the Service // Manager. When this bit is set, // the application may assume a // significant state change has // occurred on this reader. #define SCARD_STATE_UNKNOWN 0x00000004 // This implies that the given // reader name is not recognized by // the Service Manager. If this bit // is set, then SCARD_STATE_CHANGED // and SCARD_STATE_IGNORE will also // be set. #define SCARD_STATE_UNAVAILABLE 0x00000008 // This implies that the actual // state of this reader is not // available. If this bit is set, // then all the following bits are // clear. #define SCARD_STATE_EMPTY 0x00000010 // This implies that there is not // card in the reader. If this bit // is set, all the following bits // will be clear. #define SCARD_STATE_PRESENT 0x00000020 // This implies that there is a card // in the reader. #define SCARD_STATE_ATRMATCH 0x00000040 // This implies that there is a card // in the reader with an ATR // matching one of the target cards. // If this bit is set, // SCARD_STATE_PRESENT will also be // set. This bit is only returned // on the SCardLocateCard() service. #define SCARD_STATE_EXCLUSIVE 0x00000080 // This implies that the card in the // reader is allocated for exclusive // use by another application. If // this bit is set, // SCARD_STATE_PRESENT will also be // set. #define SCARD_STATE_INUSE 0x00000100 // This implies that the card in the // reader is in use by one or more // other applications, but may be // connected to in shared mode. If // this bit is set, // SCARD_STATE_PRESENT will also be // set. #define SCARD_STATE_MUTE 0x00000200 // This implies that the card in the // reader is unresponsive or not // supported by the reader or // software. #define SCARD_STATE_UNPOWERED 0x00000400 // This implies that the card in the // reader has not been powered up. extern WINSCARDAPI LONG WINAPI SCardLocateCardsA( SCARDCONTEXT hContext, LPCSTR mszCards, LPSCARD_READERSTATEA rgReaderStates, DWORD cReaders); extern WINSCARDAPI LONG WINAPI SCardLocateCardsW( SCARDCONTEXT hContext, LPCWSTR mszCards, LPSCARD_READERSTATEW rgReaderStates, DWORD cReaders); #ifdef UNICODE #define SCardLocateCards SCardLocateCardsW #else #define SCardLocateCards SCardLocateCardsA #endif // !UNICODE #if (NTDDI_VERSION >= NTDDI_WINXP) typedef struct _SCARD_ATRMASK { DWORD cbAtr; // Number of bytes in the ATR and the mask. BYTE rgbAtr[36]; // Atr of card (extra alignment bytes) BYTE rgbMask[36]; // Mask for the Atr (extra alignment bytes) } SCARD_ATRMASK, *PSCARD_ATRMASK, *LPSCARD_ATRMASK; extern WINSCARDAPI LONG WINAPI SCardLocateCardsByATRA( SCARDCONTEXT hContext, LPSCARD_ATRMASK rgAtrMasks, DWORD cAtrs, LPSCARD_READERSTATEA rgReaderStates, DWORD cReaders); extern WINSCARDAPI LONG WINAPI SCardLocateCardsByATRW( SCARDCONTEXT hContext, LPSCARD_ATRMASK rgAtrMasks, DWORD cAtrs, LPSCARD_READERSTATEW rgReaderStates, DWORD cReaders); #ifdef UNICODE #define SCardLocateCardsByATR SCardLocateCardsByATRW #else #define SCardLocateCardsByATR SCardLocateCardsByATRA #endif // !UNICODE #endif // (NTDDI_VERSION >= NTDDI_WINXP) extern WINSCARDAPI LONG WINAPI SCardGetStatusChangeA( SCARDCONTEXT hContext, DWORD dwTimeout, LPSCARD_READERSTATEA rgReaderStates, DWORD cReaders); extern WINSCARDAPI LONG WINAPI SCardGetStatusChangeW( SCARDCONTEXT hContext, DWORD dwTimeout, LPSCARD_READERSTATEW rgReaderStates, DWORD cReaders); #ifdef UNICODE #define SCardGetStatusChange SCardGetStatusChangeW #else #define SCardGetStatusChange SCardGetStatusChangeA #endif // !UNICODE extern WINSCARDAPI LONG WINAPI SCardCancel( SCARDCONTEXT hContext); // //////////////////////////////////////////////////////////////////////////////// // // Card/Reader Communication Services // // The following services provide means for communication with the card. // #define SCARD_SHARE_EXCLUSIVE 1 // This application is not willing to share this // card with other applications. #define SCARD_SHARE_SHARED 2 // This application is willing to share this // card with other applications. #define SCARD_SHARE_DIRECT 3 // This application demands direct control of // the reader, so it is not available to other // applications. #define SCARD_LEAVE_CARD 0 // Don't do anything special on close #define SCARD_RESET_CARD 1 // Reset the card on close #define SCARD_UNPOWER_CARD 2 // Power down the card on close #define SCARD_EJECT_CARD 3 // Eject the card on close extern WINSCARDAPI LONG WINAPI SCardConnectA( SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol); extern WINSCARDAPI LONG WINAPI SCardConnectW( SCARDCONTEXT hContext, LPCWSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol); #ifdef UNICODE #define SCardConnect SCardConnectW #else #define SCardConnect SCardConnectA #endif // !UNICODE extern WINSCARDAPI LONG WINAPI SCardReconnect( SCARDHANDLE hCard, DWORD dwShareMode, DWORD dwPreferredProtocols, DWORD dwInitialization, LPDWORD pdwActiveProtocol); extern WINSCARDAPI LONG WINAPI SCardDisconnect( SCARDHANDLE hCard, DWORD dwDisposition); extern WINSCARDAPI LONG WINAPI SCardBeginTransaction( SCARDHANDLE hCard); extern WINSCARDAPI LONG WINAPI SCardEndTransaction( SCARDHANDLE hCard, DWORD dwDisposition); extern WINSCARDAPI LONG WINAPI SCardCancelTransaction( SCARDHANDLE hCard); // // NOTE: This call corresponds to the PC/SC SCARDCOMM::Cancel routine, // terminating a blocked SCardBeginTransaction service. // extern WINSCARDAPI LONG WINAPI SCardState( SCARDHANDLE hCard, LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen); // // NOTE: SCardState is an obsolete routine. PC/SC has replaced it with // SCardStatus. // extern WINSCARDAPI LONG WINAPI SCardStatusA( SCARDHANDLE hCard, LPSTR mszReaderNames, LPDWORD pcchReaderLen, LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen); extern WINSCARDAPI LONG WINAPI SCardStatusW( SCARDHANDLE hCard, LPWSTR mszReaderNames, LPDWORD pcchReaderLen, LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen); #ifdef UNICODE #define SCardStatus SCardStatusW #else #define SCardStatus SCardStatusA #endif // !UNICODE extern WINSCARDAPI LONG WINAPI SCardTransmit( SCARDHANDLE hCard, LPCSCARD_IO_REQUEST pioSendPci, LPCBYTE pbSendBuffer, DWORD cbSendLength, LPSCARD_IO_REQUEST pioRecvPci, LPBYTE pbRecvBuffer, LPDWORD pcbRecvLength); #if (NTDDI_VERSION >= NTDDI_VISTA) extern WINSCARDAPI LONG WINAPI SCardGetTransmitCount( SCARDHANDLE hCard, LPDWORD pcTransmitCount); #endif // (NTDDI_VERSION >= NTDDI_VISTA) // //////////////////////////////////////////////////////////////////////////////// // // Reader Control Routines // // The following services provide for direct, low-level manipulation of the // reader by the calling application allowing it control over the // attributes of the communications with the card. // extern WINSCARDAPI LONG WINAPI SCardControl( SCARDHANDLE hCard, DWORD dwControlCode, LPCVOID lpInBuffer, DWORD cbInBufferSize, LPVOID lpOutBuffer, DWORD cbOutBufferSize, LPDWORD lpBytesReturned); extern WINSCARDAPI LONG WINAPI SCardGetAttrib( SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE pbAttr, LPDWORD pcbAttrLen); // // NOTE: The routine SCardGetAttrib's name differs from the PC/SC definition. // It should be: // // extern WINSCARDAPI LONG WINAPI // SCardGetReaderCapabilities( // SCARDHANDLE hCard, // DWORD dwTag, // LPBYTE pbAttr, // out LPDWORD pcbAttrLen); // // Here's a work-around MACRO: #define SCardGetReaderCapabilities SCardGetAttrib extern WINSCARDAPI LONG WINAPI SCardSetAttrib( SCARDHANDLE hCard, DWORD dwAttrId, LPCBYTE pbAttr, DWORD cbAttrLen); // // NOTE: The routine SCardSetAttrib's name differs from the PC/SC definition. // It should be: // // extern WINSCARDAPI LONG WINAPI // SCardSetReaderCapabilities( // SCARDHANDLE hCard, // DWORD dwTag, // LPCBYTE pbAttr, // DWORD cbAttrLen); // // Here's a work-around MACRO: #define SCardSetReaderCapabilities SCardSetAttrib // //////////////////////////////////////////////////////////////////////////////// // // Smart Card Dialog definitions // // The following section contains structures and exported function // declarations for the Smart Card Common Dialog dialog. // // Defined constants // Flags #define SC_DLG_MINIMAL_UI 0x01 #define SC_DLG_NO_UI 0x02 #define SC_DLG_FORCE_UI 0x04 #define SCERR_NOCARDNAME 0x4000 #define SCERR_NOGUIDS 0x8000 typedef SCARDHANDLE (WINAPI *LPOCNCONNPROCA) ( SCARDCONTEXT, LPSTR, LPSTR, PVOID); typedef SCARDHANDLE (WINAPI *LPOCNCONNPROCW) ( SCARDCONTEXT, LPWSTR, LPWSTR, PVOID); #ifdef UNICODE #define LPOCNCONNPROC LPOCNCONNPROCW #else #define LPOCNCONNPROC LPOCNCONNPROCA #endif // !UNICODE typedef BOOL (WINAPI *LPOCNCHKPROC) ( SCARDCONTEXT, SCARDHANDLE, PVOID); typedef void (WINAPI *LPOCNDSCPROC) ( SCARDCONTEXT, SCARDHANDLE, PVOID); // // OPENCARD_SEARCH_CRITERIA: In order to specify a user-extended search, // lpfnCheck must not be NULL. Moreover, the connection to be made to the // card before performing the callback must be indicated by either providing // lpfnConnect and lpfnDisconnect OR by setting dwShareMode. // If both the connection callbacks and dwShareMode are non-NULL, the callbacks // will be used. // typedef struct { DWORD dwStructSize; LPSTR lpstrGroupNames; // OPTIONAL reader groups to include in DWORD nMaxGroupNames; // search. NULL defaults to // SCard$DefaultReaders LPCGUID rgguidInterfaces; // OPTIONAL requested interfaces DWORD cguidInterfaces; // supported by card's SSP LPSTR lpstrCardNames; // OPTIONAL requested card names; all cards w/ DWORD nMaxCardNames; // matching ATRs will be accepted LPOCNCHKPROC lpfnCheck; // OPTIONAL if NULL no user check will be performed. LPOCNCONNPROCA lpfnConnect; // OPTIONAL if lpfnConnect is provided, LPOCNDSCPROC lpfnDisconnect; // lpfnDisconnect must also be set. LPVOID pvUserData; // OPTIONAL parameter to callbacks DWORD dwShareMode; // OPTIONAL must be set if lpfnCheck is not null DWORD dwPreferredProtocols; // OPTIONAL } OPENCARD_SEARCH_CRITERIAA, *POPENCARD_SEARCH_CRITERIAA, *LPOPENCARD_SEARCH_CRITERIAA; typedef struct { DWORD dwStructSize; LPWSTR lpstrGroupNames; // OPTIONAL reader groups to include in DWORD nMaxGroupNames; // search. NULL defaults to // SCard$DefaultReaders LPCGUID rgguidInterfaces; // OPTIONAL requested interfaces DWORD cguidInterfaces; // supported by card's SSP LPWSTR lpstrCardNames; // OPTIONAL requested card names; all cards w/ DWORD nMaxCardNames; // matching ATRs will be accepted LPOCNCHKPROC lpfnCheck; // OPTIONAL if NULL no user check will be performed. LPOCNCONNPROCW lpfnConnect; // OPTIONAL if lpfnConnect is provided, LPOCNDSCPROC lpfnDisconnect; // lpfnDisconnect must also be set. LPVOID pvUserData; // OPTIONAL parameter to callbacks DWORD dwShareMode; // OPTIONAL must be set if lpfnCheck is not null DWORD dwPreferredProtocols; // OPTIONAL } OPENCARD_SEARCH_CRITERIAW, *POPENCARD_SEARCH_CRITERIAW, *LPOPENCARD_SEARCH_CRITERIAW; #ifdef UNICODE typedef OPENCARD_SEARCH_CRITERIAW OPENCARD_SEARCH_CRITERIA; typedef POPENCARD_SEARCH_CRITERIAW POPENCARD_SEARCH_CRITERIA; typedef LPOPENCARD_SEARCH_CRITERIAW LPOPENCARD_SEARCH_CRITERIA; #else typedef OPENCARD_SEARCH_CRITERIAA OPENCARD_SEARCH_CRITERIA; typedef POPENCARD_SEARCH_CRITERIAA POPENCARD_SEARCH_CRITERIA; typedef LPOPENCARD_SEARCH_CRITERIAA LPOPENCARD_SEARCH_CRITERIA; #endif // UNICODE // // OPENCARDNAME_EX: used by SCardUIDlgSelectCard; replaces obsolete OPENCARDNAME // typedef struct { DWORD dwStructSize; // REQUIRED SCARDCONTEXT hSCardContext; // REQUIRED HWND hwndOwner; // OPTIONAL DWORD dwFlags; // OPTIONAL -- default is SC_DLG_MINIMAL_UI LPCSTR lpstrTitle; // OPTIONAL LPCSTR lpstrSearchDesc; // OPTIONAL (eg. "Please insert your <brandname> smart card.") HICON hIcon; // OPTIONAL 32x32 icon for your brand insignia POPENCARD_SEARCH_CRITERIAA pOpenCardSearchCriteria; // OPTIONAL LPOCNCONNPROCA lpfnConnect; // OPTIONAL - performed on successful selection LPVOID pvUserData; // OPTIONAL parameter to lpfnConnect DWORD dwShareMode; // OPTIONAL - if lpfnConnect is NULL, dwShareMode and DWORD dwPreferredProtocols; // OPTIONAL dwPreferredProtocols will be used to // connect to the selected card LPSTR lpstrRdr; // REQUIRED [IN|OUT] Name of selected reader DWORD nMaxRdr; // REQUIRED [IN|OUT] LPSTR lpstrCard; // REQUIRED [IN|OUT] Name of selected card DWORD nMaxCard; // REQUIRED [IN|OUT] DWORD dwActiveProtocol; // [OUT] set only if dwShareMode not NULL SCARDHANDLE hCardHandle; // [OUT] set if a card connection was indicated } OPENCARDNAME_EXA, *POPENCARDNAME_EXA, *LPOPENCARDNAME_EXA; typedef struct { DWORD dwStructSize; // REQUIRED SCARDCONTEXT hSCardContext; // REQUIRED HWND hwndOwner; // OPTIONAL DWORD dwFlags; // OPTIONAL -- default is SC_DLG_MINIMAL_UI LPCWSTR lpstrTitle; // OPTIONAL LPCWSTR lpstrSearchDesc; // OPTIONAL (eg. "Please insert your <brandname> smart card.") HICON hIcon; // OPTIONAL 32x32 icon for your brand insignia POPENCARD_SEARCH_CRITERIAW pOpenCardSearchCriteria; // OPTIONAL LPOCNCONNPROCW lpfnConnect; // OPTIONAL - performed on successful selection LPVOID pvUserData; // OPTIONAL parameter to lpfnConnect DWORD dwShareMode; // OPTIONAL - if lpfnConnect is NULL, dwShareMode and DWORD dwPreferredProtocols; // OPTIONAL dwPreferredProtocols will be used to // connect to the selected card LPWSTR lpstrRdr; // REQUIRED [IN|OUT] Name of selected reader DWORD nMaxRdr; // REQUIRED [IN|OUT] LPWSTR lpstrCard; // REQUIRED [IN|OUT] Name of selected card DWORD nMaxCard; // REQUIRED [IN|OUT] DWORD dwActiveProtocol; // [OUT] set only if dwShareMode not NULL SCARDHANDLE hCardHandle; // [OUT] set if a card connection was indicated } OPENCARDNAME_EXW, *POPENCARDNAME_EXW, *LPOPENCARDNAME_EXW; #ifdef UNICODE typedef OPENCARDNAME_EXW OPENCARDNAME_EX; typedef POPENCARDNAME_EXW POPENCARDNAME_EX; typedef LPOPENCARDNAME_EXW LPOPENCARDNAME_EX; #else typedef OPENCARDNAME_EXA OPENCARDNAME_EX; typedef POPENCARDNAME_EXA POPENCARDNAME_EX; typedef LPOPENCARDNAME_EXA LPOPENCARDNAME_EX; #endif // UNICODE #define OPENCARDNAMEA_EX OPENCARDNAME_EXA #define OPENCARDNAMEW_EX OPENCARDNAME_EXW #define POPENCARDNAMEA_EX POPENCARDNAME_EXA #define POPENCARDNAMEW_EX POPENCARDNAME_EXW #define LPOPENCARDNAMEA_EX LPOPENCARDNAME_EXA #define LPOPENCARDNAMEW_EX LPOPENCARDNAME_EXW // // SCardUIDlgSelectCard replaces GetOpenCardName // extern WINSCARDAPI LONG WINAPI SCardUIDlgSelectCardA( LPOPENCARDNAMEA_EX); extern WINSCARDAPI LONG WINAPI SCardUIDlgSelectCardW( LPOPENCARDNAMEW_EX); #ifdef UNICODE #define SCardUIDlgSelectCard SCardUIDlgSelectCardW #else #define SCardUIDlgSelectCard SCardUIDlgSelectCardA #endif // !UNICODE // // "Smart Card Common Dialog" definitions for backwards compatibility // with the Smart Card Base Services SDK version 1.0 // typedef struct { DWORD dwStructSize; HWND hwndOwner; SCARDCONTEXT hSCardContext; LPSTR lpstrGroupNames; DWORD nMaxGroupNames; LPSTR lpstrCardNames; DWORD nMaxCardNames; LPCGUID rgguidInterfaces; DWORD cguidInterfaces; LPSTR lpstrRdr; DWORD nMaxRdr; LPSTR lpstrCard; DWORD nMaxCard; LPCSTR lpstrTitle; DWORD dwFlags; LPVOID pvUserData; DWORD dwShareMode; DWORD dwPreferredProtocols; DWORD dwActiveProtocol; LPOCNCONNPROCA lpfnConnect; LPOCNCHKPROC lpfnCheck; LPOCNDSCPROC lpfnDisconnect; SCARDHANDLE hCardHandle; } OPENCARDNAMEA, *POPENCARDNAMEA, *LPOPENCARDNAMEA; typedef struct { DWORD dwStructSize; HWND hwndOwner; SCARDCONTEXT hSCardContext; LPWSTR lpstrGroupNames; DWORD nMaxGroupNames; LPWSTR lpstrCardNames; DWORD nMaxCardNames; LPCGUID rgguidInterfaces; DWORD cguidInterfaces; LPWSTR lpstrRdr; DWORD nMaxRdr; LPWSTR lpstrCard; DWORD nMaxCard; LPCWSTR lpstrTitle; DWORD dwFlags; LPVOID pvUserData; DWORD dwShareMode; DWORD dwPreferredProtocols; DWORD dwActiveProtocol; LPOCNCONNPROCW lpfnConnect; LPOCNCHKPROC lpfnCheck; LPOCNDSCPROC lpfnDisconnect; SCARDHANDLE hCardHandle; } OPENCARDNAMEW, *POPENCARDNAMEW, *LPOPENCARDNAMEW; #ifdef UNICODE typedef OPENCARDNAMEW OPENCARDNAME; typedef POPENCARDNAMEW POPENCARDNAME; typedef LPOPENCARDNAMEW LPOPENCARDNAME; #else typedef OPENCARDNAMEA OPENCARDNAME; typedef POPENCARDNAMEA POPENCARDNAME; typedef LPOPENCARDNAMEA LPOPENCARDNAME; #endif // UNICODE // Backwards compatibility macros #define OPENCARDNAME_A OPENCARDNAMEA #define OPENCARDNAME_W OPENCARDNAMEW #define POPENCARDNAME_A POPENCARDNAMEA #define POPENCARDNAME_W POPENCARDNAMEW #define LPOPENCARDNAME_A LPOPENCARDNAMEA #define LPOPENCARDNAME_W LPOPENCARDNAMEW extern WINSCARDAPI LONG WINAPI GetOpenCardNameA( LPOPENCARDNAMEA); extern WINSCARDAPI LONG WINAPI GetOpenCardNameW( LPOPENCARDNAMEW); #ifdef UNICODE #define GetOpenCardName GetOpenCardNameW #else #define GetOpenCardName GetOpenCardNameA #endif // !UNICODE extern WINSCARDAPI LONG WINAPI SCardDlgExtendedError (void); #if (NTDDI_VERSION >= NTDDI_VISTA) // // Smartcard Caching API // extern WINSCARDAPI LONG WINAPI SCardReadCacheA( SCARDCONTEXT hContext, UUID *CardIdentifier, DWORD FreshnessCounter, LPSTR LookupName, PBYTE Data, DWORD *DataLen); extern WINSCARDAPI LONG WINAPI SCardReadCacheW( SCARDCONTEXT hContext, UUID *CardIdentifier, DWORD FreshnessCounter, LPWSTR LookupName, PBYTE Data, DWORD *DataLen); #ifdef UNICODE #define SCardReadCache SCardReadCacheW #else #define SCardReadCache SCardReadCacheA #endif // !UNICODE extern WINSCARDAPI LONG WINAPI SCardWriteCacheA( SCARDCONTEXT hContext, UUID *CardIdentifier, DWORD FreshnessCounter, LPSTR LookupName, PBYTE Data, DWORD DataLen); extern WINSCARDAPI LONG WINAPI SCardWriteCacheW( SCARDCONTEXT hContext, UUID *CardIdentifier, DWORD FreshnessCounter, LPWSTR LookupName, PBYTE Data, DWORD DataLen); #ifdef UNICODE #define SCardWriteCache SCardWriteCacheW #else #define SCardWriteCache SCardWriteCacheA #endif // !UNICODE #endif // (NTDDI_VERSION >= NTDDI_VISTA) #ifdef __cplusplus } #endif #endif // _WINSCARD_H_ |
< < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted build/cackey_win32_build/include/winsmcrd.h version [7735605d6f].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
/*++ Copyright (c) 1996 Microsoft Corporation Module Name: winsmcrd.h Abstract: Smart Card class/port IOCTL codes. This file is required for all code user mode and kernel mode, using Smart Card IOCTL's, defines, data structures Revision History: --*/ #ifndef _NTDDSCRD_H2_ #define _NTDDSCRD_H2_ #if defined (_MSC_VER) && (_MSC_VER >= 1020) #pragma once #endif #ifdef __cplusplus extern "C" { #endif #ifdef _WINSCARD_H_ typedef DWORD ULONG; typedef WORD UWORD; typedef BYTE UCHAR; #else typedef ULONG DWORD; // typedef UWORD WORD; typedef UCHAR BYTE; #endif #ifndef DEVICE_TYPE_SMARTCARD #ifndef FILE_DEVICE_SMARTCARD #define FILE_DEVICE_SMARTCARD 0x00000031 #endif #else #if 0x00000031 != FILE_DEVICE_SMARTCARD #error "Incorrect Smart Card Device Definition" #endif #endif // // Various constants // #define SCARD_ATR_LENGTH 33 // ISO 7816-3 spec. // /////////////////////////////////////////////////////////////////////////////// // // Protocol Flag definitions // #define SCARD_PROTOCOL_UNDEFINED 0x00000000 // There is no active protocol. #define SCARD_PROTOCOL_T0 0x00000001 // T=0 is the active protocol. #define SCARD_PROTOCOL_T1 0x00000002 // T=1 is the active protocol. #define SCARD_PROTOCOL_RAW 0x00010000 // Raw is the active protocol. // // This is the mask of ISO defined transmission protocols // #define SCARD_PROTOCOL_Tx (SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1) // // Use the default transmission parameters / card clock freq. // #define SCARD_PROTOCOL_DEFAULT 0x80000000 // // Use optimal transmission parameters / card clock freq. // Since using the optimal parameters is the default case no bit is defined to be 1 // #define SCARD_PROTOCOL_OPTIMAL 0x00000000 // // Ioctl parameters 1 for IOCTL_SMARTCARD_POWER // #define SCARD_POWER_DOWN 0 // Power down the card. #define SCARD_COLD_RESET 1 // Cycle power and reset the card. #define SCARD_WARM_RESET 2 // Force a reset on the card. // /////////////////////////////////////////////////////////////////////////////// // // Reader Action IOCTLs // #define SCARD_CTL_CODE(code) CTL_CODE(FILE_DEVICE_SMARTCARD, \ (code), \ METHOD_BUFFERED, \ FILE_ANY_ACCESS) #define IOCTL_SMARTCARD_POWER SCARD_CTL_CODE( 1) #define IOCTL_SMARTCARD_GET_ATTRIBUTE SCARD_CTL_CODE( 2) #define IOCTL_SMARTCARD_SET_ATTRIBUTE SCARD_CTL_CODE( 3) #define IOCTL_SMARTCARD_CONFISCATE SCARD_CTL_CODE( 4) #define IOCTL_SMARTCARD_TRANSMIT SCARD_CTL_CODE( 5) #define IOCTL_SMARTCARD_EJECT SCARD_CTL_CODE( 6) #define IOCTL_SMARTCARD_SWALLOW SCARD_CTL_CODE( 7) // #define IOCTL_SMARTCARD_READ SCARD_CTL_CODE( 8) obsolete // #define IOCTL_SMARTCARD_WRITE SCARD_CTL_CODE( 9) obsolete #define IOCTL_SMARTCARD_IS_PRESENT SCARD_CTL_CODE(10) #define IOCTL_SMARTCARD_IS_ABSENT SCARD_CTL_CODE(11) #define IOCTL_SMARTCARD_SET_PROTOCOL SCARD_CTL_CODE(12) #define IOCTL_SMARTCARD_GET_STATE SCARD_CTL_CODE(14) #define IOCTL_SMARTCARD_GET_LAST_ERROR SCARD_CTL_CODE(15) #define IOCTL_SMARTCARD_GET_PERF_CNTR SCARD_CTL_CODE(16) // /////////////////////////////////////////////////////////////////////////////// // // Tags for requesting card and reader attributes // #define MAXIMUM_ATTR_STRING_LENGTH 32 // Nothing bigger than this from getAttr #define MAXIMUM_SMARTCARD_READERS 10 // Limit the readers on the system #define SCARD_ATTR_VALUE(Class, Tag) ((((ULONG)(Class)) << 16) | ((ULONG)(Tag))) #define SCARD_CLASS_VENDOR_INFO 1 // Vendor information definitions #define SCARD_CLASS_COMMUNICATIONS 2 // Communication definitions #define SCARD_CLASS_PROTOCOL 3 // Protocol definitions #define SCARD_CLASS_POWER_MGMT 4 // Power Management definitions #define SCARD_CLASS_SECURITY 5 // Security Assurance definitions #define SCARD_CLASS_MECHANICAL 6 // Mechanical characteristic definitions #define SCARD_CLASS_VENDOR_DEFINED 7 // Vendor specific definitions #define SCARD_CLASS_IFD_PROTOCOL 8 // Interface Device Protocol options #define SCARD_CLASS_ICC_STATE 9 // ICC State specific definitions #define SCARD_CLASS_PERF 0x7ffe // performace counters #define SCARD_CLASS_SYSTEM 0x7fff // System-specific definitions #define SCARD_ATTR_VENDOR_NAME SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0100) #define SCARD_ATTR_VENDOR_IFD_TYPE SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0101) #define SCARD_ATTR_VENDOR_IFD_VERSION SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0102) #define SCARD_ATTR_VENDOR_IFD_SERIAL_NO SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0103) #define SCARD_ATTR_CHANNEL_ID SCARD_ATTR_VALUE(SCARD_CLASS_COMMUNICATIONS, 0x0110) #define SCARD_ATTR_PROTOCOL_TYPES SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0120) // #define SCARD_ATTR_ASYNC_PROTOCOL_TYPES SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0120) #define SCARD_ATTR_DEFAULT_CLK SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0121) #define SCARD_ATTR_MAX_CLK SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0122) #define SCARD_ATTR_DEFAULT_DATA_RATE SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0123) #define SCARD_ATTR_MAX_DATA_RATE SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0124) #define SCARD_ATTR_MAX_IFSD SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0125) // #define SCARD_ATTR_SYNC_PROTOCOL_TYPES SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0126) #define SCARD_ATTR_POWER_MGMT_SUPPORT SCARD_ATTR_VALUE(SCARD_CLASS_POWER_MGMT, 0x0131) #define SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE SCARD_ATTR_VALUE(SCARD_CLASS_SECURITY, 0x0140) #define SCARD_ATTR_USER_AUTH_INPUT_DEVICE SCARD_ATTR_VALUE(SCARD_CLASS_SECURITY, 0x0142) #define SCARD_ATTR_CHARACTERISTICS SCARD_ATTR_VALUE(SCARD_CLASS_MECHANICAL, 0x0150) #define SCARD_ATTR_CURRENT_PROTOCOL_TYPE SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0201) #define SCARD_ATTR_CURRENT_CLK SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0202) #define SCARD_ATTR_CURRENT_F SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0203) #define SCARD_ATTR_CURRENT_D SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0204) #define SCARD_ATTR_CURRENT_N SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0205) #define SCARD_ATTR_CURRENT_W SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0206) #define SCARD_ATTR_CURRENT_IFSC SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0207) #define SCARD_ATTR_CURRENT_IFSD SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0208) #define SCARD_ATTR_CURRENT_BWT SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0209) #define SCARD_ATTR_CURRENT_CWT SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x020a) #define SCARD_ATTR_CURRENT_EBC_ENCODING SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x020b) #define SCARD_ATTR_EXTENDED_BWT SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x020c) #define SCARD_ATTR_ICC_PRESENCE SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0300) #define SCARD_ATTR_ICC_INTERFACE_STATUS SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0301) #define SCARD_ATTR_CURRENT_IO_STATE SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0302) #define SCARD_ATTR_ATR_STRING SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0303) #define SCARD_ATTR_ICC_TYPE_PER_ATR SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0304) #define SCARD_ATTR_ESC_RESET SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA000) #define SCARD_ATTR_ESC_CANCEL SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA003) #define SCARD_ATTR_ESC_AUTHREQUEST SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA005) #define SCARD_ATTR_MAXINPUT SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA007) #define SCARD_ATTR_DEVICE_UNIT SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0001) #define SCARD_ATTR_DEVICE_IN_USE SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0002) #define SCARD_ATTR_DEVICE_FRIENDLY_NAME_A SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0003) #define SCARD_ATTR_DEVICE_SYSTEM_NAME_A SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0004) #define SCARD_ATTR_DEVICE_FRIENDLY_NAME_W SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0005) #define SCARD_ATTR_DEVICE_SYSTEM_NAME_W SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0006) #define SCARD_ATTR_SUPRESS_T1_IFS_REQUEST SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0007) #define SCARD_PERF_NUM_TRANSMISSIONS SCARD_ATTR_VALUE(SCARD_CLASS_PERF, 0x0001) #define SCARD_PERF_BYTES_TRANSMITTED SCARD_ATTR_VALUE(SCARD_CLASS_PERF, 0x0002) #define SCARD_PERF_TRANSMISSION_TIME SCARD_ATTR_VALUE(SCARD_CLASS_PERF, 0x0003) #ifdef UNICODE #define SCARD_ATTR_DEVICE_FRIENDLY_NAME SCARD_ATTR_DEVICE_FRIENDLY_NAME_W #define SCARD_ATTR_DEVICE_SYSTEM_NAME SCARD_ATTR_DEVICE_SYSTEM_NAME_W #else #define SCARD_ATTR_DEVICE_FRIENDLY_NAME SCARD_ATTR_DEVICE_FRIENDLY_NAME_A #define SCARD_ATTR_DEVICE_SYSTEM_NAME SCARD_ATTR_DEVICE_SYSTEM_NAME_A #endif // // T=0 Protocol Defines // #define SCARD_T0_HEADER_LENGTH 7 #define SCARD_T0_CMD_LENGTH 5 // // T=1 Protocol Defines // #define SCARD_T1_PROLOGUE_LENGTH 3 #define SCARD_T1_EPILOGUE_LENGTH 2 #define SCARD_T1_MAX_IFS 254 // /////////////////////////////////////////////////////////////////////////////// // // Reader states // #define SCARD_UNKNOWN 0 // This value implies the driver is unaware // of the current state of the reader. #define SCARD_ABSENT 1 // This value implies there is no card in // the reader. #define SCARD_PRESENT 2 // This value implies there is a card is // present in the reader, but that it has // not been moved into position for use. #define SCARD_SWALLOWED 3 // This value implies there is a card in the // reader in position for use. The card is // not powered. #define SCARD_POWERED 4 // This value implies there is power is // being provided to the card, but the // Reader Driver is unaware of the mode of // the card. #define SCARD_NEGOTIABLE 5 // This value implies the card has been // reset and is awaiting PTS negotiation. #define SCARD_SPECIFIC 6 // This value implies the card has been // reset and specific communication // protocols have been established. //////////////////////////////////////////////////////////////////////////////// // // I/O Services // // The following services provide access to the I/O capabilities of the // reader drivers. Services of the Smart Card are requested by placing the // following structure into the protocol buffer: // typedef struct _SCARD_IO_REQUEST{ DWORD dwProtocol; // Protocol identifier DWORD cbPciLength; // Protocol Control Information Length } SCARD_IO_REQUEST, *PSCARD_IO_REQUEST, *LPSCARD_IO_REQUEST; typedef const SCARD_IO_REQUEST *LPCSCARD_IO_REQUEST; // // T=0 protocol services. // typedef struct { BYTE bCla, // The instruction class bIns, // The instruction code within the instruction class bP1, bP2, // Parameters to the instruction bP3; // Size of I/O Transfer } SCARD_T0_COMMAND, *LPSCARD_T0_COMMAND; typedef struct { SCARD_IO_REQUEST ioRequest; BYTE bSw1, bSw2; // Return codes from the instruction union { SCARD_T0_COMMAND CmdBytes; BYTE rgbHeader[5]; } DUMMYUNIONNAME; } SCARD_T0_REQUEST; typedef SCARD_T0_REQUEST *PSCARD_T0_REQUEST, *LPSCARD_T0_REQUEST; // // T=1 Protocol Services // typedef struct { SCARD_IO_REQUEST ioRequest; } SCARD_T1_REQUEST; typedef SCARD_T1_REQUEST *PSCARD_T1_REQUEST, *LPSCARD_T1_REQUEST; // //////////////////////////////////////////////////////////////////////////////// // // Driver attribute flags // #define SCARD_READER_SWALLOWS 0x00000001 // Reader has a card swallowing // mechanism. #define SCARD_READER_EJECTS 0x00000002 // Reader has a card ejection // mechanism. #define SCARD_READER_CONFISCATES 0x00000004 // Reader has a card capture // mechanism. // /////////////////////////////////////////////////////////////////////////////// // // Type of reader // #define SCARD_READER_TYPE_SERIAL 0x01 #define SCARD_READER_TYPE_PARALELL 0x02 #define SCARD_READER_TYPE_KEYBOARD 0x04 #define SCARD_READER_TYPE_SCSI 0x08 #define SCARD_READER_TYPE_IDE 0x10 #define SCARD_READER_TYPE_USB 0x20 #define SCARD_READER_TYPE_PCMCIA 0x40 #define SCARD_READER_TYPE_VENDOR 0xF0 #ifdef __cplusplus } #endif #endif |
< < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted build/cackey_win32_build/lib/winscard.dll version [c65243081f].
cannot compute difference between binary files
Deleted build/cackey_win32_build/lib/winscard.lib version [eadd06eb72].
cannot compute difference between binary files
Modified build/certs-to-c from [c49efbf6f1] to [1cd87f2aca].
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
continue fi openssl x509 -in "${file}" -out tmpfile.x509 -inform pem -outform der pubkeylen="$(openssl x509 -in tmpfile.x509 -inform der -text -noout | grep 'RSA Public Key:' | sed 's@^.*(\([0-9][0-9]*\) bit).*$@\1@')" certlen="$(stat -c '%s' tmpfile.x509)" cert="$(( cat tmpfile.x509 | od -t x1 | cut -c 9- | tr "\n" ' '; echo ) | sed 's@ @@g;s@..@\\x&@g')" cat << _EOF_ { {0}, 0, ${certlen}, (unsigned char *) "${cert}", ${pubkeylen} }, _EOF_ done rm -f tmpfile.x509 |
| | < | | | |
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
continue fi openssl x509 -in "${file}" -out tmpfile.x509 -inform pem -outform der pubkeylen="$(openssl x509 -in tmpfile.x509 -inform der -text -noout | grep 'RSA Public Key:' | sed 's@^.*(\([0-9][0-9]*\) bit).*$@\1@')" certlen="$(cat tmpfile.x509 | wc -c)" cert="$(( cat tmpfile.x509 | od -t x1 | cut -c 9- | tr "\n" ' '; echo ) | sed 's@ @@g;s@..@\\x&@g')" cat << _EOF_ { CACKEY_ID_TYPE_CERT_ONLY, /* id_type */ ${certlen}, /* certificate_len */ (unsigned char *) "${cert}", /* certificate */ ${pubkeylen} /* keysize */ }, _EOF_ done rm -f tmpfile.x509 |
Modified cackey.c from [711a90f529] to [60fa6fcd12].
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 .. 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 ... 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 ... 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 ... 205 206 207 208 209 210 211 212 213 214 215 216 217 218 ... 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 ... 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 ... 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 ... 709 710 711 712 713 714 715 716 717 718 719 720 721 722 ... 725 726 727 728 729 730 731 732 733 734 735 736 737 738 ... 794 795 796 797 798 799 800 801 802 803 804 805 806 807 ... 857 858 859 860 861 862 863 864 865 866 867 868 869 870 .... 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 .... 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 .... 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 .... 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 .... 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 .... 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 .... 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 .... 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 .... 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 .... 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 .... 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 .... 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 .... 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 .... 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 .... 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 .... 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 .... 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 .... 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 .... 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 .... 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 .... 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 .... 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 .... 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 .... 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 .... 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 .... 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 .... 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 .... 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 .... 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 .... 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 .... 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 .... 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 .... 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 .... 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 .... 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 .... 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 .... 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 .... 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 .... 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 .... 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 .... 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 |
#endif #ifdef HAVE_LIMITS_H # include <limits.h> #endif #ifdef HAVE_STDIO_H # include <stdio.h> #endif #ifdef HAVE_ZLIB_H # ifdef HAVE_LIBZ # include <zlib.h> # endif #else # ifdef HAVE_LIBZ # undef HAVE_LIBZ # endif #endif #define CK_PTR * #define CK_DEFINE_FUNCTION(returnType, name) returnType name #define CK_DECLARE_FUNCTION(returnType, name) returnType name #define CK_DECLARE_FUNCTION_POINTER(returnType, name) returnType (* name) #define CK_CALLBACK_FUNCTION(returnType, name) returnType (* name) ................................................................................ #include "pkcs11.h" #include "pkcs11n.h" #include "asn1-x509.h" #include "sha1.h" #include "md5.h" /* * Include these source files in this translation unit so that we can bind to * functions and not include any symbols in the output shared object. */ #include "asn1-x509.c" #include "sha1.c" #include "md5.c" #ifndef CACKEY_CRYPTOKI_VERSION_CODE # define CACKEY_CRYPTOKI_VERSION_CODE 0x021e00 #endif /* GSC-IS v2.1 Definitions */ /** Classes **/ #define GSCIS_CLASS_ISO7816 0x00 ................................................................................ #define GSCIS_TAG_SERNO 0x51 #define GSCIS_TAG_ISSUE_DATE 0x52 #define GSCIS_TAG_EXPIRE_DATE 0x53 #define GSCIS_TAG_CARD_TYPE 0x54 #define GSCIS_TAG_SECURITY_CODE 0x57 #define GSCIS_TAG_CARDID_AID 0x58 /*** PKI Information - EF 7000 ***/ #define GSCIS_TAG_CERTIFICATE 0x70 #define GSCIS_TAG_CERT_ISSUE_DATE 0x71 #define GSCIS_TAG_CERT_EXPIRE_DATE 0x72 /** Applet IDs **/ #define GSCIS_AID_CCC 0xA0, 0x00, 0x00, 0x01, 0x16, 0xDB, 0x00 /* Maximum size of data portion of APDUs */ /** Do not set this above 250 **/ #define CACKEY_APDU_MTU 250 /* ATR If not available */ #ifndef MAX_ATR_SIZE ................................................................................ #define MAX_ATR_SIZE 1024 #endif #ifdef CACKEY_DEBUG # ifdef HAVE_TIME_H # include <time.h> static time_t cackey_debug_start_time = 0; # define CACKEY_DEBUG_PRINTTIME { if (cackey_debug_start_time == 0) { cackey_debug_start_time = time(NULL); }; fprintf(cackey_debug_fd(), "[%lu]: ", (unsigned long) (time(NULL) - cackey_debug_start_time)); } # else # define CACKEY_DEBUG_PRINTTIME /**/ # endif # define CACKEY_DEBUG_PRINTF(x...) { CACKEY_DEBUG_PRINTTIME; fprintf(cackey_debug_fd(), "%s():%i: ", __func__, __LINE__); fprintf(cackey_debug_fd(), x); fprintf(cackey_debug_fd(), "\n"); fflush(cackey_debug_fd()); } # define CACKEY_DEBUG_PRINTBUF(f, x, y) { unsigned char *TMPBUF; unsigned long idx; TMPBUF = (unsigned char *) (x); CACKEY_DEBUG_PRINTTIME; fprintf(cackey_debug_fd(), "%s():%i: %s (%s/%lu = {%02x", __func__, __LINE__, f, #x, (unsigned long) (y), TMPBUF[0]); for (idx = 1; idx < (y); idx++) { fprintf(cackey_debug_fd(), ", %02x", TMPBUF[idx]); }; fprintf(cackey_debug_fd(), "})\n"); fflush(cackey_debug_fd()); } # define CACKEY_DEBUG_PERROR(x) { fprintf(cackey_debug_fd(), "%s():%i: ", __func__, __LINE__); CACKEY_DEBUG_PRINTTIME; perror(x); fflush(cackey_debug_fd()); } # define free(x) { CACKEY_DEBUG_PRINTF("FREE(%p) (%s)", (void *) x, #x); free(x); } static FILE *cackey_debug_fd(void) { static FILE *fd = NULL; char *logfile; if (fd != NULL) { ................................................................................ logfile = strchr(logfile, '='); if (logfile == NULL) { logfile = getenv("CACKEY_DEBUG_LOGFILE"); } else { logfile++; } } if (logfile != NULL) { CACKEY_DEBUG_PRINTF("Found log file: %s", logfile); fd = fopen(logfile, "a"); } ................................................................................ } static void *CACKEY_DEBUG_FUNC_MALLOC(size_t size, const char *func, int line) { void *retval; retval = malloc(size); CACKEY_DEBUG_PRINTTIME; fprintf(cackey_debug_fd(), "%s():%i: ", func, line); fprintf(cackey_debug_fd(), "MALLOC() = %p", retval); fprintf(cackey_debug_fd(), "\n"); fflush(cackey_debug_fd()); return(retval); } static void *CACKEY_DEBUG_FUNC_REALLOC(void *ptr, size_t size, const char *func, int line) { void *retval; retval = realloc(ptr, size); if (retval != ptr) { CACKEY_DEBUG_PRINTTIME; fprintf(cackey_debug_fd(), "%s():%i: ", func, line); fprintf(cackey_debug_fd(), "REALLOC(%p) = %p", ptr, retval); fprintf(cackey_debug_fd(), "\n"); fflush(cackey_debug_fd()); } if (retval == NULL) { CACKEY_DEBUG_PRINTF(" *** ERROR *** realloc returned NULL (size = %lu)", (unsigned long) size); } ................................................................................ } static char *CACKEY_DEBUG_FUNC_STRDUP(const char *ptr, const char *func, int line) { char *retval; retval = strdup(ptr); CACKEY_DEBUG_PRINTTIME; fprintf(cackey_debug_fd(), "%s():%i: ", func, line); fprintf(cackey_debug_fd(), "STRDUP_MALLOC() = %p", retval); fprintf(cackey_debug_fd(), "\n"); fflush(cackey_debug_fd()); return(retval); } static const char *CACKEY_DEBUG_FUNC_TAG_TO_STR(unsigned char tag) { switch (tag) { ................................................................................ # ifdef strdup # undef strdup # endif # define strdup(x) CACKEY_DEBUG_FUNC_STRDUP(x, __func__, __LINE__) #else # define CACKEY_DEBUG_PRINTF(x...) /**/ # define CACKEY_DEBUG_PRINTBUF(f, x, y) /**/ # define CACKEY_DEBUG_PERROR(x) /**/ # define CACKEY_DEBUG_FUNC_TAG_TO_STR(x) "DEBUG_DISABLED" # define CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(x) "DEBUG_DISABLED" # define CACKEY_DEBUG_FUNC_OBJID_TO_STR(x) "DEBUG_DISABLED" # define CACKEY_DEBUG_FUNC_APPTYPE_TO_STR(x) "DEBUG_DISABLED" # define CACKEY_DEBUG_FUNC_ATTRIBUTE_TO_STR(x) "DEBUG_DISABLED" #endif struct cackey_pcsc_identity { unsigned char applet[7]; uint16_t file; size_t certificate_len; unsigned char *certificate; ssize_t keysize; }; struct cackey_identity { struct cackey_pcsc_identity *pcsc_identity; CK_ATTRIBUTE *attributes; CK_ULONG attributes_count; ................................................................................ CK_VOID_PTR decrypt_mech_parm; CK_ULONG decrypt_mech_parmlen; struct cackey_identity *decrypt_identity; }; struct cackey_slot { int active; char *pcsc_reader; int pcsc_card_connected; SCARDHANDLE pcsc_card; int transaction_depth; ................................................................................ int slot_reset; CK_FLAGS token_flags; unsigned char *label; DWORD protocol; }; typedef enum { CACKEY_TLV_APP_GENERIC = 0x01, CACKEY_TLV_APP_SKI = 0x02, CACKEY_TLV_APP_PKI = 0x04 } cackey_tlv_apptype; ................................................................................ CK_C_INITIALIZE_ARGS cackey_args; /** Extra certificates to include in token **/ struct cackey_pcsc_identity extra_certs[] = { #include "cackey_builtin_certs.h" }; /* PCSC Global Handles */ static LPSCARDCONTEXT cackey_pcsc_handle = NULL; static unsigned long cackey_getversion(void) { static unsigned long retval = 255; unsigned long major = 0; unsigned long minor = 0; ................................................................................ */ static void cackey_slots_disconnect_all(void) { uint32_t idx; CACKEY_DEBUG_PRINTF("Called."); for (idx = 0; idx < (sizeof(cackey_slots) / sizeof(cackey_slots[0])); idx++) { if (cackey_slots[idx].pcsc_card_connected) { CACKEY_DEBUG_PRINTF("SCardDisconnect(%lu) called", (unsigned long) idx); SCardDisconnect(cackey_slots[idx].pcsc_card, SCARD_LEAVE_CARD); } if (cackey_slots[idx].label) { ................................................................................ if (slot->pcsc_card_connected) { SCardDisconnect(slot->pcsc_card, SCARD_LEAVE_CARD); } slot->slot_reset = 1; slot->pcsc_card_connected = 0; slot->token_flags = 0; if (login_required == -1) { if (cackey_login_required(slot) != CACKEY_PCSC_S_OK) { login_required = 1; } else { login_required = 0; } ................................................................................ CACKEY_DEBUG_PRINTF("Returning."); return; } /* * SYNPOSIS * LONG cackey_reconnect_card(struct cackey_slot *slot, DWORD default_protocol, LPDWORD selected_protocol); * * ARGUMENTS * cackey_slot *slot * Slot to send commands to * * DWORD default_protocol * Protocol to attempt first * * LPDWORD selected_protocol * [OUT] Protocol selected * * RETURN VALUE * The return value from SCardReconnect() * * NOTES * This function is a wrapper around SCardReconnect() * * The SCardReconnect() function call will be called first with the * dwPreferredProtocols of "default_protocol". If that call returns * SCARD_E_PROTO_MISMATCH try again with a protocol of T=0, and failing * that T=1. * */ static LONG cackey_reconnect_card(struct cackey_slot *slot, DWORD default_protocol, LPDWORD selected_protocol) { LONG scard_conn_ret; scard_conn_ret = SCardReconnect(slot->pcsc_card, SCARD_SHARE_SHARED, default_protocol, SCARD_RESET_CARD, selected_protocol); if (scard_conn_ret == SCARD_E_PROTO_MISMATCH) { CACKEY_DEBUG_PRINTF("SCardReconnect() returned SCARD_E_PROTO_MISMATCH, trying with just T=0") scard_conn_ret = SCardReconnect(slot->pcsc_card, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, SCARD_RESET_CARD, selected_protocol); if (scard_conn_ret == SCARD_E_PROTO_MISMATCH) { CACKEY_DEBUG_PRINTF("SCardReconnect() returned SCARD_E_PROTO_MISMATCH, trying with just T=1") scard_conn_ret = SCardReconnect(slot->pcsc_card, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T1, SCARD_RESET_CARD, selected_protocol); } } return(scard_conn_ret); } /* * SYNPOSIS * cackey_ret cackey_connect_card(struct cackey_slot *slot); ................................................................................ CACKEY_DEBUG_PRINTF("Connection to PC/SC failed, returning in failure"); return(CACKEY_PCSC_E_GENERIC); } /* Connect to reader, if needed */ if (!slot->pcsc_card_connected) { CACKEY_DEBUG_PRINTF("SCardConnect(%s) called", slot->pcsc_reader); scard_conn_ret = SCardConnect(*cackey_pcsc_handle, slot->pcsc_reader, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &slot->pcsc_card, &protocol); if (scard_conn_ret == SCARD_E_PROTO_MISMATCH) { CACKEY_DEBUG_PRINTF("SCardConnect() returned SCARD_E_PROTO_MISMATCH, trying with just T=0") scard_conn_ret = SCardConnect(*cackey_pcsc_handle, slot->pcsc_reader, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &slot->pcsc_card, &protocol); if (scard_conn_ret == SCARD_E_PROTO_MISMATCH) { ................................................................................ if (scard_conn_ret == SCARD_E_PROTO_MISMATCH) { CACKEY_DEBUG_PRINTF("SCardConnect() returned SCARD_E_PROTO_MISMATCH, trying with just T=1") scard_conn_ret = SCardConnect(*cackey_pcsc_handle, slot->pcsc_reader, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T1, &slot->pcsc_card, &protocol); } } scard_conn_ret = cackey_reconnect_card(slot, protocol, &protocol); } if (scard_conn_ret != SCARD_S_SUCCESS) { CACKEY_DEBUG_PRINTF("Connection to card failed, returning in failure (SCardConnect() = %s/%li)", CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(scard_conn_ret), (long) scard_conn_ret); return(CACKEY_PCSC_E_GENERIC); } slot->pcsc_card_connected = 1; slot->transaction_depth = 0; slot->transaction_need_hw_lock = 0; slot->protocol = protocol; } return(CACKEY_PCSC_S_OK); } /* * SYNPOSIS * cackey_ret cackey_begin_transaction(struct cackey_slot *slot); ................................................................................ * cackey_pcsc_connect() if needed. * * It will connect to the card in the reader attached to the slot * specified. It will reconnect to the card if the connection * goes away. * */ static cackey_ret cackey_send_apdu(struct cackey_slot *slot, unsigned char class, unsigned char instruction, unsigned char p1, unsigned char p2, unsigned char lc, unsigned char *data, unsigned char le, uint16_t *respcode, unsigned char *respdata, size_t *respdata_len) { uint8_t major_rc, minor_rc; size_t bytes_to_copy, tmp_respdata_len; LPCSCARD_IO_REQUEST pioSendPci; DWORD protocol; DWORD xmit_len, recv_len; LONG scard_xmit_ret, scard_reconn_ret; BYTE xmit_buf[1024], recv_buf[1024]; int pcsc_connect_ret, pcsc_getresp_ret; int idx; CACKEY_DEBUG_PRINTF("Called."); ................................................................................ return(CACKEY_PCSC_E_GENERIC); } /* Determine which protocol to send using */ switch (slot->protocol) { case SCARD_PROTOCOL_T0: pioSendPci = SCARD_PCI_T0; break; case SCARD_PROTOCOL_T1: pioSendPci = SCARD_PCI_T1; break; default: CACKEY_DEBUG_PRINTF("Invalid protocol found, aborting."); return(CACKEY_PCSC_E_GENERIC); ................................................................................ /* Transmit */ xmit_len = 0; xmit_buf[xmit_len++] = class; xmit_buf[xmit_len++] = instruction; xmit_buf[xmit_len++] = p1; xmit_buf[xmit_len++] = p2; if (data) { xmit_buf[xmit_len++] = lc; for (idx = 0; idx < lc; idx++) { xmit_buf[xmit_len++] = data[idx]; } } if (le != 0x00) { xmit_buf[xmit_len++] = le; } /* Begin Smartcard Transaction */ cackey_begin_transaction(slot); if (class == GSCIS_CLASS_ISO7816 && instruction == GSCIS_INSTR_VERIFY && p1 == 0x00 && p2 == 0x00) { CACKEY_DEBUG_PRINTF("Sending APDU: <<censored>>"); } else { CACKEY_DEBUG_PRINTBUF("Sending APDU:", xmit_buf, xmit_len); } recv_len = sizeof(recv_buf); scard_xmit_ret = SCardTransmit(slot->pcsc_card, pioSendPci, xmit_buf, xmit_len, NULL, recv_buf, &recv_len); ................................................................................ if (scard_xmit_ret == SCARD_E_NOT_TRANSACTED) { CACKEY_DEBUG_PRINTF("Failed to send APDU to card (SCardTransmit() = %s/%lx), will ask calling function to retry (not resetting card)...", CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(scard_xmit_ret), (unsigned long) scard_xmit_ret); /* Begin Smartcard Transaction */ cackey_end_transaction(slot); return(CACKEY_PCSC_E_RETRY); } if (scard_xmit_ret != SCARD_S_SUCCESS) { CACKEY_DEBUG_PRINTF("Failed to send APDU to card (SCardTransmit() = %s/%lx)", CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(scard_xmit_ret), (unsigned long) scard_xmit_ret); CACKEY_DEBUG_PRINTF("Marking slot as having been reset"); cackey_mark_slot_reset(slot); if (scard_xmit_ret == SCARD_W_RESET_CARD) { CACKEY_DEBUG_PRINTF("Reset required, please hold..."); scard_reconn_ret = cackey_reconnect_card(slot, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &protocol); if (scard_reconn_ret == SCARD_S_SUCCESS) { /* Update protocol */ slot->protocol = protocol; switch (slot->protocol) { case SCARD_PROTOCOL_T0: pioSendPci = SCARD_PCI_T0; break; case SCARD_PROTOCOL_T1: pioSendPci = SCARD_PCI_T1; ................................................................................ } CACKEY_DEBUG_PRINTF("APDU Returned an error, returning in failure"); return(CACKEY_PCSC_E_GENERIC); } /* * SYNPOSIS * ssize_t cackey_read_buffer(struct cackey_slot *slot, unsigned char *buffer, size_t count, unsigned char t_or_v, size_t initial_offset); * * ARGUMENTS * struct cackey_slot *slot ................................................................................ if (free_start) { free(start); } return; } /* * SYNPOSIS * ... * * ARGUMENTS * ... ................................................................................ * NOTES * ... * */ static struct cackey_pcsc_identity *cackey_read_certs(struct cackey_slot *slot, struct cackey_pcsc_identity *certs, unsigned long *count) { struct cackey_pcsc_identity *curr_id; struct cackey_tlv_entity *ccc_tlv, *ccc_curr, *app_tlv, *app_curr; unsigned char ccc_aid[] = {GSCIS_AID_CCC}; unsigned char curr_aid[7]; unsigned long outidx = 0; cackey_ret transaction_ret; int certs_resizable; int send_ret, select_ret; CACKEY_DEBUG_PRINTF("Called."); if (count == NULL) { CACKEY_DEBUG_PRINTF("count is NULL, returning in failure"); return(NULL); ................................................................................ if (certs != NULL) { if (*count == 0) { CACKEY_DEBUG_PRINTF("Requested we return 0 objects, short-circuit"); return(certs); } } /* Begin a SmartCard transaction */ transaction_ret = cackey_begin_transaction(slot); if (transaction_ret != CACKEY_PCSC_S_OK) { CACKEY_DEBUG_PRINTF("Unable begin transaction, returning in failure"); return(NULL); ................................................................................ } else { certs_resizable = 0; } /* Select the CCC Applet */ send_ret = cackey_select_applet(slot, ccc_aid, sizeof(ccc_aid)); if (send_ret != CACKEY_PCSC_S_OK) { CACKEY_DEBUG_PRINTF("Unable to select CCC Applet, returning in failure"); /* Terminate SmartCard Transaction */ cackey_end_transaction(slot); return(NULL); } /* Read all the applets from the CCC's TLV */ ccc_tlv = cackey_read_tlv(slot); /* Look for CARDURLs that coorespond to PKI applets */ for (ccc_curr = ccc_tlv; ccc_curr; ccc_curr = ccc_curr->_next) { CACKEY_DEBUG_PRINTF("Found tag: %s ... ", CACKEY_DEBUG_FUNC_TAG_TO_STR(ccc_curr->tag)); if (ccc_curr->tag != GSCIS_TAG_CARDURL) { CACKEY_DEBUG_PRINTF(" ... skipping it (we only care about CARDURLs)"); continue; } if ((ccc_curr->value_cardurl->apptype & CACKEY_TLV_APP_PKI) != CACKEY_TLV_APP_PKI) { CACKEY_DEBUG_PRINTF(" ... skipping it (we only care about PKI applets, this applet supports: %s/%02x)", CACKEY_DEBUG_FUNC_APPTYPE_TO_STR(ccc_curr->value_cardurl->apptype), (unsigned int) ccc_curr->value_cardurl->apptype); continue; } CACKEY_DEBUG_PRINTBUF("RID:", ccc_curr->value_cardurl->rid, sizeof(ccc_curr->value_cardurl->rid)); CACKEY_DEBUG_PRINTF("AppID = %s/%04lx", CACKEY_DEBUG_FUNC_OBJID_TO_STR(ccc_curr->value_cardurl->appid), (unsigned long) ccc_curr->value_cardurl->appid); CACKEY_DEBUG_PRINTF("ObjectID = %s/%04lx", CACKEY_DEBUG_FUNC_OBJID_TO_STR(ccc_curr->value_cardurl->objectid), (unsigned long) ccc_curr->value_cardurl->objectid); memcpy(curr_aid, ccc_curr->value_cardurl->rid, sizeof(ccc_curr->value_cardurl->rid)); curr_aid[sizeof(curr_aid) - 2] = (ccc_curr->value_cardurl->appid >> 8) & 0xff; curr_aid[sizeof(curr_aid) - 1] = ccc_curr->value_cardurl->appid & 0xff; /* Select found applet ... */ select_ret = cackey_select_applet(slot, curr_aid, sizeof(curr_aid)); if (select_ret != CACKEY_PCSC_S_OK) { CACKEY_DEBUG_PRINTF("Failed to select applet, skipping processing of this object"); continue; } /* ... and object (file) */ select_ret = cackey_select_file(slot, ccc_curr->value_cardurl->objectid); if (select_ret != CACKEY_PCSC_S_OK) { CACKEY_DEBUG_PRINTF("Failed to select file, skipping processing of this object"); continue; } /* Process this file's TLV looking for certificates */ app_tlv = cackey_read_tlv(slot); for (app_curr = app_tlv; app_curr; app_curr = app_curr->_next) { CACKEY_DEBUG_PRINTF("Found tag: %s", CACKEY_DEBUG_FUNC_TAG_TO_STR(app_curr->tag)); if (app_curr->tag != GSCIS_TAG_CERTIFICATE) { CACKEY_DEBUG_PRINTF(" ... skipping it (we only care about CERTIFICATEs)"); continue; } curr_id = &certs[outidx]; outidx++; memcpy(curr_id->applet, curr_aid, sizeof(curr_id->applet)); curr_id->file = ccc_curr->value_cardurl->objectid; curr_id->keysize = -1; CACKEY_DEBUG_PRINTF("Filling curr_id->applet (%p) with %lu bytes:", curr_id->applet, (unsigned long) sizeof(curr_id->applet)); CACKEY_DEBUG_PRINTBUF("VAL:", curr_id->applet, sizeof(curr_id->applet)); curr_id->certificate_len = app_curr->length; curr_id->certificate = malloc(curr_id->certificate_len); memcpy(curr_id->certificate, app_curr->value, curr_id->certificate_len); if (outidx >= *count) { if (certs_resizable) { *count *= 2; certs = realloc(certs, sizeof(*certs) * (*count)); } else { break; } } } cackey_free_tlv(app_tlv); if (outidx >= *count) { break; } } cackey_free_tlv(ccc_tlv); *count = outidx; if (certs_resizable) { certs = realloc(certs, sizeof(*certs) * (*count)); } /* Terminate SmartCard Transaction */ cackey_end_transaction(slot); return(certs); } ................................................................................ * ... * * NOTES * ... * */ static ssize_t cackey_signdecrypt(struct cackey_slot *slot, struct cackey_identity *identity, unsigned char *buf, size_t buflen, unsigned char *outbuf, size_t outbuflen, int padInput, int unpadOutput) { unsigned char *tmpbuf, *tmpbuf_s, *outbuf_s; unsigned char bytes_to_send, p1; unsigned char blocktype; cackey_ret send_ret; uint16_t respcode; ssize_t retval = 0, unpadoffset; size_t tmpbuflen, padlen, tmpoutbuflen; int free_tmpbuf = 0; int le; CACKEY_DEBUG_PRINTF("Called."); if (slot == NULL) { CACKEY_DEBUG_PRINTF("Error. slot is NULL"); ................................................................................ } if (identity->pcsc_identity == NULL) { CACKEY_DEBUG_PRINTF("Error. identity->pcsc_identity is NULL"); return(-1); } /* Determine identity Key size */ if (identity->pcsc_identity->keysize < 0) { identity->pcsc_identity->keysize = x509_to_keysize(identity->pcsc_identity->certificate, identity->pcsc_identity->certificate_len); } /* Pad message to key size */ ................................................................................ padlen = 0; } /* Begin transaction */ cackey_begin_transaction(slot); /* Select correct applet */ CACKEY_DEBUG_PRINTF("Selecting applet found at %p ...", identity->pcsc_identity->applet); cackey_select_applet(slot, identity->pcsc_identity->applet, sizeof(identity->pcsc_identity->applet)); /* Select correct file */ cackey_select_file(slot, identity->pcsc_identity->file); tmpbuf_s = tmpbuf; outbuf_s = outbuf; while (tmpbuflen) { if (tmpbuflen > 245) { bytes_to_send = 245; p1 = 0x80; le = 0x00; } else { bytes_to_send = tmpbuflen; p1 = 0x00; le = 0x00; } tmpoutbuflen = outbuflen; send_ret = cackey_send_apdu(slot, GSCIS_CLASS_GLOBAL_PLATFORM, GSCIS_INSTR_SIGNDECRYPT, p1, 0x00, bytes_to_send, tmpbuf, le, &respcode, outbuf, &tmpoutbuflen); if (send_ret != CACKEY_PCSC_S_OK) { CACKEY_DEBUG_PRINTF("ADPU Sending Failed -- returning in error."); if (free_tmpbuf) { if (tmpbuf_s) { free(tmpbuf_s); } } /* End transaction */ cackey_end_transaction(slot); if (respcode == 0x6982) { CACKEY_DEBUG_PRINTF("Security status not satisified. Returning NEEDLOGIN"); cackey_mark_slot_reset(slot); return(CACKEY_PCSC_E_NEEDLOGIN); } if (send_ret == CACKEY_PCSC_E_TOKENABSENT) { ................................................................................ if (outbuflen > _POSIX_SSIZE_MAX) { CACKEY_DEBUG_PRINTF("Outbuflen exceeds maximum value, returning in failure. (max = %li, outbuflen = %lu)", (long) _POSIX_SSIZE_MAX, (unsigned long) outbuflen); return(-1); } # endif #endif /* Unpad reply */ if (unpadOutput) { if (retval < 3) { CACKEY_DEBUG_PRINTF("Reply is too small, we are not able to unpad -- passing back and hoping for the best!"); CACKEY_DEBUG_PRINTF("Returning in success, retval = %li (bytes)", (long) retval); ................................................................................ * ... * * NOTES * ... * */ static cackey_ret cackey_login(struct cackey_slot *slot, unsigned char *pin, unsigned long pin_len, int *tries_remaining_p) { unsigned char cac_pin[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint16_t response_code; int tries_remaining; int send_ret; /* Indicate that we do not know about how many tries are remaining */ if (tries_remaining_p) { *tries_remaining_p = -1; } /* Apparently, CAC PINs are *EXACTLY* 8 bytes long -- pad with 0xFF if too short */ if (pin_len >= 8) { memcpy(cac_pin, pin, 8); } else { memcpy(cac_pin, pin, pin_len); } /* Issue PIN Verify */ send_ret = cackey_send_apdu(slot, GSCIS_CLASS_ISO7816, GSCIS_INSTR_VERIFY, 0x00, 0x00, sizeof(cac_pin), cac_pin, 0x00, &response_code, NULL, NULL); if (send_ret != CACKEY_PCSC_S_OK) { if ((response_code & 0x63C0) == 0x63C0) { tries_remaining = (response_code & 0xF); CACKEY_DEBUG_PRINTF("PIN Verification failed, %i tries remaining", tries_remaining); if (tries_remaining_p) { ................................................................................ * * NOTES * ... * */ static cackey_ret cackey_token_present(struct cackey_slot *slot) { cackey_ret pcsc_connect_ret; DWORD reader_len, state, protocol, atr_len; BYTE atr[MAX_ATR_SIZE]; LONG status_ret, scard_reconn_ret; CACKEY_DEBUG_PRINTF("Called."); pcsc_connect_ret = cackey_connect_card(slot); if (pcsc_connect_ret != CACKEY_PCSC_S_OK) { CACKEY_DEBUG_PRINTF("Unable to connect to card, returning token absent"); return(CACKEY_PCSC_E_TOKENABSENT); } atr_len = sizeof(atr); status_ret = SCardStatus(slot->pcsc_card, NULL, &reader_len, &state, &protocol, atr, &atr_len); if (status_ret == SCARD_E_INVALID_HANDLE) { CACKEY_DEBUG_PRINTF("SCardStatus() returned SCARD_E_INVALID_HANDLE, marking is not already connected and trying again"); cackey_mark_slot_reset(slot); ................................................................................ pcsc_connect_ret = cackey_connect_card(slot); if (pcsc_connect_ret != CACKEY_PCSC_S_OK) { CACKEY_DEBUG_PRINTF("Unable to connect to card, returning token absent"); return(CACKEY_PCSC_E_TOKENABSENT); } atr_len = sizeof(atr); status_ret = SCardStatus(slot->pcsc_card, NULL, &reader_len, &state, &protocol, atr, &atr_len); } if (status_ret != SCARD_S_SUCCESS) { cackey_mark_slot_reset(slot); if (status_ret == SCARD_W_RESET_CARD) { CACKEY_DEBUG_PRINTF("Reset required, please hold..."); scard_reconn_ret = cackey_reconnect_card(slot, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &protocol); if (scard_reconn_ret == SCARD_S_SUCCESS) { /* Update protocol */ slot->protocol = protocol; /* Re-establish transaction, if it was present */ if (slot->transaction_depth > 0) { slot->transaction_depth--; slot->transaction_need_hw_lock = 1; cackey_begin_transaction(slot); } ................................................................................ CACKEY_DEBUG_PRINTF(" ... returning %lu (%p/%lu)", (unsigned long) *((CK_BBOOL *) pValue), pValue, (unsigned long) ulValueLen); break; case CKA_LABEL: CACKEY_DEBUG_PRINTF("Requesting attribute CKA_LABEL (0x%08lx) ...", (unsigned long) curr_attr_type); /* XXX: Determine name */ ulValueLen = snprintf((char *) ucTmpBuf, sizeof(ucTmpBuf), "Identity #%lu", (unsigned long) identity_num); pValue = ucTmpBuf; if (ulValueLen >= sizeof(ucTmpBuf)) { ulValueLen = 0; pValue = NULL; } CACKEY_DEBUG_PRINTF(" ... returning (%p/%lu)", pValue, (unsigned long) ulValueLen); break; case CKA_VALUE: CACKEY_DEBUG_PRINTF("Requesting attribute CKA_VALUE (0x%08lx) ...", (unsigned long) curr_attr_type); ................................................................................ cackey_free_certs(identities[id_idx].pcsc_identity, 1, 1); } } free(identities); } static struct cackey_identity *cackey_read_identities(struct cackey_slot *slot, unsigned long *ids_found) { struct cackey_pcsc_identity *pcsc_identities; struct cackey_identity *identities; unsigned long num_ids, id_idx, curr_id_type; unsigned long num_certs, num_extra_certs, cert_idx; int include_extra_certs = 1; CACKEY_DEBUG_PRINTF("Called."); if (getenv("CACKEY_NO_EXTRA_CERTS") != NULL) { CACKEY_DEBUG_PRINTF("Asked not to include extra (DoD) certificates"); include_extra_certs = 0; } if (include_extra_certs) { num_extra_certs = sizeof(extra_certs) / sizeof(extra_certs[0]); CACKEY_DEBUG_PRINTF("Including %li DoD Certificates as objects on this token", num_extra_certs); } else { num_extra_certs = 0; } if (ids_found == NULL) { CACKEY_DEBUG_PRINTF("Error. ids_found is NULL"); return(NULL); } pcsc_identities = cackey_read_certs(slot, NULL, &num_certs); if (pcsc_identities != NULL) { /* Convert number of Certs to number of objects */ num_ids = (CKO_PRIVATE_KEY - CKO_CERTIFICATE + 1) * num_certs; num_ids += num_extra_certs * 3; identities = malloc(num_ids * sizeof(*identities)); /* Add certificates, public keys, and private keys from the smartcard */ id_idx = 0; for (cert_idx = 0; cert_idx < num_certs; cert_idx++) { for (curr_id_type = CKO_CERTIFICATE; curr_id_type <= CKO_PRIVATE_KEY; curr_id_type++) { ................................................................................ identities[id_idx].pcsc_identity->certificate = malloc(pcsc_identities[cert_idx].certificate_len); memcpy(identities[id_idx].pcsc_identity->certificate, pcsc_identities[cert_idx].certificate, pcsc_identities[cert_idx].certificate_len); id_idx++; } } cackey_free_certs(pcsc_identities, num_certs, 1); /* Add DoD Certificates and Netscape Trust Objects */ for (cert_idx = 0; cert_idx < num_extra_certs; cert_idx++) { identities[id_idx].pcsc_identity = NULL; identities[id_idx].attributes = cackey_get_attributes(CKO_CERTIFICATE, &extra_certs[cert_idx], 0xf000 | cert_idx, &identities[id_idx].attributes_count); id_idx++; identities[id_idx].pcsc_identity = NULL; identities[id_idx].attributes = cackey_get_attributes(CKO_PUBLIC_KEY, &extra_certs[cert_idx], 0xf000 | cert_idx, &identities[id_idx].attributes_count); id_idx++; identities[id_idx].pcsc_identity = NULL; identities[id_idx].attributes = cackey_get_attributes(CKO_NETSCAPE_TRUST, &extra_certs[cert_idx], 0xf000 | cert_idx, &identities[id_idx].attributes_count); id_idx++; } *ids_found = num_ids; return(identities); } *ids_found = 0; return(NULL); } CK_DEFINE_FUNCTION(CK_RV, C_Initialize)(CK_VOID_PTR pInitArgs) { CK_C_INITIALIZE_ARGS CK_PTR args; uint32_t idx; int mutex_init_ret; CACKEY_DEBUG_PRINTF("Called."); if (cackey_initialized) { CACKEY_DEBUG_PRINTF("Error. Already initialized."); return(CKR_CRYPTOKI_ALREADY_INITIALIZED); ................................................................................ cackey_slots[idx].active = 0; cackey_slots[idx].pcsc_reader = NULL; cackey_slots[idx].transaction_depth = 0; cackey_slots[idx].transaction_need_hw_lock = 0; cackey_slots[idx].slot_reset = 0; cackey_slots[idx].token_flags = 0; cackey_slots[idx].label = NULL; } cackey_initialized = 1; if (!cackey_biglock_init) { mutex_init_ret = cackey_mutex_create(&cackey_biglock); ................................................................................ CACKEY_DEBUG_PRINTF("Error. Mutex initialization failed."); return(CKR_CANT_LOCK); } cackey_biglock_init = 1; } CACKEY_DEBUG_PRINTF("Returning CKR_OK (%i)", CKR_OK); return(CKR_OK); } CK_DEFINE_FUNCTION(CK_RV, C_Finalize)(CK_VOID_PTR pReserved) { ................................................................................ C_CloseSession(idx); } } cackey_slots_disconnect_all(); for (idx = 0; idx < (sizeof(cackey_slots) / sizeof(cackey_slots[0])); idx++) { if (cackey_slots[idx].pcsc_reader) { free(cackey_slots[idx].pcsc_reader); } } cackey_pcsc_disconnect(); cackey_initialized = 0; CACKEY_DEBUG_PRINTF("Returning CKR_OK (%i)", CKR_OK); ................................................................................ return(CKR_OK); } /* * Process list of readers, and create mapping between reader name and slot ID */ CK_DEFINE_FUNCTION(CK_RV, C_GetSlotList)(CK_BBOOL tokenPresent, CK_SLOT_ID_PTR pSlotList, CK_ULONG_PTR pulCount) { int mutex_retval; int pcsc_connect_ret; CK_ULONG count, slot_count = 0, currslot; char *pcsc_readers, *pcsc_readers_s, *pcsc_readers_e; DWORD pcsc_readers_len; LONG scard_listreaders_ret; size_t curr_reader_len; CACKEY_DEBUG_PRINTF("Called."); if (pulCount == NULL) { CACKEY_DEBUG_PRINTF("Error. pulCount is NULL."); return(CKR_ARGUMENTS_BAD); ................................................................................ if (mutex_retval != 0) { CACKEY_DEBUG_PRINTF("Error. Locking failed."); return(CKR_GENERAL_ERROR); } /* Clear list of slots */ if (pSlotList) { CACKEY_DEBUG_PRINTF("Purging all slot information."); /* Only update the list of slots if we are actually being supply the slot information */ cackey_slots_disconnect_all(); for (currslot = 0; currslot < (sizeof(cackey_slots) / sizeof(cackey_slots[0])); currslot++) { if (cackey_slots[currslot].pcsc_reader) { free(cackey_slots[currslot].pcsc_reader); cackey_slots[currslot].pcsc_reader = NULL; } if (cackey_slots[currslot].label) { free(cackey_slots[currslot].label); cackey_slots[currslot].label = NULL; } cackey_slots[currslot].active = 0; } } /* Determine list of readers */ pcsc_connect_ret = cackey_pcsc_connect(); if (pcsc_connect_ret != CACKEY_PCSC_S_OK) { CACKEY_DEBUG_PRINTF("Connection to PC/SC failed, assuming no slots"); slot_count = 0; } else { pcsc_readers_len = 0; ................................................................................ scard_listreaders_ret = SCardListReaders(*cackey_pcsc_handle, NULL, pcsc_readers, &pcsc_readers_len); if (scard_listreaders_ret == SCARD_S_SUCCESS) { pcsc_readers_e = pcsc_readers + pcsc_readers_len; /* Start with Slot ID 1, to avoid a bug in GDM on RHEL */ /* Bug 594911: https://bugzilla.redhat.com/show_bug.cgi?id=594911 */ currslot = 1; while (pcsc_readers < pcsc_readers_e) { curr_reader_len = strlen(pcsc_readers); if ((pcsc_readers + curr_reader_len) > pcsc_readers_e) { break; } if (curr_reader_len == 0) { ................................................................................ if (currslot >= (sizeof(cackey_slots) / sizeof(cackey_slots[0]))) { CACKEY_DEBUG_PRINTF("Found more readers than slots are available!"); break; } CACKEY_DEBUG_PRINTF("Found reader: %s", pcsc_readers); /* Only update the list of slots if we are actually being asked supply the slot information */ if (pSlotList) { cackey_slots[currslot].active = 1; cackey_slots[currslot].pcsc_reader = strdup(pcsc_readers); cackey_slots[currslot].pcsc_card_connected = 0; cackey_slots[currslot].transaction_depth = 0; cackey_slots[currslot].transaction_need_hw_lock = 0; cackey_slots[currslot].token_flags = 0; cackey_slots[currslot].label = NULL; cackey_mark_slot_reset(&cackey_slots[currslot]); } currslot++; pcsc_readers += curr_reader_len + 1; } /* Start with Slot ID 1, to avoid a bug in GDM on RHEL */ /* Bug 594911: https://bugzilla.redhat.com/show_bug.cgi?id=594911 */ if (currslot > 1) { /* Start with Slot ID 1, to avoid a bug in GDM on RHEL */ /* Bug 594911: https://bugzilla.redhat.com/show_bug.cgi?id=594911 */ slot_count = currslot - 1; } } else { CACKEY_DEBUG_PRINTF("Second call to SCardListReaders failed, return %s/%li", CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(scard_listreaders_ret), (long) scard_listreaders_ret); } free(pcsc_readers_s); } else { ................................................................................ return(CKR_OK); } count = *pulCount; if (count < slot_count) { CACKEY_DEBUG_PRINTF("Error. User allocated %lu entries, but we have %lu entries.", count, slot_count); return(CKR_BUFFER_TOO_SMALL); } for (currslot = 0; currslot < slot_count; currslot++) { /* Start with Slot ID 1, to avoid a bug in GDM on RHEL */ /* Bug 594911: https://bugzilla.redhat.com/show_bug.cgi?id=594911 */ pSlotList[currslot] = currslot + 1; } *pulCount = slot_count; CACKEY_DEBUG_PRINTF("Returning CKR_OK (%i). Found %lu readers.", CKR_OK, (unsigned long) slot_count); return(CKR_OK); ................................................................................ CACKEY_DEBUG_PRINTF("Error. Invalid slot requested (%lu), slot not currently active", slotID); cackey_mutex_unlock(cackey_biglock); return(CKR_SLOT_ID_INVALID); } pInfo->flags = CKF_REMOVABLE_DEVICE | CKF_HW_SLOT; if (cackey_token_present(&cackey_slots[slotID]) == CACKEY_PCSC_S_TOKENPRESENT) { pInfo->flags |= CKF_TOKEN_PRESENT; } bytes_to_copy = strlen(cackey_slots[slotID].pcsc_reader); if (sizeof(pInfo->manufacturerID) < bytes_to_copy) { ................................................................................ pInfo->hardwareVersion.major = (cackey_getversion() >> 16) & 0xff; pInfo->hardwareVersion.minor = (cackey_getversion() >> 8) & 0xff; pInfo->firmwareVersion.major = 0x00; pInfo->firmwareVersion.minor = 0x00; pInfo->flags = CKF_WRITE_PROTECTED | CKF_USER_PIN_INITIALIZED | CKF_TOKEN_INITIALIZED | cackey_slots[slotID].token_flags; pInfo->ulMaxSessionCount = (sizeof(cackey_sessions) / sizeof(cackey_sessions[0])) - 1; pInfo->ulSessionCount = CK_UNAVAILABLE_INFORMATION; pInfo->ulMaxRwSessionCount = 0; pInfo->ulRwSessionCount = CK_UNAVAILABLE_INFORMATION; pInfo->ulMaxPinLen = 128; pInfo->ulMinPinLen = 0; ................................................................................ } CACKEY_DEBUG_PRINTF("Returning CKR_FUNCTION_NOT_SUPPORTED (%i)", CKR_FUNCTION_NOT_SUPPORTED); return(CKR_FUNCTION_NOT_SUPPORTED); } CK_DEFINE_FUNCTION(CK_RV, C_Login)(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen) { CK_SLOT_ID slotID; int mutex_retval; int tries_remaining; int login_ret; CACKEY_DEBUG_PRINTF("Called."); if (!cackey_initialized) { CACKEY_DEBUG_PRINTF("Error. Not initialized."); return(CKR_CRYPTOKI_NOT_INITIALIZED); ................................................................................ if (userType != CKU_USER) { CACKEY_DEBUG_PRINTF("Error. We only support USER mode, asked for %lu mode.", (unsigned long) userType) return(CKR_USER_TYPE_INVALID); } mutex_retval = cackey_mutex_lock(cackey_biglock); if (mutex_retval != 0) { CACKEY_DEBUG_PRINTF("Error. Locking failed."); return(CKR_GENERAL_ERROR); } if (!cackey_sessions[hSession].active) { cackey_mutex_unlock(cackey_biglock); CACKEY_DEBUG_PRINTF("Error. Session not active."); return(CKR_SESSION_HANDLE_INVALID); } slotID = cackey_sessions[hSession].slotID; if (slotID < 0 || slotID >= (sizeof(cackey_slots) / sizeof(cackey_slots[0]))) { CACKEY_DEBUG_PRINTF("Error. Invalid slot requested (%lu), outside of valid range", slotID); return(CKR_GENERAL_ERROR); } if (cackey_slots[slotID].active == 0) { CACKEY_DEBUG_PRINTF("Error. Invalid slot requested (%lu), slot not currently active", slotID); cackey_mutex_unlock(cackey_biglock); return(CKR_GENERAL_ERROR); } login_ret = cackey_login(&cackey_slots[slotID], pPin, ulPinLen, &tries_remaining); if (login_ret != CACKEY_PCSC_S_OK) { cackey_mutex_unlock(cackey_biglock); if (login_ret == CACKEY_PCSC_E_LOCKED) { CACKEY_DEBUG_PRINTF("Error. Token is locked."); cackey_slots[slotID].token_flags |= CKF_USER_PIN_LOCKED; return(CKR_PIN_LOCKED); } else if (login_ret == CACKEY_PCSC_E_BADPIN) { CACKEY_DEBUG_PRINTF("Error. Invalid PIN."); cackey_slots[slotID].token_flags |= CKF_USER_PIN_COUNT_LOW; if (tries_remaining == 1) { cackey_slots[slotID].token_flags |= CKF_USER_PIN_FINAL_TRY; } return(CKR_PIN_INCORRECT); } CACKEY_DEBUG_PRINTF("Error. Unknown error returned from cackey_login() (%i)", login_ret); return(CKR_GENERAL_ERROR); } cackey_slots[slotID].token_flags &= ~(CKF_USER_PIN_LOCKED | CKF_USER_PIN_COUNT_LOW | CKF_LOGIN_REQUIRED | CKF_USER_PIN_FINAL_TRY); cackey_sessions[hSession].state = CKS_RO_USER_FUNCTIONS; mutex_retval = cackey_mutex_unlock(cackey_biglock); if (mutex_retval != 0) { CACKEY_DEBUG_PRINTF("Error. Unlocking failed."); return(CKR_GENERAL_ERROR); } CACKEY_DEBUG_PRINTF("Returning CKR_OK (%i)", CKR_OK); return(CKR_OK); } CK_DEFINE_FUNCTION(CK_RV, C_Logout)(CK_SESSION_HANDLE hSession) { CK_SLOT_ID slotID; int mutex_retval; CACKEY_DEBUG_PRINTF("Called."); ................................................................................ cackey_mutex_unlock(cackey_biglock); return(CKR_GENERAL_ERROR); } cackey_sessions[hSession].state = CKS_RO_PUBLIC_SESSION; cackey_slots[slotID].token_flags = CKF_LOGIN_REQUIRED; mutex_retval = cackey_mutex_unlock(cackey_biglock); if (mutex_retval != 0) { CACKEY_DEBUG_PRINTF("Error. Unlocking failed."); return(CKR_GENERAL_ERROR); } ................................................................................ CK_DEFINE_FUNCTION(CK_RV, C_FindObjects)(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE_PTR phObject, CK_ULONG ulMaxObjectCount, CK_ULONG_PTR pulObjectCount) { struct cackey_identity *curr_id; CK_ATTRIBUTE *curr_attr; CK_ULONG curr_id_idx, curr_out_id_idx, curr_attr_idx, sess_attr_idx; CK_ULONG matched_count, prev_matched_count; int mutex_retval; CACKEY_DEBUG_PRINTF("Called."); if (!cackey_initialized) { CACKEY_DEBUG_PRINTF("Error. Not initialized."); return(CKR_CRYPTOKI_NOT_INITIALIZED); ................................................................................ if (!cackey_sessions[hSession].search_active) { cackey_mutex_unlock(cackey_biglock); CACKEY_DEBUG_PRINTF("Error. Search not active."); return(CKR_OPERATION_NOT_INITIALIZED); } curr_out_id_idx = 0; for (curr_id_idx = cackey_sessions[hSession].search_curr_id; curr_id_idx < cackey_sessions[hSession].identities_count && ulMaxObjectCount; curr_id_idx++) { curr_id = &cackey_sessions[hSession].identities[curr_id_idx]; CACKEY_DEBUG_PRINTF("Processing identity:%lu", (unsigned long) curr_id_idx); ................................................................................ curr_out_id_idx++; } else { CACKEY_DEBUG_PRINTF(" ... Not all %i (only found %i) attributes checked for found, not adding identity:%i", (int) cackey_sessions[hSession].search_query_count, (int) matched_count, (int) curr_id_idx); } } cackey_sessions[hSession].search_curr_id = curr_id_idx; *pulObjectCount = curr_out_id_idx; mutex_retval = cackey_mutex_unlock(cackey_biglock); if (mutex_retval != 0) { CACKEY_DEBUG_PRINTF("Error. Unlocking failed."); return(CKR_GENERAL_ERROR); } ................................................................................ return(CKR_GENERAL_ERROR); } switch (cackey_sessions[hSession].decrypt_mechanism) { case CKM_RSA_PKCS: /* Ask card to decrypt */ buflen = cackey_signdecrypt(&cackey_slots[slotID], cackey_sessions[hSession].decrypt_identity, pEncryptedPart, ulEncryptedPartLen, buf, sizeof(buf), 0, 1); if (buflen < 0) { /* Decryption failed. */ if (buflen == CACKEY_PCSC_E_NEEDLOGIN) { retval = CKR_USER_NOT_LOGGED_IN; } else if (buflen == CACKEY_PCSC_E_TOKENABSENT) { retval = CKR_DEVICE_REMOVED; } else { retval = CKR_GENERAL_ERROR; } } else if (((unsigned long) buflen) > *pulPartLen && pPart) { /* Decrypted data too large */ retval = CKR_BUFFER_TOO_SMALL; } else { if (pPart) { ................................................................................ } switch (cackey_sessions[hSession].sign_mechanism) { case CKM_RSA_PKCS: /* Ask card to sign */ CACKEY_DEBUG_PRINTF("Asking to sign from identity %p in session %lu", (void *) cackey_sessions[hSession].sign_identity, (unsigned long) hSession); sigbuflen = cackey_signdecrypt(&cackey_slots[slotID], cackey_sessions[hSession].sign_identity, cackey_sessions[hSession].sign_buf, cackey_sessions[hSession].sign_bufused, sigbuf, sizeof(sigbuf), 1, 0); if (sigbuflen < 0) { /* Signing failed. */ if (sigbuflen == CACKEY_PCSC_E_NEEDLOGIN) { retval = CKR_USER_NOT_LOGGED_IN; } else if (sigbuflen == CACKEY_PCSC_E_TOKENABSENT) { retval = CKR_DEVICE_REMOVED; |
> > > > > > > < < < < < < < < > > > > > > > > > > > > > > > > > > > > > > | > > > > > > < > > > < < < > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < < < | < < < | < < < | < > > > > > > > > > > > > > > < < > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | < < < | > > > | | | > > > > | | > > | < > > > > > > > > > > > | > > > > > > > > > > | > | > > | < < > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | < > | | | | | | | > | | > > > | | > > > > > > > | | < < | < < < < > | > > | > > > > > > | | | > > > > > > > > > > > > > > > > > > > | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > | > > > > > > | | | < | | | < < | < < > > > > > > > > | > > > > > > > > > > > > > > > > > | > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > | > > > > > > > > > > | < < < | > > > | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > | | | | > > > > | > | > > | > > | > > > > > > > > > > > > > > > > > | > > | < > > > > > > > > | < > | | < | > | > > > > > > > > | < < < < < < < < < < < < < < > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | > > > > | | | | | | | | | | > | | > > > > > > > > > > > | > | > | | | | | | | > > > > > > > > | | | | | | > > < < | > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > | > > > > > | > > > > | | | | > > | > > > > > > | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > | | | | > > > > > < > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 .. 63 64 65 66 67 68 69 70 71 72 73 74 75 76 ... 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 ... 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 ... 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 ... 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 ... 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 ... 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 ... 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 ... 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 ... 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 ... 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 .... 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 .... 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 .... 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 .... 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 .... 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 .... 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 .... 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 .... 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 .... 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 .... 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 .... 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 .... 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 .... 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 .... 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 .... 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 .... 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 .... 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 .... 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 .... 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 .... 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 .... 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 .... 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 .... 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 .... 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 .... 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 .... 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 .... 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 .... 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 .... 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 .... 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 .... 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 .... 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 .... 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 .... 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 .... 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 .... 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 .... 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 .... 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 .... 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 .... 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 .... 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 |
#endif #ifdef HAVE_LIMITS_H # include <limits.h> #endif #ifdef HAVE_STDIO_H # include <stdio.h> #endif #define HAVE_ERRNO_H 1 #ifdef HAVE_ERRNO_H # include <errno.h> #endif #ifdef HAVE_ZLIB_H # ifdef HAVE_LIBZ # include <zlib.h> # endif #else # ifdef HAVE_LIBZ # undef HAVE_LIBZ # endif #endif #ifdef CACKEY_DEBUG_SEARCH_SPEEDTEST # include <sys/time.h> #endif #define CK_PTR * #define CK_DEFINE_FUNCTION(returnType, name) returnType name #define CK_DECLARE_FUNCTION(returnType, name) returnType name #define CK_DECLARE_FUNCTION_POINTER(returnType, name) returnType (* name) #define CK_CALLBACK_FUNCTION(returnType, name) returnType (* name) ................................................................................ #include "pkcs11.h" #include "pkcs11n.h" #include "asn1-x509.h" #include "sha1.h" #include "md5.h" #ifndef CACKEY_CRYPTOKI_VERSION_CODE # define CACKEY_CRYPTOKI_VERSION_CODE 0x021e00 #endif /* GSC-IS v2.1 Definitions */ /** Classes **/ #define GSCIS_CLASS_ISO7816 0x00 ................................................................................ #define GSCIS_TAG_SERNO 0x51 #define GSCIS_TAG_ISSUE_DATE 0x52 #define GSCIS_TAG_EXPIRE_DATE 0x53 #define GSCIS_TAG_CARD_TYPE 0x54 #define GSCIS_TAG_SECURITY_CODE 0x57 #define GSCIS_TAG_CARDID_AID 0x58 /*** PIV Codes ***/ #define NISTSP800_73_3_INSTR_GET_DATA 0xCB #define NISTSP800_73_3_INSTR_GENAUTH 0x87 /*** PKI Information - EF 7000 ***/ #define GSCIS_TAG_CERTIFICATE 0x70 #define GSCIS_TAG_CERT_ISSUE_DATE 0x71 #define GSCIS_TAG_CERT_EXPIRE_DATE 0x72 /** Applet IDs **/ #define GSCIS_AID_CCC 0xA0, 0x00, 0x00, 0x01, 0x16, 0xDB, 0x00 #define NISTSP800_73_3_PIV_AID 0xA0, 0x00, 0x00, 0x03, 0x08, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00 /* PIV IDs */ /** Key Identifiers (NIST SP 800-78-3, Table 6-1 **/ #define NISTSP800_78_3_KEY_PIVAUTH 0x9A #define NISTSP800_78_3_KEY_SIGNATURE 0x9C #define NISTSP800_78_3_KEY_KEYMGT 0x9D #define NISTSP800_78_3_KEY_CARDAUTH 0x9E /** Algorithm Identifiers (NIST SP 800-78-3, Table 6-2 **/ #define NISTSP800_78_3_ALGO_RSA1024 0x06 #define NISTSP800_78_3_ALGO_RSA2048 0x07 /** Object Identifiers (NIST SP 800-73-3 Part 1, Table 2) **/ #define NISTSP800_73_3_OID_PIVAUTH 0x5F, 0xC1, 0x05 #define NISTSP800_73_3_OID_SIGNATURE 0x5F, 0xC1, 0x0A #define NISTSP800_73_3_OID_KEYMGT 0x5F, 0xC1, 0x0B #define NISTSP800_73_3_OID_CARDAUTH 0x5F, 0xC1, 0x01 /* Maximum size of data portion of APDUs */ /** Do not set this above 250 **/ #define CACKEY_APDU_MTU 250 /* ATR If not available */ #ifndef MAX_ATR_SIZE ................................................................................ #define MAX_ATR_SIZE 1024 #endif #ifdef CACKEY_DEBUG # ifdef HAVE_TIME_H # include <time.h> static time_t cackey_debug_start_time = 0; static unsigned long CACKEY_DEBUG_GETTIME(void) { if (cackey_debug_start_time == 0) { cackey_debug_start_time = time(NULL); } return(time(NULL) - cackey_debug_start_time); } # else static unsigned long CACKEY_DEBUG_GETTIME(void) { return(0); } # endif # define CACKEY_DEBUG_PRINTF(x...) { \ static char buf_user[4096] = {0}; \ snprintf(buf_user, sizeof(buf_user), x); \ buf_user[sizeof(buf_user) - 1] = '\0'; \ fprintf(cackey_debug_fd(), "[%lu]: %s():%i: %s\n", CACKEY_DEBUG_GETTIME(), __func__, __LINE__, buf_user); \ fflush(cackey_debug_fd()); \ } # define CACKEY_DEBUG_PRINTBUF(f, x, y) { \ static char buf_user[4096] = {0}, *buf_user_p; \ unsigned long buf_user_size; \ unsigned char *TMPBUF; \ unsigned long idx; \ int snprintf_ret; \ TMPBUF = (unsigned char *) (x); \ buf_user[0] = 0; \ buf_user_p = buf_user; \ buf_user_size = sizeof(buf_user); \ for (idx = 1; idx < (y); idx++) { \ if (buf_user_size <= 0) { \ break; \ }; \ snprintf_ret = snprintf(buf_user_p, buf_user_size, ", %02x", TMPBUF[idx]); \ if (snprintf_ret <= 0) { \ break; \ }; \ buf_user_p += snprintf_ret; \ buf_user_size -= snprintf_ret; \ }; \ buf_user[sizeof(buf_user) - 1] = '\0'; \ fprintf(cackey_debug_fd(), "[%lu]: %s():%i: %s (%s/%lu = {%02x%s})\n", CACKEY_DEBUG_GETTIME(), __func__, __LINE__, f, #x, (unsigned long) (y), TMPBUF[0], buf_user); \ fflush(cackey_debug_fd()); \ } # define free(x) { CACKEY_DEBUG_PRINTF("FREE(%p) (%s)", (void *) x, #x); free(x); } static FILE *cackey_debug_fd(void) { static FILE *fd = NULL; char *logfile; if (fd != NULL) { ................................................................................ logfile = strchr(logfile, '='); if (logfile == NULL) { logfile = getenv("CACKEY_DEBUG_LOGFILE"); } else { logfile++; } } #ifdef CACKEY_DEBUG_LOGFILE if (logfile == NULL) { logfile = CACKEY_DEBUG_LOGFILE; } #endif if (logfile != NULL) { CACKEY_DEBUG_PRINTF("Found log file: %s", logfile); fd = fopen(logfile, "a"); } ................................................................................ } static void *CACKEY_DEBUG_FUNC_MALLOC(size_t size, const char *func, int line) { void *retval; retval = malloc(size); fprintf(cackey_debug_fd(), "[%lu]: %s():%i: MALLOC() = %p\n", CACKEY_DEBUG_GETTIME(), func, line, retval); fflush(cackey_debug_fd()); return(retval); } static void *CACKEY_DEBUG_FUNC_REALLOC(void *ptr, size_t size, const char *func, int line) { void *retval; retval = realloc(ptr, size); if (retval != ptr) { fprintf(cackey_debug_fd(), "[%lu]: %s():%i: REALLOC(%p) = %p\n", CACKEY_DEBUG_GETTIME(), func, line, ptr, retval); fflush(cackey_debug_fd()); } if (retval == NULL) { CACKEY_DEBUG_PRINTF(" *** ERROR *** realloc returned NULL (size = %lu)", (unsigned long) size); } ................................................................................ } static char *CACKEY_DEBUG_FUNC_STRDUP(const char *ptr, const char *func, int line) { char *retval; retval = strdup(ptr); fprintf(cackey_debug_fd(), "[%lu]: %s():%i: STRDUP_MALLOC() = %p\n", CACKEY_DEBUG_GETTIME(), func, line, retval); fflush(cackey_debug_fd()); return(retval); } static const char *CACKEY_DEBUG_FUNC_TAG_TO_STR(unsigned char tag) { switch (tag) { ................................................................................ # ifdef strdup # undef strdup # endif # define strdup(x) CACKEY_DEBUG_FUNC_STRDUP(x, __func__, __LINE__) #else # define CACKEY_DEBUG_PRINTF(x...) /**/ # define CACKEY_DEBUG_PRINTBUF(f, x, y) /**/ # define CACKEY_DEBUG_FUNC_TAG_TO_STR(x) "DEBUG_DISABLED" # define CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(x) "DEBUG_DISABLED" # define CACKEY_DEBUG_FUNC_OBJID_TO_STR(x) "DEBUG_DISABLED" # define CACKEY_DEBUG_FUNC_APPTYPE_TO_STR(x) "DEBUG_DISABLED" # define CACKEY_DEBUG_FUNC_ATTRIBUTE_TO_STR(x) "DEBUG_DISABLED" #endif /* * Include these source files in this translation unit so that we can bind to * functions and not include any symbols in the output shared object. */ #include "asn1-x509.c" #include "sha1.c" #include "md5.c" typedef enum { CACKEY_ID_TYPE_CAC, CACKEY_ID_TYPE_PIV, CACKEY_ID_TYPE_CERT_ONLY } cackey_pcsc_id_type; struct cackey_pcsc_identity { cackey_pcsc_id_type id_type; size_t certificate_len; unsigned char *certificate; ssize_t keysize; union { struct { unsigned char applet[7]; uint16_t file; } cac; struct { unsigned char key_id; char label[32]; } piv; } card; }; struct cackey_identity { struct cackey_pcsc_identity *pcsc_identity; CK_ATTRIBUTE *attributes; CK_ULONG attributes_count; ................................................................................ CK_VOID_PTR decrypt_mech_parm; CK_ULONG decrypt_mech_parmlen; struct cackey_identity *decrypt_identity; }; struct cackey_slot { int active; int internal; char *pcsc_reader; int pcsc_card_connected; SCARDHANDLE pcsc_card; int transaction_depth; ................................................................................ int slot_reset; CK_FLAGS token_flags; unsigned char *label; DWORD protocol; unsigned int cached_certs_count; struct cackey_pcsc_identity *cached_certs; }; typedef enum { CACKEY_TLV_APP_GENERIC = 0x01, CACKEY_TLV_APP_SKI = 0x02, CACKEY_TLV_APP_PKI = 0x04 } cackey_tlv_apptype; ................................................................................ CK_C_INITIALIZE_ARGS cackey_args; /** Extra certificates to include in token **/ struct cackey_pcsc_identity extra_certs[] = { #include "cackey_builtin_certs.h" }; /* Protected Authentication Path command */ #define CACKEY_PIN_COMMAND_DEFAULT_XSTR(str) CACKEY_PIN_COMMAND_DEFAULT_STR(str) #define CACKEY_PIN_COMMAND_DEFAULT_STR(str) #str static char *cackey_pin_command = NULL; /* PCSC Global Handles */ static LPSCARDCONTEXT cackey_pcsc_handle = NULL; static unsigned long cackey_getversion(void) { static unsigned long retval = 255; unsigned long major = 0; unsigned long minor = 0; ................................................................................ */ static void cackey_slots_disconnect_all(void) { uint32_t idx; CACKEY_DEBUG_PRINTF("Called."); for (idx = 0; idx < (sizeof(cackey_slots) / sizeof(cackey_slots[0])); idx++) { if (cackey_slots[idx].internal) { /* Skip internal slots */ continue; } if (cackey_slots[idx].pcsc_card_connected) { CACKEY_DEBUG_PRINTF("SCardDisconnect(%lu) called", (unsigned long) idx); SCardDisconnect(cackey_slots[idx].pcsc_card, SCARD_LEAVE_CARD); } if (cackey_slots[idx].label) { ................................................................................ if (slot->pcsc_card_connected) { SCardDisconnect(slot->pcsc_card, SCARD_LEAVE_CARD); } slot->slot_reset = 1; slot->pcsc_card_connected = 0; slot->token_flags = 0; if (cackey_pin_command == NULL) { login_required = 0; } if (login_required == -1) { if (cackey_login_required(slot) != CACKEY_PCSC_S_OK) { login_required = 1; } else { login_required = 0; } ................................................................................ CACKEY_DEBUG_PRINTF("Returning."); return; } /* * SYNPOSIS * LONG cackey_reconnect_card(struct cackey_slot *slot, DWORD default_protocol); * * ARGUMENTS * cackey_slot *slot * Slot to send commands to * * DWORD default_protocol * Protocol to attempt first * * RETURN VALUE * The return value from SCardReconnect() * * NOTES * This function is a wrapper around SCardReconnect() * * The SCardReconnect() function call will be called first with the * dwPreferredProtocols of "default_protocol". If that call returns * SCARD_E_PROTO_MISMATCH try again with a protocol of T=0, and failing * that T=1. * */ static LONG cackey_reconnect_card(struct cackey_slot *slot, DWORD default_protocol) { DWORD selected_protocol; LONG scard_conn_ret; selected_protocol = 0; scard_conn_ret = SCardReconnect(slot->pcsc_card, SCARD_SHARE_SHARED, default_protocol, SCARD_RESET_CARD, &selected_protocol); if (scard_conn_ret == SCARD_E_PROTO_MISMATCH) { CACKEY_DEBUG_PRINTF("SCardReconnect() returned SCARD_E_PROTO_MISMATCH, trying with just T=0") scard_conn_ret = SCardReconnect(slot->pcsc_card, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, SCARD_RESET_CARD, &selected_protocol); if (scard_conn_ret == SCARD_E_PROTO_MISMATCH) { CACKEY_DEBUG_PRINTF("SCardReconnect() returned SCARD_E_PROTO_MISMATCH, trying with just T=1") scard_conn_ret = SCardReconnect(slot->pcsc_card, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T1, SCARD_RESET_CARD, &selected_protocol); } } if (scard_conn_ret == SCARD_S_SUCCESS) { slot->protocol = selected_protocol; } return(scard_conn_ret); } /* * SYNPOSIS * cackey_ret cackey_connect_card(struct cackey_slot *slot); ................................................................................ CACKEY_DEBUG_PRINTF("Connection to PC/SC failed, returning in failure"); return(CACKEY_PCSC_E_GENERIC); } /* Connect to reader, if needed */ if (!slot->pcsc_card_connected) { CACKEY_DEBUG_PRINTF("SCardConnect(%s) called for slot %p", slot->pcsc_reader, slot); scard_conn_ret = SCardConnect(*cackey_pcsc_handle, slot->pcsc_reader, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &slot->pcsc_card, &protocol); if (scard_conn_ret == SCARD_E_PROTO_MISMATCH) { CACKEY_DEBUG_PRINTF("SCardConnect() returned SCARD_E_PROTO_MISMATCH, trying with just T=0") scard_conn_ret = SCardConnect(*cackey_pcsc_handle, slot->pcsc_reader, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &slot->pcsc_card, &protocol); if (scard_conn_ret == SCARD_E_PROTO_MISMATCH) { ................................................................................ if (scard_conn_ret == SCARD_E_PROTO_MISMATCH) { CACKEY_DEBUG_PRINTF("SCardConnect() returned SCARD_E_PROTO_MISMATCH, trying with just T=1") scard_conn_ret = SCardConnect(*cackey_pcsc_handle, slot->pcsc_reader, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T1, &slot->pcsc_card, &protocol); } } scard_conn_ret = cackey_reconnect_card(slot, protocol); } if (scard_conn_ret != SCARD_S_SUCCESS) { CACKEY_DEBUG_PRINTF("Connection to card failed, returning in failure (SCardConnect() = %s/%li)", CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(scard_conn_ret), (long) scard_conn_ret); return(CACKEY_PCSC_E_GENERIC); } slot->pcsc_card_connected = 1; slot->transaction_depth = 0; slot->transaction_need_hw_lock = 0; slot->protocol = protocol; } CACKEY_DEBUG_PRINTF("Returning in success"); return(CACKEY_PCSC_S_OK); } /* * SYNPOSIS * cackey_ret cackey_begin_transaction(struct cackey_slot *slot); ................................................................................ * cackey_pcsc_connect() if needed. * * It will connect to the card in the reader attached to the slot * specified. It will reconnect to the card if the connection * goes away. * */ static cackey_ret cackey_send_apdu(struct cackey_slot *slot, unsigned char class, unsigned char instruction, unsigned char p1, unsigned char p2, unsigned int lc, unsigned char *data, unsigned int le, uint16_t *respcode, unsigned char *respdata, size_t *respdata_len) { uint8_t major_rc, minor_rc; size_t bytes_to_copy, tmp_respdata_len; LPCSCARD_IO_REQUEST pioSendPci; DWORD xmit_len, recv_len; LONG scard_xmit_ret, scard_reconn_ret; BYTE xmit_buf[1024], recv_buf[1024]; int pcsc_connect_ret, pcsc_getresp_ret; int idx; CACKEY_DEBUG_PRINTF("Called."); ................................................................................ return(CACKEY_PCSC_E_GENERIC); } /* Determine which protocol to send using */ switch (slot->protocol) { case SCARD_PROTOCOL_T0: CACKEY_DEBUG_PRINTF("Protocol to send datagram is T=0"); pioSendPci = SCARD_PCI_T0; break; case SCARD_PROTOCOL_T1: CACKEY_DEBUG_PRINTF("Protocol to send datagram is T=1"); pioSendPci = SCARD_PCI_T1; break; default: CACKEY_DEBUG_PRINTF("Invalid protocol found, aborting."); return(CACKEY_PCSC_E_GENERIC); ................................................................................ /* Transmit */ xmit_len = 0; xmit_buf[xmit_len++] = class; xmit_buf[xmit_len++] = instruction; xmit_buf[xmit_len++] = p1; xmit_buf[xmit_len++] = p2; if (data) { if (lc > 255) { CACKEY_DEBUG_PRINTF("CAUTION! Using an Lc greater than 255 is untested. Lc = %u", lc); xmit_buf[xmit_len++] = 0x82; /* XXX UNTESTED */ xmit_buf[xmit_len++] = (lc & 0xff00) >> 8; xmit_buf[xmit_len++] = lc & 0xff; } else { xmit_buf[xmit_len++] = lc; } for (idx = 0; idx < lc; idx++) { xmit_buf[xmit_len++] = data[idx]; } } if (le != 0x00) { if (le > 256) { CACKEY_DEBUG_PRINTF("CAUTION! Using an Le greater than 256 is untested. Le = %u", le); xmit_buf[xmit_len++] = 0x82; /* XXX UNTESTED */ xmit_buf[xmit_len++] = (le & 0xff00) >> 8; xmit_buf[xmit_len++] = le & 0xff; } else if (le == 256) { xmit_buf[xmit_len++] = 0x00; } else { xmit_buf[xmit_len++] = le; } } /* Begin Smartcard Transaction */ cackey_begin_transaction(slot); if (class == GSCIS_CLASS_ISO7816 && instruction == GSCIS_INSTR_VERIFY && p1 == 0x00) { CACKEY_DEBUG_PRINTF("Sending APDU: <<censored>>"); } else { CACKEY_DEBUG_PRINTBUF("Sending APDU:", xmit_buf, xmit_len); } recv_len = sizeof(recv_buf); scard_xmit_ret = SCardTransmit(slot->pcsc_card, pioSendPci, xmit_buf, xmit_len, NULL, recv_buf, &recv_len); ................................................................................ if (scard_xmit_ret == SCARD_E_NOT_TRANSACTED) { CACKEY_DEBUG_PRINTF("Failed to send APDU to card (SCardTransmit() = %s/%lx), will ask calling function to retry (not resetting card)...", CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(scard_xmit_ret), (unsigned long) scard_xmit_ret); /* Begin Smartcard Transaction */ cackey_end_transaction(slot); cackey_reconnect_card(slot, slot->protocol); return(CACKEY_PCSC_E_RETRY); } if (scard_xmit_ret != SCARD_S_SUCCESS) { CACKEY_DEBUG_PRINTF("Failed to send APDU to card (SCardTransmit() = %s/%lx)", CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(scard_xmit_ret), (unsigned long) scard_xmit_ret); CACKEY_DEBUG_PRINTF("Marking slot as having been reset"); cackey_mark_slot_reset(slot); if (scard_xmit_ret == SCARD_W_RESET_CARD) { CACKEY_DEBUG_PRINTF("Reset required, please hold..."); scard_reconn_ret = cackey_reconnect_card(slot, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1); if (scard_reconn_ret == SCARD_S_SUCCESS) { switch (slot->protocol) { case SCARD_PROTOCOL_T0: pioSendPci = SCARD_PCI_T0; break; case SCARD_PROTOCOL_T1: pioSendPci = SCARD_PCI_T1; ................................................................................ } CACKEY_DEBUG_PRINTF("APDU Returned an error, returning in failure"); return(CACKEY_PCSC_E_GENERIC); } static unsigned char *cackey_read_bertlv_tag(unsigned char *buffer, size_t *buffer_len_p, unsigned char tag, unsigned char *outbuffer, size_t *outbuffer_len_p) { unsigned char *buffer_p; size_t outbuffer_len, buffer_len; size_t size; int idx; CACKEY_DEBUG_PRINTF("Called."); if (buffer_len_p == NULL) { CACKEY_DEBUG_PRINTF("buffer_len_p is NULL. Returning in failure."); return(NULL); } if (outbuffer_len_p == NULL) { CACKEY_DEBUG_PRINTF("outbuffer_len_p is NULL. Returning in failure."); return(NULL); } buffer_len = *outbuffer_len_p; outbuffer_len = *outbuffer_len_p; if (buffer_len < 2) { CACKEY_DEBUG_PRINTF("buffer_len is less than 2, so we can't read any tag. Returning in failure."); return(NULL); } buffer_p = buffer; if (buffer_p[0] != tag) { CACKEY_DEBUG_PRINTF("Tag found was not tag expected. Tag = %02x, Expected = %02x. Returning in failure.", (unsigned int) buffer_p[0], tag); return(NULL); } buffer_p++; buffer_len--; if ((buffer_p[0] & 0x80) == 0x80) { size = 0; idx = (buffer_p[0] & 0x7f); if (idx > buffer_len) { CACKEY_DEBUG_PRINTF("Malformed BER value -- not enough bytes available to read length (idx = %i, buffer_len = %lu)", idx, (unsigned long) buffer_len); return(NULL); } for (; idx > 0; idx--) { buffer_p++; buffer_len--; size <<= 8; size |= buffer_p[0]; } } else { size = buffer_p[0]; } buffer_p++; buffer_len--; if (size > outbuffer_len) { CACKEY_DEBUG_PRINTF("Unable to copy value buffer to outbuffer, not enough room. Value buffer length = %lu, out buffer length = %lu", (unsigned long) size, (unsigned long) outbuffer_len); return(NULL); } *outbuffer_len_p = size; if (outbuffer) { memcpy(outbuffer, buffer_p, size); buffer_p += size; buffer_len -= size; *buffer_len_p = buffer_len; CACKEY_DEBUG_PRINTBUF("BER-TLV results:", outbuffer, size); } else { memmove(buffer, buffer_p, size); buffer_p = buffer; CACKEY_DEBUG_PRINTBUF("BER-TLV results:", buffer, size); } CACKEY_DEBUG_PRINTF("Returning in success. Size of contents for tag %02x is %lu", (unsigned int) tag, (unsigned long) size); return(buffer_p); } /* * SYNPOSIS * ssize_t cackey_get_data(struct cackey_slot *slot, unsigned char *buffer, size_t buffer_len, unsigned char oid[3]); * * ARGUMENTS * struct cackey_slot *slot * Slot to send commands to * * unsigned char *buffer * [OUT] Buffer * * size_t buffer_len * Number of bytes to attempt to read * * unsigned char oid[3] * 3-byte OID to read * * * RETURN VALUE * This function returns the number of bytes actually read, or -1 on error. * * NOTES * None * */ static ssize_t cackey_get_data(struct cackey_slot *slot, unsigned char *buffer, size_t buffer_len, unsigned char oid[3]) { unsigned char cmd[] = {0x5C, 0x03, 0x00, 0x00, 0x00}; unsigned char *buffer_p; size_t init_buffer_len, size; uint16_t respcode; int send_ret; CACKEY_DEBUG_PRINTF("Called."); init_buffer_len = buffer_len; cmd[2] = oid[0]; cmd[3] = oid[1]; cmd[4] = oid[2]; /* 256 to indicate the largest message size -- not clear if this will work with all messages */ send_ret = cackey_send_apdu(slot, GSCIS_CLASS_ISO7816, NISTSP800_73_3_INSTR_GET_DATA, 0x3F, 0xFF, sizeof(cmd), cmd, 256, &respcode, buffer, &buffer_len); if (send_ret == CACKEY_PCSC_E_RETRY) { CACKEY_DEBUG_PRINTF("ADPU Sending failed, retrying read buffer"); return(cackey_get_data(slot, buffer, init_buffer_len, oid)); } if (send_ret != CACKEY_PCSC_S_OK) { CACKEY_DEBUG_PRINTF("cackey_send_apdu() failed, returning in failure"); return(-1); } #ifdef CACKEY_PARANOID # ifdef _POSIX_SSIZE_MAX if (buffer_len > _POSIX_SSIZE_MAX) { CACKEY_DEBUG_PRINTF("Read bytes (buffer_len) exceeds maximum value, returning in failure. (max = %li, buffer_len = %lu)", (long) _POSIX_SSIZE_MAX, (unsigned long) buffer_len); return(-1); } # endif #endif if (buffer_len < 2) { CACKEY_DEBUG_PRINTF("APDU GET DATA returned %lu bytes, which is too short for a BER-TLV response", (unsigned long) buffer_len); return(-1); } size = buffer_len; buffer_p = cackey_read_bertlv_tag(buffer, &buffer_len, 0x53, NULL, &size); if (buffer_p == NULL) { CACKEY_DEBUG_PRINTF("Tag decoding failed, returning in error."); return(-1); } CACKEY_DEBUG_PRINTBUF("GET DATA result", buffer, size); CACKEY_DEBUG_PRINTF("Returning in success, read %lu bytes", (unsigned long) size); return(size); } /* * SYNPOSIS * ssize_t cackey_read_buffer(struct cackey_slot *slot, unsigned char *buffer, size_t count, unsigned char t_or_v, size_t initial_offset); * * ARGUMENTS * struct cackey_slot *slot ................................................................................ if (free_start) { free(start); } return; } static struct cackey_pcsc_identity *cackey_copy_certs(struct cackey_pcsc_identity *dest, struct cackey_pcsc_identity *start, size_t count) { size_t idx; if (start == NULL) { return(NULL); } if (dest == NULL) { dest = malloc(sizeof(*dest) * count); } for (idx = 0; idx < count; idx++) { dest[idx].id_type = start[idx].id_type; switch (dest[idx].id_type) { case CACKEY_ID_TYPE_CAC: memcpy(dest[idx].card.cac.applet, start[idx].card.cac.applet, sizeof(dest[idx].card.cac.applet)); dest[idx].card.cac.file = start[idx].card.cac.file; break; case CACKEY_ID_TYPE_PIV: dest[idx].card.piv.key_id = start[idx].card.piv.key_id; memcpy(dest[idx].card.piv.label, start[idx].card.piv.label, sizeof(dest[idx].card.piv.label)); break; case CACKEY_ID_TYPE_CERT_ONLY: break; } dest[idx].certificate_len = start[idx].certificate_len; dest[idx].keysize = start[idx].keysize; dest[idx].certificate = malloc(dest[idx].certificate_len); memcpy(dest[idx].certificate, start[idx].certificate, dest[idx].certificate_len); } return(dest); } /* * SYNPOSIS * ... * * ARGUMENTS * ... ................................................................................ * NOTES * ... * */ static struct cackey_pcsc_identity *cackey_read_certs(struct cackey_slot *slot, struct cackey_pcsc_identity *certs, unsigned long *count) { struct cackey_pcsc_identity *curr_id; struct cackey_tlv_entity *ccc_tlv, *ccc_curr, *app_tlv, *app_curr; unsigned char ccc_aid[] = {GSCIS_AID_CCC}, piv_aid[] = {NISTSP800_73_3_PIV_AID}; unsigned char *piv_oid, piv_oid_pivauth[] = {NISTSP800_73_3_OID_PIVAUTH}, piv_oid_signature[] = {NISTSP800_73_3_OID_SIGNATURE}, piv_oid_keymgt[] = {NISTSP800_73_3_OID_KEYMGT}; unsigned char curr_aid[7]; unsigned char buffer[8192], *buffer_p, *tmpbuf; unsigned long outidx = 0; char *piv_label; cackey_ret transaction_ret; ssize_t read_ret; size_t buffer_len, tmpbuflen; int certs_resizable; int send_ret, select_ret; int piv_key, piv = 0; int idx; #ifdef HAVE_LIBZ int uncompress_ret; z_stream gzip_stream; #endif CACKEY_DEBUG_PRINTF("Called."); if (count == NULL) { CACKEY_DEBUG_PRINTF("count is NULL, returning in failure"); return(NULL); ................................................................................ if (certs != NULL) { if (*count == 0) { CACKEY_DEBUG_PRINTF("Requested we return 0 objects, short-circuit"); return(certs); } } if (!slot->slot_reset) { if (slot->cached_certs) { if (certs == NULL) { certs = malloc(sizeof(*certs) * slot->cached_certs_count); *count = slot->cached_certs_count; } else { if (*count > slot->cached_certs_count) { *count = slot->cached_certs_count; } } cackey_copy_certs(certs, slot->cached_certs, *count); return(certs); } } if (slot->cached_certs) { cackey_free_certs(slot->cached_certs, slot->cached_certs_count, 1); slot->cached_certs = NULL; } /* Begin a SmartCard transaction */ transaction_ret = cackey_begin_transaction(slot); if (transaction_ret != CACKEY_PCSC_S_OK) { CACKEY_DEBUG_PRINTF("Unable begin transaction, returning in failure"); return(NULL); ................................................................................ } else { certs_resizable = 0; } /* Select the CCC Applet */ send_ret = cackey_select_applet(slot, ccc_aid, sizeof(ccc_aid)); if (send_ret != CACKEY_PCSC_S_OK) { /* Try PIV application */ send_ret = cackey_select_applet(slot, piv_aid, sizeof(piv_aid)); if (send_ret == CACKEY_PCSC_S_OK) { CACKEY_DEBUG_PRINTF("We have a PIV card -- not using the CCC, pulling pre-selected keys"); piv = 1; } else { CACKEY_DEBUG_PRINTF("Unable to select CCC Applet, returning in failure"); /* Terminate SmartCard Transaction */ cackey_end_transaction(slot); return(NULL); } } if (piv) { for (idx = 0; idx < 3; idx++) { switch (idx) { case 0: piv_oid = piv_oid_pivauth; piv_key = NISTSP800_78_3_KEY_PIVAUTH; piv_label = "Authentication"; break; case 1: piv_oid = piv_oid_signature; piv_key = NISTSP800_78_3_KEY_SIGNATURE; piv_label = "Signature"; break; case 2: piv_oid = piv_oid_keymgt; piv_key = NISTSP800_78_3_KEY_KEYMGT; piv_label = "Key Management"; break; } read_ret = cackey_get_data(slot, buffer, sizeof(buffer), piv_oid); if (read_ret <= 0) { continue; } curr_id = &certs[outidx]; outidx++; curr_id->keysize = -1; curr_id->id_type = CACKEY_ID_TYPE_PIV; curr_id->card.piv.key_id = piv_key; memcpy(curr_id->card.piv.label, piv_label, strlen(piv_label) + 1); curr_id->certificate_len = read_ret; curr_id->certificate = malloc(curr_id->certificate_len); buffer_len = sizeof(buffer); buffer_p = cackey_read_bertlv_tag(buffer, &buffer_len, 0x70, curr_id->certificate, &curr_id->certificate_len); if (buffer_p == NULL) { CACKEY_DEBUG_PRINTF("Reading certificate from BER-TLV response failed, skipping key %i", idx); free(curr_id->certificate); curr_id->certificate = NULL; outidx--; continue; } #ifdef HAVE_LIBZ if (curr_id->certificate_len > 4) { if (memcmp(curr_id->certificate, "\x1f\x8b\x08\x00", 4) == 0) { tmpbuflen = curr_id->certificate_len * 2; tmpbuf = malloc(tmpbuflen); CACKEY_DEBUG_PRINTBUF("Attempting to decompress:", curr_id->certificate, curr_id->certificate_len); gzip_stream.zalloc = NULL; gzip_stream.zfree = NULL; gzip_stream.opaque = NULL; gzip_stream.next_in = curr_id->certificate; gzip_stream.avail_in = curr_id->certificate_len; gzip_stream.next_out = tmpbuf; gzip_stream.avail_out = tmpbuflen; uncompress_ret = inflateInit(&gzip_stream); if (uncompress_ret == Z_OK) { uncompress_ret = inflateReset2(&gzip_stream, 31); } if (uncompress_ret == Z_OK) { uncompress_ret = inflate(&gzip_stream, 0); } if (uncompress_ret == Z_STREAM_END) { uncompress_ret = inflateEnd(&gzip_stream); } else { uncompress_ret = Z_DATA_ERROR; } if (uncompress_ret == Z_OK) { tmpbuflen = gzip_stream.total_out; CACKEY_DEBUG_PRINTBUF("Decompressed to:", tmpbuf, tmpbuflen); free(curr_id->certificate); curr_id->certificate = tmpbuf; curr_id->certificate_len = tmpbuflen; } else { CACKEY_DEBUG_PRINTF("Decompressing failed! uncompress() returned %i", uncompress_ret); free(tmpbuf); } } } #endif } } else { /* Read all the applets from the CCC's TLV */ ccc_tlv = cackey_read_tlv(slot); /* Look for CARDURLs that coorespond to PKI applets */ for (ccc_curr = ccc_tlv; ccc_curr; ccc_curr = ccc_curr->_next) { CACKEY_DEBUG_PRINTF("Found tag: %s ... ", CACKEY_DEBUG_FUNC_TAG_TO_STR(ccc_curr->tag)); if (ccc_curr->tag != GSCIS_TAG_CARDURL) { CACKEY_DEBUG_PRINTF(" ... skipping it (we only care about CARDURLs)"); continue; } if ((ccc_curr->value_cardurl->apptype & CACKEY_TLV_APP_PKI) != CACKEY_TLV_APP_PKI) { CACKEY_DEBUG_PRINTF(" ... skipping it (we only care about PKI applets, this applet supports: %s/%02x)", CACKEY_DEBUG_FUNC_APPTYPE_TO_STR(ccc_curr->value_cardurl->apptype), (unsigned int) ccc_curr->value_cardurl->apptype); continue; } CACKEY_DEBUG_PRINTBUF("RID:", ccc_curr->value_cardurl->rid, sizeof(ccc_curr->value_cardurl->rid)); CACKEY_DEBUG_PRINTF("AppID = %s/%04lx", CACKEY_DEBUG_FUNC_OBJID_TO_STR(ccc_curr->value_cardurl->appid), (unsigned long) ccc_curr->value_cardurl->appid); CACKEY_DEBUG_PRINTF("ObjectID = %s/%04lx", CACKEY_DEBUG_FUNC_OBJID_TO_STR(ccc_curr->value_cardurl->objectid), (unsigned long) ccc_curr->value_cardurl->objectid); memcpy(curr_aid, ccc_curr->value_cardurl->rid, sizeof(ccc_curr->value_cardurl->rid)); curr_aid[sizeof(curr_aid) - 2] = (ccc_curr->value_cardurl->appid >> 8) & 0xff; curr_aid[sizeof(curr_aid) - 1] = ccc_curr->value_cardurl->appid & 0xff; /* Select found applet ... */ select_ret = cackey_select_applet(slot, curr_aid, sizeof(curr_aid)); if (select_ret != CACKEY_PCSC_S_OK) { CACKEY_DEBUG_PRINTF("Failed to select applet, skipping processing of this object"); continue; } /* ... and object (file) */ select_ret = cackey_select_file(slot, ccc_curr->value_cardurl->objectid); if (select_ret != CACKEY_PCSC_S_OK) { CACKEY_DEBUG_PRINTF("Failed to select file, skipping processing of this object"); continue; } /* Process this file's TLV looking for certificates */ app_tlv = cackey_read_tlv(slot); for (app_curr = app_tlv; app_curr; app_curr = app_curr->_next) { CACKEY_DEBUG_PRINTF("Found tag: %s", CACKEY_DEBUG_FUNC_TAG_TO_STR(app_curr->tag)); if (app_curr->tag != GSCIS_TAG_CERTIFICATE) { CACKEY_DEBUG_PRINTF(" ... skipping it (we only care about CERTIFICATEs)"); continue; } curr_id = &certs[outidx]; outidx++; curr_id->id_type = CACKEY_ID_TYPE_CAC; memcpy(curr_id->card.cac.applet, curr_aid, sizeof(curr_id->card.cac.applet)); curr_id->card.cac.file = ccc_curr->value_cardurl->objectid; curr_id->keysize = -1; CACKEY_DEBUG_PRINTF("Filling curr_id->card.cac.applet (%p) with %lu bytes:", curr_id->card.cac.applet, (unsigned long) sizeof(curr_id->card.cac.applet)); CACKEY_DEBUG_PRINTBUF("VAL:", curr_id->card.cac.applet, sizeof(curr_id->card.cac.applet)); curr_id->certificate_len = app_curr->length; curr_id->certificate = malloc(curr_id->certificate_len); memcpy(curr_id->certificate, app_curr->value, curr_id->certificate_len); if (outidx >= *count) { if (certs_resizable) { *count *= 2; if (*count != 0) { certs = realloc(certs, sizeof(*certs) * (*count)); } else { certs = NULL; } } else { break; } } } cackey_free_tlv(app_tlv); if (outidx >= *count) { break; } } cackey_free_tlv(ccc_tlv); } *count = outidx; if (certs_resizable) { if (*count != 0) { certs = realloc(certs, sizeof(*certs) * (*count)); } else { certs = NULL; } } slot->cached_certs = cackey_copy_certs(NULL, certs, *count); slot->cached_certs_count = *count; /* Terminate SmartCard Transaction */ cackey_end_transaction(slot); return(certs); } ................................................................................ * ... * * NOTES * ... * */ static ssize_t cackey_signdecrypt(struct cackey_slot *slot, struct cackey_identity *identity, unsigned char *buf, size_t buflen, unsigned char *outbuf, size_t outbuflen, int padInput, int unpadOutput) { cackey_pcsc_id_type id_type; unsigned char dyn_auth_template[10], *dyn_auth_tmpbuf; unsigned char *tmpbuf, *tmpbuf_s, *outbuf_s, *outbuf_p; unsigned char bytes_to_send, p1, class; unsigned char blocktype; cackey_ret send_ret; uint16_t respcode; ssize_t retval = 0, unpadoffset; size_t tmpbuflen, padlen, tmpoutbuflen, outbuf_len; int free_tmpbuf = 0; int le; CACKEY_DEBUG_PRINTF("Called."); if (slot == NULL) { CACKEY_DEBUG_PRINTF("Error. slot is NULL"); ................................................................................ } if (identity->pcsc_identity == NULL) { CACKEY_DEBUG_PRINTF("Error. identity->pcsc_identity is NULL"); return(-1); } id_type = identity->pcsc_identity->id_type; if (id_type == CACKEY_ID_TYPE_CERT_ONLY) { CACKEY_DEBUG_PRINTF("Error. identity->pcsc_identity is CACKEY_ID_TYPE_CERT_ONLY, which cannot be used for sign/decrypt"); return(-1); } switch (id_type) { case CACKEY_ID_TYPE_PIV: case CACKEY_ID_TYPE_CAC: break; default: CACKEY_DEBUG_PRINTF("Error. identity->pcsc_identity is not a supported value. Type is: 0x%lx (PIV = 0x%lx, CAC = 0x%lx)", (unsigned long) id_type, (unsigned long) CACKEY_ID_TYPE_PIV, (unsigned long) CACKEY_ID_TYPE_CAC); return(-1); } /* Determine identity Key size */ if (identity->pcsc_identity->keysize < 0) { identity->pcsc_identity->keysize = x509_to_keysize(identity->pcsc_identity->certificate, identity->pcsc_identity->certificate_len); } /* Pad message to key size */ ................................................................................ padlen = 0; } /* Begin transaction */ cackey_begin_transaction(slot); /* Select correct applet */ switch (id_type) { case CACKEY_ID_TYPE_CAC: CACKEY_DEBUG_PRINTF("Selecting applet found at %p ...", identity->pcsc_identity->card.cac.applet); cackey_select_applet(slot, identity->pcsc_identity->card.cac.applet, sizeof(identity->pcsc_identity->card.cac.applet)); /* Select correct file */ cackey_select_file(slot, identity->pcsc_identity->card.cac.file); break; case CACKEY_ID_TYPE_PIV: dyn_auth_template[0] = 0x7C; dyn_auth_template[1] = 0x82; dyn_auth_template[2] = ((tmpbuflen + 6) & 0xff00) >> 8; dyn_auth_template[3] = (tmpbuflen + 6) & 0x00ff; dyn_auth_template[4] = 0x82; dyn_auth_template[5] = 0x00; dyn_auth_template[6] = 0x81; dyn_auth_template[7] = 0x82; dyn_auth_template[8] = (tmpbuflen & 0xff00) >> 8; dyn_auth_template[9] = tmpbuflen & 0x00ff; dyn_auth_tmpbuf = malloc(tmpbuflen + sizeof(dyn_auth_template)); memcpy(dyn_auth_tmpbuf, dyn_auth_template, sizeof(dyn_auth_template)); memcpy(dyn_auth_tmpbuf + sizeof(dyn_auth_template), tmpbuf, tmpbuflen); if (free_tmpbuf) { free(tmpbuf); } tmpbuflen += sizeof(dyn_auth_template); tmpbuf = dyn_auth_tmpbuf; free_tmpbuf = 1; break; case CACKEY_ID_TYPE_CERT_ONLY: break; } tmpbuf_s = tmpbuf; outbuf_s = outbuf; while (tmpbuflen) { tmpoutbuflen = outbuflen; if (tmpbuflen > CACKEY_APDU_MTU) { bytes_to_send = CACKEY_APDU_MTU; } else { bytes_to_send = tmpbuflen; } send_ret = CACKEY_PCSC_E_GENERIC; switch (id_type) { case CACKEY_ID_TYPE_CAC: if (tmpbuflen > CACKEY_APDU_MTU) { p1 = 0x80; le = 0x00; } else { p1 = 0x00; le = 0x00; } send_ret = cackey_send_apdu(slot, GSCIS_CLASS_GLOBAL_PLATFORM, GSCIS_INSTR_SIGNDECRYPT, p1, 0x00, bytes_to_send, tmpbuf, le, &respcode, outbuf, &tmpoutbuflen); break; case CACKEY_ID_TYPE_PIV: if (tmpbuflen > CACKEY_APDU_MTU) { class = 0x10; le = 0x00; } else { class = GSCIS_CLASS_ISO7816; le = 256; } send_ret = cackey_send_apdu(slot, class, NISTSP800_73_3_INSTR_GENAUTH, NISTSP800_78_3_ALGO_RSA2048, identity->pcsc_identity->card.piv.key_id, bytes_to_send, tmpbuf, le, &respcode, outbuf, &tmpoutbuflen); break; case CACKEY_ID_TYPE_CERT_ONLY: break; } if (send_ret != CACKEY_PCSC_S_OK) { if (free_tmpbuf) { if (tmpbuf_s) { free(tmpbuf_s); } } /* End transaction */ cackey_end_transaction(slot); if (send_ret == CACKEY_PCSC_E_RETRY) { CACKEY_DEBUG_PRINTF("ADPU Sending Failed -- retrying."); return(cackey_signdecrypt(slot, identity, buf, buflen, outbuf, outbuflen, padInput, unpadOutput)); } CACKEY_DEBUG_PRINTF("ADPU Sending Failed -- returning in error."); if (respcode == 0x6982 || respcode == 0x6e00) { if (respcode == 0x6E00) { CACKEY_DEBUG_PRINTF("Got \"WRONG CLASS\", this means we are talking to the wrong object (likely because the card went away) -- resetting"); } else { CACKEY_DEBUG_PRINTF("Security status not satisified (respcode = 0x%04x). Returning NEEDLOGIN", (int) respcode); } cackey_mark_slot_reset(slot); return(CACKEY_PCSC_E_NEEDLOGIN); } if (send_ret == CACKEY_PCSC_E_TOKENABSENT) { ................................................................................ if (outbuflen > _POSIX_SSIZE_MAX) { CACKEY_DEBUG_PRINTF("Outbuflen exceeds maximum value, returning in failure. (max = %li, outbuflen = %lu)", (long) _POSIX_SSIZE_MAX, (unsigned long) outbuflen); return(-1); } # endif #endif /* We must remove the "7C" tag to get to the signature */ switch (id_type) { case CACKEY_ID_TYPE_PIV: outbuf_len = retval; outbuf_p = cackey_read_bertlv_tag(outbuf, &outbuf_len, 0x7C, NULL, &outbuf_len); if (outbuf_p == NULL) { CACKEY_DEBUG_PRINTF("Response from PIV for GENERATE AUTHENTICATION was not a 0x7C tag, returning in failure"); return(-1); } retval = outbuf_len; outbuf_len = retval; outbuf_p = cackey_read_bertlv_tag(outbuf, &outbuf_len, 0x82, NULL, &outbuf_len); if (outbuf_p == NULL) { CACKEY_DEBUG_PRINTF("Response from PIV for GENERATE AUTHENTICATION was not a 0x82 within a 0x7C tag, returning in failure"); return(-1); } retval = outbuf_len; break; case CACKEY_ID_TYPE_CAC: case CACKEY_ID_TYPE_CERT_ONLY: break; } /* Unpad reply */ if (unpadOutput) { if (retval < 3) { CACKEY_DEBUG_PRINTF("Reply is too small, we are not able to unpad -- passing back and hoping for the best!"); CACKEY_DEBUG_PRINTF("Returning in success, retval = %li (bytes)", (long) retval); ................................................................................ * ... * * NOTES * ... * */ static cackey_ret cackey_login(struct cackey_slot *slot, unsigned char *pin, unsigned long pin_len, int *tries_remaining_p) { struct cackey_pcsc_identity *pcsc_identities; unsigned char cac_pin[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; unsigned long num_certs; uint16_t response_code; int tries_remaining; int send_ret; int key_reference = 0x00; /* Indicate that we do not know about how many tries are remaining */ if (tries_remaining_p) { *tries_remaining_p = -1; } /* Apparently, CAC PINs are *EXACTLY* 8 bytes long -- pad with 0xFF if too short */ if (pin_len >= 8) { memcpy(cac_pin, pin, 8); } else { memcpy(cac_pin, pin, pin_len); } /* Reject PINs which are too short */ if (pin_len < 5) { CACKEY_DEBUG_PRINTF("Rejecting PIN which is too short (length = %lu, must be atleast 5)", pin_len); return(CACKEY_PCSC_E_BADPIN); } /* PIV authentication uses a "key_reference" of 0x80 */ pcsc_identities = cackey_read_certs(slot, NULL, &num_certs); if (num_certs > 0 && pcsc_identities != NULL) { switch (pcsc_identities[0].id_type) { case CACKEY_ID_TYPE_PIV: CACKEY_DEBUG_PRINTF("We have PIV card, so we will attempt to authenticate using the PIV Application key reference"); key_reference = 0x80; break; default: break; } cackey_free_certs(pcsc_identities, num_certs, 1); } /* Issue PIN Verify */ send_ret = cackey_send_apdu(slot, GSCIS_CLASS_ISO7816, GSCIS_INSTR_VERIFY, 0x00, key_reference, sizeof(cac_pin), cac_pin, 0x00, &response_code, NULL, NULL); if (send_ret != CACKEY_PCSC_S_OK) { if ((response_code & 0x63C0) == 0x63C0) { tries_remaining = (response_code & 0xF); CACKEY_DEBUG_PRINTF("PIN Verification failed, %i tries remaining", tries_remaining); if (tries_remaining_p) { ................................................................................ * * NOTES * ... * */ static cackey_ret cackey_token_present(struct cackey_slot *slot) { cackey_ret pcsc_connect_ret; DWORD reader_len = 0, state = 0, protocol = 0, atr_len; BYTE atr[MAX_ATR_SIZE]; LONG status_ret, scard_reconn_ret; CACKEY_DEBUG_PRINTF("Called."); if (slot->internal) { CACKEY_DEBUG_PRINTF("Returning token present (internal token)"); return(CACKEY_PCSC_S_TOKENPRESENT); } pcsc_connect_ret = cackey_connect_card(slot); if (pcsc_connect_ret != CACKEY_PCSC_S_OK) { CACKEY_DEBUG_PRINTF("Unable to connect to card, returning token absent"); return(CACKEY_PCSC_E_TOKENABSENT); } CACKEY_DEBUG_PRINTF("Calling SCardStatus() to determine card status"); atr_len = sizeof(atr); status_ret = SCardStatus(slot->pcsc_card, NULL, &reader_len, &state, &protocol, atr, &atr_len); if (status_ret == SCARD_E_INVALID_HANDLE) { CACKEY_DEBUG_PRINTF("SCardStatus() returned SCARD_E_INVALID_HANDLE, marking is not already connected and trying again"); cackey_mark_slot_reset(slot); ................................................................................ pcsc_connect_ret = cackey_connect_card(slot); if (pcsc_connect_ret != CACKEY_PCSC_S_OK) { CACKEY_DEBUG_PRINTF("Unable to connect to card, returning token absent"); return(CACKEY_PCSC_E_TOKENABSENT); } CACKEY_DEBUG_PRINTF("Calling SCardStatus() again"); atr_len = sizeof(atr); status_ret = SCardStatus(slot->pcsc_card, NULL, &reader_len, &state, &protocol, atr, &atr_len); } if (status_ret != SCARD_S_SUCCESS) { cackey_mark_slot_reset(slot); if (status_ret == SCARD_W_RESET_CARD) { CACKEY_DEBUG_PRINTF("Reset required, please hold..."); scard_reconn_ret = cackey_reconnect_card(slot, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1); if (scard_reconn_ret == SCARD_S_SUCCESS) { /* Re-establish transaction, if it was present */ if (slot->transaction_depth > 0) { slot->transaction_depth--; slot->transaction_need_hw_lock = 1; cackey_begin_transaction(slot); } ................................................................................ CACKEY_DEBUG_PRINTF(" ... returning %lu (%p/%lu)", (unsigned long) *((CK_BBOOL *) pValue), pValue, (unsigned long) ulValueLen); break; case CKA_LABEL: CACKEY_DEBUG_PRINTF("Requesting attribute CKA_LABEL (0x%08lx) ...", (unsigned long) curr_attr_type); if (identity->id_type == CACKEY_ID_TYPE_PIV) { pValue = identity->card.piv.label; ulValueLen = strlen(pValue); } else { ulValueLen = snprintf((char *) ucTmpBuf, sizeof(ucTmpBuf), "Identity #%lu", (unsigned long) identity_num); pValue = ucTmpBuf; if (ulValueLen >= sizeof(ucTmpBuf)) { ulValueLen = 0; pValue = NULL; } } CACKEY_DEBUG_PRINTF(" ... returning (%p/%lu)", pValue, (unsigned long) ulValueLen); break; case CKA_VALUE: CACKEY_DEBUG_PRINTF("Requesting attribute CKA_VALUE (0x%08lx) ...", (unsigned long) curr_attr_type); ................................................................................ cackey_free_certs(identities[id_idx].pcsc_identity, 1, 1); } } free(identities); } static unsigned long cackey_read_dod_identities(struct cackey_identity *identities, unsigned long num_dod_certs) { unsigned long cert_idx, id_idx = 0; if (identities == NULL) { return(num_dod_certs * 3); } for (cert_idx = 0; cert_idx < num_dod_certs; cert_idx++) { identities[id_idx].pcsc_identity = NULL; identities[id_idx].attributes = cackey_get_attributes(CKO_CERTIFICATE, &extra_certs[cert_idx], 0xf000 | cert_idx, &identities[id_idx].attributes_count); id_idx++; identities[id_idx].pcsc_identity = NULL; identities[id_idx].attributes = cackey_get_attributes(CKO_PUBLIC_KEY, &extra_certs[cert_idx], 0xf000 | cert_idx, &identities[id_idx].attributes_count); id_idx++; identities[id_idx].pcsc_identity = NULL; identities[id_idx].attributes = cackey_get_attributes(CKO_NETSCAPE_TRUST, &extra_certs[cert_idx], 0xf000 | cert_idx, &identities[id_idx].attributes_count); id_idx++; } return(id_idx); } static struct cackey_identity *cackey_read_identities(struct cackey_slot *slot, unsigned long *ids_found) { struct cackey_pcsc_identity *pcsc_identities; struct cackey_identity *identities; unsigned long num_ids, id_idx, curr_id_type; unsigned long num_certs, num_dod_certs, cert_idx; int include_extra_certs = 0, include_dod_certs; CACKEY_DEBUG_PRINTF("Called."); if (ids_found == NULL) { CACKEY_DEBUG_PRINTF("Error. ids_found is NULL"); return(NULL); } #ifdef CACKEY_CARD_SLOT_INCLUDE_EXTRA_CERTS include_extra_certs = 1; #endif if (getenv("CACKEY_DOD_CERTS_ON_HW_SLOTS") != NULL) { include_extra_certs = 1; } if (getenv("CACKEY_NO_DOD_CERTS_ON_HW_SLOTS") != NULL) { include_extra_certs = 0; } #ifdef CACKEY_NO_EXTRA_CERTS if (getenv("CACKEY_EXTRA_CERTS") != NULL) { include_dod_certs = 1; } else { include_dod_certs = 0; } #else if (getenv("CACKEY_NO_EXTRA_CERTS") != NULL) { include_dod_certs = 0; } else { include_dod_certs = 1; } #endif if (include_dod_certs) { num_dod_certs = sizeof(extra_certs) / sizeof(extra_certs[0]); } else { num_dod_certs = 0; } if (slot->internal) { num_ids = cackey_read_dod_identities(NULL, num_dod_certs); if (num_ids != 0) { identities = malloc(num_ids * sizeof(*identities)); cackey_read_dod_identities(identities, num_dod_certs); } else { identities = NULL; } *ids_found = num_ids; return(identities); } pcsc_identities = cackey_read_certs(slot, NULL, &num_certs); if (pcsc_identities != NULL) { /* Convert number of Certs to number of objects */ num_ids = (CKO_PRIVATE_KEY - CKO_CERTIFICATE + 1) * num_certs; if (include_extra_certs) { num_ids += cackey_read_dod_identities(NULL, num_dod_certs); } identities = malloc(num_ids * sizeof(*identities)); /* Add certificates, public keys, and private keys from the smartcard */ id_idx = 0; for (cert_idx = 0; cert_idx < num_certs; cert_idx++) { for (curr_id_type = CKO_CERTIFICATE; curr_id_type <= CKO_PRIVATE_KEY; curr_id_type++) { ................................................................................ identities[id_idx].pcsc_identity->certificate = malloc(pcsc_identities[cert_idx].certificate_len); memcpy(identities[id_idx].pcsc_identity->certificate, pcsc_identities[cert_idx].certificate, pcsc_identities[cert_idx].certificate_len); id_idx++; } } if (include_extra_certs) { CACKEY_DEBUG_PRINTF("Including US Government Certificates on hardware slot"); cackey_read_dod_identities(identities + id_idx, num_dod_certs); } cackey_free_certs(pcsc_identities, num_certs, 1); *ids_found = num_ids; return(identities); } *ids_found = 0; return(NULL); } CK_DEFINE_FUNCTION(CK_RV, C_Initialize)(CK_VOID_PTR pInitArgs) { CK_C_INITIALIZE_ARGS CK_PTR args; uint32_t idx, highest_slot; int mutex_init_ret; int include_dod_certs; CACKEY_DEBUG_PRINTF("Called."); if (cackey_initialized) { CACKEY_DEBUG_PRINTF("Error. Already initialized."); return(CKR_CRYPTOKI_ALREADY_INITIALIZED); ................................................................................ cackey_slots[idx].active = 0; cackey_slots[idx].pcsc_reader = NULL; cackey_slots[idx].transaction_depth = 0; cackey_slots[idx].transaction_need_hw_lock = 0; cackey_slots[idx].slot_reset = 0; cackey_slots[idx].token_flags = 0; cackey_slots[idx].label = NULL; cackey_slots[idx].internal = 0; } #ifdef CACKEY_NO_EXTRA_CERTS if (getenv("CACKEY_EXTRA_CERTS") != NULL) { include_dod_certs = 1; } else { include_dod_certs = 0; } #else if (getenv("CACKEY_NO_EXTRA_CERTS") != NULL) { include_dod_certs = 0; } else { include_dod_certs = 1; } #endif if (include_dod_certs == 0) { CACKEY_DEBUG_PRINTF("Asked not to include DoD certificates"); } else { highest_slot = (sizeof(cackey_slots) / sizeof(cackey_slots[0])) - 1; CACKEY_DEBUG_PRINTF("Including DoD certs in slot %lu", (unsigned long) highest_slot); cackey_slots[highest_slot].active = 1; cackey_slots[highest_slot].internal = 1; cackey_slots[highest_slot].label = (unsigned char *) "US Government Certificates"; cackey_slots[highest_slot].pcsc_reader = "CACKey"; cackey_slots[highest_slot].token_flags = 0; } cackey_initialized = 1; if (!cackey_biglock_init) { mutex_init_ret = cackey_mutex_create(&cackey_biglock); ................................................................................ CACKEY_DEBUG_PRINTF("Error. Mutex initialization failed."); return(CKR_CANT_LOCK); } cackey_biglock_init = 1; } /* Define a command to prompt user for a PIN */ #ifdef CACKEY_PIN_COMMAND_DEFAULT cackey_pin_command = CACKEY_PIN_COMMAND_DEFAULT_XSTR(CACKEY_PIN_COMMAND_DEFAULT); #endif #ifdef CACKEY_PIN_COMMAND_XONLY_DEFAULT if (getenv("DISPLAY") != NULL) { cackey_pin_command = CACKEY_PIN_COMMAND_DEFAULT_XSTR(CACKEY_PIN_COMMAND_XONLY_DEFAULT); } #endif if (getenv("CACKEY_PIN_COMMAND") != NULL) { cackey_pin_command = getenv("CACKEY_PIN_COMMAND"); } if (getenv("CACKEY_PIN_COMMAND_XONLY") != NULL && getenv("DISPLAY") != NULL) { cackey_pin_command = getenv("CACKEY_PIN_COMMAND_XONLY"); } CACKEY_DEBUG_PRINTF("Returning CKR_OK (%i)", CKR_OK); return(CKR_OK); } CK_DEFINE_FUNCTION(CK_RV, C_Finalize)(CK_VOID_PTR pReserved) { ................................................................................ C_CloseSession(idx); } } cackey_slots_disconnect_all(); for (idx = 0; idx < (sizeof(cackey_slots) / sizeof(cackey_slots[0])); idx++) { if (cackey_slots[idx].internal) { continue; } if (cackey_slots[idx].pcsc_reader) { free(cackey_slots[idx].pcsc_reader); } if (cackey_slots[idx].cached_certs) { cackey_free_certs(cackey_slots[idx].cached_certs, cackey_slots[idx].cached_certs_count, 1); cackey_slots[idx].cached_certs = NULL; } } cackey_pcsc_disconnect(); cackey_initialized = 0; CACKEY_DEBUG_PRINTF("Returning CKR_OK (%i)", CKR_OK); ................................................................................ return(CKR_OK); } /* * Process list of readers, and create mapping between reader name and slot ID */ CK_DEFINE_FUNCTION(CK_RV, C_GetSlotList)(CK_BBOOL tokenPresent, CK_SLOT_ID_PTR pSlotList, CK_ULONG_PTR pulCount) { static int first_call = 1; int mutex_retval; int pcsc_connect_ret; CK_ULONG count, slot_count = 0, currslot, slot_idx; char *pcsc_readers, *pcsc_readers_s, *pcsc_readers_e; DWORD pcsc_readers_len; LONG scard_listreaders_ret; size_t curr_reader_len; int slot_reset; CACKEY_DEBUG_PRINTF("Called."); if (pulCount == NULL) { CACKEY_DEBUG_PRINTF("Error. pulCount is NULL."); return(CKR_ARGUMENTS_BAD); ................................................................................ if (mutex_retval != 0) { CACKEY_DEBUG_PRINTF("Error. Locking failed."); return(CKR_GENERAL_ERROR); } /* Clear list of slots */ slot_reset = 0; if (pSlotList) { if (first_call) { first_call = 0; slot_reset = 1; } /* If any of the slots have been reset then purge all information and check again */ for (currslot = 0; currslot < (sizeof(cackey_slots) / sizeof(cackey_slots[0])); currslot++) { if (cackey_slots[currslot].internal) { continue; } if (!cackey_slots[currslot].active) { continue; } if (cackey_slots[currslot].slot_reset) { slot_reset = 1; break; } } if (slot_reset) { CACKEY_DEBUG_PRINTF("Purging all slot information."); /* Only update the list of slots if we are actually being supply the slot information */ cackey_slots_disconnect_all(); for (currslot = 0; currslot < (sizeof(cackey_slots) / sizeof(cackey_slots[0])); currslot++) { if (cackey_slots[currslot].internal) { continue; } if (cackey_slots[currslot].pcsc_reader) { free(cackey_slots[currslot].pcsc_reader); cackey_slots[currslot].pcsc_reader = NULL; } if (cackey_slots[currslot].label) { free(cackey_slots[currslot].label); cackey_slots[currslot].label = NULL; } cackey_slots[currslot].active = 0; } } else { } } /* Determine list of readers */ pcsc_connect_ret = cackey_pcsc_connect(); /* XXX: CAN HANG HERE ! */ if (pcsc_connect_ret != CACKEY_PCSC_S_OK) { CACKEY_DEBUG_PRINTF("Connection to PC/SC failed, assuming no slots"); slot_count = 0; } else { pcsc_readers_len = 0; ................................................................................ scard_listreaders_ret = SCardListReaders(*cackey_pcsc_handle, NULL, pcsc_readers, &pcsc_readers_len); if (scard_listreaders_ret == SCARD_S_SUCCESS) { pcsc_readers_e = pcsc_readers + pcsc_readers_len; /* Start with Slot ID 1, to avoid a bug in GDM on RHEL */ /* Bug 594911: https://bugzilla.redhat.com/show_bug.cgi?id=594911 */ currslot = 1; slot_count = 0; while (pcsc_readers < pcsc_readers_e) { /* Find next available slot */ for (; currslot < (sizeof(cackey_slots) / sizeof(cackey_slots[0])); currslot++) { if (!cackey_slots[currslot].active) { break; } } curr_reader_len = strlen(pcsc_readers); if ((pcsc_readers + curr_reader_len) > pcsc_readers_e) { break; } if (curr_reader_len == 0) { ................................................................................ if (currslot >= (sizeof(cackey_slots) / sizeof(cackey_slots[0]))) { CACKEY_DEBUG_PRINTF("Found more readers than slots are available!"); break; } CACKEY_DEBUG_PRINTF("Found reader: %s (currslot = %lu)", pcsc_readers, (unsigned long) currslot); /* Only update the list of slots if we are actually being asked supply the slot information */ if (pSlotList) { if (slot_reset) { cackey_slots[currslot].active = 1; cackey_slots[currslot].internal = 0; cackey_slots[currslot].pcsc_reader = strdup(pcsc_readers); cackey_slots[currslot].pcsc_card_connected = 0; cackey_slots[currslot].transaction_depth = 0; cackey_slots[currslot].transaction_need_hw_lock = 0; cackey_slots[currslot].token_flags = 0; cackey_slots[currslot].label = NULL; cackey_mark_slot_reset(&cackey_slots[currslot]); } } else { if (!cackey_slots[currslot].active) { /* Artificially increase the number of active slots by what will become active */ CACKEY_DEBUG_PRINTF("Found in-active slot %lu, but it will be active after a reset -- marking as active for accounting purposes", (unsigned long) currslot); slot_count++; } } currslot++; pcsc_readers += curr_reader_len + 1; } for (currslot = 0; currslot < (sizeof(cackey_slots) / sizeof(cackey_slots[0])); currslot++) { if (cackey_slots[currslot].active) { CACKEY_DEBUG_PRINTF("Found active slot %lu, reader = %s", (unsigned long) currslot, cackey_slots[currslot].pcsc_reader); slot_count++; } } } else { CACKEY_DEBUG_PRINTF("Second call to SCardListReaders failed, return %s/%li", CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(scard_listreaders_ret), (long) scard_listreaders_ret); } free(pcsc_readers_s); } else { ................................................................................ return(CKR_OK); } count = *pulCount; if (count < slot_count) { CACKEY_DEBUG_PRINTF("Error. User allocated %lu entries, but we have %lu entries.", count, slot_count); CACKEY_DEBUG_PRINTF("Returning CKR_BUFFER_TOO_SMALL"); return(CKR_BUFFER_TOO_SMALL); } mutex_retval = cackey_mutex_lock(cackey_biglock); if (mutex_retval != 0) { CACKEY_DEBUG_PRINTF("Error. Locking failed."); return(CKR_GENERAL_ERROR); } slot_idx = 0; for (currslot = 0; (currslot < (sizeof(cackey_slots) / sizeof(cackey_slots[0]))); currslot++) { if (!cackey_slots[currslot].active) { continue; } if (slot_idx >= count) { CACKEY_DEBUG_PRINTF("Error. User allocated %lu entries, but we just tried to write to the %lu index -- ignoring", count, slot_idx); continue; } pSlotList[slot_idx] = currslot; slot_idx++; } mutex_retval = cackey_mutex_unlock(cackey_biglock); if (mutex_retval != 0) { CACKEY_DEBUG_PRINTF("Error. Unlocking failed."); return(CKR_GENERAL_ERROR); } *pulCount = slot_count; CACKEY_DEBUG_PRINTF("Returning CKR_OK (%i). Found %lu readers.", CKR_OK, (unsigned long) slot_count); return(CKR_OK); ................................................................................ CACKEY_DEBUG_PRINTF("Error. Invalid slot requested (%lu), slot not currently active", slotID); cackey_mutex_unlock(cackey_biglock); return(CKR_SLOT_ID_INVALID); } pInfo->flags = CKF_HW_SLOT; if (!cackey_slots[slotID].internal) { pInfo->flags |= CKF_REMOVABLE_DEVICE; } if (cackey_token_present(&cackey_slots[slotID]) == CACKEY_PCSC_S_TOKENPRESENT) { pInfo->flags |= CKF_TOKEN_PRESENT; } bytes_to_copy = strlen(cackey_slots[slotID].pcsc_reader); if (sizeof(pInfo->manufacturerID) < bytes_to_copy) { ................................................................................ pInfo->hardwareVersion.major = (cackey_getversion() >> 16) & 0xff; pInfo->hardwareVersion.minor = (cackey_getversion() >> 8) & 0xff; pInfo->firmwareVersion.major = 0x00; pInfo->firmwareVersion.minor = 0x00; pInfo->flags = CKF_WRITE_PROTECTED | CKF_USER_PIN_INITIALIZED | CKF_TOKEN_INITIALIZED | cackey_slots[slotID].token_flags; if (cackey_pin_command != NULL) { pInfo->flags |= CKF_PROTECTED_AUTHENTICATION_PATH; } pInfo->ulMaxSessionCount = (sizeof(cackey_sessions) / sizeof(cackey_sessions[0])) - 1; pInfo->ulSessionCount = CK_UNAVAILABLE_INFORMATION; pInfo->ulMaxRwSessionCount = 0; pInfo->ulRwSessionCount = CK_UNAVAILABLE_INFORMATION; pInfo->ulMaxPinLen = 128; pInfo->ulMinPinLen = 0; ................................................................................ } CACKEY_DEBUG_PRINTF("Returning CKR_FUNCTION_NOT_SUPPORTED (%i)", CKR_FUNCTION_NOT_SUPPORTED); return(CKR_FUNCTION_NOT_SUPPORTED); } CK_DEFINE_FUNCTION(CK_RV, _C_LoginMutexArg)(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen, int lock_mutex) { CK_SLOT_ID slotID; FILE *pinfd; char *pincmd, pinbuf[64], *fgets_ret; int mutex_retval; int tries_remaining; int login_ret; int pclose_ret; CACKEY_DEBUG_PRINTF("Called."); if (!cackey_initialized) { CACKEY_DEBUG_PRINTF("Error. Not initialized."); return(CKR_CRYPTOKI_NOT_INITIALIZED); ................................................................................ if (userType != CKU_USER) { CACKEY_DEBUG_PRINTF("Error. We only support USER mode, asked for %lu mode.", (unsigned long) userType) return(CKR_USER_TYPE_INVALID); } if (lock_mutex) { mutex_retval = cackey_mutex_lock(cackey_biglock); if (mutex_retval != 0) { CACKEY_DEBUG_PRINTF("Error. Locking failed."); return(CKR_GENERAL_ERROR); } } if (!cackey_sessions[hSession].active) { if (lock_mutex) { cackey_mutex_unlock(cackey_biglock); } CACKEY_DEBUG_PRINTF("Error. Session not active."); return(CKR_SESSION_HANDLE_INVALID); } slotID = cackey_sessions[hSession].slotID; if (slotID < 0 || slotID >= (sizeof(cackey_slots) / sizeof(cackey_slots[0]))) { CACKEY_DEBUG_PRINTF("Error. Invalid slot requested (%lu), outside of valid range", slotID); if (lock_mutex) { cackey_mutex_unlock(cackey_biglock); } return(CKR_GENERAL_ERROR); } if (cackey_slots[slotID].active == 0) { CACKEY_DEBUG_PRINTF("Error. Invalid slot requested (%lu), slot not currently active", slotID); if (lock_mutex) { cackey_mutex_unlock(cackey_biglock); } return(CKR_GENERAL_ERROR); } pincmd = cackey_pin_command; if (pincmd != NULL) { CACKEY_DEBUG_PRINTF("CACKEY_PIN_COMMAND = %s", pincmd); if (pPin != NULL) { CACKEY_DEBUG_PRINTF("Protected authentication path in effect and PIN provided !?"); } pinfd = popen(pincmd, "r"); if (pinfd == NULL) { CACKEY_DEBUG_PRINTF("Error. %s: Unable to run", pincmd); if (lock_mutex) { cackey_mutex_unlock(cackey_biglock); } CACKEY_DEBUG_PRINTF("Returning CKR_PIN_INCORRECT (%i)", (int) CKR_PIN_INCORRECT); return(CKR_PIN_INCORRECT); } fgets_ret = fgets(pinbuf, sizeof(pinbuf), pinfd); if (fgets_ret == NULL) { pinbuf[0] = '\0'; } pclose_ret = pclose(pinfd); if (pclose_ret == -1 && errno == ECHILD) { CACKEY_DEBUG_PRINTF("Notice. pclose() indicated it could not get the status of the child, assuming it succeeeded !"); pclose_ret = 0; } if (pclose_ret != 0) { CACKEY_DEBUG_PRINTF("Error. %s: exited with non-zero status of %i", pincmd, pclose_ret); if (lock_mutex) { cackey_mutex_unlock(cackey_biglock); } CACKEY_DEBUG_PRINTF("Returning CKR_PIN_INCORRECT (%i)", (int) CKR_PIN_INCORRECT); return(CKR_PIN_INCORRECT); } if (strlen(pinbuf) < 1) { CACKEY_DEBUG_PRINTF("Error. %s: returned no data", pincmd); if (lock_mutex) { cackey_mutex_unlock(cackey_biglock); } CACKEY_DEBUG_PRINTF("Returning CKR_PIN_INCORRECT (%i)", (int) CKR_PIN_INCORRECT); return(CKR_PIN_INCORRECT); } if (pinbuf[strlen(pinbuf) - 1] == '\n') { pinbuf[strlen(pinbuf) - 1] = '\0'; } pPin = (CK_UTF8CHAR_PTR) pinbuf; ulPinLen = strlen(pinbuf); } login_ret = cackey_login(&cackey_slots[slotID], pPin, ulPinLen, &tries_remaining); if (login_ret != CACKEY_PCSC_S_OK) { if (lock_mutex) { cackey_mutex_unlock(cackey_biglock); } if (login_ret == CACKEY_PCSC_E_LOCKED) { CACKEY_DEBUG_PRINTF("Error. Token is locked."); cackey_slots[slotID].token_flags |= CKF_USER_PIN_LOCKED; CACKEY_DEBUG_PRINTF("Returning CKR_PIN_LOCKED (%i)", (int) CKR_PIN_LOCKED); return(CKR_PIN_LOCKED); } else if (login_ret == CACKEY_PCSC_E_BADPIN) { CACKEY_DEBUG_PRINTF("Error. Invalid PIN."); cackey_slots[slotID].token_flags |= CKF_USER_PIN_COUNT_LOW; if (tries_remaining == 1) { cackey_slots[slotID].token_flags |= CKF_USER_PIN_FINAL_TRY; } CACKEY_DEBUG_PRINTF("Returning CKR_PIN_INCORRECT (%i)", (int) CKR_PIN_INCORRECT); return(CKR_PIN_INCORRECT); } CACKEY_DEBUG_PRINTF("Error. Unknown error returned from cackey_login() (%i)", login_ret); return(CKR_GENERAL_ERROR); } cackey_slots[slotID].token_flags &= ~(CKF_USER_PIN_LOCKED | CKF_USER_PIN_COUNT_LOW | CKF_LOGIN_REQUIRED | CKF_USER_PIN_FINAL_TRY); cackey_sessions[hSession].state = CKS_RO_USER_FUNCTIONS; if (lock_mutex) { mutex_retval = cackey_mutex_unlock(cackey_biglock); if (mutex_retval != 0) { CACKEY_DEBUG_PRINTF("Error. Unlocking failed."); return(CKR_GENERAL_ERROR); } } CACKEY_DEBUG_PRINTF("Returning CKR_OK (%i)", CKR_OK); return(CKR_OK); } CK_DEFINE_FUNCTION(CK_RV, C_Login)(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen) { return(_C_LoginMutexArg(hSession, userType, pPin, ulPinLen, 1)); } CK_DEFINE_FUNCTION(CK_RV, C_Logout)(CK_SESSION_HANDLE hSession) { CK_SLOT_ID slotID; int mutex_retval; CACKEY_DEBUG_PRINTF("Called."); ................................................................................ cackey_mutex_unlock(cackey_biglock); return(CKR_GENERAL_ERROR); } cackey_sessions[hSession].state = CKS_RO_PUBLIC_SESSION; mutex_retval = cackey_mutex_unlock(cackey_biglock); if (mutex_retval != 0) { CACKEY_DEBUG_PRINTF("Error. Unlocking failed."); return(CKR_GENERAL_ERROR); } ................................................................................ CK_DEFINE_FUNCTION(CK_RV, C_FindObjects)(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE_PTR phObject, CK_ULONG ulMaxObjectCount, CK_ULONG_PTR pulObjectCount) { struct cackey_identity *curr_id; CK_ATTRIBUTE *curr_attr; CK_ULONG curr_id_idx, curr_out_id_idx, curr_attr_idx, sess_attr_idx; CK_ULONG matched_count, prev_matched_count; int mutex_retval; #ifdef CACKEY_DEBUG_SEARCH_SPEEDTEST struct timeval start, end; uint64_t start_int, end_int; #endif CACKEY_DEBUG_PRINTF("Called."); if (!cackey_initialized) { CACKEY_DEBUG_PRINTF("Error. Not initialized."); return(CKR_CRYPTOKI_NOT_INITIALIZED); ................................................................................ if (!cackey_sessions[hSession].search_active) { cackey_mutex_unlock(cackey_biglock); CACKEY_DEBUG_PRINTF("Error. Search not active."); return(CKR_OPERATION_NOT_INITIALIZED); } #ifdef CACKEY_DEBUG_SEARCH_SPEEDTEST gettimeofday(&start, NULL); #endif curr_out_id_idx = 0; for (curr_id_idx = cackey_sessions[hSession].search_curr_id; curr_id_idx < cackey_sessions[hSession].identities_count && ulMaxObjectCount; curr_id_idx++) { curr_id = &cackey_sessions[hSession].identities[curr_id_idx]; CACKEY_DEBUG_PRINTF("Processing identity:%lu", (unsigned long) curr_id_idx); ................................................................................ curr_out_id_idx++; } else { CACKEY_DEBUG_PRINTF(" ... Not all %i (only found %i) attributes checked for found, not adding identity:%i", (int) cackey_sessions[hSession].search_query_count, (int) matched_count, (int) curr_id_idx); } } cackey_sessions[hSession].search_curr_id = curr_id_idx; *pulObjectCount = curr_out_id_idx; #ifdef CACKEY_DEBUG_SEARCH_SPEEDTEST gettimeofday(&end, NULL); start_int = (start.tv_sec * 1000000) + start.tv_usec; end_int = (end.tv_sec * 1000000) + end.tv_usec; fprintf(stderr, "Search took %lu microseconds\n", (unsigned long) (end_int - start_int)); #endif mutex_retval = cackey_mutex_unlock(cackey_biglock); if (mutex_retval != 0) { CACKEY_DEBUG_PRINTF("Error. Unlocking failed."); return(CKR_GENERAL_ERROR); } ................................................................................ return(CKR_GENERAL_ERROR); } switch (cackey_sessions[hSession].decrypt_mechanism) { case CKM_RSA_PKCS: /* Ask card to decrypt */ buflen = cackey_signdecrypt(&cackey_slots[slotID], cackey_sessions[hSession].decrypt_identity, pEncryptedPart, ulEncryptedPartLen, buf, sizeof(buf), 0, 1); if (buflen == CACKEY_PCSC_E_NEEDLOGIN && cackey_pin_command != NULL) { if (_C_LoginMutexArg(hSession, CKU_USER, NULL, 0, 0) == CKR_OK) { buflen = cackey_signdecrypt(&cackey_slots[slotID], cackey_sessions[hSession].decrypt_identity, pEncryptedPart, ulEncryptedPartLen, buf, sizeof(buf), 0, 1); } } if (buflen < 0) { /* Decryption failed. */ if (buflen == CACKEY_PCSC_E_NEEDLOGIN) { retval = CKR_USER_NOT_LOGGED_IN; } else if (buflen == CACKEY_PCSC_E_TOKENABSENT) { retval = CKR_DEVICE_REMOVED; } else { CACKEY_DEBUG_PRINTF("Failed to send APDU, error = %li", (long int) buflen); retval = CKR_GENERAL_ERROR; } } else if (((unsigned long) buflen) > *pulPartLen && pPart) { /* Decrypted data too large */ retval = CKR_BUFFER_TOO_SMALL; } else { if (pPart) { ................................................................................ } switch (cackey_sessions[hSession].sign_mechanism) { case CKM_RSA_PKCS: /* Ask card to sign */ CACKEY_DEBUG_PRINTF("Asking to sign from identity %p in session %lu", (void *) cackey_sessions[hSession].sign_identity, (unsigned long) hSession); sigbuflen = cackey_signdecrypt(&cackey_slots[slotID], cackey_sessions[hSession].sign_identity, cackey_sessions[hSession].sign_buf, cackey_sessions[hSession].sign_bufused, sigbuf, sizeof(sigbuf), 1, 0); if (sigbuflen == CACKEY_PCSC_E_NEEDLOGIN && cackey_pin_command != NULL) { if (_C_LoginMutexArg(hSession, CKU_USER, NULL, 0, 0) == CKR_OK) { sigbuflen = cackey_signdecrypt(&cackey_slots[slotID], cackey_sessions[hSession].sign_identity, cackey_sessions[hSession].sign_buf, cackey_sessions[hSession].sign_bufused, sigbuf, sizeof(sigbuf), 1, 0); } } if (sigbuflen < 0) { /* Signing failed. */ if (sigbuflen == CACKEY_PCSC_E_NEEDLOGIN) { retval = CKR_USER_NOT_LOGGED_IN; } else if (sigbuflen == CACKEY_PCSC_E_TOKENABSENT) { retval = CKR_DEVICE_REMOVED; |
Modified cackey_builtin_certs.h from [093ba34f4f] to [9c64b878c6].
cannot compute difference between binary files
Modified configure.ac from [8952b0e3fb] to [76a04092ae].
1
2
3
4
5
6
7
8
...
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
AC_INIT(cackey, 0.6.6) AC_CONFIG_HEADERS(config.h) dnl Locate standard tools AC_PROG_CC AC_PROG_MAKE_SET AC_PROG_INSTALL AC_AIX ................................................................................ AC_MSG_RESULT(okay) ], [ AC_MSG_RESULT(failed) AC_MSG_FAILURE([simple PC/SC program failed]) ] ) dnl Set version script, to limit the scope of symbols DC_SETVERSIONSCRIPT(libcackey.vers, libcackey.syms) dnl Upate LDFLAGS to include setting the run-time linker path to the same as our compile-time linker DC_SYNC_RPATH dnl If we updated LIBOBJS, update SHLIBOBJS -- must be last. DC_SYNC_SHLIBOBJS dnl Produce Makefile AC_OUTPUT(Makefile libcackey.syms) |
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
1
2
3
4
5
6
7
8
...
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
AC_INIT(cackey, 0.7.1) AC_CONFIG_HEADERS(config.h) dnl Locate standard tools AC_PROG_CC AC_PROG_MAKE_SET AC_PROG_INSTALL AC_AIX ................................................................................ AC_MSG_RESULT(okay) ], [ AC_MSG_RESULT(failed) AC_MSG_FAILURE([simple PC/SC program failed]) ] ) dnl Option to enable DoD certs on hardware slot AC_ARG_ENABLE(dod-certs-on-hw-slots, AC_HELP_STRING([--enable-dod-certs-on-hw-slots], [Specify that DoD certificates should be made available on hardware token slots]), [ dodcertsonhwslots=$enableval ], [ dodcertsonhwslots=no ]) if ! test "${dodcertsonhwslots}" = 'no'; then AC_DEFINE(CACKEY_CARD_SLOT_INCLUDE_EXTRA_CERTS, [1], [Specify that DoD certificates should be made available on hardware token slots]) fi dnl Option to disable DoD certs entirely AC_ARG_ENABLE(dod-certs, AC_HELP_STRING([--disable-dod-certs], [Disable including DoD certs entirely. The user may override this with the CACKEY_EXTRA_CERTS environment variable.]), [ dodcerts=$enableval ], [ dodcerts=yes ]) if test "${dodcerts}" = 'no'; then AC_DEFINE(CACKEY_NO_EXTRA_CERTS, [1], [Specify that DoD certificates should not be made available]) fi dnl Option to hard-code a command to run to request a PIN (enabling protected authentication path) AC_ARG_WITH(pin-command, AC_HELP_STRING([--with-pin-command=<command>], [Specify a command to run to request a PIN from the user. The user may override this with the CACKEY_PIN_COMMAND environment variable.]), [ pincommand="${withval}" ], [ pincommand="no" ]) AC_ARG_WITH(pin-command-x, AC_HELP_STRING([--with-pin-command-x=<command>], [Same as --with-pin-command, but only sets Protected Authentication Path if the DISPLAY environment variable is set]), [ pincommandxonly="${withval}" ], [ pincommandxonly="no" ]) if ! test "${pincommand}" = 'no'; then AC_DEFINE_UNQUOTED(CACKEY_PIN_COMMAND_DEFAULT, [$pincommand], [Command to run to prompt user for PIN]) fi if ! test "${pincommandxonly}" = 'no'; then AC_DEFINE_UNQUOTED(CACKEY_PIN_COMMAND_XONLY_DEFAULT, [$pincommandxonly], [Command to run to prompt user for PIN only if DISPLAY environment variable is set]) fi dnl Set version script, to limit the scope of symbols DC_SETVERSIONSCRIPT(libcackey.vers, libcackey.syms) dnl Upate LDFLAGS to include setting the run-time linker path to the same as our compile-time linker DC_SYNC_RPATH dnl If we updated LIBOBJS, update SHLIBOBJS -- must be last. DC_SYNC_SHLIBOBJS dnl Produce Makefile AC_OUTPUT(Makefile libcackey.syms) |
Modified leakcheck/leakcheck from [a80110599b] to [2624af0c94].
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
if [ -z "${LEAKCHECKFILE}" ]; then echo "Usage: leakcheck <filename>" >&2 echo " filename Name of file containing debugging output" >&2 exit 1 fi egrep '(MALLOC|FREE|REALLOC)' "${LEAKCHECKFILE}" | sed 's@^.*FREE(\(0x[0-9a-f]*\)).*$@free \1@;s@^.*MALLOC() = @malloc @;s@^.*REALLOC(\(0x[0-9a-f]*\)) = @realloc \1 @' > "${TMPFILE}" cat "${TMPFILE}" | while read op addr newaddr; do case "${op}" in malloc) if [ -z "${alloclist}" ]; then alloclist="${addr}" else |
| |
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
if [ -z "${LEAKCHECKFILE}" ]; then echo "Usage: leakcheck <filename>" >&2 echo " filename Name of file containing debugging output" >&2 exit 1 fi egrep '(MALLOC|FREE|REALLOC)' "${LEAKCHECKFILE}" | sed 's@^.*FREE(\([x0-9a-fA-F]*\)).*$@free \1@;s@^.*MALLOC() = @malloc @;s@^.*REALLOC(\([x0-9a-fA-F]*\)) = @realloc \1 @' > "${TMPFILE}" cat "${TMPFILE}" | while read op addr newaddr; do case "${op}" in malloc) if [ -z "${alloclist}" ]; then alloclist="${addr}" else |
Modified test.c from [7438606333] to [47338c5b52].
234
235
236
237
238
239
240
241
242
243
244
245
246
247
...
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
|
printf(" Slot %lu:\n", currSlot);
chk_rv = C_GetSlotInfo(slots[currSlot], &slotInfo);
if (chk_rv != CKR_OK) {
return(1);
}
printf(" Desc : %.*s\n", 32, slotInfo.slotDescription);
printf(" ManufID: %.*s\n", 32, slotInfo.manufacturerID);
printf(" HWVers : %i.%i\n", slotInfo.hardwareVersion.major, slotInfo.hardwareVersion.minor);
printf(" FWVers : %i.%i\n", slotInfo.firmwareVersion.major, slotInfo.firmwareVersion.minor);
printf(" Flags : ");
if ((slotInfo.flags & CKF_TOKEN_PRESENT) == CKF_TOKEN_PRESENT) {
printf("CKF_TOKEN_PRESENT ");
................................................................................
}
printf("\n");
}
}
chk_rv = C_OpenSession(slots[0], CKF_SERIAL_SESSION, NULL, NULL, &hSession);
if (chk_rv == CKR_OK) {
if ((tokenInfo.flags & CKF_LOGIN_REQUIRED) == CKF_LOGIN_REQUIRED) {
fgets_ret = NULL;
while (fgets_ret == NULL) {
printf("** ENTER PIN: ");
fflush(stdout);
fgets_ret = fgets((char *) user_pin, sizeof(user_pin), stdin);
|
>
>
>
>
>
>
|
|
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
...
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
printf(" Slot %lu:\n", currSlot); chk_rv = C_GetSlotInfo(slots[currSlot], &slotInfo); if (chk_rv != CKR_OK) { return(1); } printf(" Id : %lu\n", (unsigned long) slots[currSlot]); printf(" Desc : %.*s\n", 32, slotInfo.slotDescription); printf(" ManufID: %.*s\n", 32, slotInfo.manufacturerID); printf(" HWVers : %i.%i\n", slotInfo.hardwareVersion.major, slotInfo.hardwareVersion.minor); printf(" FWVers : %i.%i\n", slotInfo.firmwareVersion.major, slotInfo.firmwareVersion.minor); printf(" Flags : "); if ((slotInfo.flags & CKF_TOKEN_PRESENT) == CKF_TOKEN_PRESENT) { printf("CKF_TOKEN_PRESENT "); ................................................................................ } printf("\n"); } } chk_rv = C_OpenSession(slots[0], CKF_SERIAL_SESSION, NULL, NULL, &hSession); if (chk_rv == CKR_OK) { chk_rv = C_GetTokenInfo(slots[0], &tokenInfo); if (chk_rv != CKR_OK) { return(1); } if ((tokenInfo.flags & CKF_LOGIN_REQUIRED) == CKF_LOGIN_REQUIRED && (tokenInfo.flags & CKF_PROTECTED_AUTHENTICATION_PATH) == 0) { fgets_ret = NULL; while (fgets_ret == NULL) { printf("** ENTER PIN: "); fflush(stdout); fgets_ret = fgets((char *) user_pin, sizeof(user_pin), stdin); |