Exemplo n.º 1
0
static void on_session_established(const std::string& name, fscp::server& server, const fscp::server::ep_type& host, bool is_new, const fscp::cipher_suite_type& cs, const fscp::elliptic_curve_type& ec)
{
	mutex::scoped_lock lock(output_mutex);

	std::cout << "[" << name << "] Session established with " << host << std::endl;
	std::cout << "[" << name << "] New session: " << is_new << std::endl;
	std::cout << "[" << name << "] Cipher suite: " << cs << std::endl;
	std::cout << "[" << name << "] Elliptic curve: " << ec << std::endl;

	static const std::string HELLO = "Hello you !";

	server.async_send_data(host, fscp::CHANNEL_NUMBER_3, boost::asio::buffer(HELLO), boost::bind(&simple_handler, name, "async_send_data()", _1));

	if (name == "alice")
	{
		using cryptoplus::file;

		cryptoplus::x509::certificate cert = cryptoplus::x509::certificate::from_certificate(file::open("chris.crt", "r"));

		fscp::hash_list_type hash_list;
		hash_list.insert(fscp::get_certificate_hash(cert));

		server.async_send_contact_request(host, hash_list, boost::bind(&simple_handler, name, "async_send_contact_request()", _1));
	}
}
Exemplo n.º 2
0
static void on_data(const std::string& name, fscp::server& server, const fscp::server::ep_type& sender, fscp::channel_number_type channel_number, boost::asio::const_buffer data)
{
	const std::string str_data(boost::asio::buffer_cast<const char*>(data), boost::asio::buffer_size(data));

	std::cout << "[" << name << "] Received DATA on channel " << static_cast<unsigned int>(channel_number) << " from " << sender << ": " << str_data << std::endl;

	if (name == "alice")
	{
		if (str_data == "Hello ! I'm chris")
		{
			const std::string common_name = server.identity().signature_certificate().subject().find(NID_commonName)->data().str();
			const std::string new_common_name = "denis";

			if (common_name != new_common_name)
			{
				std::cout << "[" << name << "] My current name is " << common_name << ". Switching to " << new_common_name << "." << std::endl;

				server.set_identity(load_identity_store(new_common_name));
			}
		}
		else
		{
			using cryptoplus::file;

			cryptoplus::x509::certificate cert = cryptoplus::x509::certificate::from_certificate(file::open("chris.crt", "r"));

			server.async_send_contact_request(sender, cert);
		}
	}
}