# Key Counter in NitroKey HSM

**URL:** https://support.nitrokey.com/t/key-counter-in-nitrokey-hsm/658
**Category:** Nitrokeys
**Created:** [September 15, 2017, 11:39pm UTC](https://support.nitrokey.com/t/key-counter-in-nitrokey-hsm/658 "2017-09-15T23:39:45Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![dchan](https://support.nitrokey.com/user_avatar/support.nitrokey.com/dchan/32/152_2.png) [@dchan](https://support.nitrokey.com/u/dchan)
#### Post date: [September 15, 2017, 11:39pm UTC](https://support.nitrokey.com/t/key-counter-in-nitrokey-hsm/658/1 "2017-09-15T23:39:45Z")

</div>

The NitroKey HSM literature talks about Key Counter that can limit the number of times the key can be used.

However I cannot find documentation on where to specify this in any documentation. Are there examples?

---

<div class="post-metadata">

### Author: ![nitroalex](https://support.nitrokey.com/user_avatar/support.nitrokey.com/nitroalex/32/133_2.png) [@nitroalex](https://support.nitrokey.com/u/nitroalex)
#### Post date: [September 18, 2017, 9:15am UTC](https://support.nitrokey.com/t/key-counter-in-nitrokey-hsm/658/2 "2017-09-18T09:15:43Z")

</div>

Hi,

as far as I can see it is not implemented in the command set of the [OpenSC project](https://github.com/OpenSC/OpenSC/wiki/SmartCardHSM) yet. Maybe a feature request is worth a try?  
There are probably other options to manage this (maybe by setting the value directly with help of opensc-explorer?). I try to find out…

Kind regards  
Alex

---

<div class="post-metadata">

### Author: ![nitroalex](https://support.nitrokey.com/user_avatar/support.nitrokey.com/nitroalex/32/133_2.png) [@nitroalex](https://support.nitrokey.com/u/nitroalex)
#### Post date: [September 18, 2017, 9:16am UTC](https://support.nitrokey.com/t/key-counter-in-nitrokey-hsm/658/3 "2017-09-18T09:16:54Z")

</div>

Ah… and by the way: you mean the “[key use counter](https://www.smartcard-hsm.com/2015/10/10/Shared_Control_over_Key_Usage.html)”, do you?

---

<div class="post-metadata">

### Author: ![jan](https://support.nitrokey.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@jan](https://support.nitrokey.com/u/jan)
#### Post date: [September 18, 2017, 12:34pm UTC](https://support.nitrokey.com/t/key-counter-in-nitrokey-hsm/658/4 "2017-09-18T12:34:27Z")

</div>

Hi dchan! You would need the SDK. Please register at the [CardContact Developer Network](https://www.cardcontact.de/cdn/about.html) to get access to the SDK.

---

<div class="post-metadata">

### Author: ![dchan](https://support.nitrokey.com/user_avatar/support.nitrokey.com/dchan/32/152_2.png) [@dchan](https://support.nitrokey.com/u/dchan)
#### Post date: [September 18, 2017, 3:44pm UTC](https://support.nitrokey.com/t/key-counter-in-nitrokey-hsm/658/5 "2017-09-18T15:44:34Z")

</div>

> [@nitroalex](#):
>
> key use counter

Yes. I was referring to the Key Use Counter

---

<div class="post-metadata">

### Author: ![dchan](https://support.nitrokey.com/user_avatar/support.nitrokey.com/dchan/32/152_2.png) [@dchan](https://support.nitrokey.com/u/dchan)
#### Post date: [September 18, 2017, 3:51pm UTC](https://support.nitrokey.com/t/key-counter-in-nitrokey-hsm/658/6 "2017-09-18T15:51:28Z")

</div>

I did download the CardContact SDK and studied over the weekend.

Looks like it requires some extra data when constructing the GAKP payload in the APDU…I modified CardContact’s scsh scripts and confirms it works

opensc\_explorer also displays the counter as a proprietary attribute:

```
OpenSC [E82B/0601/0401/81C3/1F02/01]> info CC05

Elementary File ID CC05

File path: CC05
File size: 0 bytes
EF structure: Transparent
ACL for READ: N/A
ACL for UPDATE: N/A
ACL for DELETE: N/A
ACL for WRITE: N/A
ACL for REHABILITATE: N/A
ACL for INVALIDATE: N/A
ACL for LIST FILES: N/A
ACL for CRYPTO: N/A
Proprietary attributes: 90 04 00 00 00 F6

```

Open to ideas on how to integrate this properly into pkcs11-tool. Perhaps as a tag in --key-type? E.g

```
pkcs11-tool -k --key-type "EC:prime256v1/counter=255" -l
```

---

<div class="post-metadata">

### Author: ![nitroalex](https://support.nitrokey.com/user_avatar/support.nitrokey.com/nitroalex/32/133_2.png) [@nitroalex](https://support.nitrokey.com/u/nitroalex)
#### Post date: [September 20, 2017, 5:10pm UTC](https://support.nitrokey.com/t/key-counter-in-nitrokey-hsm/658/7 "2017-09-20T17:10:20Z")

</div>

Hi @dchan,

that’s great! If you can provide a short description for other users here, you are welcome to do so 😉

If you are willing to get this feature integrated in pkcs11-tool even better!

We’d have to ask the opensc people anyway, but in my point of view it would be best to introduce a new flag like

> –key-usage-counter=X

where the functionality is disabled by default.

Integrating this information in the --key-type flag is may confusing and may conflicts with older instructions/scripts.

Are you willing to open a issue/feature request on [github](https://github.com/OpenSC/OpenSC/issues)?

Kind regards  
Alex

---

<div class="post-metadata">

### Author: ![dchan](https://support.nitrokey.com/user_avatar/support.nitrokey.com/dchan/32/152_2.png) [@dchan](https://support.nitrokey.com/u/dchan)
#### Post date: [September 20, 2017, 10:56pm UTC](https://support.nitrokey.com/t/key-counter-in-nitrokey-hsm/658/8 "2017-09-20T22:56:09Z")

</div>

Sure, I have opened up issue [#1154](https://github.com/OpenSC/OpenSC/issues/1154) on GitHub.

---

<div class="post-metadata">

### Author: ![ant1a](https://support.nitrokey.com/user_avatar/support.nitrokey.com/ant1a/32/213_2.png) [@ant1a](https://support.nitrokey.com/u/ant1a)
#### Post date: [April 24, 2018, 12:41pm UTC](https://support.nitrokey.com/t/key-counter-in-nitrokey-hsm/658/9 "2018-04-24T12:41:01Z")

</div>

Hello  
Can you provide any simple example on how to use the scsh for setting a key with a counter?  
I would be gratefull  
Thank you
