Beispiel #1
0
void IoTService::authenticateMessage(boost::asio::ip::address_v6 senderAddress, std::vector<uint8_t> data, ec taKey) {
	LOG(INFO) << "CBOR decode message...";

	Signature sig;
	std::vector<uint8_t> message;
	std::array<uint8_t, 16> senderBytes = senderAddress.to_bytes();
	std::vector<uint8_t> senderBytesVec(senderBytes.begin(), senderBytes.end());

	struct cbor_load_result result;
	cbor_item_t* item = cbor_load(data.data(), data.size(), &result);
	size_t pairs = cbor_map_size(item);
	for (cbor_pair* pair = cbor_map_handle(item); pairs > 0; pair++, pairs--) {
		if (strncmp(reinterpret_cast<char*>(cbor_string_handle(pair->key)), "sig", 3) == 0) {
			sig = Signature::fromCBORArray(pair->value);
		}
		else if (strncmp(reinterpret_cast<char*>(cbor_string_handle(pair->key)), "msg", 3) == 0) {
			size_t length = cbor_bytestring_length(pair->value);
			message = std::vector<uint8_t>(cbor_bytestring_handle(pair->value), cbor_bytestring_handle(pair->value) + length);
		}
	}
	LOG(INFO) << "Authenticating message...";
	bool sigCorrect = Signature::verify(senderBytesVec, message, taKey.p, sig);
	if (sigCorrect) {
		LOG(INFO) << "Signature correct:	msg: " << byteVecToStr(message);
	}
	else {
		LOG(INFO) << "Signature invalid.";
	}
}
Beispiel #2
0
void HBAOutput::print_ipv6address(boost::asio::ip::address_v6 addr, std::ostream& ostr) {
  boost::array<unsigned char, 16> addr_bytes = addr.to_bytes();
  for(unsigned int i = 0; i < 16; i++) {
    if(!(i % 2) && i)
      ostr<<":";
    ostr << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)addr_bytes[i];
  }
}
Beispiel #3
0
void compute_ipv6_subnet(boost::asio::ip::address_v6 netAddr,
                         uint8_t prefixLen,
                         /* out */ struct in6_addr* mask,
                         /* out */ struct in6_addr* addr) {
    std::memcpy(addr, netAddr.to_bytes().data(), sizeof(struct in6_addr));
    get_subnet_mask_v6(prefixLen, mask);
    ((uint64_t*)addr)[0] &= ((uint64_t*)mask)[0];
    ((uint64_t*)addr)[1] &= ((uint64_t*)mask)[1];

}
Beispiel #4
0
void construct_auto_ip(boost::asio::ip::address_v6 prefix,
                       const uint8_t* srcMac,
                       /* out */ struct in6_addr* dstAddr) {
    address_v6::bytes_type prefixb = prefix.to_bytes();
    memset(dstAddr, 0, sizeof(struct in6_addr));
    memcpy((char*)dstAddr, prefixb.data(), 8);
    memcpy(((char*)dstAddr) + 8, srcMac, 3);
    ((char*)dstAddr)[8] ^= 0x02;
    ((char*)dstAddr)[11] = 0xff;
    ((char*)dstAddr)[12] = 0xfe;
    memcpy(((char*)dstAddr) + 13, srcMac+3, 3);
}
Beispiel #5
0
//	////////////////////////////////////////////////////////////////////////////
HostEntry HostAddressToEntry(const boost::asio::ip::address_v6 &host_address)
{

	return(HostAddressToEntry(host_address.to_bytes().data(),
		sizeof(boost::asio::ip::address_v6::bytes_type), AF_INET6));
}
Beispiel #6
0
				/**
				 * \brief Set the target address.
				 * \param _target The target address.
				 */
				void set_target(const boost::asio::ip::address_v6& _target) const
				{
					std::memcpy(this->frame().target.s6_addr, _target.to_bytes().data(), _target.to_bytes().size());
				}
Beispiel #7
0
static inline void fill_in6_addr(struct in6_addr& addr,
                                 const boost::asio::ip::address_v6& ip) {
    boost::asio::ip::address_v6::bytes_type bytes = ip.to_bytes();
    std::memcpy(&addr, bytes.data(), bytes.size());
}