STDMETHODIMP CEstEIDIEPluginBHO::sign(BSTR id, BSTR hash, BSTR language, BSTR *signature){ LOG_LOCATION; FAIL_IF_SITE_IS_NOT_ALLOWED; try { EstEID_setLocale(CW2A(this->language)); if(isCNGInstalled() && isWinVistaOrLater()) { signWithCNG(id, hash, signature); } else if(isWinVistaOrLater()){ signWithCSP(id, hash, signature); } else { signWithPKCS11(NULL, id, hash, signature); } } catch (CryptoException e) { EstEID_log("CryptoException caught during signing!"); if(e._reason.compare("User cancel")){ setError(ESTEID_USER_CANCEL); EstEID_log("CryptoExcepton reason - user cancel"); } mapInternalErrorCodes(e.windowsErrorCode); return Error((this->errorMessage).c_str()); } setError(ESTEID_NO_ERROR); EstEID_log("Signing ended"); return S_OK; }
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 pluginInvoke(PluginInstance *obj, NPIdentifier name, NPVariant *args, unsigned argCount, NPVariant *result) { LOG_LOCATION; EstEID_clear_error(); EstEID_setLocale(pluginLanguage); if (isSameIdentifier(name, "sign")) { return doSign(obj, args, argCount, result); } if (isSameIdentifier(name, "getCertificate")) { return doGetCertificate(obj, result); } if (isSameIdentifier(name, "getVersion")) { return pluginGetProperty(obj, browserFunctions->getstringidentifier("version"), result); } EstEID_log("obj=%p, name=%p, argCount=%u", obj, name, argCount); 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; } }
STDMETHODIMP CEstEIDIEPluginBHO::getCertificate(IDispatch **_certificate){ EstEID_log(""); FAIL_IF_SITE_IS_NOT_ALLOWED EstEID_setLocale(CW2A(this->language)); try { if(!this->certificate || !isSameCardInReader(this->certificate)) { this->certificate.CoCreateInstance(CLSID_EstEIDCertificate); } CComPtr<IEstEIDCertificate> cert; this->certificate.CopyTo(&cert); *_certificate = cert.Detach(); } catch(CryptoException e) { mapInternalErrorCodes(e.windowsErrorCode); return Error((this->errorMessage).c_str()); } setError(ESTEID_NO_ERROR); return S_OK; }