private void ProcessSyncEventPkcs11GetKeys(string msg) { PKCS11Detail d = ManagementParser.getPKCS11ID(msg); if (d != null) { m_pkcs11details.Add(d); if (d.Number < m_pkcs11count - 1) { m_ovpnComm.send("pkcs11-id-get " + (d.Number + 1)); } else { releaseLock(); int kid = m_ovpn.getKeyID(m_pkcs11details); if (kid == NeedCardIdEventArgs.Retry) { setLock(WaitState.PKCS11_GET_COUNT); m_ovpnComm.send("pkcs11-id-count"); } else if (kid != NeedCardIdEventArgs.None) { m_ovpnComm.send("needstr 'pkcs11-id-request' '" + m_pkcs11details[kid].Id + "'"); } } } // error in parsing else { m_logs.logDebugLine(1, "Error while parsing pkcs11-id-get: \"" + msg + "\""); releaseLock(); } }
/// <summary> /// We got a synchronous message. /// </summary> /// <param name="msg">The message</param> public void cb_syncEvent(string msg) { // the reaction depends on what we are waiting for switch (m_state) { // the number of SmartCards case WaitState.PKCS11_GET_COUNT: m_pkcs11count = m_ovpnMParser.getPKCS11IDCount(msg); if (m_pkcs11count == -1) { m_logs.logLine(OVPNLogEventArgs.LogType.MGNMT, "Could not determine the number of pkcs11-ids:\"" + msg + "\""); releaseLock(); } else if (m_pkcs11count == 0) { m_logs.logLine(OVPNLogEventArgs.LogType.MGNMT, "No pkcs11-ids were found"); int id = m_ovpn.getKeyID(new List <PKCS11Detail>()); if (id == OVPNNeedCardIDEventArgs.RETRY) { m_ovpnComm.send("pkcs11-id-count"); } else { releaseLock(); } } else { m_logs.logLine(OVPNLogEventArgs.LogType.MGNMT, "Got " + m_pkcs11count + " PKCS11-IDs"); m_pkcs11details.Clear(); releaseLock(); setLock(WaitState.PKCS11_GET_KEYS); m_ovpnComm.send("pkcs11-id-get 0"); } break; case WaitState.PKCS11_GET_KEYS: PKCS11Detail d = m_ovpnMParser.getPKCS11ID(msg); if (d != null) { m_pkcs11details.Add(d); if (d.Number < m_pkcs11count - 1) { m_ovpnComm.send("pkcs11-id-get " + (d.Number + 1)); } else { releaseLock(); int kid = m_ovpn.getKeyID(m_pkcs11details); if (kid == OVPNNeedCardIDEventArgs.RETRY) { setLock(WaitState.PKCS11_GET_COUNT); m_ovpnComm.send("pkcs11-id-count"); } else if (kid != OVPNNeedCardIDEventArgs.NONE) { m_ovpnComm.send("needstr 'pkcs11-id-request' '" + m_pkcs11details[kid].Id + "'"); } } } // error in parsing else { m_logs.logDebugLine(1, "Error while parsing pkcs11-id-get: \"" + msg + "\""); releaseLock(); } break; // logging was turned on, wait for log lines case WaitState.LOG_ON_ALL_1: setLock(WaitState.LOG_ON_ALL_2,true); break; // logging was turned on case WaitState.LOG_ON: case WaitState.LOG_ON_ALL_2: releaseLock(); string[] m = msg.Split("\n".ToCharArray()); for (int i = 0; i < m.GetUpperBound(0) - 1; ++i) { addLog(m[i]); } setLock(WaitState.STATE); m_ovpnComm.send("state on"); break; // "state" was set case WaitState.STATE: releaseLock(); if (m_releaselock) { setLock(WaitState.HOLD_RELEASE); m_ovpnComm.send("hold release"); m_releaselock = false; } break; // hold relese was executed case WaitState.HOLD_RELEASE: releaseLock(); break; // we sent a signal case WaitState.SIGNAL: releaseLock(); break; // something else happened (this should not happen) // we release the lock default: releaseLock(); break; } }