A Discrete-Event Network Simulator
API
qkd-app-014.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 DOTFEESA www.tk.etf.unsa.ba
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Emir Dervisevic <emir.dervisevic@etf.unsa.ba>
19  * Miralem Mehic <miralem.mehic@ieee.org>
20  */
21 
22 #include "ns3/address.h"
23 #include "ns3/address-utils.h"
24 #include "ns3/log.h"
25 #include "ns3/inet-socket-address.h"
26 #include "ns3/inet6-socket-address.h"
27 #include "ns3/node.h"
28 #include "ns3/socket.h"
29 #include "ns3/udp-socket-factory.h"
30 #include "ns3/tcp-socket-factory.h"
31 #include "ns3/simulator.h"
32 #include "ns3/socket-factory.h"
33 #include "ns3/packet.h"
34 #include "ns3/trace-source-accessor.h"
35 #include "qkd-app-014.h"
36 
37 namespace ns3 {
38 
39 NS_LOG_COMPONENT_DEFINE ("QKDApp014");
40 
41 NS_OBJECT_ENSURE_REGISTERED (QKDApp014);
42 
43 TypeId
45 {
46  static TypeId tid = TypeId ("ns3::QKDApp014")
48  .SetGroupName("Applications")
49  .AddConstructor<QKDApp014> ()
50  .AddAttribute ("Protocol", "The type of protocol to use.",
54  .AddAttribute ("NumberOfKeyToFetchFromKMS",
55  "The total number of keys per request to LKMS (ESTI QKD 014)",
56  UintegerValue (3),
58  MakeUintegerChecker<uint32_t> ())
59  .AddAttribute ("LengthOfAuthenticationTag",
60  "The default length of the authentication tag",
61  UintegerValue (256), //32 bytes
63  MakeUintegerChecker<uint32_t> ())
64  .AddAttribute ("EncryptionType",
65  "The type of encryption to be used (0-unencrypted, 1-OTP, 2-AES)",
66  UintegerValue (1),
68  MakeUintegerChecker<uint32_t> ())
69  .AddAttribute ("AuthenticationType",
70  "The type of authentication to be used (0-unauthenticated, 1-VMAC, 2-MD5, 3-SHA1)",
71  UintegerValue (2),
73  MakeUintegerChecker<uint32_t> ())
74  .AddAttribute ("AESLifetime",
75  "Lifetime of AES key expressed in bytes",
76  UintegerValue (1),
78  MakeUintegerChecker<uint64_t> ())
79  .AddAttribute ("UseCrypto",
80  "Should crypto functions be performed (0-No, 1-Yes)",
81  UintegerValue (0),
83  MakeUintegerChecker<uint32_t> ())
84  .AddAttribute ("WaitInsufficient","Penalty time (in seconds) when there is insufficient amount of key",
85  TimeValue (Seconds (0.3)),
87  MakeTimeChecker ())
88  .AddAttribute ("WaitTransform","Penalty time (in seconds) when keys are being transformed",
89  TimeValue (Seconds (0.05)),
91  MakeTimeChecker ())
92 
93  .AddTraceSource ("Tx", "A new packet is created and is sent",
95  "ns3::Packet::TracedCallback")
96  .AddTraceSource ("TxSig", "A new signaling packet is created and is sent",
98  "ns3::Packet::TracedCallback")
99  .AddTraceSource ("TxKMS", "A new packet is created and is sent to local KMS",
101  "ns3::Packet::TracedCallback")
102  .AddTraceSource ("Rx", "A new packet is received",
104  "ns3::Packet::TracedCallback")
105  .AddTraceSource ("RxSig", "A new signaling packet is received",
107  "ns3::Packet::TracedCallback")
108  .AddTraceSource ("RxKMS", "A new packet is received from local KMS",
110  "ns3::Packet::TracedCallback")
111  .AddTraceSource ("StateTransition",
112  "Trace fired upon every QKDApp014 state transition.",
114  "ns3::Application::StateTransitionCallback")
115  .AddTraceSource ("PacketEncrypted",
116  "The change trance for currenly ecrypted packet",
118  "ns3::QKDCrypto::PacketEncrypted")
119  .AddTraceSource ("PacketDecrypted",
120  "The change trance for currenly decrypted packet",
122  "ns3::QKDCrypto::PacketDecrypted")
123  .AddTraceSource ("PacketAuthenticated",
124  "The change trance for currenly authenticated packet",
126  "ns3::QKDCrypto::PacketAuthenticated")
127  .AddTraceSource ("PacketDeAuthenticated",
128  "The change trance for currenly deauthenticated packet",
130  "ns3::QKDCrypto::PacketDeAuthenticated")
131  .AddTraceSource ("Mx", "Missed send packet call",
133  "ns3::Packet::TracedCallback")
134  .AddTraceSource ("KeyObtained", "Trace amount of obtained key material",
136  "ns3::QKDApp014::KeyObtained")
137  ;
138 
139  return tid;
140 }
141 //@toDo: add use fallback to AES when OTP is used (Y/N)
142 
143 uint32_t QKDApp014::m_applicationCounts = 0;
144 
154  : m_sendSignalingSocketApp (0),
155  m_sinkSignalingSocketApp (0),
156  m_sendDataSocketApp (0),
157  m_sinkDataSocketApp (0),
158  m_sendSocketToKMS (0),
159  m_sinkSocketFromKMS (0),
160  m_packetSize (0),
161  m_dataRate (0),
162  m_sendEvent (),
163  m_packetsSent (0),
164  m_dataSent (0),
165  m_master (0),
166  m_encryptor (0),
167  m_appState (NOT_STARTED)
168 {
170  m_id = UUID::Random();
171  m_random = CreateObject<UniformRandomVariable> ();
172 
174  {"NOT_STARTED", "INITIALIZED"},
175  {"INITIALIZED", "WAIT"},
176  {"INITIALIZED", "READY"},
177  {"WAIT", "READY"},
178  {"READY", "WAIT"},
179  {"READY", "SEND_DATA"},
180  {"SEND_DATA", "READY"},
181  {"READY", "DECRYPT_DATA"},
182  {"DECRYPT_DATA", "READY"},
183  {"DECRYPT_DATA", "STOPPED"},
184  {"SEND_DATA", "STOPPED"},
185  {"READY", "STOPPED"},
186  {"WAIT", "STOPPED"},
187  };
188 }
189 
191 {
192  //Data sockets
195  //Signaling sockets
198  //KMS sockets
199  m_sendSocketToKMS = 0;
201 }
202 
203 void
205  std::string socketType,
206  Address src,
207  Address dst,
208  Address kms,
209  UUID dstSaeId,
210  std::string type
211 ){
212  Setup(
213  socketType,
214  src,
215  dst,
216  kms,
217  dstSaeId,
218  0,
219  0,
220  DataRate ("0bps"),
221  type
222  );
223 }
224 
225 void
227  std::string socketType,
228  Address src,
229  Address dst,
230  Address kms,
231  UUID dstSaeId,
232  uint32_t packetSize,
233  uint32_t nPacketsSize,
234  DataRate dataRate,
235  std::string type
236 ){
237 
238  NS_LOG_FUNCTION (this << m_appState);
239 
240  if(type == "alice"){
241  m_master = 1;
242  }else{
243  m_master = 0;
244  }
245 
246  m_local = src;
247  m_peer = dst;
248  m_kms = kms;
249 
253  );
257  );
258 
259  m_dstSaeId = dstSaeId;
261  m_dataRate = dataRate;
262  m_socketType = socketType;
263 
264  m_internalAppWait = false; //No longer wait schedule required!
265  InitializeAppKeyBuffer (); //Setup application key buffer!
267 }
268 
269 
270 
278 void
280 {
281  NS_LOG_FUNCTION (this << m_appState);
282 
284  {
285  NS_LOG_FUNCTION (this << "QKDApp014 is running!");
286  double delay = m_packetSize * 8 / static_cast<double> (m_dataRate.GetBitRate ());
287  NS_LOG_FUNCTION( this << "delay" << Seconds (delay) );
288  Time tNext (Seconds (delay));
290 
291  } else
292  NS_LOG_FUNCTION (this << "QKDApp014 is" << GetAppStateString(m_appState));
293 }
294 
295 uint32_t
296 QKDApp014::ScheduleAction(Time t, std::string action)
297 {
298  NS_LOG_FUNCTION( this << action << t );
299  uint32_t scheduleID {0};
300  EventId event;
301  if(action == "CheckAppBufferState"){
302  if(m_internalAppWait == false){
303  m_internalAppWait = true;
305  scheduleID = event.GetUid();
306  m_scheduledEvents.insert( std::make_pair( scheduleID , event) );
307  NS_LOG_FUNCTION(this << "Event successfully scheduled!");
308  }else{
309  NS_LOG_FUNCTION(this << "Scheduled event already exists!");
310  }
311  }else
312  NS_FATAL_ERROR( this << "Invalid action" << action );
313 
314  return scheduleID;
315 }
316 
317 void
319 {
320  NS_LOG_FUNCTION(this << eventId);
321 
322  std::map<uint32_t, EventId >::iterator eventEntry = m_scheduledEvents.find ( eventId );
323  if(eventEntry != m_scheduledEvents.end ()){
324  Simulator::Cancel (eventEntry->second);
325  }else{
326  NS_FATAL_ERROR ("Invalid entryId " << eventId );
327  }
328 
329 }
330 
331 
339 void
341 {
342 
343  NS_LOG_FUNCTION(this);
344 
345  if(m_sinkSocketFromKMS == 0){
346  Address localAddress = InetSocketAddress(
347  //InetSocketAddress::ConvertFrom(m_kms).GetIpv4 (),
349  82//InetSocketAddress::ConvertFrom(m_kms).GetPort ()
350  );
352 
353  if (m_sinkSocketFromKMS->Bind (localAddress) == -1)
354  NS_FATAL_ERROR ("Failed to bind socket");
355 
362  );
366  );
367  NS_LOG_FUNCTION (this << "Create new APP socket " << m_sinkSocketFromKMS
368  << " to listen packets from KMS on " << InetSocketAddress::ConvertFrom(localAddress).GetIpv4 ()
369  << " and port " << 82//InetSocketAddress::ConvertFrom(localAddress).GetPort ()
370  );
371  }else{
372  NS_LOG_FUNCTION (this << "Socket to listen from local KMS exists!" << m_sinkSocketFromKMS);
373  }
374 
375 }
376 
377 void
379 {
380  NS_LOG_FUNCTION(this);
381 
382  if(m_sendSocketToKMS == 0){
383  Address lkmsAddress = InetSocketAddress(
386  );
395  m_sendSocketToKMS->Connect ( lkmsAddress );
396  NS_LOG_FUNCTION (this << "Create new APP socket " << m_sendSocketToKMS << " to reach local KMS!");
397  }else{
398  NS_LOG_FUNCTION (this << "Socket to reach local KMS exists!" << m_sendSocketToKMS);
399  }
400 
401 }
402 
403 void
405 {
407 
409 
410  if(m_sendSignalingSocketApp == 0){
411 
412  if(m_socketType == "tcp"){
414  }else{
416  }
417 
423  }
424 
425  if(m_sendDataSocketApp == 0){
426 
427  if(m_socketType == "tcp"){
429  }else{
431  }
432 
438  }
439 
440  }else{
441  NS_LOG_FUNCTION (this << "Socket to reach peer app exists!" << m_sendSignalingSocketApp);
442  }
443 }
444 
445 void
447 {
448  NS_LOG_FUNCTION(this << GetNode()->GetId() << m_socketType );
449 
450  if(m_sinkSignalingSocketApp == 0){
451 
452  if(m_socketType == "tcp") {
454  } else {
456  }
457 
459  NS_FATAL_ERROR ("Failed to bind socket");
460 
465  MakeNullCallback<bool, Ptr<Socket>, const Address &> (),
467  );
471  );
472 
473  }else{
474  NS_LOG_FUNCTION (this << "Socket to listen signaling from peer app exists!" << m_sinkSignalingSocketApp);
475  }
476 
477 
478  if(m_sinkDataSocketApp == 0){
479 
480  if(m_socketType == "tcp")
482  else
484 
485  if (m_sinkDataSocketApp->Bind (m_local) == -1)
486  NS_FATAL_ERROR ("Failed to bind socket");
487 
492  MakeNullCallback<bool, Ptr<Socket>, const Address &> (),
494  );
498  );
499  }else{
500  NS_LOG_FUNCTION (this << "Socket to listen data from peer app exists!" << m_sinkSignalingSocketApp);
501  }
502 
503 }
504 
505 bool
507 {
508  NS_LOG_FUNCTION (this << socket << from
509  << InetSocketAddress::ConvertFrom(from).GetIpv4 ()
510  << InetSocketAddress::ConvertFrom(from).GetPort ()
511  );
512  NS_LOG_FUNCTION (this << "QKDApp014 Connection from KMS requested on socket " << socket);
513  return true; // Unconditionally accept the connection request.
514 
515 }
516 
517 void
519 {
520  Address peer;
521  NS_LOG_FUNCTION (this << socket << from
522  << InetSocketAddress::ConvertFrom(from).GetIpv4 ()
523  << InetSocketAddress::ConvertFrom(from).GetPort ()
524  );
525  NS_LOG_FUNCTION (this << "QKDApp014 Connection from KMS accepted on socket " << socket);
527 }
528 
529 void
531 {
532  NS_LOG_FUNCTION (this << s << from
533  << InetSocketAddress::ConvertFrom(from).GetIpv4 ()
534  << InetSocketAddress::ConvertFrom(from).GetPort ()
535  );
536 
537  NS_LOG_FUNCTION (this << "QKDApp014 Connection from APP accepted on socket " << s);
539 }
540 
541 void
543 {
544  NS_LOG_FUNCTION (this << s << from
545  << InetSocketAddress::ConvertFrom(from).GetIpv4 ()
546  << InetSocketAddress::ConvertFrom(from).GetPort ()
547  );
548 
549  NS_LOG_FUNCTION (this << "QKDApp014 Signaling Connection from APP accepted on socket " << s);
551 }
552 
553 void
555 {
556  NS_LOG_FUNCTION (this << socket << "QKDApp014 Connection to KMS succeeded via socket " << socket);
557 }
558 
559 void
561 {
562  NS_LOG_FUNCTION (this << socket << "QKDApp014, Connection to KMS Failed via socket " << socket);
563 }
564 
565 void
567 {
568  NS_LOG_FUNCTION (this << socket << "QKDApp014 Connection to APP succeeded via socket " << socket);
569 }
570 
571 void
573 {
574  NS_LOG_FUNCTION (this << socket << "QKDApp014, Connection to APP Failed via socket " << socket);
575 }
576 
577 void
579 {
580  NS_LOG_FUNCTION (this << socket << "QKDApp014 Signaling Connection to APP succeeded via socket " << socket);
581 }
582 
583 void
585 {
586  NS_LOG_FUNCTION (this << socket << "QKDApp014, Connection to APP Failed via socket " << socket);
587 }
588 
589 void
591 {
592  NS_LOG_FUNCTION (this << socket);
593 }
594 
595 void
597 {
598  NS_LOG_FUNCTION (this << socket);
599 }
600 
601 void
603 {
604  NS_LOG_FUNCTION (this << socket);
605 }
606 void
608 {
609  NS_LOG_FUNCTION (this << socket);
610 }
611 
612 void
614 {
615  NS_LOG_FUNCTION (this << socket);
616 }
617 
618 void
620 {
621  NS_LOG_FUNCTION (this << socket);
622 }
623 
624 void
626 {
627  NS_LOG_FUNCTION (this << socket);
628 
629  Ptr<Packet> packet;
630  Address from;
631  while ((packet = socket->RecvFrom (from)))
632  {
633  if (packet->GetSize () == 0)
634  { //EOF
635  break;
636  }
637 
638  NS_LOG_FUNCTION (this
639  << packet << "PACKETID: " << packet->GetUid()
640  << " of size: " << packet->GetSize()
641  );
642 
644  {
645  NS_LOG_FUNCTION("At time " << Simulator::Now ().GetSeconds ()
646  << "s packet from KMS received "
647  << packet->GetSize () << " bytes from "
649  << " port " << InetSocketAddress::ConvertFrom (from).GetPort ()
650  );
651  }
652 
653  PacketReceivedFromKMS (packet, from, socket);
654  }
655 }
656 
657 void
659 {
660  NS_LOG_FUNCTION (this << socket);
661 
662  Ptr<Packet> packet;
663  Address from;
664  while ((packet = socket->RecvFrom (from)))
665  {
666  if (packet->GetSize () == 0)
667  { //EOF
668  break;
669  }
670 
671  NS_LOG_FUNCTION (this << packet
672  << "PACKETID: " << packet->GetUid()
673  << " of size: " << packet->GetSize()
674  );
675 
677  {
678  NS_LOG_FUNCTION( this << "At time " << Simulator::Now ().GetSeconds ()
679  << "s packet from APP pair received "
680  << packet->GetSize () << " bytes from "
682  << " port " << InetSocketAddress::ConvertFrom (from).GetPort () << "\n");
683  }
684 
685  DataPacketReceivedFromApp (packet, from, socket);
686  }
687 }
688 
689 void
691 {
692  NS_LOG_FUNCTION (this << socket);
693 
694  Ptr<Packet> packet;
695  Address from;
696  while ((packet = socket->RecvFrom (from)))
697  {
698  if (packet->GetSize () == 0)
699  { //EOF
700  break;
701  }
702 
703  NS_LOG_FUNCTION (this << packet
704  << "PACKETID: " << packet->GetUid()
705  << " of size: " << packet->GetSize()
706  );
707 
709  {
710  NS_LOG_FUNCTION( this << "At time " << Simulator::Now ().GetSeconds ()
711  << "s signaling packet from APP pair received "
712  << packet->GetSize () << " bytes from "
714  << " port " << InetSocketAddress::ConvertFrom (from).GetPort () << "\n");
715  }
716 
717  SignalingPacketReceivedFromApp (packet, from, socket);
718  }
719 }
720 
721 void
723 {
724  NS_LOG_FUNCTION (this << "QKDApp014 Data to KMS Sent via socket " << socket);
725 }
726 
727 
735 void
737 {
738 
739  NS_LOG_FUNCTION( this << "Application key buffer is initialized!");
740  //Initialize storages of keys!
745 }
746 
747 void
748 QKDApp014::RemoveKeysFromTemporaryKeyStore (std::vector<std::string> keyIds)
749 {
750  NS_LOG_FUNCTION( this << "Keys removed from temporary key store" << keyIds );
751  std::map<std::string, QKDApp014::QKDApp014Key>::iterator it;
752  for (uint i = 0; i < keyIds.size(); i++) {
753  it = (m_appKeyBuffer.temporaryKeyStoreMaster).find(keyIds[i]);
754  if (it == m_appKeyBuffer.temporaryKeyStoreMaster.end())
755  //NS_FATAL_ERROR( this << "Key with ID" << keyIds[i] << "does not exist in temporary key store!" );
756  NS_LOG_DEBUG( this << "Key with ID" << keyIds[i] << "does not exist in temporary key store!" );
757  else
759  }
760 }
761 
762 void
764 {
765  NS_LOG_FUNCTION( this << "Key with ID" << key.keyId << "is added to inbound key store!" );
766  (m_appKeyBuffer.inboundKeyStore).insert(std::make_pair(key.keyId, key));
767 }
768 
769 void
771 {
772  NS_LOG_FUNCTION( this << "Key with ID" << key.keyId << "is added to encription key store!" );
773  (m_appKeyBuffer.outboundEncKeyStore).insert(std::make_pair(key.keyId, key));
774 }
775 
776 void
778 {
779  NS_LOG_FUNCTION( this << "Key with ID" << key.keyId << "is added to authentication key store!" );
780  (m_appKeyBuffer.outboundAuthKeyStore).insert(std::make_pair(key.keyId, key));
781 }
782 
783 void
785 {
786  std::map<std::string, QKDApp014::QKDApp014Key>::iterator it = (m_appKeyBuffer.temporaryKeyStoreMaster).begin();
787  while (it != (m_appKeyBuffer.temporaryKeyStoreMaster).end()) {
788  NS_LOG_FUNCTION( this << "KeyId" << it->first << it->second.keyId << "\n" );
789  it++;
790  }
791 }
792 
793 void
795 {
796  NS_LOG_FUNCTION( this << "Outbound encrption key count" << m_appKeyBuffer.outboundEncKeyStore.size()
797  << "Outbound authentication key count" << m_appKeyBuffer.outboundAuthKeyStore.size()
798  << "Inbound key count" << m_appKeyBuffer.inboundKeyStore.size() );
799 }
800 
801 void
803 {
804  NS_LOG_FUNCTION(this << "Primary QKDApp checks internal enc/auth buffer states ...");
806  //Note: CheckAppBufferState must not be triggered from anywhere while m_internalAppWait is true! It is called on scheduled event!
807  if(m_master){ //Only at Primary application!
808  if(GetEncryptionKeySize() != 0 && m_appKeyBuffer.outboundEncKeyStore.empty()) //Check the state of encryption key store
809  GetKeysFromKMS(0); // 0 - Encryption key
810  if(GetAuthenticationKeySize() != 0 && m_appKeyBuffer.outboundAuthKeyStore.empty()) //Check the state of authentication key store
811  GetKeysFromKMS(1); // 1 - Authentication key
812  CheckAppState();
813  }
814 }
815 
816 void
818 {
819  NS_LOG_FUNCTION(this << "Checking the conditions to change the application state ...");
820  bool encryptionReady {true}, authenticationReady {true};
822  encryptionReady = false;
824  authenticationReady = false;
825 
826  if(m_appState == WAIT && encryptionReady && authenticationReady)
828  else if(m_appState == READY && !(encryptionReady && authenticationReady))
830 }
831 
834 {
836  if(keyType == 0){ //Get encryption key
837  NS_LOG_FUNCTION( this << "Obtaining encryption key from application key buffer!" );
838  if(!m_appKeyBuffer.outboundEncKeyStore.empty()){
839  std::map<std::string, QKDApp014::QKDApp014Key>::iterator it = m_appKeyBuffer.outboundEncKeyStore.begin();
840  key = it->second;
841  NS_LOG_FUNCTION( this << "Key" << key.keyId << key.lifetime << m_packetSize );
842  if(int64_t (key.lifetime - m_packetSize) < int64_t (m_packetSize)){
843  NS_LOG_FUNCTION( this << "Key " << key.keyId << " removed from application key buffer!" );
845  } else {
846  it->second.lifetime = key.lifetime - m_packetSize;
847  }
848  } else
849  NS_FATAL_ERROR ( this << "Encryption key buffer is empty!" );
850 
851  }else if(keyType == 1){ //Get authentication key
852  NS_LOG_FUNCTION( this << "Obtaining authentication key from application key buffer!" );
854  std::map<std::string, QKDApp014::QKDApp014Key>::iterator it = m_appKeyBuffer.outboundAuthKeyStore.begin();
855  key = it->second;
856  NS_LOG_FUNCTION( this << "Key " << key.keyId << " removed from applicaiton key buffer!" );
858  } else
859  NS_FATAL_ERROR ( this << "Authentication key buffer is empty!" );
860 
861  }else
862  NS_FATAL_ERROR( this << "Invalid key type" << keyType
863  << "Allowed values are 0-Encryption key type, and 1-Authentication key type" );
864 
865  return key;
866 
867 }
868 
870 QKDApp014::GetKeyFromAppKeyBuffer (std::string keyId, std::string keyType)
871 {
872  NS_LOG_FUNCTION( this << keyId );
874  std::map<std::string, QKDApp014::QKDApp014Key>::iterator it;
875  it = m_appKeyBuffer.inboundKeyStore.find(keyId);
876  if(it != m_appKeyBuffer.inboundKeyStore.end()){
877  key = it->second;
878  if (keyType == "enc"){
879  if(
880  (m_encryptionTypeInt == 2 &&
881  int64_t (key.lifetime - m_packetSize) < int64_t (m_packetSize)) ||
883  ){ //AES expired key or OTP
884  NS_LOG_FUNCTION( this << "Key " << key.keyId << " removed from inbound key buffer!" );
886  }else if(m_encryptionTypeInt == 2){ //AES update lifetime
887  it->second.lifetime = key.lifetime - m_packetSize;
888  }
889  }else if(keyType == "auth"){
890  NS_LOG_FUNCTION( this << "Key " << key.keyId << " removed from inbound key buffer!" );
892  }else
893  NS_FATAL_ERROR( this << "Inalid key type as input " << keyType );
894  }else
895  NS_FATAL_ERROR( this << "Key" << keyId << " is missing from inbound key store" );
896 
897  return key;
898 }
899 
900 
908 void
909 QKDApp014::MemoriesRequestKMS (uint32_t methodType, uint32_t keyType)
910 {
911  m_httpRequestsKMS.push_back (std::make_pair (methodType, keyType));
912 }
913 
914 void
915 QKDApp014::MemoriesRequestApp (std::vector<std::string> keyIds)
916 {
917  m_httpRequestsApp.push_back (keyIds);
918 }
919 
920 void
922 {
923  m_httpRequestsKMS.erase (m_httpRequestsKMS.begin());
924 }
925 
926 void
928 {
929  m_httpRequestsApp.erase (m_httpRequestsApp.begin());
930 }
931 
932 uint32_t
934 {
935  return (m_httpRequestsKMS[0]).first;
936 }
937 
938 uint32_t
940 {
941  return (m_httpRequestsKMS[0]).second;
942 }
943 
944 
952 void
954 {
955  NS_LOG_FUNCTION ( this << m_local << m_peer << m_master );
956 
957  m_packetsSent = 0;
958 
959  if(m_encryptionTypeInt < 0 || m_encryptionTypeInt > 2){
960  NS_FATAL_ERROR ("Invalid encryption type " << m_encryptionTypeInt << ". Allowed values are (0-unencrypted, 1-OTP, 2-AES)" );
961  }
962 
963  if(m_authenticationTypeInt < 0 || m_authenticationTypeInt > 3){
964  NS_FATAL_ERROR ("Invalid authentication type " << m_authenticationTypeInt << ". Allowed values are (0-unauthenticated, 1-VMAC, 2-MD5, 3-SHA1)" );
965  }
966 
967  if(m_aesLifetime < 0)
968  NS_FATAL_ERROR ("Invalid AES lifetime " << m_aesLifetime << ". The value must be larger than zero." );
969 
970  else if (m_aesLifetime < m_packetSize && m_aesLifetime != 0)
971  NS_FATAL_ERROR ("Invalid AES lifetime " << m_aesLifetime << ". The value must be larger than one packet size " << m_packetSize );
972 
973  if (m_appState == INITIALIZED)
974  {
975 
980  );
981  AppTransitionTree(); //Transition states
982  PrepareSinkSocketFromApp(); //Create sink sockets for peer QKD applications
983 
984  } else {
985  NS_FATAL_ERROR ("Invalid state " << GetAppStateString ()
986  << " for StartApplication().");
987  }
988 
989 }
990 
991 void
993 {
994  NS_LOG_FUNCTION( this );
995 
996  if (m_sendEvent.IsRunning ())
997  {
999  }
1000 
1001  if (m_sendDataSocketApp)
1003  if (m_sinkDataSocketApp)
1009 
1010  InitializeAppKeyBuffer(); //Clear app key buffer!
1011  if (m_sendSocketToKMS)
1013  if (m_sinkSocketFromKMS)
1015 
1016  NS_LOG_FUNCTION( this << "Open sockets are closed and application is stopped" );
1018 }
1019 
1020 void
1022 {
1023  NS_LOG_FUNCTION( this );
1024 
1025  if (m_appState == READY) //Direct call from SceduleTx()
1027 
1028  if (m_appState == SEND_DATA) { //QKDApp014 can send packets only when in SEND_DATA state!
1029 
1030  if(m_sendDataSocketApp == 0) {
1032  }
1033 
1034  bool encrypted = m_encryptionType;
1035  bool authenticated = m_authenticationType;
1036  NS_LOG_FUNCTION( this << "Enc/Auth" << encrypted << authenticated );
1037 
1038  //Obtain secret keys!
1039  QKDApp014::QKDApp014Key encKey;
1040  encKey.keyId = std::string(32, '0');
1041  QKDApp014::QKDApp014Key authKey;
1042  authKey.keyId = std::string(32, '0');
1043 
1044  if (encrypted) //Obtain encryption key from application key buffer!
1045  encKey = GetKeyFromAppKeyBuffer(0); //0 - encryption key
1046  if (GetAuthenticationKeySize() != 0) //Obtain authentication key from application key buffer!
1047  authKey = GetKeyFromAppKeyBuffer(1); //1 - authentication key
1048 
1049  //Decode keys from Base64!
1050  std::string encKeyDecoded = m_encryptor->Base64Decode(encKey.key);
1051  std::string authKeyDecoded = m_encryptor->Base64Decode(authKey.key);
1052 
1053  //Define confidential message
1054  std::string confidentialMsg = GetPacketContent();
1055  NS_LOG_FUNCTION( this << "Confidential message" << confidentialMsg.size() << confidentialMsg );
1056 
1057  std::string encryptedMsg;
1058  std::string authTag;
1059 
1060  if (m_useCrypto) {
1061 
1062  encryptedMsg = m_encryptor->EncryptMsg(confidentialMsg, encKeyDecoded);
1063  NS_LOG_FUNCTION ( this << "Encryption key" << encKey.keyId << encKeyDecoded
1064  << "Encrypted message (Base64 print)" << m_encryptor->Base64Encode(encryptedMsg));
1065  authTag = m_encryptor->Authenticate (encryptedMsg, authKeyDecoded);
1066  NS_LOG_FUNCTION( this << "Authentication key" << authKey.keyId << authKeyDecoded
1067  << "Authentication tag" << authTag );
1068 
1069  } else {
1070 
1071  encryptedMsg = confidentialMsg;
1072  authTag = GetPacketContent(32); //Use random authTag
1073  NS_LOG_FUNCTION ( this << "Encryption key" << encKey.keyId << encKeyDecoded );
1074  NS_LOG_FUNCTION( this << "Authentication key" << authKey.keyId << authKeyDecoded );
1075 
1076  }
1077 
1078  //Create packet with protected/unprotected data
1079  std::string msg = encryptedMsg;
1080  Ptr<Packet> packet = Create<Packet> ( (uint8_t*) msg.c_str(), msg.length() );
1081  NS_ASSERT (packet != 0);
1082  m_authenticationTrace (packet, authTag);
1083 
1084  //Add qkd header!
1085  QKDAppHeader qHeader;
1086  qHeader.SetEncrypted(m_encryptionType);
1087  qHeader.SetEncryptionKeyId(CreateKeyIdField(encKey.keyId));
1089  qHeader.SetAuthenticationKeyId(CreateKeyIdField(authKey.keyId));
1090  qHeader.SetAuthTag(authTag);
1091  qHeader.SetLength(packet->GetSize() + qHeader.GetSerializedSize());
1092  packet->AddHeader(qHeader);
1093 
1094  //Send packet!
1095  m_txTrace (packet, m_dstSaeId.string());
1096  m_sendDataSocketApp->Send (packet);
1097  m_packetsSent++;
1098  m_dataSent += packet->GetSize();
1099 
1100  NS_LOG_FUNCTION (this << "Sending protected packet: " << packet->GetUid() << " of size " << packet->GetSize() );
1101 
1102  SwitchAppState(READY); //Application is now ready
1104  //Schedule new time instance to send data!
1105  ScheduleTx ();
1106 
1107  } else if (m_appState == WAIT) {
1108 
1109  m_mxTrace (0, m_dstSaeId.string());
1110  ScheduleTx ();
1111  NS_LOG_FUNCTION( this << "Application is currently unable to send new data! QKDApp014 state" << GetAppStateString(m_appState) );
1112 
1113  }
1114 
1115 }
1116 
1117 void
1119 {
1120  NS_LOG_FUNCTION ( this << m_master << p->GetUid() << p->GetSize() << from );
1121 
1122  if (m_master == 0) { //Process encrypted data on Replica QKDApp014
1123 
1124  if (m_appState == READY) { //Replica QKDApp014 MUST be in ready state to receive data
1125 
1126  QKDAppHeader header;
1127  Ptr<Packet> buffer;
1128 
1129  auto itBuffer = m_buffer_QKDApp014.find (from);
1130  if (itBuffer == m_buffer_QKDApp014.end ())
1131  {
1132  itBuffer = m_buffer_QKDApp014.insert (std::make_pair (from, Create<Packet> (0))).first;
1133  }
1134 
1135  buffer = itBuffer->second;
1136  buffer->AddAtEnd (p);
1137  buffer->PeekHeader (header);
1138 
1139  NS_ABORT_IF (header.GetLength () == 0);
1140 
1141  while (buffer->GetSize () >= header.GetLength ())
1142  {
1143  NS_LOG_DEBUG ("Removing packet of size " << header.GetLength () << " from buffer of size " << buffer->GetSize ());
1144  Ptr<Packet> completePacket = buffer->CreateFragment (0, static_cast<uint32_t> (header.GetLength ()));
1145  buffer->RemoveAtStart (static_cast<uint32_t> (header.GetLength ()));
1146 
1147  m_rxTrace ( completePacket, m_dstSaeId.string() );
1148  completePacket->RemoveHeader (header);
1149  NS_LOG_FUNCTION(this << "RECEIVED QKDApp014 HEADER: " << header);
1150 
1151  ProcessDataPacketFromApp(header, completePacket, socket);
1152 
1153  if (buffer->GetSize () > header.GetSerializedSize ())
1154  {
1155  buffer->PeekHeader (header);
1156  }
1157  else
1158  {
1159  break;
1160  }
1161  }
1162 
1163  } else {
1164  NS_LOG_FUNCTION( this << "Primary/Replica:" << m_master << "Invalid state " << GetAppStateString() );
1165  }
1166  }
1167 
1168 }
1169 
1170 void
1172 {
1173  NS_LOG_FUNCTION( this );
1174 
1175  if (m_master == 0) { //Only Replica QKDApp014 receives encrypted data!
1176 
1177  uint8_t *buffer = new uint8_t[packet->GetSize ()];
1178  packet->CopyData(buffer, packet->GetSize ());
1179  std::string payload = std::string((char*)buffer, packet->GetSize ());
1180  delete[] buffer;
1181 
1182  NS_LOG_FUNCTION( this << "Replica QKDApp014 received data packet from peer QKDApp014" << m_encryptor->Base64Encode(payload) );
1183 
1186  std::string decryptedMsg;
1187  bool authSuccessful = false;
1188  m_packetSize = payload.length();
1189  //Perform authentication first
1190  if (GetAuthenticationKeySize() != 0)
1191  {
1192  //Fetch key
1195 
1196  if (m_useCrypto)
1197  {
1198  //Decode key
1199  std::string decodedKey = m_encryptor->Base64Decode(key.key);
1200  //Check authTag
1201  if (m_encryptor->CheckAuthentication(payload, header.GetAuthTag(), decodedKey)) {
1202  authSuccessful = true;
1203  NS_LOG_FUNCTION( this << "Packet successfully authenticated" );
1204  }
1205  else
1206  NS_LOG_FUNCTION( this << "FAILED authentication of received packet" );
1207 
1208  } else { //We assume packet is authenticated
1209 
1210  authSuccessful = true;
1211  NS_LOG_FUNCTION( this << "Packet authenticated" );
1212  }
1213 
1214  } else if (header.GetAuthenticated()) {
1215 
1216  if (m_useCrypto)
1217  {
1218  if (m_encryptor->CheckAuthentication(payload, header.GetAuthTag(), "")) {
1219  authSuccessful = true;
1220  NS_LOG_FUNCTION( this << "Packet successfully authenticated" );
1221  }
1222  else
1223  NS_LOG_FUNCTION( this << "FAILED authentication of received packet" );
1224  } else { //We assume packet is authenticated
1225 
1226  authSuccessful = true;
1227  NS_LOG_FUNCTION( this << "Packet authenticated" );
1228  }
1229  } else
1230  authSuccessful = true;
1231 
1232  //Perform decryption
1233  if (header.GetEncrypted()) //Perform decryption
1234  {
1235  //Fetch key
1238  if (m_useCrypto)
1239  {
1240  //Decode key
1241  std::string decodedKey = m_encryptor->Base64Decode(key.key);
1242  NS_LOG_FUNCTION( this << decodedKey );
1243  //Decrypt packet
1244  if (authSuccessful)
1245  {
1246  decryptedMsg = m_encryptor->DecryptMsg (payload, decodedKey);
1247  NS_LOG_FUNCTION( this << "Decrypted message" << decryptedMsg );
1248  }
1249  } else {
1250 
1251  if (authSuccessful)
1252  NS_LOG_FUNCTION( this << "Packet decrypted" );
1253  }
1254 
1255  } else {
1256 
1257  if (m_useCrypto)
1258  NS_LOG_FUNCTION( this << "Packet decrypted" );
1259  else
1260  NS_LOG_FUNCTION( this << "Received message" << payload );
1261  }
1262 
1264 
1265  } else
1266  NS_FATAL_ERROR( this << "Only Replica QKDApp014 should receive protected packet" );
1267 }
1268 
1269 
1270 
1279 void
1281 {
1282  NS_LOG_FUNCTION (this << "QKDApp014 Get Status " << keyType);
1283 
1284  if(m_sendSocketToKMS == 0)
1286 
1287  if(m_sinkSocketFromKMS == 0)
1289 
1290  //SEND PACKET TO KMS - GET STATUS
1291 
1293  std::ostringstream lkmsAddressTemp;
1294  lkmsAddress.Print(lkmsAddressTemp); //IPv4Address to string
1295  std::string headerUri = "http://" + lkmsAddressTemp.str ();
1296 
1297  if(keyType)
1298  headerUri += "/api/v1/keys/" + m_ksid_enc.string() + "/status";
1299  else
1300  headerUri += "/api/v1/keys/" + m_ksid_auth.string() + "/status";
1301 
1302 
1303  //Create packet
1304  HTTPMessage httpMessage;
1305  httpMessage.CreateRequest(headerUri, "GET");
1306  std::string hMessage = httpMessage.ToString();
1307  Ptr<Packet> packet = Create<Packet> (
1308  (uint8_t*) (hMessage).c_str(),
1309  hMessage.size()
1310  );
1311  NS_ASSERT (packet != 0);
1312 
1313  NS_LOG_FUNCTION (this << "Sending PACKETID: " << packet->GetUid()
1314  << " of size: " << packet->GetSize()
1315  << " via socket " << m_sendSocketToKMS
1316  );
1317 
1318  MemoriesRequestKMS(0);
1319  m_txKmsTrace (packet);
1320  m_sendSocketToKMS->Send (packet);
1321 
1322 }
1323 
1324 void
1325 QKDApp014::GetKeysFromKMS (uint32_t keyType)
1326 {
1327  NS_LOG_FUNCTION( this << "QKDApp014 Get Key" << m_master );
1328 
1329  if(m_sendSocketToKMS == 0)
1331  if(m_sinkSocketFromKMS == 0)
1333 
1334  uint32_t numberOfKeys = m_numberOfKeysKMS; //@toDo dinamic behaviour of numberOfKeys!
1335  if (numberOfKeys <= 0) //Application basic check of user input!
1336  NS_FATAL_ERROR( this << "Invalid application parameter - m_numberOfKeysKMS" << numberOfKeys );
1337 
1338  if (keyType == 0) //Get Key request for encryption keys!
1339  {
1340 
1341  uint32_t sizeOfKeys = GetEncryptionKeySize(); //Size of a key based on defined encryption algorithm
1342  NS_LOG_FUNCTION( this << "Size of encryption keys" << sizeOfKeys );
1343 
1344  std::vector<std::string> additional_slave_SAE_IDs {}; //No additional Replica SAEs
1345  bool useGet = false; //Is application allowed to use GET method for such request?
1346  bool usedMethod; //Used method: false -> POST, true -> GET (if possible)
1347 
1348  if (additional_slave_SAE_IDs.empty() && useGet)
1349  usedMethod = true;
1350  else
1351  usedMethod = false;
1352 
1353  //Create HTTP header - ETSI014 Get Key request!
1355  std::ostringstream lkmsAddressTemp;
1356  lkmsAddress.Print(lkmsAddressTemp); //IPv4Address to string
1357  std::string headerUri = "http://" + lkmsAddressTemp.str ();
1358  headerUri += "/api/v1/keys/" + m_ksid_enc.string() + "/enc_keys";
1359 
1360 
1361  std::string requestBody;
1362  HTTPMessage httpMessage;
1363  if (usedMethod)
1364  {
1365  requestBody = {};
1366 
1367  //Update header URI
1368  headerUri += "/number/" + std::to_string(numberOfKeys);
1369  headerUri += "/size/" + std::to_string(sizeOfKeys);
1370  httpMessage.CreateRequest(headerUri, "GET");
1371  } else {
1372 
1373  nlohmann::json jkeyrequest;
1374  jkeyrequest["number"] = numberOfKeys;
1375  jkeyrequest["size"] = sizeOfKeys;
1376  if (!additional_slave_SAE_IDs.empty()){
1377  jkeyrequest["additional_slave_SAE_IDs"] = additional_slave_SAE_IDs;
1378  }
1379  requestBody = jkeyrequest.dump();
1380 
1381  httpMessage.CreateRequest(headerUri, "POST", requestBody);
1382  }
1383 
1384  std::string hMessage = httpMessage.ToString();
1385  Ptr<Packet> packet = Create<Packet> (
1386  (uint8_t*) (hMessage).c_str(),
1387  hMessage.size()
1388  );
1389  NS_ASSERT (packet != 0);
1390 
1391 
1392  NS_LOG_FUNCTION (this << "Sending PACKETID: " << packet->GetUid()
1393  << " of size: " << packet->GetSize()
1394  << " via socket " << m_sendSocketToKMS
1395  );
1396 
1397  //Store request to HTTP requests store (to be able to map responses)
1398  MemoriesRequestKMS(1, 0); //(method type, key type)
1399  m_txKmsTrace (packet);
1400  m_sendSocketToKMS->Send (packet);
1401 
1402  } else if (keyType == 1)
1403  {
1404 
1405  uint32_t sizeOfKeys = GetAuthenticationKeySize(); //Size of a key based on defined authentication algorithm
1406  NS_LOG_FUNCTION( this << "Size of authentication keys" << sizeOfKeys );
1407 
1408  std::vector<std::string> additional_slave_SAE_IDs {}; //No additional Replica SAEs
1409  bool useGet = false; //Is application allowed to use GET method for such request?
1410  bool usedMethod; //Used method: false -> POST, true -> GET
1411 
1412  if (additional_slave_SAE_IDs.empty() && useGet)
1413  usedMethod = true;
1414  else
1415  usedMethod = false;
1416 
1417  //Create HTTP header - ETSI014 Get Key request!
1419  std::ostringstream lkmsAddressTemp;
1420  lkmsAddress.Print(lkmsAddressTemp); //IPv4Address to string
1421  std::string headerUri = "http://" + lkmsAddressTemp.str ();
1422  headerUri += "/api/v1/keys/" + m_ksid_auth.string() + "/enc_keys";
1423 
1424  HTTPMessage httpMessage;
1425  std::string requestBody;
1426  if (usedMethod)
1427  {
1428  //Update header URI
1429  headerUri += "/number/" + std::to_string(numberOfKeys);
1430  headerUri += "/size/" + std::to_string(sizeOfKeys);
1431  requestBody = {};
1432  httpMessage.CreateRequest(headerUri, "GET");
1433 
1434  } else {
1435 
1436  nlohmann::json jkeyrequest;
1437  jkeyrequest["number"] = numberOfKeys;
1438  jkeyrequest["size"] = sizeOfKeys;
1439  if (!additional_slave_SAE_IDs.empty()){
1440  jkeyrequest["additional_slave_SAE_IDs"] = additional_slave_SAE_IDs;
1441  }
1442 
1443  requestBody = jkeyrequest.dump();
1444  httpMessage.CreateRequest(headerUri, "POST", requestBody);
1445 
1446  }
1447 
1448  //SEND PACKET
1449  std::string hMessage = httpMessage.ToString();
1450  Ptr<Packet> packet = Create<Packet> (
1451  (uint8_t*) (hMessage).c_str(),
1452  hMessage.size()
1453  );
1454  NS_ASSERT (packet != 0);
1455 
1456  NS_LOG_FUNCTION (this << "Sending PACKETID: " << packet->GetUid()
1457  << " of size: " << packet->GetSize()
1458  << " via socket " << m_sendSocketToKMS
1459  );
1460 
1461  MemoriesRequestKMS(1, 1);
1462  m_txKmsTrace (packet);
1463  m_sendSocketToKMS->Send (packet);
1464 
1465  } else {
1466  NS_FATAL_ERROR( this << "Invalid key type" << keyType << "Available values are 0-Encryption key type, and 1-Authentication key type" );
1467  }
1468 
1469 }
1470 
1471 void
1473 {
1474  NS_LOG_FUNCTION( this << "QKDApp014 Get key with key IDs" << m_master );
1475 
1476  if(m_sendSocketToKMS == 0)
1478 
1479  if(m_sinkSocketFromKMS == 0)
1481 
1482  std::string ksid;
1483  if (m_keyIDs.contains("ksid"))
1484  ksid = m_keyIDs["ksid"];
1485 
1486  //Create HTTP header
1488  std::ostringstream lkmsAddressTemp;
1489  lkmsAddress.Print(lkmsAddressTemp); //IPv4Address to string
1490  std::string headerUri = "http://" + lkmsAddressTemp.str ();
1491 
1492  std::string msg = m_keyIDs.dump(); //Json - KeyIDs is already in m_keyIDs variable!
1493  headerUri += "/api/v1/keys/"+ksid+"/dec_keys";
1494 
1495  NS_LOG_FUNCTION(this << "ccc:" << m_keyIDs);
1496 
1497  //Create packet
1498  HTTPMessage httpMessage;
1499  httpMessage.CreateRequest(headerUri, "POST", msg);
1500  std::string hMessage = httpMessage.ToString();
1501  Ptr<Packet> packet = Create<Packet> (
1502  (uint8_t*) (hMessage).c_str(),
1503  hMessage.size()
1504  );
1505  NS_ASSERT (packet != 0);
1506 
1507  NS_LOG_FUNCTION (this << "Sending PACKETID: " << packet->GetUid()
1508  << " of size: " << packet->GetSize()
1509  << " via socket " << m_sendSocketToKMS
1510  );
1511 
1512  MemoriesRequestKMS(2);
1513  m_txKmsTrace (packet);
1514  m_sendSocketToKMS->Send (packet);
1515 
1516 }
1517 
1518 void
1520 {
1521  std::string receivedStatus = p->ToString();
1522  NS_LOG_FUNCTION ( this << "\n\n\n" << p->GetUid() << p->GetSize() << receivedStatus << from );
1523 
1524  Ptr<Packet> buffer;
1525  if (receivedStatus.find("Fragment") != std::string::npos) {
1526  auto itBuffer = m_buffer_kms.find (from);
1527  if (itBuffer == m_buffer_kms.end ()){
1528  itBuffer = m_buffer_kms.insert (
1529  std::make_pair (from, Create<Packet> (0))
1530  ).first;
1531  }
1532  buffer = itBuffer->second;
1533  buffer->AddAtEnd (p);
1534  }else{
1535  NS_LOG_FUNCTION(this << "Full packet received!");
1536  buffer = p;
1537  }
1538 
1539  HTTPMessageParser parser;
1540  HTTPMessage request;
1541 
1542  //copy buffer payload to string
1543  uint8_t *b1 = new uint8_t[buffer->GetSize ()];
1544  buffer->CopyData(b1, buffer->GetSize ());
1545  std::string requestString = std::string((char*)b1);
1546  delete[] b1;
1547 
1548  //parse HTTP message
1549  parser.Parse(&request, requestString);
1550  if(request.IsFragmented() || request.GetStatusMessage() == "Undefined")
1551  {
1552  NS_LOG_FUNCTION(this << "HTTP Content Parsed after merge with buffer: " << request.ToString() << "\n ***IsFragmented:" << request.IsFragmented() << "\n\n\n\n");
1553  }else{
1554  NS_LOG_FUNCTION(this << "Full packet received:" << request.ToString());
1555  }
1556 
1557  while (buffer->GetSize () >= request.GetSize())
1558  {
1559  NS_LOG_DEBUG ("Parsing packet pid(" << p->GetUid() << ") of size " << request.GetSize () << " from buffer of size " << buffer->GetSize ());
1560  Ptr<Packet> completePacket = buffer->CreateFragment (0, static_cast<uint32_t> (request.GetSize () ));
1561 
1562  uint8_t *b2 = new uint8_t[completePacket->GetSize ()];
1563  completePacket->CopyData(b2, completePacket->GetSize ());
1564  std::string s2 = std::string((char*)b2);
1565 
1566  HTTPMessage request2;
1567  parser.Parse(&request2, s2);
1568  delete[] b2;
1569 
1570  if(request2.IsFragmented() == false){
1571  buffer->RemoveAtStart (static_cast<uint32_t> (request2.GetSize () ));
1572  m_rxKmsTrace (completePacket);
1573  ProcessResponseFromKMS(request2, completePacket, socket);
1574  }
1575 
1576  NS_LOG_FUNCTION(this << "Croped HTTP message: " << request2.ToString());
1577  NS_LOG_FUNCTION(this << "Remains in the buffer " << buffer->GetSize () );
1578  break;
1579  }
1580 }
1581 
1582 void
1584 {
1585  NS_LOG_FUNCTION (this << packet->GetUid() << packet->GetSize());
1586 
1587  std::string payload = header.GetMessageBodyString();
1588  //Map response to request
1589  uint32_t methodType = GetETSIMethod();
1590  //Process json data structure of KMS response!
1591  nlohmann::json jresponse;
1592  try {
1593 
1594  jresponse = nlohmann::json::parse(payload);
1595 
1596  if (methodType == 0) {
1597 
1598  ProcessStatusResponse(header, jresponse);
1599 
1600  } else if (methodType == 1){
1601 
1602  ProcessGetKeyResponse(header, jresponse);
1603 
1604  } else if (methodType == 2) {
1605 
1606  ProcessGetKeyWithKeyIDsResponse(header, jresponse);
1607 
1608  } else {
1609  NS_FATAL_ERROR (this << "Invalid ETSI method used in request");
1610  }
1611 
1612  } catch (...) {
1613  NS_FATAL_ERROR (this << "JSON parse error!");
1614  }
1615 }
1616 
1617 void
1619 {
1620 
1621  HTTPMessage::HttpStatus responseStatus = header.GetStatus();
1622  if (
1623  responseStatus == HTTPMessage::HttpStatus::BadRequest ||
1624  responseStatus == HTTPMessage::HttpStatus::Unauthorized ||
1625  responseStatus == HTTPMessage::HttpStatus::ServiceUnavailable
1626  ) {
1627 
1628  NS_FATAL_ERROR( this << "QKDApp014 received ERROR status information from local KMS" << jstatusResponse.dump() );
1629 
1630  } else if (responseStatus == HTTPMessage::HttpStatus::Ok){
1631 
1632  NS_LOG_FUNCTION( this << "QKDApp014 received status information from local KMS" );
1633  //Check the AppBufferState
1635 
1636  } else {
1637  NS_FATAL_ERROR( this << "Unsupported error status code" << responseStatus << "of response.");
1638  }
1639 
1640  RequestProcessedKMS(); //Remove request from store.
1641 
1642 }
1643 
1644 void
1646 {
1647  NS_LOG_FUNCTION( this );
1648 
1649  if(jGetKeyResponse.empty())
1650  NS_FATAL_ERROR(this << "KMS response on GET_KEY is empty!");
1651 
1652  std::string ksid;
1653  if (jGetKeyResponse.contains("ksid"))
1654  ksid = jGetKeyResponse["ksid"];
1655 
1656  HTTPMessage::HttpStatus responseStatus = header.GetStatus();
1657  if (
1658  responseStatus == HTTPMessage::HttpStatus::BadRequest ||
1659  responseStatus == HTTPMessage::HttpStatus::Unauthorized ||
1660  responseStatus == HTTPMessage::HttpStatus::ServiceUnavailable
1661  ) {
1662 
1663  if (jGetKeyResponse.contains("message"))
1664  {
1665  if (jGetKeyResponse["message"] == std::string {"requested parameters do not adhere to KMS rules"})
1666  NS_FATAL_ERROR( this << jGetKeyResponse.dump());
1667  else if (jGetKeyResponse["message"] == std::string {"insufficient amount of key material"})
1668  ScheduleAction(Time (m_waitInsufficient), "CheckAppBufferState");
1669  else if (jGetKeyResponse["message"] == std::string {"keys are being transformed"})
1670  ScheduleAction(Time (m_waitTransform), "CheckAppBufferState"); //Results in two times schedule when enc and auth! Fixed in ScheduleAction
1671  else
1672  NS_FATAL_ERROR( this << "uknown error message");
1673  } else {
1674  NS_FATAL_ERROR( this << "uknown error message");
1675  }
1676 
1677  } else if (responseStatus == HTTPMessage::HttpStatus::Ok){
1678 
1679  NS_LOG_FUNCTION( this << "Primary QKDApp014 received requested number of keys" << jGetKeyResponse.dump() );
1680 
1681  uint32_t keyType = GetKeyType();
1682  //Push obtained keys to temporary key buffer, until they are negotiated with peer QKDApp014.
1684  std::vector<std::string> keysToNegotiate;
1685  for (nlohmann::json::iterator it = jGetKeyResponse["keys"].begin(); it != jGetKeyResponse["keys"].end(); ++it) {
1686  key.key = (it.value())["key"];
1687  key.keyId = (it.value())["key_ID"];
1688  key.keyType = keyType;
1689  if(keyType == 0 && m_encryptionType == 2)
1690  key.lifetime = m_aesLifetime;
1691  else
1692  key.lifetime = m_packetSize;
1693  (m_appKeyBuffer.temporaryKeyStoreMaster).insert(std::make_pair(key.keyId, key));
1694  keysToNegotiate.push_back(key.keyId);
1695 
1696  m_obtainedKeyMaterialTrace ((m_encryptor->Base64Decode(key.key)).size() * 8);
1697  }
1698 
1700  ExchangeInfoMessages(ksid, keysToNegotiate);
1701 
1702  } else {
1703  NS_FATAL_ERROR( this << "Unsupported error status code" << responseStatus << "of response.");
1704  }
1705 
1706  RequestProcessedKMS(); //Remove request from store.
1707 
1708 }
1709 
1710 void
1712 {
1713 
1714  NS_LOG_FUNCTION( this );
1715 
1716  std::string ksid;
1717  if (jGetKeyWithKeyIDsResponse.contains("ksid"))
1718  ksid = jGetKeyWithKeyIDsResponse["ksid"];
1719 
1720  HTTPMessage::HttpStatus responseStatus = header.GetStatus();
1721  if (
1722  responseStatus == HTTPMessage::HttpStatus::BadRequest ||
1723  responseStatus == HTTPMessage::HttpStatus::Unauthorized ||
1724  responseStatus == HTTPMessage::HttpStatus::ServiceUnavailable
1725  ) {
1726 
1727  NS_FATAL_ERROR( this << "Replica QKDApp014 received ERROR response on key request" << jGetKeyWithKeyIDsResponse.dump() );
1728 
1729  ExchangeInfoMessages(ksid, {}, responseStatus);
1730 
1731  } else if (responseStatus == HTTPMessage::HttpStatus::Ok) {
1732 
1733  NS_LOG_FUNCTION( this << "Replica QKDApp014 received requested keys" << jGetKeyWithKeyIDsResponse.dump() );
1734 
1735  //Replica application directly stores the keys in application key buffer!
1737  for (nlohmann::json::iterator it = jGetKeyWithKeyIDsResponse["keys"].begin(); it != jGetKeyWithKeyIDsResponse["keys"].end(); ++it) {
1738 
1739  key.key = (it.value())["key"];
1740  key.keyId = (it.value())["key_ID"];
1741  key.lifetime = m_aesLifetime; //In case AES is used!
1743 
1744  m_obtainedKeyMaterialTrace ((m_encryptor->Base64Decode(key.key)).size() * 8);
1745  }
1746 
1747  ExchangeInfoMessages(ksid, {}, responseStatus);
1748 
1749  } else {
1750  NS_FATAL_ERROR( this << "Unsupported HTTP status code" << responseStatus << "of response");
1751  }
1752 
1753  RequestProcessedKMS(); //Remove request from store.
1754 
1755 }
1756 
1757 void
1759 {
1760  std::string receivedStatus = p->ToString();
1761  NS_LOG_FUNCTION ( this << "\n\n\n" << p->GetUid() << p->GetSize() << receivedStatus << from );
1762 
1763  Ptr<Packet> buffer;
1764  if (receivedStatus.find("Fragment") != std::string::npos) {
1765  auto itBuffer = m_buffer_kms.find (from);
1766  if (itBuffer == m_buffer_kms.end ()){
1767  itBuffer = m_buffer_kms.insert (
1768  std::make_pair (from, Create<Packet> (0))
1769  ).first;
1770  }
1771  buffer = itBuffer->second;
1772  buffer->AddAtEnd (p);
1773  }else{
1774  NS_LOG_FUNCTION(this << "Full packet received!");
1775  buffer = p;
1776  }
1777 
1778  HTTPMessageParser parser;
1779  HTTPMessage request;
1780 
1781  //copy buffer payload to string
1782  uint8_t *b1 = new uint8_t[buffer->GetSize ()];
1783  buffer->CopyData(b1, buffer->GetSize ());
1784  std::string requestString = std::string((char*)b1);
1785  delete[] b1;
1786 
1787  //parse HTTP message
1788  parser.Parse(&request, requestString);
1789  if(request.IsFragmented() || request.GetStatusMessage() == "Undefined")
1790  {
1791  NS_LOG_FUNCTION(this << "HTTP Content Parsed after merge with buffer: " << request.ToString() << "\n ***IsFragmented:" << request.IsFragmented() << "\n\n\n\n");
1792  }else{
1793  NS_LOG_FUNCTION(this << "Full packet received:" << request.ToString());
1794  }
1795 
1796  NS_LOG_FUNCTION(this << "aaaaa: \t" << buffer->GetSize() << request.GetSize());
1797 
1798  while (buffer->GetSize () >= request.GetSize())
1799  {
1800  NS_LOG_DEBUG ("Parsing packet pid(" << p->GetUid() << ") of size " << request.GetSize () << " from buffer of size " << buffer->GetSize ());
1801  Ptr<Packet> completePacket = buffer->CreateFragment (0, static_cast<uint32_t> (request.GetSize () ));
1802 
1803  uint8_t *b2 = new uint8_t[completePacket->GetSize ()];
1804  completePacket->CopyData(b2, completePacket->GetSize ());
1805  std::string s2 = std::string((char*)b2);
1806 
1807  HTTPMessage request2;
1808  parser.Parse(&request2, s2);
1809  delete[] b2;
1810 
1811  if(request2.IsFragmented() == false){
1812  buffer->RemoveAtStart (static_cast<uint32_t> (request2.GetSize () ));
1813  m_rxSigTrace (completePacket);
1814  ProcessSignalingPacketFromApp(request2, completePacket, socket);
1815  }
1816  NS_LOG_FUNCTION(this << "Croped HTTP message: " << request2.ToString());
1817  NS_LOG_FUNCTION(this << "Remains in the buffer " << buffer->GetSize () );
1818  break;
1819  }
1820 }
1821 
1822 void
1824 {
1825  NS_LOG_FUNCTION( this << packet->GetSize() << packet->GetUid() );
1826 
1827  if (m_master == 1) { //Primary QKDApp014 processes received signaling packet from Replica QKDApp014.
1828 
1829  NS_LOG_FUNCTION( this << "APP-SIGNALING: Primary QKDApp014 received response from Replica QKDApp014. Packet ID" << packet->GetUid());
1830 
1831  std::vector<std::string> keyIds = m_httpRequestsApp[0]; //Take first request in store (mapping of response to request)
1832  if (header.GetStatus() == HTTPMessage::HttpStatus::Ok) { //Keys successfully negotiated! Primary QKDApp014 adds keys to enc/auth key store for use.
1833 
1835 
1836  for (uint i = 0; i < keyIds.size(); i++) {
1837  NS_LOG_FUNCTION( this << keyIds[i] << i << keyIds.size() );
1838 
1839  std::map<std::string, QKDApp014::QKDApp014Key>::iterator it;
1840  it = m_appKeyBuffer.temporaryKeyStoreMaster.find(keyIds[i]);
1841 
1842  if (it == m_appKeyBuffer.temporaryKeyStoreMaster.end()){
1843 
1844  NS_LOG_DEBUG( this << "Key " << keyIds[i] << " was not found in the temporary key store!" );
1845 
1846  }else{
1847  if ((it->second).keyType == 0)
1848  AddEncKeyInKeyStore(it->second);
1849  else
1850  AddAuthKeyInKeyStore(it->second);
1851  }
1852  }
1853 
1857  CheckAppState();
1858 
1859 
1860  } else { //Possible collision on requested key!
1861 
1862  NS_LOG_DEBUG ( this << "The attempt to negotiate keys failed.");
1863  //Only the request for this particular key type must be repeated
1864  if(!m_internalAppWait){ //Only repeat the request if the CheckAppBufferState is not scheduled!
1865  NS_LOG_FUNCTION(this << "Application is submitting a new GET_KEY request ...");
1866  //First find a key type! Take a single keyID (first one) ->
1867  std::string keyID = m_httpRequestsApp[0][0];
1868  //Find this key in the temporary key store to determine the type ->
1869  std::map<std::string, QKDApp014::QKDApp014Key>::iterator it = m_appKeyBuffer.temporaryKeyStoreMaster.find(keyID);
1871  GetKeysFromKMS(it->second.keyType); //Try to aquire and negotiate a new key material.
1872  }else
1873  NS_LOG_DEBUG(this << "Key" << keyID << "was not found in the temporary key store!");
1874  }
1875  RemoveKeysFromTemporaryKeyStore(keyIds); //Remove keys from the temporary key store!
1877  }
1878 
1880 
1881  } else { //Replica QKDApp014 processes received signaling packet from Primary QKDApp014.
1882 
1883 
1884  std::string payload = header.GetMessageBodyString();
1885  nlohmann::json jKeyIDs;
1886 
1887  try {
1888 
1889  jKeyIDs = nlohmann::json::parse(payload);
1890 
1891  NS_LOG_FUNCTION( this << "APP-SIGNALING: Replica QKDApp014 received proposal from Primary QKDApp014. Packet ID" << packet->GetUid() << jKeyIDs);
1892 
1893  m_keyIDs = jKeyIDs; //Use m_keyIDs to make GetKeyWithKeyIDs!
1894  GetKeyWithKeyIDs();
1895 
1896  } catch(...) {
1897  NS_LOG_FUNCTION( this << "JSON parse error" );
1898  }
1899 
1900  }
1901 }
1902 
1903 void
1904 QKDApp014::ExchangeInfoMessages (std::string ksid, std::vector<std::string> keyIds, HTTPMessage::HttpStatus statusCode)
1905 {
1906 
1907  if (m_sendSignalingSocketApp == 0)
1909  if (m_sinkSignalingSocketApp == 0)
1911 
1912  if(m_master) { //Primary QKDApp014 sends proposal of keys to Replica QKDApp014.
1913 
1914  nlohmann::json key_IDs;
1915  key_IDs["ksid"] = ksid;
1916  for (uint i = 0; i < keyIds.size(); i++) {
1917  key_IDs["key_IDs"].push_back({ {"key_ID", keyIds[i] } });
1918  }
1919 
1920  std::string msg = key_IDs.dump();
1921 
1922  //Create packet
1923  HTTPMessage httpMessage;
1924  httpMessage.CreateRequest("/keys/key_ids", "POST", msg);
1925  std::string hMessage = httpMessage.ToString();
1926  Ptr<Packet> packet = Create<Packet> (
1927  (uint8_t*) (hMessage).c_str(),
1928  hMessage.size()
1929  );
1930  NS_ASSERT (packet != 0);
1931 
1932  MemoriesRequestApp(keyIds);
1933  m_txSigTrace (packet);
1934  m_sendSignalingSocketApp->Send(packet);
1935  m_packetsSent++;
1936  m_dataSent += packet->GetSize();
1937  NS_LOG_FUNCTION(this << "APP-SIGNALING: Primary QKDApp014 sends proposal to Replica QKDApp014. Packet ID" << packet->GetUid() << packet->GetSize());
1938 
1939  } else { //Replica QKDApp014 sends response to Primary QKDApp014.
1940 
1941  //create packet
1942  HTTPMessage httpMessage;
1943  httpMessage.CreateResponse(statusCode);
1944  std::string hMessage = httpMessage.ToString();
1945  Ptr<Packet> packet = Create<Packet> (
1946  (uint8_t*) (hMessage).c_str(),
1947  hMessage.size()
1948  );
1949  NS_ASSERT (packet != 0);
1950 
1951  m_txSigTrace (packet);
1952  m_sendSignalingSocketApp->Send(packet);
1953  m_packetsSent++;
1954  m_dataSent += packet->GetSize();
1955  NS_LOG_FUNCTION( this << "APP-SIGNALING: Replica QKDApp014 sends respond to Primary QKDApp014. Packet ID" << packet->GetUid() );
1956 
1957  }
1958 }
1959 
1960 
1961 
1970 /*
1971  * \brief QKD App state transitions (Data transmision)
1972  */
1973 void
1975 {
1976  NS_LOG_FUNCTION( this );
1977 
1978  if (m_master) //Data transmision state transition for Primary QKDApp014
1979  {
1980 
1981  if (m_appState == INITIALIZED) {
1983  if (GetEncryptionKeySize() == 0 && GetAuthenticationKeySize() == 0) //No initial key material needed!
1984  {
1987  SendPacket(); //Imidiatly send packet
1988  } else { //Obtain status information from KMS, obtain initial key material!
1991 
1992  if(GetEncryptionKeySize() > 0) GetStatusFromKMS(0); //First call Get Status
1993  if(GetAuthenticationKeySize() > 0) GetStatusFromKMS(1); //First call Get Status
1994 
1995  SendPacket(); //It will result in schedule
1996  }
1997  } else {
1998  NS_FATAL_ERROR( this << "Invalid entry state" << m_appState <<
1999  "for AppTransitionTree()!");
2000  }
2001 
2002  } else if (!m_master) { //Data transmision state transition for Replica QKDApp014
2003 
2004  if (m_appState == INITIALIZED) {
2006  } else {
2007  NS_FATAL_ERROR( this << "Invalid entry state" << m_appState <<
2008  "for AppTransitionTree()!");
2009  }
2010 
2011  }
2012 }
2013 
2014 
2017 {
2018  return m_appState;
2019 }
2020 
2021 std::string
2023 {
2024  switch (state)
2025  {
2026  case NOT_STARTED:
2027  return "NOT_STARTED";
2028  break;
2029  case INITIALIZED:
2030  return "INITIALIZED";
2031  break;
2032  case READY:
2033  return "READY";
2034  break;
2035  case WAIT:
2036  return "WAIT";
2037  break;
2038  case SEND_DATA:
2039  return "SEND_DATA";
2040  break;
2041  case DECRYPT_DATA:
2042  return "DECRYPT_DATA";
2043  break;
2044  case STOPPED:
2045  return "STOPPED";
2046  break;
2047  default:
2048  NS_FATAL_ERROR ("Unknown state");
2049  return "FATAL_ERROR";
2050  break;
2051  }
2052 }
2053 
2054 
2055 std::string
2057 {
2058  return GetAppStateString (m_appState);
2059 }
2060 
2061 void
2063 {
2064 
2065  const std::string oldState = GetAppStateString ();
2066  const std::string newState = GetAppStateString (state);
2067 
2068 
2069  bool found = false;
2070  for (std::multimap<std::string, std::string>::iterator iter =
2071  m_transitionMatrix.begin ();
2072  iter != m_transitionMatrix.end (); iter++
2073  ){
2074  if(iter->first == oldState && iter->second == newState){
2075  m_appState = state;
2076  NS_LOG_DEBUG (this << " QKDApp014 " << oldState << " --> " << newState << ".");
2077  m_stateTransitionTrace (oldState, newState);
2078  found = true;
2079  }
2080  }
2081 
2082  if(found == false) {
2083  NS_FATAL_ERROR ("Unsupported transition from " << oldState << " to " << newState);
2084  }
2085 
2086 
2087 }
2088 
2097 void
2099  uint32_t encryptionType,
2100  uint32_t authenticationType,
2101  uint32_t authenticationTagLengthInBits
2102 ){
2103 
2104  NS_LOG_FUNCTION (this << encryptionType << authenticationType << authenticationTagLengthInBits);
2105 
2106  switch (encryptionType){
2107  case 0:
2109  break;
2110  case 1:
2112  break;
2113  case 2:
2115  break;
2116  }
2117 
2118  switch (authenticationType){
2119  case 0:
2121  break;
2122  case 1:
2124  break;
2125  case 2:
2127  break;
2128  case 3:
2130  break;
2131  }
2132 
2133  if(m_encryptor == 0){
2134  m_encryptor = CreateObject<QKDEncryptor> (
2137  authenticationTagLengthInBits
2138  );
2139  }else{
2140  m_encryptor->ChangeSettings(
2143  authenticationTagLengthInBits
2144  );
2145  }
2146 
2147 }
2148 
2149 std::string
2150 QKDApp014::GetPacketContent(uint32_t msgLength)
2151 {
2152  NS_LOG_FUNCTION(this);
2153 
2154  if (msgLength == 0)
2155  msgLength = m_packetSize;
2156 
2157  //Generate random string with same size as merged key string
2158  std::string confidentialMessage;
2159  static const char alphanum[] =
2160  "0123456789"
2161  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
2162  "abcdefghijklmnopqrstuvwxyz";
2163 
2164  uint32_t randVal = 0;
2165  for (uint32_t i = 0; i < msgLength; ++i){
2166  randVal = round(m_random->GetValue (0, sizeof(alphanum) - 1));
2167  confidentialMessage += alphanum[ randVal ];
2168  }
2169 
2170  return confidentialMessage;
2171 
2172 }
2173 
2174 std::string
2175 QKDApp014::CreateKeyIdField (std::string keyId)
2176 {
2177  keyId.erase(std::remove(keyId.begin(), keyId.end(), '-'), keyId.end());
2178  return keyId;
2179 }
2180 
2181 std::string
2182 QKDApp014::ReadKeyIdField (std::string keyId)
2183 {
2184  NS_LOG_FUNCTION(this << keyId);
2185  keyId.insert(8, "-");
2186  keyId.insert(13, "-");
2187  keyId.insert(18, "-");
2188  keyId.insert(23, "-");
2189  NS_LOG_FUNCTION(this << keyId);
2190  return keyId;
2191 }
2192 
2193 uint32_t
2195 {
2196 
2197  NS_LOG_FUNCTION(this << CryptoPP::AES::DEFAULT_KEYLENGTH);
2198 
2199  switch (m_encryptionType)
2200  {
2202  return 0;
2203  break;
2205  return m_packetSize * 8; //This will work great for Primary QKDApp014, Replica QKDApp014 needs to calculate for itself this!
2206  break;
2208  return CryptoPP::AES::MAX_KEYLENGTH * 8; //In bits 256!
2209  break;
2210  }
2211 
2212  return 0;
2213 
2214 }
2215 
2216 uint32_t
2218 {
2219  switch (m_authenticationType)
2220  {
2222  return 0;
2223  break;
2225  return CryptoPP::AES::BLOCKSIZE * 8; //In bits //Before: m_authenticationTagLengthInBits - 32B?
2226  break;
2228  return 0; //NoKey
2229  break;
2231  return 0; //NoKey
2232  break;
2233  }
2234 
2235  return 0;
2236 
2237 }
2238 
2239 
2240 
2241 } // Namespace ns3
a polymophic address class
Definition: address.h:91
The base class for all ns3 applications.
Definition: application.h:61
Ptr< Node > GetNode() const
Definition: application.cc:104
Class for representing data rates.
Definition: data-rate.h:89
uint64_t GetBitRate() const
Get the underlying bitrate.
Definition: data-rate.cc:287
An identifier for simulation events.
Definition: event-id.h:54
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:71
The basic class to represent both HTTP requests and responses.
Definition: http.h:78
std::string ToString()
Takes the headers added to the message along with the body and outputs it to a std::string for use in...
Definition: http.h:633
uint32_t GetSize()
Definition: http.h:686
void CreateRequest(const std::string &url, const std::string &method)
Definition: http.h:738
bool IsFragmented()
Definition: http.h:852
std::string GetMessageBodyString()
Definition: http.h:714
void CreateResponse(const HttpStatus status)
Definition: http.h:785
HTTPMessage::HttpStatus GetStatus()
To be returned with a status code in a response is a status text describing the status code by text r...
Definition: http.h:169
std::string GetStatusMessage() const
Get the current status message for this message.
Definition: http.h:623
A basic class to parse a HTTP message, both request and response.
Definition: http.h:941
void Parse(HTTPMessage *httpMessage, const std::string &buffer)
Parse a std::string to a HTTP message.
Definition: http.h:951
an Inet address class
uint16_t GetPort(void) const
Ipv4Address GetIpv4(void) const
static bool IsMatchingType(const Address &address)
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
void Print(std::ostream &os) const
Print this address to the given output stream.
static Ipv4Address GetAny(void)
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
Definition: packet.cc:335
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:378
std::string ToString(void) const
Return a string representation of the packet.
Definition: packet.cc:426
void RemoveAtStart(uint32_t size)
Remove size bytes from the start of the current packet.
Definition: packet.cc:362
uint64_t GetUid(void) const
Returns the packet's Uid.
Definition: packet.cc:390
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
Definition: packet.cc:227
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
Establish secure communication on application lavel to use the key and test LKSM.
Definition: qkd-app-014.h:82
uint32_t m_master
Is a master (sender/primary) application?
Definition: qkd-app-014.h:725
void HandleAcceptFromKMS(Ptr< Socket > s, const Address &from)
Handle an incoming connection from the KMS.
Definition: qkd-app-014.cc:518
void GetKeyWithKeyIDs()
Requests keys with given identifiers from the KMS (ETSI QKD 014 - Get key with key IDs method).
void PrepareSendSocketToKMS()
Prepare the send socket to communicate with the KMS Application.
Definition: qkd-app-014.cc:378
uint32_t GetKeyType(void)
Map the HTTP response and obtain the key type.
Definition: qkd-app-014.cc:939
void SwitchAppState(QKDApp014State state)
Change the state of the application.
void HandleReadFromKMS(Ptr< Socket > socket)
Handle a packet received from the KMS application.
Definition: qkd-app-014.cc:625
Ptr< QKDEncryptor > m_encryptor
The QKD encryptor.
Definition: qkd-app-014.h:762
void ConnectionSignalingToAppSucceeded(Ptr< Socket > socket)
Callback function after the signaling connection to the APP is complete.
Definition: qkd-app-014.cc:578
TracedCallback< const uint32_t & > m_obtainedKeyMaterialTrace
A trace callback for the obtained key material.
Definition: qkd-app-014.h:764
std::string CreateKeyIdField(std::string keyId)
Adjust the encryption key identifier for the QKDApp header.
void HandlePeerCloseSignalingFromApp(Ptr< Socket > socket)
Handle a signaling connection close from the peer QKD application.
Definition: qkd-app-014.cc:613
TracedCallback< Ptr< const Packet >, std::string > m_txTrace
A trace for transmitted data packets.
Definition: qkd-app-014.h:579
void ConnectionSignalingToAppFailed(Ptr< Socket > socket)
Callback function after the signaling connection to the APP has failed.
Definition: qkd-app-014.cc:584
void AddAuthKeyInKeyStore(QKDApp014::QKDApp014Key &key)
Add a new key to the authentication key store.
Definition: qkd-app-014.cc:777
void ProcessStatusResponse(HTTPMessage &header, nlohmann::json jstatusResponse)
Process the status response from the KMS.
QKDApp014State
The application states.
Definition: qkd-app-014.h:143
std::string GetPacketContent(uint32_t msgLength=0)
Generate a random packet (message) of a given size.
void HandlePeerErrorFromKMS(Ptr< Socket > socket)
Handle a connection error from the KMS.
Definition: qkd-app-014.cc:596
std::unordered_map< Address, Ptr< Packet >, AddressHash > m_buffer_kms
The buffer for the received packets from the KMS (fragmentation).
Definition: qkd-app-014.h:768
QKDApp014State GetAppState() const
Get the current state of the application.
TypeId m_tid
The type identifier.
Definition: qkd-app-014.h:724
UUID m_ksid_auth
The authentication key stream identifier.
Definition: qkd-app-014.h:743
static TypeId GetTypeId(void)
Get the type ID.
Definition: qkd-app-014.cc:44
void GetKeysFromKMS(uint32_t keyType)
Request keys from the KMS (ETSI QKD 014 - Get key method).
Time m_waitInsufficient
The amount of time spent waiting before issuing a new GET_KEY request when the previous one resulted ...
Definition: qkd-app-014.h:727
void SendPacket(void)
Send the application packet (includes the generation of a random message and optional encryption or/a...
void ConnectionToKMSSucceeded(Ptr< Socket > socket)
Callback function after the connection to the KMS is complete.
Definition: qkd-app-014.cc:554
void ProcessDataPacketFromApp(QKDAppHeader header, Ptr< Packet > packet, Ptr< Socket > socket)
Process the data packets from the peer QKD application.
std::vector< std::vector< std::string > > m_httpRequestsApp
A vector of HTTP requests sent to the peer application.
Definition: qkd-app-014.h:737
std::map< uint32_t, EventId > m_scheduledEvents
The map of scheduled events.
Definition: qkd-app-014.h:773
void MemoriesRequestKMS(uint32_t methodType, uint32_t keyType=0)
Memories the HTTP request made to the local KMS.
Definition: qkd-app-014.cc:909
TracedCallback< Ptr< const Packet >, std::string > m_mxTrace
A trace for the missed time slots to send data packets.
Definition: qkd-app-014.h:586
UUID m_dstSaeId
The peer application identifier.
Definition: qkd-app-014.h:740
uint32_t ScheduleAction(Time t, std::string action)
Schedule the action.
Definition: qkd-app-014.cc:296
DataRate m_dataRate
The application data rate.
Definition: qkd-app-014.h:720
UUID m_ksid_enc
The encryption key stream identifier.
Definition: qkd-app-014.h:742
void AddEncKeyInKeyStore(QKDApp014::QKDApp014Key &key)
Add a new key to the encryption key store.
Definition: qkd-app-014.cc:770
void PacketReceivedFromKMS(const Ptr< Packet > &p, const Address &from, Ptr< Socket > socket)
Check for the TCP segmentation of the packets received from the KMS.
uint32_t GetETSIMethod(void)
Map the HTTP response and obtrain the request method.
Definition: qkd-app-014.cc:933
void HandleAcceptSignalingFromApp(Ptr< Socket > s, const Address &from)
Handle a signaling incoming connection from the peer QKD application.
Definition: qkd-app-014.cc:542
uint32_t GetAuthenticationKeySize()
Get required key size for the choosen authentication algorithm.
TracedCallback< Ptr< const Packet > > m_txKmsTrace
A trace for transmitted packets to the KMS.
Definition: qkd-app-014.h:581
void HandlePeerCloseFromKMS(Ptr< Socket > socket)
Handle a connection close from the KMS.
Definition: qkd-app-014.cc:590
QKDApp014State m_appState
The application state.
Definition: qkd-app-014.h:766
uint32_t GetEncryptionKeySize()
Get required key size for the choosen encryption algorithm.
void MemoriesRequestApp(std::vector< std::string > keyIds)
Memories the HTTP request made to the peer QKD application.
Definition: qkd-app-014.cc:915
Ptr< Socket > m_sendSocketToKMS
The sending socket to the KMS.
Definition: qkd-app-014.h:706
void ProcessResponseFromKMS(HTTPMessage &header, Ptr< Packet > packet, Ptr< Socket > socket)
Process the response from the KMS application.
uint32_t m_encryptionTypeInt
The encryption algorithm.
Definition: qkd-app-014.h:752
void ProcessGetKeyResponse(HTTPMessage &header, nlohmann::json jGetKeyResponse)
Process the GET_KEY response from the KMS.
void HandleAcceptFromApp(Ptr< Socket > s, const Address &from)
Handle an incoming connection from the peer QKD application.
Definition: qkd-app-014.cc:530
void ConnectionToAppFailed(Ptr< Socket > socket)
Callback function after the connection to the APP has failed.
Definition: qkd-app-014.cc:572
std::string GetAppStateString() const
Get the current state of the application in the string format.
Address m_kms
The local KMS address.
Definition: qkd-app-014.h:715
uint32_t m_authenticationTagLengthInBits
The size of the authentication tag in bits (32 by default).
Definition: qkd-app-014.h:754
TracedCallback< Ptr< const Packet > > m_rxSigTrace
A trace for received signaling packets.
Definition: qkd-app-014.h:583
void ExchangeInfoMessages(std::string ksid, std::vector< std::string > keyIds, HTTPMessage::HttpStatus statusCode=HTTPMessage::Ok)
Exchange key identifiers between sending and receiving application.
ns3::TracedCallback< const std::string &, const std::string & > m_stateTransitionTrace
The posible application state transitions.
Definition: qkd-app-014.h:585
TracedCallback< Ptr< Packet >, std::string > m_authenticationTrace
A trace callback for the authentication event.
Definition: qkd-app-014.h:758
void SignalingPacketReceivedFromApp(const Ptr< Packet > &p, const Address &from, Ptr< Socket > socket)
Check for the TCP segmentation of the signaling packets received from the peer QKD application.
QKDApp014()
Constructor.
Definition: qkd-app-014.cc:153
uint32_t m_numberOfKeysKMS
The number of keys to fetch per request.
Definition: qkd-app-014.h:748
std::string ReadKeyIdField(std::string keyId)
Rebuild the key identifier for the QKDApp header.
bool ConnectionRequestedFromKMS(Ptr< Socket > socket, const Address &address)
Callback function after the connection response from the KMS has been received.
Definition: qkd-app-014.cc:506
void RequestProcessedKMS(void)
Remove the request from the HTTP requests store (once the response from the KMS has been processed).
Definition: qkd-app-014.cc:921
virtual void StartApplication(void)
Definition: qkd-app-014.cc:953
void CheckAppBufferState()
Check the state of the application key buffer.
Definition: qkd-app-014.cc:802
std::string m_socketType
The sockets type.
Definition: qkd-app-014.h:717
QKDApp014KeyBuffer m_appKeyBuffer
The application key buffer.
Definition: qkd-app-014.h:732
UUID GetId(void)
Get the application identifier.
Definition: qkd-app-014.h:561
Address m_localSignaling
The local address for the signaling data transmission.
Definition: qkd-app-014.h:713
TracedCallback< Ptr< Packet > > m_encryptionTrace
A trace callback for the encryption event.
Definition: qkd-app-014.h:756
std::vector< std::pair< uint32_t, uint32_t > > m_httpRequestsKMS
A vector of HTTP requests set to the KMS.
Definition: qkd-app-014.h:736
EventId m_sendEvent
The data transmission event.
Definition: qkd-app-014.h:721
void PrintAppBufferStatusInformation()
Print the status information on the application key buffer.
Definition: qkd-app-014.cc:794
uint32_t m_authenticationTypeInt
The authentication algorithm.
Definition: qkd-app-014.h:753
void ProcessGetKeyWithKeyIDsResponse(HTTPMessage &header, nlohmann::json jGetKeyWithKeyIDsResponse)
Process the Get Key with Key IDs response from the KMS.
void InitializeAppKeyBuffer()
Initialize the application key buffer.
Definition: qkd-app-014.cc:736
uint32_t m_packetSize
The data packet size.
Definition: qkd-app-014.h:719
void HandleReadFromApp(Ptr< Socket > socket)
Handle a packet received from the peer QKD application.
Definition: qkd-app-014.cc:658
TracedCallback< Ptr< const Packet > > m_txSigTrace
A trace for transmitted signaling packets.
Definition: qkd-app-014.h:580
Ptr< Socket > m_sendDataSocketApp
The sending socket for the data.
Definition: qkd-app-014.h:703
TracedCallback< Ptr< const Packet > > m_rxKmsTrace
A trace for received packets from the KMS.
Definition: qkd-app-014.h:584
virtual void StopApplication(void)
Application specific shutdown code.
Definition: qkd-app-014.cc:992
void HandlePeerErrorFromApp(Ptr< Socket > socket)
Handle a connection error from the peer QKD application.
Definition: qkd-app-014.cc:607
void ConnectionToAppSucceeded(Ptr< Socket > socket)
Callback function after the connection to the APP is complete.
Definition: qkd-app-014.cc:566
void ProcessSignalingPacketFromApp(HTTPMessage &header, Ptr< Packet > packet, Ptr< Socket > socket)
Process the signaling packets received from the peer QKD application.
uint32_t m_packetsSent
The number of sent data packets.
Definition: qkd-app-014.h:722
uint64_t m_aesLifetime
The AES key lifetime.
Definition: qkd-app-014.h:755
void DataPacketReceivedFromApp(const Ptr< Packet > &p, const Address &from, Ptr< Socket > socket)
Check for the TCP segmentation of the data packets received from the peer QKD application.
void DataToKMSSend(Ptr< Socket >, uint32_t)
Callback function to notify that data to KMS has been sent.
Definition: qkd-app-014.cc:722
void ConnectionToKMSFailed(Ptr< Socket > socket)
Callback function after the connection to the KMS has failed.
Definition: qkd-app-014.cc:560
Ptr< Socket > m_sinkDataSocketApp
The receiving socket for the data.
Definition: qkd-app-014.h:704
TracedCallback< Ptr< const Packet >, std::string > m_rxTrace
A trace for received data packets.
Definition: qkd-app-014.h:582
std::unordered_map< Address, Ptr< Packet >, AddressHash > m_buffer_QKDApp014
The buffer for received data packets (fragmentation).
Definition: qkd-app-014.h:770
void SetEncryptionAndAuthenticationSettings(uint32_t encryptionType, uint32_t authenticationType, uint32_t authenticationTagLengthInBits)
Set the encryption and the authentication algorithms.
void CancelScheduledAction(uint32_t eventId)
Cancel the scheduled event/action.
Definition: qkd-app-014.cc:318
Ptr< Socket > m_sinkSocketFromKMS
The receiving socket from the KMS.
Definition: qkd-app-014.h:707
QKDApp014::QKDApp014Key GetKeyFromAppKeyBuffer(uint32_t keyType)
Get the key from the application key buffer.
Definition: qkd-app-014.cc:833
void RemoveKeysFromTemporaryKeyStore(std::vector< std::string > keyIds)
Remove keys from the temporary key store.
Definition: qkd-app-014.cc:748
Address m_local
The local address for the data transmission.
Definition: qkd-app-014.h:712
void HandlePeerErrorSignalingFromApp(Ptr< Socket > socket)
Handle a signaling connection error from the peer QKD application.
Definition: qkd-app-014.cc:619
static uint32_t m_applicationCounts
The number of running applications.
Definition: qkd-app-014.h:745
nlohmann::json m_keyIDs
The latest received key identifiers from the sender application.
Definition: qkd-app-014.h:733
bool m_internalAppWait
The indicator for the longer wait (used after the GetKey error!).
Definition: qkd-app-014.h:772
void AppTransitionTree(void)
Transition through a tree of the application states and trigger actions.
void CheckAppState()
Check the conditions to change the application state.
Definition: qkd-app-014.cc:817
uint32_t m_useCrypto
Execute actual cryptographic algorithms?
Definition: qkd-app-014.h:751
std::multimap< std::string, std::string > m_transitionMatrix
The map of the possible state transitions.
Definition: qkd-app-014.h:774
void RequestProcessedApp(void)
Remove request from the HTTP requests store (once the response from the peer application has been pro...
Definition: qkd-app-014.cc:927
virtual ~QKDApp014()
Destructor.
Definition: qkd-app-014.cc:190
Ptr< UniformRandomVariable > m_random
The uniform random variable.
Definition: qkd-app-014.h:730
TracedCallback< Ptr< Packet >, std::string > m_deauthenticationTrace
A trace callback for the authentication check event.
Definition: qkd-app-014.h:759
void PrintTemporaryKeyStoreContent()
Print the content of the temporary key store.
Definition: qkd-app-014.cc:784
void PrepareSendSocketToApp()
Prepare the send socket to communicate with the peer QKD Application.
Definition: qkd-app-014.cc:404
void Setup(std::string socketType, Address src, Address dst, Address kms, UUID dstSaeId, std::string type)
Configure the application.
Definition: qkd-app-014.cc:204
UUID m_id
The application identifier.
Definition: qkd-app-014.h:739
void HandleReadSignalingFromApp(Ptr< Socket > socket)
Handle a signaling packet received from the peer QKD application.
Definition: qkd-app-014.cc:690
void GetStatusFromKMS(uint32_t keyType)
Request status information from the KMS (ETSI QKD 014 - Get status method).
Time m_waitTransform
The amount of time spent waiting before issuing a new GET_KEY request when the previous one resulted ...
Definition: qkd-app-014.h:728
TracedCallback< Ptr< Packet > > m_decryptionTrace
A trace callback for the decryption event.
Definition: qkd-app-014.h:757
Ptr< Socket > m_sendSignalingSocketApp
The sending socket for the signaling messages.
Definition: qkd-app-014.h:701
void ScheduleTx(void)
Schedule the time slot to send the data packets.
Definition: qkd-app-014.cc:279
Address m_peer
The address of the peer for the data transmission.
Definition: qkd-app-014.h:709
QKDEncryptor::AuthenticationType m_authenticationType
The authentication algorithm.
Definition: qkd-app-014.h:761
Address m_peerSignaling
The address of the peer for the signaling data transmission.
Definition: qkd-app-014.h:710
void HandlePeerCloseFromApp(Ptr< Socket > socket)
Handle a connection close from the peer QKD application.
Definition: qkd-app-014.cc:602
uint32_t m_dataSent
The amount of the sent data.
Definition: qkd-app-014.h:723
void AddKeyInInboundKeyStore(QKDApp014::QKDApp014Key &key)
Add a new key to the inbound key store.
Definition: qkd-app-014.cc:763
Ptr< Socket > m_sinkSignalingSocketApp
The receiving socket for the signaling messages.
Definition: qkd-app-014.h:702
void PrepareSinkSocketFromApp()
Prepare the sink socket to listen from the peer QKD Application.
Definition: qkd-app-014.cc:446
QKDEncryptor::EncryptionType m_encryptionType
The encryption algorithm.
Definition: qkd-app-014.h:760
void PrepareSinkSocketFromKMS()
Prepare the sink socket to listen from the KMS Application.
Definition: qkd-app-014.cc:340
QKD app packet header that carries info about used encryption, auth tag and other.
std::string GetEncryptionKeyId(void) const
Read the encryption key identifier.
std::string GetAuthTag(void) const
Read the authentication tag.
uint32_t GetSerializedSize() const
Get the serialized size of a packet.
void SetEncryptionKeyId(std::string value)
Set the encryption key identifier.
void SetEncrypted(uint32_t value)
Set the encrypted field.
uint32_t GetLength(void) const
Get message length.
void SetLength(uint32_t value)
Set the message length.
void SetAuthenticated(uint32_t value)
Set the authentication field.
uint32_t GetAuthenticated(void) const
Read the authentication field.
void SetAuthTag(std::string value)
Set the authentication tag.
std::string GetAuthenticationKeyId(void) const
Read the authentication key identifier.
void SetAuthenticationKeyId(std::string keyID)
Set the authentication key identifier.
uint32_t GetEncrypted(void) const
Read the encrypted field.
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
Definition: simulator.cc:268
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
void SetConnectCallback(Callback< void, Ptr< Socket > > connectionSucceeded, Callback< void, Ptr< Socket > > connectionFailed)
Specify callbacks to allow the caller to determine if the connection succeeds of fails.
Definition: socket.cc:84
void SetAcceptCallback(Callback< bool, Ptr< Socket >, const Address & > connectionRequest, Callback< void, Ptr< Socket >, const Address & > newConnectionCreated)
Accept connection requests from remote hosts.
Definition: socket.cc:104
virtual int ShutdownRecv(void)=0
virtual int Listen(void)=0
Listen for incoming connections.
void SetDataSentCallback(Callback< void, Ptr< Socket >, uint32_t > dataSent)
Notify application when a packet has been sent from transport protocol (non-standard socket call)
Definition: socket.cc:114
virtual int ShutdownSend(void)=0
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
virtual int Close(void)=0
Close a socket.
void SetCloseCallbacks(Callback< void, Ptr< Socket > > normalClose, Callback< void, Ptr< Socket > > errorClose)
Detect socket recv() events such as graceful shutdown or error.
Definition: socket.cc:94
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
Definition: socket.cc:128
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
Definition: socket.cc:71
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
static TypeId GetTypeId(void)
Get the type ID.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
AttributeValue implementation for Time.
Definition: nstime.h:1308
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
AttributeValue implementation for TypeId.
Definition: type-id.h:595
Universally unique identifier (UUID)
Definition: uuid.h:35
static UUID Random()
Generate random UUID4 (randomly or pseudo-randomly generated version)
Definition: uuid.cc:148
std::string string() const
Get string from the current UUID in format "00000000-0000-0000-0000-000000000000".
Definition: uuid.cc:74
static TypeId GetTypeId(void)
Get the type ID.
Hold an unsigned integer type.
Definition: uinteger.h:44
double GetValue(double min, double max)
Get the next random value, as a double in the specified range .
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: nstime.h:1309
Ptr< const AttributeAccessor > MakeTypeIdAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: type-id.h:595
Ptr< const AttributeChecker > MakeTypeIdChecker(void)
Definition: type-id.cc:1226
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: uinteger.h:45
Callback< R, Ts... > MakeNullCallback(void)
Definition: callback.h:1688
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition: abort.h:77
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
basic_json<> json
default JSON class
Definition: json.h:3000
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Definition: json.h:25255
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:522
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
std::map< std::string, QKDApp014Key > outboundEncKeyStore
Definition: qkd-app-014.h:133
std::map< std::string, QKDApp014Key > outboundAuthKeyStore
Definition: qkd-app-014.h:134
std::map< std::string, QKDApp014Key > inboundKeyStore
Definition: qkd-app-014.h:135
std::map< std::string, QKDApp014Key > temporaryKeyStoreMaster
Definition: qkd-app-014.h:136
The cryptographic key at the application layer.
Definition: qkd-app-014.h:120
static const uint32_t packetSize