-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_token_info.go
65 lines (60 loc) · 2.15 KB
/
get_token_info.go
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
package certex
/*
#include <stdlib.h>
#include <dlfcn.h>
#include <unistd.h>
#include <stdio.h>
#include "./headers/cryptoki.h"
#include "./headers/pkcs11def.h"
#include "./headers/pkcs11t.h"
#include "./headers/PKICertexHSM.h"
CK_RV get_token_info(CK_FUNCTION_LIST_PTR fl, CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo) {
return (*fl->C_GetTokenInfo)(slotID, pInfo);
}
*/
import "C"
import (
"fmt"
"unsafe"
)
func (s *Slot) GetTokenInfo() (TokenInfo, error) {
var cTokenInfo C.CK_TOKEN_INFO
if rv := C.get_token_info(s.fl, C.CK_SLOT_ID(s.id), &cTokenInfo); rv != C.CKR_OK {
return TokenInfo{}, fmt.Errorf("GetTokenInfo: 0x%08x : %s", rv, returnValues[rv])
}
r := TokenInfo{
Label: toString(cTokenInfo.label[:]),
ManufacturerID: toString(cTokenInfo.manufacturerID[:]),
Model: toString(cTokenInfo.model[:]),
SerialNumber: toString(cTokenInfo.serialNumber[:]),
Flags: uint(cTokenInfo.flags),
MaxSessionCount: uint(cTokenInfo.ulMaxSessionCount),
SessionCount: uint(cTokenInfo.ulSessionCount),
MaxRwSessionCount: uint(cTokenInfo.ulMaxRwSessionCount),
RwSessionCount: uint(cTokenInfo.ulRwSessionCount),
MaxPinLen: uint(cTokenInfo.ulMaxPinLen),
MinPinLen: uint(cTokenInfo.ulMinPinLen),
TotalPublicMemory: uint(cTokenInfo.ulTotalPublicMemory),
FreePublicMemory: uint(cTokenInfo.ulFreePrivateMemory),
TotalPrivateMemory: uint(cTokenInfo.ulTotalPrivateMemory),
FreePrivateMemory: uint(cTokenInfo.ulFreePrivateMemory),
HardwareVersion: Version{
Major: uint8(cTokenInfo.hardwareVersion.major),
Minor: uint8(cTokenInfo.hardwareVersion.minor),
},
FirmwareVersion: Version{
Major: uint8(cTokenInfo.firmwareVersion.major),
Minor: uint8(cTokenInfo.firmwareVersion.minor),
},
TimeUTC: toString(cTokenInfo.utcTime[:]),
}
C.free(unsafe.Pointer(&cTokenInfo))
return r, nil
}
func (s *Slot) getTokenInfo() (C.CK_TOKEN_INFO, error) {
var cTokenInfo C.CK_TOKEN_INFO
if rv := C.get_token_info(s.fl, C.CK_SLOT_ID(s.id), &cTokenInfo); rv != C.CKR_OK {
return C.CK_TOKEN_INFO{}, fmt.Errorf("GetTokenInfo: 0x%08x : %s", rv, returnValues[rv])
}
return cTokenInfo, nil
}