-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segmentation Fault #48
Comments
Can you try the latest version of the [email protected]? This version uses the latest version of the |
You can update C++ code to gathering segmentation fault stack trace
or
main.cpp#include <nan.h>
#include <node.h>
#include <execinfo.h>
#include <signal.h>
#include <unistd.h>
#include "const.h"
#include "node.h"
void handler(int sig)
{
void *array[10];
size_t size;
// get void*'s for all entries on the stack
size = backtrace(array, 10);
// print out all the frames to stderr
fprintf(stderr, "Error: signal %d:\n", sig);
backtrace_symbols_fd(array, size, STDERR_FILENO);
exit(1);
}
NAN_MODULE_INIT(init)
{
signal(SIGSEGV, handler); // install our handler
Nan::HandleScope scope;
WPKCS11::Init(target);
declare_objects(target);
declare_attributes(target);
declare_ket_types(target);
declare_mechanisms(target);
declare_flags(target);
declare_certificates(target);
declare_mgf(target);
declare_kdf(target);
declare_params(target);
declare_initialize_flags(target);
declare_user_types(target);
}
NODE_MODULE(pkcs11, init) Output example
|
thanks for your response, sadly updating to 1.0.18 didn't help, > var pkcs11js = require("pkcs11js");
undefined
> var pkcs11 = new pkcs11js.PKCS11();
undefined
> pkcs11.load("/usr/lib/arm-linux-gnueabihf/opensc-pkcs11.so")
undefined
> pkcs11.C_Initialize()
undefined
> pkcs11.C_GetInfo()
{ cryptokiVersion: { major: 2, minor: 20 },
manufacturerID: 'OpenSC Project ',
flags: 0,
libraryDescription: 'OpenSC smartcard framework ',
libraryVersion: { major: 0, minor: 16 } }
> slots = pkcs11.C_GetSlotList(true)
[ <Buffer 00 00 00 00> ]
> slot = slots[0]
<Buffer 00 00 00 00>
> pkcs11.C_GetSlotInfo(slot)
{ slotDescription:
'Feitian ePass2003 00 00 ',
manufacturerID: 'FS ',
flags: 7,
hardwareVersion: { major: 1, minor: 16 },
firmwareVersion: { major: 0, minor: 0 } }
> pkcs11.C_GetTokenInfo(slot)
{ label: '*my label* (User PIN) ',
manufacturerID: 'EnterSafe ',
model: 'PKCS#15 ',
serialNumber: '*the serial number*',
flags: 1037,
maxSessionCount: 0,
sessionCount: 0,
maxRwSessionCount: 0,
rwSessionCount: 0,
maxPinLen: 16,
minPinLen: 4,
hardwareVersion: { major: 0, minor: 0 },
firmwareVersion: { major: 0, minor: 0 },
utcTime:
'\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000',
totalPublicMemory: 4294967295,
freePublicMemory: 4294967295,
totalPrivateMemory: 4294967295,
freePrivateMemory: 4294967295 }
> session = pkcs11.C_OpenSession(slot, pkcs11js.CKF_RW_SESSION | pkcs11js.CKF_SERIAL_SESSION)
<Buffer f0 94 d4 02>
> info = pkcs11.C_GetSessionInfo(session)
{ slotID: <Buffer 00 00 00 00>,
state: 2,
flags: 6,
deviceError: 0 }
> pkcs11.C_Login(session, 1, "mypass")
*** Error in `node': malloc(): memory corruption: 0x02d493e8 ***
and now it hangs! I can't exit node! any idea? |
As I can see you are using Cryptoki v2.20 pkcs11js is based on Cryptoki v2.30 |
Can you add logs like |
after some debug messages, if hangs on void PKCS11::C_Login(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, Scoped<string> pin) {
try {
puts("bfore pkcs11 login");
CHECK_PKCS11_RV(functionList->C_Login(
hSession,
userType,
pin->length() ? (CK_UTF8CHAR_PTR)pin->c_str() : NULL_PTR, (CK_ULONG)pin->length()
));
puts("after pkcs11 login (never shown...)");
}
CATCH_ERROR;
} where is this functionList and how can I further debug? (how can I update the Cryptoki or it's inherent of my device?) |
The
|
it seems hSession is the content of session buffer, usertype is 1 as in the example, pin length and pin c_str is the provided pin void PKCS11::C_Login(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, Scoped<string> pin) {
try {
puts("bfore pkcs11 login");
printf("session %lx\n", hSession);
printf("utype %lx\n", userType);
printf("pin lenght %u\n", pin->length());
printf("pin str %s\n", pin->c_str());
CHECK_PKCS11_RV(functionList->C_Login(
hSession,
userType,
pin->length() ? (CK_UTF8CHAR_PTR)pin->c_str() : NULL_PTR, (CK_ULONG)pin->length()
));
puts("after pkcs11 login (never shown)");
}
CATCH_ERROR;
} |
something I noted is that the session buffer is 4 bytes in the raspberry and 8 bytes on a PC |
pkcs11js version: "1.0.17",
I have been testing node-webcrypto-p11 and graphene with a feitian epass2003 token on ubuntu18, and everything seems to work, I can login(auth) and sign some data..
now I'm trying to make it work on a raspberry (4.14.98-v7+ ARM7l debian/raspbian), most tools, works ok (I can login and list the private cert with
pkcs11-tool --module /usr/lib/arm-linux-gnueabihf/opensc-pkcs11.so --login --list-objects
)but it gives me error on Node. I isolated up to pkcs11js if I try a
pkcs11.C_Login
it exists with a "Segmentation Fault" message and nothing more...is there someway to get more information or debug logs? pcscd doesn't show anything unnatural BTW
The text was updated successfully, but these errors were encountered: