private static void CSCbpinopResult(eid_vwr_pinops pinop, eid_vwr_result result) { try { if (theData.log_level == eid_vwr_loglevel.EID_VWR_LOG_DETAIL) { theData.logText += "CSCbpinopResult called, result = " + result.ToString() + "\n"; } ResourceManager rm = new ResourceManager("eIDViewer.Resources.ApplicationStringResources", Assembly.GetExecutingAssembly()); switch (result) { //pkcs11 will bring up a message box in case of a failure //case eid_vwr_result.EID_VWR_RES_FAILED: // System.Windows.MessageBox.Show("PinOp Failed"); // break; case eid_vwr_result.EID_VWR_RES_SUCCESS: System.Windows.MessageBox.Show(rm.GetString("pinVerifiedOKDialogMessage", Thread.CurrentThread.CurrentUICulture)); break; } } catch (Exception e) { theData.logText += "CSCbpinopResult encountered an error " + e.ToString() + "\n"; } }
private static void CSCbpinopResult(eid_vwr_pinops pinop, eid_vwr_result result) { try { //Console.WriteLine("CSCbpinopResult called "); if (theData.log_level == eid_vwr_loglevel.EID_VWR_LOG_DETAIL) { theData.logText += "CSCbpinopResult called, result = " + result.ToString() + "\n"; } System.Resources.ResourceManager rm = new System.Resources.ResourceManager("ApplicationStringResources", typeof(eIDViewer.Resources.ApplicationStringResources).Assembly); switch (result) { case eid_vwr_result.EID_VWR_RES_FAILED: System.Windows.MessageBox.Show("PinOp Failed"); break; case eid_vwr_result.EID_VWR_RES_SUCCESS: System.Windows.MessageBox.Show(rm.GetString("CARD", null)); break; } } catch (Exception e) { theData.logText += "CSCbpinopResult encountered an error " + e.ToString() + "\n"; } }
private static void CSCbpinopResult(eid_vwr_pinops pinop, eid_vwr_result result) { try { theData.WriteLog("CSCbpinopResult called, result = " + result.ToString() + "\n", eid_vwr_loglevel.EID_VWR_LOG_NORMAL); ResourceManager rm = new ResourceManager("eIDViewer.Resources.ApplicationStringResources", Assembly.GetExecutingAssembly()); switch (result) { //pkcs11 will bring up a message box in case of a failure //case eid_vwr_result.EID_VWR_RES_FAILED: // System.Windows.MessageBox.Show("PinOp Failed"); // break; case eid_vwr_result.EID_VWR_RES_SUCCESS: if (pinop == eid_vwr_pinops.EID_VWR_PINOP_TEST) { theData.pincodeVerifiedSucces("pinVerifiedOKDialogMessage"); } else if (pinop == eid_vwr_pinops.EID_VWR_PINOP_CHG) { theData.pincodeVerifiedSucces("pinChangedOKDialogMessage"); } //CultureInfo culture = new CultureInfo(theData.localization); // System.Windows.MessageBox.Show(rm.GetString("pinVerifiedOKDialogMessage", culture)); break; } } catch (Exception e) { theData.WriteLog("CSCbpinopResult encountered an error " + e.ToString() + "\n", eid_vwr_loglevel.EID_VWR_LOG_ERROR); } }
private static void CSCbchallengeResult([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] byte[] signature, int signaturelen, eid_vwr_result result) { try { theData.WriteLog("CSCbchallengeResult called, result = " + result.ToString() + "\n", eid_vwr_loglevel.EID_VWR_LOG_NORMAL); switch (result) { //in case the function failed, we should not generate an error case eid_vwr_result.EID_VWR_RES_SUCCESS: //verify the response /* Offset ENCODING ASN.1 Syntax * * 00 30 76 -- SEQUENCE LENGTH * 02 30 10 -- SEQUENCE LENGTH * Label * 04 06 07 -- OBJECT_ID LENGTH * 2A 86 48 CE 3D 02 01 EcPublicKey (1 2 840 10045 2 1) * * 0D 06 05 -- OBJECT_ID LENGTH * 0F 2B 81 04 00 22 Secp384r1 (1 3 132 0 34) * * 14 03 62 -- BIT_STRING (98 bytes) LENGTH * 16 00 -- no bits unused in the final byte * 17 04 compression byte * 18 {48 bytes} -- X coordinate * 48 {48 bytes} -- Y coordinate * */ //For now: No real parsing here, only accepting the above fixed format //Will add the parsing in pkcs#11, or here, later if (theData.basicKeyFile.Length != 0x78) { //File for supported format is incorrect, cannot verify, exit } byte[] KeyParams = new byte[5]; byte[] Secp384r1 = { 0x2B, 0x81, 0x04, 0x00, 0x22 }; byte[] KeyValue_X = new byte[48]; byte[] KeyValue_Y = new byte[48]; Array.Copy(theData.basicKeyFile, 0x0F, KeyParams, 0, 5); ECParameters parameters = new ECParameters(); if (System.Collections.StructuralComparisons.StructuralEqualityComparer.Equals(KeyParams, Secp384r1)) { //Fill in parameters named curve: //Create a named curve using the specified Oid object. System.Security.Cryptography.Oid cardP384oid = new Oid("ECDSA_P384"); parameters.Curve = ECCurve.CreateFromOid(cardP384oid); Array.Copy(theData.basicKeyFile, 0x18, KeyValue_X, 0, 48); Array.Copy(theData.basicKeyFile, 0x48, KeyValue_Y, 0, 48); //Fill in parameters public key (Q) System.Security.Cryptography.ECPoint Q; Q.X = KeyValue_X; Q.Y = KeyValue_Y; parameters.Q = Q; } else { //not supported, cannot verify, exit } ECDsa dsa = ECDsa.Create(parameters); if (dsa.VerifyData(theData.challenge, signature, HashAlgorithmName.SHA384)) { Console.WriteLine("Data is good"); } else { Console.WriteLine("Data is bad"); } break; case eid_vwr_result.EID_VWR_RES_FAILED: //mark the verification as not happened theData.WriteLog("CSCbchallengeResult encountered an error, key verification could not start \n", eid_vwr_loglevel.EID_VWR_LOG_ERROR); break; } } catch (Exception e) { theData.WriteLog("CSCbchallengeResult encountered an error " + e.ToString() + "\n", eid_vwr_loglevel.EID_VWR_LOG_ERROR); } }