Exemplo n.º 1
0
bool doSign(PluginInstance *obj, NPVariant *args, unsigned argCount, NPVariant *result) {
	EstEID_log("obj=%p, name=sign argCount=%u", obj, argCount);

	FAIL_IF_NOT_ALLOWED_SITE;

	if (argCount < 2) {
		browserFunctions->setexception(&obj->header, "Missing arguments");
		return false;
	}
	
	if(argCount > 2 && NPVARIANT_IS_OBJECT(args[2])){
		strncpy(pluginLanguage, getLanguageFromOptions(obj, args[2]), 2);
	}
	EstEID_setLocale(pluginLanguage);

	void* wnd = getNativeWindowHandle(obj);

	EstEID_PINPromptData pinPromptData = {promptForPIN, showAlert, wnd};
	NPUTF8* certId = createStringFromNPVariant(&args[0]);
	NPUTF8* hash = createStringFromNPVariant(&args[1]);
	char *signature = NULL;

#ifdef _WIN32
	DialogData dialogData;
	dialogData.pin2[0] = '\0';
	dialogData.minPin2Length = 5;
	dialogData.certId = certId;
	dialogData.hash = hash;
	dialogData.signature[0] = '\0';

	CK_SLOT_ID slotId;	
	if(EstEID_getSlotId(certId, &slotId)){
		if(EstEID_isPinPad(slotId)) {
			signature = EstEID_sign(certId, hash, pinPromptData);
		}
		else {
			DialogBoxParam(pluginInstance, MAKEINTRESOURCEW(IDD_PIN_DIALOG), (HWND)wnd, Pin2DialogProc, (LPARAM)&dialogData);
			LOG_LOCATION;
			signature = (char*)malloc(SIGNATURE_BUFFER_SIZE); // check?
			strcpy(signature, dialogData.signature);
		}
	}
	else {
		return false;
	}
#else
	signature = EstEID_sign(certId, hash, pinPromptData);
#endif
	LOG_LOCATION
	if (signature) {
		copyStringToNPVariant(signature, result);
		free(signature);
		return true;
	}
	else {
		EstEID_log("EstEID_error=%s", EstEID_error);
		browserFunctions->setexception(&obj->header, EstEID_error);
		return false;
	}
}
bool doSign(PluginInstance *obj, NPVariant *args, unsigned argCount, NPVariant *result) {
	EstEID_log("obj=%p, name=sign argCount=%u", obj, argCount);

	FAIL_IF_NOT_ALLOWED_SITE;

	if (argCount < 2) {
		browserFunctions->setexception(&obj->header, "Missing arguments");
		return false;
	}
	
	if(argCount > 2 && NPVARIANT_IS_OBJECT(args[2])){
		strncpy(pluginLanguage, getLanguageFromOptions(obj, args[2]), 2);
	}
	EstEID_setLocale(pluginLanguage);

	if(argCount > 3 && NPVARIANT_IS_OBJECT(args[3])){
		strcpy(promptMessage, createStringFromNPVariant(args[3]));
	}

	void* wnd = getNativeWindowHandle(obj);

	EstEID_PINPromptData pinPromptData = {promptForPIN, showAlert, wnd, promptMessage, NULL};
	NPUTF8* certId = createStringFromNPVariant(&args[0]);
	NPUTF8* hash = createStringFromNPVariant(&args[1]);
	char *signature = NULL;

	signature = EstEID_sign(certId, hash, pinPromptData);

	LOG_LOCATION
	if (signature) {
		copyStringToNPVariant(signature, result);
		free(signature);
		return true;
	}
	else {
		EstEID_log("EstEID_error=%s", EstEID_error);
		browserFunctions->setexception(&obj->header, EstEID_error);
		return false;
	}
}