On 2010/11/14 07:15 PDT, Matej Kurpel wrote:
> Hello, I am developing a PKCS#11 module and stumbled upon a confusion as
> how to manage multiple applications calling Cryptoki calls. I can't seem
> to get an answer by reading the PKCS#11 specification, nor by googling,
> so I am asking you :) Currently, I have a boolean flag indicating whether
> C_Initialize has been called. It is set to true in call to C_Initialize,
> and back to false in C_Finalize. Now, when I load my module into Firefox,
> it calls C_Initialize upon its start and C_Finalize when closing the last
> window. But when I launch Thunderbird (with the module loaded as well)
> while Firefox is already running, it calls C_Initialize, and, obviously
> fails with CKR_CRYPTOKI_ALREADY_INITIALIZED.

Obviously?  Obviously something is wrong with that module!
Your implementation has apparently done something to maintain one single
global state for all applications, rather than each application having its
own state.  That's the problem.

> From what I understood from the specification, access to a Cryptoki 
> library should be permitted for more applications simultaneously.

Sure, just as access to libc is permitted by multiple applications
simultaneously.  But that doesn't mean that when one application opens a
file, then all applications have that file open.  The fact that one
application can do a read on fd 5 (say) does not mean that all applications
can do it.  The library's code is shared.  The library's STATE is not.

There may be some underlying device or devices to which the application
provides access.  Do not confuse device state with application API state.
C_Initialize initializes the APPLICATION's copy of the library, not the
device.  How the device, its drivers and its PKCS#11 API library manage to
multiplex multiple applications onto a single device is up to them.
However, they must not allow one application's API state to become
co-mingled with another's.

> The problem is, I don't have any form of application identification on 
> C_Initialize; only on C_OpenSession (the pApplication pointer).

C_Initialize initializes the application's (process's) copy of the API.
It doesn't reference any slot or token.  C_OpenSession talks to a device
(token).

> If I am to implement application identification on C_OpenSession, then
> when is C_Initialize supposed to return CKR_CRYPTOKI_ALREADY_INITIALIZED
> and when CKR_OK? I don't have a way of knowing if it's the same or new 
> application trying to initalize the library.

Sounds to me like you've tried to make all copies of your PKCS#11 library
share one common data segment for all state.  Oops.

> Any clues, please?
> 
> M. Kurpel

-- 
dev-tech-crypto mailing list
dev-tech-crypto@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-crypto

Reply via email to