void CCryptosaurEngine::MsgValidateAuthToken (const SArchonMessage &Msg, const CHexeSecurityCtx *pSecurityCtx) // MsgValidateAuthToken // // Cryptosaur.validateAuthToken {authToken} { // Any service can validate a token if (!ValidateMessage(Msg, pSecurityCtx, false)) return; // Get the key to sign with (the key is guaranteed to exist because we // checked at boot time). CIPInteger *pAuthTokenKey = m_Keys.GetAt(KEY_CRYPTOSAUR_AUTH_TOKEN); // Validate CDatum dData; if (!CCryptosaurInterface::ValidateAuthToken(Msg.dPayload.GetElement(0), *pAuthTokenKey, &dData)) { SendMessageReply(MSG_REPLY_DATA, CDatum(), Msg); return; } // A sandboxed authtoken is not valid outside of its scope. // (But it is valid in admin services). const CString &sScope = dData.GetElement(FIELD_SCOPE); if (!sScope.IsEmpty() && pSecurityCtx && !pSecurityCtx->IsNamespaceAccessible(sScope)) { SendMessageReply(MSG_REPLY_DATA, CDatum(), Msg); return; } // Return the data in the auth token SendMessageReply(MSG_REPLY_DATA, dData, Msg); }
// Receive message void SCreceiver::Receive(void){ /* 1) check if listenning 2) update elapsed time 3) check for time overflow 4) analyze data received (on transition) 4.1) check for start signal (reset state & buffer_length) 4.2) check for buffer overflow (when applicable) 4.3) store value (when applicable) 4.4) update signal value {ID+Chn, Len, mes, CS} --> (message to send) {0x11, 0x03, 1, 2, 3, 0x06} --> {00010001, 00000011, 00000001, 00000010, 00000011, 00000110} */ //check if initialized if(!_initialized) return; //check state if((_state != SC_STATE_LISTENNING) && (_state != SC_STATE_MESSAGE_READY)) return; _elapsed_time += SC_TIMER_INTERVAL; //update //check for time overflow if(_elapsed_time >= SC_SIGNAL_MAX_TIME){ _elapsed_time = 0; //reset _previous_signal = LOW; //reset //check if is end of transmission if(_signal_state & SC_FOUND){ if(abs(_signal[0] - _duration_high) <= SC_SIGNAL_DEVIATION){ // ONE //check for buffer overflow if(_buffer_length >= SC_TOTAL_MESSAGE_SIZE){ _state = SC_STATE_ERROR_OVERFLOW; return; } //not overflow, continue _buffer[_buffer_length] |= (1 << _bit); //store value (bitwise OR) if(_bit <= 0){ //SHOULD ENTER HERE ! _buffer_length++; //new byte } } else if(abs(_signal[0] - _duration_low) <= SC_SIGNAL_DEVIATION){ // ZERO //check for buffer overflow if(_buffer_length >= SC_TOTAL_MESSAGE_SIZE){ _state = SC_STATE_ERROR_OVERFLOW; return; } //not overflow, continue _buffer[_buffer_length] &= ~(1 << _bit); //store value (bitwise AND + using NOT operator) if(_bit <= 0){ //SHOULD ENTER HERE ! _buffer_length++; //new byte } } } //validate message if someting was found if((_signal_state & SC_FOUND) && (_state == SC_STATE_LISTENNING)) ValidateMessage(); _signal_state = 0; //reset } else { // WAIT NEXT CYCLE TO BEGIN because call to ValidateMessage() can be too much time consuming uint8_t signal = digitalRead(_pin); if(signal != _previous_signal){ //transition if((_previous_signal == LOW) && (_signal_state & SC_FOUND)){ //store LOW if already found something _signal[1] = _elapsed_time; //previous was LOW _elapsed_time = 0; //reset for next signal //check wich signal was found if((abs(_signal[0] - _start_duration_high) <= SC_SIGNAL_DEVIATION) && (abs(_signal[1] - _start_duration_low) <= SC_SIGNAL_DEVIATION)){ // START _signal_state = SC_START | SC_FOUND; _buffer_length = 0; //reset _bit = 7; //reset (start with msb) //set state if necessary (overwrite previous message) if(_state == SC_STATE_MESSAGE_READY) _state = SC_STATE_LISTENNING; } else if((abs(_signal[0] - _duration_high) <= SC_SIGNAL_DEVIATION) && (abs(_signal[1] - _duration_low) <= SC_SIGNAL_DEVIATION)){ // ONE //check for buffer overflow if(_buffer_length >= SC_TOTAL_MESSAGE_SIZE){ _state = SC_STATE_ERROR_OVERFLOW; return; } //not overflow, continue _signal_state = SC_ONE | SC_FOUND; _buffer[_buffer_length] |= (1 << _bit); //store value (bitwise OR) if(_bit <= 0){ _bit = 7; //reset _buffer_length++; //new byte } else { _bit--; //decrease } } else if((abs(_signal[0] - _duration_low) <= SC_SIGNAL_DEVIATION) && (abs(_signal[1] - _duration_high) <= SC_SIGNAL_DEVIATION)){ // ZERO //check for buffer overflow if(_buffer_length >= SC_TOTAL_MESSAGE_SIZE){ _state = SC_STATE_ERROR_OVERFLOW; return; } //not overflow, continue _signal_state = SC_ZERO | SC_FOUND; _buffer[_buffer_length] &= ~(1 << _bit); //store value (bitwise AND + using NOT operator) if(_bit <= 0){ _bit = 7; //reset _buffer_length++; //new byte } else { _bit--; //decrease } } } else if((_previous_signal == LOW) && ((_signal_state & SC_FOUND) == 0)){ //found first signal _signal_state |= SC_FOUND; _elapsed_time = 0; //reset for next signal } else if((_previous_signal == HIGH) && (_signal_state & SC_FOUND)){ //store HIGH if already found something _signal[0] = _elapsed_time; //previous was HIGH _elapsed_time = 0; //reset for next signal } _previous_signal = signal; //update } } //end of WAIT NEXT CYCLE }