rns 1.3.0__tar.gz → 1.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. {rns-1.3.0 → rns-1.3.2}/PKG-INFO +1 -1
  2. {rns-1.3.0 → rns-1.3.2}/RNS/Discovery.py +1 -1
  3. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/WeaveInterface.py +2 -2
  4. {rns-1.3.0 → rns-1.3.2}/RNS/Link.py +17 -14
  5. {rns-1.3.0 → rns-1.3.2}/RNS/Reticulum.py +31 -6
  6. {rns-1.3.0 → rns-1.3.2}/RNS/Transport.py +10 -8
  7. rns-1.3.2/RNS/Utilities/rngit/commitsigs.py +324 -0
  8. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rngit/pages.py +99 -6
  9. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rngit/server.py +24 -4
  10. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnid.py +2 -3
  11. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnsd.py +11 -0
  12. {rns-1.3.0 → rns-1.3.2}/RNS/__init__.py +3 -2
  13. rns-1.3.2/RNS/_version.py +1 -0
  14. {rns-1.3.0 → rns-1.3.2}/rns.egg-info/PKG-INFO +1 -1
  15. {rns-1.3.0 → rns-1.3.2}/rns.egg-info/SOURCES.txt +1 -0
  16. {rns-1.3.0 → rns-1.3.2}/rns.egg-info/entry_points.txt +1 -0
  17. {rns-1.3.0 → rns-1.3.2}/setup.py +1 -0
  18. rns-1.3.0/RNS/_version.py +0 -1
  19. {rns-1.3.0 → rns-1.3.2}/CRNS/__init__.py +0 -0
  20. {rns-1.3.0 → rns-1.3.2}/README.md +0 -0
  21. {rns-1.3.0 → rns-1.3.2}/RNS/Buffer.py +0 -0
  22. {rns-1.3.0 → rns-1.3.2}/RNS/Channel.py +0 -0
  23. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/AES.py +0 -0
  24. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/Ed25519.py +0 -0
  25. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/HKDF.py +0 -0
  26. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/HMAC.py +0 -0
  27. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/Hashes.py +0 -0
  28. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/PKCS7.py +0 -0
  29. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/Provider.py +0 -0
  30. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/Proxies.py +0 -0
  31. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/SHA256.py +0 -0
  32. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/SHA512.py +0 -0
  33. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/Token.py +0 -0
  34. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/X25519.py +0 -0
  35. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/__init__.py +0 -0
  36. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/aes/__init__.py +0 -0
  37. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/aes/aes128.py +0 -0
  38. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/aes/aes256.py +0 -0
  39. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/pure25519/__init__.py +0 -0
  40. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/pure25519/_ed25519.py +0 -0
  41. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/pure25519/basic.py +0 -0
  42. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/pure25519/ed25519_oop.py +0 -0
  43. {rns-1.3.0 → rns-1.3.2}/RNS/Cryptography/pure25519/eddsa.py +0 -0
  44. {rns-1.3.0 → rns-1.3.2}/RNS/Destination.py +0 -0
  45. {rns-1.3.0 → rns-1.3.2}/RNS/Identity.py +0 -0
  46. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/AX25KISSInterface.py +0 -0
  47. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/Android/KISSInterface.py +0 -0
  48. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/Android/RNodeInterface.py +0 -0
  49. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/Android/SerialInterface.py +0 -0
  50. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/Android/__init__.py +0 -0
  51. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/AutoInterface.py +0 -0
  52. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/BackboneInterface.py +0 -0
  53. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/I2PInterface.py +0 -0
  54. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/Interface.py +0 -0
  55. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/KISSInterface.py +0 -0
  56. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/LocalInterface.py +0 -0
  57. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/PipeInterface.py +0 -0
  58. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/RNodeInterface.py +0 -0
  59. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/RNodeMultiInterface.py +0 -0
  60. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/SerialInterface.py +0 -0
  61. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/TCPInterface.py +0 -0
  62. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/UDPInterface.py +0 -0
  63. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/__init__.py +0 -0
  64. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/util/__init__.py +0 -0
  65. {rns-1.3.0 → rns-1.3.2}/RNS/Interfaces/util/netinfo.py +0 -0
  66. {rns-1.3.0 → rns-1.3.2}/RNS/Packet.py +0 -0
  67. {rns-1.3.0 → rns-1.3.2}/RNS/Resolver.py +0 -0
  68. {rns-1.3.0 → rns-1.3.2}/RNS/Resource.py +0 -0
  69. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/__init__.py +0 -0
  70. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rncp.py +0 -0
  71. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rngit/__init__.py +0 -0
  72. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rngit/client.py +0 -0
  73. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rngit/highlight.py +0 -0
  74. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rngit/main.py +0 -0
  75. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rngit/util.py +0 -0
  76. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnir.py +0 -0
  77. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnodeconf.py +0 -0
  78. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnpath.py +0 -0
  79. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnpkg.py +0 -0
  80. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnprobe.py +0 -0
  81. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnsh/__init__.py +0 -0
  82. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnsh/_version.py +0 -0
  83. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnsh/args.py +0 -0
  84. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnsh/exception.py +0 -0
  85. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnsh/helpers.py +0 -0
  86. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnsh/initiator.py +0 -0
  87. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnsh/listener.py +0 -0
  88. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnsh/loop.py +0 -0
  89. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnsh/process.py +0 -0
  90. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnsh/protocol.py +0 -0
  91. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnsh/retry.py +0 -0
  92. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnsh/rnsh.py +0 -0
  93. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnsh/session.py +0 -0
  94. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnstatus.py +0 -0
  95. {rns-1.3.0 → rns-1.3.2}/RNS/Utilities/rnx.py +0 -0
  96. {rns-1.3.0 → rns-1.3.2}/RNS/vendor/__init__.py +0 -0
  97. {rns-1.3.0 → rns-1.3.2}/RNS/vendor/configobj.py +0 -0
  98. {rns-1.3.0 → rns-1.3.2}/RNS/vendor/i2plib/__init__.py +0 -0
  99. {rns-1.3.0 → rns-1.3.2}/RNS/vendor/i2plib/__version__.py +0 -0
  100. {rns-1.3.0 → rns-1.3.2}/RNS/vendor/i2plib/aiosam.py +0 -0
  101. {rns-1.3.0 → rns-1.3.2}/RNS/vendor/i2plib/exceptions.py +0 -0
  102. {rns-1.3.0 → rns-1.3.2}/RNS/vendor/i2plib/log.py +0 -0
  103. {rns-1.3.0 → rns-1.3.2}/RNS/vendor/i2plib/sam.py +0 -0
  104. {rns-1.3.0 → rns-1.3.2}/RNS/vendor/i2plib/tunnel.py +0 -0
  105. {rns-1.3.0 → rns-1.3.2}/RNS/vendor/i2plib/utils.py +0 -0
  106. {rns-1.3.0 → rns-1.3.2}/RNS/vendor/platformutils.py +0 -0
  107. {rns-1.3.0 → rns-1.3.2}/RNS/vendor/umsgpack.py +0 -0
  108. {rns-1.3.0 → rns-1.3.2}/RNS/vendor/validate.py +0 -0
  109. {rns-1.3.0 → rns-1.3.2}/rns.egg-info/dependency_links.txt +0 -0
  110. {rns-1.3.0 → rns-1.3.2}/rns.egg-info/requires.txt +0 -0
  111. {rns-1.3.0 → rns-1.3.2}/rns.egg-info/top_level.txt +0 -0
  112. {rns-1.3.0 → rns-1.3.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rns
3
- Version: 1.3.0
3
+ Version: 1.3.2
4
4
  Summary: Self-configuring, encrypted and resilient mesh networking stack for LoRa, packet radio, WiFi and everything in between
5
5
  Home-page: https://reticulum.network/
6
6
  Author: Mark Qvist
@@ -746,7 +746,7 @@ class BlackholeUpdater():
746
746
  if identity_hash in self.last_updates: last_update = self.last_updates[identity_hash]
747
747
  else: last_update = 0
748
748
 
749
- if now > last_update+self.UPDATE_INTERVAL:
749
+ if now > last_update+RNS.Reticulum.blackhole_update_interval():
750
750
  try:
751
751
  destination_hash = RNS.Destination.hash_from_name_and_identity("rnstransport.info.blackhole", identity_hash)
752
752
  RNS.log(f"Attempting blackhole list update from {RNS.prettyhexrep(identity_hash)}...", RNS.LOG_DEBUG)
@@ -775,8 +775,8 @@ class WeaveDevice():
775
775
  self.cpu_load = frame.data[0]
776
776
  self.capture_stats_cpu()
777
777
  elif frame.event == Evt.ET_STAT_MEMORY:
778
- self.memory_free = int.from_bytes(frame.data[:4])
779
- self.memory_total = int.from_bytes(frame.data[4:])
778
+ self.memory_free = int.from_bytes(frame.data[:4], "big")
779
+ self.memory_total = int.from_bytes(frame.data[4:], "big")
780
780
  self.memory_used = self.memory_total-self.memory_free
781
781
  self.memory_used_pct = round((self.memory_used/self.memory_total)*100, 2)
782
782
  self.capture_stats_memory()
@@ -903,21 +903,21 @@ class Link:
903
903
  identity_string = str(self.get_remote_identity()) if self.get_remote_identity() != None else "<Unknown>"
904
904
  RNS.log("Request "+RNS.prettyhexrep(request_id)+" from "+identity_string+" not allowed for: "+str(path), RNS.LOG_DEBUG)
905
905
 
906
- def handle_response(self, request_id, response_data, response_size, response_transfer_size, metadata=None):
906
+ def handle_response(self, request_id, response_data, response_size, response_transfer_size, metadata=None, update_sizes=False):
907
907
  if self.status == Link.ACTIVE:
908
908
  remove = None
909
909
  for pending_request in self.pending_requests:
910
910
  if pending_request.request_id == request_id:
911
911
  remove = pending_request
912
912
  try:
913
- pending_request.response_size = response_size
914
- if pending_request.response_transfer_size == None:
915
- pending_request.response_transfer_size = 0
916
- pending_request.response_transfer_size += response_transfer_size
913
+ if update_sizes:
914
+ pending_request.response_size = response_size
915
+ if pending_request.response_transfer_size == None: pending_request.response_transfer_size = 0
916
+ pending_request.response_transfer_size += response_transfer_size
917
+
917
918
  pending_request.response_received(response_data, metadata)
918
- except Exception as e:
919
- RNS.log("Error occurred while handling response. The contained exception was: "+str(e), RNS.LOG_ERROR)
920
919
 
920
+ except Exception as e: RNS.log("Error occurred while handling response. The contained exception was: "+str(e), RNS.LOG_ERROR)
921
921
  break
922
922
 
923
923
  if remove != None:
@@ -1018,12 +1018,15 @@ class Link:
1018
1018
  identity.load_public_key(public_key)
1019
1019
 
1020
1020
  if identity.validate(signature, signed_data):
1021
- self.__remote_identity = identity
1022
- if self.callbacks.remote_identified != None:
1023
- try:
1024
- self.callbacks.remote_identified(self, self.__remote_identity)
1025
- except Exception as e:
1026
- RNS.log("Error while executing remote identified callback from "+str(self)+". The contained exception was: "+str(e), RNS.LOG_ERROR)
1021
+ if RNS.Reticulum.get_instance().is_blackholed(identity.hash):
1022
+ RNS.log(f"Terminating incoming link from blackholed identity {RNS.prettyhexrep(identity.hash)}", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
1023
+ self.teardown()
1024
+
1025
+ else:
1026
+ self.__remote_identity = identity
1027
+ if self.callbacks.remote_identified != None:
1028
+ try: self.callbacks.remote_identified(self, self.__remote_identity)
1029
+ except Exception as e: RNS.log(f"Error while executing remote identified callback from {self}. The contained exception was: "+str(e), RNS.LOG_ERROR)
1027
1030
 
1028
1031
  self.__update_phy_stats(packet, query_shared=True)
1029
1032
 
@@ -1047,7 +1050,7 @@ class Link:
1047
1050
  request_id = unpacked_response[0]
1048
1051
  response_data = unpacked_response[1]
1049
1052
  transfer_size = len(umsgpack.packb(response_data))-2
1050
- def job(): self.handle_response(request_id, response_data, transfer_size, transfer_size)
1053
+ def job(): self.handle_response(request_id, response_data, transfer_size, transfer_size, update_sizes=True)
1051
1054
  threading.Thread(target=job, daemon=True).start()
1052
1055
  self.__update_phy_stats(packet, query_shared=True)
1053
1056
  except Exception as e:
@@ -260,6 +260,7 @@ class Reticulum:
260
260
  Reticulum.__autoconnect_discovered_interfaces = False
261
261
  Reticulum.__required_discovery_value = None
262
262
  Reticulum.__publish_blackhole = False
263
+ Reticulum.__blackhole_update_interval = RNS.Discovery.BlackholeUpdater.UPDATE_INTERVAL
263
264
  Reticulum.__blackhole_sources = []
264
265
  Reticulum.__interface_sources = []
265
266
  Reticulum.__default_ar_target = None
@@ -452,12 +453,12 @@ class Reticulum:
452
453
  value = self.config["logging"][option]
453
454
  if option == "loglevel" and self.requested_loglevel == None:
454
455
  RNS.loglevel = int(value)
455
- if self.requested_verbosity != None:
456
- RNS.loglevel += self.requested_verbosity
457
- if RNS.loglevel < 0:
458
- RNS.loglevel = 0
459
- if RNS.loglevel > 7:
460
- RNS.loglevel = 7
456
+ if self.requested_verbosity != None: RNS.loglevel += self.requested_verbosity
457
+ if RNS.loglevel < 0: RNS.loglevel = 0
458
+ if RNS.loglevel > 7: RNS.loglevel = 7
459
+ elif option == "logtimestamps":
460
+ value = self.config["logging"].as_bool(option)
461
+ RNS.logtimestamps = bool(value)
461
462
 
462
463
  if "reticulum" in self.config:
463
464
  for option in self.config["reticulum"]:
@@ -581,6 +582,11 @@ class Reticulum:
581
582
  except Exception as e: raise ValueError(f"Invalid identity hash for remote blackhole source: {hexhash}")
582
583
  if not source_identity_hash in Reticulum.__blackhole_sources: Reticulum.__blackhole_sources.append(source_identity_hash)
583
584
 
585
+ if option == "blackhole_update_interval":
586
+ v = self.config["reticulum"].as_float(option)
587
+ if v < 2: v = 2
588
+ Reticulum.__blackhole_update_interval = v*60
589
+
584
590
  if option == "interface_discovery_sources":
585
591
  v = self.config["reticulum"].as_list(option)
586
592
  for hexhash in v:
@@ -1196,6 +1202,7 @@ class Reticulum:
1196
1202
  if path == "packet_snr": rpc_connection.send(self.get_packet_snr(call["packet_hash"]))
1197
1203
  if path == "packet_q": rpc_connection.send(self.get_packet_q(call["packet_hash"]))
1198
1204
  if path == "blackholed_identities": rpc_connection.send(self.get_blackholed_identities())
1205
+ if path == "is_blackholed": rpc_connection.send(self.is_blackholed(call["identity_hash"]))
1199
1206
 
1200
1207
  if "drop" in call:
1201
1208
  path = call["drop"]
@@ -1673,6 +1680,20 @@ class Reticulum:
1673
1680
 
1674
1681
  else: return RNS.Transport.blackholed_identities
1675
1682
 
1683
+ def is_blackholed(self, identity):
1684
+ if type(identity) == RNS.Identity: identity_hash = identity.hash
1685
+ elif type(identity) == bytes: identity_hash = identity
1686
+ else: raise TypeError("Invalid identity for blackhole check, must be hash as bytes or RNS.Identity")
1687
+ if len(identity_hash) != RNS.Reticulum.TRUNCATED_HASHLENGTH//8: raise ValueError("Invalid identity hash length for blackhole check")
1688
+
1689
+ if self.is_connected_to_shared_instance:
1690
+ rpc_connection = self.get_rpc_client()
1691
+ rpc_connection.send({"get": "is_blackholed", "identity_hash": identity_hash})
1692
+ response = rpc_connection.recv()
1693
+ return response
1694
+
1695
+ else: return identity_hash in RNS.Transport.blackholed_identities
1696
+
1676
1697
  def blackhole_identity(self, identity_hash, until=None, reason=None):
1677
1698
  if len(identity_hash) != RNS.Reticulum.TRUNCATED_HASHLENGTH//8: return False
1678
1699
  else:
@@ -1779,6 +1800,10 @@ class Reticulum:
1779
1800
  """
1780
1801
  return Reticulum.__blackhole_sources
1781
1802
 
1803
+ @staticmethod
1804
+ def blackhole_update_interval():
1805
+ return Reticulum.__blackhole_update_interval
1806
+
1782
1807
  @staticmethod
1783
1808
  def discovered_interfaces():
1784
1809
  """
@@ -212,6 +212,7 @@ class Transport:
212
212
  @staticmethod
213
213
  def start(reticulum_instance):
214
214
  Transport.owner = reticulum_instance
215
+ Transport.PR_LOGLEVEL = RNS.LOG_EXTREME
215
216
 
216
217
  if Transport.identity == None:
217
218
  transport_identity_path = RNS.Reticulum.storagepath+"/transport_identity"
@@ -289,6 +290,7 @@ class Transport:
289
290
  if RNS.Reticulum.transport_enabled():
290
291
  path_table_path = RNS.Reticulum.storagepath+"/destination_table"
291
292
  tunnel_table_path = RNS.Reticulum.storagepath+"/tunnels"
293
+ Transport.PR_LOGLEVEL = RNS.LOG_DEBUG
292
294
 
293
295
  if os.path.isfile(path_table_path) and not Transport.owner.is_connected_to_shared_instance:
294
296
  serialised_destinations = []
@@ -805,7 +807,7 @@ class Transport:
805
807
  if time.time() > entry["timeout"]:
806
808
  stale_discovery_path_requests.append(destination_hash)
807
809
  should_collect = True
808
- RNS.log("Waiting path request for "+RNS.prettyhexrep(destination_hash)+" timed out and was removed", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
810
+ RNS.log("Waiting path request for "+RNS.prettyhexrep(destination_hash)+" timed out and was removed", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None
809
811
 
810
812
  # Cull the tunnel table
811
813
  stale_tunnels = []; ti = 0
@@ -1984,7 +1986,7 @@ class Transport:
1984
1986
 
1985
1987
  interface_str = " on "+str(attached_interface)
1986
1988
 
1987
- RNS.log("Got matching announce, answering waiting discovery path request for "+RNS.prettyhexrep(packet.destination_hash)+interface_str, RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
1989
+ RNS.log("Got matching announce, answering waiting discovery path request for "+RNS.prettyhexrep(packet.destination_hash)+interface_str, Transport.PR_LOGLEVEL) if RNS.sl(Transport.PR_LOGLEVEL) else None
1988
1990
  announce_identity = RNS.Identity.recall(packet.destination_hash, _no_use=False)
1989
1991
  announce_destination = RNS.Destination(announce_identity, RNS.Destination.OUT, RNS.Destination.SINGLE, "unknown", "unknown");
1990
1992
  announce_destination.hash = packet.destination_hash
@@ -2902,7 +2904,7 @@ class Transport:
2902
2904
  tag=tag_bytes)
2903
2905
 
2904
2906
  else: RNS.log("Ignoring duplicate path request for "+RNS.prettyhexrep(destination_hash)+" with tag "+RNS.prettyhexrep(unique_tag), RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None
2905
- else: RNS.log("Ignoring tagless path request for "+RNS.prettyhexrep(destination_hash), RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
2907
+ else: RNS.log("Ignoring tagless path request for "+RNS.prettyhexrep(destination_hash), Transport.PR_LOGLEVEL) if RNS.sl(Transport.PR_LOGLEVEL) else None
2906
2908
  except Exception as e: RNS.log(f"Error while handling path request. The contained exception was: {e}", RNS.LOG_ERROR)
2907
2909
 
2908
2910
  @staticmethod
@@ -2917,7 +2919,7 @@ class Transport:
2917
2919
 
2918
2920
  if RNS.sl(RNS.LOG_DEBUG):
2919
2921
  interface_str = f" on {attached_interface}"
2920
- RNS.log(f"Path request for {RNS.prettyhexrep(destination_hash)}{interface_str}", RNS.LOG_DEBUG)
2922
+ RNS.log(f"Path request for {RNS.prettyhexrep(destination_hash)}{interface_str}", Transport.PR_LOGLEVEL)
2921
2923
 
2922
2924
  destination_exists_on_local_client = False
2923
2925
  if len(Transport.local_client_interfaces) > 0:
@@ -2962,7 +2964,7 @@ class Transport:
2962
2964
  # convergence time. Maybe just drop it?
2963
2965
  RNS.log("Not answering path request for "+RNS.prettyhexrep(destination_hash)+interface_str+", since next hop is the requestor", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
2964
2966
  else:
2965
- RNS.log("Answering path request for "+RNS.prettyhexrep(destination_hash)+interface_str+", path is known", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
2967
+ RNS.log("Answering path request for "+RNS.prettyhexrep(destination_hash)+interface_str+", path is known", Transport.PR_LOGLEVEL) if RNS.sl(Transport.PR_LOGLEVEL) else None
2966
2968
 
2967
2969
  now = time.time()
2968
2970
  retries = Transport.PATHFINDER_R
@@ -3004,7 +3006,7 @@ class Transport:
3004
3006
  elif is_from_local_client:
3005
3007
  # Forward path request on all interfaces
3006
3008
  # except the local client
3007
- RNS.log("Forwarding path request from local client for "+RNS.prettyhexrep(destination_hash)+interface_str+" to all other interfaces", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
3009
+ RNS.log("Forwarding path request from local client for "+RNS.prettyhexrep(destination_hash)+interface_str+" to all other interfaces", Transport.PR_LOGLEVEL) if RNS.sl(Transport.PR_LOGLEVEL) else None
3008
3010
  request_tag = RNS.Identity.get_random_hash()
3009
3011
  for interface in Transport.interfaces:
3010
3012
  if not interface == attached_interface:
@@ -3041,12 +3043,12 @@ class Transport:
3041
3043
  elif not is_from_local_client and len(Transport.local_client_interfaces) > 0:
3042
3044
  # Forward the path request on all local
3043
3045
  # client interfaces
3044
- RNS.log("Forwarding path request for "+RNS.prettyhexrep(destination_hash)+interface_str+" to local clients", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
3046
+ RNS.log("Forwarding path request for "+RNS.prettyhexrep(destination_hash)+interface_str+" to local clients", Transport.PR_LOGLEVEL) if RNS.sl(Transport.PR_LOGLEVEL) else None
3045
3047
  for interface in Transport.local_client_interfaces:
3046
3048
  Transport.request_path(destination_hash, on_interface=interface)
3047
3049
 
3048
3050
  else:
3049
- RNS.log("Ignoring path request for "+RNS.prettyhexrep(destination_hash)+interface_str+", no path known", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
3051
+ RNS.log("Ignoring path request for "+RNS.prettyhexrep(destination_hash)+interface_str+", no path known", Transport.PR_LOGLEVEL) if RNS.sl(Transport.PR_LOGLEVEL) else None
3050
3052
 
3051
3053
  @staticmethod
3052
3054
  def from_local_client(packet):
@@ -0,0 +1,324 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Reticulum License
4
+ #
5
+ # Copyright (c) 2016-2026 Mark Qvist
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # - The Software shall not be used in any kind of system which includes amongst
15
+ # its functions the ability to purposefully do harm to human beings.
16
+ #
17
+ # - The Software shall not be used, directly or indirectly, in the creation of
18
+ # an artificial intelligence, machine learning or language model training
19
+ # dataset, including but not limited to any use that contributes to the
20
+ # training or development of such a model or algorithm.
21
+ #
22
+ # - The above copyright notice and this permission notice shall be included in
23
+ # all copies or substantial portions of the Software.
24
+ #
25
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ # SOFTWARE.
32
+
33
+ import os
34
+ import sys
35
+ import RNS
36
+ import struct
37
+ import base64
38
+ import argparse
39
+
40
+ from RNS.Utilities.rnid import validate_rsg, create_rsg, extract_signed_rsg_data
41
+
42
+ SSHSIG_MAGIC = b"SSHSIG"
43
+ SSHSIG_VERSION = 1
44
+ NAMESPACE_GIT = b"git"
45
+ RESERVED_EMPTY = b""
46
+ HASH_ALGORITHM = b"sha256"
47
+
48
+ def ssh_string(data): return struct.pack(">I", len(data)) + data
49
+
50
+ def read_ssh_string(data, offset):
51
+ if offset + 4 > len(data): raise ValueError("Not enough data for string length")
52
+ length = struct.unpack(">I", data[offset:offset+4])[0]
53
+ if offset + 4 + length > len(data): raise ValueError("Not enough data for string content")
54
+ return data[offset+4:offset+4+length], offset + 4 + length
55
+
56
+ def create_ssh_signature(public_key_wire, namespace, reserved, hash_algorithm, signature_data):
57
+ # SSHSIG (6 bytes) || version (uint32) || pubkey (ssh-string) || namespace (ssh-string) ||
58
+ # reserved (ssh-string) || hash_algorithm (ssh-string) || signature (ssh-string)
59
+ sig_blob = SSHSIG_MAGIC
60
+ sig_blob += struct.pack(">I", SSHSIG_VERSION)
61
+ sig_blob += ssh_string(public_key_wire)
62
+ sig_blob += ssh_string(namespace)
63
+ sig_blob += ssh_string(reserved)
64
+ sig_blob += ssh_string(hash_algorithm)
65
+ sig_blob += ssh_string(signature_data)
66
+ return sig_blob
67
+
68
+ def parse_ssh_signature(sig_data):
69
+ offset = 0
70
+
71
+ if not sig_data.startswith(SSHSIG_MAGIC): raise ValueError("Invalid SSH signature: missing SSHSIG magic")
72
+ offset += len(SSHSIG_MAGIC)
73
+
74
+ if offset + 4 > len(sig_data): raise ValueError("Invalid SSH signature: truncated")
75
+ version = struct.unpack(">I", sig_data[offset:offset+4])[0]
76
+ if version != SSHSIG_VERSION: raise ValueError(f"Unsupported SSH signature version: {version}")
77
+ offset += 4
78
+
79
+ public_key, offset = read_ssh_string(sig_data, offset)
80
+ namespace, offset = read_ssh_string(sig_data, offset)
81
+ reserved, offset = read_ssh_string(sig_data, offset)
82
+ hash_algorithm, offset = read_ssh_string(sig_data, offset)
83
+ signature_data, offset = read_ssh_string(sig_data, offset)
84
+
85
+ return { "version": version,
86
+ "public_key": public_key,
87
+ "namespace": namespace,
88
+ "reserved": reserved,
89
+ "hash_algorithm": hash_algorithm,
90
+ "signature_data": signature_data }
91
+
92
+ def armor_ssh_signature(sig_blob):
93
+ b64_data = base64.b64encode(sig_blob).decode('ascii')
94
+ lines = [b64_data[i:i+70] for i in range(0, len(b64_data), 70)]
95
+
96
+ result = "-----BEGIN SSH SIGNATURE-----\n"
97
+ result += "\n".join(lines) + "\n"
98
+ result += "-----END SSH SIGNATURE-----\n"
99
+ return result
100
+
101
+ def unarmor_ssh_signature(armored_data):
102
+ lines = armored_data.strip().split('\n')
103
+ b64_data = ""
104
+ in_sig = False
105
+
106
+ for line in lines:
107
+ if 'BEGIN SSH SIGNATURE' in line: in_sig = True; continue
108
+ if 'END SSH SIGNATURE' in line: break
109
+ if in_sig: b64_data += line.strip()
110
+
111
+ if not b64_data: raise ValueError("No signature data found in armored input")
112
+
113
+ return base64.b64decode(b64_data)
114
+
115
+ def get_pubkey_wire_format(identity):
116
+ return ssh_string(b"ssh-ed25519")+ssh_string(identity.sig_pub_bytes)
117
+
118
+ def sign(args):
119
+ keyfile = args.keyfile
120
+ if not keyfile or not os.path.isfile(keyfile):
121
+ print(f"Identity file not found: {keyfile}", file=sys.stderr)
122
+ return 1
123
+
124
+ try:
125
+ identity = RNS.Identity.from_file(keyfile)
126
+ if not identity or not identity.get_private_key():
127
+ print("Error: Could not load identity or identity has no private key", file=sys.stderr)
128
+ return 1
129
+ except Exception as e:
130
+ print(f"Error loading identity: {e}", file=sys.stderr)
131
+ return 1
132
+
133
+ if args.file and os.path.isfile(args.file):
134
+ with open(args.file, 'rb') as f: message = f.read()
135
+ sig_file = args.file + ".sig"
136
+ else:
137
+ message = sys.stdin.buffer.read()
138
+ sig_file = None
139
+
140
+ try: rsg = create_rsg(identity, message)
141
+ except Exception as e:
142
+ print(f"Error creating signature: {e}", file=sys.stderr)
143
+ return 1
144
+
145
+ try: ssh_pubkey = get_pubkey_wire_format(identity)
146
+ except Exception as e:
147
+ print(f"Error converting public key: {e}", file=sys.stderr)
148
+ return 1
149
+
150
+ try:
151
+ ssh_sig = create_ssh_signature(public_key_wire=ssh_pubkey, namespace=NAMESPACE_GIT, reserved=RESERVED_EMPTY,
152
+ hash_algorithm=HASH_ALGORITHM, signature_data=rsg)
153
+ except Exception as e:
154
+ print(f"Error creating SSH signature: {e}", file=sys.stderr)
155
+ return 1
156
+
157
+ try: armored = armor_ssh_signature(ssh_sig)
158
+ except Exception as e:
159
+ print(f"Error armoring signature: {e}", file=sys.stderr)
160
+ return 1
161
+
162
+ if sig_file:
163
+ try:
164
+ with open(sig_file, 'w') as f: f.write(armored)
165
+ except Exception as e:
166
+ print(f"Error writing signature file: {e}", file=sys.stderr)
167
+ return 1
168
+
169
+ else: print(armored, end="")
170
+
171
+ return 0
172
+
173
+ def find_principals(args):
174
+ sigfile = args.sigfile
175
+ if not sigfile or not os.path.isfile(sigfile): print("Error: Signature file not found", file=sys.stderr); return 1
176
+
177
+ try:
178
+ with open(sigfile, 'r') as f: armored_sig = f.read()
179
+ except Exception as e: print(f"Error reading signature file: {e}", file=sys.stderr); return 1
180
+
181
+ try: ssh_sig = parse_ssh_signature(unarmor_ssh_signature(armored_sig))
182
+ except Exception as e: print(f"Error parsing SSH signature: {e}", file=sys.stderr); return 1
183
+
184
+ if ssh_sig["namespace"] != NAMESPACE_GIT:
185
+ print(f"Error: Namespace mismatch: {ssh_sig['namespace']}", file=sys.stderr)
186
+ return 1
187
+
188
+ rsg = ssh_sig["signature_data"]
189
+ try: identity_hash = extract_signed_rsg_data(rsg)["meta"]["signer"]
190
+ except Exception as e: print(f"Could not determine signer identity: {e}", file=sys.stderr); return 1
191
+
192
+ print(RNS.hexrep(identity_hash, delimit=False))
193
+ return 0
194
+
195
+ def check_novalidate(args):
196
+ sigfile = args.sigfile
197
+ if not sigfile or not os.path.isfile(sigfile): return 1
198
+
199
+ try:
200
+ with open(sigfile, 'r') as f: armored_sig = f.read()
201
+ ssh_sig = parse_ssh_signature(unarmor_ssh_signature(armored_sig))
202
+
203
+ if ssh_sig["namespace"] != NAMESPACE_GIT: return 1
204
+
205
+ rsg = ssh_sig["signature_data"]
206
+ signed_data = extract_signed_rsg_data(rsg)
207
+ if not signed_data: return 1
208
+ else: return 0
209
+
210
+ except Exception: return 1
211
+
212
+ def extract_commit_author(message):
213
+ message_lines = message.splitlines()
214
+ author = ""
215
+ AUTHOR_TARGET = b"author "
216
+ for line in message_lines:
217
+ if not line.strip(b""): break
218
+ elif line.startswith(AUTHOR_TARGET):
219
+ try:
220
+ spos = line.find(b"<"); epos = line.find(b">")
221
+ if spos > len(AUTHOR_TARGET) and epos > spos and epos < len(line)-1:
222
+ author = line[spos+1:epos].decode("utf-8")
223
+ break
224
+ except Exception as e: print(f"Error while determining author from signed commit"); return 1
225
+
226
+ return author
227
+
228
+ def extract_commit_committer(message):
229
+ message_lines = message.splitlines()
230
+ committer = ""
231
+ COMMITTER_TARGET = b"committer "
232
+ for line in message_lines:
233
+ if not line.strip(b""): break
234
+ elif line.startswith(COMMITTER_TARGET):
235
+ try:
236
+ spos = line.find(b"<"); epos = line.find(b">")
237
+ if spos > len(COMMITTER_TARGET) and epos > spos and epos < len(line)-1:
238
+ committer = line[spos+1:epos].decode("utf-8")
239
+ break
240
+ except Exception as e: print(f"Error while determining committer from signed commit"); return 1
241
+
242
+ return committer
243
+
244
+ def extract_commit_tagger(message):
245
+ message_lines = message.splitlines()
246
+ tagger = ""
247
+ is_tag = False
248
+ for line in message_lines:
249
+ TAG_TARGET = b"tag "
250
+ TAGGER_TARGET = b"tagger "
251
+ if not line.strip(b""): break
252
+ elif line.startswith(TAG_TARGET): is_tag = True
253
+ elif line.startswith(TAGGER_TARGET) and is_tag:
254
+ try:
255
+ spos = line.find(b"<"); epos = line.find(b">")
256
+ if spos > len(TAGGER_TARGET) and epos > spos and epos < len(line)-1:
257
+ tagger = line[spos+1:epos].decode("utf-8")
258
+ break
259
+ except Exception as e: print(f"Error while determining tagger from signed commit"); return 1
260
+
261
+ return tagger, is_tag
262
+
263
+ def verify(args):
264
+ sigfile = args.sigfile
265
+ principal = args.principal
266
+ if not sigfile or not os.path.isfile(sigfile): print("Error: Signature file not found", file=sys.stderr); return 1
267
+
268
+ message = sys.stdin.buffer.read()
269
+
270
+ try:
271
+ with open(sigfile, 'r') as f: armored_sig = f.read()
272
+ raw_sig = unarmor_ssh_signature(armored_sig)
273
+ ssh_sig = parse_ssh_signature(raw_sig)
274
+
275
+ except Exception as e: print(f"Error parsing signature: {e}", file=sys.stderr); return 1
276
+
277
+ author = extract_commit_author(message)
278
+ committer = extract_commit_committer(message)
279
+ tagger, is_tag = extract_commit_tagger(message)
280
+
281
+ if ssh_sig["namespace"] != NAMESPACE_GIT: print(f"Invalid commit signature namespace", file=sys.stderr); return 1
282
+
283
+ rsg = ssh_sig["signature_data"]
284
+ valid, signed_data, signing_identity = validate_rsg(rsg, message)
285
+
286
+ if not valid: print(f"Invalid signature", file=sys.stderr); return 1
287
+
288
+ if is_tag: author = tagger
289
+
290
+ signer_hash = RNS.hexrep(signing_identity.hash, delimit=False)
291
+ if not author == signer_hash: print(f"Commit not signed by author <{author}>"); return 1
292
+
293
+ if principal:
294
+ if principal != signer_hash: print(f"Principal mismatch", file=sys.stderr); return 1
295
+
296
+ print(f"Good \"git\" signature for commit, signed with Reticulum Identity key <{signer_hash}>")
297
+ return 0
298
+
299
+ def main():
300
+ parser = argparse.ArgumentParser(description="Git commit signer and validator")
301
+ parser.add_argument("-Y", dest="op", required=True, choices=["sign", "find-principals", "check-novalidate", "verify"], help="Operation to perform")
302
+ parser.add_argument("-n", dest="namespace", default="git", help="Namespace")
303
+ parser.add_argument("-f", dest="keyfile", help="Key file (for signing) or allowed signers file (for verification)")
304
+ parser.add_argument("-I", dest="principal", help="Principal identity (for verification)")
305
+ parser.add_argument("-s", dest="sigfile", help="Signature file")
306
+ parser.add_argument("file", nargs="?", help="File to sign (for signing)")
307
+ parser.add_argument("-O", dest="ssh_options", action="append", default=[], help="SSH options (for git compatibility, ignored)")
308
+
309
+ args, unknown = parser.parse_known_args()
310
+ for arg in unknown:
311
+ if arg.startswith('-O'): continue # TODO: Add options for time validation
312
+ else:
313
+ print(f"Error: Unknown argument: {arg}", file=sys.stderr)
314
+ sys.exit(1)
315
+
316
+ if args.op == "sign": return sign(args)
317
+ elif args.op == "find-principals": return find_principals(args)
318
+ elif args.op == "check-novalidate": return check_novalidate(args)
319
+ elif args.op == "verify": return verify(args)
320
+ else:
321
+ print(f"Error: Unknown operation: {args.op}", file=sys.stderr)
322
+ return 1
323
+
324
+ if __name__ == "__main__": sys.exit(main())