summaryrefslogtreecommitdiffstats
path: root/libtransport/src
diff options
context:
space:
mode:
authorAlberto Compagno <acompagn+fdio@cisco.com>2019-02-07 13:12:19 +0100
committerAlberto Compagno <acompagn+fdio@cisco.com>2019-02-07 13:15:40 +0000
commitdb1afad8749fce983636456c16c9df9c24d73af4 (patch)
treed78492674a1fbc5b923941991542d8115e11493d /libtransport/src
parent216e35ba535efa00af39b7624f363ca832836e3f (diff)
[HICN-39] Added api that return a pointer to the signature hold in a packet
[HICN-40] Fixed signature calculation by allocating a contiguous portion of memory that holds the entire hICN header (IP+TCP+AH) Change-Id: I9d40bab0e3ecb82949b8b3a00e2cc1214457e4e3 Signed-off-by: Alberto Compagno <acompagn+fdio@cisco.com>
Diffstat (limited to 'libtransport/src')
-rw-r--r--libtransport/src/hicn/transport/core/packet.cc30
-rw-r--r--libtransport/src/hicn/transport/core/packet.h2
-rw-r--r--libtransport/src/hicn/transport/http/server_acceptor.cc2
-rw-r--r--libtransport/src/hicn/transport/http/server_acceptor.h2
-rw-r--r--libtransport/src/hicn/transport/interfaces/socket.h5
-rw-r--r--libtransport/src/hicn/transport/interfaces/socket_producer.cc2
-rw-r--r--libtransport/src/hicn/transport/interfaces/socket_producer.h6
-rw-r--r--libtransport/src/hicn/transport/utils/signer.cc44
-rw-r--r--libtransport/src/hicn/transport/utils/signer.h2
9 files changed, 39 insertions, 56 deletions
diff --git a/libtransport/src/hicn/transport/core/packet.cc b/libtransport/src/hicn/transport/core/packet.cc
index dd150d723..3872510ec 100644
--- a/libtransport/src/hicn/transport/core/packet.cc
+++ b/libtransport/src/hicn/transport/core/packet.cc
@@ -32,7 +32,7 @@ namespace core {
const core::Name Packet::base_name("0::0|0");
Packet::Packet(Format format)
- : packet_(utils::MemBuf::create(getHeaderSizeFromFormat(format)).release()),
+ : packet_(utils::MemBuf::create(getHeaderSizeFromFormat(format, 256)).release()),
packet_start_(packet_->writableData()),
header_head_(packet_.get()),
payload_head_(nullptr),
@@ -50,28 +50,22 @@ Packet::Packet(MemBufPtr &&buffer)
header_head_(packet_.get()),
payload_head_(nullptr),
format_(getFormatFromBuffer(packet_start_)) {
- auto header_size = getHeaderSizeFromFormat(format_);
- int signature_size = 0;
+ int signature_size = 0;
if (_is_ah(format_)) {
signature_size = getSignatureSize();
}
+ auto header_size = getHeaderSizeFromFormat(format_, signature_size);
+
auto payload_length = packet_->length() - header_size - signature_size;
- if (!payload_length && !signature_size) {
+ if (!payload_length) {
return;
}
packet_->trimEnd(packet_->length());
- if (signature_size) {
- auto sig = packet_->cloneOne();
- sig->advance(header_size);
- sig->append(signature_size);
- packet_->appendChain(std::move(sig));
- }
-
if (payload_length) {
auto payload = packet_->cloneOne();
payload_head_ = payload.get();
@@ -285,6 +279,20 @@ void Packet::setSignatureSize(std::size_t size_bytes) {
if (ret < 0) {
throw errors::RuntimeException("Packet without Authentication Header.");
}
+
+ packet_->append(size_bytes);
+}
+
+uint8_t * Packet::getSignature() const {
+ uint8_t * signature;
+ int ret = hicn_packet_get_signature(
+ format_, (hicn_header_t *)packet_start_, &signature);
+
+ if (ret < 0) {
+ throw errors::RuntimeException("Packet without Authentication Header.");
+ }
+
+ return signature;
}
std::size_t Packet::getSignatureSize() const {
diff --git a/libtransport/src/hicn/transport/core/packet.h b/libtransport/src/hicn/transport/core/packet.h
index bc23588dc..038676540 100644
--- a/libtransport/src/hicn/transport/core/packet.h
+++ b/libtransport/src/hicn/transport/core/packet.h
@@ -133,6 +133,8 @@ class Packet : public std::enable_shared_from_this<Packet> {
std::size_t getSignatureSize() const;
+ uint8_t * getSignature() const;
+
void setSignatureTimestamp(const uint64_t &timestamp);
uint64_t getSignatureTimestamp() const;
diff --git a/libtransport/src/hicn/transport/http/server_acceptor.cc b/libtransport/src/hicn/transport/http/server_acceptor.cc
index 717dfb642..615fa80d8 100644
--- a/libtransport/src/hicn/transport/http/server_acceptor.cc
+++ b/libtransport/src/hicn/transport/http/server_acceptor.cc
@@ -83,7 +83,7 @@ void HTTPServerAcceptor::listen(bool async) {
}
void HTTPServerAcceptor::processIncomingInterest(ProducerSocket &p,
- const Interest &interest) {
+ Interest &interest) {
// Temporary solution. With
utils::Array<uint8_t> payload = interest.getPayload();
diff --git a/libtransport/src/hicn/transport/http/server_acceptor.h b/libtransport/src/hicn/transport/http/server_acceptor.h
index 549962414..99480028a 100644
--- a/libtransport/src/hicn/transport/http/server_acceptor.h
+++ b/libtransport/src/hicn/transport/http/server_acceptor.h
@@ -48,7 +48,7 @@ class HTTPServerAcceptor {
// HTTPResponse&& response();
private:
- void processIncomingInterest(ProducerSocket &p, const Interest &interest);
+ void processIncomingInterest(ProducerSocket &p, Interest &interest);
OnHttpRequest callback_;
asio::io_service io_service_;
diff --git a/libtransport/src/hicn/transport/interfaces/socket.h b/libtransport/src/hicn/transport/interfaces/socket.h
index 22757810a..14ef86422 100644
--- a/libtransport/src/hicn/transport/interfaces/socket.h
+++ b/libtransport/src/hicn/transport/interfaces/socket.h
@@ -104,10 +104,7 @@ using ProducerContentObjectCallback =
std::function<void(ProducerSocket &, core::ContentObject &)>;
using ProducerInterestCallback =
- std::function<void(ProducerSocket &, const core::Interest &)>;
-
-using ProducerInterestCallback =
- std::function<void(ProducerSocket &, const core::Interest &)>;
+ std::function<void(ProducerSocket &, core::Interest &)>;
using namespace protocol;
diff --git a/libtransport/src/hicn/transport/interfaces/socket_producer.cc b/libtransport/src/hicn/transport/interfaces/socket_producer.cc
index 5bd522faf..ab9de4a95 100644
--- a/libtransport/src/hicn/transport/interfaces/socket_producer.cc
+++ b/libtransport/src/hicn/transport/interfaces/socket_producer.cc
@@ -401,7 +401,7 @@ void ProducerSocket::asyncProduce(
}
}
-void ProducerSocket::onInterest(const Interest &interest) {
+void ProducerSocket::onInterest(Interest &interest) {
if (on_interest_input_ != VOID_HANDLER) {
on_interest_input_(*this, interest);
}
diff --git a/libtransport/src/hicn/transport/interfaces/socket_producer.h b/libtransport/src/hicn/transport/interfaces/socket_producer.h
index 06c47d973..bd7d3f35f 100644
--- a/libtransport/src/hicn/transport/interfaces/socket_producer.h
+++ b/libtransport/src/hicn/transport/interfaces/socket_producer.h
@@ -69,7 +69,7 @@ class ProducerSocket : public Socket<BasePortal>,
asio::io_service &getIoService() override;
- virtual void onInterest(const Interest &interest);
+ virtual void onInterest(Interest &interest);
virtual void onInterest(Interest::Ptr &&interest) override {
onInterest(*interest);
@@ -206,6 +206,8 @@ class ProducerSocket : public Socket<BasePortal>,
// buffers
utils::ContentStore output_buffer_;
+ std::unique_ptr<utils::Identity> identity_;
+
private:
utils::EventThread async_thread_;
@@ -221,7 +223,7 @@ class ProducerSocket : public Socket<BasePortal>,
HashAlgorithm hash_algorithm_;
utils::CryptoSuite crypto_suite_;
- std::unique_ptr<utils::Identity> identity_;
+ //std::unique_ptr<utils::Identity> identity_;
// utils::Signer& signer_;
// buffers
diff --git a/libtransport/src/hicn/transport/utils/signer.cc b/libtransport/src/hicn/transport/utils/signer.cc
index 005236c2e..9c06a051c 100644
--- a/libtransport/src/hicn/transport/utils/signer.cc
+++ b/libtransport/src/hicn/transport/utils/signer.cc
@@ -76,10 +76,10 @@ Signer::~Signer() {
}
void Signer::sign(Packet &packet) {
- // header chain points to the IP + TCP hicn header
+ // header chain points to the IP + TCP hicn header + AH Header
utils::MemBuf *header_chain = packet.header_head_;
utils::MemBuf *payload_chain = packet.payload_head_;
- uint8_t *hicn_packet = header_chain->writableData();
+ uint8_t *hicn_packet = (uint8_t *)header_chain->writableData();
Packet::Format format = packet.getFormat();
std::size_t sign_len_bytes = parcSigner_GetSignatureSize(signer_);
@@ -98,35 +98,26 @@ void Signer::sign(Packet &packet) {
std::size_t header_len = Packet::getHeaderSizeFromFormat(format);
packet.resetForHash();
- packet.setSignatureSize(sign_len_bytes);
/* Fill the hicn_ah header */
using namespace std::chrono;
auto now = duration_cast<milliseconds>(system_clock::now().time_since_epoch())
.count();
packet.setSignatureTimestamp(now);
- // *reinterpret_cast<uint64_t*>(ah->signTime) = utils::hton<uint64_t>(now);
- // // std::memcpy(&ah->hicn_ah.signTime, &sign_time,
- // sizeof(ah->hicn_ah.signTime));
packet.setValidationAlgorithm(
CryptoSuite(parcSigner_GetCryptoSuite(this->signer_)));
- // ah->validationAlgorithm = parcSigner_GetCryptoSuite(this->signer_);
KeyId key_id;
key_id.first = (uint8_t *)parcBuffer_Overlay(
(PARCBuffer *)parcKeyId_GetKeyId(this->key_id_), 0);
packet.setKeyId(key_id);
- // memcpy(ah->keyId,
- // parcBuffer_Overlay((PARCBuffer *) parcKeyId_GetKeyId(this->key_id_),
- // 0), sizeof(_ah_header_t::keyId));
-
// Calculate hash
utils::CryptoHasher hasher(parcSigner_GetCryptoHasher(signer_));
hasher.init();
- hasher.updateBytes(hicn_packet, header_len);
- hasher.updateBytes(zeros, sign_len_bytes);
+ hasher.updateBytes(hicn_packet, header_len + sign_len_bytes);
+ //hasher.updateBytes(zeros, sign_len_bytes);
for (utils::MemBuf *current = payload_chain; current != header_chain;
current = current->next()) {
@@ -135,11 +126,8 @@ void Signer::sign(Packet &packet) {
utils::CryptoHash hash = hasher.finalize();
- PARCSignature *signature = parcSigner_SignDigest(this->signer_, hash.hash_);
+ PARCSignature *signature = parcSigner_SignDigest(this->signer_, hash.hash_, packet.getSignature(), sign_len_bytes);
PARCBuffer *buffer = parcSignature_GetSignature(signature);
-
- PARCByteArray *byte_array = parcBuffer_Array(buffer);
- uint8_t *bytes = parcByteArray_Array(byte_array);
size_t bytes_len = parcBuffer_Remaining(buffer);
if (bytes_len > sign_len_bytes) {
@@ -153,26 +141,10 @@ void Signer::sign(Packet &packet) {
memcpy(hicn_packet, &header_copy, sizeof(hicn_v6_hdr_t));
}
- int offset = sign_len_bytes - bytes_len;
-
- std::unique_ptr<utils::MemBuf> signature_buffer;
- std::unique_ptr<utils::MemBuf> tmp_buf = utils::MemBuf::takeOwnership(
- bytes, bytes_len, bytes_len,
- [](void *buf, void *userData) {
- parcSignature_Release((PARCSignature **)&userData);
- },
- signature, true);
-
- if (offset) {
- signature_buffer = utils::MemBuf::create(offset);
- memset(signature_buffer->writableData(), 0, offset);
- signature_buffer->append(offset);
- signature_buffer->appendChain(std::move(tmp_buf));
- } else {
- signature_buffer = std::move(tmp_buf);
- }
+}
- packet.setSignature(std::move(signature_buffer));
+PARCKeyStore * Signer::getKeyStore() {
+ return parcSigner_GetKeyStore(this->signer_);
}
} // namespace utils
diff --git a/libtransport/src/hicn/transport/utils/signer.h b/libtransport/src/hicn/transport/utils/signer.h
index 7b54b63c8..10b1bfe8c 100644
--- a/libtransport/src/hicn/transport/utils/signer.h
+++ b/libtransport/src/hicn/transport/utils/signer.h
@@ -60,6 +60,8 @@ class Signer {
*/
void sign(Packet &packet);
+ PARCKeyStore * getKeyStore();
+
private:
PARCSigner *signer_;
PARCKeyId *key_id_;