-
Notifications
You must be signed in to change notification settings - Fork 0
/
open.go
66 lines (56 loc) · 1.25 KB
/
open.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
66
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"
*/
// #cgo linux LDFLAGS: -ldl
// #cgo darwin LDFLAGS: -ldl
// #cgo openbsd LDFLAGS:
// #cgo freebsd LDFLAGS: -ldl
import "C"
import (
"fmt"
"os"
)
// Opens Cryptoki module
func Open(libName string, confPath string) (*Cryptoki, error) {
mod, err := dlOpen(libName)
if err != nil {
fmt.Printf("dlOpen: %s\n", err)
os.Exit(1)
}
connect(mod, confPath)
var p C.CK_FUNCTION_LIST_PTR
// fmt.Printf("p: %v\n", p)
// fmt.Printf("mod: %d\n", mod)
p, err = getFunctionList(mod, p)
if err != nil {
fmt.Printf("getFunctionList: %s\n", err)
}
if err := initialize(p); err != nil {
fmt.Printf("initialize: %s\n", err)
}
info, err := getInfo(p)
if err != nil {
fmt.Printf("getInfo: %s\n", err)
}
return &Cryptoki{
mod: mod,
fl: p,
version: info.cryptokiVersion,
info: Info{
Manufacturer: string(info.manufacturerID[:]),
Version: Version{
Major: uint8(info.libraryVersion.major),
Minor: uint8(info.libraryVersion.minor),
},
Description: string(info.libraryDescription[:]),
},
}, nil
}