Abstract class for creation and decryption of Onion messages. More...
#include "onion-routing.h"
Inheritance diagram for ns3::OnionRouting:
Collaboration diagram for ns3::OnionRouting:Public Types | |
| enum | OnionErrno { ERROR_NOTERROR, ERROR_PROT_NUMBER, ERROR_ROUTE_TO_SHORT, ERROR_ENCRYPTION, ERROR_DECRYPTION } |
| Enumeration of the possible errors using the class onion-routing. More... | |
Public Member Functions | |
| OnionRouting () | |
| OnionRouting (uint16_t keySize, uint16_t sealPadding, uint16_t addressSize) | |
| OnionRouting (uint16_t sealPadding, const uint16_t protocolNumber) | |
| Constructor – Setup parameters for the creation of onions. More... | |
| virtual | ~OnionRouting () |
| void | AddressToStream (uint8_t *ip) |
| void | AddressToStream (uint8_t *ip) |
| Output an ip address to a stream variable, used to LOG the onion message. More... | |
| int | BuildOnion (uint8_t *cipher, uint8_t **route, uint16_t routeLen, uint8_t **keys, uint8_t *content, uint16_t contentLen) |
| void | BuildOnion (uint8_t *cipher, uint8_t **route, uint8_t **keys, uint16_t routeLen) |
| Manage construction of the onion ONION_NO_CONTENT. More... | |
| void | BuildOnion (uint8_t *cipher, uint8_t **route, uint8_t **keys, uint16_t routeLen, uint8_t *endContent, uint16_t endContentLen) |
| Manage construction of the onion ONION_ENDCONTENT. More... | |
| void | BuildOnion (uint8_t *cipher, uint8_t **route, uint8_t **keys, uint8_t **layerContent, uint16_t layerContentLen, uint16_t routeLen) |
| Manage construction of the onion ONION_LAYERCONTENT. More... | |
| void | BuildOnion (uint8_t *cipher, uint8_t **route, uint8_t **keys, uint8_t **layerContent, uint16_t layerContentLen, uint16_t routeLen, uint8_t *endContent, uint16_t endContentLen) |
| Manage construction of the onion ONION_LAYERCONTENT_ENDCONTENT. More... | |
| int | CreateOnion (uint8_t *cipher, uint8_t **route, uint16_t index, uint16_t routeLen, uint8_t **keys, uint8_t *content, uint16_t contentLen) |
| void | CreateOnion (uint8_t *cipher, uint8_t **route, uint8_t **keys, uint16_t index, uint16_t routeLen, uint8_t **layerContent, uint16_t layerContentLen, uint8_t *endContent, uint16_t endContentLen) |
| Constructs the onion message *. More... | |
| virtual void | DecryptLayer (uint8_t *innerLayer, uint8_t *onion, uint16_t onionLen, uint8_t *pk, uint8_t *sk) const =0 |
| virtual void | DecryptLayer (uint8_t *plaintext, uint8_t *ciphertext, uint16_t len, uint8_t *publicKey, uint8_t *secretKey) const =0 |
| virtual method, implement decryption More... | |
| virtual void | EncryptLayer (uint8_t *ciphertext, uint8_t *message, int len, uint8_t *key) const =0 |
| virtual void | EncryptLayer (uint8_t *ciphertext, uint8_t *plaintext, int len, uint8_t *key) const =0 |
| virtual method, implement encryption More... | |
| enum OnionErrno | GetErrno (void) |
| Return the last error code of the OnionErrno enum. More... | |
| uint16_t | OnionLength (uint16_t routeLen, uint16_t contentLen) |
| uint16_t | OnionLength (uint16_t routeLen, uint16_t layerContentLen, uint16_t endContentLen) |
| Compute the length in bytes of the onion message at given parameters. More... | |
| orLayer * | PeelOnion (uint8_t *onion, uint16_t onionLen, uint8_t *pk, uint8_t *sk) |
| orLayer * | PeelOnion (uint8_t *onion, uint16_t onionLen, uint8_t *publicKey, uint8_t *secretKey) |
| Decipher the outer layer of the onion and return details. More... | |
Static Public Member Functions | |
| static TypeId | GetTypeId (void) |
| static TypeId | GetTypeId (void) |
| Register this type. More... | |
Public Attributes | |
| uint16_t | m_addressSize |
| size in bytes of the used address type (4-Ipv4, 16-Ipv6) More... | |
| enum OnionErrno | m_errno |
| error status while using the onion class More... | |
| uint16_t | m_keySize |
| std::stringstream | m_onionStream |
| stringstream used to LOG onion construction More... | |
| uint16_t | m_sealPadding |
| size increase of the ciphertext in bytes, intorduced by the encryption method More... | |
Abstract class for creation and decryption of Onion messages.
The OnionRouting abstract class include useful methods for the creation and redirection of Onion Messages. The given class can be used to construct onion messages of the following features:
ONION_NO_CONTENT - onion message including only routing information
example: (((10.1.1.2) 10.1.1.1) 10.1.1.5)10.1.1.3
ONION_ENDCONTENT - onion message including content to be delivered to the last node in the path
example: ((((end_content,0.0.0.0) 10.1.1.2) 10.1.1.1) 10.1.1.5) 10.1.1.3
ONION_LAYERCONTENT - onion message including a content of fixed length (in bytes) in each layer
example: ((((layer_content,0.0.0.0) layer_content,10.1.1.2) layer_content,10.1.1.1) layer_content,10.1.1.5)10.1.1.3
ONION_LAYERCONTENT_ENDCONTENT - onion message including a content of fixed length in each layer and content of arbitrary length to be delivered to the last node in the path
example: ((((end_content,0.0.0.0) layer_content,10.1.1.2) layer_content,10.1.1.1) layer_content,10.1.1.5)10.1.1.3
The given class can be used to construct onion circuits as described in Hiding Routing Information by david M. Goldschlag, Micheal G. Reed, and Paul F. Syverson, May 1996
We designed an abstract class to allow the use of an arbitrary encryption suite, by implementing methods EncryptLayer & DecryptLayer
implementing dummy Encryption/Decryption methods.
The class simulates the use of encryption keys by including them into encryption layers of onion messages. A node deciphering a layer of the onion message will compare its encryption key with the encryption key included in the layer of the onion message. If the two keys match the layer is succesfully deciphered, otherwise the node is not the expected recipient of the onion message and the encryption will fail triggering an error message.
Since dummy encryption keys of 4B are included in each layer of the onion message, the parameter m_sealPadding must be set to at least 4 Bytes. The parameter m_sealPadding is used to emulate additional bytes introduced by a real encryption technique. This parameter is set in the constructor.
Definition at line 29 of file onion-routing.h.
Enumeration of the possible errors using the class onion-routing.
| Enumerator | |
|---|---|
| ERROR_NOTERROR | |
| ERROR_PROT_NUMBER | |
| ERROR_ROUTE_TO_SHORT | |
| ERROR_ENCRYPTION | |
| ERROR_DECRYPTION | |
Definition at line 104 of file onion-routing.h.
| ns3::OnionRouting::OnionRouting | ( | ) |
Definition at line 27 of file onion-routing.cc.
| ns3::OnionRouting::OnionRouting | ( | uint16_t | keySize, |
| uint16_t | sealPadding, | ||
| uint16_t | addressSize | ||
| ) |
Definition at line 43 of file onion-routing.cc.
References m_addressSize, m_keySize, and m_sealPadding.
|
virtual |
Definition at line 50 of file onion-routing.cc.
| ns3::OnionRouting::OnionRouting | ( | uint16_t | sealPadding, |
| const uint16_t | protocolNumber | ||
| ) |
Constructor – Setup parameters for the creation of onions.
| [in] | sealPadding | size increase of the ciphertext in bytes, intorduced by the encryption method |
| [in] | protocolNumber | value detailing the utilized IP protocol: IPv4–Ipv4L3Protocol::PROT_NUMBER, IPv6–Ipv6L3Protocol::PROT_NUMBER |
Definition at line 51 of file onion-routing.cc.
References ERROR_NOTERROR, ERROR_PROT_NUMBER, m_addressSize, m_errno, and m_sealPadding.
| void ns3::OnionRouting::AddressToStream | ( | uint8_t * | ip | ) |
Definition at line 200 of file onion-routing.cc.
References m_addressSize, and m_onionStream.
Referenced by BuildOnion(), and CreateOnion().
Here is the caller graph for this function:| void ns3::OnionRouting::AddressToStream | ( | uint8_t * | ip | ) |
Output an ip address to a stream variable, used to LOG the onion message.
| [in] | ip | serialized ip address |
| int ns3::OnionRouting::BuildOnion | ( | uint8_t * | cipher, |
| uint8_t ** | route, | ||
| uint16_t | routeLen, | ||
| uint8_t ** | keys, | ||
| uint8_t * | content = nullptr, |
||
| uint16_t | contentLen = 0 |
||
| ) |
Definition at line 63 of file onion-routing.cc.
References AddressToStream(), CreateOnion(), and m_onionStream.
Referenced by ns3::Sink::PrepareOnion().
Here is the call graph for this function:
Here is the caller graph for this function:| void ns3::OnionRouting::BuildOnion | ( | uint8_t * | cipher, |
| uint8_t ** | route, | ||
| uint8_t ** | keys, | ||
| uint16_t | routeLen | ||
| ) |
Manage construction of the onion ONION_NO_CONTENT.
The resulting onion message include only routing information and the last hop in the onion path will not recieve content example: (((10.1.1.2) 10.1.1.1) 10.1.1.5)10.1.1.3
Allow the construction of onions of route length > 4, and manage the LOG output
| [in,out] | cipher | memory locations on which the onion message will be stored |
| [in] | route | array of ip addresses defining the route of the onion message, ip addresses are stored in the serialized form |
| [in] | keys | array of encryption keys, keys are stored in the serialized form |
| [in] | routeLen | the length of the route that the onion message will travel (equal to the number of ip addresses stored in the route parameter) |
Definition at line 77 of file onion-routing.cc.
References AddressToStream(), CreateOnion(), ERROR_NOTERROR, ERROR_ROUTE_TO_SHORT, m_errno, and m_onionStream.
Here is the call graph for this function:| void ns3::OnionRouting::BuildOnion | ( | uint8_t * | cipher, |
| uint8_t ** | route, | ||
| uint8_t ** | keys, | ||
| uint16_t | routeLen, | ||
| uint8_t * | endContent, | ||
| uint16_t | endContentLen | ||
| ) |
Manage construction of the onion ONION_ENDCONTENT.
The resulting onion message include routing information and the last hop in the onion path recieve the given content
The zero address – 0.0.0.0 (ipv4) identifies the last hop in the path of the onion message
example: ((((end_content,0.0.0.0) 10.1.1.2) 10.1.1.1) 10.1.1.5) 10.1.1.3
Allow the construction of onions of route length > 4, and manage the LOG output
| [in,out] | cipher | memory locations on which the onion message will be stored |
| [in] | route | array of ip addresses defining the route of the onion message, ip addresses are stored in the serialized form |
| [in] | keys | array of encryption keys, keys are stored in the serialized form |
| [in] | routeLen | the length of the route that the onion message will travel (equal to the number of ip addresses stored in the route) |
| [in] | endContent | location of the content to forward to the last node in the onion message path |
| [in] | endContentLen | length in bytes of the data stored at endContent |
Definition at line 105 of file onion-routing.cc.
References AddressToStream(), CreateOnion(), ERROR_NOTERROR, ERROR_ROUTE_TO_SHORT, m_errno, and m_onionStream.
Here is the call graph for this function:| void ns3::OnionRouting::BuildOnion | ( | uint8_t * | cipher, |
| uint8_t ** | route, | ||
| uint8_t ** | keys, | ||
| uint8_t ** | layerContent, | ||
| uint16_t | layerContentLen, | ||
| uint16_t | routeLen | ||
| ) |
Manage construction of the onion ONION_LAYERCONTENT.
The resulting onion message include only routing information, and each hop in the route will receive data stored in layerContent
The zero address – 0.0.0.0 (ipv4) identifies the last hop in the path of the onion message
example: ((((layer_content,0.0.0.0) layer_content,10.1.1.2) layer_content,10.1.1.1) layer_content,10.1.1.5)10.1.1.3
Allow the construction of onions of route length > 4, and manage the LOG output
| [in,out] | cipher | memory locations on which the onion message will be stored |
| [in] | route | array of ip addresses defining the route of the onion message, ip addresses are stored in the serialized form |
| [in] | keys | array of encryption keys, keys are stored in the serialized form |
| [in] | layerContent | array of of pointers, pointing to data to be stored in a layer of the onion message the data is of fixed length in bytes |
| [in] | layerContentLen | length in bytes of the data to be stored in each layer of the onion message |
| [in] | routeLen | the length of the route that the onion message will travel (equal to the number of ip addresses stored in the route) |
Definition at line 133 of file onion-routing.cc.
References AddressToStream(), CreateOnion(), ERROR_NOTERROR, ERROR_ROUTE_TO_SHORT, m_errno, and m_onionStream.
Here is the call graph for this function:| void ns3::OnionRouting::BuildOnion | ( | uint8_t * | cipher, |
| uint8_t ** | route, | ||
| uint8_t ** | keys, | ||
| uint8_t ** | layerContent, | ||
| uint16_t | layerContentLen, | ||
| uint16_t | routeLen, | ||
| uint8_t * | endContent, | ||
| uint16_t | endContentLen | ||
| ) |
Manage construction of the onion ONION_LAYERCONTENT_ENDCONTENT.
The resulting onion message include only routing information, each hop in the route will receive data stored in layerContent, the last hop in the onion path recieve content only data stored in endContent
The zero address – 0.0.0.0 (ipv4) identifies the last hop in the path of the onion message
example: ((((end_content,0.0.0.0) layer_content,10.1.1.2) layer_content,10.1.1.1) layer_content,10.1.1.5)10.1.1.3
Allow the construction of onions of route length > 4, and manage the LOG output
| [in,out] | cipher | memory locations on which the onion message will be stored |
| [in] | route | array of ip addresses defining the route of the onion message, ip addresses are stored in the serialized form |
| [in] | keys | array of encryption keys, keys are stored in the serialized form |
| [in] | layerContent | array of of pointers, pointing to data to be stored in a layer of the onion message the data is of fixed length in bytes |
| [in] | layerContentLen | length in bytes of the data to be stored in each layer of the onion message |
| [in] | routeLen | the length of the route that the onion message will travel (equal to the number of ip addresses stored in the route) |
| [in] | endContent | location of the content to forward to the last node in the onion message path |
| [in] | endContentLen | length in bytes of the data stored at endContent |
Definition at line 160 of file onion-routing.cc.
References AddressToStream(), CreateOnion(), ERROR_NOTERROR, ERROR_ROUTE_TO_SHORT, m_errno, and m_onionStream.
Here is the call graph for this function:| int ns3::OnionRouting::CreateOnion | ( | uint8_t * | cipher, |
| uint8_t ** | route, | ||
| uint16_t | index, | ||
| uint16_t | routeLen, | ||
| uint8_t ** | keys, | ||
| uint8_t * | content = nullptr, |
||
| uint16_t | contentLen = 0 |
||
| ) |
Definition at line 103 of file onion-routing.cc.
References AddressToStream(), EncryptLayer(), m_addressSize, m_onionStream, m_sealPadding, and OnionLength().
Referenced by BuildOnion(), and CreateOnion().
Here is the call graph for this function:
Here is the caller graph for this function:| void ns3::OnionRouting::CreateOnion | ( | uint8_t * | cipher, |
| uint8_t ** | route, | ||
| uint8_t ** | keys, | ||
| uint16_t | index, | ||
| uint16_t | routeLen, | ||
| uint8_t ** | layerContent, | ||
| uint16_t | layerContentLen, | ||
| uint8_t * | endContent, | ||
| uint16_t | endContentLen | ||
| ) |
Constructs the onion message *.
| [in,out] | cipher | memory on which the onion message will be stored |
| [in] | route | array of ip addresses defining the route of the onion message, ip addresses are stored in the serialized form |
| [in] | keys | array of encryption keys, keys are stored in the serialized form |
| [in] | layerContent | array of of pointers, pointing to data to be stored in a layer of the onion message the data is of fixed length in bytes |
| [in] | layerContentLen | length in bytes of the data to be stored in each layer of the onion message |
| [in] | index | additional parameter used for the construction of the onion message |
| [in] | routeLen | the length of the route that the onion message will travel (equal to the number of ip addresses stored in the route) |
| [in] | endContent | location of the content to forward to the last node in the onion message path |
| [in] | endContentLen | length in bytes of the data stored at endContent |
Definition at line 185 of file onion-routing.cc.
References AddressToStream(), CreateOnion(), EncryptLayer(), m_addressSize, m_onionStream, m_sealPadding, and OnionLength().
Here is the call graph for this function:
|
pure virtual |
Implemented in ns3::OnionRoutingDummyEncryption.
Referenced by PeelOnion().
Here is the caller graph for this function:
|
pure virtual |
virtual method, implement decryption
| [in,out] | plaintext | memory locations containing the decrypted data |
| [in] | ciphertext | memory locations containing the encrypted data |
| [in] | len | length in bytes of the ciphertext |
| [in] | publicKey | encryption key |
| [in] | secretKey | encryption key |
Implemented in ns3::OnionRoutingDummyEncryption.
|
pure virtual |
Implemented in ns3::OnionRoutingDummyEncryption.
Referenced by CreateOnion().
Here is the caller graph for this function:
|
pure virtual |
virtual method, implement encryption
| [in,out] | ciphertext | memory on which the ciphertext will be stored |
| [in] | plaintext | memory locations containing the data to be encrypted |
| [in] | len | length in bytes of the plaintext |
| [in] | key | encryption key |
Implemented in ns3::OnionRoutingDummyEncryption.
| enum OnionRouting::OnionErrno ns3::OnionRouting::GetErrno | ( | void | ) |
Return the last error code of the OnionErrno enum.
Definition at line 292 of file onion-routing.cc.
References m_errno.
|
static |
Definition at line 17 of file onion-routing.cc.
|
static |
Register this type.
| uint16_t ns3::OnionRouting::OnionLength | ( | uint16_t | routeLen, |
| uint16_t | contentLen | ||
| ) |
Definition at line 180 of file onion-routing.cc.
References m_addressSize, and m_sealPadding.
Referenced by CreateOnion(), and ns3::Sink::PrepareOnion().
Here is the caller graph for this function:| uint16_t ns3::OnionRouting::OnionLength | ( | uint16_t | routeLen, |
| uint16_t | layerContentLen, | ||
| uint16_t | endContentLen | ||
| ) |
Compute the length in bytes of the onion message at given parameters.
| [in] | routeLen | the length of the route that the onion message will travel (equal to the number of ip addresses stored in the route) |
| [in] | layerContentLen | length in bytes of the data to be stored in layers of the onion message |
| [in] | endContentLen | length in bytes of the data stored in the last hop's layer of the onion message |
Definition at line 259 of file onion-routing.cc.
References m_addressSize, and m_sealPadding.
| orLayer * ns3::OnionRouting::PeelOnion | ( | uint8_t * | onion, |
| uint16_t | onionLen, | ||
| uint8_t * | pk, | ||
| uint8_t * | sk | ||
| ) |
Definition at line 158 of file onion-routing.cc.
References DecryptLayer(), ns3::orLayer::innerLayer, ns3::orLayer::innerLayerLen, m_addressSize, m_sealPadding, and ns3::orLayer::nextHopIP.
Referenced by ns3::SensorNode::ProcessOnionHead().
Here is the call graph for this function:
Here is the caller graph for this function:| orLayer* ns3::OnionRouting::PeelOnion | ( | uint8_t * | onion, |
| uint16_t | onionLen, | ||
| uint8_t * | publicKey, | ||
| uint8_t * | secretKey | ||
| ) |
Decipher the outer layer of the onion and return details.
| [in] | onion | the onion message |
| [in] | onionLen | the length in bytes of the onion message |
| [in] | publicKey | encryption key |
| [in] | secretKey | encryption key |
| uint16_t ns3::OnionRouting::m_addressSize |
size in bytes of the used address type (4-Ipv4, 16-Ipv6)
Definition at line 52 of file onion-routing.h.
Referenced by AddressToStream(), CreateOnion(), OnionLength(), OnionRouting(), and PeelOnion().
|
mutable |
error status while using the onion class
Definition at line 320 of file onion-routing.h.
Referenced by BuildOnion(), ns3::OnionRoutingDummyEncryption::DecryptLayer(), GetErrno(), and OnionRouting().
| uint16_t ns3::OnionRouting::m_keySize |
Definition at line 51 of file onion-routing.h.
Referenced by OnionRouting().
| std::stringstream ns3::OnionRouting::m_onionStream |
stringstream used to LOG onion construction
Definition at line 56 of file onion-routing.h.
Referenced by AddressToStream(), BuildOnion(), and CreateOnion().
| uint16_t ns3::OnionRouting::m_sealPadding |
size increase of the ciphertext in bytes, intorduced by the encryption method
Definition at line 50 of file onion-routing.h.
Referenced by CreateOnion(), ns3::OnionRoutingDummyEncryption::DecryptLayer(), ns3::OnionRoutingDummyEncryption::EncryptLayer(), OnionLength(), OnionRouting(), and PeelOnion().