gnunet-handbook

The GNUnet Handbook
Log | Files | Refs

cong.rst (32656B)


      1 .. _CONG-Subsystem-Dev:
      2 
      3 .. index::
      4    double: CONG; subsystem
      5 
      6 CONG
      7 ====
      8 
      9 CONG (COre Next Generation) is the name of the project redesigns the
     10 :ref:`CORE-Subsystem-Dev` service. Here we document the design decisions and
     11 parts that are changing.
     12 The most notable change concerns peer ids: In order to avoid location tracking,
     13 they are being made non-permanent - they change with each change of underlying
     14 addresses. Next to that, the cryptographic primitives in use change, and the
     15 interface to the (transport) layers below. The interface to the underlying
     16 layers is made more generic so that libp2p can be switched in for gnunet's own
     17 transport (layer 2 overlay/L2O). Finally, protocol-versioning above core will
     18 be introduced.
     19 
     20 ..
     21   TODO (from project plan)
     22   - cryptographic protocol:
     23     - key exchange
     24     - key management
     25 
     26 ..
     27   TODO write a short overview
     28   - peer ids
     29   - libp2p
     30   - protocol versioning
     31 
     32 ..
     33   Design goals
     34   ------------
     35    - limit tracking
     36 
     37 
     38 Key exchange
     39 ------------
     40 
     41 While we are at it we may as well improve the key exchange
     42 (:ref:`The-CORE-Peer_002dto_002dPeer-Protocol`).
     43 Currently, we are using our own ECDHE key exchange that derives 2x2 keys.
     44 2 keys for each direction (sending/receiving).
     45 Each direction uses two 256-bit symmetric encryption keys derived through the ECDH exchange.
     46 Each payload is encrypted using AES(kA, Twofish(kB, payload)) both in CFB mode (!).
     47 
     48 ..
     49   TODO Ephemeral key derivation, material sent, checks, ...
     50   TODO Initiate handshake
     51 
     52 Next Steps
     53 ^^^^^^^^^^
     54 
     55 For CONG, we should double-check the security of your ECDHE construction.
     56 We decided on 11/03/2024 to investigate XChaCha20-Poly1305:
     57 
     58 Proposal:
     59 
     60   * Use X25519 for the KX with ephemeral Curve25519 keys.
     61   * Use XChaCha20-Poly1305 and kTx,kRx := KDF(X25519(),senderPK,receiverPK) for symmetric encryption
     62 
     63 We will have to replace the use of ``GNUNET_CRYPTO_symmetric_encrypt`` and
     64 HMAC use in ``gnunet-service-core_kx.c`` including the respective keys and IVs.
     65 
     66 Handshake Protocol (Current)
     67 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     68 
     69 .. warning:: This is incomplete as the protocol is very messy and has around 6 RTTs
     70 
     71 We assume that the peers have semi-*static* (as opposed to ephemeral) key pairs.
     72 Let (pk\ :sub:`A`,sk\ :sub:`A`) be the key pair of peer PID\ :sub:`A` and (pk\ :sub:`B`,sk\ :sub:`B`) the
     73 key pair of peer PID\ :sub:`B`.
     74 
     75 For any secure handshake protocol, we have to dermine an initiator and a receiver in the protocol.
     76 We use `GNUNET_CRYPTO_hash_cmp` to determine which peer is the receiver `R` and which peer the initiator `I`:
     77 
     78 .. code-block:: c
     79 
     80   if (GNUNET_CRYPTO_hash_cmp (pk_A, pk_B))
     81   {
     82     pk_I = pk_A
     83     pk_R = pk_B
     84   }
     85   else
     86   {
     87     pk_I = pk_B
     88     pk_R = pk_A
     89   }
     90 
     91 It is possible that the designated initiator does not initiate the handshake. After a pre-determined timeout,
     92 the respective other peer may initiate.
     93   
     94 We assume that the initiator knows pk\ :sub:`R` (pre-distributed through HELLO, for example).
     95 
     96 ``I`` and ``R`` calculate *before any connection attempt is made*:
     97 
     98 * (pk\ :sub:`e`,sk\ :sub:`e`) <- *KeyGen*\ ()
     99 
    100 .. danger:: Yes, both peers calculate *ephemeral* keys that are used for a set period of time in **all** handshakes.
    101 
    102 ``I`` calculates:
    103 
    104 * ``EphemeralKeyMessage`` <- (pk\ :sub:`I`, pk\ :sub:`e`, creation_time, ...)
    105 * sig\ :sub:`e` <- *Sign*\ (sk\ :sub:`I`, ``EphemeralKeyMessage``)
    106   
    107 .. admonition:: ``I`` sends to ``R``
    108 
    109                 ``EphemeralKeyMessage``, sig\ :sub:`e`
    110 
    111 ``R`` calculates:
    112 
    113 * assert *Verify*\ (pk\ :sub:`R`, ``EphemeralKeyMessage``, sig\ :sub:`e`)
    114 * Establish session keys through ECDH with *ephemeral* keys.
    115 * ``EphemeralKeyMessage`` <- (pk\ :sub:`R`, pk\ :sub:`e`, creation_time, ...)
    116 * sig\ :sub:`e` <- *Sign*\ (sk\ :sub:`R`, ``EphemeralKeyMessage``)
    117   
    118 .. admonition:: ``R`` sends to ``I``
    119 
    120                 ``EphemeralKeyMessage``, sig\ :sub:`e`
    121 
    122 ``I`` calculates:
    123 
    124 * assert *Verify*\ (pk\ :sub:`R`, ``EphemeralKeyMessage``, sig\ :sub:`e`)
    125 * Establish session keys through ECDH with *ephemeral* keys.
    126 
    127 .. admonition:: ``I`` sends to ``R``
    128 
    129                 ``PingMessage``
    130 
    131 ``R`` calculates:
    132 
    133 * Pong message
    134 
    135 .. admonition:: ``R`` sends to ``I``
    136 
    137                 ``PongMessage``
    138 
    139 
    140 Draft: CORE Authenticated Key Exchange (CAKE)
    141 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    142 
    143 .. seealso:: This protocol is derived from `KEMTLS <https://thomwiggers.nl/publication/thesis/thesis.pdf>`_ (page 81ff).
    144 
    145 
    146 The initiator selection remains unchanged from the above protocol.
    147 
    148 
    149 
    150 First Message (RTT=0) 
    151 """""""""""""""""""""
    152 
    153 ``I`` sends to ``R`` the following message:
    154 
    155 ``MessageHeader||InitiatorHello||EncryptedInitiatorCert``
    156 
    157 where:
    158 
    159 ``MessageHeader`` is a ``GNUNET_MessageHeader`` of type *TBD* (GANA registration).
    160 
    161 The ``InitiatorHello`` consists of:
    162 
    163 * (pk\ :sub:`e`, c\ :sub:`R`, SHA512(pk\ :sub:`R`), r\ :sub:`I`, [SupportedAlgs,Version])
    164 
    165 r\ :sub:`I` is nonce value (256 or 512 bit TBD).
    166 pk\ :sub:`e` is the public key from a freshly generated ephemeral key pair:
    167 
    168 * (pk\ :sub:`e`,sk\ :sub:`e`) <- *KeyGen*\ ()
    169 
    170 In GNUnet this ``KeyGen`` corresponds to ``GNUNET_CRYPTO_ecdhe_key_create()``. This is a X25519 key pair.
    171 The ``InitiatorHello`` may contain our version and other metadata which
    172 is indicated by the brackets. But, we may want to put this information into the ``cert`` below, as this is encrypted
    173 (identity hiding).
    174 
    175 The ``EncryptedInitiatorCert`` is created as 
    176 
    177 * *Enc*\ (**ETS**, cert [pk\ :sub:`I`])
    178 
    179 We may encode the capabilities/supported class in ``cert``.
    180 We do not want to use X.509 here, probably. ``cert`` is just a placeholder for the
    181 signed metadata (e.g. supported services string) and pk\ :sub:`I`.
    182 
    183 .. admonition:: Certificate definition
    184                 
    185                 The definition of certificate is incomplete.
    186                 For now, we only use self-signed certificates: The cert is signed using sk\ :sub:`I`. Use ``GNUNET_CRYPTO_eddsa_sign`` API for this.
    187 
    188 
    189 .. admonition:: Supported services string
    190                 
    191                 Supported services are just a series of *service*:*version* strings
    192                 separated by a separator. We may want to use libtool versioning?
    193 
    194 *Enc* is XChaCha20-Poly1305 (IETF version).
    195 To derive **ETS** we create our first shared secret as:
    196 
    197 * (ss\ :sub:`R`,c\ :sub:`R`) <- *Encaps*\ (pk\ :sub:`R`)
    198 
    199 pk\ :sub:`R` is the EdDSA public key of the peer we want to connect to.
    200 We should have received this as part of the trigger for this message.
    201 In GNUnet, ``Encaps`` corresponds to ``GNUNET_CRYPTO_eddsa_kem_encaps``.
    202 
    203 .. admonition:: X25519 vs EdDSA
    204                 Notice how X25519 and EdDSA keys are different. Accordingly, different/additional KEM implementations may be required in this handshake, but here the EdDSA version is correct.
    205 
    206 We then derive our encryption keys:
    207 
    208 * **ES** <- *HKDF-Extract*\ (ss\ :sub:`R`, 0)
    209 * **ETS** <- *HKDF-Expand*\ (**ES**, ``"early data"``, ``InitiatorHello``)
    210 
    211 and encrypt the certificate giving us the ``EncryptedInitiatorCert``.
    212 
    213 
    214 
    215 Second Message (RTT=0.5) 
    216 """"""""""""""""""""""""
    217 
    218 ``R`` the receives:
    219 
    220 ``MessageHeader||InitiatorHello||EncryptedInitiatorCert``
    221 
    222 and sends to ``I`` the following message:
    223 
    224 ``MessageHeader||ReceiverHello||EncryptedExtensions||ReceiverKemCiphertext||ReceiverFinished``
    225 
    226 The message may have already application payload appended, but in our case this is unlikely.
    227 
    228 First ``R`` processes the message received from ``I``:
    229 
    230 * Verify that the message type is *TBD*
    231 
    232 * Decrypt ``EncryptedInitiatorCert`` (cf. encryption above):
    233 
    234   * (ss\ :sub:`R`) <- Decaps(sk\ :sub:`R`, c\ :sub:`R`)
    235   * **ES** <- *HKDF-Extract*\ (ss\ :sub:`R`, 0)
    236   * **ETS** <- *HKDF-Expand*\ (**ES**, "early data", ``InitiatorHello``) 
    237   * cert [pk\ :sub:`I`] <- *Dec*\ (**ETS**, ``EncryptedInitiatorCert``)
    238 
    239 .. admonition:: Encaps X25519
    240 
    241                 Here, ``Decaps`` corresponds to ``GNUNET_CRYPTO_eddsa_kem_decaps``.
    242 
    243 * Setup Handshake and Master Secrets (these can also be done as-needed and not necessarily all at once here):
    244 
    245   * **dES** <- *HKDF-Expand*\ (**ES**, "derived", ``NULL``)
    246   * (ss\ :sub:`e`,c\ :sub:`e`) <- *Encaps*\ (pk\ :sub:`e`)
    247   * **HS** <- *HKDF-Extract*\ (ss\ :sub:`e`, **dES**)
    248   * **dHS** <-  *HKDF-Expand*\ (**HS**, "derived", ``NULL``)
    249   * (ss\ :sub:`I`,c\ :sub:`I`) <- ``Encaps``\ (pk\ :sub:`I`)
    250   * **MS** <- *HKDF-Extract*\ (ss\ :sub:`I`, **dHS**)
    251 
    252 .. admonition:: Encaps X25519
    253 
    254                 Here, ``Encaps`` corresponds to ``GNUNET_CRYPTO_hpke_kem_encaps``.
    255     
    256 * Derive Handshake Traffic Encryption Keys:
    257 
    258   * ``ReceiverHello`` <- (c\ :sub:`e`, r\ :sub:`R`, [SelectedAlgs])
    259   * **IHTS** <- *HKDF-Expand*\ (**HS**, "i hs traffic", ``InitiatorHello...ReceiverHello``)
    260   * **RHTS** <- *HKDF-Expand*\ (**HS**, "r hs traffic", ``InitiatorHello...ReceiverHello``)
    261   * ``ReceiverKemCiphertext`` <- *Enc*\ (**RHTS**, c\ :sub:`I`)
    262   * (Optional) ``EncryptedExtensions`` <- *Enc*\ (**RHTS**, SupportedAlgs/Services?)
    263 
    264 * Build ``ReceiverFinished`` message:
    265 
    266   * fk\ :sub:`R` <- *HKDF-Expand*\ (**MS**, "r finished", ``NULL``)
    267   * ``RF`` <- *HMAC*\ (fk\ :sub:`R`, ``InitiatorHello...ReceiverKemCiphertext``)
    268   * ``ReceiverFinished`` <- *Enc*\ (**RHTS**, ``RF``) (TLS1.3-style explicit authentication of receiver after 1RTT!)
    269 
    270 * Derive Application Traffic Encryption Key:
    271 
    272   * **RATS** <- *HKDF-Expand*\ (**MS**, "r ap traffic", ``InitiatorHello...ReceiverFinished``)
    273 
    274 
    275 Third Message (RTT=1.5) 
    276 """""""""""""""""""""""
    277 
    278 ``I`` receives:
    279 
    280 ``MessageHeader||ReceiverHello||EncryptedExtensions||ReceiverKemCiphertext||ReceiverFinished``
    281 
    282 and sends to ``I`` the following message:
    283 
    284 ``MessageHeader||IteratorFinished``
    285 
    286 The message may have already application payload appended, but in our case this again is unlikely.
    287 
    288 First ``I`` processes the message received from ``R``:
    289 
    290 * Verify that the message type is *TBD*
    291 
    292 * Setup Master Secret (cf. derivation in Second Message):
    293 
    294   * (ss\ :sub:`e`) <- *Decaps*\ (sk\ :sub:`e`, c\ :sub:`e`) (X25519 KEM)
    295 
    296   * **dES** <- *HKDF-Expand*\ (**ES**, ``"derived"``, ``NULL``)
    297   * **HS** <- *HKDF-Extract*\ (ss\ :sub:`e`, **dES**)
    298   * **dHS** <- *HKDF-Expand*\ (**HS**, "derived", ``NULL``)
    299   * (ss\ :sub:`I`) <- *Decaps*\ (sk\ :sub:`I`, c\ :sub:`I`) (EdDSA KEM)
    300   * **MS** <- *HKDF-Extract*\ (ss\ :sub:`I`, **dHS**)
    301 
    302 
    303 * Derive Traffic Encryption Keys (these can also be done as-needed and not necessarily all at once here):
    304 
    305   * **IHTS** <- *HKDF-Expand*\ (**HS**, "i hs traffic", ``InitiatorHello...ReceiverHello``)
    306   * **RHTS** <- *HKDF-Expand*\ (**HS**, "r hs traffic", ``InitiatorHello...ReceiverHello``)
    307   * **IATS** <- *HKDF-Expand*\ (**MS**, "i ap traffic", ``InitiatorHello...InitiatorFinished``)
    308   * **RATS** <- *HKDF-Expand*\ (**MS**, "r ap traffic", ``InitiatorHello...ReceiverFinished``)
    309 
    310 * Build ``ReceiverFinished`` and ``InitiatorFinished`` plain texts:
    311 
    312   * fk\ :sub:`I` <- *HKDF-Expand*\ (**MS**, "i finished", NULL)
    313   * ``IF`` <- *HMAC*\ (fk\ :sub:`I`, ``InitiatorHello...ReceiverFinished``)
    314   * fk\ :sub:`R` <- *HKDF-Expand*\ (**MS**, "r finished", NULL)
    315   * ``RF`` <- *Dec*\ (RHTS, ``ReceiverFinished``)
    316   * assert *HMAC*\ (fk\ :sub:`R`, ``InitiatorHello...ReceiverKemCiphertext``) == ``RF``
    317 
    318 * ``InitiatorFinished`` <- *Enc*\ (**IHTS**, ``IF``)
    319 
    320 
    321 Confirmation (RTT=1.5)
    322 """"""""""""""""""""""
    323 
    324 ``R`` receives ``IteratorFinished`` and computes:
    325 
    326 * ``IF`` <- *Dec*\ (IHTS, ``InitiatorFinished``)
    327 * fk\ :sub:`I` <- *HKDF-Expand*\ (**MS**, "i finished", ``NULL``)
    328 * assert *HMAC*\ (fk\ :sub:`I`, ``InitiatorHello...ReceiverFinished``) == ``IF``
    329 * **IATS** <- *HKDF-Expand*\ (**MS**, "i ap traffic", ``InitiatorHello...InitiatorFinished``)
    330 
    331 
    332 At this point we have a secure channel and application payload can be en/decrypted using **IATS** and **RATS**, respectively.
    333 
    334 Rekey / Service Status change
    335 """""""""""""""""""""""""""""
    336 
    337 TODO
    338 
    339 
    340 Edge Cases
    341 """"""""""
    342 
    343 * The Initiator/Receiver selection logic may require a timed fallback: The designates Initiator may never initiate (NAT, already has sufficient connections, learns about receiver later than receiver about initiator etc.)
    344 * This may result in edge cases where the Initiator initiates a handshake and the Receiver also initiates a handshake at the same time switching roles.
    345 * In such cases we may simply do both key exchanges. If both succeed, we drop the key exchange that was not initiated by the designated initiator on both peers. Otherwise we use the successful key exchange and the roles are swapped. 
    346 
    347 
    348 Glossary
    349 """"""""
    350 
    351   * **IATS**: Initiator Application Traffic Secret Key
    352   * **RATS**: Receiver Application Traffic Secret Key
    353   * **dES**: Derived Early Secret Key
    354   * **dHS**: Derived Handshake Key
    355   * **ES**: Early Secret Key
    356   * **ETS**: Early Traffic Secret Key
    357   * **HS**: Handshake Secret Key
    358   * **MS**: Main Secret Key
    359   * **ES**: Early Secret Key
    360   * **IHTS**: Initiator Handshake Secret Key
    361   * **RHTS**: Receiver Handshake Secret Key
    362   * ``Foo...Bar`` means the transcript of received/send messages from ``Foo`` until ``Bar``
    363   
    364 
    365 Unified Address Format for L2O and libp2p
    366 -----------------------------------------
    367 
    368 ..
    369   TODO
    370   libp2p peer-id multiaddress?, gnunet-hello
    371   https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md
    372   https://github.com/libp2p/specs/blob/master/addressing/README.md#multiaddr-basics
    373   https://docs.gnunet.org/latest/users/subsystems.html#hellos
    374   https://docs.gnunet.org/latest/users/subsystems.html#hello-ng
    375   https://docs.libp2p.io/concepts/fundamentals/addressing/
    376   https://github.com/multiformats/multiaddr/
    377 
    378 As a unified address format for L2O and libp2p we will use a concatenation of
    379 the string representations of gnunet's hellos and libp2p's multiaddress,
    380 separated by `;;`.
    381 For example: `gnunet://hello/XXPIDXX/XXPIDXX/1725622944?udp=%5B%3A%3A1%5D%3A2086&;;libp2p:///ip4/127.0.0.1/tcp/24915`
    382 
    383 This is only for the time being. For the long run the integration within each
    384 other's addressing schemes should be evaluated. Meaning: Integrate a
    385 gnunet-hello address type in libp2p's multiaddress format and integrate the
    386 multiaddress format with the gnunet-hello.
    387 
    388 
    389 .. _Peer-IDs:
    390 
    391 Peer IDs
    392 --------
    393 
    394 Peer ids stop to be unique for the lifetime of a peer, but change each time a
    395 peer's addresses change. This includes gaining or losing an address.
    396 
    397 It is important to note that this design choice only increases the cost of
    398 network location tracking and does not fully prevent it. For this feature onion
    399 routing on top of CADET is envisioned.
    400 
    401 At this point it seems like one has to weigh privacy versus performance when it
    402 comes to this design decision.
    403 
    404 .. _Reasoning:
    405 
    406 Reasoning
    407 ^^^^^^^^^
    408 
    409 ..
    410   	 - why this decision (and not others?)
    411   		 - (scenarios to understand whether it makes sense)
    412 
    413 This change was introduced in order to stop tracking of more mobile peers
    414 across the network. For example a more mobile peer (laptop) that logs into the
    415 network at different places can be easily tracked by everyone just by recording
    416 the different addresses that are tied to that peer id over time.
    417 
    418 ..
    419   TODO
    420    - why does this prevent tracking? (partially answered in the attacker
    421      model section below
    422    - tracking hellos of peer: visible
    423    - reverse mapping (address to peer?) not possible - there's no functionality
    424      for that
    425    - gaining/losing as criterium to change peer id makes sense?
    426 
    427 
    428 .. _Attacker-Model:
    429 
    430 Attacker Model
    431 """"""""""""""
    432 An attacker observes the hellos (containing ip and other addresses) published
    433 under a peer id and is thus capable of tracking locations and thus obtaining a
    434 movement profile of this peer.
    435 
    436 With the proposed changes to the peer id an attacker can only see a peer id and
    437 its connected set of addresses. A movement profile can not be obtained in the
    438 previous way.
    439 
    440 ..
    441   TODO how much info can be gained by that? all an observing peer sees is the
    442   ip addresses. how much can this tell?
    443   - mobile provider (implicit: mobile connection)
    444   - internet provider - home, company, public, ...
    445   - region (country, city, building, ...)
    446 
    447 Tracking of addresses/locations might still be possible in the scenario that a
    448 mobile client uses mobile broadband and wifi uplinks and uses them in an
    449 'overlapping' manner. (Switching on mobile broadband before leaving the range
    450 of a wifi hotspot and vice versa Turning off mobile broadband after connecting
    451 to a wifi.) For the 'overlapping' time the peer would publish a HELLO
    452 containing the old and the new network addresses. After the overlapping time,
    453 the peer's HELLO would just contain the new network address, which was already
    454 in the HELLO from during the 'overlap'. That way the overlap can be used to
    455 link the old and new address and - in extreme scenarios - obtain the full
    456 movement profile again. Note that this does not work on all, not all the time
    457 and requires work for the correlation. It should be highlighted that, although
    458 this attack is possible, the new design still greatly reduces the attack
    459 surface.
    460 
    461 A way to circumvent this anti-tracking mechanism would be for an attacker to
    462 exploit the means for consistently connect to the same peer.
    463 .. TODO wording/conceptualisation - overlap with next sentence
    464 For example with the means of higher-layer services like gns. With the
    465 knowledge of the gns entry, its peer ids and thus its addresses can be fully
    466 tracked. Until the existence of an onion-routing service and its decoupling of
    467 identities and network addresses, this behavior is probably intended and maybe
    468 the only way to connect endpoints. Although this leak is still existent the
    469 new design still prevents a lot of other leakage. Also it is important to point
    470 out that it is impossible to prevent leakage at higher layers, but necessary to
    471 prevent leakage at this layer, because leakage at this level could not be fixed
    472 at higher layers.
    473 
    474 .. TODO review for wording/clarity
    475 
    476 
    477 .. _Implications-PeerIDs:
    478 
    479 Implications
    480 ^^^^^^^^^^^^
    481 
    482 Here we present the implications for different parts of the framework. This
    483 should help get a grasp of the implications of the change.
    484 .. TODO poor phrasing?
    485 
    486 .. _DHT:
    487 
    488 DHT
    489 """
    490 
    491 The DHT uses the peer id such that it determines which buckets a peer is
    492 responsible for. So each time the peer id changes, the peer becomes responsible
    493 for different data. This means that each time a peer changes address, it leaves
    494 and re-enters the DHT, changes its and other peer's neighbors and changes the
    495 stored data.
    496 
    497 
    498 .. _Scope-of-Peer-ID-for-higher-Layers:
    499 
    500 Scope of Peer ID for higher Layers
    501 """"""""""""""""""""""""""""""""""
    502 
    503 When peer ids stop to be unique over time, the framework is in lack of a
    504 globally unique identifier. Higher layers may rely (have relied) on the
    505 uniqueness of the ids. This means gnunet has to use other means for this
    506 purpose. The Reconnects_ section below is concerned with the specific impact on
    507 reconnects for different higher-layer services. In general gns/identity offers
    508 this functionality.
    509 
    510 As peer ids cease to be unique over time, this might be a good point to review
    511 the scope of its and other elements' usage and terminology. (See
    512 Open_Design_Questions_)
    513 
    514 .. FIXME This section overlaps in scope with the next section.
    515 
    516 
    517 .. _Reconnects:
    518 
    519 Reconnects
    520 """"""""""
    521 
    522 When addresses (and with those the peer id) of a peer change, all core
    523 connections need to be torn down and with them all higher-layer connections.
    524 This affects the layers above CADET as follows:
    525 
    526  - Revocation: Is not really affected as it is only connected to direct CADET
    527    neighbors and makes no use of CADET's routing, only of its flow and
    528    congestion control.
    529  - File sharing: Only the non-anonymous filesharing uses CADET connections.
    530    This is not significantly affected by a reconnect as it only looks up peer
    531    and port in the DHT, so in the meanwhile it's looking for other peers. TODO
    532    this is very unclear to me!
    533  - Messenger: All CADET connections would break and the peer might assume that
    534    all previously connected peers went offline. So it would require a
    535    mechanism to reconnect to peers with a known peer identity which offer
    536    routing capability (open port via CADET to connect to). In case the peer
    537    itself is providing such capability, it would help to know about peer ID
    538    changes ahead of time to communicate a switch between IDs to other peers.
    539    For other reconnections via GNS lookups are required.
    540  - Conversation: The call would be interrupted until the new peer id of the
    541    other has been found (potentially via GNS).
    542 
    543 Open question: is gns needed for a reconnect? Could the peer with the new
    544 id not simply 'call back' the other peer? Of course this would only work if
    545 only one peer changes its peer id. If both change their peer id at the same
    546 time, an external mechanism would be needed.
    547 
    548 See Open_Design_Questions_ for thoughts on good designs to handle address
    549 changes more smoothly.
    550 
    551 
    552 .. _Messenger-Implications:
    553 
    554 Messenger
    555 """""""""
    556 
    557 The current implementation of messenger heavily relies on a globally unique
    558 peer id. The change requires messenger to account for peer id changes.
    559 
    560 
    561 .. _Details-on-how_PeerIDs:
    562 
    563 Details on how
    564 ^^^^^^^^^^^^^^
    565 
    566 Peer ids will be generated from the set of a peer's current addresses. Once a
    567 peer obtains the same set of addresses it shall be using the same peer id. To
    568 achieve this behavior, the current string representation of addresses is
    569 sorted, the sorted representation hashed and the peer id generated from the
    570 hash. We call the hash 'network generation hash'. The hash can be used to
    571 quickly identify and recognise a set of addresses that was used in the past.
    572 
    573 Once a peer id changes, all communication via open channels shall immediately
    574 cease. To signal this, the mq is to be used.
    575 To identify all queued messages that are to be cancelled, the 'network
    576 generation id' is used. (This was decided to be implemented as a simple counter
    577 of 64 bit.) With each address and peer id change, the network generation id is
    578 incremented. When enqueueing a message with the mq, the current generation id
    579 is stored with is. This way, when the generation id changes, all enqueued
    580 messages with the old id (which still might refer to the old peer id in some
    581 way) can be identified and dequeued. It is important to manage the network
    582 generation id as close to the communicators as possible to be able to stop the
    583 actual outgoing messages as quick as possible.
    584 
    585 To be more precise, the communication via open channels should not cease when
    586 the new peer id is available, but already when there's a change to the
    587 addresses in use. This means there is a small window, until the new peer id is
    588 generated, in which the peer is without peer id and thus without means to
    589 communicate. This might open a new attack window by trying to change the
    590 addresses of a peer via for example opening and closing wifi hotspots and
    591 sending out new addresses via dhcp.
    592 
    593 ..
    594   64 bit: similar size to pid/hash
    595 
    596 ..
    597    - adress bundle (transport communicators implement decision?)
    598    - I vaguely remember the talk of 'insignificant' address changes (within
    599      local network or such), that don't require a new peer id, but forgot the
    600      specifics.
    601 
    602 
    603 .. _Open-questions:
    604 
    605 Open questions
    606 ^^^^^^^^^^^^^^
    607 
    608 ..
    609   overall for this "peer id" section
    610   Notes from the meeting:
    611    - higher-layer roll-over
    612   	 - problem in practice 'phone call not interrupted by change of
    613   	   location'
    614   	 - solved by gns entries? and re-connect?
    615   	 - cadet search for peer id - search in dht and via gns
    616   	 - caching-problem for gns
    617   	 - no signaling for roll-over
    618   	 - estimated reconnect within 15 minutes
    619   	 - change of address/peerid results in unclear state (down? lost
    620   	   connection, ....?)
    621   	 - cadet needs to regularily check gns entries
    622    - how signal the change of addresses?
    623   	 - do we signal trear-down?
    624   	 - scenario address change in internet cafe?
    625   	 - choice between privacy and connectivity
    626   	 - sense of changing ids for cadet?
    627   		 - -> rendez-vous peer (more stable)
    628   	 - tracking via gns?
    629   		 - only for people who are connected/known (tracking might be
    630   		   ok for this)
    631   			 - requires pir for gns
    632   		 - tracking impossible/hard for others
    633 
    634 
    635 .. _Ownership-of-Peer-IDs:
    636 
    637 Ownership of Peer IDs
    638 ^^^^^^^^^^^^^^^^^^^^^
    639 
    640 When the peer id was static, all parts of gnunet had a simple way to interface
    641 with it. Once it becomes dynamic, it makes a lot of sense that a single part
    642 takes control/responsibility/ownership for it. A new service is created for
    643 this purpose. A name suggestion was "peer id lifecycle service" - PILS.
    644 
    645 The reasons for this new service:
    646 
    647  - Good encapsulation (which is even more important as it is a component deals
    648    with crucial cryptographic operation).
    649  - Avoidance of circular subscriptions of core and transport.
    650  - Avoidance of callback api hell between core and transport.
    651  - Using peerstore for this would be really messy.
    652 
    653 The reasons against this new service:
    654  - Having yet another service.
    655 
    656 Core will be the responsible service to provide addresses to pils for the
    657 switching of peer ids.
    658 
    659 Peer ids should not be stored in permanent memory (on disk), but kept in
    660 working memory.
    661 They will be (re-) computed from the new set of addresses. The advantage is
    662 that it is not possible to prove that a peer id belonged to a peer by
    663 examining its hard-drive. Keeping the respective HELLO in the peerstore is fine
    664 as a peer also keeps other peer's hello in there and the existence of a hello
    665 in the peerstore proves nothing.
    666 
    667 
    668 .. _Implications-onwnership_PeerIDs:
    669 
    670 Implications
    671 ^^^^^^^^^^^^
    672 
    673 Pils needs to take ownership. It is responsible for generating, changing of
    674 peer ids, informing subscribers of changes and signing with the current peer
    675 id. (To be gentle on the ipc, it should not sign big amounts of data - if
    676 applicable rather hashes of data or such.)
    677 
    678 
    679 .. _Transport:
    680 
    681 Transport
    682 """""""""
    683 
    684 Up until now transport still creates, signs and puts hellos into the peerstore.
    685 When pils takes ownership of peer ids, transport will need to ask it for
    686 signing the hellos before putting it into the peerstore. (With libp2p as
    687 alternative/additional underlay in mind, everything related to hellos needs to
    688 move to core eventually as libp2p is oblivious about that part of gnunet. Core
    689 will have to create and provide the hellos. See libp2p-Underlay_ below.)
    690 
    691 
    692 .. _Other:
    693 
    694 Other
    695 """""
    696 
    697 Generally, all parts that so far read the peer id from a file into local
    698 memory, will need to ask pils for it. All services that sign/encrypt something
    699 with the peer id now will need to ask pils to do it.
    700 
    701 
    702 .. _Details-on-how_ownership_PeerIDs:
    703 
    704 Details on how
    705 ^^^^^^^^^^^^^^
    706 
    707 In order to provide the needed functionality, pils needs to expose it via its
    708 api:
    709 
    710  - a call to provide the current set of addresses, so the generation of the
    711    peer id can be triggered.
    712  - a call to obtain the current peer id
    713  - registering a handler that informs about new peer ids
    714  - signing data with the peer id
    715 
    716 
    717 
    718 .. _libp2p-Underlay:
    719 
    720 libp2p Underlay
    721 ---------------
    722 
    723 Get gnunet to work on libp2p. This includes the FFI with rust (or binding to
    724 implementations in other languages), converting address formats, signaling
    725 metadata (traffic class and priority, as far as libp2p supports it) and
    726 signalling connectivity changes.  This is a first attempt to technically link
    727 the two projects. Therefore the feasibility is quite uncertain and the
    728 milestones might have to be re-evaluated after the report on the needs and
    729 feasibility. Should it turn out that the needed resources are beyond the
    730 capabilities of this project, a detailed report on the requirements and roadmap
    731 of and for the realisation shall be written and published.
    732 
    733 For a lot of practical purposes it would be a lot easier to add a new
    734 communicator for libp2p instead of integrating it as an underlay below core,
    735 next to transport. The downside would be that there might be a lot of
    736 duplication of functionality.
    737 
    738 ..
    739   TODO this generally needs more love
    740 
    741 ..
    742   - addresses from underlay in string representation go into core
    743   - libp2p can't handle hellos/peerstore
    744   - address signaling between transport and core
    745   - hellos should be handled by core
    746 
    747 
    748 .. _Protocol_002dVersioning:
    749 
    750 Protocol-Versioning
    751 -------------------
    752 
    753 Currently applications signal to core which message types they support. For
    754 this milestone we will implement proper protocol versioning where higher-level
    755 applications can signal a range of protocol versions which they support (min,
    756 max) and exchange messages at the CONG layer between peers to determine common
    757 protocols.
    758 
    759 
    760 
    761 .. _Open_Design_Questions:
    762 
    763 Open Design Questions
    764 ---------------------
    765 
    766 In this section we list design question that are not decided on, yet.
    767 
    768 ..
    769  - scope of peer ids and other such elements (gns/identity, ...)
    770  - resolve gns to pid on lower layer? (cadet or even core)
    771     - convenience api: cadet connection to domain name
    772     - -> not the scope of cong
    773 
    774 
    775 .. _Peer-ID-changes-and-connectivity:
    776 
    777 Peer ID changes and connectivity
    778 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    779 
    780 ..
    781  - smooth handling of address/pid change possible?/signaling change of address
    782     - should be possible at least when we gain one address
    783     - construct that allows an additional peer id that is pre-computed (not
    784       based on addresses) and announced ahead of address change?
    785     - other terminology: provide tracking capability selectively
    786     - use peer ids as long as there are open connections with them?
    787 
    788 In case a peer's addresses change, it gets a new peer id and therefor needs to
    789 reconnect. The challenge is to reconnect as fast as possible. The main problem
    790 is that a peer cannot know its next peer id in all cases. Connections that have
    791 dedicated peers at its endpoints will probably look up the new peer id of the
    792 other peer in a higher-layer service, most probably gns.
    793 
    794 In the case in which a peer just gains an additional address, that peer can
    795 pre-calculate its next peer id, signal it via still open connections on the old
    796 peer id and finally switch to using the new peer id.
    797 
    798 Other more evolved ideas include using multiple peer ids per peer: Either an
    799 additional address-independent peer id that will 'survive' address changes and
    800 serve as means to link to the address-based peer id after a change. It would
    801 just be sent to connected peers and reset once all connections have been
    802 re-established.
    803 
    804 Alternatively (maybe in addition) peers could use multiple address-based peer
    805 ids - one per address. Thus some peer ids might stay unchanged while others go
    806 offline.
    807 
    808 ..
    809     - tracking even harder
    810     - comes closer to equivalent of ip addresses
    811     - possibly helps with (privacy-preserving) roll-overs
    812     - we ceased having unique peer ids over time, why not cease to have a
    813       single address at a time?
    814     - might serve as an 'onion-address light'?
    815     - cleaner, less messy abstraction
    816 
    817 
    818 Another idea to address this challenge is to keep peer ids in use on
    819 connections which are still in use, but don't publish those ids anymore.
    820 
    821 Terminology-wise we might add another perspective and say that we selectively
    822 and deliberately provide tracking capability to peers which we want to stay in
    823 touch with.
    824 
    825 
    826 .. _Peer-ID-Terminology:
    827 
    828 Peer ID Terminology
    829 ^^^^^^^^^^^^^^^^^^^
    830 
    831 Once peer ids cease to be unique over time the question raises whether they
    832 should actually be called identities. (In my intuition an identity is something
    833 more persistent.)
    834 As we discuss peer ids as an analogue to ip addresses, a natural close idea
    835 would be to use "peer address".
    836 
    837 
    838 .. _Requirements:
    839 
    840 
    841 Requirements
    842 ------------
    843 
    844 In the discussions we seem to have lost partial oversight over things.
    845 In this section we figure out the requirements for core (and possibly other
    846 components) it's mechanisms.
    847 
    848 TODO: what requirements exactly did we want to document here?
    849 
    850 
    851 .. _Use-Cases-and-Scenarios:
    852 
    853 Use Cases and Scenarios
    854 -----------------------
    855 
    856 This section is supposed to help with the understanding of the use of elements
    857 and structures by imagined examples.
    858 
    859 
    860 .. _Peer-ID:
    861 
    862 Peer ID
    863 ^^^^^^^
    864 
    865 The peer id has been used throughout gnunet as a very convenient means for many
    866 purposes. It was used as globally unique and stable identifier of a peer. From
    867 now on it should rather be treated as something more volatile and fitting for
    868 its layer: an ip address. Below we collect the intended purposes and use cases
    869 and also point out some uses for which it was not intended and point to other
    870 means to achieve it.
    871 
    872 ..
    873    - address change: shutdown vs. standby vs. ...
    874 
    875 
    876 .. _GNS:
    877 
    878 GNS
    879 ^^^
    880 
    881 TODO
    882 
    883 ..
    884   - identify on user level
    885   - vpn record: globally unique id
    886 
    887 
    888 .. _CADET:
    889 
    890 CADET
    891 ^^^^^
    892 
    893 TODO
    894 
    895 
    896 .. _Messenger-scenarios:
    897 
    898 Messenger
    899 ^^^^^^^^^
    900 
    901 TODO
    902 
    903 ..
    904   TODO 'tracking capability' via gns: shared secret
    905    - this a good place?
    906    - understand how that would work
    907    - hide multiple devices behind one identity
    908 
    909 
    910 ..
    911   TODO Overall: Look at the project milestones to check coverage