PKCS11 » History » Version 1
Johannes Schmölz, 12/18/2012 07:43 PM
1 | 1 | Johannes Schmölz | h1. PKCS11 |
---|---|---|---|
2 | |||
3 | The main goal of the PKCS#11-interface of the Open eCard App is to provide the functionality, which is required by Mozilla’s Firefox browser. |
||
4 | |||
5 | Mozilla’s overall crypto architecture as taken from [Grif09] is depicted in Figure 1. |
||
6 | |||
7 | !mozilla-crypto-architecture.jpg! |
||
8 | _Figure 1: Mozilla's Cryptographic Architecture_ |
||
9 | |||
10 | The important part is the usage of the PKCS#11-interface by the “Core Crypto Code” within the “Network Security Services” as explained in [NSS-PKCS#11]. |
||
11 | |||
12 | As this browser is a successor of Netscape’s Communicator it is expected that the PKCS#11-usage in today’s Firefox is similar to the PKCS#11-usage explained in [NSS-PKCS#11]. |
||
13 | |||
14 | |||
15 | h2. Required Functions |
||
16 | |||
17 | |||
18 | h3. General-Purpose Functions |
||
19 | |||
20 | Among the general-purpose functions defined in Section 11.4 of [NSS-PKCS#11] the following functions need to be supported: |
||
21 | |||
22 | * C_Initialize |
||
23 | * C_Finalize |
||
24 | * C_GetFunctionList |
||
25 | * C_GetInfo |
||
26 | |||
27 | |||
28 | *C_Initialize* |
||
29 | |||
30 | As explained in [NSS-PKCS#11] the Netscape Security Library calls C_Initialize on startup or when it loads a new module. The Netscape Security Library always passes NULL, as required by the PKCS #11 specification, in the single C_Initialize parameter pReserved. This function will use the IFD-function EstablishContext to initialize the IFD-module. |
||
31 | |||
32 | |||
33 | *C_Finalize* |
||
34 | |||
35 | As explained in [NSS-PKCS#11] the Netscape Security Library calls C_Finalize on shutdown and whenever it unloads a module. |
||
36 | |||
37 | This function will use the IFD-function ReleaseContext to initialize the IFD-module. |
||
38 | |||
39 | |||
40 | *C_GetInfo* |
||
41 | |||
42 | The Netscape Security Library calls C_GetInfo on startup or when it loads a new module. The version numbers, manufacturer IDs, and so on are displayed when the user views the information. The supplied library names are used as the default library names; currently, these names should not include any double quotation marks. |
||
43 | |||
44 | This function will only return static information and does not involve any IFD-function. |
||
45 | |||
46 | *C_GetFunctionList* |
||
47 | |||
48 | As explained in [NSS-PKCS#11] the Netscape Security Library calls C_GetFunctionList on startup or when it loads a new module. In [NSS-PKCS#11] it is recommended that for a not implemented function there should at least be a stub that returns CKR_FUNCTION_NOT_SUPPORTED. |
||
49 | |||
50 | This function will only return static information and does not involve any IFD-function. |
||
51 | |||
52 | |||
53 | h3. Slot and Token Management |
||
54 | |||
55 | |||
56 | *C_GetSlotList* |
||
57 | |||
58 | As explained in [NSS-PKCS#11] the Netscape Security Library calls C_GetSlotList on startup or when it loads a new module, requests all the module's slots, and keeps track of the list from that point on. The slots are expected to remain static: that is, the module never has more slots or fewer slots than the number on the original list. This means that the function C_WaitForSlotEvent is not used by the Netscape Se-curity Library. |
||
59 | |||
60 | This function uses the following IFD-functions: |
||
61 | |||
62 | * ListIFDs |
||
63 | * GetIFDCapabilities |
||
64 | * GetStatus |
||
65 | |||
66 | |||
67 | *C_GetSlotInfo* |
||
68 | |||
69 | As explained in [NSS-PKCS#11] the Netscape Security Library calls C_GetSlotInfo on startup or when it loads a new module and reads in the information that can be viewed on the slot information page. If the CKF_REMOVABLE_DEVICE flag is set, the Netscape Security Library also calls C_GetSlotInfo whenever it looks up slots to make sure the token is present. If the CKF_REMOVABLE_DEVICE flag is not set, the Netscape Security Library uses that token information without checking again. |
||
70 | |||
71 | If the CKF_REMOVABLE_DEVICE flag is not set, the CKF_TOKEN_PRESENT flag must be set, or else the Netscape Security Library marks the slot as bad and will never use it. |
||
72 | |||
73 | The Netscape Security Library doesn't currently use the CKF_HW_SLOT flag. |
||
74 | |||
75 | For a particular slot this function returns the following structure: |
||
76 | |||
77 | <pre><code class="c"> |
||
78 | typedef struct CK_SLOT_INFO { |
||
79 | CK_UTF8CHAR slotDescription[64]; |
||
80 | CK_UTF8CHAR manufacturerID[32]; |
||
81 | CK_FLAGS flags; |
||
82 | CK_VERSION hardwareVersion; |
||
83 | CK_VERSION firmwareVersion; |
||
84 | } CK_SLOT_INFO; |
||
85 | </code></pre> |
||
86 | |||
87 | |||
88 | *C_GetTokenInfo* |
||
89 | |||
90 | If a token is a permanent device (that is, if the CKF_REMOVABLE_DEVICE flag is not set), the Netscape Security Library calls C_GetTokenInfo only on startup or when it loads a new module. If the token is a removable device, the Netscape Security Library may call C_GetTokenInfo anytime it's looking for a new token to check whether the token is write protected, whether it can generate random numbers, and so on. |
||
91 | |||
92 | The Netscape Security Library expects CK_TOKEN_INFO.label to contain the name of the token. |
||
93 | |||
94 | If the CKF_WRITE_PROTECTED flag is set, the Netscape Security Library won't use the token to generate keys. |
||
95 | |||
96 | The Netscape Security Library interprets the combination of the CKF_LOGIN_REQUIRED and CKF_USER_PIN_INITIALIZED flags as shown in the following table. |
||
97 | |||
98 | TODO: insert table |
||
99 | |||
100 | For a typical signature card in operational mode the two flags are TRUE. On the other side the two flags for the private key on the eGK, which is used for card2card-authentication, are both FALSE. |
||
101 | |||
102 | This function returns the CK_TOKEN_INFO struct for a specific token. |
||
103 | |||
104 | <pre><code class="c"> |
||
105 | typedef struct CK_TOKEN_INFO { |
||
106 | CK_UTF8CHAR label[32]; |
||
107 | CK_UTF8CHAR manufacturerID[32]; |
||
108 | CK_UTF8CHAR model[16]; |
||
109 | CK_CHAR serialNumber[16]; |
||
110 | CK_FLAGS flags; |
||
111 | CK_ULONG ulMaxSessionCount; |
||
112 | CK_ULONG ulSessionCount; |
||
113 | CK_ULONG ulMaxRwSessionCount; |
||
114 | CK_ULONG ulRwSessionCount; |
||
115 | CK_ULONG ulMaxPinLen; |
||
116 | CK_ULONG ulMinPinLen; |
||
117 | CK_ULONG ulTotalPublicMemory; |
||
118 | CK_ULONG ulFreePublicMemory; |
||
119 | CK_ULONG ulTotalPrivateMemory; |
||
120 | CK_ULONG ulFreePrivateMemory; |
||
121 | CK_VERSION hardwareVersion; |
||
122 | CK_VERSION firmwareVersion; |
||
123 | CK_CHAR utcTime[16]; |
||
124 | } CK_TOKEN_INFO; |
||
125 | </code></pre> |
||
126 | |||
127 | |||
128 | *C_GetMechanismList* |
||
129 | |||
130 | As explained in [NSS-PKCS#11], the Netscape Security Library calls C_GetMechanismList fairly frequently to identify the mechanisms supported by a token. |
||
131 | |||
132 | This function returns the CK_MECHANISM_INFO struct for a specific token. |
||
133 | |||
134 | <pre><code class="c"> |
||
135 | typedef struct CK_MECHANISM_INFO { |
||
136 | CK_ULONG ulMinKeySize; |
||
137 | CK_ULONG ulMaxKeySize; |
||
138 | CK_FLAGS flags; |
||
139 | } CK_MECHANISM_INFO; |
||
140 | </code></pre> |
||
141 | |||
142 | TODO: insert table |
||
143 | |||
144 | |||
145 | h3. Session Management |
||
146 | |||
147 | |||
148 | *C_OpenSession* |
||
149 | |||
150 | As explained in [NSS-PKCS#11] the Netscape Security Library calls C_OpenSession whenever it initializes a token and keeps the session open as long as possible. The Netscape Security Library almost never closes a session after it finishes doing some-thing with a token. It uses a single session for all single-part RSA operations such as logging in, logging out, signing, verifying, generating keys, wrapping keys, and so on. |
||
151 | |||
152 | The Netscape Security Library opens a separate session for each part of a multipart encryption (bulk encryption). If it runs out of sessions, it uses the initial session for saves and restores. |
||
153 | |||
154 | This function will use the IFD-function Connect to open a session to the token. |
||
155 | |||
156 | |||
157 | *C_CloseSession* |
||
158 | |||
159 | As explained in [NSS-PKCS#11] the Netscape Security Library calls C_CloseSession to close sessions created for bulk encryption. |
||
160 | |||
161 | This function will use the IFD-function Disconnect to close a session to the token. |
||
162 | |||
163 | |||
164 | *C_CloseAllSessions* |
||
165 | |||
166 | As explained in [NSS-PKCS#11] the Netscape Security Library may call C_CloseAllSessions when it closes down a slot. |
||
167 | |||
168 | |||
169 | *C_GetSessionInfo* |
||
170 | |||
171 | The Netscape Security Library calls C_GetSessionInfo frequently. |
||
172 | |||
173 | If a token has been removed during a session, C_GetSessionInfo should return either CKR_SESSION_CLOSED or CKR_SESSION_HANDLE_INVALID. If a token has been removed and then the same or another token is inserted, C_GetSessionInfo should return CKR_SESSION_HANDLE_INVALID. |
||
174 | |||
175 | |||
176 | *C_Login* |
||
177 | |||
178 | The Netscape Security Library calls C_Login on a token's initial session whenever CKF_LOGIN_REQUIRED is TRUE and the user state indicates that the user isn't logged in. |
||
179 | |||
180 | This function will use the IFD-function VerifyUser to perform the authentication of a user. |
||
181 | |||
182 | |||
183 | *C_Logout* |
||
184 | |||
185 | The Netscape Security Library calls C_Logout on a token's initial session |
||
186 | |||
187 | * when the password is timed out |
||
188 | * when performing any kind of private key operation if "ask always" is turned on |
||
189 | * when changing a password |
||
190 | * when the user logs out |
||
191 | |||
192 | |||
193 | h3. Object Management |
||
194 | |||
195 | In the scope of a TLS-handshake the client needs to read the certificate from the card and send it to the server. This functionality is most likely performed using the following two functions. |
||
196 | |||
197 | |||
198 | *C_GetAttributeValue* |
||
199 | |||
200 | The Netscape Security Library calls C_GetAttributeValue to get the value of attrib-utes for both single objects and multiple objects. This is useful for extracting public keys, nonsecret bulk keys, and so on. |
||
201 | |||
202 | |||
203 | *C_FindObjectsInit, C_FindObjects, C_FindFinal* |
||
204 | |||
205 | The Netscape Security Library calls these functions frequently to look up objects by CKA_ID or CKA_LABEL. These values must match the equivalent values for related keys and certificates and must be unique among key pairs on a given token. |
||
206 | |||
207 | The Netscape Security Library also looks up certificates by CK_ISSUER and CK_SERIAL. If those fields aren't set on the token, S/MIME won't work. |
||
208 | |||
209 | |||
210 | h3. Cryptographic Operations |
||
211 | |||
212 | In the scope of a TLS-handshake the client needs to sign data, which is constructed based on previously exchanged messages in the handshake. This signature is most likely created using the functions C_SignInit, C_Sign and C_SignFinal. |
||
213 | |||
214 | |||
215 | h2. References |
||
216 | |||
217 | [Grif09] R. Griffin: Encryption and Key Management Tutorials, Part II: PKCS #11 – Enhancements and Opportunities, Talk at RSA 2009, ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-11/v2-30/TUT-M51_Griffin_PKCS11.pdf |
||
218 | |||
219 | [NSS-PKCS#11] Implementing PKCS #11 for the Netscape Security Library, http://docs.oracle.com/cd/E19957-01/816-6150-10/pkcs.htm |