Can you provide an example of how to use PKCS#11 interface to connect MQTT on Android9.0? #251
-
Confirm by changing [ ] to [x] below:
Platform/OS/Hardware/Device Describe the question
Which fields are definitely required in the TlsContextPkcs11Options instance? Can you help provide a sample code? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I believe the following settings are the minimal required settings for making an PKCS11 connection:
You can find sample code for creating an MQTT PKCS11 connection in the PKCS11 PubSub sample. Also: While we know the code compiles on Android, we have currently not run tests to ensure it works on Android at this time. |
Beta Was this translation helpful? Give feedback.
-
@TwistedTwigleg, I am curious if you have any further suggestions. There seems to be threading/locking issues with the use of this library in conjunction with the CRT library for android. After some slight modifications to the library the current issues is with the failure around the mutex and then lack of OS locking support when using this library on android. For example, when attempting to call .newMtlsPkcs11Builder(pkcs11Options) I get the following error: Exception encountered: software.amazon.awssdk.crt.CrtRuntimeException: TlsContext.tls_ctx_new: Failed to create new aws_tls_ctx (aws_last_error: AWS_ERROR_PKCS11_CKR_CANT_LOCK(1086), A PKCS#11 (Cryptoki) library function failed with return value CKR_CANT_LOCK) AWS_ERROR_PKCS11_CKR_CANT_LOCK(1086) However, when I load the module manually, and supply a null pointer for the mutex handler AND disable OS Locking I am able to initialize and query the device via the PKCS11 library: Module module = Module.getInstance("/vendor/lib/libcryptoauth.so", "/vendor/lib/libcryptoauth.so"); CK_INFO info = pkcs11.C_GetInfo(); These calls to pkcs11 lib function as expected. I am struggling to see a way for the current AWS SDK implementation to function with the CRT library on Android. Any thoughts/suggestions? |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
I believe the following settings are the minimal required settings for making an PKCS11 connection:
pkcs11Lib
userPin
certificateFilePath
You can find sample code for creating an MQTT PKCS11 connection in the PKCS11 PubSub sample.
There is also a simplified PKCS11 connection sample here in this PR that might also be helpful as a reference as it only contains code for making a PKCS11 connection and nothing more: #233
Also: While we know the code compiles on Android, we have currently not run tests to ensure it works on Android at this time.