| 1 | A quick installation guide to opensc |
|---|
| 2 | ==================================== |
|---|
| 3 | |
|---|
| 4 | To install opensc, please do as user, |
|---|
| 5 | |
|---|
| 6 | $ wget http://www.opensc.org/files/opensc-0.9.4.tar.gz |
|---|
| 7 | $ tar xfvz opensc-0.9.4.tar.gz |
|---|
| 8 | $ cd opensc-0.9.4 |
|---|
| 9 | |
|---|
| 10 | nothing special so far. |
|---|
| 11 | |
|---|
| 12 | $ ./configure --prefix=/usr --sysconfdir=/etc |
|---|
| 13 | |
|---|
| 14 | This will install opensc in /usr with the config file in /etc. |
|---|
| 15 | If you installed openct at some special place opensc might not |
|---|
| 16 | find it. Please add "--with-openct=/path/to/openct" to make |
|---|
| 17 | sure it is found. At the end of the configure script, opensc |
|---|
| 18 | will print a summary page, too. It should look like this: |
|---|
| 19 | |
|---|
| 20 | OpenSC has been configured with the following options |
|---|
| 21 | |
|---|
| 22 | User binaries: /usr/bin |
|---|
| 23 | Configuration files: /etc |
|---|
| 24 | |
|---|
| 25 | Host: i686-pc-linux-gnu |
|---|
| 26 | Compiler: gcc |
|---|
| 27 | Compiler flags: -Wall -fno-strict-aliasing -g -O2 |
|---|
| 28 | Preprocessor flags: -I${top_builddir}/src/include |
|---|
| 29 | Linker flags: -L/usr -L/usr/lib -L/usr/lib |
|---|
| 30 | Libraries: -lpthread |
|---|
| 31 | |
|---|
| 32 | Random number collection: device (/dev/urandom) |
|---|
| 33 | OpenSSL support: yes |
|---|
| 34 | with engine: yes |
|---|
| 35 | PC/SC support: yes |
|---|
| 36 | OpenCT support: yes |
|---|
| 37 | Assuan support: no |
|---|
| 38 | LDAP support: yes |
|---|
| 39 | PAM support: yes |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | OpenSSL support is very important, some cards cannot work without. |
|---|
| 43 | I strongly suggest to use a recent version. Best is 0.9.7d or later, |
|---|
| 44 | as the OpenSSL project improved one issue very important to opensc. |
|---|
| 45 | But older versions will work fine, too. |
|---|
| 46 | |
|---|
| 47 | If you want to use openssl version 0.9.6, be aware that it is available in two |
|---|
| 48 | flavors: the normal version and an "engine" version. Only with the "engine" |
|---|
| 49 | version OpenSC can provide full OpenSSL support, including two engines for |
|---|
| 50 | OpenSSL. |
|---|
| 51 | |
|---|
| 52 | With OpenSSL 0.9.7 you don't need to worry, the engine support is always |
|---|
| 53 | enabled. |
|---|
| 54 | |
|---|
| 55 | OpenSC is about smart cards. You need some software that knows smart |
|---|
| 56 | card readers to access the cards in them. OpenSC supports three flavors: |
|---|
| 57 | - CT-API is a very simple interface, and there are many drivers for it, |
|---|
| 58 | mostly binary only. This support is always build into OpenSC. |
|---|
| 59 | But it is recommended to use this only for testing, or in environments |
|---|
| 60 | with a single user and a single application using smart cards. |
|---|
| 61 | - PC/SC is a standard used in the Windows world. But the pcsc-lite software |
|---|
| 62 | implements this standard for Unix and Mac OS X, too, and many drivers |
|---|
| 63 | are available for it. Some are open source, many are binary only. |
|---|
| 64 | - OpenCT is an open source software implementing smart card drivers for |
|---|
| 65 | many smart card readers and usb tokens. OpenCT does not follow any |
|---|
| 66 | standard, but instead it is small, lean, and still has everything |
|---|
| 67 | needed to do the job. OpenCT is only available on Linux and Unix-like |
|---|
| 68 | operating systems, but not on Windows. |
|---|
| 69 | |
|---|
| 70 | If OpenCT supports your reader, it is the recommended choice to use. |
|---|
| 71 | Otherwise if there is a driver for pcsc-lite, that is your best alternative. |
|---|
| 72 | |
|---|
| 73 | Note: it is possible to use OpenCT both directly with OpenSC, |
|---|
| 74 | but you can also create a chain OpenCT -> PC/SC-Lite -> OpenSC. |
|---|
| 75 | Such a chain is only recommended, if applications other than OpenSC |
|---|
| 76 | need to access the same readers and smart cards, too. Otherwise |
|---|
| 77 | it adds an overhead and is not tested very much. |
|---|
| 78 | |
|---|
| 79 | Note also that OpenSC can use both, OpenCT and PC/SC-Lite at the |
|---|
| 80 | same time. So if both are turned on, that is fine. |
|---|
| 81 | |
|---|
| 82 | To use OpenSC with GnuPG, first compile the assuan library, then compile |
|---|
| 83 | OpenSC with support for Assuan, and then compile GnuPG with OpenSC. This |
|---|
| 84 | only works with development versions of GnuPG (1.9.*) and has not been |
|---|
| 85 | well tested. Feedback is very welcome. Other than to use OpenSC with |
|---|
| 86 | GnuPG, the Assuan support is not needed. |
|---|
| 87 | |
|---|
| 88 | PAM support allowes you to use a smart card and the opensc PAM module |
|---|
| 89 | to log into your system. If enabled, the pam module has two flavors: |
|---|
| 90 | it can compare a key on a smart card to a certificate stored localy, |
|---|
| 91 | or it can communicate with an LDAP server to check the key and |
|---|
| 92 | certificate stored on a smart card. The former mode requires only |
|---|
| 93 | PAM support, the later is only available, if OpenSC is compiled with |
|---|
| 94 | LDAP and PAM support enabled. |
|---|
| 95 | |
|---|
| 96 | Now if your configuration is similar, you can compile the software. |
|---|
| 97 | |
|---|
| 98 | $ make |
|---|
| 99 | $ su root |
|---|
| 100 | |
|---|
| 101 | and install the software as root |
|---|
| 102 | # make install |
|---|
| 103 | |
|---|
| 104 | usualy opensc is fine without any config file, still you can install it: |
|---|
| 105 | |
|---|
| 106 | # cp etc/opensc.conf.example /etc/opensc.conf |
|---|
| 107 | # cp etc/scldap.conf.example /etc/scldap.conf |
|---|
| 108 | |
|---|
| 109 | If you have some reason to edit the config file, feel free to do so. |
|---|
| 110 | But most users are fine without. |
|---|
| 111 | |
|---|
| 112 | OpenSC is now fully installed. Have fun. |
|---|
| 113 | |
|---|
| 114 | Some usual commands include: |
|---|
| 115 | |
|---|
| 116 | $ opensc-tool --list-readers |
|---|
| 117 | Readers known about: |
|---|
| 118 | Nr. Driver Name |
|---|
| 119 | 0 openct Towitoko Chipdrive Micro |
|---|
| 120 | 1 openct Aladdin eToken PRO |
|---|
| 121 | 2 openct OpenCT reader (detached) |
|---|
| 122 | 3 openct OpenCT reader (detached) |
|---|
| 123 | 4 openct OpenCT reader (detached) |
|---|
| 124 | |
|---|
| 125 | You can see, openct claims five slots, but only two are used. |
|---|
| 126 | This is done to support hotplugging. If you are using OpenCT |
|---|
| 127 | and PC/SC-Lite, please use this test often to make sure you |
|---|
| 128 | are using some openct driver directly, and not indirectly |
|---|
| 129 | via openct. In theory both should work fine, but if you have |
|---|
| 130 | some problems, please test this. |
|---|
| 131 | |
|---|
| 132 | $ opensc-tool --reader 1 --atr |
|---|
| 133 | 3B E2 00 FF C1 10 31 FE 55 C8 02 9C ;.....1.U... |
|---|
| 134 | |
|---|
| 135 | OpenCT can give you the atr as well. |
|---|
| 136 | |
|---|
| 137 | $ opensc-explorer |
|---|
| 138 | |
|---|
| 139 | Is a tool to explore the smart card - list directories, change |
|---|
| 140 | directories, look at files, and so on. If this doesn't work, |
|---|
| 141 | do not panic. Many cards simply do not support this, they |
|---|
| 142 | have no "ls" command. Many other tools will still work. |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | Quick start guide to initializing a card |
|---|
| 146 | ======================================== |
|---|
| 147 | |
|---|
| 148 | If opensc and openct are both installed and can see the reader |
|---|
| 149 | and the card, you might want to start formatting it, creating |
|---|
| 150 | an pkcs#15 structure, adding a user name and pin, generate a key, |
|---|
| 151 | create a certificate and use it everywhere. Here is the quick guide. |
|---|
| 152 | |
|---|
| 153 | You can add "-v" to all of these commands, to get a more verbose |
|---|
| 154 | output. Adding "-v" more than once will enable debugging or increase |
|---|
| 155 | the debugging level. |
|---|
| 156 | |
|---|
| 157 | $ pkcs15-init --create-pkcs15 |
|---|
| 158 | New Security Officer PIN (Optional - press return for no PIN). |
|---|
| 159 | Please enter Security Officer PIN: |
|---|
| 160 | Please type again to verify: |
|---|
| 161 | Unblock Code for New User PIN (Optional - press return for no PIN). |
|---|
| 162 | Please enter User unblocking PIN (PUK): |
|---|
| 163 | Please type again to verify: |
|---|
| 164 | |
|---|
| 165 | This created an empty pkcs15 structure. You can't do much without it. |
|---|
| 166 | Also I entered a pin for the security officer, and an unblocking pin. |
|---|
| 167 | As a general rule, the SO pin is required everytime you change the |
|---|
| 168 | card, but only the user pin is required to use it. |
|---|
| 169 | |
|---|
| 170 | $ pkcs15-init --store-pin --auth-id 01 --label "Andreas Jellinghaus" |
|---|
| 171 | New User PIN. |
|---|
| 172 | Please enter User PIN: |
|---|
| 173 | Please type again to verify: |
|---|
| 174 | Unblock Code for New User PIN (Optional - press return for no PIN). |
|---|
| 175 | Please enter User unblocking PIN (PUK): |
|---|
| 176 | Please type again to verify: |
|---|
| 177 | Security officer PIN required. |
|---|
| 178 | Please enter Security officer PIN: |
|---|
| 179 | |
|---|
| 180 | I created a user with my name on it, so it is easier to see who uses |
|---|
| 181 | this card. The security officer pin is required as this changes the |
|---|
| 182 | card. However later to use it, the security officer pin will never |
|---|
| 183 | work, there is no way for the security officer to get to my key. |
|---|
| 184 | Also I need to remember my unblocking pin, as only I can reset it, |
|---|
| 185 | the security officer cannot. |
|---|
| 186 | |
|---|
| 187 | $ pkcs15-init --generate-key rsa/1024 --auth-id 01 |
|---|
| 188 | Security officer PIN required. |
|---|
| 189 | Please enter Security officer PIN: |
|---|
| 190 | User PIN required. |
|---|
| 191 | Please enter User PIN: |
|---|
| 192 | Security officer PIN required. |
|---|
| 193 | Please enter Security officer PIN: |
|---|
| 194 | |
|---|
| 195 | This created an RSA key that I as User can use. |
|---|
| 196 | Lets create a new self-signed certificate with it. |
|---|
| 197 | To do this, we use openssl. |
|---|
| 198 | |
|---|
| 199 | $ openssl |
|---|
| 200 | OpenSSL> engine dynamic -pre SO_PATH:/usr/lib/opensc/engine_pkcs11.so \ |
|---|
| 201 | -pre ID:pkcs11 -pre LIST_ADD:1 -pre LOAD |
|---|
| 202 | (dynamic) Dynamic engine loading support |
|---|
| 203 | [Success]: SO_PATH:/home/aj/opentest/lib/opensc/engine_pkcs11.so |
|---|
| 204 | [Success]: ID:pkcs11 |
|---|
| 205 | [Success]: LIST_ADD:1 |
|---|
| 206 | [Success]: LOAD |
|---|
| 207 | Loaded: (pkcs11) pkcs11 engine |
|---|
| 208 | OpenSSL> |
|---|
| 209 | |
|---|
| 210 | It is important to enter the whole long command in one single command |
|---|
| 211 | line. I usualy copy&paste the command, to make sure I don't mistype |
|---|
| 212 | anything. This command loads the opensc engine, so openssl can delegate |
|---|
| 213 | some work from your computers cpu to the smart card. |
|---|
| 214 | |
|---|
| 215 | OpenSSL> req -engine pkcs11 -new -key id_45 -keyform engine -out req.pem -text -x509 |
|---|
| 216 | SmartCard PIN: |
|---|
| 217 | You are about to be asked to enter information that will be incorporated |
|---|
| 218 | into your certificate request. |
|---|
| 219 | What you are about to enter is what is called a Distinguished Name or a DN. |
|---|
| 220 | There are quite a few fields but you can leave some blank |
|---|
| 221 | For some fields there will be a default value, |
|---|
| 222 | If you enter '.', the field will be left blank. |
|---|
| 223 | ----- |
|---|
| 224 | Country Name (2 letter code) [AU]:. |
|---|
| 225 | State or Province Name (full name) [Some-State]:. |
|---|
| 226 | Locality Name (eg, city) []:. |
|---|
| 227 | Organization Name (eg, company) [Internet Widgits Pty Ltd]:. |
|---|
| 228 | Organizational Unit Name (eg, section) []:. |
|---|
| 229 | Common Name (eg, YOUR name) []:Andreas Jellinghaus |
|---|
| 230 | Email Address []:aj@dungeon.inka.de |
|---|
| 231 | |
|---|
| 232 | Please enter the following 'extra' attributes |
|---|
| 233 | to be sent with your certificate request |
|---|
| 234 | A challenge password []: |
|---|
| 235 | An optional company name []: |
|---|
| 236 | OpenSSL> |
|---|
| 237 | |
|---|
| 238 | So now I have a signed certificate. Remove the final "-x509" if you want |
|---|
| 239 | a certificate signing request only. In that case, send the request |
|---|
| 240 | to the CA, wait till you get it back, signed, and proceed as normal. |
|---|
| 241 | |
|---|
| 242 | Now store the certificate side by side with the key. It is important |
|---|
| 243 | to save the certificate under the same ID as the key. You can get |
|---|
| 244 | a list of all keys and their details (including the ID) with: |
|---|
| 245 | |
|---|
| 246 | $ pkcs15-tool --list-keys |
|---|
| 247 | Private RSA Key [Private Key] |
|---|
| 248 | Com. Flags : 3 |
|---|
| 249 | Usage : [0x4], sign |
|---|
| 250 | Access Flags: [0x1D], sensitive, alwaysSensitive, neverExtract, local |
|---|
| 251 | ModLength : 1024 |
|---|
| 252 | Key ref : 16 |
|---|
| 253 | Native : yes |
|---|
| 254 | Path : 3F005015 |
|---|
| 255 | Auth ID : 01 |
|---|
| 256 | ID : 45 |
|---|
| 257 | |
|---|
| 258 | So lets store the key: |
|---|
| 259 | $ pkcs15-init --store-certificate req.pem --auth-id 01 --id 45 --format pem |
|---|
| 260 | Security officer PIN required. |
|---|
| 261 | Please enter Security officer PIN: |
|---|
| 262 | |
|---|
| 263 | Now we are ready to go. If you want to add more certificates (e.g. the root |
|---|
| 264 | certificate of the CA that signed your key, or some intermediate certificates |
|---|
| 265 | in the chain to the root CA) simply put those into pem files, and add them |
|---|
| 266 | to id 46, 47 and so on. |
|---|
| 267 | |
|---|