Ejemplo n.º 1
0
		BundleFilter::ACTION SecurityFilter::evaluate(const FilterContext &context) const throw ()
		{
#ifdef IBRDTN_SUPPORT_BSP
			switch (_mode)
			{
				default:
					break;

				case VERIFY_AUTH:
				{
					try {
						// extract bundle from context
						const dtn::data::Bundle &bundle = context.getBundle();

						// check if at least one BAB is present
						if (std::count(bundle.begin(), bundle.end(), dtn::security::BundleAuthenticationBlock::BLOCK_TYPE) > 0)
						{
							if (_positive_action != BundleFilter::PASS) return _positive_action;
						}
						else
						{
							if (_negative_action != BundleFilter::PASS) return _negative_action;
						}
					} catch (const FilterException&) {
						// necessary bundle object is not present - abort the chain
						return BundleFilter::PASS;
					}
					break;
				}

				case VERIFY_INTEGRITY:
				{
					try {
						// extract bundle from context
						const dtn::data::Bundle &bundle = context.getBundle();

						// check if at least one PIB is present
						if (std::count(bundle.begin(), bundle.end(), dtn::security::PayloadIntegrityBlock::BLOCK_TYPE) > 0)
						{
							if (_positive_action != BundleFilter::PASS) return _positive_action;
						}
						else
						{
							if (_negative_action != BundleFilter::PASS) return _negative_action;
						}
					} catch (const FilterException&) {
						// necessary bundle object is not present - abort the chain
						return BundleFilter::PASS;
					}
					break;
				}

				case VERIFY_CONFIDENTIALITY:
				{
					try {
						// extract bundle from context
						const dtn::data::Bundle &bundle = context.getBundle();

						// check if at least one PCB is present
						if (std::count(bundle.begin(), bundle.end(), dtn::security::PayloadConfidentialBlock::BLOCK_TYPE) > 0)
						{
							if (_positive_action != BundleFilter::PASS) return _positive_action;
						}
						else
						{
							if (_negative_action != BundleFilter::PASS) return _negative_action;
						}
					} catch (const FilterException&) {
						// necessary bundle object is not present - abort the chain
						return BundleFilter::PASS;
					}
					break;
				}
			}
#else
			// without BSP support we can not execute any security check
			// therefore we always proceed as if the check were successful and
			// return with the positive action
			return _positive_action;
#endif

			// forward call to the next filter or return with the default action
			return BundleFilter::evaluate(context);
		}