summaryrefslogtreecommitdiff
path: root/doc/rst/legacy/reference/nsc_inittoken/index.rst
blob: 1857e7ab48e5ed5e0e4dab729565a6d72b91e56f (plain)
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
.. _mozilla_projects_nss_reference_nsc_inittoken:

NSC_InitToken
=============

`Name <#name>`__
~~~~~~~~~~~~~~~~

.. container::

   ``NSC_InitToken()`` - initialize or re-initialize a token.

`Syntax <#syntax>`__
~~~~~~~~~~~~~~~~~~~~

.. container::

   .. code:: eval

      CK_RV NSC_InitToken(
        CK_SLOT_ID slotID,
        CK_CHAR_PTR pPin,
        CK_ULONG ulPinLen,
        CK_CHAR_PTR pLabel
      );

`Parameters <#parameters>`__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. container::

   ``NSC_InitToken()`` has the following parameters:

   ``slotID``
      the ID of the token's slot
   ``pPin``
      the password of the security officer (SO)
   ``ulPinLen``
      the length in bytes of the SO password
   ``pLabel``
      points to the label of the token, which must be padded with spaces to 32 bytes and not be
      null-terminated

`Description <#description>`__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. container::

   ``NSC_InitToken()`` initializes a brand new token or re-initializes a token that was initialized
   before.

   Specifically, ``NSC_InitToken()`` initializes or clears the key database, removes the password,
   and then marks all the *user certs* in the certificate database as *non-user certs*. (User certs
   are the certificates that have their associated private keys in the key database.)

   .. note::

      **Note:** The SO password should be the empty string, i.e., ``ulPinLen`` argument should be 0.
      ``NSC_InitToken()`` ignores the ``pLabel`` argument.

.. _return_value:

`Return value <#return_value>`__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. container::

   ``NSC_InitToken()`` returns the following return codes.

   -  ``CKR_OK``: token initialization succeeded.
   -  ``CKR_SLOT_ID_INVALID``: slot ID is invalid.
   -  ``CKR_TOKEN_WRITE_PROTECTED``

      -  slot ID is 1. (The non-FIPS mode has two slots: 1 and 2. The key database is in slot 2.
         Slot 1 doesn't have a key database.)
      -  we don't have a reference to the key database (we failed to open the key database or we
         have released our reference).

   -  ``CKR_DEVICE_ERROR``: failed to reset the key database.

`Examples <#examples>`__
~~~~~~~~~~~~~~~~~~~~~~~~

.. container::

.. _application_usage:

`Application usage <#application_usage>`__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. container::

   ``NSC_InitToken()`` is used to reset the password for the key database when the user forgets the
   password.

   -  The "Reset Password" button of the Mozilla Application Suite and SeaMonkey (in
      **Preferences->Privacy & Security->Master Passwords**) calls ``NSC_InitToken()``.
   -  The "-T" (token reset) command of ``certutil`` calls ``NSC_InitToken()``.

   .. note::

      **Note:** Resetting the password clears all permanent secret and private keys. You won't be
      able to decrypt the data, such as Mozilla's stored passwords, that were encrypted using any of
      those keys.

.. _see_also:

`See also <#see_also>`__
~~~~~~~~~~~~~~~~~~~~~~~~

.. container::

   -  `NSC_InitPIN </en-US/NSC_InitPIN>`__, :ref:`mozilla_projects_nss_reference_fc_inittoken`