void BundleAuthenticationBlock::verify(const dtn::data::Bundle& bundle, const dtn::security::SecurityKey &key, dtn::data::Number &correlator) throw (ibrcommon::Exception)
		{
			// get the blocks, with which the key should match
			std::set<dtn::data::Number> correlators;

			// calculate the MAC of this bundle
			std::string our_hash_string = calcMAC(bundle, key);

			dtn::data::Bundle::const_find_iterator it(bundle.begin(), BundleAuthenticationBlock::BLOCK_TYPE);
			while (it.next(bundle.end()))
			{
				const BundleAuthenticationBlock &bab = dynamic_cast<const BundleAuthenticationBlock&>(**it);

				// the bab contains a security result
				if (bab._ciphersuite_flags & CONTAINS_SECURITY_RESULT)
				{
					// is this correlator known?
					if (correlators.find(bab._correlator) == correlators.end()) continue;

					std::string bab_result = bab._security_result.get(SecurityBlock::integrity_signature);
					if (our_hash_string == bab_result)
					{
						// hash matched
						correlator = bab._correlator;
						return;
					}

					IBRCOMMON_LOGGER_DEBUG_TAG("BundleAuthenticationBlock", 15) << "security mac does not match" << IBRCOMMON_LOGGER_ENDL;
				}
				// bab contains no security result but a correlator
				else if (bab._ciphersuite_flags &  CONTAINS_CORRELATOR)
				{
					// currently we only support BAB_HMAC mechanism
					if (bab._ciphersuite_id != SecurityBlock::BAB_HMAC) continue;

					// skip this BAB if the security source do not match the key
					if (!bab.isSecuritySource(bundle, key.reference)) continue;

					// remember it for later check
					correlators.insert(bab._correlator);
				}
			}

			throw ibrcommon::Exception("verification failed");
		}
		void BundleAuthenticationBlock::auth(dtn::data::Bundle &bundle, const dtn::security::SecurityKey &key)
		{
			BundleAuthenticationBlock& bab_begin = bundle.push_front<BundleAuthenticationBlock>();
			bab_begin.set(dtn::data::Block::DISCARD_IF_NOT_PROCESSED, true);

			// set security source
			if (!key.reference.sameHost(bundle.source)) bab_begin.setSecuritySource( key.reference );

			dtn::data::Number correlator = createCorrelatorValue(bundle);
			bab_begin.setCorrelator(correlator);
			bab_begin.setCiphersuiteId(BAB_HMAC);

			BundleAuthenticationBlock& bab_end = bundle.push_back<BundleAuthenticationBlock>();
			bab_end.set(dtn::data::Block::DISCARD_IF_NOT_PROCESSED, true);

			bab_end.setCorrelator(correlator);
			bab_end._ciphersuite_flags |= CONTAINS_SECURITY_RESULT;

			std::string sizehash_hash = calcMAC(bundle, key);
			bab_end._security_result.set(SecurityBlock::integrity_signature, sizehash_hash);
		}
示例#3
0
void FPTWriter::flexSave( std::string filepath, ChunkChunkList * globalChunks )
{
  DEBUG << "saving " + filepath;

  ops::msole::FileWriter * writer = new ops::msole::FileWriter();
  writer->open( filepath );

  {
    int32_t handler = writer->fileOpen( "Future Pinball/File Version" );

    ChunkChunkList * chunks = (ChunkChunkList*)getChunkByLabel( globalChunks, CHUNK_FILE_VERSION.label );
    ChunkRawData * chunkRawData = (ChunkRawData*)getChunkByLabel( chunks, CHUNK_FILE_VERSION_DATA.label );
    writer->fileWrite( handler, &chunkRawData->value );

    writer->fileClose( handler );
  }
  {
    int32_t handler = writer->fileOpen( "Future Pinball/Table MAC" );

	#ifdef _WIN32
	ops::RawData dataMAC(16, true);
	calcMAC(globalChunks, dataMAC.data, dataMAC.len);
	writer->fileWrite( handler, &dataMAC );
    #else
    WARNING << "Can't rebuild table MAC"
	ChunkChunkList * chunks = (ChunkChunkList*)getChunkByLabel( globalChunks, CHUNK_TABLE_MAC.label );
    ChunkRawData * chunkRawData = (ChunkRawData*)getChunkByLabel( chunks, CHUNK_TABLE_MAC_DATA.label );
    writer->fileWrite( handler, &chunkRawData->value );
    #endif

    writer->fileClose( handler );
  }
  {
    int32_t handler = writer->fileOpen( "Future Pinball/Table Data" );

    ChunkChunkList * chunks = (ChunkChunkList*)getChunkByLabel( globalChunks, CHUNK_TABLE_DATA.label );
    saveChunk( writer, handler, chunks );

    writer->fileClose( handler );
  }
  {
    ChunkChunkList * chunksList = (ChunkChunkList*)getChunksByLabel( globalChunks, CHUNK_IMAGE.label );
    for( uint32_t i = 0; i < chunksList->value.size(); i++ )
    {
      ChunkChunkList * currentChunk = (ChunkChunkList *)chunksList->value[i];
      std::string name = "Future Pinball/Image ";
      std::stringstream ss;
      std::string number;
      ss << ( i + 1 );
      ss >> number;
      int32_t handler = writer->fileOpen( name + number );
      saveChunk( writer, handler, currentChunk );
      writer->fileClose( handler );
    }
  }
  {
    ChunkChunkList * chunksList = (ChunkChunkList*)getChunksByLabel( globalChunks, CHUNK_SOUND.label );
    for( uint32_t i = 0; i < chunksList->value.size(); i++ )
    {
      ChunkChunkList * currentChunk = (ChunkChunkList *)chunksList->value[i];
      std::string name = "Future Pinball/Sound ";
      std::stringstream ss;
      std::string number;
      ss << ( i + 1 );
      ss >> number;
      int32_t handler = writer->fileOpen( name + number );
      saveChunk( writer, handler, currentChunk );
      writer->fileClose( handler );
    }
  }
  {
    ChunkChunkList * chunksList = (ChunkChunkList*)getChunksByLabel( globalChunks, CHUNK_MUSIC.label );
    for( uint32_t i = 0; i < chunksList->value.size(); i++ )
    {
      ChunkChunkList * currentChunk = (ChunkChunkList *)chunksList->value[i];
      std::string name = "Future Pinball/Music ";
      std::stringstream ss;
      std::string number;
      ss << ( i + 1 );
      ss >> number;
      int32_t handler = writer->fileOpen( name + number );
      saveChunk( writer, handler, currentChunk );
      writer->fileClose( handler );
    }
  }
  {
    ChunkChunkList * chunksList = (ChunkChunkList*)getChunksByLabel( globalChunks, CHUNK_DMDFONT.label );
    for( uint32_t i = 0; i < chunksList->value.size(); i++ )
    {
      ChunkChunkList * currentChunk = (ChunkChunkList *)chunksList->value[i];
      std::string name = "Future Pinball/DmdFont ";
      std::stringstream ss;
      std::string number;
      ss << ( i + 1 );
      ss >> number;
      int32_t handler = writer->fileOpen( name + number );
      saveChunk( writer, handler, currentChunk );
      writer->fileClose( handler );
    }
  }
  {
    ChunkChunkList * chunksList = (ChunkChunkList*)getChunksByLabel( globalChunks, CHUNK_PINMODEL.label );
    for( uint32_t i = 0; i < chunksList->value.size(); i++ )
    {
      ChunkChunkList * currentChunk = (ChunkChunkList *)chunksList->value[i];

      std::string name = "Future Pinball/PinModel ";
      std::stringstream ss;
      std::string number;
      ss << ( i + 1 );
      ss >> number;
      int32_t handler = writer->fileOpen( name + number );
      saveChunk( writer, handler, currentChunk );
      writer->fileClose( handler );

    }
  }
  {
    ChunkChunkList * chunksList = (ChunkChunkList*)getChunksByLabel( globalChunks, CHUNK_IMAGELIST.label );
    for( uint32_t i = 0; i < chunksList->value.size(); i++ )
    {
      ChunkChunkList * currentChunk = (ChunkChunkList *)chunksList->value[i];
      std::string name = "Future Pinball/ImageList ";
      std::stringstream ss;
      std::string number;
      ss << ( i + 1 );
      ss >> number;
      int32_t handler = writer->fileOpen( name + number );
      saveChunk( writer, handler, currentChunk );
      writer->fileClose( handler );
    }
  }
  {
    ChunkChunkList * chunksList = (ChunkChunkList*)getChunksByLabel( globalChunks, CHUNK_LIGHTLIST.label );
    for( uint32_t i = 0; i < chunksList->value.size(); i++ )
    {
      ChunkChunkList * currentChunk = (ChunkChunkList *)chunksList->value[i];
      std::string name = "Future Pinball/LightList ";
      std::stringstream ss;
      std::string number;
      ss << ( i + 1 );
      ss >> number;
      int32_t handler = writer->fileOpen( name + number );
      saveChunk( writer, handler, currentChunk );
      writer->fileClose( handler );
    }
  }

  {
    ChunkChunkList * chunksList = (ChunkChunkList*)getChunksByLabel( globalChunks, CHUNK_TABLE_ELEMENT.label );
    for( uint32_t i = 0; i < chunksList->value.size(); i++ )
    {
      ChunkChunkList * currentChunk = (ChunkChunkList *)chunksList->value[i];
      std::string name = "Future Pinball/Table Element ";
      std::stringstream ss;
      std::string number;
      ss << ( i + 1 );
      ss >> number;
      int32_t handler = writer->fileOpen( name + number );
      saveChunk( writer, handler, currentChunk );
      writer->fileClose( handler );
    }
  }

  writer->close();
  DEBUG << filepath + " saved";
}