Comments (9)
Can you try the latest version of the [email protected]? This version uses the latest version of the nan
and it can fix the error
from pkcs11js.
You can update C++ code to gathering segmentation fault stack trace
- Update main.cpp
- Rebuild pkcs11js
npm rebuild
or
cd node_modules/pkcs11js
node-gyp counfigure build
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
Error: signal 11:
0 pkcs11.node 0x00000001069e0bc1 _Z7handleri + 33
1 libsystem_platform.dylib 0x00007fff7393db5d _sigtramp + 29
2 node 0x00000001001e2975 _ZN2v88internal6String9VisitFlatINS_17Utf8WriterVisitorEEEPNS0_10ConsStringEPT_PS1_i + 165
3 pkcs11.node 0x0000000106a14644 _ZN7WPKCS117C_LoginERKN3Nan20FunctionCallbackInfoIN2v85ValueEEE + 1354
4 pkcs11.node 0x0000000106a3117c _ZN3Nan3impL23FunctionCallbackWrapperERKN2v820FunctionCallbackInfoINS1_5ValueEEE + 170
5 node 0x000000010023663f _ZN2v88internal25FunctionCallbackArguments4CallEPNS0_15CallHandlerInfoE + 623
6 node 0x0000000100235b81 _ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEESA_NS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EENS0_16BuiltinArgumentsE + 689
7 node 0x0000000100235220 _ZN2v88internalL26Builtin_Impl_HandleApiCallENS0_16BuiltinArgumentsEPNS0_7IsolateE + 288
8 ??? 0x00001c4b44fdbe3d 0x0 + 31109605604925
9 ??? 0x00001c4b44f918d5 0x0 + 31109605300437
from pkcs11js.
thanks for your response, sadly updating to 1.0.18 didn't help,
also after adding the signal handler, it gave an obscure error:
> 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?
from pkcs11js.
As I can see you are using Cryptoki v2.20
I'm checking it's API
pkcs11js is based on Cryptoki v2.30
from pkcs11js.
Can you add logs like puts("Log message");
to node.cpp:609-626 and pkcs11.cpp:365-376 files?
from pkcs11js.
after some debug messages, if hangs on C_Login
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?)
from pkcs11js.
The functionLsit
is CK_FUNCTION_LIST
structure from PKCS#11.
functionList->C_Login
- calls C_Login function from PKCS#11 library. You can print the incomming parameters to check that they are right
from pkcs11js.
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;
}
from pkcs11js.
something I noted is that the session buffer is 4 bytes in the raspberry and 8 bytes on a PC
from pkcs11js.
Related Issues (20)
- WebUSB support?
- How do we popup the PIN dialog (runtime) for the user to enter PIN during C_Login / C_LoginUser HOT 1
- Docker image Alpine unable to Install pkcs11js HOT 6
- segfault in C_Sign with fabric-sdk-node and SoftHSM2 HOT 6
- I want to install pkcs11js but I have not managed to run it HOT 3
- key pair not persistet as file object HOT 7
- SafeNET 5100 token crashes the application on MacOS
- unable to install pkcs11.js in windows 10 HOT 2
- Help wanted, I am trying to sign a CSR using pkcs11 with private key stored in HSM, but the CSR signature is not valid. HOT 27
- Ability to define custom pkcs wrapper HOT 9
- Module did not self-register HOT 4
- No error thrown when methods are called without loading library HOT 2
- Meaning of variable name `token` in tests? HOT 3
- Pkcs11Error: CKR_OBJECT_HANDLE_INVALID HOT 1
- Test possibly mislabeled?
- Can't support mac m1 arm64 cpu HOT 3
- Unable to wrap with RSA key HOT 3
- Problem with NODE_MODULE_VERSION HOT 5
- Build problem with ElectronJS 21
- Add support for pkcs#11 3.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pkcs11js.