I have a Safenet 5110 dongle. I am using MacOS ventura 13.2.1 (with Swift 5.7 and Xcode 14.2). I have downloaded the driver to authenticate with the dongle (Safenet Authentication Token - SAC). There, I have found libeTPkcs11.dylib
which can be used to communicate with their dongle.
Here is my code:
import Foundation
let pkcs11LibPath = "/usr/local/lib/libeTPkcs11.dylib"
let pkcs11LibHandle = dlopen(pkcs11LibPath, RTLD_NOW)
if pkcs11LibHandle == nil {
let errorMsg = String(cString: dlerror())
print("Failed to load PKCS#11 library: \(errorMsg)")
exit(1)
}
// Get a pointer to the C_GetInfo function
let cGetInfoPtr = dlsym(pkcs11LibHandle, "C_GetInfo")
typealias C_GetInfo_Type = @convention(c) (UnsafeMutableRawPointer?, UnsafeMutablePointer<CK_INFO>?) -> CK_RV
let cGetInfo = unsafeBitCast(cGetInfoPtr, to: C_GetInfo_Type.self)
// Call the C_GetInfo function to get information about the token
var info = CK_INFO()
let rv = cGetInfo(nil, &info)
if rv != CKR_OK {
print("Failed to get token info: \(rv)")
exit(1)
}
print("Manufacturer ID: \(String(cString: &info.manufacturerID))")
print("Model: \(String(cString: &info.model))")
print("Serial number: \(String(cString: &info.serialNumber))")
I am getting the following errors when I try to compile the code:
- Cannot find type 'CK_RV' in scope
- Cannot find type 'CK_INFO' in scope
I think that, these come from the pkcs11.h header files from OASIS specifications.
I have created a bridging header caclient-Bridging-Header.h
. There I have included the file pkcs11.h
. But I think xcode is recognizing the header file as a objective-c header (not c99 header).