pypcapkit 1.3.3.post1__cp313-none-any.whl
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.
- pcapkit/__init__.py +126 -0
- pcapkit/__main__.py +138 -0
- pcapkit/all.py +136 -0
- pcapkit/const/__init__.py +81 -0
- pcapkit/const/arp/__init__.py +25 -0
- pcapkit/const/arp/hardware.py +181 -0
- pcapkit/const/arp/operation.py +131 -0
- pcapkit/const/ftp/__init__.py +25 -0
- pcapkit/const/ftp/command.py +309 -0
- pcapkit/const/ftp/return_code.py +304 -0
- pcapkit/const/hip/__init__.py +94 -0
- pcapkit/const/hip/certificate.py +77 -0
- pcapkit/const/hip/cipher.py +65 -0
- pcapkit/const/hip/di.py +59 -0
- pcapkit/const/hip/ecdsa_curve.py +59 -0
- pcapkit/const/hip/ecdsa_low_curve.py +56 -0
- pcapkit/const/hip/eddsa_curve.py +65 -0
- pcapkit/const/hip/esp_transform_suite.py +98 -0
- pcapkit/const/hip/group.py +86 -0
- pcapkit/const/hip/hi_algorithm.py +86 -0
- pcapkit/const/hip/hit_suite.py +68 -0
- pcapkit/const/hip/nat_traversal.py +62 -0
- pcapkit/const/hip/notify_message.py +200 -0
- pcapkit/const/hip/packet.py +89 -0
- pcapkit/const/hip/parameter.py +377 -0
- pcapkit/const/hip/registration.py +68 -0
- pcapkit/const/hip/registration_failure.py +84 -0
- pcapkit/const/hip/suite.py +71 -0
- pcapkit/const/hip/transport.py +59 -0
- pcapkit/const/http/__init__.py +39 -0
- pcapkit/const/http/error_code.py +95 -0
- pcapkit/const/http/frame.py +95 -0
- pcapkit/const/http/method.py +184 -0
- pcapkit/const/http/setting.py +96 -0
- pcapkit/const/http/status_code.py +294 -0
- pcapkit/const/ipv4/__init__.py +57 -0
- pcapkit/const/ipv4/classification_level.py +64 -0
- pcapkit/const/ipv4/option_class.py +55 -0
- pcapkit/const/ipv4/option_number.py +137 -0
- pcapkit/const/ipv4/protection_authority.py +63 -0
- pcapkit/const/ipv4/qs_function.py +51 -0
- pcapkit/const/ipv4/router_alert.py +251 -0
- pcapkit/const/ipv4/tos_del.py +51 -0
- pcapkit/const/ipv4/tos_ecn.py +55 -0
- pcapkit/const/ipv4/tos_pre.py +63 -0
- pcapkit/const/ipv4/tos_rel.py +51 -0
- pcapkit/const/ipv4/tos_thr.py +51 -0
- pcapkit/const/ipv4/ts_flag.py +53 -0
- pcapkit/const/ipv6/__init__.py +53 -0
- pcapkit/const/ipv6/extension_header.py +66 -0
- pcapkit/const/ipv6/option.py +137 -0
- pcapkit/const/ipv6/option_action.py +55 -0
- pcapkit/const/ipv6/qs_function.py +51 -0
- pcapkit/const/ipv6/router_alert.py +266 -0
- pcapkit/const/ipv6/routing.py +80 -0
- pcapkit/const/ipv6/seed_id.py +55 -0
- pcapkit/const/ipv6/smf_dpd_mode.py +51 -0
- pcapkit/const/ipv6/tagger_id.py +62 -0
- pcapkit/const/ipx/__init__.py +27 -0
- pcapkit/const/ipx/packet.py +72 -0
- pcapkit/const/ipx/socket.py +104 -0
- pcapkit/const/l2tp/__init__.py +21 -0
- pcapkit/const/l2tp/type.py +51 -0
- pcapkit/const/mh/__init__.py +204 -0
- pcapkit/const/mh/access_type.py +92 -0
- pcapkit/const/mh/ack_status_code.py +71 -0
- pcapkit/const/mh/ani_suboption.py +74 -0
- pcapkit/const/mh/auth_subtype.py +53 -0
- pcapkit/const/mh/binding_ack_flag.py +66 -0
- pcapkit/const/mh/binding_error.py +51 -0
- pcapkit/const/mh/binding_revocation.py +59 -0
- pcapkit/const/mh/binding_update_flag.py +81 -0
- pcapkit/const/mh/cga_extension.py +66 -0
- pcapkit/const/mh/cga_sec.py +57 -0
- pcapkit/const/mh/cga_type.py +68 -0
- pcapkit/const/mh/dhcp_support_mode.py +53 -0
- pcapkit/const/mh/dns_status_code.py +65 -0
- pcapkit/const/mh/dsmip6_tls_packet.py +62 -0
- pcapkit/const/mh/dsmipv6_home_address.py +74 -0
- pcapkit/const/mh/enumerating_algorithm.py +56 -0
- pcapkit/const/mh/fb_ack_status.py +62 -0
- pcapkit/const/mh/fb_action.py +71 -0
- pcapkit/const/mh/fb_indication_trigger.py +65 -0
- pcapkit/const/mh/fb_type.py +59 -0
- pcapkit/const/mh/flow_id_status.py +77 -0
- pcapkit/const/mh/flow_id_suboption.py +71 -0
- pcapkit/const/mh/handoff_type.py +71 -0
- pcapkit/const/mh/handover_ack_flag.py +54 -0
- pcapkit/const/mh/handover_ack_status.py +92 -0
- pcapkit/const/mh/handover_initiate_flag.py +57 -0
- pcapkit/const/mh/handover_initiate_status.py +62 -0
- pcapkit/const/mh/home_address_reply.py +71 -0
- pcapkit/const/mh/lla_code.py +63 -0
- pcapkit/const/mh/lma_mag_suboption.py +59 -0
- pcapkit/const/mh/mn_group_id.py +59 -0
- pcapkit/const/mh/mn_id_subtype.py +77 -0
- pcapkit/const/mh/operator_id.py +63 -0
- pcapkit/const/mh/option.py +260 -0
- pcapkit/const/mh/packet.py +119 -0
- pcapkit/const/mh/qos_attribute.py +89 -0
- pcapkit/const/mh/revocation_status_code.py +83 -0
- pcapkit/const/mh/revocation_trigger.py +86 -0
- pcapkit/const/mh/status_code.py +232 -0
- pcapkit/const/mh/traffic_selector.py +62 -0
- pcapkit/const/mh/upa_status.py +71 -0
- pcapkit/const/mh/upn_reason.py +80 -0
- pcapkit/const/ospf/__init__.py +27 -0
- pcapkit/const/ospf/authentication.py +65 -0
- pcapkit/const/ospf/packet.py +71 -0
- pcapkit/const/pcapng/__init__.py +51 -0
- pcapkit/const/pcapng/block_type.py +152 -0
- pcapkit/const/pcapng/filter_type.py +48 -0
- pcapkit/const/pcapng/hash_algorithm.py +59 -0
- pcapkit/const/pcapng/option_type.py +233 -0
- pcapkit/const/pcapng/record_type.py +57 -0
- pcapkit/const/pcapng/secrets_type.py +56 -0
- pcapkit/const/pcapng/verdict_type.py +53 -0
- pcapkit/const/reg/__init__.py +34 -0
- pcapkit/const/reg/apptype.py +32702 -0
- pcapkit/const/reg/ethertype.py +714 -0
- pcapkit/const/reg/linktype.py +902 -0
- pcapkit/const/reg/transtype.py +523 -0
- pcapkit/const/tcp/__init__.py +35 -0
- pcapkit/const/tcp/checksum.py +55 -0
- pcapkit/const/tcp/flags.py +73 -0
- pcapkit/const/tcp/mp_tcp_option.py +80 -0
- pcapkit/const/tcp/option.py +198 -0
- pcapkit/const/vlan/__init__.py +23 -0
- pcapkit/const/vlan/priority_level.py +71 -0
- pcapkit/corekit/__init__.py +59 -0
- pcapkit/corekit/fields/__init__.py +45 -0
- pcapkit/corekit/fields/collections.py +282 -0
- pcapkit/corekit/fields/field.py +269 -0
- pcapkit/corekit/fields/ipaddress.py +274 -0
- pcapkit/corekit/fields/misc.py +722 -0
- pcapkit/corekit/fields/numbers.py +375 -0
- pcapkit/corekit/fields/strings.py +245 -0
- pcapkit/corekit/infoclass.py +394 -0
- pcapkit/corekit/io.py +506 -0
- pcapkit/corekit/module.py +39 -0
- pcapkit/corekit/multidict.py +626 -0
- pcapkit/corekit/protochain.py +263 -0
- pcapkit/corekit/version.py +33 -0
- pcapkit/dumpkit/__init__.py +15 -0
- pcapkit/dumpkit/common.py +199 -0
- pcapkit/dumpkit/null.py +77 -0
- pcapkit/dumpkit/pcap.py +144 -0
- pcapkit/foundation/__init__.py +45 -0
- pcapkit/foundation/engines/__init__.py +36 -0
- pcapkit/foundation/engines/dpkt.py +230 -0
- pcapkit/foundation/engines/engine.py +194 -0
- pcapkit/foundation/engines/pcap.py +188 -0
- pcapkit/foundation/engines/pcapng.py +310 -0
- pcapkit/foundation/engines/pyshark.py +166 -0
- pcapkit/foundation/engines/scapy.py +161 -0
- pcapkit/foundation/extraction.py +915 -0
- pcapkit/foundation/reassembly/__init__.py +49 -0
- pcapkit/foundation/reassembly/data/__init__.py +48 -0
- pcapkit/foundation/reassembly/data/ip.py +117 -0
- pcapkit/foundation/reassembly/data/tcp.py +145 -0
- pcapkit/foundation/reassembly/ip.py +192 -0
- pcapkit/foundation/reassembly/ipv4.py +50 -0
- pcapkit/foundation/reassembly/ipv6.py +50 -0
- pcapkit/foundation/reassembly/reassembly.py +389 -0
- pcapkit/foundation/reassembly/tcp.py +249 -0
- pcapkit/foundation/registry/__init__.py +41 -0
- pcapkit/foundation/registry/foundation.py +327 -0
- pcapkit/foundation/registry/protocols.py +885 -0
- pcapkit/foundation/traceflow/__init__.py +44 -0
- pcapkit/foundation/traceflow/data/__init__.py +30 -0
- pcapkit/foundation/traceflow/data/tcp.py +105 -0
- pcapkit/foundation/traceflow/tcp.py +159 -0
- pcapkit/foundation/traceflow/traceflow.py +390 -0
- pcapkit/interface/__init__.py +22 -0
- pcapkit/interface/core.py +185 -0
- pcapkit/interface/misc.py +120 -0
- pcapkit/protocols/__init__.py +85 -0
- pcapkit/protocols/application/NotImplemented/bgp.py +0 -0
- pcapkit/protocols/application/NotImplemented/dhcp.py +0 -0
- pcapkit/protocols/application/NotImplemented/dhcpv6.py +0 -0
- pcapkit/protocols/application/NotImplemented/dns.py +0 -0
- pcapkit/protocols/application/NotImplemented/imap.py +0 -0
- pcapkit/protocols/application/NotImplemented/ldap.py +0 -0
- pcapkit/protocols/application/NotImplemented/mqtt.py +0 -0
- pcapkit/protocols/application/NotImplemented/nntp.py +0 -0
- pcapkit/protocols/application/NotImplemented/ntp.py +0 -0
- pcapkit/protocols/application/NotImplemented/onc_rpc.py +0 -0
- pcapkit/protocols/application/NotImplemented/pop.py +0 -0
- pcapkit/protocols/application/NotImplemented/rip.py +0 -0
- pcapkit/protocols/application/NotImplemented/rtp.py +0 -0
- pcapkit/protocols/application/NotImplemented/sip.py +0 -0
- pcapkit/protocols/application/NotImplemented/smtp.py +0 -0
- pcapkit/protocols/application/NotImplemented/snmp.py +0 -0
- pcapkit/protocols/application/NotImplemented/ssh.py +0 -0
- pcapkit/protocols/application/NotImplemented/telnet.py +0 -0
- pcapkit/protocols/application/NotImplemented/tls.py +0 -0
- pcapkit/protocols/application/NotImplemented/xmpp.py +0 -0
- pcapkit/protocols/application/__init__.py +34 -0
- pcapkit/protocols/application/application.py +114 -0
- pcapkit/protocols/application/ftp.py +206 -0
- pcapkit/protocols/application/http.py +176 -0
- pcapkit/protocols/application/httpv1.py +320 -0
- pcapkit/protocols/application/httpv2.py +1255 -0
- pcapkit/protocols/data/__init__.py +192 -0
- pcapkit/protocols/data/application/__init__.py +57 -0
- pcapkit/protocols/data/application/ftp.py +59 -0
- pcapkit/protocols/data/application/httpv1.py +79 -0
- pcapkit/protocols/data/application/httpv2.py +293 -0
- pcapkit/protocols/data/data.py +25 -0
- pcapkit/protocols/data/internet/__init__.py +298 -0
- pcapkit/protocols/data/internet/ah.py +31 -0
- pcapkit/protocols/data/internet/hip.py +804 -0
- pcapkit/protocols/data/internet/hopopt.py +351 -0
- pcapkit/protocols/data/internet/ipv4.py +369 -0
- pcapkit/protocols/data/internet/ipv6.py +67 -0
- pcapkit/protocols/data/internet/ipv6_frag.py +29 -0
- pcapkit/protocols/data/internet/ipv6_opts.py +368 -0
- pcapkit/protocols/data/internet/ipv6_route.py +86 -0
- pcapkit/protocols/data/internet/ipx.py +56 -0
- pcapkit/protocols/data/internet/mh.py +509 -0
- pcapkit/protocols/data/link/__init__.py +33 -0
- pcapkit/protocols/data/link/arp.py +74 -0
- pcapkit/protocols/data/link/ethernet.py +28 -0
- pcapkit/protocols/data/link/l2tp.py +63 -0
- pcapkit/protocols/data/link/ospf.py +58 -0
- pcapkit/protocols/data/link/vlan.py +42 -0
- pcapkit/protocols/data/misc/__init__.py +109 -0
- pcapkit/protocols/data/misc/null.py +18 -0
- pcapkit/protocols/data/misc/pcap/__init__.py +18 -0
- pcapkit/protocols/data/misc/pcap/frame.py +56 -0
- pcapkit/protocols/data/misc/pcap/header.py +53 -0
- pcapkit/protocols/data/misc/pcapng.py +925 -0
- pcapkit/protocols/data/misc/raw.py +25 -0
- pcapkit/protocols/data/protocol.py +32 -0
- pcapkit/protocols/data/transport/__init__.py +71 -0
- pcapkit/protocols/data/transport/tcp.py +555 -0
- pcapkit/protocols/data/transport/udp.py +29 -0
- pcapkit/protocols/internet/NotImplemented/ecn.py +0 -0
- pcapkit/protocols/internet/NotImplemented/esp.py +97 -0
- pcapkit/protocols/internet/NotImplemented/icmp.py +0 -0
- pcapkit/protocols/internet/NotImplemented/icmpv6.py +0 -0
- pcapkit/protocols/internet/NotImplemented/igmp.py +0 -0
- pcapkit/protocols/internet/NotImplemented/shim6.py +0 -0
- pcapkit/protocols/internet/__init__.py +43 -0
- pcapkit/protocols/internet/ah.py +275 -0
- pcapkit/protocols/internet/hip.py +4727 -0
- pcapkit/protocols/internet/hopopt.py +1879 -0
- pcapkit/protocols/internet/internet.py +240 -0
- pcapkit/protocols/internet/ip.py +51 -0
- pcapkit/protocols/internet/ipsec.py +50 -0
- pcapkit/protocols/internet/ipv4.py +1782 -0
- pcapkit/protocols/internet/ipv6.py +361 -0
- pcapkit/protocols/internet/ipv6_frag.py +258 -0
- pcapkit/protocols/internet/ipv6_opts.py +1890 -0
- pcapkit/protocols/internet/ipv6_route.py +710 -0
- pcapkit/protocols/internet/ipx.py +230 -0
- pcapkit/protocols/internet/mh.py +2764 -0
- pcapkit/protocols/link/NotImplemented/dsl.py +0 -0
- pcapkit/protocols/link/NotImplemented/eapol.py +1 -0
- pcapkit/protocols/link/NotImplemented/fddi.py +0 -0
- pcapkit/protocols/link/NotImplemented/isdn.py +0 -0
- pcapkit/protocols/link/NotImplemented/ndp.py +0 -0
- pcapkit/protocols/link/NotImplemented/ppp.py +0 -0
- pcapkit/protocols/link/__init__.py +35 -0
- pcapkit/protocols/link/arp.py +421 -0
- pcapkit/protocols/link/ethernet.py +248 -0
- pcapkit/protocols/link/l2tp.py +267 -0
- pcapkit/protocols/link/link.py +140 -0
- pcapkit/protocols/link/ospf.py +342 -0
- pcapkit/protocols/link/rarp.py +82 -0
- pcapkit/protocols/link/vlan.py +225 -0
- pcapkit/protocols/misc/__init__.py +37 -0
- pcapkit/protocols/misc/null.py +129 -0
- pcapkit/protocols/misc/pcap/__init__.py +17 -0
- pcapkit/protocols/misc/pcap/frame.py +478 -0
- pcapkit/protocols/misc/pcap/header.py +358 -0
- pcapkit/protocols/misc/pcapng.py +5520 -0
- pcapkit/protocols/misc/raw.py +180 -0
- pcapkit/protocols/protocol.py +1216 -0
- pcapkit/protocols/schema/__init__.py +140 -0
- pcapkit/protocols/schema/application/__init__.py +40 -0
- pcapkit/protocols/schema/application/ftp.py +21 -0
- pcapkit/protocols/schema/application/httpv1.py +21 -0
- pcapkit/protocols/schema/application/httpv2.py +384 -0
- pcapkit/protocols/schema/internet/__init__.py +294 -0
- pcapkit/protocols/schema/internet/ah.py +40 -0
- pcapkit/protocols/schema/internet/hip.py +1184 -0
- pcapkit/protocols/schema/internet/hopopt.py +679 -0
- pcapkit/protocols/schema/internet/ipv4.py +576 -0
- pcapkit/protocols/schema/internet/ipv6.py +63 -0
- pcapkit/protocols/schema/internet/ipv6_frag.py +48 -0
- pcapkit/protocols/schema/internet/ipv6_opts.py +680 -0
- pcapkit/protocols/schema/internet/ipv6_route.py +198 -0
- pcapkit/protocols/schema/internet/ipx.py +40 -0
- pcapkit/protocols/schema/internet/mh.py +718 -0
- pcapkit/protocols/schema/link/__init__.py +19 -0
- pcapkit/protocols/schema/link/arp.py +39 -0
- pcapkit/protocols/schema/link/ethernet.py +51 -0
- pcapkit/protocols/schema/link/l2tp.py +88 -0
- pcapkit/protocols/schema/link/ospf.py +90 -0
- pcapkit/protocols/schema/link/vlan.py +69 -0
- pcapkit/protocols/schema/misc/__init__.py +108 -0
- pcapkit/protocols/schema/misc/null.py +18 -0
- pcapkit/protocols/schema/misc/pcap/__init__.py +10 -0
- pcapkit/protocols/schema/misc/pcap/frame.py +51 -0
- pcapkit/protocols/schema/misc/pcap/header.py +63 -0
- pcapkit/protocols/schema/misc/pcapng.py +1689 -0
- pcapkit/protocols/schema/misc/raw.py +24 -0
- pcapkit/protocols/schema/schema.py +809 -0
- pcapkit/protocols/schema/transport/__init__.py +69 -0
- pcapkit/protocols/schema/transport/tcp.py +928 -0
- pcapkit/protocols/schema/transport/udp.py +90 -0
- pcapkit/protocols/transport/NotImplemented/dccp.py +0 -0
- pcapkit/protocols/transport/NotImplemented/rsvp.py +0 -0
- pcapkit/protocols/transport/NotImplemented/sctp.py +0 -0
- pcapkit/protocols/transport/__init__.py +27 -0
- pcapkit/protocols/transport/tcp.py +3025 -0
- pcapkit/protocols/transport/transport.py +158 -0
- pcapkit/protocols/transport/udp.py +214 -0
- pcapkit/py.typed +0 -0
- pcapkit/toolkit/__init__.py +57 -0
- pcapkit/toolkit/dpkt.py +306 -0
- pcapkit/toolkit/pcap.py +212 -0
- pcapkit/toolkit/pcapng.py +251 -0
- pcapkit/toolkit/pyshark.py +99 -0
- pcapkit/toolkit/scapy.py +297 -0
- pcapkit/utilities/__init__.py +20 -0
- pcapkit/utilities/compat.py +196 -0
- pcapkit/utilities/decorators.py +192 -0
- pcapkit/utilities/exceptions.py +365 -0
- pcapkit/utilities/logging.py +55 -0
- pcapkit/utilities/warnings.py +185 -0
- pcapkit/vendor/__init__.py +105 -0
- pcapkit/vendor/__main__.py +92 -0
- pcapkit/vendor/arp/__init__.py +27 -0
- pcapkit/vendor/arp/hardware.py +29 -0
- pcapkit/vendor/arp/operation.py +29 -0
- pcapkit/vendor/default.py +474 -0
- pcapkit/vendor/ftp/__init__.py +27 -0
- pcapkit/vendor/ftp/command.py +244 -0
- pcapkit/vendor/ftp/return_code.py +256 -0
- pcapkit/vendor/hip/__init__.py +94 -0
- pcapkit/vendor/hip/certificate.py +29 -0
- pcapkit/vendor/hip/cipher.py +29 -0
- pcapkit/vendor/hip/di.py +29 -0
- pcapkit/vendor/hip/ecdsa_curve.py +29 -0
- pcapkit/vendor/hip/ecdsa_low_curve.py +29 -0
- pcapkit/vendor/hip/eddsa_curve.py +85 -0
- pcapkit/vendor/hip/esp_transform_suite.py +29 -0
- pcapkit/vendor/hip/group.py +87 -0
- pcapkit/vendor/hip/hi_algorithm.py +29 -0
- pcapkit/vendor/hip/hit_suite.py +29 -0
- pcapkit/vendor/hip/nat_traversal.py +29 -0
- pcapkit/vendor/hip/notify_message.py +29 -0
- pcapkit/vendor/hip/packet.py +88 -0
- pcapkit/vendor/hip/parameter.py +88 -0
- pcapkit/vendor/hip/registration.py +29 -0
- pcapkit/vendor/hip/registration_failure.py +29 -0
- pcapkit/vendor/hip/suite.py +29 -0
- pcapkit/vendor/hip/transport.py +29 -0
- pcapkit/vendor/http/__init__.py +39 -0
- pcapkit/vendor/http/error_code.py +95 -0
- pcapkit/vendor/http/frame.py +91 -0
- pcapkit/vendor/http/method.py +167 -0
- pcapkit/vendor/http/setting.py +93 -0
- pcapkit/vendor/http/status_code.py +185 -0
- pcapkit/vendor/ipv4/__init__.py +57 -0
- pcapkit/vendor/ipv4/classification_level.py +91 -0
- pcapkit/vendor/ipv4/option_class.py +80 -0
- pcapkit/vendor/ipv4/option_number.py +105 -0
- pcapkit/vendor/ipv4/protection_authority.py +84 -0
- pcapkit/vendor/ipv4/qs_function.py +78 -0
- pcapkit/vendor/ipv4/router_alert.py +93 -0
- pcapkit/vendor/ipv4/tos_del.py +78 -0
- pcapkit/vendor/ipv4/tos_ecn.py +95 -0
- pcapkit/vendor/ipv4/tos_pre.py +84 -0
- pcapkit/vendor/ipv4/tos_rel.py +78 -0
- pcapkit/vendor/ipv4/tos_thr.py +77 -0
- pcapkit/vendor/ipv4/ts_flag.py +79 -0
- pcapkit/vendor/ipv6/__init__.py +53 -0
- pcapkit/vendor/ipv6/extension_header.py +171 -0
- pcapkit/vendor/ipv6/option.py +104 -0
- pcapkit/vendor/ipv6/option_action.py +90 -0
- pcapkit/vendor/ipv6/qs_function.py +78 -0
- pcapkit/vendor/ipv6/router_alert.py +93 -0
- pcapkit/vendor/ipv6/routing.py +87 -0
- pcapkit/vendor/ipv6/seed_id.py +81 -0
- pcapkit/vendor/ipv6/smf_dpd_mode.py +78 -0
- pcapkit/vendor/ipv6/tagger_id.py +81 -0
- pcapkit/vendor/ipx/__init__.py +37 -0
- pcapkit/vendor/ipx/packet.py +123 -0
- pcapkit/vendor/ipx/socket.py +125 -0
- pcapkit/vendor/l2tp/__init__.py +21 -0
- pcapkit/vendor/l2tp/type.py +78 -0
- pcapkit/vendor/mh/__init__.py +204 -0
- pcapkit/vendor/mh/access_type.py +87 -0
- pcapkit/vendor/mh/ack_status_code.py +88 -0
- pcapkit/vendor/mh/ani_suboption.py +88 -0
- pcapkit/vendor/mh/auth_subtype.py +83 -0
- pcapkit/vendor/mh/binding_ack_flag.py +148 -0
- pcapkit/vendor/mh/binding_error.py +78 -0
- pcapkit/vendor/mh/binding_revocation.py +87 -0
- pcapkit/vendor/mh/binding_update_flag.py +147 -0
- pcapkit/vendor/mh/cga_extension.py +91 -0
- pcapkit/vendor/mh/cga_sec.py +91 -0
- pcapkit/vendor/mh/cga_type.py +74 -0
- pcapkit/vendor/mh/dhcp_support_mode.py +77 -0
- pcapkit/vendor/mh/dns_status_code.py +87 -0
- pcapkit/vendor/mh/dsmip6_tls_packet.py +87 -0
- pcapkit/vendor/mh/dsmipv6_home_address.py +87 -0
- pcapkit/vendor/mh/enumerating_algorithm.py +82 -0
- pcapkit/vendor/mh/fb_ack_status.py +87 -0
- pcapkit/vendor/mh/fb_action.py +88 -0
- pcapkit/vendor/mh/fb_indication_trigger.py +87 -0
- pcapkit/vendor/mh/fb_type.py +88 -0
- pcapkit/vendor/mh/flow_id_status.py +87 -0
- pcapkit/vendor/mh/flow_id_suboption.py +87 -0
- pcapkit/vendor/mh/handoff_type.py +87 -0
- pcapkit/vendor/mh/handover_ack_flag.py +143 -0
- pcapkit/vendor/mh/handover_ack_status.py +87 -0
- pcapkit/vendor/mh/handover_initiate_flag.py +143 -0
- pcapkit/vendor/mh/handover_initiate_status.py +87 -0
- pcapkit/vendor/mh/home_address_reply.py +87 -0
- pcapkit/vendor/mh/lla_code.py +97 -0
- pcapkit/vendor/mh/lma_mag_suboption.py +88 -0
- pcapkit/vendor/mh/mn_group_id.py +87 -0
- pcapkit/vendor/mh/mn_id_subtype.py +87 -0
- pcapkit/vendor/mh/operator_id.py +87 -0
- pcapkit/vendor/mh/option.py +83 -0
- pcapkit/vendor/mh/packet.py +82 -0
- pcapkit/vendor/mh/qos_attribute.py +87 -0
- pcapkit/vendor/mh/revocation_status_code.py +87 -0
- pcapkit/vendor/mh/revocation_trigger.py +87 -0
- pcapkit/vendor/mh/status_code.py +91 -0
- pcapkit/vendor/mh/traffic_selector.py +87 -0
- pcapkit/vendor/mh/upa_status.py +87 -0
- pcapkit/vendor/mh/upn_reason.py +87 -0
- pcapkit/vendor/ospf/__init__.py +27 -0
- pcapkit/vendor/ospf/authentication.py +29 -0
- pcapkit/vendor/ospf/packet.py +29 -0
- pcapkit/vendor/pcapng/__init__.py +51 -0
- pcapkit/vendor/pcapng/block_type.py +94 -0
- pcapkit/vendor/pcapng/filter_type.py +77 -0
- pcapkit/vendor/pcapng/hash_algorithm.py +82 -0
- pcapkit/vendor/pcapng/option_type.py +287 -0
- pcapkit/vendor/pcapng/record_type.py +81 -0
- pcapkit/vendor/pcapng/secrets_type.py +81 -0
- pcapkit/vendor/pcapng/verdict_type.py +79 -0
- pcapkit/vendor/reg/__init__.py +34 -0
- pcapkit/vendor/reg/apptype.py +338 -0
- pcapkit/vendor/reg/ethertype.py +121 -0
- pcapkit/vendor/reg/linktype.py +110 -0
- pcapkit/vendor/reg/transtype.py +111 -0
- pcapkit/vendor/tcp/__init__.py +35 -0
- pcapkit/vendor/tcp/checksum.py +80 -0
- pcapkit/vendor/tcp/flags.py +149 -0
- pcapkit/vendor/tcp/mp_tcp_option.py +90 -0
- pcapkit/vendor/tcp/option.py +103 -0
- pcapkit/vendor/vlan/__init__.py +23 -0
- pcapkit/vendor/vlan/priority_level.py +97 -0
- pypcapkit-1.3.3.post1.dist-info/LICENSE +29 -0
- pypcapkit-1.3.3.post1.dist-info/METADATA +236 -0
- pypcapkit-1.3.3.post1.dist-info/RECORD +466 -0
- pypcapkit-1.3.3.post1.dist-info/WHEEL +5 -0
- pypcapkit-1.3.3.post1.dist-info/entry_points.txt +3 -0
- pypcapkit-1.3.3.post1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,4727 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""HIP - Host Identity Protocol
|
3
|
+
==================================
|
4
|
+
|
5
|
+
.. module:: pcapkit.protocols.internet.hip
|
6
|
+
|
7
|
+
:mod:`pcapkit.protocols.internet.hip` contains
|
8
|
+
:class:`~pcapkit.protocols.internet.hip.HIP` only,
|
9
|
+
which implements extractor for Host Identity
|
10
|
+
Protocol (HIP) [*]_, whose structure is described
|
11
|
+
as below:
|
12
|
+
|
13
|
+
======= ========= ====================== ==================================
|
14
|
+
Octets Bits Name Description
|
15
|
+
======= ========= ====================== ==================================
|
16
|
+
0 0 ``hip.next`` Next Header
|
17
|
+
1 8 ``hip.length`` Header Length
|
18
|
+
2 16 Reserved (``\\x00``)
|
19
|
+
2 17 ``hip.type`` Packet Type
|
20
|
+
3 24 ``hip.version`` Version
|
21
|
+
3 28 Reserved
|
22
|
+
3 31 Reserved (``\\x01``)
|
23
|
+
4 32 ``hip.chksum`` Checksum
|
24
|
+
6 48 ``hip.control`` Controls
|
25
|
+
8 64 ``hip.shit`` Sender's Host Identity Tag
|
26
|
+
24 192 ``hip.rhit`` Receiver's Host Identity Tag
|
27
|
+
40 320 ``hip.parameters`` HIP Parameters
|
28
|
+
======= ========= ====================== ==================================
|
29
|
+
|
30
|
+
.. [*] https://en.wikipedia.org/wiki/Host_Identity_Protocol
|
31
|
+
|
32
|
+
"""
|
33
|
+
import datetime
|
34
|
+
import ipaddress
|
35
|
+
import math
|
36
|
+
from typing import TYPE_CHECKING, cast, overload
|
37
|
+
|
38
|
+
from pcapkit.const.hip.certificate import Certificate as Enum_Certificate
|
39
|
+
from pcapkit.const.hip.cipher import Cipher as Enum_Cipher
|
40
|
+
from pcapkit.const.hip.di import DITypes as Enum_DITypes
|
41
|
+
from pcapkit.const.hip.ecdsa_curve import ECDSACurve as Enum_ECDSACurve
|
42
|
+
from pcapkit.const.hip.ecdsa_low_curve import ECDSALowCurve as Enum_ECDSALowCurve
|
43
|
+
from pcapkit.const.hip.eddsa_curve import EdDSACurve as Enum_EdDSACurve
|
44
|
+
from pcapkit.const.hip.group import Group as Enum_Group
|
45
|
+
from pcapkit.const.hip.hi_algorithm import HIAlgorithm as Enum_HIAlgorithm
|
46
|
+
from pcapkit.const.hip.hit_suite import HITSuite as Enum_HITSuite
|
47
|
+
from pcapkit.const.hip.notify_message import NotifyMessage as Enum_NotifyMessage
|
48
|
+
from pcapkit.const.hip.packet import Packet as Enum_Packet
|
49
|
+
from pcapkit.const.hip.parameter import Parameter as Enum_Parameter
|
50
|
+
from pcapkit.const.reg.transtype import TransType as Enum_TransType
|
51
|
+
from pcapkit.corekit.multidict import OrderedMultiDict
|
52
|
+
from pcapkit.protocols.data.internet.hip import HIP as Data_HIP
|
53
|
+
from pcapkit.protocols.data.internet.hip import AckDataParameter as Data_AckDataParameter
|
54
|
+
from pcapkit.protocols.data.internet.hip import ACKParameter as Data_ACKParameter
|
55
|
+
from pcapkit.protocols.data.internet.hip import CertParameter as Data_CertParameter
|
56
|
+
from pcapkit.protocols.data.internet.hip import Control as Data_Control
|
57
|
+
from pcapkit.protocols.data.internet.hip import DHGroupListParameter as Data_DHGroupListParameter
|
58
|
+
from pcapkit.protocols.data.internet.hip import \
|
59
|
+
DiffieHellmanParameter as Data_DiffieHellmanParameter
|
60
|
+
from pcapkit.protocols.data.internet.hip import \
|
61
|
+
EchoRequestSignedParameter as Data_EchoRequestSignedParameter
|
62
|
+
from pcapkit.protocols.data.internet.hip import \
|
63
|
+
EchoRequestUnsignedParameter as Data_EchoRequestUnsignedParameter
|
64
|
+
from pcapkit.protocols.data.internet.hip import \
|
65
|
+
EchoResponseSignedParameter as Data_EchoResponseSignedParameter
|
66
|
+
from pcapkit.protocols.data.internet.hip import \
|
67
|
+
EchoResponseUnsignedParameter as Data_EchoResponseUnsignedParameter
|
68
|
+
from pcapkit.protocols.data.internet.hip import EncryptedParameter as Data_EncryptedParameter
|
69
|
+
from pcapkit.protocols.data.internet.hip import ESPInfoParameter as Data_ESPInfoParameter
|
70
|
+
from pcapkit.protocols.data.internet.hip import ESPTransformParameter as Data_ESPTransformParameter
|
71
|
+
from pcapkit.protocols.data.internet.hip import Flags as Data_Flags
|
72
|
+
from pcapkit.protocols.data.internet.hip import FromParameter as Data_FromParameter
|
73
|
+
from pcapkit.protocols.data.internet.hip import HIPCipherParameter as Data_HIPCipherParameter
|
74
|
+
from pcapkit.protocols.data.internet.hip import HIPMAC2Parameter as Data_HIPMAC2Parameter
|
75
|
+
from pcapkit.protocols.data.internet.hip import HIPMACParameter as Data_HIPMACParameter
|
76
|
+
from pcapkit.protocols.data.internet.hip import \
|
77
|
+
HIPSignature2Parameter as Data_HIPSignature2Parameter
|
78
|
+
from pcapkit.protocols.data.internet.hip import HIPSignatureParameter as Data_HIPSignatureParameter
|
79
|
+
from pcapkit.protocols.data.internet.hip import HIPTransformParameter as Data_HIPTransformParameter
|
80
|
+
from pcapkit.protocols.data.internet.hip import \
|
81
|
+
HIPTransportModeParameter as Data_HIPTransportModeParameter
|
82
|
+
from pcapkit.protocols.data.internet.hip import HITSuiteListParameter as Data_HITSuiteListParameter
|
83
|
+
from pcapkit.protocols.data.internet.hip import HostIdentity as Data_HostIdentity
|
84
|
+
from pcapkit.protocols.data.internet.hip import HostIDParameter as Data_HostIDParameter
|
85
|
+
from pcapkit.protocols.data.internet.hip import Lifetime as Data_Lifetime
|
86
|
+
from pcapkit.protocols.data.internet.hip import Locator as Data_Locator
|
87
|
+
from pcapkit.protocols.data.internet.hip import LocatorData as Data_LocatorData
|
88
|
+
from pcapkit.protocols.data.internet.hip import LocatorSetParameter as Data_LocatorSetParameter
|
89
|
+
from pcapkit.protocols.data.internet.hip import \
|
90
|
+
NATTraversalModeParameter as Data_NATTraversalModeParameter
|
91
|
+
from pcapkit.protocols.data.internet.hip import NotificationParameter as Data_NotificationParameter
|
92
|
+
from pcapkit.protocols.data.internet.hip import OverlayIDParameter as Data_OverlayIDParameter
|
93
|
+
from pcapkit.protocols.data.internet.hip import OverlayTTLParameter as Data_OverlayTTLParameter
|
94
|
+
from pcapkit.protocols.data.internet.hip import PayloadMICParameter as Data_PayloadMICParameter
|
95
|
+
from pcapkit.protocols.data.internet.hip import PuzzleParameter as Data_PuzzleParameter
|
96
|
+
from pcapkit.protocols.data.internet.hip import R1CounterParameter as Data_R1CounterParameter
|
97
|
+
from pcapkit.protocols.data.internet.hip import RegFailedParameter as Data_RegFailedParameter
|
98
|
+
from pcapkit.protocols.data.internet.hip import RegFromParameter as Data_RegFromParameter
|
99
|
+
from pcapkit.protocols.data.internet.hip import RegInfoParameter as Data_RegInfoParameter
|
100
|
+
from pcapkit.protocols.data.internet.hip import RegRequestParameter as Data_RegRequestParameter
|
101
|
+
from pcapkit.protocols.data.internet.hip import RegResponseParameter as Data_RegResponseParameter
|
102
|
+
from pcapkit.protocols.data.internet.hip import RelayFromParameter as Data_RelayFromParameter
|
103
|
+
from pcapkit.protocols.data.internet.hip import RelayHMACParameter as Data_RelayHMACParameter
|
104
|
+
from pcapkit.protocols.data.internet.hip import RelayToParameter as Data_RelayToParameter
|
105
|
+
from pcapkit.protocols.data.internet.hip import RouteDstParameter as Data_RouteDstParameter
|
106
|
+
from pcapkit.protocols.data.internet.hip import RouteViaParameter as Data_RouteViaParameter
|
107
|
+
from pcapkit.protocols.data.internet.hip import RVSHMACParameter as Data_RVSHMACParameter
|
108
|
+
from pcapkit.protocols.data.internet.hip import SeqDataParameter as Data_SeqDataParameter
|
109
|
+
from pcapkit.protocols.data.internet.hip import SEQParameter as Data_SEQParameter
|
110
|
+
from pcapkit.protocols.data.internet.hip import SolutionParameter as Data_SolutionParameter
|
111
|
+
from pcapkit.protocols.data.internet.hip import \
|
112
|
+
TransactionIDParameter as Data_TransactionIDParameter
|
113
|
+
from pcapkit.protocols.data.internet.hip import \
|
114
|
+
TransactionPacingParameter as Data_TransactionPacingParameter
|
115
|
+
from pcapkit.protocols.data.internet.hip import \
|
116
|
+
TransportFormatListParameter as Data_TransportFormatListParameter
|
117
|
+
from pcapkit.protocols.data.internet.hip import UnassignedParameter as Data_UnassignedParameter
|
118
|
+
from pcapkit.protocols.data.internet.hip import ViaRVSParameter as Data_ViaRVSParameter
|
119
|
+
from pcapkit.protocols.internet.internet import Internet
|
120
|
+
from pcapkit.protocols.schema.internet.hip import HIP as Schema_HIP
|
121
|
+
from pcapkit.protocols.schema.internet.hip import AckDataParameter as Schema_AckDataParameter
|
122
|
+
from pcapkit.protocols.schema.internet.hip import ACKParameter as Schema_ACKParameter
|
123
|
+
from pcapkit.protocols.schema.internet.hip import CertParameter as Schema_CertParameter
|
124
|
+
from pcapkit.protocols.schema.internet.hip import \
|
125
|
+
DHGroupListParameter as Schema_DHGroupListParameter
|
126
|
+
from pcapkit.protocols.schema.internet.hip import \
|
127
|
+
DiffieHellmanParameter as Schema_DiffieHellmanParameter
|
128
|
+
from pcapkit.protocols.schema.internet.hip import \
|
129
|
+
ECDSACurveHostIdentity as Schema_ECDSACurveHostIdentity
|
130
|
+
from pcapkit.protocols.schema.internet.hip import \
|
131
|
+
ECDSALowCurveHostIdentity as Schema_ECDSALowCurveHostIdentity
|
132
|
+
from pcapkit.protocols.schema.internet.hip import \
|
133
|
+
EchoRequestSignedParameter as Schema_EchoRequestSignedParameter
|
134
|
+
from pcapkit.protocols.schema.internet.hip import \
|
135
|
+
EchoRequestUnsignedParameter as Schema_EchoRequestUnsignedParameter
|
136
|
+
from pcapkit.protocols.schema.internet.hip import \
|
137
|
+
EchoResponseSignedParameter as Schema_EchoResponseSignedParameter
|
138
|
+
from pcapkit.protocols.schema.internet.hip import \
|
139
|
+
EchoResponseUnsignedParameter as Schema_EchoResponseUnsignedParameter
|
140
|
+
from pcapkit.protocols.schema.internet.hip import \
|
141
|
+
EdDSACurveHostIdentity as Schema_EdDSACurveHostIdentity
|
142
|
+
from pcapkit.protocols.schema.internet.hip import EncryptedParameter as Schema_EncryptedParameter
|
143
|
+
from pcapkit.protocols.schema.internet.hip import ESPInfoParameter as Schema_ESPInfoParameter
|
144
|
+
from pcapkit.protocols.schema.internet.hip import \
|
145
|
+
ESPTransformParameter as Schema_ESPTransformParameter
|
146
|
+
from pcapkit.protocols.schema.internet.hip import FromParameter as Schema_FromParameter
|
147
|
+
from pcapkit.protocols.schema.internet.hip import HIPCipherParameter as Schema_HIPCipherParameter
|
148
|
+
from pcapkit.protocols.schema.internet.hip import HIPMAC2Parameter as Schema_HIPMAC2Parameter
|
149
|
+
from pcapkit.protocols.schema.internet.hip import HIPMACParameter as Schema_HIPMACParameter
|
150
|
+
from pcapkit.protocols.schema.internet.hip import \
|
151
|
+
HIPSignature2Parameter as Schema_HIPSignature2Parameter
|
152
|
+
from pcapkit.protocols.schema.internet.hip import \
|
153
|
+
HIPSignatureParameter as Schema_HIPSignatureParameter
|
154
|
+
from pcapkit.protocols.schema.internet.hip import \
|
155
|
+
HIPTransformParameter as Schema_HIPTransformParameter
|
156
|
+
from pcapkit.protocols.schema.internet.hip import \
|
157
|
+
HIPTransportModeParameter as Schema_HIPTransportModeParameter
|
158
|
+
from pcapkit.protocols.schema.internet.hip import \
|
159
|
+
HITSuiteListParameter as Schema_HITSuiteListParameter
|
160
|
+
from pcapkit.protocols.schema.internet.hip import HostIdentity as Schema_HostIdentity
|
161
|
+
from pcapkit.protocols.schema.internet.hip import HostIDParameter as Schema_HostIDParameter
|
162
|
+
from pcapkit.protocols.schema.internet.hip import Locator as Schema_Locator
|
163
|
+
from pcapkit.protocols.schema.internet.hip import LocatorData as Schema_LocatorData
|
164
|
+
from pcapkit.protocols.schema.internet.hip import LocatorSetParameter as Schema_LocatorSetParameter
|
165
|
+
from pcapkit.protocols.schema.internet.hip import \
|
166
|
+
NATTraversalModeParameter as Schema_NATTraversalModeParameter
|
167
|
+
from pcapkit.protocols.schema.internet.hip import \
|
168
|
+
NotificationParameter as Schema_NotificationParameter
|
169
|
+
from pcapkit.protocols.schema.internet.hip import OverlayIDParameter as Schema_OverlayIDParameter
|
170
|
+
from pcapkit.protocols.schema.internet.hip import OverlayTTLParameter as Schema_OverlayTTLParameter
|
171
|
+
from pcapkit.protocols.schema.internet.hip import PayloadMICParameter as Schema_PayloadMICParameter
|
172
|
+
from pcapkit.protocols.schema.internet.hip import PuzzleParameter as Schema_PuzzleParameter
|
173
|
+
from pcapkit.protocols.schema.internet.hip import R1CounterParameter as Schema_R1CounterParameter
|
174
|
+
from pcapkit.protocols.schema.internet.hip import RegFailedParameter as Schema_RegFailedParameter
|
175
|
+
from pcapkit.protocols.schema.internet.hip import RegFromParameter as Schema_RegFromParameter
|
176
|
+
from pcapkit.protocols.schema.internet.hip import RegInfoParameter as Schema_RegInfoParameter
|
177
|
+
from pcapkit.protocols.schema.internet.hip import RegRequestParameter as Schema_RegRequestParameter
|
178
|
+
from pcapkit.protocols.schema.internet.hip import \
|
179
|
+
RegResponseParameter as Schema_RegResponseParameter
|
180
|
+
from pcapkit.protocols.schema.internet.hip import RelayFromParameter as Schema_RelayFromParameter
|
181
|
+
from pcapkit.protocols.schema.internet.hip import RelayHMACParameter as Schema_RelayHMACParameter
|
182
|
+
from pcapkit.protocols.schema.internet.hip import RelayToParameter as Schema_RelayToParameter
|
183
|
+
from pcapkit.protocols.schema.internet.hip import RouteDstParameter as Schema_RouteDstParameter
|
184
|
+
from pcapkit.protocols.schema.internet.hip import RouteViaParameter as Schema_RouteViaParameter
|
185
|
+
from pcapkit.protocols.schema.internet.hip import RVSHMACParameter as Schema_RVSHMACParameter
|
186
|
+
from pcapkit.protocols.schema.internet.hip import SeqDataParameter as Schema_SeqDataParameter
|
187
|
+
from pcapkit.protocols.schema.internet.hip import SEQParameter as Schema_SEQParameter
|
188
|
+
from pcapkit.protocols.schema.internet.hip import SolutionParameter as Schema_SolutionParameter
|
189
|
+
from pcapkit.protocols.schema.internet.hip import \
|
190
|
+
TransactionIDParameter as Schema_TransactionIDParameter
|
191
|
+
from pcapkit.protocols.schema.internet.hip import \
|
192
|
+
TransactionPacingParameter as Schema_TransactionPacingParameter
|
193
|
+
from pcapkit.protocols.schema.internet.hip import \
|
194
|
+
TransportFormatListParameter as Schema_TransportFormatListParameter
|
195
|
+
from pcapkit.protocols.schema.internet.hip import UnassignedParameter as Schema_UnassignedParameter
|
196
|
+
from pcapkit.protocols.schema.internet.hip import ViaRVSParameter as Schema_ViaRVSParameter
|
197
|
+
from pcapkit.protocols.schema.schema import Schema
|
198
|
+
from pcapkit.utilities.exceptions import ProtocolError, UnsupportedCall
|
199
|
+
from pcapkit.utilities.logging import SPHINX_TYPE_CHECKING
|
200
|
+
from pcapkit.utilities.warnings import ProtocolWarning, RegistryWarning, warn
|
201
|
+
|
202
|
+
if TYPE_CHECKING:
|
203
|
+
from datetime import timedelta
|
204
|
+
from enum import IntEnum as StdlibEnum
|
205
|
+
from ipaddress import IPv6Address
|
206
|
+
from typing import IO, Any, Callable, NoReturn, Optional, Type
|
207
|
+
|
208
|
+
from aenum import IntEnum as AenumEnum
|
209
|
+
from mypy_extensions import DefaultArg, KwArg, NamedArg
|
210
|
+
from typing_extensions import Literal, NotRequired
|
211
|
+
|
212
|
+
from pcapkit.const.hip.esp_transform_suite import ESPTransformSuite as Enum_ESPTransformSuite
|
213
|
+
from pcapkit.const.hip.nat_traversal import NATTraversal as Enum_NATTraversal
|
214
|
+
from pcapkit.const.hip.registration import Registration as Enum_Registration
|
215
|
+
from pcapkit.const.hip.registration_failure import \
|
216
|
+
RegistrationFailure as Enum_RegistrationFailure
|
217
|
+
from pcapkit.const.hip.suite import Suite as Enum_Suite
|
218
|
+
from pcapkit.const.hip.transport import Transport as Enum_Transport
|
219
|
+
from pcapkit.corekit.protochain import ProtoChain
|
220
|
+
from pcapkit.protocols.data.internet.hip import Parameter as Data_Parameter
|
221
|
+
from pcapkit.protocols.protocol import ProtocolBase as Protocol
|
222
|
+
from pcapkit.protocols.schema.internet.hip import Parameter as Schema_Parameter
|
223
|
+
|
224
|
+
Parameter = OrderedMultiDict[Enum_Parameter, Data_Parameter]
|
225
|
+
ParameterParser = Callable[[Schema_Parameter, NamedArg(int, 'version'),
|
226
|
+
NamedArg(Parameter, 'options')], Data_Parameter]
|
227
|
+
ParameterConstructor = Callable[[Enum_Parameter, DefaultArg(Optional[Data_Parameter]),
|
228
|
+
NamedArg(int, 'version'), KwArg(Any)], Schema_Parameter]
|
229
|
+
|
230
|
+
__all__ = ['HIP']
|
231
|
+
|
232
|
+
|
233
|
+
if SPHINX_TYPE_CHECKING:
|
234
|
+
from typing_extensions import TypedDict
|
235
|
+
|
236
|
+
class Locator(TypedDict):
|
237
|
+
"""Locator dictionary type."""
|
238
|
+
|
239
|
+
#: Traffic type.
|
240
|
+
traffic: 'int'
|
241
|
+
#: Locator type.
|
242
|
+
type: 'int'
|
243
|
+
#: Preferred flag.
|
244
|
+
preferred: 'bool'
|
245
|
+
#: Lifetime.
|
246
|
+
lifetime: 'timedelta | int'
|
247
|
+
#: IP address.
|
248
|
+
ip: 'IPv6Address | bytes | int | str'
|
249
|
+
#: SPI.
|
250
|
+
spi: 'NotRequired[int]'
|
251
|
+
|
252
|
+
|
253
|
+
class HIP(Internet[Data_HIP, Schema_HIP],
|
254
|
+
schema=Schema_HIP, data=Data_HIP):
|
255
|
+
"""This class implements Host Identity Protocol.
|
256
|
+
|
257
|
+
This class currently supports parsing of the following HIP parameters,
|
258
|
+
which are directly mapped to the :class:`pcapkit.const.hip.parameter.Parameter`
|
259
|
+
enumeration:
|
260
|
+
|
261
|
+
.. list-table::
|
262
|
+
:header-rows: 1
|
263
|
+
|
264
|
+
* - Parameter Code
|
265
|
+
- Parameter Parser
|
266
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.ESP_INFO`
|
267
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_esp_info`
|
268
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.R1_COUNTER`
|
269
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_r1_counter`
|
270
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.LOCATOR_SET`
|
271
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_locator_set`
|
272
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.PUZZLE`
|
273
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_puzzle`
|
274
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.SOLUTION`
|
275
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_solution`
|
276
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.SEQ`
|
277
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_seq`
|
278
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.ACK`
|
279
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_ack`
|
280
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.DH_GROUP_LIST`
|
281
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_dh_group_list`
|
282
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.DIFFIE_HELLMAN`
|
283
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_diffie_hellman`
|
284
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.HIP_TRANSFORM`
|
285
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_hip_transform`
|
286
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.HIP_CIPHER`
|
287
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_hip_cipher`
|
288
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.NAT_TRAVERSAL_MODE`
|
289
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_nat_traversal_mode`
|
290
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.TRANSACTION_PACING`
|
291
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_transaction_pacing`
|
292
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.ENCRYPTED`
|
293
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_encrypted`
|
294
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.HOST_ID`
|
295
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_host_id`
|
296
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.HIT_SUITE_LIST`
|
297
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_hit_suite_list`
|
298
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.CERT`
|
299
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_cert`
|
300
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.NOTIFICATION`
|
301
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_notification`
|
302
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.ECHO_REQUEST_SIGNED`
|
303
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_echo_request_signed`
|
304
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.REG_INFO`
|
305
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_reg_info`
|
306
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.REG_REQUEST`
|
307
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_reg_request`
|
308
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.REG_RESPONSE`
|
309
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_reg_response`
|
310
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.REG_FAILED`
|
311
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_reg_failed`
|
312
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.REG_FROM`
|
313
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_reg_from`
|
314
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.ECHO_RESPONSE_SIGNED`
|
315
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_echo_response_signed`
|
316
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.TRANSPORT_FORMAT_LIST`
|
317
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_transport_format_list`
|
318
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.ESP_TRANSFORM`
|
319
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_esp_transform`
|
320
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.SEQ_DATA`
|
321
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_seq_data`
|
322
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.ACK_DATA`
|
323
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_ack_data`
|
324
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.PAYLOAD_MIC`
|
325
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_payload_mic`
|
326
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.TRANSACTION_ID`
|
327
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_transaction_id`
|
328
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.OVERLAY_ID`
|
329
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_overlay_id`
|
330
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.ROUTE_DST`
|
331
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_route_dst`
|
332
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.HIP_TRANSPORT_MODE`
|
333
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_hip_transport_mode`
|
334
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.HIP_MAC`
|
335
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_hip_mac`
|
336
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.HIP_MAC_2`
|
337
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_hip_mac_2`
|
338
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.HIP_SIGNATURE_2`
|
339
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_hip_signature_2`
|
340
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.HIP_SIGNATURE`
|
341
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_hip_signature`
|
342
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.ECHO_REQUEST_UNSIGNED`
|
343
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_echo_request_unsigned`
|
344
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.ECHO_RESPONSE_UNSIGNED`
|
345
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_echo_response_unsigned`
|
346
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.RELAY_FROM`
|
347
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_relay_from`
|
348
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.RELAY_TO`
|
349
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_relay_to`
|
350
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.OVERLAY_TTL`
|
351
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_overlay_ttl`
|
352
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.ROUTE_VIA`
|
353
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_route_via`
|
354
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.FROM`
|
355
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_from`
|
356
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.RVS_HMAC`
|
357
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_rvs_hmac`
|
358
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.VIA_RVS`
|
359
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_via_rvs`
|
360
|
+
* - :attr:`~pcapkit.const.hip.parameter.Parameter.RELAY_HMAC`
|
361
|
+
- :meth:`~pcapkit.protocols.internet.hip.HIP._read_param_relay_hmac`
|
362
|
+
|
363
|
+
"""
|
364
|
+
|
365
|
+
##########################################################################
|
366
|
+
# Properties.
|
367
|
+
##########################################################################
|
368
|
+
|
369
|
+
@property
|
370
|
+
def name(self) -> 'Literal["Host Identity Protocol"]':
|
371
|
+
"""Name of current protocol."""
|
372
|
+
return 'Host Identity Protocol'
|
373
|
+
|
374
|
+
@property
|
375
|
+
def alias(self) -> 'str':
|
376
|
+
"""Acronym of corresponding protocol."""
|
377
|
+
return f'HIPv{self._info.version}'
|
378
|
+
|
379
|
+
@property
|
380
|
+
def length(self) -> 'int':
|
381
|
+
"""Header length of current protocol."""
|
382
|
+
return self._info.length
|
383
|
+
|
384
|
+
@property
|
385
|
+
def payload(self) -> 'Protocol | NoReturn':
|
386
|
+
"""Payload of current instance.
|
387
|
+
|
388
|
+
Raises:
|
389
|
+
UnsupportedCall: if the protocol is used as an IPv6 extension header
|
390
|
+
|
391
|
+
:rtype: pcapkit.protocols.protocol.Protocol
|
392
|
+
"""
|
393
|
+
if self._extf:
|
394
|
+
raise UnsupportedCall(f"'{self.__class__.__name__}' object has no attribute 'payload'")
|
395
|
+
return self._next
|
396
|
+
|
397
|
+
@property
|
398
|
+
def protocol(self) -> 'Optional[str] | NoReturn':
|
399
|
+
"""Name of next layer protocol (if any).
|
400
|
+
|
401
|
+
Raises:
|
402
|
+
UnsupportedCall: if the protocol is used as an IPv6 extension header
|
403
|
+
|
404
|
+
"""
|
405
|
+
if self._extf:
|
406
|
+
raise UnsupportedCall(f"'{self.__class__.__name__}' object has no attribute 'protocol'")
|
407
|
+
return super().protocol
|
408
|
+
|
409
|
+
@property
|
410
|
+
def protochain(self) -> 'ProtoChain | NoReturn':
|
411
|
+
"""Protocol chain of current instance.
|
412
|
+
|
413
|
+
Raises:
|
414
|
+
UnsupportedCall: if the protocol is used as an IPv6 extension header
|
415
|
+
|
416
|
+
"""
|
417
|
+
if self._extf:
|
418
|
+
raise UnsupportedCall(f"'{self.__class__.__name__}' object has no attribute 'protochain'")
|
419
|
+
return super().protochain
|
420
|
+
|
421
|
+
##########################################################################
|
422
|
+
# Methods.
|
423
|
+
##########################################################################
|
424
|
+
|
425
|
+
def read(self, length: 'Optional[int]' = None, *, extension: bool = False, **kwargs: 'Any') -> 'Data_HIP': # pylint: disable=arguments-differ,unused-argument
|
426
|
+
"""Read Host Identity Protocol.
|
427
|
+
|
428
|
+
Structure of HIP header [:rfc:`5201`][:rfc:`7401`]:
|
429
|
+
|
430
|
+
.. code-block:: text
|
431
|
+
|
432
|
+
0 1 2 3
|
433
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
434
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
435
|
+
| Next Header | Header Length |0| Packet Type |Version| RES.|1|
|
436
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
437
|
+
| Checksum | Controls |
|
438
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
439
|
+
| Sender's Host Identity Tag (HIT) |
|
440
|
+
| |
|
441
|
+
| |
|
442
|
+
| |
|
443
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
444
|
+
| Receiver's Host Identity Tag (HIT) |
|
445
|
+
| |
|
446
|
+
| |
|
447
|
+
| |
|
448
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
449
|
+
| |
|
450
|
+
/ HIP Parameters /
|
451
|
+
/ /
|
452
|
+
| |
|
453
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
454
|
+
|
455
|
+
Args:
|
456
|
+
length: Length of packet data.
|
457
|
+
extension: If the packet is used as an IPv6 extension header.
|
458
|
+
**kwargs: Arbitrary keyword arguments.
|
459
|
+
|
460
|
+
Returns:
|
461
|
+
Parsed packet data.
|
462
|
+
|
463
|
+
Raises:
|
464
|
+
ProtocolError: If the packet is malformed.
|
465
|
+
|
466
|
+
"""
|
467
|
+
if length is None:
|
468
|
+
length = len(self)
|
469
|
+
schema = self.__header__
|
470
|
+
|
471
|
+
if schema.pkt['bit_0'] != 0:
|
472
|
+
raise ProtocolError('HIP: invalid format')
|
473
|
+
if schema.ver['bit_1'] != 1:
|
474
|
+
raise ProtocolError('HIP: invalid format')
|
475
|
+
|
476
|
+
hip = Data_HIP(
|
477
|
+
next=schema.next,
|
478
|
+
length=schema.len * 8 + 8,
|
479
|
+
type=Enum_Packet(schema.pkt['type']),
|
480
|
+
version=schema.ver['version'],
|
481
|
+
chksum=schema.checksum,
|
482
|
+
control=Data_Control(
|
483
|
+
anonymous=bool(schema.control['anonymous']),
|
484
|
+
),
|
485
|
+
shit=schema.shit,
|
486
|
+
rhit=schema.rhit,
|
487
|
+
)
|
488
|
+
|
489
|
+
_prml = (schema.len - 4) * 8
|
490
|
+
if _prml:
|
491
|
+
hip.__update__([
|
492
|
+
('parameters', self._read_hip_param(_prml, version=hip.version)),
|
493
|
+
])
|
494
|
+
|
495
|
+
if extension:
|
496
|
+
return hip
|
497
|
+
return self._decode_next_layer(hip, schema.next, length - hip.length)
|
498
|
+
|
499
|
+
def make(self,
|
500
|
+
next: 'Enum_TransType | StdlibEnum | AenumEnum | str | int' = Enum_TransType.UDP,
|
501
|
+
next_default: 'Optional[int]' = None,
|
502
|
+
next_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
503
|
+
next_reversed: 'bool' = False,
|
504
|
+
packet: 'Enum_Packet | StdlibEnum | AenumEnum | str | int' = Enum_Packet.HIP_DATA,
|
505
|
+
packet_default: 'Optional[int]' = None,
|
506
|
+
packet_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
507
|
+
packet_reversed: 'bool' = False,
|
508
|
+
version: 'int' = 2,
|
509
|
+
checksum: 'bytes' = b'\x00\x00',
|
510
|
+
controls_anonymous: 'bool' = False,
|
511
|
+
shit: 'int' = 0,
|
512
|
+
rhit: 'int' = 0,
|
513
|
+
parameters: 'Optional[list[Schema_Parameter | tuple[Enum_Parameter, dict[str, Any]] | bytes] | Parameter]' = None, # pylint: disable=line-too-long
|
514
|
+
payload: 'bytes | Protocol | Schema' = b'',
|
515
|
+
**kwargs: 'Any') -> 'Schema_HIP':
|
516
|
+
"""Make (construct) packet data.
|
517
|
+
|
518
|
+
Args:
|
519
|
+
next: Next header type.
|
520
|
+
next_default: Default value for next header type.
|
521
|
+
next_namespace: Namespace for next header type.
|
522
|
+
next_reversed: If the next header type is reversed.
|
523
|
+
packet: HIP packet type.
|
524
|
+
packet_default: Default value for HIP packet type.
|
525
|
+
packet_namespace: Namespace for HIP packet type.
|
526
|
+
packet_reversed: If the HIP packet type is reversed.
|
527
|
+
version: HIP version.
|
528
|
+
checksum: Checksum.
|
529
|
+
controls_anonymous: If the sender is anonymous.
|
530
|
+
shit: Sender's host identity tag (HIT).
|
531
|
+
rhit: Receiver's host identity tag (HIT).
|
532
|
+
parameters: HIP parameters.
|
533
|
+
payload: Payload.
|
534
|
+
**kwargs: Arbitrary keyword arguments.
|
535
|
+
|
536
|
+
Returns:
|
537
|
+
Constructed packet data.
|
538
|
+
|
539
|
+
"""
|
540
|
+
next_value = self._make_index(next, next_default, namespace=next_namespace,
|
541
|
+
reversed=next_reversed, pack=False)
|
542
|
+
packet_value = self._make_index(packet, packet_default, namespace=packet_namespace,
|
543
|
+
reversed=packet_reversed, pack=False)
|
544
|
+
|
545
|
+
if parameters is not None:
|
546
|
+
parameters_value, total_length = self._make_hip_param(parameters, version=version)
|
547
|
+
length = total_length // 8 + 4
|
548
|
+
else:
|
549
|
+
parameters_value, length = [], 0
|
550
|
+
|
551
|
+
return Schema_HIP(
|
552
|
+
next=next_value, # type: ignore[arg-type]
|
553
|
+
len=length,
|
554
|
+
pkt = {
|
555
|
+
'bit_0': 0,
|
556
|
+
'type': packet_value,
|
557
|
+
},
|
558
|
+
ver = {
|
559
|
+
'bit_1': 1,
|
560
|
+
'version': version,
|
561
|
+
},
|
562
|
+
checksum=checksum,
|
563
|
+
control = {
|
564
|
+
'anonymous': controls_anonymous,
|
565
|
+
},
|
566
|
+
shit=shit,
|
567
|
+
rhit=rhit,
|
568
|
+
param=parameters_value,
|
569
|
+
payload=payload,
|
570
|
+
)
|
571
|
+
|
572
|
+
@classmethod
|
573
|
+
def register_parameter(cls, code: 'Enum_Parameter', meth: 'str | tuple[ParameterParser, ParameterConstructor]') -> 'None':
|
574
|
+
"""Register a parameter parser.
|
575
|
+
|
576
|
+
Args:
|
577
|
+
code: IPv4 option code.
|
578
|
+
meth: Method name or callable to parse and/or construct the option.
|
579
|
+
|
580
|
+
"""
|
581
|
+
name = code.name.lower()
|
582
|
+
if hasattr(cls, f'_read_param_{name}'):
|
583
|
+
warn(f'parameter {code} already registered, overwriting', RegistryWarning)
|
584
|
+
|
585
|
+
if isinstance(meth, str):
|
586
|
+
meth = (getattr(cls, f'_read_param_{meth}', cls._read_param_unassigned), # type: ignore[arg-type]
|
587
|
+
getattr(cls, f'_make_param_{meth}', cls._make_param_unassigned)) # type: ignore[arg-type]
|
588
|
+
|
589
|
+
setattr(cls, f'_read_param_{name}', meth[0])
|
590
|
+
setattr(cls, f'_make_param_{name}', meth[1])
|
591
|
+
|
592
|
+
##########################################################################
|
593
|
+
# Data models.
|
594
|
+
##########################################################################
|
595
|
+
|
596
|
+
@overload
|
597
|
+
def __post_init__(self, file: 'IO[bytes] | bytes', length: 'Optional[int]' = ..., *, # pylint: disable=arguments-differ
|
598
|
+
extension: 'bool' = ..., **kwargs: 'Any') -> 'None': ...
|
599
|
+
|
600
|
+
@overload
|
601
|
+
def __post_init__(self, **kwargs: 'Any') -> 'None': ... # pylint: disable=arguments-differ
|
602
|
+
|
603
|
+
def __post_init__(self, file: 'Optional[IO[bytes] | bytes]' = None, length: 'Optional[int]' = None, *, # pylint: disable=arguments-differ
|
604
|
+
extension: 'bool' = False, **kwargs: 'Any') -> 'None':
|
605
|
+
"""Post initialisation hook.
|
606
|
+
|
607
|
+
Args:
|
608
|
+
file: Source packet stream.
|
609
|
+
length: Length of packet data.
|
610
|
+
extension: If the protocol is used as an IPv6 extension header.
|
611
|
+
**kwargs: Arbitrary keyword arguments.
|
612
|
+
|
613
|
+
See Also:
|
614
|
+
For construction argument, please refer to :meth:`self.make <HIP.make>`.
|
615
|
+
|
616
|
+
"""
|
617
|
+
#: bool: If the protocol is used as an IPv6 extension header.
|
618
|
+
self._extf = extension
|
619
|
+
|
620
|
+
# call super __post_init__
|
621
|
+
super().__post_init__(file, length, extension=extension, **kwargs) # type: ignore[arg-type]
|
622
|
+
|
623
|
+
def __length_hint__(self) -> 'Literal[40]':
|
624
|
+
"""Return an estimated length for the object."""
|
625
|
+
return 40
|
626
|
+
|
627
|
+
@classmethod
|
628
|
+
def __index__(cls) -> 'Enum_TransType': # pylint: disable=invalid-index-returned
|
629
|
+
"""Numeral registry index of the protocol.
|
630
|
+
|
631
|
+
Returns:
|
632
|
+
Numeral registry index of the protocol in `IANA`_.
|
633
|
+
|
634
|
+
.. _IANA: https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
|
635
|
+
|
636
|
+
"""
|
637
|
+
return Enum_TransType.HIP # type: ignore[return-value]
|
638
|
+
|
639
|
+
##########################################################################
|
640
|
+
# Utilities.
|
641
|
+
##########################################################################
|
642
|
+
|
643
|
+
@classmethod
|
644
|
+
def _make_data(cls, data: 'Data_HIP') -> 'dict[str, Any]': # type: ignore[override]
|
645
|
+
"""Create key-value pairs from ``data`` for protocol construction.
|
646
|
+
|
647
|
+
Args:
|
648
|
+
data: protocol data
|
649
|
+
|
650
|
+
Returns:
|
651
|
+
Key-value pairs for protocol construction.
|
652
|
+
|
653
|
+
"""
|
654
|
+
return {
|
655
|
+
'next': data.next,
|
656
|
+
'packet': data.type,
|
657
|
+
'version': data.version,
|
658
|
+
'checksum': data.chksum,
|
659
|
+
'controls_anonymous': data.control.anonymous,
|
660
|
+
'shit': data.shit,
|
661
|
+
'rhit': data.rhit,
|
662
|
+
'parameters': data.parameters,
|
663
|
+
'payload': cls._make_payload(data),
|
664
|
+
}
|
665
|
+
|
666
|
+
def _read_hip_param(self, length: 'int', *, version: 'int') -> 'Parameter': # pylint: disable=line-too-long
|
667
|
+
"""Read HIP parameters.
|
668
|
+
|
669
|
+
Arguments:
|
670
|
+
length: length of parameters
|
671
|
+
version: HIP version
|
672
|
+
|
673
|
+
Returns:
|
674
|
+
Extracted HIP parameters.
|
675
|
+
|
676
|
+
Raises:
|
677
|
+
ProtocolError: if packet length threshold check failed
|
678
|
+
|
679
|
+
"""
|
680
|
+
counter = 0 # length of read parameters
|
681
|
+
options = OrderedMultiDict() # type: Parameter
|
682
|
+
|
683
|
+
for schema in self.__header__.param:
|
684
|
+
dscp = schema.type
|
685
|
+
|
686
|
+
meth_name = f'_read_param_{dscp.name.lower()}'
|
687
|
+
meth = cast('ParameterParser',
|
688
|
+
getattr(self, meth_name, self._read_param_unassigned))
|
689
|
+
data = meth(schema, version=version, options=options)
|
690
|
+
|
691
|
+
# record parameter data
|
692
|
+
options.add(dscp, data)
|
693
|
+
counter += len(schema)
|
694
|
+
|
695
|
+
# check threshold
|
696
|
+
if counter != length:
|
697
|
+
raise ProtocolError(f'HIPv{version}: invalid format')
|
698
|
+
return options
|
699
|
+
|
700
|
+
def _read_param_unassigned(self, schema: 'Schema_UnassignedParameter', *, version: 'int', # pylint: disable=unused-argument
|
701
|
+
options: 'Parameter') -> 'Data_UnassignedParameter': # pylint: disable=unused-argument
|
702
|
+
"""Read HIP unassigned parameters.
|
703
|
+
|
704
|
+
Structure of HIP unassigned parameters [:rfc:`5201`][:rfc:`7401`]:
|
705
|
+
|
706
|
+
.. code-block:: text
|
707
|
+
|
708
|
+
0 1 2 3
|
709
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
710
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
711
|
+
| Type |C| Length |
|
712
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
713
|
+
| |
|
714
|
+
/ Contents /
|
715
|
+
/ +-+-+-+-+-+-+-+-+
|
716
|
+
| | Padding |
|
717
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
718
|
+
|
719
|
+
Args:
|
720
|
+
schema: parsed parameter schama
|
721
|
+
version: HIP protocol version
|
722
|
+
options: parsed HIP parameters
|
723
|
+
|
724
|
+
Returns:
|
725
|
+
Parsed parameter data.
|
726
|
+
|
727
|
+
"""
|
728
|
+
unassigned = Data_UnassignedParameter(
|
729
|
+
type=schema.type,
|
730
|
+
critical=bool(schema.type & 0b1),
|
731
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
732
|
+
contents=schema.value,
|
733
|
+
)
|
734
|
+
return unassigned
|
735
|
+
|
736
|
+
def _read_param_esp_info(self, schema: 'Schema_ESPInfoParameter', *, version: 'int', # pylint: disable=unused-argument
|
737
|
+
options: 'Parameter') -> 'Data_ESPInfoParameter': # pylint: disable=unused-argument
|
738
|
+
"""Read HIP ``ESP_INFO`` parameter.
|
739
|
+
|
740
|
+
Structure of HIP ``ESP_INFO`` parameter [:rfc:`7402`]:
|
741
|
+
|
742
|
+
.. code-block:: text
|
743
|
+
|
744
|
+
0 1 2 3
|
745
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
746
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
747
|
+
| Type | Length |
|
748
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
749
|
+
| Reserved | KEYMAT Index |
|
750
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
751
|
+
| OLD SPI |
|
752
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
753
|
+
| NEW SPI |
|
754
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
755
|
+
|
756
|
+
Args:
|
757
|
+
schema: parsed parameter schama
|
758
|
+
version: HIP protocol version
|
759
|
+
options: parsed HIP parameters
|
760
|
+
|
761
|
+
Returns:
|
762
|
+
Parsed parameter data.
|
763
|
+
|
764
|
+
Raises:
|
765
|
+
ProtocolError: If ``schema.len`` is **NOT** ``12``.
|
766
|
+
|
767
|
+
"""
|
768
|
+
if schema.len != 12:
|
769
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
770
|
+
|
771
|
+
esp_info = Data_ESPInfoParameter(
|
772
|
+
type=schema.type,
|
773
|
+
critical=bool(schema.type & 0b1),
|
774
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
775
|
+
index=schema.index,
|
776
|
+
old_spi=schema.old_spi,
|
777
|
+
new_spi=schema.new_spi,
|
778
|
+
)
|
779
|
+
return esp_info
|
780
|
+
|
781
|
+
def _read_param_r1_counter(self, schema: 'Schema_R1CounterParameter', *, version: 'int', # pylint: disable=unused-argument
|
782
|
+
options: 'Parameter') -> 'Data_R1CounterParameter': # pylint: disable=unused-argument
|
783
|
+
"""Read HIP ``R1_COUNTER`` parameter.
|
784
|
+
|
785
|
+
Structure of HIP ``R1_COUNTER`` parameter [:rfc:`5201`][:rfc:`7401`]:
|
786
|
+
|
787
|
+
.. code-block:: text
|
788
|
+
|
789
|
+
0 1 2 3
|
790
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
791
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
792
|
+
| Type | Length |
|
793
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
794
|
+
| Reserved, 4 bytes |
|
795
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
796
|
+
| R1 generation counter, 8 bytes |
|
797
|
+
| |
|
798
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
799
|
+
|
800
|
+
Args:
|
801
|
+
schema: parsed parameter schama
|
802
|
+
version: HIP protocol version
|
803
|
+
options: parsed HIP parameters
|
804
|
+
|
805
|
+
Returns:
|
806
|
+
Parsed parameter data.
|
807
|
+
|
808
|
+
Raises:
|
809
|
+
ProtocolError: If ``schema.len`` is **NOT** ``12`` or the parameter is **NOT** used in HIPv1.
|
810
|
+
|
811
|
+
"""
|
812
|
+
if schema.len != 12:
|
813
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
814
|
+
if schema.type == 128 and version != 1:
|
815
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid parameter')
|
816
|
+
|
817
|
+
r1_counter = Data_R1CounterParameter(
|
818
|
+
type=schema.type,
|
819
|
+
critical=bool(schema.type & 0b1),
|
820
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
821
|
+
counter=schema.counter,
|
822
|
+
)
|
823
|
+
return r1_counter
|
824
|
+
|
825
|
+
def _read_param_locator_set(self, schema: 'Schema_LocatorSetParameter', *, version: 'int', # pylint: disable=unused-argument
|
826
|
+
options: 'Parameter') -> 'Data_LocatorSetParameter': # pylint: disable=unused-argument
|
827
|
+
"""Read HIP ``LOCATOR_SET`` parameter.
|
828
|
+
|
829
|
+
Structure of HIP ``LOCATOR_SET`` parameter [:rfc:`8046`]:
|
830
|
+
|
831
|
+
.. code-block:: text
|
832
|
+
|
833
|
+
0 1 2 3
|
834
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
835
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
836
|
+
| Type | Length |
|
837
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
838
|
+
| Traffic Type | Locator Type | Locator Length | Reserved |P|
|
839
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
840
|
+
| Locator Lifetime |
|
841
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
842
|
+
| Locator |
|
843
|
+
| |
|
844
|
+
| |
|
845
|
+
| |
|
846
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
847
|
+
. .
|
848
|
+
. .
|
849
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
850
|
+
| Traffic Type | Locator Type | Locator Length | Reserved |P|
|
851
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
852
|
+
| Locator Lifetime |
|
853
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
854
|
+
| Locator |
|
855
|
+
| |
|
856
|
+
| |
|
857
|
+
| |
|
858
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
859
|
+
|
860
|
+
Args:
|
861
|
+
schema: parsed parameter schama
|
862
|
+
version: HIP protocol version
|
863
|
+
options: parsed HIP parameters
|
864
|
+
|
865
|
+
Returns:
|
866
|
+
Parsed parameter data.
|
867
|
+
|
868
|
+
Raises:
|
869
|
+
ProtocolError: If locator data is malformed.
|
870
|
+
|
871
|
+
"""
|
872
|
+
def _read_locator(locator: 'Schema_Locator') -> 'Data_LocatorData | IPv6Address':
|
873
|
+
"""Parse locator data.
|
874
|
+
|
875
|
+
Args:
|
876
|
+
locator: locator data
|
877
|
+
|
878
|
+
Returns:
|
879
|
+
* If ``kind`` is ``0`` and ``size`` is ``16``,
|
880
|
+
returns an :class:`~ipaddress.IPv4Address` object.
|
881
|
+
* If ``kind`` is ``1`` and ``size`` is ``20``,
|
882
|
+
returns a :class:`~pcapkit.protocols.data.internet.hip.Locator` object.
|
883
|
+
|
884
|
+
Raises:
|
885
|
+
ProtocolError: in other cases
|
886
|
+
|
887
|
+
"""
|
888
|
+
kind = locator.type
|
889
|
+
size = 8 + locator.len * 4
|
890
|
+
|
891
|
+
if kind == 0 and locator.len == 4:
|
892
|
+
return cast('IPv6Address', locator.value)
|
893
|
+
if kind == 1 and locator.len == 5:
|
894
|
+
loc_val = cast('Schema_LocatorData', locator.value)
|
895
|
+
return Data_LocatorData(
|
896
|
+
spi=loc_val.spi,
|
897
|
+
ip=ipaddress.ip_address(loc_val.ip), # type: ignore[arg-type]
|
898
|
+
)
|
899
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
900
|
+
|
901
|
+
# length of read locators
|
902
|
+
_size = 0
|
903
|
+
# list of locators
|
904
|
+
_locs = [] # type: list[Data_Locator]
|
905
|
+
|
906
|
+
for locator in schema.locators:
|
907
|
+
_traf = locator.traffic
|
908
|
+
_loct = locator.type
|
909
|
+
_locl = locator.len * 4
|
910
|
+
_resp = locator.flags
|
911
|
+
_life = locator.lifetime
|
912
|
+
_lobj = _read_locator(locator)
|
913
|
+
|
914
|
+
_locs.append(Data_Locator(
|
915
|
+
traffic=_traf,
|
916
|
+
type=_loct,
|
917
|
+
length=_locl,
|
918
|
+
preferred=bool(_resp['preferred']),
|
919
|
+
lifetime=datetime.timedelta(seconds=_life),
|
920
|
+
locator=_lobj,
|
921
|
+
))
|
922
|
+
|
923
|
+
locator_set = Data_LocatorSetParameter(
|
924
|
+
type=schema.type,
|
925
|
+
critical=bool(schema.type & 0b1),
|
926
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
927
|
+
locator_set=tuple(_locs),
|
928
|
+
)
|
929
|
+
|
930
|
+
return locator_set
|
931
|
+
|
932
|
+
def _read_param_puzzle(self, schema: 'Schema_PuzzleParameter', *, version: 'int',
|
933
|
+
options: 'Parameter') -> 'Data_PuzzleParameter': # pylint: disable=unused-argument
|
934
|
+
"""Read HIP ``PUZZLE`` parameter.
|
935
|
+
|
936
|
+
Structure of HIP ``PUZZLE`` parameter [:rfc:`5201`][:rfc:`7401`]:
|
937
|
+
|
938
|
+
.. code-block:: text
|
939
|
+
|
940
|
+
0 1 2 3
|
941
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
942
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
943
|
+
| Type | Length |
|
944
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
945
|
+
| #K, 1 byte | Lifetime | Opaque, 2 bytes |
|
946
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
947
|
+
| Random #I, RHASH_len / 8 bytes |
|
948
|
+
/ /
|
949
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
950
|
+
|
951
|
+
Args:
|
952
|
+
schema: parsed parameter schama
|
953
|
+
version: HIP protocol version
|
954
|
+
options: parsed HIP parameters
|
955
|
+
|
956
|
+
Returns:
|
957
|
+
Parsed parameter data.
|
958
|
+
|
959
|
+
Raises:
|
960
|
+
ProtocolError: The parameter is **ONLY** supported in HIPv1.
|
961
|
+
|
962
|
+
"""
|
963
|
+
if version == 1 and schema.len != 12:
|
964
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
965
|
+
|
966
|
+
_numk = schema.index
|
967
|
+
_time = schema.lifetime
|
968
|
+
_opak = schema.opaque
|
969
|
+
_rand = schema.random # Length (schema.len) = 4 + RHASH_len / 8
|
970
|
+
|
971
|
+
puzzle = Data_PuzzleParameter(
|
972
|
+
type=schema.type,
|
973
|
+
critical=bool(schema.type & 0b1),
|
974
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
975
|
+
index=_numk,
|
976
|
+
lifetime=datetime.timedelta(seconds=2 ** (_time - 32)),
|
977
|
+
opaque=_opak,
|
978
|
+
random=_rand,
|
979
|
+
)
|
980
|
+
return puzzle
|
981
|
+
|
982
|
+
def _read_param_solution(self, schema: 'Schema_SolutionParameter', *, version: 'int',
|
983
|
+
options: 'Parameter') -> 'Data_SolutionParameter': # pylint: disable=unused-argument
|
984
|
+
"""Read HIP ``SOLUTION`` parameter.
|
985
|
+
|
986
|
+
Structure of HIP ``SOLUTION`` parameter [:rfc:`5201`][:rfc:`7401`]:
|
987
|
+
|
988
|
+
.. code-block:: text
|
989
|
+
|
990
|
+
0 1 2 3
|
991
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
992
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
993
|
+
| Type | Length |
|
994
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
995
|
+
| #K, 1 byte | Lifetime | Opaque, 2 bytes |
|
996
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
997
|
+
| Random #I, n bytes |
|
998
|
+
/ /
|
999
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1000
|
+
| Puzzle solution #J, RHASH_len / 8 bytes |
|
1001
|
+
/ /
|
1002
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1003
|
+
|
1004
|
+
Args:
|
1005
|
+
schema: parsed parameter schama
|
1006
|
+
version: HIP protocol version
|
1007
|
+
options: parsed HIP parameters
|
1008
|
+
|
1009
|
+
Returns:
|
1010
|
+
Parsed parameter data.
|
1011
|
+
|
1012
|
+
Raises:
|
1013
|
+
ProtocolError: The parameter is **ONLY** supported in HIPv1.
|
1014
|
+
|
1015
|
+
"""
|
1016
|
+
if version == 1 and schema.len != 20:
|
1017
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
1018
|
+
if (schema.len - 4) % 2 != 0:
|
1019
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
1020
|
+
|
1021
|
+
_numk = schema.index
|
1022
|
+
_time = schema.lifetime
|
1023
|
+
_opak = schema.opaque
|
1024
|
+
_rand = schema.random
|
1025
|
+
_solt = schema.solution # Length (schema.len) = 4 + RHASH_len / 4
|
1026
|
+
|
1027
|
+
solution = Data_SolutionParameter(
|
1028
|
+
type=schema.type,
|
1029
|
+
critical=bool(schema.type & 0b1),
|
1030
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1031
|
+
index=_numk,
|
1032
|
+
lifetime=datetime.timedelta(seconds=2 ** (_time - 32)),
|
1033
|
+
opaque=_opak,
|
1034
|
+
random=_rand,
|
1035
|
+
solution=_solt,
|
1036
|
+
)
|
1037
|
+
return solution
|
1038
|
+
|
1039
|
+
def _read_param_seq(self, schema: 'Schema_SEQParameter', *, version: 'int', # pylint: disable=unused-argument
|
1040
|
+
options: 'Parameter') -> 'Data_SEQParameter': # pylint: disable=unused-argument
|
1041
|
+
"""Read HIP ``SEQ`` parameter.
|
1042
|
+
|
1043
|
+
Structure of HIP ``SEQ`` parameter [:rfc:`7401`]:
|
1044
|
+
|
1045
|
+
.. code-block:: text
|
1046
|
+
|
1047
|
+
0 1 2 3
|
1048
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1049
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1050
|
+
| Type | Length |
|
1051
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1052
|
+
| Update ID |
|
1053
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1054
|
+
|
1055
|
+
Args:
|
1056
|
+
schema: parsed parameter schama
|
1057
|
+
version: HIP protocol version
|
1058
|
+
options: parsed HIP parameters
|
1059
|
+
|
1060
|
+
Returns:
|
1061
|
+
Parsed parameter data.
|
1062
|
+
|
1063
|
+
Raises:
|
1064
|
+
ProtocolError: If ``schema.len`` is **NOT** ``4``.
|
1065
|
+
|
1066
|
+
"""
|
1067
|
+
if schema.len != 4:
|
1068
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
1069
|
+
|
1070
|
+
_upid = schema.update_id
|
1071
|
+
|
1072
|
+
seq = Data_SEQParameter(
|
1073
|
+
type=schema.type,
|
1074
|
+
critical=bool(schema.type & 0b1),
|
1075
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1076
|
+
id=_upid,
|
1077
|
+
)
|
1078
|
+
return seq
|
1079
|
+
|
1080
|
+
def _read_param_ack(self, schema: 'Schema_ACKParameter', *, version: 'int', # pylint: disable=unused-argument
|
1081
|
+
options: 'Parameter') -> 'Data_ACKParameter': # pylint: disable=unused-argument
|
1082
|
+
"""Read HIP ``ACK`` parameter.
|
1083
|
+
|
1084
|
+
Structure of HIP ``ACK`` parameter [:rfc:`7401`]:
|
1085
|
+
|
1086
|
+
.. code-block:: text
|
1087
|
+
|
1088
|
+
0 1 2 3
|
1089
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1090
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1091
|
+
| Type | Length |
|
1092
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1093
|
+
| peer Update ID 1 |
|
1094
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1095
|
+
/ peer Update ID n |
|
1096
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1097
|
+
|
1098
|
+
Args:
|
1099
|
+
schema: parsed parameter schama
|
1100
|
+
version: HIP protocol version
|
1101
|
+
options: parsed HIP parameters
|
1102
|
+
|
1103
|
+
Returns:
|
1104
|
+
Parsed parameter data.
|
1105
|
+
|
1106
|
+
Raises:
|
1107
|
+
ProtocolError: If ``schema.len`` is **NOT** ``4`` modulo.
|
1108
|
+
|
1109
|
+
"""
|
1110
|
+
if schema.len % 4 != 0:
|
1111
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
1112
|
+
|
1113
|
+
ack = Data_ACKParameter(
|
1114
|
+
type=schema.type,
|
1115
|
+
critical=bool(schema.type & 0b1),
|
1116
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1117
|
+
update_id=tuple(schema.update_id),
|
1118
|
+
)
|
1119
|
+
return ack
|
1120
|
+
|
1121
|
+
def _read_param_dh_group_list(self, schema: 'Schema_DHGroupListParameter', *, version: 'int', # pylint: disable=unused-argument
|
1122
|
+
options: 'Parameter') -> 'Data_DHGroupListParameter': # pylint: disable=unused-argument
|
1123
|
+
"""Read HIP ``DH_GROUP_LIST`` parameter.
|
1124
|
+
|
1125
|
+
Structure of HIP ``DH_GROUP_LIST`` parameter [:rfc:`7401`]:
|
1126
|
+
|
1127
|
+
.. code-block:: text
|
1128
|
+
|
1129
|
+
0 1 2 3
|
1130
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1131
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1132
|
+
| Type | Length |
|
1133
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1134
|
+
| DH GROUP ID #1| DH GROUP ID #2| DH GROUP ID #3| DH GROUP ID #4|
|
1135
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1136
|
+
| DH GROUP ID #n| Padding |
|
1137
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1138
|
+
|
1139
|
+
Args:
|
1140
|
+
schema: parsed parameter schama
|
1141
|
+
version: HIP protocol version
|
1142
|
+
options: parsed HIP parameters
|
1143
|
+
|
1144
|
+
Returns:
|
1145
|
+
Parsed parameter data.
|
1146
|
+
|
1147
|
+
"""
|
1148
|
+
dh_group_list = Data_DHGroupListParameter(
|
1149
|
+
type=schema.type,
|
1150
|
+
critical=bool(schema.type & 0b1),
|
1151
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1152
|
+
group_id=tuple(schema.groups),
|
1153
|
+
)
|
1154
|
+
return dh_group_list
|
1155
|
+
|
1156
|
+
def _read_param_diffie_hellman(self, schema: 'Schema_DiffieHellmanParameter', *, version: 'int', # pylint: disable=unused-argument
|
1157
|
+
options: 'Parameter') -> 'Data_DiffieHellmanParameter': # pylint: disable=unused-argument
|
1158
|
+
"""Read HIP ``DIFFIE_HELLMAN`` parameter.
|
1159
|
+
|
1160
|
+
Structure of HIP ``DIFFIE_HELLMAN`` parameter [:rfc:`7401`]:
|
1161
|
+
|
1162
|
+
.. code-block:: text
|
1163
|
+
|
1164
|
+
0 1 2 3
|
1165
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1166
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1167
|
+
| Type | Length |
|
1168
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1169
|
+
| Group ID | Public Value Length | Public Value /
|
1170
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1171
|
+
/ |
|
1172
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1173
|
+
/ | Padding |
|
1174
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1175
|
+
|
1176
|
+
Args:
|
1177
|
+
schema: parsed parameter schama
|
1178
|
+
version: HIP protocol version
|
1179
|
+
options: parsed HIP parameters
|
1180
|
+
|
1181
|
+
Returns:
|
1182
|
+
Parsed parameter data.
|
1183
|
+
|
1184
|
+
"""
|
1185
|
+
diffie_hellman = Data_DiffieHellmanParameter(
|
1186
|
+
type=schema.type,
|
1187
|
+
critical=bool(schema.type & 0b1),
|
1188
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1189
|
+
group_id=schema.group,
|
1190
|
+
pub_len=schema.pub_len,
|
1191
|
+
pub_val=schema.pub_val,
|
1192
|
+
)
|
1193
|
+
return diffie_hellman
|
1194
|
+
|
1195
|
+
def _read_param_hip_transform(self, schema: 'Schema_HIPTransformParameter', *, version: 'int',
|
1196
|
+
options: 'Parameter') -> 'Data_HIPTransformParameter': # pylint: disable=unused-argument
|
1197
|
+
"""Read HIP ``HIP_TRANSFORM`` parameter.
|
1198
|
+
|
1199
|
+
Structure of HIP ``HIP_TRANSFORM`` parameter [:rfc:`5201`]:
|
1200
|
+
|
1201
|
+
.. code-block:: text
|
1202
|
+
|
1203
|
+
0 1 2 3
|
1204
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1205
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1206
|
+
| Type | Length |
|
1207
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1208
|
+
| Suite ID #1 | Suite ID #2 |
|
1209
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1210
|
+
| Suite ID #n | Padding |
|
1211
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1212
|
+
|
1213
|
+
Args:
|
1214
|
+
schema: parsed parameter schama
|
1215
|
+
version: HIP protocol version
|
1216
|
+
options: parsed HIP parameters
|
1217
|
+
|
1218
|
+
Returns:
|
1219
|
+
Parsed parameter data.
|
1220
|
+
|
1221
|
+
Raises:
|
1222
|
+
ProtocolError: The parameter is **ONLY** supported in HIPv1.
|
1223
|
+
|
1224
|
+
"""
|
1225
|
+
if version != 1:
|
1226
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid parameter')
|
1227
|
+
if schema.len % 2 != 0:
|
1228
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
1229
|
+
|
1230
|
+
hip_transform = Data_HIPTransformParameter(
|
1231
|
+
type=schema.type,
|
1232
|
+
critical=bool(schema.type & 0b1),
|
1233
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1234
|
+
suite_id=tuple(schema.suites),
|
1235
|
+
)
|
1236
|
+
return hip_transform
|
1237
|
+
|
1238
|
+
def _read_param_hip_cipher(self, schema: 'Schema_HIPCipherParameter', *, version: 'int',
|
1239
|
+
options: 'Parameter') -> 'Data_HIPCipherParameter': # pylint: disable=unused-argument
|
1240
|
+
"""Read HIP ``HIP_CIPHER`` parameter.
|
1241
|
+
|
1242
|
+
Structure of HIP ``HIP_CIPHER`` parameter [:rfc:`7401`]:
|
1243
|
+
|
1244
|
+
.. code-block:: text
|
1245
|
+
|
1246
|
+
0 1 2 3
|
1247
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1248
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1249
|
+
| Type | Length |
|
1250
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1251
|
+
| Cipher ID #1 | Cipher ID #2 |
|
1252
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1253
|
+
| Cipher ID #n | Padding |
|
1254
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1255
|
+
|
1256
|
+
Args:
|
1257
|
+
schema: parsed parameter schama
|
1258
|
+
version: HIP protocol version
|
1259
|
+
options: parsed HIP parameters
|
1260
|
+
|
1261
|
+
Returns:
|
1262
|
+
Parsed parameter data.
|
1263
|
+
|
1264
|
+
Raises:
|
1265
|
+
ProtocolError: If ``schema.len`` is **NOT** a ``2`` modulo.
|
1266
|
+
|
1267
|
+
"""
|
1268
|
+
if schema.len % 2 != 0:
|
1269
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
1270
|
+
|
1271
|
+
# NOTE: The sender of a HIP_CIPHER parameter MUST make sure that there are no
|
1272
|
+
# more than six (6) Cipher IDs in one HIP_CIPHER parameter. [:rfc:`7401#section-5.2.8`]
|
1273
|
+
if len(schema.ciphers) > 5:
|
1274
|
+
warn(f'HIPv{version}: [ParamNo {schema.type}] invalid format', ProtocolWarning)
|
1275
|
+
# raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
1276
|
+
|
1277
|
+
hip_cipher = Data_HIPCipherParameter(
|
1278
|
+
type=schema.type,
|
1279
|
+
critical=bool(schema.type & 0b1),
|
1280
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1281
|
+
cipher_id=tuple(schema.ciphers),
|
1282
|
+
)
|
1283
|
+
return hip_cipher
|
1284
|
+
|
1285
|
+
def _read_param_nat_traversal_mode(self, schema: 'Schema_NATTraversalModeParameter', *, version: 'int', # pylint: disable=unused-argument
|
1286
|
+
options: 'Parameter') -> 'Data_NATTraversalModeParameter': # pylint: disable=unused-argument,line-too-long
|
1287
|
+
"""Read HIP ``NAT_TRAVERSAL_MODE`` parameter.
|
1288
|
+
|
1289
|
+
Structure of HIP ``NAT_TRAVERSAL_MODE`` parameter [:rfc:`5770`]:
|
1290
|
+
|
1291
|
+
.. code-block:: text
|
1292
|
+
|
1293
|
+
0 1 2 3
|
1294
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1295
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1296
|
+
| Type | Length |
|
1297
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1298
|
+
| Reserved | Mode ID #1 |
|
1299
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1300
|
+
| Mode ID #2 | Mode ID #3 |
|
1301
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1302
|
+
| Mode ID #n | Padding |
|
1303
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1304
|
+
|
1305
|
+
Args:
|
1306
|
+
schema: parsed parameter schama
|
1307
|
+
version: HIP protocol version
|
1308
|
+
options: parsed HIP parameters
|
1309
|
+
|
1310
|
+
Returns:
|
1311
|
+
Parsed parameter data.
|
1312
|
+
|
1313
|
+
Raises:
|
1314
|
+
ProtocolError: If ``schema.len`` is **NOT** a ``2`` modulo.
|
1315
|
+
|
1316
|
+
"""
|
1317
|
+
if schema.len % 2 != 0:
|
1318
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
1319
|
+
|
1320
|
+
nat_traversal_mode = Data_NATTraversalModeParameter(
|
1321
|
+
type=schema.type,
|
1322
|
+
critical=bool(schema.type & 0b1),
|
1323
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1324
|
+
mode_id=tuple(schema.modes),
|
1325
|
+
)
|
1326
|
+
return nat_traversal_mode
|
1327
|
+
|
1328
|
+
def _read_param_transaction_pacing(self, schema: 'Schema_TransactionPacingParameter', *, version: 'int', # pylint: disable=unused-argument
|
1329
|
+
options: 'Parameter') -> 'Data_TransactionPacingParameter': # pylint: disable=unused-argument,line-too-long
|
1330
|
+
"""Read HIP ``TRANSACTION_PACING`` parameter.
|
1331
|
+
|
1332
|
+
Structure of HIP ``TRANSACTION_PACING`` parameter [:rfc:`5770`]:
|
1333
|
+
|
1334
|
+
.. code-block:: text
|
1335
|
+
|
1336
|
+
0 1 2 3
|
1337
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1338
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1339
|
+
| Type | Length |
|
1340
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1341
|
+
| Min Ta |
|
1342
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1343
|
+
|
1344
|
+
Args:
|
1345
|
+
schema: parsed parameter schama
|
1346
|
+
version: HIP protocol version
|
1347
|
+
options: parsed HIP parameters
|
1348
|
+
|
1349
|
+
Returns:
|
1350
|
+
Parsed parameter data.
|
1351
|
+
|
1352
|
+
Raises:
|
1353
|
+
ProtocolError: If ``schema.len`` is **NOT** ``4``.
|
1354
|
+
|
1355
|
+
"""
|
1356
|
+
if schema.len != 4:
|
1357
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
1358
|
+
|
1359
|
+
transaction_pacing = Data_TransactionPacingParameter(
|
1360
|
+
type=schema.type,
|
1361
|
+
critical=bool(schema.type & 0b1),
|
1362
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1363
|
+
min_ta=schema.min_ta,
|
1364
|
+
)
|
1365
|
+
return transaction_pacing
|
1366
|
+
|
1367
|
+
def _read_param_encrypted(self, schema: 'Schema_EncryptedParameter', *, version: 'int', # pylint: disable=unused-argument
|
1368
|
+
options: 'Parameter') -> 'Data_EncryptedParameter': # pylint: disable=unused-argument
|
1369
|
+
"""Read HIP ``ENCRYPTED`` parameter.
|
1370
|
+
|
1371
|
+
Structure of HIP ``ENCRYPTED`` parameter [:rfc:`7401`]:
|
1372
|
+
|
1373
|
+
.. code-block:: text
|
1374
|
+
|
1375
|
+
0 1 2 3
|
1376
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1377
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1378
|
+
| Type | Length |
|
1379
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1380
|
+
| Reserved |
|
1381
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1382
|
+
| IV /
|
1383
|
+
/ /
|
1384
|
+
/ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1385
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /
|
1386
|
+
/ Encrypted data /
|
1387
|
+
/ /
|
1388
|
+
/ +-------------------------------+
|
1389
|
+
/ | Padding |
|
1390
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1391
|
+
|
1392
|
+
Args:
|
1393
|
+
schema: parsed parameter schama
|
1394
|
+
version: HIP protocol version
|
1395
|
+
options: parsed HIP parameters
|
1396
|
+
|
1397
|
+
Returns:
|
1398
|
+
Parsed parameter data.
|
1399
|
+
|
1400
|
+
"""
|
1401
|
+
encrypted = Data_EncryptedParameter(
|
1402
|
+
type=schema.type,
|
1403
|
+
critical=bool(schema.type & 0b1),
|
1404
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1405
|
+
cipher=schema.cipher,
|
1406
|
+
iv=getattr(schema, 'iv', None),
|
1407
|
+
data=schema.data,
|
1408
|
+
)
|
1409
|
+
return encrypted
|
1410
|
+
|
1411
|
+
def _read_param_host_id(self, schema: 'Schema_HostIDParameter', *, version: 'int', # pylint: disable=unused-argument
|
1412
|
+
options: 'Parameter') -> 'Data_HostIDParameter': # pylint: disable=unused-argument
|
1413
|
+
"""Read HIP ``HOST_ID`` parameter.
|
1414
|
+
|
1415
|
+
Structure of HIP ``HOST_ID`` parameter [:rfc:`7401`]:
|
1416
|
+
|
1417
|
+
.. code-block:: text
|
1418
|
+
|
1419
|
+
0 1 2 3
|
1420
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1421
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1422
|
+
| Type | Length |
|
1423
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1424
|
+
| HI Length |DI-Type| DI Length |
|
1425
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1426
|
+
| Algorithm | Host Identity /
|
1427
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1428
|
+
/ | Domain Identifier /
|
1429
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1430
|
+
/ | Padding |
|
1431
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1432
|
+
|
1433
|
+
Args:
|
1434
|
+
schema: parsed parameter schama
|
1435
|
+
version: HIP protocol version
|
1436
|
+
options: parsed HIP parameters
|
1437
|
+
|
1438
|
+
Returns:
|
1439
|
+
Parsed parameter data.
|
1440
|
+
|
1441
|
+
"""
|
1442
|
+
if schema.algorithm == Enum_HIAlgorithm.ECDSA:
|
1443
|
+
schema_hi = cast('Schema_ECDSACurveHostIdentity', schema.hi)
|
1444
|
+
hi = Data_HostIdentity(
|
1445
|
+
curve=schema_hi.curve,
|
1446
|
+
pubkey=schema_hi.pub_key,
|
1447
|
+
)
|
1448
|
+
elif schema.algorithm == Enum_HIAlgorithm.ECDSA_LOW:
|
1449
|
+
schema_hi = cast('Schema_ECDSALowCurveHostIdentity', schema.hi) # type: ignore[assignment]
|
1450
|
+
hi = Data_HostIdentity(
|
1451
|
+
curve=schema_hi.curve,
|
1452
|
+
pubkey=schema_hi.pub_key,
|
1453
|
+
)
|
1454
|
+
elif schema.algorithm == Enum_HIAlgorithm.EdDSA:
|
1455
|
+
schema_hi = cast('Schema_EdDSACurveHostIdentity', schema.hi) # type: ignore[assignment]
|
1456
|
+
hi = Data_HostIdentity(
|
1457
|
+
curve=schema_hi.curve,
|
1458
|
+
pubkey=schema_hi.pub_key,
|
1459
|
+
)
|
1460
|
+
else:
|
1461
|
+
hi = cast('bytes', schema.hi) # type: ignore[assignment]
|
1462
|
+
|
1463
|
+
host_id = Data_HostIDParameter(
|
1464
|
+
type=schema.type,
|
1465
|
+
critical=bool(schema.type & 0b1),
|
1466
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1467
|
+
hi_len=schema.hi_len,
|
1468
|
+
di_type=schema.di_data['type'],
|
1469
|
+
di_len=schema.di_data['len'],
|
1470
|
+
algorithm=schema.algorithm,
|
1471
|
+
hi=hi,
|
1472
|
+
di=schema.di,
|
1473
|
+
)
|
1474
|
+
return host_id
|
1475
|
+
|
1476
|
+
def _read_param_hit_suite_list(self, schema: 'Schema_HITSuiteListParameter', *, version: 'int', # pylint: disable=unused-argument
|
1477
|
+
options: 'Parameter') -> 'Data_HITSuiteListParameter': # pylint: disable=unused-argument
|
1478
|
+
"""Read HIP ``HIT_SUITE_LIST`` parameter.
|
1479
|
+
|
1480
|
+
Structure of HIP ``HIT_SUITE_LIST`` parameter [:rfc:`7401`]:
|
1481
|
+
|
1482
|
+
.. code-block:: text
|
1483
|
+
|
1484
|
+
0 1 2 3
|
1485
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1486
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1487
|
+
| Type | Length |
|
1488
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1489
|
+
| ID #1 | ID #2 | ID #3 | ID #4 |
|
1490
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1491
|
+
| ID #n | Padding |
|
1492
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1493
|
+
|
1494
|
+
Args:
|
1495
|
+
schema: parsed parameter schama
|
1496
|
+
version: HIP protocol version
|
1497
|
+
options: parsed HIP parameters
|
1498
|
+
|
1499
|
+
Returns:
|
1500
|
+
Parsed parameter data.
|
1501
|
+
|
1502
|
+
"""
|
1503
|
+
hit_suite_list = Data_HITSuiteListParameter(
|
1504
|
+
type=schema.type,
|
1505
|
+
critical=bool(schema.type & 0b1),
|
1506
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1507
|
+
suite_id=tuple(schema.suites),
|
1508
|
+
)
|
1509
|
+
return hit_suite_list
|
1510
|
+
|
1511
|
+
def _read_param_cert(self, schema: 'Schema_CertParameter', *, version: 'int', # pylint: disable=unused-argument
|
1512
|
+
options: 'Parameter') -> 'Data_CertParameter': # pylint: disable=unused-argument
|
1513
|
+
"""Read HIP ``CERT`` parameter.
|
1514
|
+
|
1515
|
+
Structure of HIP ``CERT`` parameter [:rfc:`7401`]:
|
1516
|
+
|
1517
|
+
.. code-block:: text
|
1518
|
+
|
1519
|
+
0 1 2 3
|
1520
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1521
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1522
|
+
| Type | Length |
|
1523
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1524
|
+
| CERT group | CERT count | CERT ID | CERT type |
|
1525
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1526
|
+
| Certificate /
|
1527
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1528
|
+
/ | Padding (variable length) |
|
1529
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1530
|
+
|
1531
|
+
Args:
|
1532
|
+
schema: parsed parameter schama
|
1533
|
+
version: HIP protocol version
|
1534
|
+
options: parsed HIP parameters
|
1535
|
+
|
1536
|
+
Returns:
|
1537
|
+
Parsed parameter data.
|
1538
|
+
|
1539
|
+
"""
|
1540
|
+
cert = Data_CertParameter(
|
1541
|
+
type=schema.type,
|
1542
|
+
critical=bool(schema.type & 0b1),
|
1543
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1544
|
+
cert_group=schema.cert_group,
|
1545
|
+
cert_count=schema.cert_count,
|
1546
|
+
cert_id=schema.cert_id,
|
1547
|
+
cert_type=schema.cert_type,
|
1548
|
+
cert=schema.cert,
|
1549
|
+
)
|
1550
|
+
return cert
|
1551
|
+
|
1552
|
+
def _read_param_notification(self, schema: 'Schema_NotificationParameter', *, version: 'int', # pylint: disable=unused-argument
|
1553
|
+
options: 'Parameter') -> 'Data_NotificationParameter': # pylint: disable=unused-argument
|
1554
|
+
"""Read HIP ``NOTIFICATION`` parameter.
|
1555
|
+
|
1556
|
+
Structure of HIP ``NOTIFICATION`` parameter [:rfc:`7401`]:
|
1557
|
+
|
1558
|
+
.. code-block:: text
|
1559
|
+
|
1560
|
+
0 1 2 3
|
1561
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1562
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1563
|
+
| Type | Length |
|
1564
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1565
|
+
| Reserved | Notify Message Type |
|
1566
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1567
|
+
| /
|
1568
|
+
/ Notification Data /
|
1569
|
+
/ +---------------+
|
1570
|
+
/ | Padding |
|
1571
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1572
|
+
|
1573
|
+
Args:
|
1574
|
+
schema: parsed parameter schama
|
1575
|
+
version: HIP protocol version
|
1576
|
+
options: parsed HIP parameters
|
1577
|
+
|
1578
|
+
Returns:
|
1579
|
+
Parsed parameter data.
|
1580
|
+
|
1581
|
+
"""
|
1582
|
+
notification = Data_NotificationParameter(
|
1583
|
+
type=schema.type,
|
1584
|
+
critical=bool(schema.type & 0b1),
|
1585
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1586
|
+
msg_type=schema.msg_type,
|
1587
|
+
msg=schema.msg,
|
1588
|
+
)
|
1589
|
+
return notification
|
1590
|
+
|
1591
|
+
def _read_param_echo_request_signed(self, schema: 'Schema_EchoRequestSignedParameter', *, version: 'int', # pylint: disable=unused-argument
|
1592
|
+
options: 'Parameter') -> 'Data_EchoRequestSignedParameter': # pylint: disable=unused-argument
|
1593
|
+
"""Read HIP ``ECHO_REQUEST_SIGNED`` parameter.
|
1594
|
+
|
1595
|
+
Structure of HIP ``ECHO_REQUEST_SIGNED`` parameter [:rfc:`7401`]:
|
1596
|
+
|
1597
|
+
.. code-block:: text
|
1598
|
+
|
1599
|
+
0 1 2 3
|
1600
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1601
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1602
|
+
| Type | Length |
|
1603
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1604
|
+
| Opaque data (variable length) |
|
1605
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1606
|
+
|
1607
|
+
Args:
|
1608
|
+
schema: parsed parameter schama
|
1609
|
+
version: HIP protocol version
|
1610
|
+
options: parsed HIP parameters
|
1611
|
+
|
1612
|
+
Returns:
|
1613
|
+
Parsed parameter data.
|
1614
|
+
|
1615
|
+
"""
|
1616
|
+
echo_request_signed = Data_EchoRequestSignedParameter(
|
1617
|
+
type=schema.type,
|
1618
|
+
critical=bool(schema.type & 0b1),
|
1619
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1620
|
+
opaque=schema.opaque,
|
1621
|
+
)
|
1622
|
+
return echo_request_signed
|
1623
|
+
|
1624
|
+
def _read_param_reg_info(self, schema: 'Schema_RegInfoParameter', *, version: 'int', # pylint: disable=unused-argument
|
1625
|
+
options: 'Parameter') -> 'Data_RegInfoParameter': # pylint: disable=unused-argument
|
1626
|
+
"""Read HIP ``REG_INFO`` parameter.
|
1627
|
+
|
1628
|
+
Structure of HIP ``REG_INFO`` parameter [:rfc:`8003`]:
|
1629
|
+
|
1630
|
+
.. code-block:: text
|
1631
|
+
|
1632
|
+
0 1 2 3
|
1633
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1634
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1635
|
+
| Type | Length |
|
1636
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1637
|
+
| Min Lifetime | Max Lifetime | Reg Type #1 | Reg Type #2 |
|
1638
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1639
|
+
| ... | ... | Reg Type #n | |
|
1640
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Padding +
|
1641
|
+
| |
|
1642
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1643
|
+
|
1644
|
+
Args:
|
1645
|
+
schema: parsed parameter schama
|
1646
|
+
version: HIP protocol version
|
1647
|
+
options: parsed HIP parameters
|
1648
|
+
|
1649
|
+
Returns:
|
1650
|
+
Parsed parameter data.
|
1651
|
+
|
1652
|
+
"""
|
1653
|
+
reg_info = Data_RegInfoParameter(
|
1654
|
+
type=schema.type,
|
1655
|
+
critical=bool(schema.type & 0b1),
|
1656
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1657
|
+
lifetime=Data_Lifetime(
|
1658
|
+
min=datetime.timedelta(seconds=schema.min_lifetime),
|
1659
|
+
max=datetime.timedelta(seconds=schema.max_lifetime),
|
1660
|
+
),
|
1661
|
+
reg_type=tuple(schema.reg_info),
|
1662
|
+
)
|
1663
|
+
return reg_info
|
1664
|
+
|
1665
|
+
def _read_param_reg_request(self, schema: 'Schema_RegRequestParameter', *, version: 'int', # pylint: disable=unused-argument
|
1666
|
+
options: 'Parameter') -> 'Data_RegRequestParameter': # pylint: disable=unused-argument
|
1667
|
+
"""Read HIP ``REG_REQUEST`` parameter.
|
1668
|
+
|
1669
|
+
Structure of HIP ``REG_REQUEST`` parameter [:rfc:`8003`]:
|
1670
|
+
|
1671
|
+
.. code-block:: text
|
1672
|
+
|
1673
|
+
0 1 2 3
|
1674
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1675
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1676
|
+
| Type | Length |
|
1677
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1678
|
+
| Lifetime | Reg Type #1 | Reg Type #2 | Reg Type #3 |
|
1679
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1680
|
+
| ... | ... | Reg Type #n | |
|
1681
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Padding +
|
1682
|
+
| |
|
1683
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1684
|
+
|
1685
|
+
Args:
|
1686
|
+
schema: parsed parameter schama
|
1687
|
+
version: HIP protocol version
|
1688
|
+
options: parsed HIP parameters
|
1689
|
+
|
1690
|
+
Returns:
|
1691
|
+
Parsed parameter data.
|
1692
|
+
|
1693
|
+
"""
|
1694
|
+
reg_request = Data_RegRequestParameter(
|
1695
|
+
type=schema.type,
|
1696
|
+
critical=bool(schema.type & 0b1),
|
1697
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1698
|
+
lifetime=datetime.timedelta(seconds=schema.lifetime),
|
1699
|
+
reg_type=tuple(schema.reg_request),
|
1700
|
+
)
|
1701
|
+
return reg_request
|
1702
|
+
|
1703
|
+
def _read_param_reg_response(self, schema: 'Schema_RegResponseParameter', *, version: 'int', # pylint: disable=unused-argument
|
1704
|
+
options: 'Parameter') -> 'Data_RegResponseParameter': # pylint: disable=unused-argument
|
1705
|
+
"""Read HIP ``REG_RESPONSE`` parameter.
|
1706
|
+
|
1707
|
+
Structure of HIP ``REG_RESPONSE`` parameter [:rfc:`8003`]:
|
1708
|
+
|
1709
|
+
.. code-block:: text
|
1710
|
+
|
1711
|
+
0 1 2 3
|
1712
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1713
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1714
|
+
| Type | Length |
|
1715
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1716
|
+
| Lifetime | Reg Type #1 | Reg Type #2 | Reg Type #3 |
|
1717
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1718
|
+
| ... | ... | Reg Type #n | |
|
1719
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Padding +
|
1720
|
+
| |
|
1721
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1722
|
+
|
1723
|
+
Args:
|
1724
|
+
schema: parsed parameter schama
|
1725
|
+
version: HIP protocol version
|
1726
|
+
options: parsed HIP parameters
|
1727
|
+
|
1728
|
+
Returns:
|
1729
|
+
Parsed parameter data.
|
1730
|
+
|
1731
|
+
"""
|
1732
|
+
reg_response = Data_RegResponseParameter(
|
1733
|
+
type=schema.type,
|
1734
|
+
critical=bool(schema.type & 0b1),
|
1735
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1736
|
+
lifetime=datetime.timedelta(seconds=schema.lifetime),
|
1737
|
+
reg_type=tuple(schema.reg_response),
|
1738
|
+
)
|
1739
|
+
return reg_response
|
1740
|
+
|
1741
|
+
def _read_param_reg_failed(self, schema: 'Schema_RegFailedParameter', *, version: 'int', # pylint: disable=unused-argument
|
1742
|
+
options: 'Parameter') -> 'Data_RegFailedParameter': # pylint: disable=unused-argument
|
1743
|
+
"""Read HIP ``REG_FAILED`` parameter.
|
1744
|
+
|
1745
|
+
Structure of HIP ``REG_FAILED`` parameter [:rfc:`8003`]:
|
1746
|
+
|
1747
|
+
.. code-block:: text
|
1748
|
+
|
1749
|
+
0 1 2 3
|
1750
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1751
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1752
|
+
| Type | Length |
|
1753
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1754
|
+
| Lifetime | Reg Type #1 | Reg Type #2 | Reg Type #3 |
|
1755
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1756
|
+
| ... | ... | Reg Type #n | |
|
1757
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Padding +
|
1758
|
+
| |
|
1759
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1760
|
+
|
1761
|
+
Args:
|
1762
|
+
schema: parsed parameter schama
|
1763
|
+
version: HIP protocol version
|
1764
|
+
options: parsed HIP parameters
|
1765
|
+
|
1766
|
+
Returns:
|
1767
|
+
Parsed parameter data.
|
1768
|
+
|
1769
|
+
"""
|
1770
|
+
reg_failed = Data_RegFailedParameter(
|
1771
|
+
type=schema.type,
|
1772
|
+
critical=bool(schema.type & 0b1),
|
1773
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1774
|
+
lifetime=datetime.timedelta(seconds=schema.lifetime),
|
1775
|
+
reg_type=tuple(schema.reg_failed),
|
1776
|
+
)
|
1777
|
+
return reg_failed
|
1778
|
+
|
1779
|
+
def _read_param_reg_from(self, schema: 'Schema_RegFromParameter', *, version: 'int', # pylint: disable=unused-argument
|
1780
|
+
options: 'Parameter') -> 'Data_RegFromParameter': # pylint: disable=unused-argument
|
1781
|
+
"""Read HIP ``REG_FROM`` parameter.
|
1782
|
+
|
1783
|
+
Structure of HIP ``REG_FROM`` parameter [:rfc:`5770`]:
|
1784
|
+
|
1785
|
+
.. code-block:: text
|
1786
|
+
|
1787
|
+
0 1 2 3
|
1788
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1789
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1790
|
+
| Type | Length |
|
1791
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1792
|
+
| Port | Protocol | Reserved |
|
1793
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1794
|
+
| |
|
1795
|
+
| Address |
|
1796
|
+
| |
|
1797
|
+
| |
|
1798
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1799
|
+
|
1800
|
+
Args:
|
1801
|
+
schema: parsed parameter schama
|
1802
|
+
version: HIP protocol version
|
1803
|
+
options: parsed HIP parameters
|
1804
|
+
|
1805
|
+
Returns:
|
1806
|
+
Parsed parameter data.
|
1807
|
+
|
1808
|
+
Raises:
|
1809
|
+
ProtocolError: If ``schema.len`` is **NOT** ``20``.
|
1810
|
+
|
1811
|
+
"""
|
1812
|
+
if schema.len != 20:
|
1813
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
1814
|
+
|
1815
|
+
reg_from = Data_RegFromParameter(
|
1816
|
+
type=schema.type,
|
1817
|
+
critical=bool(schema.type & 0b1),
|
1818
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1819
|
+
port=schema.port,
|
1820
|
+
protocol=schema.protocol,
|
1821
|
+
address=schema.address,
|
1822
|
+
)
|
1823
|
+
return reg_from
|
1824
|
+
|
1825
|
+
def _read_param_echo_response_signed(self, schema: 'Schema_EchoResponseSignedParameter', *, version: 'int', # pylint: disable=unused-argument
|
1826
|
+
options: 'Parameter') -> 'Data_EchoResponseSignedParameter': # pylint: disable=unused-argument
|
1827
|
+
"""Read HIP ``ECHO_RESPONSE_SIGNED`` parameter.
|
1828
|
+
|
1829
|
+
Structure of HIP ``ECHO_RESPONSE_SIGNED`` parameter [:rfc:`7401`]:
|
1830
|
+
|
1831
|
+
.. code-block:: text
|
1832
|
+
|
1833
|
+
0 1 2 3
|
1834
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1835
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1836
|
+
| Type | Length |
|
1837
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1838
|
+
| Opaque data (variable length) |
|
1839
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1840
|
+
|
1841
|
+
Args:
|
1842
|
+
schema: parsed parameter schama
|
1843
|
+
version: HIP protocol version
|
1844
|
+
options: parsed HIP parameters
|
1845
|
+
|
1846
|
+
Returns:
|
1847
|
+
Parsed parameter data.
|
1848
|
+
|
1849
|
+
"""
|
1850
|
+
echo_response_signed = Data_EchoResponseSignedParameter(
|
1851
|
+
type=schema.type,
|
1852
|
+
critical=bool(schema.type & 0b1),
|
1853
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1854
|
+
opaque=schema.opaque,
|
1855
|
+
)
|
1856
|
+
return echo_response_signed
|
1857
|
+
|
1858
|
+
def _read_param_transport_format_list(self, schema: 'Schema_TransportFormatListParameter', *, version: 'int', # pylint: disable=unused-argument
|
1859
|
+
options: 'Parameter') -> 'Data_TransportFormatListParameter': # pylint: disable=unused-argument
|
1860
|
+
"""Read HIP ``TRANSPORT_FORMAT_LIST`` parameter.
|
1861
|
+
|
1862
|
+
Structure of HIP ``TRANSPORT_FORMAT_LIST`` parameter [:rfc:`7401`]:
|
1863
|
+
|
1864
|
+
.. code-block:: text
|
1865
|
+
|
1866
|
+
0 1 2 3
|
1867
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1868
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1869
|
+
| Type | Length |
|
1870
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1871
|
+
| TF type #1 | TF type #2 /
|
1872
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1873
|
+
/ TF type #n | Padding |
|
1874
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1875
|
+
|
1876
|
+
Args:
|
1877
|
+
schema: parsed parameter schama
|
1878
|
+
version: HIP protocol version
|
1879
|
+
options: parsed HIP parameters
|
1880
|
+
|
1881
|
+
Returns:
|
1882
|
+
Parsed parameter data.
|
1883
|
+
|
1884
|
+
Raises:
|
1885
|
+
ProtocolError: If ``schema.len`` is **NOT** ``2`` modulo.
|
1886
|
+
|
1887
|
+
"""
|
1888
|
+
if schema.len % 2 != 0:
|
1889
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
1890
|
+
|
1891
|
+
transport_format_list = Data_TransportFormatListParameter(
|
1892
|
+
type=schema.type,
|
1893
|
+
critical=bool(schema.type & 0b1),
|
1894
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1895
|
+
tf_type=tuple(schema.formats),
|
1896
|
+
)
|
1897
|
+
return transport_format_list
|
1898
|
+
|
1899
|
+
def _read_param_esp_transform(self, schema: 'Schema_ESPTransformParameter', *, version: 'int', # pylint: disable=unused-argument
|
1900
|
+
options: 'Parameter') -> 'Data_ESPTransformParameter': # pylint: disable=unused-argument
|
1901
|
+
"""Read HIP ``ESP_TRANSFORM`` parameter.
|
1902
|
+
|
1903
|
+
Structure of HIP ``ESP_TRANSFORM`` parameter [:rfc:`7402`]:
|
1904
|
+
|
1905
|
+
.. code-block:: text
|
1906
|
+
|
1907
|
+
0 1 2 3
|
1908
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1909
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1910
|
+
| Type | Length |
|
1911
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1912
|
+
| Reserved | Suite ID #1 |
|
1913
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1914
|
+
| Suite ID #2 | Suite ID #3 |
|
1915
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1916
|
+
| Suite ID #n | Padding |
|
1917
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1918
|
+
|
1919
|
+
Args:
|
1920
|
+
schema: parsed parameter schama
|
1921
|
+
version: HIP protocol version
|
1922
|
+
options: parsed HIP parameters
|
1923
|
+
|
1924
|
+
Returns:
|
1925
|
+
Parsed parameter data.
|
1926
|
+
|
1927
|
+
Raises:
|
1928
|
+
ProtocolError: If ``schema.len`` is **NOT** ``2`` modulo.
|
1929
|
+
|
1930
|
+
"""
|
1931
|
+
if schema.len % 2 != 0:
|
1932
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
1933
|
+
|
1934
|
+
esp_transform = Data_ESPTransformParameter(
|
1935
|
+
type=schema.type,
|
1936
|
+
critical=bool(schema.type & 0b1),
|
1937
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1938
|
+
suite_id=tuple(schema.suites),
|
1939
|
+
)
|
1940
|
+
return esp_transform
|
1941
|
+
|
1942
|
+
def _read_param_seq_data(self, schema: 'Schema_SeqDataParameter', *, version: 'int', # pylint: disable=unused-argument
|
1943
|
+
options: 'Parameter') -> 'Data_SeqDataParameter': # pylint: disable=unused-argument
|
1944
|
+
"""Read HIP ``SEQ_DATA`` parameter.
|
1945
|
+
|
1946
|
+
Structure of HIP ``SEQ_DATA`` parameter [:rfc:`6078`]:
|
1947
|
+
|
1948
|
+
.. code-block:: text
|
1949
|
+
|
1950
|
+
0 1 2 3
|
1951
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1952
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1953
|
+
| Type | Length |
|
1954
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1955
|
+
| Sequence number |
|
1956
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1957
|
+
|
1958
|
+
Args:
|
1959
|
+
schema: parsed parameter schama
|
1960
|
+
version: HIP protocol version
|
1961
|
+
options: parsed HIP parameters
|
1962
|
+
|
1963
|
+
Returns:
|
1964
|
+
Parsed parameter data.
|
1965
|
+
|
1966
|
+
Raises:
|
1967
|
+
ProtocolError: If ``schema.len`` is **NOT** ``4``.
|
1968
|
+
|
1969
|
+
"""
|
1970
|
+
if schema.len != 4:
|
1971
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
1972
|
+
|
1973
|
+
seq_data = Data_SeqDataParameter(
|
1974
|
+
type=schema.type,
|
1975
|
+
critical=bool(schema.type & 0b1),
|
1976
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
1977
|
+
seq=schema.seq,
|
1978
|
+
)
|
1979
|
+
return seq_data
|
1980
|
+
|
1981
|
+
def _read_param_ack_data(self, schema: 'Schema_AckDataParameter', *, version: 'int', # pylint: disable=unused-argument
|
1982
|
+
options: 'Parameter') -> 'Data_AckDataParameter': # pylint: disable=unused-argument
|
1983
|
+
"""Read HIP ``ACK_DATA`` parameter.
|
1984
|
+
|
1985
|
+
Structure of HIP ``ACK_DATA`` parameter [:rfc:`6078`]:
|
1986
|
+
|
1987
|
+
.. code-block:: text
|
1988
|
+
|
1989
|
+
0 1 2 3
|
1990
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
1991
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1992
|
+
| Type | Length |
|
1993
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1994
|
+
| Acked Sequence number /
|
1995
|
+
/ /
|
1996
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
1997
|
+
|
1998
|
+
Args:
|
1999
|
+
schema: parsed parameter schama
|
2000
|
+
version: HIP protocol version
|
2001
|
+
options: parsed HIP parameters
|
2002
|
+
|
2003
|
+
Returns:
|
2004
|
+
Parsed parameter data.
|
2005
|
+
|
2006
|
+
Raises:
|
2007
|
+
ProtocolError: If ``schema.len`` is **NOT** ``4`` modulo.
|
2008
|
+
|
2009
|
+
"""
|
2010
|
+
if schema.len % 4 != 0:
|
2011
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
2012
|
+
|
2013
|
+
ack_data = Data_AckDataParameter(
|
2014
|
+
type=schema.type,
|
2015
|
+
critical=bool(schema.type & 0b1),
|
2016
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2017
|
+
ack=tuple(schema.ack),
|
2018
|
+
)
|
2019
|
+
return ack_data
|
2020
|
+
|
2021
|
+
def _read_param_payload_mic(self, schema: 'Schema_PayloadMICParameter', *, version: 'int', # pylint: disable=unused-argument
|
2022
|
+
options: 'Parameter') -> 'Data_PayloadMICParameter': # pylint: disable=unused-argument
|
2023
|
+
"""Read HIP ``PAYLOAD_MIC`` parameter.
|
2024
|
+
|
2025
|
+
Structure of HIP ``PAYLOAD_MIC`` parameter [:rfc:`6078`]:
|
2026
|
+
|
2027
|
+
.. code-block:: text
|
2028
|
+
|
2029
|
+
0 1 2 3
|
2030
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2031
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2032
|
+
| Type | Length |
|
2033
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2034
|
+
| Next Header | Reserved |
|
2035
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2036
|
+
| Payload Data |
|
2037
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2038
|
+
| |
|
2039
|
+
/ MIC Value /
|
2040
|
+
/ +-+-+-+-+-+-+-+-+
|
2041
|
+
| | Padding |
|
2042
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2043
|
+
|
2044
|
+
Args:
|
2045
|
+
schema: parsed parameter schama
|
2046
|
+
version: HIP protocol version
|
2047
|
+
options: parsed HIP parameters
|
2048
|
+
|
2049
|
+
Returns:
|
2050
|
+
Parsed parameter data.
|
2051
|
+
|
2052
|
+
"""
|
2053
|
+
payload_mic = Data_PayloadMICParameter(
|
2054
|
+
type=schema.type,
|
2055
|
+
critical=bool(schema.type & 0b1),
|
2056
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2057
|
+
next=schema.next,
|
2058
|
+
payload=schema.payload,
|
2059
|
+
mic=schema.mic,
|
2060
|
+
)
|
2061
|
+
return payload_mic
|
2062
|
+
|
2063
|
+
def _read_param_transaction_id(self, schema: 'Schema_TransactionIDParameter', *, version: 'int', # pylint: disable=unused-argument
|
2064
|
+
options: 'Parameter') -> 'Data_TransactionIDParameter': # pylint: disable=unused-argument
|
2065
|
+
"""Read HIP ``TRANSACTION_ID`` parameter.
|
2066
|
+
|
2067
|
+
Structure of HIP ``TRANSACTION_ID`` parameter [:rfc:`6078`]:
|
2068
|
+
|
2069
|
+
.. code-block:: text
|
2070
|
+
|
2071
|
+
0 1 2 3
|
2072
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2073
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2074
|
+
| Type | Length |
|
2075
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2076
|
+
| Identifier /
|
2077
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2078
|
+
/ | Padding |
|
2079
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2080
|
+
|
2081
|
+
Args:
|
2082
|
+
schema: parsed parameter schama
|
2083
|
+
version: HIP protocol version
|
2084
|
+
options: parsed HIP parameters
|
2085
|
+
|
2086
|
+
Returns:
|
2087
|
+
Parsed parameter data.
|
2088
|
+
|
2089
|
+
"""
|
2090
|
+
transaction_id = Data_TransactionIDParameter(
|
2091
|
+
type=schema.type,
|
2092
|
+
critical=bool(schema.type & 0b1),
|
2093
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2094
|
+
id=schema.id,
|
2095
|
+
)
|
2096
|
+
return transaction_id
|
2097
|
+
|
2098
|
+
def _read_param_overlay_id(self, schema: 'Schema_OverlayIDParameter', *, version: 'int', # pylint: disable=unused-argument
|
2099
|
+
options: 'Parameter') -> 'Data_OverlayIDParameter': # pylint: disable=unused-argument
|
2100
|
+
"""Read HIP ``OVERLAY_ID`` parameter.
|
2101
|
+
|
2102
|
+
Structure of HIP ``OVERLAY_ID`` parameter [:rfc:`6079`]:
|
2103
|
+
|
2104
|
+
.. code-block:: text
|
2105
|
+
|
2106
|
+
0 1 2 3
|
2107
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2108
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2109
|
+
| Type | Length |
|
2110
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2111
|
+
| Identifier /
|
2112
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2113
|
+
/ | Padding |
|
2114
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2115
|
+
|
2116
|
+
Args:
|
2117
|
+
schema: parsed parameter schama
|
2118
|
+
version: HIP protocol version
|
2119
|
+
options: parsed HIP parameters
|
2120
|
+
|
2121
|
+
Returns:
|
2122
|
+
Parsed parameter data.
|
2123
|
+
|
2124
|
+
"""
|
2125
|
+
overlay_id = Data_OverlayIDParameter(
|
2126
|
+
type=schema.type,
|
2127
|
+
critical=bool(schema.type & 0b1),
|
2128
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2129
|
+
id=schema.id,
|
2130
|
+
)
|
2131
|
+
return overlay_id
|
2132
|
+
|
2133
|
+
def _read_param_route_dst(self, schema: 'Schema_RouteDstParameter', *, version: 'int', # pylint: disable=unused-argument
|
2134
|
+
options: 'Parameter') -> 'Data_RouteDstParameter': # pylint: disable=unused-argument
|
2135
|
+
"""Read HIP ``ROUTE_DST`` parameter.
|
2136
|
+
|
2137
|
+
Structure of HIP ``ROUTE_DST`` parameter [:rfc:`6028`]:
|
2138
|
+
|
2139
|
+
.. code-block:: text
|
2140
|
+
|
2141
|
+
0 1 2 3
|
2142
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2143
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2144
|
+
| Type | Length |
|
2145
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2146
|
+
| Flags | Reserved |
|
2147
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2148
|
+
| |
|
2149
|
+
| HIT #1 |
|
2150
|
+
| |
|
2151
|
+
| |
|
2152
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2153
|
+
. . .
|
2154
|
+
. . .
|
2155
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2156
|
+
| |
|
2157
|
+
| HIT #n |
|
2158
|
+
| |
|
2159
|
+
| |
|
2160
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2161
|
+
|
2162
|
+
Args:
|
2163
|
+
schema: parsed parameter schama
|
2164
|
+
version: HIP protocol version
|
2165
|
+
options: parsed HIP parameters
|
2166
|
+
|
2167
|
+
Returns:
|
2168
|
+
Parsed parameter data.
|
2169
|
+
|
2170
|
+
Raises:
|
2171
|
+
ProtocolError: If the parameter is malformed.
|
2172
|
+
|
2173
|
+
"""
|
2174
|
+
if (schema.len - 4) % 16 != 0:
|
2175
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
2176
|
+
|
2177
|
+
route_dst = Data_RouteDstParameter(
|
2178
|
+
type=schema.type,
|
2179
|
+
critical=bool(schema.type & 0b1),
|
2180
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2181
|
+
flags=Data_Flags(
|
2182
|
+
symmetric=bool(schema.flags['symmetric']),
|
2183
|
+
must_follow=bool(schema.flags['must_follow']),
|
2184
|
+
),
|
2185
|
+
hit=tuple(schema.hit),
|
2186
|
+
)
|
2187
|
+
return route_dst
|
2188
|
+
|
2189
|
+
def _read_param_hip_transport_mode(self, schema: 'Schema_HIPTransportModeParameter', *, version: 'int', # pylint: disable=unused-argument
|
2190
|
+
options: 'Parameter') -> 'Data_HIPTransportModeParameter': # pylint: disable=unused-argument
|
2191
|
+
"""Read HIP ``HIP_TRANSPORT_MODE`` parameter.
|
2192
|
+
|
2193
|
+
Structure of HIP ``HIP_TRANSPORT_MODE`` parameter [:rfc:`6261`]:
|
2194
|
+
|
2195
|
+
.. code-block:: text
|
2196
|
+
|
2197
|
+
0 1 2 3
|
2198
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2199
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2200
|
+
| Type | Length |
|
2201
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2202
|
+
| Port | Mode ID #1 |
|
2203
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2204
|
+
| Mode ID #2 | Mode ID #3 |
|
2205
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2206
|
+
| Mode ID #n | Padding |
|
2207
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2208
|
+
|
2209
|
+
Args:
|
2210
|
+
schema: parsed parameter schama
|
2211
|
+
version: HIP protocol version
|
2212
|
+
options: parsed HIP parameters
|
2213
|
+
|
2214
|
+
Returns:
|
2215
|
+
Parsed parameter data.
|
2216
|
+
|
2217
|
+
Raises:
|
2218
|
+
ProtocolError: If ``schema.len`` is **NOT** ``2`` modulo.
|
2219
|
+
|
2220
|
+
"""
|
2221
|
+
if schema.len % 2 != 0:
|
2222
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
2223
|
+
|
2224
|
+
hip_transport_mode = Data_HIPTransportModeParameter(
|
2225
|
+
type=schema.type,
|
2226
|
+
critical=bool(schema.type & 0b1),
|
2227
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2228
|
+
port=schema.port,
|
2229
|
+
mode_id=tuple(schema.mode),
|
2230
|
+
)
|
2231
|
+
return hip_transport_mode
|
2232
|
+
|
2233
|
+
def _read_param_hip_mac(self, schema: 'Schema_HIPMACParameter', *, version: 'int', # pylint: disable=unused-argument
|
2234
|
+
options: 'Parameter') -> 'Data_HIPMACParameter': # pylint: disable=unused-argument
|
2235
|
+
"""Read HIP ``HIP_MAC`` parameter.
|
2236
|
+
|
2237
|
+
Structure of HIP ``HIP_MAC`` parameter [:rfc:`7401`]:
|
2238
|
+
|
2239
|
+
.. code-block:: text
|
2240
|
+
|
2241
|
+
0 1 2 3
|
2242
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2243
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2244
|
+
| Type | Length |
|
2245
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2246
|
+
| |
|
2247
|
+
| HMAC |
|
2248
|
+
/ /
|
2249
|
+
/ +-------------------------------+
|
2250
|
+
| | Padding |
|
2251
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2252
|
+
|
2253
|
+
Args:
|
2254
|
+
schema: parsed parameter schama
|
2255
|
+
version: HIP protocol version
|
2256
|
+
options: parsed HIP parameters
|
2257
|
+
|
2258
|
+
Returns:
|
2259
|
+
Parsed parameter data.
|
2260
|
+
|
2261
|
+
"""
|
2262
|
+
hip_mac = Data_HIPMACParameter(
|
2263
|
+
type=schema.type,
|
2264
|
+
critical=bool(schema.type & 0b1),
|
2265
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2266
|
+
hmac=schema.hmac,
|
2267
|
+
)
|
2268
|
+
return hip_mac
|
2269
|
+
|
2270
|
+
def _read_param_hip_mac_2(self, schema: 'Schema_HIPMAC2Parameter', *, version: 'int', # pylint: disable=unused-argument
|
2271
|
+
options: 'Parameter') -> 'Data_HIPMAC2Parameter': # pylint: disable=unused-argument
|
2272
|
+
"""Read HIP ``HIP_MAC_2`` parameter.
|
2273
|
+
|
2274
|
+
Structure of HIP ``HIP_MAC_2`` parameter [:rfc:`7401`]:
|
2275
|
+
|
2276
|
+
.. code-block:: text
|
2277
|
+
|
2278
|
+
0 1 2 3
|
2279
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2280
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2281
|
+
| Type | Length |
|
2282
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2283
|
+
| |
|
2284
|
+
| HMAC |
|
2285
|
+
/ /
|
2286
|
+
/ +-------------------------------+
|
2287
|
+
| | Padding |
|
2288
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2289
|
+
|
2290
|
+
Args:
|
2291
|
+
schema: parsed parameter schama
|
2292
|
+
version: HIP protocol version
|
2293
|
+
options: parsed HIP parameters
|
2294
|
+
|
2295
|
+
Returns:
|
2296
|
+
Parsed parameter data.
|
2297
|
+
|
2298
|
+
"""
|
2299
|
+
hip_mac_2 = Data_HIPMAC2Parameter(
|
2300
|
+
type=schema.type,
|
2301
|
+
critical=bool(schema.type & 0b1),
|
2302
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2303
|
+
hmac=schema.hmac,
|
2304
|
+
)
|
2305
|
+
return hip_mac_2
|
2306
|
+
|
2307
|
+
def _read_param_hip_signature_2(self, schema: 'Schema_HIPSignature2Parameter', *, version: 'int', # pylint: disable=unused-argument
|
2308
|
+
options: 'Parameter') -> 'Data_HIPSignature2Parameter': # pylint: disable=unused-argument
|
2309
|
+
"""Read HIP ``HIP_SIGNATURE_2`` parameter.
|
2310
|
+
|
2311
|
+
Structure of HIP ``HIP_SIGNATURE_2`` parameter [:rfc:`7401`]:
|
2312
|
+
|
2313
|
+
.. code-block:: text
|
2314
|
+
|
2315
|
+
0 1 2 3
|
2316
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2317
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2318
|
+
| Type | Length |
|
2319
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2320
|
+
| SIG alg | Signature /
|
2321
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2322
|
+
/ | Padding |
|
2323
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2324
|
+
|
2325
|
+
Args:
|
2326
|
+
schema: parsed parameter schama
|
2327
|
+
version: HIP protocol version
|
2328
|
+
options: parsed HIP parameters
|
2329
|
+
|
2330
|
+
Returns:
|
2331
|
+
Parsed parameter data.
|
2332
|
+
|
2333
|
+
"""
|
2334
|
+
hip_signature_2 = Data_HIPSignature2Parameter(
|
2335
|
+
type=schema.type,
|
2336
|
+
critical=bool(schema.type & 0b1),
|
2337
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2338
|
+
algorithm=schema.algorithm,
|
2339
|
+
signature=schema.signature,
|
2340
|
+
)
|
2341
|
+
return hip_signature_2
|
2342
|
+
|
2343
|
+
def _read_param_hip_signature(self, schema: 'Schema_HIPSignatureParameter', *, version: 'int', # pylint: disable=unused-argument
|
2344
|
+
options: 'Parameter') -> 'Data_HIPSignatureParameter': # pylint: disable=unused-argument
|
2345
|
+
"""Read HIP ``HIP_SIGNATURE`` parameter.
|
2346
|
+
|
2347
|
+
Structure of HIP ``HIP_SIGNATURE`` parameter [:rfc:`7401`]:
|
2348
|
+
|
2349
|
+
.. code-block:: text
|
2350
|
+
|
2351
|
+
0 1 2 3
|
2352
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2353
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2354
|
+
| Type | Length |
|
2355
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2356
|
+
| SIG alg | Signature /
|
2357
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2358
|
+
/ | Padding |
|
2359
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2360
|
+
|
2361
|
+
Args:
|
2362
|
+
schema: parsed parameter schama
|
2363
|
+
version: HIP protocol version
|
2364
|
+
options: parsed HIP parameters
|
2365
|
+
|
2366
|
+
Returns:
|
2367
|
+
Parsed parameter data.
|
2368
|
+
|
2369
|
+
"""
|
2370
|
+
hip_signature = Data_HIPSignatureParameter(
|
2371
|
+
type=schema.type,
|
2372
|
+
critical=bool(schema.type & 0b1),
|
2373
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2374
|
+
algorithm=schema.algorithm,
|
2375
|
+
signature=schema.signature,
|
2376
|
+
)
|
2377
|
+
return hip_signature
|
2378
|
+
|
2379
|
+
def _read_param_echo_request_unsigned(self, schema: 'Schema_EchoRequestUnsignedParameter', *, version: 'int', # pylint: disable=unused-argument
|
2380
|
+
options: 'Parameter') -> 'Data_EchoRequestUnsignedParameter': # pylint: disable=unused-argument
|
2381
|
+
"""Read HIP ``ECHO_REQUEST_UNSIGNED`` parameter.
|
2382
|
+
|
2383
|
+
Structure of HIP ``ECHO_REQUEST_UNSIGNED`` parameter [:rfc:`7401`]:
|
2384
|
+
|
2385
|
+
.. code-block:: text
|
2386
|
+
|
2387
|
+
0 1 2 3
|
2388
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2389
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2390
|
+
| Type | Length |
|
2391
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2392
|
+
| Opaque data (variable length) |
|
2393
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2394
|
+
|
2395
|
+
Args:
|
2396
|
+
schema: parsed parameter schama
|
2397
|
+
version: HIP protocol version
|
2398
|
+
options: parsed HIP parameters
|
2399
|
+
|
2400
|
+
Returns:
|
2401
|
+
Parsed parameter data.
|
2402
|
+
|
2403
|
+
"""
|
2404
|
+
echo_request_unsigned = Data_EchoRequestUnsignedParameter(
|
2405
|
+
type=schema.type,
|
2406
|
+
critical=bool(schema.type & 0b1),
|
2407
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2408
|
+
opaque=schema.opaque,
|
2409
|
+
)
|
2410
|
+
return echo_request_unsigned
|
2411
|
+
|
2412
|
+
def _read_param_echo_response_unsigned(self, schema: 'Schema_EchoResponseUnsignedParameter', *, version: 'int', # pylint: disable=unused-argument
|
2413
|
+
options: 'Parameter') -> 'Data_EchoResponseUnsignedParameter': # pylint: disable=unused-argument
|
2414
|
+
"""Read HIP ``ECHO_RESPONSE_UNSIGNED`` parameter.
|
2415
|
+
|
2416
|
+
Structure of HIP ``ECHO_RESPONSE_UNSIGNED`` parameter [:rfc:`7401`]:
|
2417
|
+
|
2418
|
+
.. code-block:: text
|
2419
|
+
|
2420
|
+
0 1 2 3
|
2421
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2422
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2423
|
+
| Type | Length |
|
2424
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2425
|
+
| Opaque data (variable length) |
|
2426
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2427
|
+
|
2428
|
+
Args:
|
2429
|
+
schema: parsed parameter schama
|
2430
|
+
version: HIP protocol version
|
2431
|
+
options: parsed HIP parameters
|
2432
|
+
|
2433
|
+
Returns:
|
2434
|
+
Parsed parameter data.
|
2435
|
+
|
2436
|
+
"""
|
2437
|
+
echo_response_unsigned = Data_EchoResponseUnsignedParameter(
|
2438
|
+
type=schema.type,
|
2439
|
+
critical=bool(schema.type & 0b1),
|
2440
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2441
|
+
opaque=schema.opaque,
|
2442
|
+
)
|
2443
|
+
return echo_response_unsigned
|
2444
|
+
|
2445
|
+
def _read_param_relay_from(self, schema: 'Schema_RelayFromParameter', *, version: 'int', # pylint: disable=unused-argument
|
2446
|
+
options: 'Parameter') -> 'Data_RelayFromParameter': # pylint: disable=unused-argument
|
2447
|
+
"""Read HIP ``RELAY_FROM`` parameter.
|
2448
|
+
|
2449
|
+
Structure of HIP ``RELAY_FROM`` parameter [:rfc:`5770`]:
|
2450
|
+
|
2451
|
+
.. code-block:: text
|
2452
|
+
|
2453
|
+
0 1 2 3
|
2454
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2455
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2456
|
+
| Type | Length |
|
2457
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2458
|
+
| Port | Protocol | Reserved |
|
2459
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2460
|
+
| |
|
2461
|
+
| Address |
|
2462
|
+
| |
|
2463
|
+
| |
|
2464
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2465
|
+
|
2466
|
+
Args:
|
2467
|
+
schema: parsed parameter schama
|
2468
|
+
version: HIP protocol version
|
2469
|
+
options: parsed HIP parameters
|
2470
|
+
|
2471
|
+
Returns:
|
2472
|
+
Parsed parameter data.
|
2473
|
+
|
2474
|
+
Raises:
|
2475
|
+
ProtocolError: If ``schema.len`` is **NOT** ``20``.
|
2476
|
+
|
2477
|
+
"""
|
2478
|
+
if schema.len != 20:
|
2479
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
2480
|
+
|
2481
|
+
address = ipaddress.ip_address(schema.address)
|
2482
|
+
schema.address = address # type: ignore[assignment]
|
2483
|
+
|
2484
|
+
relay_from = Data_RelayFromParameter(
|
2485
|
+
type=schema.type,
|
2486
|
+
critical=bool(schema.type & 0b1),
|
2487
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2488
|
+
port=schema.port,
|
2489
|
+
protocol=schema.protocol,
|
2490
|
+
address=address, # type: ignore[arg-type]
|
2491
|
+
)
|
2492
|
+
return relay_from
|
2493
|
+
|
2494
|
+
def _read_param_relay_to(self, schema: 'Schema_RelayToParameter', *, version: 'int', # pylint: disable=unused-argument
|
2495
|
+
options: 'Parameter') -> 'Data_RelayToParameter': # pylint: disable=unused-argument
|
2496
|
+
"""Read HIP ``RELAY_TO`` parameter.
|
2497
|
+
|
2498
|
+
Structure of HIP ``RELAY_TO`` parameter [:rfc:`5770`]:
|
2499
|
+
|
2500
|
+
.. code-block:: text
|
2501
|
+
|
2502
|
+
0 1 2 3
|
2503
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2504
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2505
|
+
| Type | Length |
|
2506
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2507
|
+
| Port | Protocol | Reserved |
|
2508
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2509
|
+
| |
|
2510
|
+
| Address |
|
2511
|
+
| |
|
2512
|
+
| |
|
2513
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2514
|
+
|
2515
|
+
Args:
|
2516
|
+
schema: parsed parameter schama
|
2517
|
+
version: HIP protocol version
|
2518
|
+
options: parsed HIP parameters
|
2519
|
+
|
2520
|
+
Returns:
|
2521
|
+
Parsed parameter data.
|
2522
|
+
|
2523
|
+
Raises:
|
2524
|
+
ProtocolError: If ``schema.len`` is **NOT** ``20``.
|
2525
|
+
|
2526
|
+
"""
|
2527
|
+
if schema.len != 20:
|
2528
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
2529
|
+
|
2530
|
+
address = ipaddress.ip_address(schema.address)
|
2531
|
+
schema.address = address # type: ignore[assignment]
|
2532
|
+
|
2533
|
+
relay_to = Data_RelayToParameter(
|
2534
|
+
type=schema.type,
|
2535
|
+
critical=bool(schema.type & 0b1),
|
2536
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2537
|
+
port=schema.port,
|
2538
|
+
protocol=schema.protocol,
|
2539
|
+
address=address, # type: ignore[arg-type]
|
2540
|
+
)
|
2541
|
+
return relay_to
|
2542
|
+
|
2543
|
+
def _read_param_overlay_ttl(self, schema: 'Schema_OverlayTTLParameter', *, version: 'int', # pylint: disable=unused-argument
|
2544
|
+
options: 'Parameter') -> 'Data_OverlayTTLParameter': # pylint: disable=unused-argument
|
2545
|
+
"""Read HIP ``OVERLAY_TTL`` parameter.
|
2546
|
+
|
2547
|
+
Structure of HIP ``OVERLAY_TTL`` parameter [:rfc:`6078`]:
|
2548
|
+
|
2549
|
+
.. code-block:: text
|
2550
|
+
|
2551
|
+
0 1 2 3
|
2552
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2553
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2554
|
+
| Type | Length |
|
2555
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2556
|
+
| TTL | Reserved |
|
2557
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2558
|
+
|
2559
|
+
Args:
|
2560
|
+
schema: parsed parameter schama
|
2561
|
+
version: HIP protocol version
|
2562
|
+
options: parsed HIP parameters
|
2563
|
+
|
2564
|
+
Returns:
|
2565
|
+
Parsed parameter data.
|
2566
|
+
|
2567
|
+
Raises:
|
2568
|
+
ProtocolError: If ``schema.len`` is **NOT** ``4``.
|
2569
|
+
|
2570
|
+
"""
|
2571
|
+
if schema.len != 4:
|
2572
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
2573
|
+
|
2574
|
+
overlay_ttl = Data_OverlayTTLParameter(
|
2575
|
+
type=schema.type,
|
2576
|
+
critical=bool(schema.type & 0b1),
|
2577
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2578
|
+
ttl=datetime.timedelta(seconds=schema.ttl),
|
2579
|
+
)
|
2580
|
+
return overlay_ttl
|
2581
|
+
|
2582
|
+
def _read_param_route_via(self, schema: 'Schema_RouteViaParameter', *, version: 'int', # pylint: disable=unused-argument
|
2583
|
+
options: 'Parameter') -> 'Data_RouteViaParameter': # pylint: disable=unused-argument
|
2584
|
+
"""Read HIP ``ROUTE_VIA`` parameter.
|
2585
|
+
|
2586
|
+
Structure of HIP ``ROUTE_VIA`` parameter [:rfc:`6028`]:
|
2587
|
+
|
2588
|
+
.. code-block:: text
|
2589
|
+
|
2590
|
+
0 1 2 3
|
2591
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2592
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2593
|
+
| Type | Length |
|
2594
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2595
|
+
| Flags | Reserved |
|
2596
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2597
|
+
| |
|
2598
|
+
| HIT #1 |
|
2599
|
+
| |
|
2600
|
+
| |
|
2601
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2602
|
+
. . .
|
2603
|
+
. . .
|
2604
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2605
|
+
| |
|
2606
|
+
| HIT #n |
|
2607
|
+
| |
|
2608
|
+
| |
|
2609
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2610
|
+
|
2611
|
+
Args:
|
2612
|
+
schema: parsed parameter schama
|
2613
|
+
version: HIP protocol version
|
2614
|
+
options: parsed HIP parameters
|
2615
|
+
|
2616
|
+
Returns:
|
2617
|
+
Parsed parameter data.
|
2618
|
+
|
2619
|
+
Raises:
|
2620
|
+
ProtocolError: If the parameter is malformed.
|
2621
|
+
|
2622
|
+
"""
|
2623
|
+
if (schema.len - 4) % 16 != 0:
|
2624
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
2625
|
+
|
2626
|
+
route_via = Data_RouteViaParameter(
|
2627
|
+
type=schema.type,
|
2628
|
+
critical=bool(schema.type & 0b1),
|
2629
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2630
|
+
flags=Data_Flags(
|
2631
|
+
symmetric=bool(schema.flags['symmetric']),
|
2632
|
+
must_follow=bool(schema.flags['must_follow']),
|
2633
|
+
),
|
2634
|
+
hit=tuple(schema.hit),
|
2635
|
+
)
|
2636
|
+
return route_via
|
2637
|
+
|
2638
|
+
def _read_param_from(self, schema: 'Schema_FromParameter', *, version: 'int', # pylint: disable=unused-argument
|
2639
|
+
options: 'Parameter') -> 'Data_FromParameter': # pylint: disable=unused-argument
|
2640
|
+
"""Read HIP ``FROM`` parameter.
|
2641
|
+
|
2642
|
+
Structure of HIP ``FROM`` parameter [:rfc:`8004`]:
|
2643
|
+
|
2644
|
+
.. code-block:: text
|
2645
|
+
|
2646
|
+
0 1 2 3
|
2647
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2648
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2649
|
+
| Type | Length |
|
2650
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2651
|
+
| |
|
2652
|
+
| Address |
|
2653
|
+
| |
|
2654
|
+
| |
|
2655
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2656
|
+
|
2657
|
+
Args:
|
2658
|
+
schema: parsed parameter schama
|
2659
|
+
version: HIP protocol version
|
2660
|
+
options: parsed HIP parameters
|
2661
|
+
|
2662
|
+
Returns:
|
2663
|
+
Parsed parameter data.
|
2664
|
+
|
2665
|
+
Raises:
|
2666
|
+
ProtocolError: If ``schema.len`` is **NOT** ``16``.
|
2667
|
+
|
2668
|
+
"""
|
2669
|
+
if schema.len != 16:
|
2670
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
2671
|
+
|
2672
|
+
from_ = Data_FromParameter(
|
2673
|
+
type=schema.type,
|
2674
|
+
critical=bool(schema.type & 0b1),
|
2675
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2676
|
+
address=schema.address,
|
2677
|
+
)
|
2678
|
+
return from_
|
2679
|
+
|
2680
|
+
def _read_param_rvs_hmac(self, schema: 'Schema_RVSHMACParameter', *, version: 'int', # pylint: disable=unused-argument
|
2681
|
+
options: 'Parameter') -> 'Data_RVSHMACParameter': # pylint: disable=unused-argument
|
2682
|
+
"""Read HIP ``RVS_HMAC`` parameter.
|
2683
|
+
|
2684
|
+
Structure of HIP ``RVS_HMAC`` parameter [:rfc:`8004`]:
|
2685
|
+
|
2686
|
+
.. code-block:: text
|
2687
|
+
|
2688
|
+
0 1 2 3
|
2689
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2690
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2691
|
+
| |
|
2692
|
+
| HMAC |
|
2693
|
+
/ /
|
2694
|
+
/ +-------------------------------+
|
2695
|
+
| | Padding |
|
2696
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2697
|
+
|
2698
|
+
Args:
|
2699
|
+
schema: parsed parameter schama
|
2700
|
+
version: HIP protocol version
|
2701
|
+
options: parsed HIP parameters
|
2702
|
+
|
2703
|
+
Returns:
|
2704
|
+
Parsed parameter data.
|
2705
|
+
|
2706
|
+
"""
|
2707
|
+
rvs_hmac = Data_RVSHMACParameter(
|
2708
|
+
type=schema.type,
|
2709
|
+
critical=bool(schema.type & 0b1),
|
2710
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2711
|
+
hmac=schema.hmac,
|
2712
|
+
)
|
2713
|
+
return rvs_hmac
|
2714
|
+
|
2715
|
+
def _read_param_via_rvs(self, schema: 'Schema_ViaRVSParameter', *, version: 'int', # pylint: disable=unused-argument
|
2716
|
+
options: 'Parameter') -> 'Data_ViaRVSParameter': # pylint: disable=unused-argument
|
2717
|
+
"""Read HIP ``VIA_RVS`` parameter.
|
2718
|
+
|
2719
|
+
Structure of HIP ``VIA_RVS`` parameter [:rfc:`6028`]:
|
2720
|
+
|
2721
|
+
.. code-block:: text
|
2722
|
+
|
2723
|
+
0 1 2 3
|
2724
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2725
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2726
|
+
| Type | Length |
|
2727
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2728
|
+
| |
|
2729
|
+
| Address |
|
2730
|
+
| |
|
2731
|
+
| |
|
2732
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2733
|
+
. . .
|
2734
|
+
. . .
|
2735
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2736
|
+
| |
|
2737
|
+
| Address |
|
2738
|
+
| |
|
2739
|
+
| |
|
2740
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2741
|
+
|
2742
|
+
Args:
|
2743
|
+
schema: parsed parameter schama
|
2744
|
+
version: HIP protocol version
|
2745
|
+
options: parsed HIP parameters
|
2746
|
+
|
2747
|
+
Returns:
|
2748
|
+
Parsed parameter data.
|
2749
|
+
|
2750
|
+
Raises:
|
2751
|
+
ProtocolError: If ``schema.len`` is **NOT** ``16`` modulo.
|
2752
|
+
|
2753
|
+
"""
|
2754
|
+
if schema.len % 16 != 0:
|
2755
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
|
2756
|
+
|
2757
|
+
via_rvs = Data_ViaRVSParameter(
|
2758
|
+
type=schema.type,
|
2759
|
+
critical=bool(schema.type & 0b1),
|
2760
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2761
|
+
address=tuple(schema.address),
|
2762
|
+
)
|
2763
|
+
return via_rvs
|
2764
|
+
|
2765
|
+
def _read_param_relay_hmac(self, schema: 'Schema_RelayHMACParameter', version: 'int', # pylint: disable=unused-argument
|
2766
|
+
options: 'Parameter') -> 'Data_RelayHMACParameter': # pylint: disable=unused-argument
|
2767
|
+
"""Read HIP ``RELAY_HMAC`` parameter.
|
2768
|
+
|
2769
|
+
Structure of HIP ``RELAY_HMAC`` parameter [:rfc:`5770`]:
|
2770
|
+
|
2771
|
+
.. code-block::
|
2772
|
+
|
2773
|
+
0 1 2 3
|
2774
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2775
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2776
|
+
| |
|
2777
|
+
| HMAC |
|
2778
|
+
/ /
|
2779
|
+
/ +-------------------------------+
|
2780
|
+
| | Padding |
|
2781
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2782
|
+
|
2783
|
+
Args:
|
2784
|
+
schema: parsed parameter schama
|
2785
|
+
version: HIP protocol version
|
2786
|
+
options: parsed HIP parameters
|
2787
|
+
|
2788
|
+
Returns:
|
2789
|
+
Parsed parameter data.
|
2790
|
+
|
2791
|
+
"""
|
2792
|
+
relay_hmac = Data_RelayHMACParameter(
|
2793
|
+
type=schema.type,
|
2794
|
+
critical=bool(schema.type & 0b1),
|
2795
|
+
length=4 + schema.len + (8 - schema.len % 8) % 8,
|
2796
|
+
hmac=schema.hmac,
|
2797
|
+
)
|
2798
|
+
return relay_hmac
|
2799
|
+
|
2800
|
+
def _make_hip_param(self, parameters: 'list[Schema_Parameter | tuple[Enum_Parameter, dict[str, Any]] | bytes] | Parameter', *,
|
2801
|
+
version: 'int') -> 'tuple[list[Schema_Parameter | bytes], int]':
|
2802
|
+
"""Make HIP parameter.
|
2803
|
+
|
2804
|
+
Args:
|
2805
|
+
parameters: HIP parameters
|
2806
|
+
version: HIP protocol version
|
2807
|
+
|
2808
|
+
Returns:
|
2809
|
+
HIP parameters and total length.
|
2810
|
+
|
2811
|
+
"""
|
2812
|
+
total_length = 0
|
2813
|
+
if isinstance(parameters, list):
|
2814
|
+
parameters_list = [] # type: list[Schema_Parameter | bytes]
|
2815
|
+
for schema in parameters:
|
2816
|
+
if isinstance(schema, bytes):
|
2817
|
+
parameters_list.append(schema)
|
2818
|
+
total_length += len(schema)
|
2819
|
+
elif isinstance(schema, Schema):
|
2820
|
+
schema_packed = schema.pack()
|
2821
|
+
|
2822
|
+
parameters_list.append(schema_packed)
|
2823
|
+
total_length += len(schema_packed)
|
2824
|
+
else:
|
2825
|
+
code, args = cast('tuple[Enum_Parameter, dict[str, Any]]', schema)
|
2826
|
+
meth_name = f'_make_param_{code.name.lower()}'
|
2827
|
+
meth = cast('ParameterConstructor',
|
2828
|
+
getattr(self, meth_name, self._make_param_unassigned))
|
2829
|
+
|
2830
|
+
data = meth(code, version=version, **args) # type: Schema_Parameter
|
2831
|
+
data_packed = data.pack()
|
2832
|
+
|
2833
|
+
parameters_list.append(data)
|
2834
|
+
total_length += len(data_packed)
|
2835
|
+
return parameters_list, total_length
|
2836
|
+
|
2837
|
+
parameters_list = []
|
2838
|
+
for code, param in parameters.items(multi=True):
|
2839
|
+
meth_name = f'_make_param_{code.name.lower()}'
|
2840
|
+
meth = cast('ParameterConstructor',
|
2841
|
+
getattr(self, meth_name, self._make_param_unassigned))
|
2842
|
+
|
2843
|
+
data = meth(code, param, version=version)
|
2844
|
+
data_packed = data.pack()
|
2845
|
+
|
2846
|
+
parameters_list.append(data)
|
2847
|
+
total_length += len(data_packed)
|
2848
|
+
return parameters_list, total_length
|
2849
|
+
|
2850
|
+
def _make_param_unassigned(self, code: 'Enum_Parameter', param: 'Optional[Data_UnassignedParameter]' = None, *, # pylint: disable=unused-argument
|
2851
|
+
version: 'int',
|
2852
|
+
contents: 'bytes' = b'',
|
2853
|
+
**kwargs: 'Any') -> 'Schema_UnassignedParameter':
|
2854
|
+
"""Make HIP unassigned parameter.
|
2855
|
+
|
2856
|
+
Args:
|
2857
|
+
code: parameter code
|
2858
|
+
param: parameter data
|
2859
|
+
version: HIP protocol version
|
2860
|
+
contents: parameter contents
|
2861
|
+
**kwargs: arbitrary keyword arguments
|
2862
|
+
|
2863
|
+
Returns:
|
2864
|
+
HIP parameter schema.
|
2865
|
+
|
2866
|
+
"""
|
2867
|
+
if param is not None:
|
2868
|
+
contents = param.contents
|
2869
|
+
|
2870
|
+
return Schema_UnassignedParameter(
|
2871
|
+
type=code,
|
2872
|
+
len=len(contents),
|
2873
|
+
value=contents,
|
2874
|
+
)
|
2875
|
+
|
2876
|
+
def _make_param_esp_info(self, code: 'Enum_Parameter', param: 'Optional[Data_ESPInfoParameter]' = None, *, # pylint: disable=unused-argument
|
2877
|
+
version: 'int',
|
2878
|
+
index: 'int' = 0,
|
2879
|
+
old_spi: 'int' = 0,
|
2880
|
+
new_spi: 'int' = 0,
|
2881
|
+
**kwargs: 'Any') -> 'Schema_ESPInfoParameter':
|
2882
|
+
"""Make HIP ``ESP_INFO`` parameter.
|
2883
|
+
|
2884
|
+
Args:
|
2885
|
+
code: parameter code
|
2886
|
+
param: parameter data
|
2887
|
+
version: HIP protocol version
|
2888
|
+
index: KEYMAT index
|
2889
|
+
old_spi: old SPI
|
2890
|
+
new_spi: new SPI
|
2891
|
+
**kwargs: arbitrary keyword arguments
|
2892
|
+
|
2893
|
+
Returns:
|
2894
|
+
HIP parameter schema.
|
2895
|
+
|
2896
|
+
"""
|
2897
|
+
if param is not None:
|
2898
|
+
index = param.index
|
2899
|
+
old_spi = param.old_spi
|
2900
|
+
new_spi = param.new_spi
|
2901
|
+
|
2902
|
+
return Schema_ESPInfoParameter(
|
2903
|
+
type=code,
|
2904
|
+
len=12,
|
2905
|
+
index=index,
|
2906
|
+
old_spi=old_spi,
|
2907
|
+
new_spi=new_spi,
|
2908
|
+
)
|
2909
|
+
|
2910
|
+
def _make_param_r1_counter(self, code: 'Enum_Parameter', param: 'Optional[Data_R1CounterParameter]' = None, *, # pylint: disable=unused-argument
|
2911
|
+
version: 'int',
|
2912
|
+
counter: 'int' = 0,
|
2913
|
+
**kwargs: 'Any') -> 'Schema_R1CounterParameter':
|
2914
|
+
"""Make HIP ``R1_COUNTER`` parameter.
|
2915
|
+
|
2916
|
+
Args:
|
2917
|
+
code: parameter code
|
2918
|
+
param: parameter data
|
2919
|
+
version: HIP protocol version
|
2920
|
+
counter: R1 generation counter
|
2921
|
+
**kwargs: arbitrary keyword arguments
|
2922
|
+
|
2923
|
+
Returns:
|
2924
|
+
HIP parameter schema.
|
2925
|
+
|
2926
|
+
"""
|
2927
|
+
if code == Enum_Parameter.R1_Counter and version != 1:
|
2928
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {code}] invalid parameter')
|
2929
|
+
|
2930
|
+
if param is not None:
|
2931
|
+
counter = param.counter
|
2932
|
+
|
2933
|
+
return Schema_R1CounterParameter(
|
2934
|
+
type=code,
|
2935
|
+
len=12,
|
2936
|
+
counter=counter,
|
2937
|
+
)
|
2938
|
+
|
2939
|
+
def _make_param_locator_set(self, code: 'Enum_Parameter', param: 'Optional[Data_LocatorSetParameter]' = None, *, # pylint: disable=unused-argument
|
2940
|
+
version: 'int',
|
2941
|
+
locator_set: 'Optional[list[Data_Locator | Locator]]' = None,
|
2942
|
+
**kwargs: 'Any') -> 'Schema_LocatorSetParameter':
|
2943
|
+
"""Make HIP ``LOCATOR_SET`` parameter.
|
2944
|
+
|
2945
|
+
Args:
|
2946
|
+
code: parameter code
|
2947
|
+
param: parameter data
|
2948
|
+
version: HIP protocol version
|
2949
|
+
locator_set: locators data
|
2950
|
+
**kwargs: arbitrary keyword arguments
|
2951
|
+
|
2952
|
+
Returns:
|
2953
|
+
HIP parameter schema.
|
2954
|
+
|
2955
|
+
"""
|
2956
|
+
def _make_locator(locator: 'Optional[Data_Locator]' = None, *,
|
2957
|
+
traffic: 'int' = 0,
|
2958
|
+
type: 'int' = 0,
|
2959
|
+
preferred: 'bool' = False,
|
2960
|
+
lifetime: 'timedelta | int' = 0,
|
2961
|
+
ip: 'IPv6Address | bytes | int | str' = '::',
|
2962
|
+
spi: 'Optional[int]' = None,
|
2963
|
+
**kwargs: 'Any') -> 'Schema_Locator':
|
2964
|
+
"""Make locator data.
|
2965
|
+
|
2966
|
+
Args:
|
2967
|
+
locator: locator data
|
2968
|
+
traffic: traffic type
|
2969
|
+
type: locator type
|
2970
|
+
preferred: preferred flag
|
2971
|
+
lifetime: lifetime
|
2972
|
+
ip: IP address
|
2973
|
+
spi: SPI
|
2974
|
+
**kwargs: arbitrary keyword arguments
|
2975
|
+
|
2976
|
+
Returns:
|
2977
|
+
HIP locator schema.
|
2978
|
+
|
2979
|
+
"""
|
2980
|
+
if locator is not None:
|
2981
|
+
value = locator.locator
|
2982
|
+
if isinstance(value, ipaddress.IPv6Address):
|
2983
|
+
data = value.packed # type: bytes | Schema_LocatorData
|
2984
|
+
elif isinstance(value, Data_LocatorData):
|
2985
|
+
data = Schema_LocatorData(
|
2986
|
+
spi=value.spi,
|
2987
|
+
ip=value.ip.packed,
|
2988
|
+
)
|
2989
|
+
else:
|
2990
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {code}] invalid format')
|
2991
|
+
|
2992
|
+
traffic = locator.traffic
|
2993
|
+
type = locator.type
|
2994
|
+
length = locator.length // 4
|
2995
|
+
preferred = locator.preferred
|
2996
|
+
lifetime = math.floor(locator.lifetime.total_seconds())
|
2997
|
+
else:
|
2998
|
+
if spi is None:
|
2999
|
+
length = 4
|
3000
|
+
data = ipaddress.IPv6Address(ip).packed
|
3001
|
+
else:
|
3002
|
+
length = 5
|
3003
|
+
data = Schema_LocatorData(
|
3004
|
+
spi=spi,
|
3005
|
+
ip=ipaddress.IPv6Address(ip).packed,
|
3006
|
+
)
|
3007
|
+
|
3008
|
+
if isinstance(lifetime, timedelta):
|
3009
|
+
lifetime = math.floor(lifetime.total_seconds())
|
3010
|
+
|
3011
|
+
return Schema_Locator(
|
3012
|
+
traffic=traffic,
|
3013
|
+
type=type,
|
3014
|
+
len=length,
|
3015
|
+
flags={
|
3016
|
+
'preferred': preferred,
|
3017
|
+
},
|
3018
|
+
lifetime=lifetime,
|
3019
|
+
value=data,
|
3020
|
+
)
|
3021
|
+
|
3022
|
+
if param is not None:
|
3023
|
+
locators = [_make_locator(locator) for locator in param.locator_set]
|
3024
|
+
else:
|
3025
|
+
if locator_set is None:
|
3026
|
+
locator_set = []
|
3027
|
+
locators = [_make_locator(**locator) for locator in locator_set]
|
3028
|
+
|
3029
|
+
return Schema_LocatorSetParameter(
|
3030
|
+
type=code,
|
3031
|
+
len=sum(locator['len'] for locator in locators),
|
3032
|
+
locators=locators,
|
3033
|
+
)
|
3034
|
+
|
3035
|
+
def _make_param_puzzle(self, code: 'Enum_Parameter', param: 'Optional[Data_PuzzleParameter]' = None, *, # pylint: disable=unused-argument
|
3036
|
+
version: 'int',
|
3037
|
+
index: 'int' = 0,
|
3038
|
+
lifetime: 'timedelta | int' = 0,
|
3039
|
+
opaque: 'bytes' = b'',
|
3040
|
+
random: 'int' = 0,
|
3041
|
+
**kwargs: 'Any') -> 'Schema_PuzzleParameter':
|
3042
|
+
"""Make HIP ``PUZZLE`` parameter.
|
3043
|
+
|
3044
|
+
Args:
|
3045
|
+
code: parameter code
|
3046
|
+
param: parameter data
|
3047
|
+
version: HIP protocol version
|
3048
|
+
index: #K index
|
3049
|
+
lifetime: lifetime
|
3050
|
+
opaque: opaque data
|
3051
|
+
random: random #I value
|
3052
|
+
**kwargs: arbitrary keyword arguments
|
3053
|
+
|
3054
|
+
Returns:
|
3055
|
+
HIP parameter schema.
|
3056
|
+
|
3057
|
+
"""
|
3058
|
+
if param is not None:
|
3059
|
+
index = param.index
|
3060
|
+
lifetime = math.floor(math.log2(param.lifetime.total_seconds()) + 32)
|
3061
|
+
opaque = param.opaque
|
3062
|
+
random = param.random
|
3063
|
+
else:
|
3064
|
+
lifetime = math.floor(math.log2(
|
3065
|
+
lifetime if isinstance(lifetime, int) else lifetime.total_seconds()
|
3066
|
+
) + 32)
|
3067
|
+
|
3068
|
+
return Schema_PuzzleParameter(
|
3069
|
+
type=code,
|
3070
|
+
len=4 + math.ceil(random.bit_length() / 8),
|
3071
|
+
index=index,
|
3072
|
+
lifetime=lifetime,
|
3073
|
+
opaque=opaque,
|
3074
|
+
random=random,
|
3075
|
+
)
|
3076
|
+
|
3077
|
+
def _make_param_solution(self, code: 'Enum_Parameter', param: 'Optional[Data_SolutionParameter]' = None, *, # pylint: disable=unused-argument
|
3078
|
+
version: 'int',
|
3079
|
+
index: 'int' = 0,
|
3080
|
+
lifetime: 'timedelta | int' = 0,
|
3081
|
+
opaque: 'bytes' = b'',
|
3082
|
+
random: 'int' = 0,
|
3083
|
+
solution: 'int' = 0,
|
3084
|
+
**kwargs: 'Any') -> 'Schema_SolutionParameter':
|
3085
|
+
"""Make HIP ``SOLUTION`` parameter.
|
3086
|
+
|
3087
|
+
Args:
|
3088
|
+
code: parameter code
|
3089
|
+
param: parameter data
|
3090
|
+
version: HIP protocol version
|
3091
|
+
index: #K index
|
3092
|
+
lifetime: lifetime
|
3093
|
+
opaque: opaque data
|
3094
|
+
random: random #I value
|
3095
|
+
solution: solution #J value
|
3096
|
+
|
3097
|
+
Returns:
|
3098
|
+
HIP parameter schema.
|
3099
|
+
|
3100
|
+
"""
|
3101
|
+
if param is not None:
|
3102
|
+
index = param.index
|
3103
|
+
lifetime = math.floor(math.log2(param.lifetime.total_seconds()) + 32)
|
3104
|
+
opaque = param.opaque
|
3105
|
+
random = param.random
|
3106
|
+
solution = param.solution
|
3107
|
+
else:
|
3108
|
+
lifetime = math.floor(math.log2(
|
3109
|
+
lifetime if isinstance(lifetime, int) else lifetime.total_seconds()
|
3110
|
+
) + 32)
|
3111
|
+
|
3112
|
+
return Schema_SolutionParameter(
|
3113
|
+
type=code,
|
3114
|
+
len=4 + math.ceil(max(random.bit_length(), solution.bit_length()) / 4),
|
3115
|
+
index=index,
|
3116
|
+
lifetime=lifetime,
|
3117
|
+
opaque=opaque,
|
3118
|
+
random=random,
|
3119
|
+
solution=solution,
|
3120
|
+
)
|
3121
|
+
|
3122
|
+
def _make_param_seq(self, code: 'Enum_Parameter', param: 'Optional[Data_SEQParameter]' = None, *, # pylint: disable=unused-argument
|
3123
|
+
version: 'int',
|
3124
|
+
update_id: 'int' = 0,
|
3125
|
+
**kwargs: 'Any') -> 'Schema_SEQParameter':
|
3126
|
+
"""Make HIP ``SEQ`` parameter.
|
3127
|
+
|
3128
|
+
Args:
|
3129
|
+
code: parameter code
|
3130
|
+
param: parameter data
|
3131
|
+
version: HIP protocol version
|
3132
|
+
update_id: update ID
|
3133
|
+
|
3134
|
+
Returns:
|
3135
|
+
HIP parameter schema.
|
3136
|
+
|
3137
|
+
"""
|
3138
|
+
if param is not None:
|
3139
|
+
update_id = param.id
|
3140
|
+
|
3141
|
+
return Schema_SEQParameter(
|
3142
|
+
type=code,
|
3143
|
+
len=4,
|
3144
|
+
update_id=update_id,
|
3145
|
+
)
|
3146
|
+
|
3147
|
+
def _make_param_ack(self, code: 'Enum_Parameter', param: 'Optional[Data_ACKParameter]' = None, *, # pylint: disable=unused-argument
|
3148
|
+
version: 'int',
|
3149
|
+
update_id: 'Optional[list[int]]' = None,
|
3150
|
+
**kwargs: 'Any') -> 'Schema_ACKParameter':
|
3151
|
+
"""Make HIP ``ACK`` parameter.
|
3152
|
+
|
3153
|
+
Args:
|
3154
|
+
code: parameter code
|
3155
|
+
param: parameter data
|
3156
|
+
version: HIP protocol version
|
3157
|
+
update_id: list of update ID
|
3158
|
+
|
3159
|
+
Returns:
|
3160
|
+
HIP parameter schema.
|
3161
|
+
|
3162
|
+
"""
|
3163
|
+
if param is not None:
|
3164
|
+
id_list = cast('list[int]', param.update_id)
|
3165
|
+
else:
|
3166
|
+
if update_id is None:
|
3167
|
+
update_id = []
|
3168
|
+
id_list = update_id
|
3169
|
+
|
3170
|
+
return Schema_ACKParameter(
|
3171
|
+
type=code,
|
3172
|
+
len=4 * len(id_list),
|
3173
|
+
update_id=id_list,
|
3174
|
+
)
|
3175
|
+
|
3176
|
+
def _make_param_dh_group_list(self, code: 'Enum_Parameter', param: 'Optional[Data_DHGroupListParameter]' = None, *, # pylint: disable=unused-argument
|
3177
|
+
version: 'int',
|
3178
|
+
groups: 'Optional[list[Enum_Group | StdlibEnum | AenumEnum | str | int]]' = None,
|
3179
|
+
group_default: 'Optional[int]' = None,
|
3180
|
+
group_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
3181
|
+
group_reversed: 'bool' = False,
|
3182
|
+
**kwargs: 'Any') -> 'Schema_DHGroupListParameter':
|
3183
|
+
"""Make HIP ``DH_GROUP_LIST`` parameter.
|
3184
|
+
|
3185
|
+
Args:
|
3186
|
+
code: parameter code
|
3187
|
+
param: parameter data
|
3188
|
+
version: HIP protocol version
|
3189
|
+
groups: list of group ID
|
3190
|
+
group_default: default group ID
|
3191
|
+
group_namespace: group ID namespace
|
3192
|
+
group_reversed: reverse group ID namespace
|
3193
|
+
**kwargs: arbitrary keyword arguments
|
3194
|
+
|
3195
|
+
Returns:
|
3196
|
+
HIP parameter schema.
|
3197
|
+
|
3198
|
+
"""
|
3199
|
+
if param is not None:
|
3200
|
+
group_id = cast('list[Enum_Group]', param.group_id)
|
3201
|
+
else:
|
3202
|
+
if groups is None:
|
3203
|
+
groups = []
|
3204
|
+
|
3205
|
+
group_id = []
|
3206
|
+
for group in groups:
|
3207
|
+
group_id.append(self._make_index(group, group_default, namespace=group_namespace, # type: ignore[arg-type]
|
3208
|
+
reversed=group_reversed, pack=False))
|
3209
|
+
|
3210
|
+
return Schema_DHGroupListParameter(
|
3211
|
+
type=code,
|
3212
|
+
len=len(group_id),
|
3213
|
+
groups=group_id,
|
3214
|
+
)
|
3215
|
+
|
3216
|
+
def _make_param_diffie_hellman(self, code: 'Enum_Parameter', param: 'Optional[Data_DiffieHellmanParameter]' = None, *, # pylint: disable=unused-argument
|
3217
|
+
version: 'int',
|
3218
|
+
group: 'Enum_Group | StdlibEnum | AenumEnum | str | int' = Enum_Group.NIST_P_256,
|
3219
|
+
group_default: 'Optional[int]' = None,
|
3220
|
+
group_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
3221
|
+
group_reversed: 'bool' = False,
|
3222
|
+
pub_val: 'int' = 0,
|
3223
|
+
**kwargs: 'Any') -> 'Schema_DiffieHellmanParameter':
|
3224
|
+
"""Make HIP ``DIFFIE_HELLMAN`` parameter.
|
3225
|
+
|
3226
|
+
Args:
|
3227
|
+
code: parameter code
|
3228
|
+
param: parameter data
|
3229
|
+
version: HIP protocol version
|
3230
|
+
group: group ID
|
3231
|
+
group_default: default group ID
|
3232
|
+
group_namespace: group ID namespace
|
3233
|
+
group_reversed: reverse group ID namespace
|
3234
|
+
pub_val: public value
|
3235
|
+
**kwargs: arbitrary keyword arguments
|
3236
|
+
|
3237
|
+
Returns:
|
3238
|
+
HIP parameter schema.
|
3239
|
+
|
3240
|
+
"""
|
3241
|
+
if param is not None:
|
3242
|
+
group_id = param.group_id
|
3243
|
+
pub_len = param.pub_len
|
3244
|
+
pub_val = param.pub_val
|
3245
|
+
else:
|
3246
|
+
group_id = self._make_index(group, group_default, namespace=group_namespace, # type: ignore[assignment]
|
3247
|
+
reversed=group_reversed, pack=False)
|
3248
|
+
pub_len = math.ceil(pub_val.bit_length() / 8)
|
3249
|
+
|
3250
|
+
return Schema_DiffieHellmanParameter(
|
3251
|
+
type=code,
|
3252
|
+
len=3 + pub_len,
|
3253
|
+
group=group_id,
|
3254
|
+
pub_len=pub_len,
|
3255
|
+
pub_val=pub_val,
|
3256
|
+
)
|
3257
|
+
|
3258
|
+
def _make_param_hip_transform(self, code: 'Enum_Parameter', param: 'Optional[Data_HIPTransformParameter]' = None, *, # pylint: disable=unused-argument
|
3259
|
+
version: 'int',
|
3260
|
+
suites: 'Optional[list[Enum_Suite | StdlibEnum | AenumEnum | str | int]]' = None,
|
3261
|
+
suite_default: 'Optional[int]' = None,
|
3262
|
+
suite_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
3263
|
+
suite_reversed: 'bool' = False,
|
3264
|
+
**kwargs: 'Any') -> 'Schema_HIPTransformParameter':
|
3265
|
+
"""Make HIP ``HIP_TRANSFORM`` parameter.
|
3266
|
+
|
3267
|
+
Args:
|
3268
|
+
code: parameter code
|
3269
|
+
param: parameter data
|
3270
|
+
version: HIP protocol version
|
3271
|
+
suites: list of suite ID
|
3272
|
+
suite_default: default suite ID
|
3273
|
+
suite_namespace: suite ID namespace
|
3274
|
+
suite_reversed: reverse suite ID namespace
|
3275
|
+
**kwargs: arbitrary keyword arguments
|
3276
|
+
|
3277
|
+
Returns:
|
3278
|
+
HIP parameter schema.
|
3279
|
+
|
3280
|
+
"""
|
3281
|
+
if param is not None:
|
3282
|
+
suite_id = cast('list[Enum_Suite]', param.suite_id)
|
3283
|
+
else:
|
3284
|
+
if suites is None:
|
3285
|
+
suites = []
|
3286
|
+
|
3287
|
+
suite_id = []
|
3288
|
+
for suite in suites:
|
3289
|
+
suite_id.append(self._make_index(suite, suite_default, namespace=suite_namespace, # type: ignore[arg-type]
|
3290
|
+
reversed=suite_reversed, pack=False))
|
3291
|
+
|
3292
|
+
return Schema_HIPTransformParameter(
|
3293
|
+
type=code,
|
3294
|
+
len=2 * len(suite_id),
|
3295
|
+
suites=suite_id,
|
3296
|
+
)
|
3297
|
+
|
3298
|
+
def _make_param_hip_cipher(self, code: 'Enum_Parameter', param: 'Optional[Data_HIPCipherParameter]' = None, *, # pylint: disable=unused-argument
|
3299
|
+
version: 'int',
|
3300
|
+
ciphers: 'Optional[list[Enum_Cipher | StdlibEnum | AenumEnum | str | int]]' = None,
|
3301
|
+
cipher_default: 'Optional[int]' = None,
|
3302
|
+
cipher_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
3303
|
+
cipher_reversed: 'bool' = False,
|
3304
|
+
**kwargs: 'Any') -> 'Schema_HIPCipherParameter':
|
3305
|
+
"""Make HIP ``HIP_CIPHER`` parameter.
|
3306
|
+
|
3307
|
+
Args:
|
3308
|
+
code: parameter code
|
3309
|
+
param: parameter data
|
3310
|
+
version: HIP protocol version
|
3311
|
+
ciphers: list of cipher ID
|
3312
|
+
cipher_default: default cipher ID
|
3313
|
+
cipher_namespace: cipher ID namespace
|
3314
|
+
cipher_reversed: reverse cipher ID namespace
|
3315
|
+
**kwargs: arbitrary keyword arguments
|
3316
|
+
|
3317
|
+
Returns:
|
3318
|
+
HIP parameter schema.
|
3319
|
+
|
3320
|
+
"""
|
3321
|
+
if param is not None:
|
3322
|
+
cipher_id = cast('list[Enum_Cipher]', param.cipher_id)
|
3323
|
+
else:
|
3324
|
+
if ciphers is None:
|
3325
|
+
ciphers = []
|
3326
|
+
|
3327
|
+
cipher_id = []
|
3328
|
+
for cipher in ciphers:
|
3329
|
+
cipher_id.append(self._make_index(cipher, cipher_default, namespace=cipher_namespace, # type: ignore[arg-type]
|
3330
|
+
reversed=cipher_reversed, pack=False))
|
3331
|
+
|
3332
|
+
return Schema_HIPCipherParameter(
|
3333
|
+
type=code,
|
3334
|
+
len=2 * len(cipher_id),
|
3335
|
+
ciphers=cipher_id,
|
3336
|
+
)
|
3337
|
+
|
3338
|
+
def _make_param_nat_traversal_mode(self, code: 'Enum_Parameter', param: 'Optional[Data_NATTraversalModeParameter]' = None, *, # pylint: disable=unused-argument
|
3339
|
+
version: 'int',
|
3340
|
+
modes: 'Optional[list[Enum_NATTraversal | StdlibEnum | AenumEnum | str | int]]' = None,
|
3341
|
+
mode_default: 'Optional[int]' = None,
|
3342
|
+
mode_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
3343
|
+
mode_reversed: 'bool' = False,
|
3344
|
+
**kwargs: 'Any') -> 'Schema_NATTraversalModeParameter':
|
3345
|
+
"""Make HIP ``NAT_TRAVERSAL_MODE`` parameter.
|
3346
|
+
|
3347
|
+
Args:
|
3348
|
+
code: parameter code
|
3349
|
+
param: parameter data
|
3350
|
+
version: HIP protocol version
|
3351
|
+
modes: list of mode ID
|
3352
|
+
mode_default: default mode ID
|
3353
|
+
mode_namespace: mode ID namespace
|
3354
|
+
mode_reversed: reverse mode ID namespace
|
3355
|
+
**kwargs: arbitrary keyword arguments
|
3356
|
+
|
3357
|
+
Returns:
|
3358
|
+
HIP parameter schema.
|
3359
|
+
|
3360
|
+
"""
|
3361
|
+
if param is not None:
|
3362
|
+
mode_id = cast('list[Enum_NATTraversal]', param.mode_id)
|
3363
|
+
else:
|
3364
|
+
if modes is None:
|
3365
|
+
modes = []
|
3366
|
+
|
3367
|
+
mode_id = []
|
3368
|
+
for mode in modes:
|
3369
|
+
mode_id.append(self._make_index(mode, mode_default, namespace=mode_namespace, # type: ignore[arg-type]
|
3370
|
+
reversed=mode_reversed, pack=False))
|
3371
|
+
|
3372
|
+
return Schema_NATTraversalModeParameter(
|
3373
|
+
type=code,
|
3374
|
+
len=2 + 2 * len(mode_id),
|
3375
|
+
modes=mode_id,
|
3376
|
+
)
|
3377
|
+
|
3378
|
+
def _make_param_transaction_pacing(self, code: 'Enum_Parameter', param: 'Optional[Data_TransactionPacingParameter]' = None, *, # pylint: disable=unused-argument
|
3379
|
+
version: 'int',
|
3380
|
+
min_ta: 'int' = 0,
|
3381
|
+
**kwargs: 'Any') -> 'Schema_TransactionPacingParameter':
|
3382
|
+
"""Make HIP ``TRANSACTION_PACING`` parameter.
|
3383
|
+
|
3384
|
+
Args:
|
3385
|
+
code: parameter code
|
3386
|
+
param: parameter data
|
3387
|
+
version: HIP protocol version
|
3388
|
+
min_ta: minimum time between transactions
|
3389
|
+
**kwargs: arbitrary keyword arguments
|
3390
|
+
|
3391
|
+
Returns:
|
3392
|
+
HIP parameter schema.
|
3393
|
+
|
3394
|
+
"""
|
3395
|
+
if param is not None:
|
3396
|
+
min_ta = param.min_ta
|
3397
|
+
|
3398
|
+
return Schema_TransactionPacingParameter(
|
3399
|
+
type=code,
|
3400
|
+
len=4,
|
3401
|
+
min_ta=min_ta,
|
3402
|
+
)
|
3403
|
+
|
3404
|
+
def _make_param_encrypted(self, code: 'Enum_Parameter', param: 'Optional[Data_EncryptedParameter]' = None, *, # pylint: disable=unused-argument
|
3405
|
+
version: 'int',
|
3406
|
+
cipher: 'Enum_Cipher | StdlibEnum | AenumEnum | str | int' = Enum_Cipher.NULL_ENCRYPT,
|
3407
|
+
cipher_default: 'Optional[int]' = None,
|
3408
|
+
cipher_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
3409
|
+
cipher_reversed: 'bool' = False,
|
3410
|
+
iv: 'Optional[bytes]' = None,
|
3411
|
+
data: 'bytes' = b'',
|
3412
|
+
**kwargs: 'Any') -> 'Schema_EncryptedParameter':
|
3413
|
+
"""Make HIP ``ENCRYPTED`` parameter.
|
3414
|
+
|
3415
|
+
Args:
|
3416
|
+
code: parameter code
|
3417
|
+
param: parameter data
|
3418
|
+
version: HIP protocol version
|
3419
|
+
cipher: cipher ID
|
3420
|
+
cipher_default: default cipher ID
|
3421
|
+
cipher_namespace: cipher ID namespace
|
3422
|
+
cipher_reversed: reverse cipher ID namespace
|
3423
|
+
iv: initialization vector (optional depending on cipher ID)
|
3424
|
+
data: encrypted data
|
3425
|
+
|
3426
|
+
Returns:
|
3427
|
+
HIP parameter schema.
|
3428
|
+
|
3429
|
+
"""
|
3430
|
+
if param is not None:
|
3431
|
+
cipher_id = param.cipher
|
3432
|
+
iv = param.iv
|
3433
|
+
data = param.data
|
3434
|
+
else:
|
3435
|
+
cipher_id = self._make_index(cipher, cipher_default, namespace=cipher_namespace, # type: ignore[assignment]
|
3436
|
+
reversed=cipher_reversed, pack=False)
|
3437
|
+
|
3438
|
+
if cipher_id in (Enum_Cipher.AES_128_CBC, Enum_Cipher.AES_256_CBC):
|
3439
|
+
if iv is None:
|
3440
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {code}] IV is required for AES cipher')
|
3441
|
+
if len(iv) != 16:
|
3442
|
+
raise ProtocolError(f'HIPv{version}: [ParamNo {code}] IV length must be 16 bytes for AES cipher')
|
3443
|
+
|
3444
|
+
return Schema_EncryptedParameter(
|
3445
|
+
type=code,
|
3446
|
+
len=4 + len(iv or b'') + len(data),
|
3447
|
+
cipher=cipher_id,
|
3448
|
+
iv=iv,
|
3449
|
+
data=data,
|
3450
|
+
)
|
3451
|
+
|
3452
|
+
def _make_param_host_id(self, code: 'Enum_Parameter', param: 'Optional[Data_HostIDParameter]' = None, *, # pylint: disable=unused-argument
|
3453
|
+
version: 'int',
|
3454
|
+
hi: 'Optional[Data_HostIdentity | bytes | Schema_HostIdentity]' = None,
|
3455
|
+
hi_curve: 'Optional[Enum_ECDSACurve | Enum_ECDSALowCurve | Enum_EdDSACurve]' = None, # pylint: disable=line-too-long
|
3456
|
+
hi_pub_key: 'bytes' = b'',
|
3457
|
+
hi_algorithm: 'Enum_HIAlgorithm | StdlibEnum | AenumEnum | str | int' = Enum_HIAlgorithm.NULL_ENCRYPT,
|
3458
|
+
hi_algorithm_default: 'Optional[int]' = None,
|
3459
|
+
hi_algorithm_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
3460
|
+
hi_algorithm_reversed: 'bool' = False,
|
3461
|
+
di: 'bytes' = b'',
|
3462
|
+
di_type: 'Enum_DITypes | StdlibEnum | AenumEnum | str | int' = Enum_DITypes.none_included,
|
3463
|
+
di_type_default: 'Optional[int]' = None,
|
3464
|
+
di_type_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
3465
|
+
di_type_reversed: 'bool' = False,
|
3466
|
+
**kwargs: 'Any') -> 'Schema_HostIDParameter':
|
3467
|
+
"""Make HIP ``HOST_ID`` parameter.
|
3468
|
+
|
3469
|
+
Args:
|
3470
|
+
code: parameter code
|
3471
|
+
param: parameter data
|
3472
|
+
version: HIP protocol version
|
3473
|
+
hi: host identity
|
3474
|
+
hi_curve: host identity curve
|
3475
|
+
hi_pub_key: host identity public key
|
3476
|
+
hi_algorithm: host identity algorithm
|
3477
|
+
hi_algorithm_default: default host identity algorithm
|
3478
|
+
hi_algorithm_namespace: host identity algorithm namespace
|
3479
|
+
hi_algorithm_reversed: reverse host identity algorithm namespace
|
3480
|
+
di: domain identifier
|
3481
|
+
di_type: domain identifier type
|
3482
|
+
di_type_default: default domain identifier type
|
3483
|
+
di_type_namespace: domain identifier type namespace
|
3484
|
+
di_type_reversed: reverse domain identifier type namespace
|
3485
|
+
**kwargs: arbitrary keyword arguments
|
3486
|
+
|
3487
|
+
Returns:
|
3488
|
+
HIP parameter schema.
|
3489
|
+
|
3490
|
+
"""
|
3491
|
+
if param is not None:
|
3492
|
+
hi = param.hi
|
3493
|
+
di = param.di
|
3494
|
+
hi_len = param.hi_len
|
3495
|
+
di_len = param.di_len
|
3496
|
+
di_enum = param.di_type
|
3497
|
+
algorithm = param.algorithm # type: int | Enum_HIAlgorithm
|
3498
|
+
else:
|
3499
|
+
di_len = len(di)
|
3500
|
+
di_enum = self._make_index(di_type, di_type_default, namespace=di_type_namespace, # type: ignore[assignment]
|
3501
|
+
reversed=di_type_reversed, pack=False)
|
3502
|
+
algorithm = self._make_index(hi_algorithm, hi_algorithm_default, namespace=hi_algorithm_namespace,
|
3503
|
+
reversed=hi_algorithm_reversed, pack=False)
|
3504
|
+
|
3505
|
+
if hi is None:
|
3506
|
+
hi_len = 2 + len(hi_pub_key)
|
3507
|
+
|
3508
|
+
if isinstance(hi_curve, Enum_ECDSACurve):
|
3509
|
+
hi_data = Schema_ECDSACurveHostIdentity(
|
3510
|
+
curve=hi_curve,
|
3511
|
+
pub_key=hi_pub_key,
|
3512
|
+
) # type: Schema_HostIdentity | bytes
|
3513
|
+
algorithm = Enum_HIAlgorithm.ECDSA
|
3514
|
+
elif isinstance(hi_curve, Enum_ECDSALowCurve):
|
3515
|
+
hi_data = Schema_ECDSALowCurveHostIdentity(
|
3516
|
+
curve=hi_curve,
|
3517
|
+
pub_key=hi_pub_key,
|
3518
|
+
)
|
3519
|
+
algorithm = Enum_HIAlgorithm.ECDSA_LOW
|
3520
|
+
elif isinstance(hi_curve, Enum_EdDSACurve):
|
3521
|
+
hi_data = Schema_EdDSACurveHostIdentity(
|
3522
|
+
curve=hi_curve,
|
3523
|
+
pub_key=hi_pub_key,
|
3524
|
+
)
|
3525
|
+
algorithm = Enum_HIAlgorithm.EdDSA
|
3526
|
+
else:
|
3527
|
+
raise ProtocolError(f'[HIPv{version}] invalid curve: {hi_curve!r}')
|
3528
|
+
else:
|
3529
|
+
if isinstance(hi, Data_HostIdentity):
|
3530
|
+
hi_len = 2 + len(hi.pubkey)
|
3531
|
+
if isinstance(hi.curve, Enum_ECDSACurve):
|
3532
|
+
hi_data = Schema_ECDSACurveHostIdentity(
|
3533
|
+
curve=hi.curve,
|
3534
|
+
pub_key=hi.pubkey,
|
3535
|
+
)
|
3536
|
+
algorithm = Enum_HIAlgorithm.ECDSA
|
3537
|
+
elif isinstance(hi.curve, Enum_ECDSALowCurve):
|
3538
|
+
hi_data = Schema_ECDSALowCurveHostIdentity(
|
3539
|
+
curve=hi.curve,
|
3540
|
+
pub_key=hi.pubkey,
|
3541
|
+
)
|
3542
|
+
algorithm = Enum_HIAlgorithm.ECDSA_LOW
|
3543
|
+
elif isinstance(hi.curve, Enum_EdDSACurve):
|
3544
|
+
hi_data = Schema_EdDSACurveHostIdentity(
|
3545
|
+
curve=hi.curve,
|
3546
|
+
pub_key=hi.pubkey,
|
3547
|
+
)
|
3548
|
+
algorithm = Enum_HIAlgorithm.EdDSA
|
3549
|
+
else:
|
3550
|
+
raise ProtocolError(f'[HIPv{version}] invalid curve: {hi.curve!r}')
|
3551
|
+
elif isinstance(hi, Schema_HostIdentity):
|
3552
|
+
hi_len = 2 + len(hi.pub_key)
|
3553
|
+
hi_data = hi
|
3554
|
+
else:
|
3555
|
+
hi_len = len(hi)
|
3556
|
+
hi_data = hi
|
3557
|
+
|
3558
|
+
return Schema_HostIDParameter(
|
3559
|
+
type=code,
|
3560
|
+
len=6 + hi_len + di_len,
|
3561
|
+
hi_len=hi_len,
|
3562
|
+
di_data={
|
3563
|
+
'type': di_enum,
|
3564
|
+
'len': di_len,
|
3565
|
+
},
|
3566
|
+
algorithm=algorithm, # type: ignore[arg-type]
|
3567
|
+
hi=hi_data,
|
3568
|
+
di=di,
|
3569
|
+
)
|
3570
|
+
|
3571
|
+
def _make_param_hit_suite_list(self, code: 'Enum_Parameter', param: 'Optional[Data_HITSuiteListParameter]' = None, *, # pylint: disable=unused-argument
|
3572
|
+
version: 'int',
|
3573
|
+
suites: 'Optional[list[Enum_HITSuite | StdlibEnum | AenumEnum | str | int]]' = None,
|
3574
|
+
suite_default: 'Optional[int]' = None,
|
3575
|
+
suite_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
3576
|
+
suite_reversed: 'bool' = False,
|
3577
|
+
**kwargs: 'Any') -> 'Schema_HITSuiteListParameter':
|
3578
|
+
"""Make HIP ``HIT_SUITE_LIST`` parameter.
|
3579
|
+
|
3580
|
+
Args:
|
3581
|
+
code: parameter code
|
3582
|
+
param: parameter data
|
3583
|
+
version: HIP protocol version
|
3584
|
+
suites: list of suites
|
3585
|
+
suite_default: default suite
|
3586
|
+
suite_namespace: suite namespace
|
3587
|
+
suite_reversed: reverse suite namespace
|
3588
|
+
|
3589
|
+
Returns:
|
3590
|
+
HIP parameter schema.
|
3591
|
+
|
3592
|
+
"""
|
3593
|
+
if param is not None:
|
3594
|
+
suite_id = cast('list[Enum_HITSuite]', param.suite_id)
|
3595
|
+
else:
|
3596
|
+
if suites is None:
|
3597
|
+
suites = []
|
3598
|
+
|
3599
|
+
suite_id = []
|
3600
|
+
for suite in suites:
|
3601
|
+
suite_id.append(self._make_index(suite, suite_default, namespace=suite_namespace, # type: ignore[arg-type]
|
3602
|
+
reversed=suite_reversed, pack=False))
|
3603
|
+
|
3604
|
+
return Schema_HITSuiteListParameter(
|
3605
|
+
type=code,
|
3606
|
+
len=len(suite_id),
|
3607
|
+
suites=suite_id,
|
3608
|
+
)
|
3609
|
+
|
3610
|
+
def _make_param_cert(self, code: 'Enum_Parameter', param: 'Optional[Data_CertParameter]' = None, *, # pylint: disable=unused-argument
|
3611
|
+
version: 'int',
|
3612
|
+
cert_group: 'Enum_Group | StdlibEnum | AenumEnum | str | int' = Enum_Group.NIST_P_256,
|
3613
|
+
cert_group_default: 'Optional[int]' = None,
|
3614
|
+
cert_group_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
3615
|
+
cert_group_reversed: 'bool' = False,
|
3616
|
+
cert_count: 'int' = 0,
|
3617
|
+
cert_id: 'int' = 0,
|
3618
|
+
cert_type: 'Enum_Certificate | StdlibEnum | AenumEnum | str | int' = Enum_Certificate.X_509_v3,
|
3619
|
+
cert_type_default: 'Optional[int]' = None,
|
3620
|
+
cert_type_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
3621
|
+
cert_type_reversed: 'bool' = False,
|
3622
|
+
cert: 'bytes' = b'',
|
3623
|
+
**kwargs: 'Any') -> 'Schema_CertParameter':
|
3624
|
+
"""Make HIP ``CERT`` parameter.
|
3625
|
+
|
3626
|
+
Args:
|
3627
|
+
code: parameter code
|
3628
|
+
param: parameter data
|
3629
|
+
version: HIP protocol version
|
3630
|
+
cert_group: certificate group
|
3631
|
+
cert_group_default: default certificate group
|
3632
|
+
cert_group_namespace: certificate group namespace
|
3633
|
+
cert_group_reversed: reverse certificate group namespace
|
3634
|
+
cert_count: certificate count
|
3635
|
+
cert_id: certificate ID
|
3636
|
+
cert_type: certificate type
|
3637
|
+
cert_type_default: default certificate type
|
3638
|
+
cert_type_namespace: certificate type namespace
|
3639
|
+
cert_type_reversed: reverse certificate type namespace
|
3640
|
+
cert: certificate data
|
3641
|
+
**kwargs: arbitrary keyword arguments
|
3642
|
+
|
3643
|
+
Returns:
|
3644
|
+
HIP parameter schema.
|
3645
|
+
|
3646
|
+
"""
|
3647
|
+
if param is not None:
|
3648
|
+
group = param.cert_group
|
3649
|
+
count = param.cert_count
|
3650
|
+
id = param.cert_id
|
3651
|
+
type = param.cert_type
|
3652
|
+
cert = param.cert
|
3653
|
+
else:
|
3654
|
+
group = self._make_index(cert_group, cert_group_default, namespace=cert_group_namespace, # type: ignore[assignment]
|
3655
|
+
reversed=cert_group_reversed, pack=False)
|
3656
|
+
count = cert_count
|
3657
|
+
id = cert_id
|
3658
|
+
type = self._make_index(cert_type, cert_type_default, namespace=cert_type_namespace, # type: ignore[assignment]
|
3659
|
+
reversed=cert_type_reversed, pack=False)
|
3660
|
+
|
3661
|
+
return Schema_CertParameter(
|
3662
|
+
type=code,
|
3663
|
+
len=4 + len(cert),
|
3664
|
+
cert_group=group,
|
3665
|
+
cert_count=count,
|
3666
|
+
cert_id=id,
|
3667
|
+
cert_type=type,
|
3668
|
+
cert=cert,
|
3669
|
+
)
|
3670
|
+
|
3671
|
+
def _make_param_notification(self, code: 'Enum_Parameter', param: 'Optional[Data_NotificationParameter]' = None, *, # pylint: disable=unused-argument
|
3672
|
+
version: 'int',
|
3673
|
+
msg_type: 'Enum_NotifyMessage | StdlibEnum | AenumEnum | str | int' = Enum_NotifyMessage.I2_ACKNOWLEDGEMENT,
|
3674
|
+
msg_type_default: 'Optional[int]' = None,
|
3675
|
+
msg_type_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
3676
|
+
msg_type_reversed: 'bool' = False,
|
3677
|
+
msg: 'bytes' = b'',
|
3678
|
+
**kwargs: 'Any') -> 'Schema_NotificationParameter':
|
3679
|
+
"""Make HIP ``NOTIFICATION`` parameter.
|
3680
|
+
|
3681
|
+
Args:
|
3682
|
+
code: parameter code
|
3683
|
+
param: parameter data
|
3684
|
+
version: HIP protocol version
|
3685
|
+
msg_type: notification message type
|
3686
|
+
msg_type_default: default notification message type
|
3687
|
+
msg_type_namespace: notification message type namespace
|
3688
|
+
msg_type_reversed: reverse notification message type namespace
|
3689
|
+
msg: notification message
|
3690
|
+
**kwargs: arbitrary keyword arguments
|
3691
|
+
|
3692
|
+
Returns:
|
3693
|
+
HIP parameter schema.
|
3694
|
+
|
3695
|
+
"""
|
3696
|
+
if param is not None:
|
3697
|
+
type = param.msg_type
|
3698
|
+
msg = param.msg
|
3699
|
+
else:
|
3700
|
+
type = self._make_index(msg_type, msg_type_default, namespace=msg_type_namespace, # type: ignore[assignment]
|
3701
|
+
reversed=msg_type_reversed, pack=False)
|
3702
|
+
|
3703
|
+
return Schema_NotificationParameter(
|
3704
|
+
type=code,
|
3705
|
+
len=4 + len(msg),
|
3706
|
+
msg_type=type,
|
3707
|
+
msg=msg,
|
3708
|
+
)
|
3709
|
+
|
3710
|
+
def _make_param_echo_request_signed(self, code: 'Enum_Parameter', param: 'Optional[Data_EchoRequestSignedParameter]' = None, *, # pylint: disable=unused-argument
|
3711
|
+
version: 'int',
|
3712
|
+
opaque: 'bytes' = b'',
|
3713
|
+
**kwargs: 'Any') -> 'Schema_EchoRequestSignedParameter':
|
3714
|
+
"""Make HIP ``ECHO_REQUEST_SIGNED`` parameter.
|
3715
|
+
|
3716
|
+
Args:
|
3717
|
+
code: parameter code
|
3718
|
+
param: parameter data
|
3719
|
+
version: HIP protocol version
|
3720
|
+
opaque: opaque data
|
3721
|
+
**kwargs: arbitrary keyword arguments
|
3722
|
+
|
3723
|
+
Returns:
|
3724
|
+
HIP parameter schema.
|
3725
|
+
|
3726
|
+
"""
|
3727
|
+
if param is not None:
|
3728
|
+
opaque = param.opaque
|
3729
|
+
|
3730
|
+
return Schema_EchoRequestSignedParameter(
|
3731
|
+
type=code,
|
3732
|
+
len=len(opaque),
|
3733
|
+
opaque=opaque,
|
3734
|
+
)
|
3735
|
+
|
3736
|
+
def _make_param_reg_info(self, code: 'Enum_Parameter', param: 'Optional[Data_RegInfoParameter]' = None, *, # pylint: disable=unused-argument
|
3737
|
+
version: 'int',
|
3738
|
+
min_lifetime: 'int | timedelta' = 0,
|
3739
|
+
max_lifetime: 'int | timedelta' = 0xf,
|
3740
|
+
reg_info: 'Optional[list[Enum_Registration | StdlibEnum | AenumEnum | str | int]]' = None,
|
3741
|
+
reg_info_default: 'Optional[int]' = None,
|
3742
|
+
reg_info_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
3743
|
+
reg_info_reversed: 'bool' = False,
|
3744
|
+
**kwargs: 'Any') -> 'Schema_RegInfoParameter':
|
3745
|
+
"""Make HIP ``REG_INFO`` parameter.
|
3746
|
+
|
3747
|
+
Args:
|
3748
|
+
code: parameter code
|
3749
|
+
param: parameter data
|
3750
|
+
version: HIP protocol version
|
3751
|
+
min_lifetime: minimum lifetime
|
3752
|
+
max_lifetime: maximum lifetime
|
3753
|
+
reg_info: registration information list
|
3754
|
+
reg_info_default: default registration information
|
3755
|
+
reg_info_namespace: registration information namespace
|
3756
|
+
reg_info_reversed: reverse registration information namespace
|
3757
|
+
**kwargs: arbitrary keyword arguments
|
3758
|
+
|
3759
|
+
Returns:
|
3760
|
+
HIP parameter schema.
|
3761
|
+
|
3762
|
+
"""
|
3763
|
+
if param is not None:
|
3764
|
+
reg_type = cast('list[Enum_Registration]', param.reg_type)
|
3765
|
+
min_lt = math.floor(param.lifetime.min.total_seconds())
|
3766
|
+
max_lt = math.floor(param.lifetime.max.total_seconds())
|
3767
|
+
else:
|
3768
|
+
if reg_info is None:
|
3769
|
+
reg_info = []
|
3770
|
+
|
3771
|
+
reg_type = []
|
3772
|
+
for reg in reg_info:
|
3773
|
+
reg_type.append(self._make_index(reg, reg_info_default, namespace=reg_info_namespace, # type: ignore[arg-type]
|
3774
|
+
reversed=reg_info_reversed, pack=False))
|
3775
|
+
|
3776
|
+
min_lt = min_lifetime if isinstance(min_lifetime, int) else math.floor(min_lifetime.total_seconds())
|
3777
|
+
max_lt = max_lifetime if isinstance(max_lifetime, int) else math.floor(max_lifetime.total_seconds())
|
3778
|
+
|
3779
|
+
return Schema_RegInfoParameter(
|
3780
|
+
type=code,
|
3781
|
+
len=2 + len(reg_type),
|
3782
|
+
min_lifetime=min_lt,
|
3783
|
+
max_lifetime=max_lt,
|
3784
|
+
reg_info=reg_type,
|
3785
|
+
)
|
3786
|
+
|
3787
|
+
def _make_param_reg_request(self, code: 'Enum_Parameter', param: 'Optional[Data_RegRequestParameter]' = None, *, # pylint: disable=unused-argument
|
3788
|
+
version: 'int',
|
3789
|
+
lifetime: 'int | timedelta' = 0,
|
3790
|
+
reg_request: 'Optional[list[Enum_Registration | StdlibEnum | AenumEnum | str | int]]' = None,
|
3791
|
+
reg_request_default: 'Optional[int]' = None,
|
3792
|
+
reg_request_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
3793
|
+
reg_request_reversed: 'bool' = False,
|
3794
|
+
**kwargs: 'Any') -> 'Schema_RegRequestParameter':
|
3795
|
+
"""Make HIP ``REG_REQUEST`` parameter.
|
3796
|
+
|
3797
|
+
Args:
|
3798
|
+
code: parameter code
|
3799
|
+
param: parameter data
|
3800
|
+
version: HIP protocol version
|
3801
|
+
lifetime: lifetime
|
3802
|
+
reg_request: registration request list
|
3803
|
+
reg_request_default: default registration request
|
3804
|
+
reg_request_namespace: registration request namespace
|
3805
|
+
reg_request_reversed: reverse registration request namespace
|
3806
|
+
**kwargs: arbitrary keyword arguments
|
3807
|
+
|
3808
|
+
Returns:
|
3809
|
+
HIP parameter schema.
|
3810
|
+
|
3811
|
+
"""
|
3812
|
+
if param is not None:
|
3813
|
+
reg_type = cast('list[Enum_Registration]', param.reg_type)
|
3814
|
+
lt = math.floor(param.lifetime.total_seconds())
|
3815
|
+
else:
|
3816
|
+
if reg_request is None:
|
3817
|
+
reg_request = []
|
3818
|
+
|
3819
|
+
reg_type = []
|
3820
|
+
for reg in reg_request:
|
3821
|
+
reg_type.append(self._make_index(reg, reg_request_default, namespace=reg_request_namespace, # type: ignore[arg-type]
|
3822
|
+
reversed=reg_request_reversed, pack=False))
|
3823
|
+
|
3824
|
+
lt = lifetime if isinstance(lifetime, int) else math.floor(lifetime.total_seconds())
|
3825
|
+
|
3826
|
+
return Schema_RegRequestParameter(
|
3827
|
+
type=code,
|
3828
|
+
len=1 + len(reg_type),
|
3829
|
+
lifetime=lt,
|
3830
|
+
reg_request=reg_type,
|
3831
|
+
)
|
3832
|
+
|
3833
|
+
def _make_param_reg_response(self, code: 'Enum_Parameter', param: 'Optional[Data_RegResponseParameter]' = None, *, # pylint: disable=unused-argument
|
3834
|
+
version: 'int',
|
3835
|
+
lifetime: 'int | timedelta' = 0,
|
3836
|
+
reg_response: 'Optional[list[Enum_Registration | StdlibEnum | AenumEnum | str | int]]' = None,
|
3837
|
+
reg_response_default: 'Optional[int]' = None,
|
3838
|
+
reg_response_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
3839
|
+
reg_response_reversed: 'bool' = False,
|
3840
|
+
**kwargs: 'Any') -> 'Schema_RegResponseParameter':
|
3841
|
+
"""Make HIP ``REG_RESPONSE`` parameter.
|
3842
|
+
|
3843
|
+
Args:
|
3844
|
+
code: parameter code
|
3845
|
+
param: parameter data
|
3846
|
+
version: HIP protocol version
|
3847
|
+
|
3848
|
+
Returns:
|
3849
|
+
HIP parameter schema.
|
3850
|
+
|
3851
|
+
"""
|
3852
|
+
if param is not None:
|
3853
|
+
reg_type = cast('list[Enum_Registration]', param.reg_type)
|
3854
|
+
lt = math.floor(param.lifetime.total_seconds())
|
3855
|
+
else:
|
3856
|
+
if reg_response is None:
|
3857
|
+
reg_response = []
|
3858
|
+
|
3859
|
+
reg_type = []
|
3860
|
+
for reg in reg_response:
|
3861
|
+
reg_type.append(self._make_index(reg, reg_response_default, namespace=reg_response_namespace, # type: ignore[arg-type]
|
3862
|
+
reversed=reg_response_reversed, pack=False))
|
3863
|
+
|
3864
|
+
lt = lifetime if isinstance(lifetime, int) else math.floor(lifetime.total_seconds())
|
3865
|
+
|
3866
|
+
return Schema_RegResponseParameter(
|
3867
|
+
type=code,
|
3868
|
+
len=1 + len(reg_type),
|
3869
|
+
lifetime=lt,
|
3870
|
+
reg_response=reg_type,
|
3871
|
+
)
|
3872
|
+
|
3873
|
+
def _make_param_reg_failed(self, code: 'Enum_Parameter', param: 'Optional[Data_RegFailedParameter]' = None, *, # pylint: disable=unused-argument
|
3874
|
+
version: 'int',
|
3875
|
+
lifetime: 'int | timedelta' = 0,
|
3876
|
+
reg_failed: 'Optional[list[Enum_RegistrationFailure | StdlibEnum | AenumEnum | str | int]]' = None,
|
3877
|
+
reg_failed_default: 'Optional[int]' = None,
|
3878
|
+
reg_failed_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
3879
|
+
reg_failed_reversed: 'bool' = False,
|
3880
|
+
**kwargs: 'Any') -> 'Schema_RegFailedParameter':
|
3881
|
+
"""Make HIP ``REG_FAILED`` parameter.
|
3882
|
+
|
3883
|
+
Args:
|
3884
|
+
code: parameter code
|
3885
|
+
param: parameter data
|
3886
|
+
version: HIP protocol version
|
3887
|
+
lifetime: lifetime
|
3888
|
+
reg_failed: registration failure list
|
3889
|
+
reg_failed_default: default registration failure
|
3890
|
+
reg_failed_namespace: registration failure namespace
|
3891
|
+
reg_failed_reversed: reverse registration failure namespace
|
3892
|
+
|
3893
|
+
Returns:
|
3894
|
+
HIP parameter schema.
|
3895
|
+
|
3896
|
+
"""
|
3897
|
+
if param is not None:
|
3898
|
+
reg_type = cast('list[Enum_RegistrationFailure]', param.reg_type)
|
3899
|
+
lt = math.floor(param.lifetime.total_seconds())
|
3900
|
+
else:
|
3901
|
+
if reg_failed is None:
|
3902
|
+
reg_failed = []
|
3903
|
+
|
3904
|
+
reg_type = []
|
3905
|
+
for reg in reg_failed:
|
3906
|
+
reg_type.append(self._make_index(reg, reg_failed_default, namespace=reg_failed_namespace, # type: ignore[arg-type]
|
3907
|
+
reversed=reg_failed_reversed, pack=False))
|
3908
|
+
|
3909
|
+
lt = lifetime if isinstance(lifetime, int) else math.floor(lifetime.total_seconds())
|
3910
|
+
|
3911
|
+
return Schema_RegFailedParameter(
|
3912
|
+
type=code,
|
3913
|
+
len=1 + len(reg_type),
|
3914
|
+
lifetime=lt,
|
3915
|
+
reg_failed=reg_type,
|
3916
|
+
)
|
3917
|
+
|
3918
|
+
def _make_param_reg_from(self, code: 'Enum_Parameter', param: 'Optional[Data_RegFromParameter]' = None, *, # pylint: disable=unused-argument
|
3919
|
+
version: 'int',
|
3920
|
+
port: 'int' = 0,
|
3921
|
+
protocol: 'Enum_TransType | StdlibEnum | AenumEnum | str | int' = Enum_TransType.UDP,
|
3922
|
+
protocol_default: 'Optional[int]' = None,
|
3923
|
+
protocol_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
3924
|
+
protocol_reversed: 'bool' = False,
|
3925
|
+
address: 'IPv6Address | str | int | bytes' = '::',
|
3926
|
+
**kwargs: 'Any') -> 'Schema_RegFromParameter':
|
3927
|
+
"""Make HIP ``REG_FROM`` parameter.
|
3928
|
+
|
3929
|
+
Args:
|
3930
|
+
code: parameter code
|
3931
|
+
param: parameter data
|
3932
|
+
version: HIP protocol version
|
3933
|
+
port: port number
|
3934
|
+
protocol: transport protocol
|
3935
|
+
protocol_default: default transport protocol
|
3936
|
+
protocol_namespace: transport protocol namespace
|
3937
|
+
protocol_reversed: reverse transport protocol namespace
|
3938
|
+
address: IPv6 address
|
3939
|
+
**kwargs: arbitrary keyword arguments
|
3940
|
+
|
3941
|
+
Returns:
|
3942
|
+
HIP parameter schema.
|
3943
|
+
|
3944
|
+
"""
|
3945
|
+
if param is not None:
|
3946
|
+
port = param.port
|
3947
|
+
proto = param.protocol
|
3948
|
+
address = param.address
|
3949
|
+
else:
|
3950
|
+
proto = self._make_index(protocol, protocol_default, namespace=protocol_namespace, # type: ignore[assignment]
|
3951
|
+
reversed=protocol_reversed, pack=False)
|
3952
|
+
|
3953
|
+
return Schema_RegFromParameter(
|
3954
|
+
type=code,
|
3955
|
+
len=20,
|
3956
|
+
port=port,
|
3957
|
+
protocol=proto,
|
3958
|
+
address=address,
|
3959
|
+
)
|
3960
|
+
|
3961
|
+
def _make_param_echo_response_signed(self, code: 'Enum_Parameter', param: 'Optional[Data_EchoResponseSignedParameter]' = None, *, # pylint: disable=unused-argument
|
3962
|
+
version: 'int',
|
3963
|
+
opaque: 'bytes' = b'',
|
3964
|
+
**kwargs: 'Any') -> 'Schema_EchoResponseSignedParameter':
|
3965
|
+
"""Make HIP ``ECHO_RESPONSE_SIGNED`` parameter.
|
3966
|
+
|
3967
|
+
Args:
|
3968
|
+
code: parameter code
|
3969
|
+
param: parameter data
|
3970
|
+
version: HIP protocol version
|
3971
|
+
opaque: opaque data
|
3972
|
+
**kwargs: arbitrary keyword arguments
|
3973
|
+
|
3974
|
+
Returns:
|
3975
|
+
HIP parameter schema.
|
3976
|
+
|
3977
|
+
"""
|
3978
|
+
if param is not None:
|
3979
|
+
opaque = param.opaque
|
3980
|
+
|
3981
|
+
return Schema_EchoResponseSignedParameter(
|
3982
|
+
type=code,
|
3983
|
+
len=len(opaque),
|
3984
|
+
opaque=opaque,
|
3985
|
+
)
|
3986
|
+
|
3987
|
+
def _make_param_transport_format_list(self, code: 'Enum_Parameter', param: 'Optional[Data_TransportFormatListParameter]' = None, *, # pylint: disable=unused-argument
|
3988
|
+
version: 'int',
|
3989
|
+
formats: 'Optional[list[Enum_Parameter | StdlibEnum | AenumEnum | str | int]]' = None,
|
3990
|
+
format_default: 'Optional[int]' = None,
|
3991
|
+
format_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
3992
|
+
format_reversed: 'bool' = False,
|
3993
|
+
**kwargs: 'Any') -> 'Schema_TransportFormatListParameter':
|
3994
|
+
"""Make HIP ``TRANSPORT_FORMAT_LIST`` parameter.
|
3995
|
+
|
3996
|
+
Args:
|
3997
|
+
code: parameter code
|
3998
|
+
param: parameter data
|
3999
|
+
version: HIP protocol version
|
4000
|
+
formats: transport format list
|
4001
|
+
format_default: default transport format
|
4002
|
+
format_namespace: transport format namespace
|
4003
|
+
format_reversed: reverse transport format namespace
|
4004
|
+
**kwargs: arbitrary keyword arguments
|
4005
|
+
|
4006
|
+
Returns:
|
4007
|
+
HIP parameter schema.
|
4008
|
+
|
4009
|
+
"""
|
4010
|
+
if param is not None:
|
4011
|
+
tf_type = cast('list[Enum_Parameter]', param.tf_type)
|
4012
|
+
else:
|
4013
|
+
if formats is None:
|
4014
|
+
formats = []
|
4015
|
+
|
4016
|
+
tf_type = []
|
4017
|
+
for tf in formats:
|
4018
|
+
tf_type.append(self._make_index(tf, format_default, namespace=format_namespace, # type: ignore[arg-type]
|
4019
|
+
reversed=format_reversed, pack=False))
|
4020
|
+
|
4021
|
+
return Schema_TransportFormatListParameter(
|
4022
|
+
type=code,
|
4023
|
+
len=2 * len(tf_type),
|
4024
|
+
formats=tf_type,
|
4025
|
+
)
|
4026
|
+
|
4027
|
+
def _make_param_esp_transform(self, code: 'Enum_Parameter', param: 'Optional[Data_ESPTransformParameter]' = None, *, # pylint: disable=unused-argument
|
4028
|
+
version: 'int',
|
4029
|
+
suites: 'Optional[list[Enum_ESPTransformSuite | StdlibEnum | AenumEnum | str | int]]' = None,
|
4030
|
+
suite_default: 'Optional[int]' = None,
|
4031
|
+
suite_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
4032
|
+
suite_reversed: 'bool' = False,
|
4033
|
+
**kwargs: 'Any') -> 'Schema_ESPTransformParameter':
|
4034
|
+
"""Make HIP ``ESP_TRANSFORM`` parameter.
|
4035
|
+
|
4036
|
+
Args:
|
4037
|
+
code: parameter code
|
4038
|
+
param: parameter data
|
4039
|
+
version: HIP protocol version
|
4040
|
+
suites: ESP transform suite list
|
4041
|
+
suite_default: default ESP transform suite
|
4042
|
+
suite_namespace: ESP transform suite namespace
|
4043
|
+
suite_reversed: reverse ESP transform suite namespace
|
4044
|
+
**kwargs: arbitrary keyword arguments
|
4045
|
+
|
4046
|
+
Returns:
|
4047
|
+
HIP parameter schema.
|
4048
|
+
|
4049
|
+
"""
|
4050
|
+
if param is not None:
|
4051
|
+
suite_id = cast('list[Enum_ESPTransformSuite]', param.suite_id)
|
4052
|
+
else:
|
4053
|
+
if suites is None:
|
4054
|
+
suites = []
|
4055
|
+
|
4056
|
+
suite_id = []
|
4057
|
+
for suite in suites:
|
4058
|
+
suite_id.append(self._make_index(suite, suite_default, namespace=suite_namespace, # type: ignore[arg-type]
|
4059
|
+
reversed=suite_reversed, pack=False))
|
4060
|
+
|
4061
|
+
return Schema_ESPTransformParameter(
|
4062
|
+
type=code,
|
4063
|
+
len=2 + 2 * len(suite_id),
|
4064
|
+
suites=suite_id,
|
4065
|
+
)
|
4066
|
+
|
4067
|
+
def _make_param_seq_data(self, code: 'Enum_Parameter', param: 'Optional[Data_SeqDataParameter]' = None, *, # pylint: disable=unused-argument
|
4068
|
+
version: 'int',
|
4069
|
+
seq: 'int' = 0,
|
4070
|
+
**kwargs: 'Any') -> 'Schema_SeqDataParameter':
|
4071
|
+
"""Make HIP ``SEQ_DATA`` parameter.
|
4072
|
+
|
4073
|
+
Args:
|
4074
|
+
code: parameter code
|
4075
|
+
param: parameter data
|
4076
|
+
version: HIP protocol version
|
4077
|
+
seq: sequence number
|
4078
|
+
**kwargs: arbitrary keyword arguments
|
4079
|
+
|
4080
|
+
Returns:
|
4081
|
+
HIP parameter schema.
|
4082
|
+
|
4083
|
+
"""
|
4084
|
+
if param is not None:
|
4085
|
+
seq = param.seq
|
4086
|
+
|
4087
|
+
return Schema_SeqDataParameter(
|
4088
|
+
type=code,
|
4089
|
+
len=4,
|
4090
|
+
seq=seq,
|
4091
|
+
)
|
4092
|
+
|
4093
|
+
def _make_param_ack_data(self, code: 'Enum_Parameter', param: 'Optional[Data_AckDataParameter]' = None, *, # pylint: disable=unused-argument
|
4094
|
+
version: 'int',
|
4095
|
+
ack: 'Optional[list[int]]' = None,
|
4096
|
+
**kwargs: 'Any') -> 'Schema_AckDataParameter':
|
4097
|
+
"""Make HIP ``ACK_DATA`` parameter.
|
4098
|
+
|
4099
|
+
Args:
|
4100
|
+
code: parameter code
|
4101
|
+
param: parameter data
|
4102
|
+
version: HIP protocol version
|
4103
|
+
ack: ACK list
|
4104
|
+
|
4105
|
+
Returns:
|
4106
|
+
HIP parameter schema.
|
4107
|
+
|
4108
|
+
"""
|
4109
|
+
if param is not None:
|
4110
|
+
ack = cast('list[int]', param.ack)
|
4111
|
+
else:
|
4112
|
+
ack = [] if ack is None else ack
|
4113
|
+
|
4114
|
+
return Schema_AckDataParameter(
|
4115
|
+
type=code,
|
4116
|
+
len=4 * len(ack),
|
4117
|
+
ack=ack,
|
4118
|
+
)
|
4119
|
+
|
4120
|
+
def _make_param_payload_mic(self, code: 'Enum_Parameter', param: 'Optional[Data_PayloadMICParameter]' = None, *, # pylint: disable=unused-argument
|
4121
|
+
version: 'int',
|
4122
|
+
next: 'Enum_TransType | StdlibEnum | AenumEnum | str | int' = Enum_TransType.UDP,
|
4123
|
+
next_default: 'Optional[int]' = None,
|
4124
|
+
next_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
4125
|
+
next_reversed: 'bool' = False,
|
4126
|
+
payload: 'bytes' = b'',
|
4127
|
+
mic: 'bytes' = b'',
|
4128
|
+
**kwargs: 'Any') -> 'Schema_PayloadMICParameter':
|
4129
|
+
"""Make HIP ``PAYLOAD_MIC`` parameter.
|
4130
|
+
|
4131
|
+
Args:
|
4132
|
+
code: parameter code
|
4133
|
+
param: parameter data
|
4134
|
+
version: HIP protocol version
|
4135
|
+
next: next protocol
|
4136
|
+
next_default: default next protocol
|
4137
|
+
next_namespace: next protocol namespace
|
4138
|
+
next_reversed: reverse next protocol namespace
|
4139
|
+
payload: payload data
|
4140
|
+
mic: message integrity code
|
4141
|
+
**kwargs: arbitrary keyword arguments
|
4142
|
+
|
4143
|
+
Returns:
|
4144
|
+
HIP parameter schema.
|
4145
|
+
|
4146
|
+
"""
|
4147
|
+
if param is not None:
|
4148
|
+
protocol = param.next
|
4149
|
+
payload = param.payload
|
4150
|
+
mic = param.mic
|
4151
|
+
else:
|
4152
|
+
protocol = self._make_index(next, next_default, namespace=next_namespace, # type: ignore[assignment]
|
4153
|
+
reversed=next_reversed, pack=False)
|
4154
|
+
|
4155
|
+
return Schema_PayloadMICParameter(
|
4156
|
+
type=code,
|
4157
|
+
len=8 + len(mic),
|
4158
|
+
next=protocol,
|
4159
|
+
payload=payload,
|
4160
|
+
mic=mic,
|
4161
|
+
)
|
4162
|
+
|
4163
|
+
def _make_param_transaction_id(self, code: 'Enum_Parameter', param: 'Optional[Data_TransactionIDParameter]' = None, *, # pylint: disable=unused-argument
|
4164
|
+
version: 'int',
|
4165
|
+
id: 'int' = 0,
|
4166
|
+
**kwargs: 'Any') -> 'Schema_TransactionIDParameter':
|
4167
|
+
"""Make HIP ``TRANSACTION_ID`` parameter.
|
4168
|
+
|
4169
|
+
Args:
|
4170
|
+
code: parameter code
|
4171
|
+
param: parameter data
|
4172
|
+
version: HIP protocol version
|
4173
|
+
id: transaction ID
|
4174
|
+
**kwargs: arbitrary keyword arguments
|
4175
|
+
|
4176
|
+
Returns:
|
4177
|
+
HIP parameter schema.
|
4178
|
+
|
4179
|
+
"""
|
4180
|
+
if param is not None:
|
4181
|
+
id = param.id
|
4182
|
+
|
4183
|
+
return Schema_TransactionIDParameter(
|
4184
|
+
type=code,
|
4185
|
+
len=math.ceil(id.bit_length() / 8),
|
4186
|
+
id=id,
|
4187
|
+
)
|
4188
|
+
|
4189
|
+
def _make_param_overlay_id(self, code: 'Enum_Parameter', param: 'Optional[Data_OverlayIDParameter]' = None, *, # pylint: disable=unused-argument
|
4190
|
+
version: 'int',
|
4191
|
+
id: 'int' = 0,
|
4192
|
+
**kwargs: 'Any') -> 'Schema_OverlayIDParameter':
|
4193
|
+
"""Make HIP ``OVERLAY_ID`` parameter.
|
4194
|
+
|
4195
|
+
Args:
|
4196
|
+
code: parameter code
|
4197
|
+
param: parameter data
|
4198
|
+
version: HIP protocol version
|
4199
|
+
id: overlay ID
|
4200
|
+
**kwargs: arbitrary keyword arguments
|
4201
|
+
|
4202
|
+
Returns:
|
4203
|
+
HIP parameter schema.
|
4204
|
+
|
4205
|
+
"""
|
4206
|
+
if param is not None:
|
4207
|
+
id = param.id
|
4208
|
+
|
4209
|
+
return Schema_OverlayIDParameter(
|
4210
|
+
type=code,
|
4211
|
+
len=math.ceil(id.bit_length() / 8),
|
4212
|
+
id=id,
|
4213
|
+
)
|
4214
|
+
|
4215
|
+
def _make_param_route_dst(self, code: 'Enum_Parameter', param: 'Optional[Data_RouteDstParameter]' = None, *, # pylint: disable=unused-argument
|
4216
|
+
version: 'int',
|
4217
|
+
symmetric: 'bool' = False,
|
4218
|
+
must_follow: 'bool' = False,
|
4219
|
+
hit: 'Optional[list[bytes | str | int | IPv6Address]]' = None,
|
4220
|
+
**kwargs: 'Any') -> 'Schema_RouteDstParameter':
|
4221
|
+
"""Make HIP ``ROUTE_DST`` parameter.
|
4222
|
+
|
4223
|
+
Args:
|
4224
|
+
code: parameter code
|
4225
|
+
param: parameter data
|
4226
|
+
version: HIP protocol version
|
4227
|
+
|
4228
|
+
Returns:
|
4229
|
+
HIP parameter schema.
|
4230
|
+
|
4231
|
+
"""
|
4232
|
+
if param is not None:
|
4233
|
+
symmetric = param.flags.symmetric
|
4234
|
+
must_follow = param.flags.must_follow
|
4235
|
+
hit_list = cast('list[bytes | str | int | IPv6Address]', param.hit)
|
4236
|
+
else:
|
4237
|
+
hit_list = hit if hit is not None else []
|
4238
|
+
|
4239
|
+
return Schema_RouteDstParameter(
|
4240
|
+
type=code,
|
4241
|
+
len=4 + 16 * len(hit_list),
|
4242
|
+
flags={
|
4243
|
+
'symmetric': int(symmetric),
|
4244
|
+
'must_follow': int(must_follow),
|
4245
|
+
},
|
4246
|
+
hit=hit_list,
|
4247
|
+
)
|
4248
|
+
|
4249
|
+
def _make_param_hip_transport_mode(self, code: 'Enum_Parameter', param: 'Optional[Data_HIPTransportModeParameter]' = None, *, # pylint: disable=unused-argument
|
4250
|
+
version: 'int',
|
4251
|
+
port: 'int' = 0,
|
4252
|
+
modes: 'Optional[list[Enum_Transport | StdlibEnum | AenumEnum | str | int]]' = None,
|
4253
|
+
mode_default: 'Optional[int]' = None,
|
4254
|
+
mode_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
4255
|
+
mode_reversed: 'bool' = False,
|
4256
|
+
**kwargs: 'Any') -> 'Schema_HIPTransportModeParameter':
|
4257
|
+
"""Make HIP ``HIP_TRANSPORT_MODE`` parameter.
|
4258
|
+
|
4259
|
+
Args:
|
4260
|
+
code: parameter code
|
4261
|
+
param: parameter data
|
4262
|
+
version: HIP protocol version
|
4263
|
+
port: port number
|
4264
|
+
modes: transport mode list
|
4265
|
+
mode_default: default transport mode
|
4266
|
+
mode_namespace: transport mode namespace
|
4267
|
+
mode_reversed: reverse transport mode namespace
|
4268
|
+
**kwargs: arbitrary keyword arguments
|
4269
|
+
|
4270
|
+
Returns:
|
4271
|
+
HIP parameter schema.
|
4272
|
+
|
4273
|
+
"""
|
4274
|
+
if param is not None:
|
4275
|
+
port = param.port
|
4276
|
+
mode_id = cast('list[Enum_Transport]', param.mode_id)
|
4277
|
+
else:
|
4278
|
+
if modes is None:
|
4279
|
+
modes = []
|
4280
|
+
|
4281
|
+
mode_id = []
|
4282
|
+
for mode in modes:
|
4283
|
+
mode_id.append(self._make_index(mode, mode_default, namespace=mode_namespace, # type: ignore[arg-type]
|
4284
|
+
reversed=mode_reversed, pack=False))
|
4285
|
+
|
4286
|
+
return Schema_HIPTransportModeParameter(
|
4287
|
+
type=code,
|
4288
|
+
len=2 + 2 * len(mode_id),
|
4289
|
+
port=port,
|
4290
|
+
mode=mode_id,
|
4291
|
+
)
|
4292
|
+
|
4293
|
+
def _make_param_hip_mac(self, code: 'Enum_Parameter', param: 'Optional[Data_HIPMACParameter]' = None, *, # pylint: disable=unused-argument
|
4294
|
+
version: 'int',
|
4295
|
+
hmac: 'bytes' = b'',
|
4296
|
+
**kwargs: 'Any') -> 'Schema_HIPMACParameter':
|
4297
|
+
"""Make HIP ``HIP_MAC`` parameter.
|
4298
|
+
|
4299
|
+
Args:
|
4300
|
+
code: parameter code
|
4301
|
+
param: parameter data
|
4302
|
+
version: HIP protocol version
|
4303
|
+
hmac: HMAC value
|
4304
|
+
**kwargs: arbitrary keyword arguments
|
4305
|
+
|
4306
|
+
Returns:
|
4307
|
+
HIP parameter schema.
|
4308
|
+
|
4309
|
+
"""
|
4310
|
+
if param is not None:
|
4311
|
+
hmac = param.hmac
|
4312
|
+
|
4313
|
+
return Schema_HIPMACParameter(
|
4314
|
+
type=code,
|
4315
|
+
len=len(hmac),
|
4316
|
+
hmac=hmac,
|
4317
|
+
)
|
4318
|
+
|
4319
|
+
def _make_param_hip_mac_2(self, code: 'Enum_Parameter', param: 'Optional[Data_HIPMAC2Parameter]' = None, *, # pylint: disable=unused-argument
|
4320
|
+
version: 'int',
|
4321
|
+
hmac: 'bytes' = b'',
|
4322
|
+
**kwargs: 'Any') -> 'Schema_HIPMAC2Parameter':
|
4323
|
+
"""Make HIP ``HIP_MAC_2`` parameter.
|
4324
|
+
|
4325
|
+
Args:
|
4326
|
+
code: parameter code
|
4327
|
+
param: parameter data
|
4328
|
+
version: HIP protocol version
|
4329
|
+
hmac: HMAC value
|
4330
|
+
**kwargs: arbitrary keyword arguments
|
4331
|
+
|
4332
|
+
Returns:
|
4333
|
+
HIP parameter schema.
|
4334
|
+
|
4335
|
+
"""
|
4336
|
+
if param is not None:
|
4337
|
+
hmac = param.hmac
|
4338
|
+
|
4339
|
+
return Schema_HIPMAC2Parameter(
|
4340
|
+
type=code,
|
4341
|
+
len=len(hmac),
|
4342
|
+
hmac=hmac,
|
4343
|
+
)
|
4344
|
+
|
4345
|
+
def _make_param_hip_signature_2(self, code: 'Enum_Parameter', param: 'Optional[Data_HIPSignature2Parameter]' = None, *, # pylint: disable=unused-argument
|
4346
|
+
version: 'int',
|
4347
|
+
algorithm: 'Enum_HIAlgorithm | StdlibEnum | AenumEnum | str | int' = Enum_HIAlgorithm.NULL_ENCRYPT,
|
4348
|
+
algorithm_default: 'Optional[int]' = None,
|
4349
|
+
algorithm_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
4350
|
+
algorithm_reversed: 'bool' = False,
|
4351
|
+
signature: 'bytes' = b'',
|
4352
|
+
**kwargs: 'Any') -> 'Schema_HIPSignature2Parameter':
|
4353
|
+
"""Make HIP ``HIP_SIGNATURE_2`` parameter.
|
4354
|
+
|
4355
|
+
Args:
|
4356
|
+
code: parameter code
|
4357
|
+
param: parameter data
|
4358
|
+
version: HIP protocol version
|
4359
|
+
algorithm: signature algorithm
|
4360
|
+
algorithm_default: default signature algorithm
|
4361
|
+
algorithm_namespace: signature algorithm namespace
|
4362
|
+
algorithm_reversed: reverse signature algorithm namespace
|
4363
|
+
signature: signature value
|
4364
|
+
**kwargs: arbitrary keyword arguments
|
4365
|
+
|
4366
|
+
Returns:
|
4367
|
+
HIP parameter schema.
|
4368
|
+
|
4369
|
+
"""
|
4370
|
+
if param is not None:
|
4371
|
+
algo = param.algorithm
|
4372
|
+
signature = param.signature
|
4373
|
+
else:
|
4374
|
+
algo = self._make_index(algorithm, algorithm_default, namespace=algorithm_namespace, # type: ignore[assignment]
|
4375
|
+
reversed=algorithm_reversed, pack=False)
|
4376
|
+
|
4377
|
+
return Schema_HIPSignature2Parameter(
|
4378
|
+
type=code,
|
4379
|
+
len=2 + len(signature),
|
4380
|
+
algorithm=algo,
|
4381
|
+
signature=signature,
|
4382
|
+
)
|
4383
|
+
|
4384
|
+
def _make_param_hip_signature(self, code: 'Enum_Parameter', param: 'Optional[Data_HIPSignatureParameter]' = None, *, # pylint: disable=unused-argument
|
4385
|
+
version: 'int',
|
4386
|
+
algorithm: 'Enum_HIAlgorithm | StdlibEnum | AenumEnum | str | int' = Enum_HIAlgorithm.NULL_ENCRYPT,
|
4387
|
+
algorithm_default: 'Optional[int]' = None,
|
4388
|
+
algorithm_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
4389
|
+
algorithm_reversed: 'bool' = False,
|
4390
|
+
signature: 'bytes' = b'',
|
4391
|
+
**kwargs: 'Any') -> 'Schema_HIPSignatureParameter':
|
4392
|
+
"""Make HIP ``HIP_SIGNATURE`` parameter.
|
4393
|
+
|
4394
|
+
Args:
|
4395
|
+
code: parameter code
|
4396
|
+
param: parameter data
|
4397
|
+
version: HIP protocol version
|
4398
|
+
algorithm: signature algorithm
|
4399
|
+
algorithm_default: default signature algorithm
|
4400
|
+
algorithm_namespace: signature algorithm namespace
|
4401
|
+
algorithm_reversed: reverse signature algorithm namespace
|
4402
|
+
signature: signature value
|
4403
|
+
**kwargs: arbitrary keyword arguments
|
4404
|
+
|
4405
|
+
Returns:
|
4406
|
+
HIP parameter schema.
|
4407
|
+
|
4408
|
+
"""
|
4409
|
+
if param is not None:
|
4410
|
+
algo = param.algorithm
|
4411
|
+
signature = param.signature
|
4412
|
+
else:
|
4413
|
+
algo = self._make_index(algorithm, algorithm_default, namespace=algorithm_namespace, # type: ignore[assignment]
|
4414
|
+
reversed=algorithm_reversed, pack=False)
|
4415
|
+
|
4416
|
+
return Schema_HIPSignatureParameter(
|
4417
|
+
type=code,
|
4418
|
+
len=2 + len(signature),
|
4419
|
+
algorithm=algo,
|
4420
|
+
signature=signature,
|
4421
|
+
)
|
4422
|
+
|
4423
|
+
def _make_param_echo_request_unsigned(self, code: 'Enum_Parameter', param: 'Optional[Data_EchoRequestUnsignedParameter]' = None, *, # pylint: disable=unused-argument
|
4424
|
+
version: 'int',
|
4425
|
+
opaque: 'bytes' = b'',
|
4426
|
+
**kwargs: 'Any') -> 'Schema_EchoRequestUnsignedParameter':
|
4427
|
+
"""Make HIP ``ECHO_REQUEST_UNSIGNED`` parameter.
|
4428
|
+
|
4429
|
+
Args:
|
4430
|
+
code: parameter code
|
4431
|
+
param: parameter data
|
4432
|
+
version: HIP protocol version
|
4433
|
+
opaque: opaque data
|
4434
|
+
**kwargs: arbitrary keyword arguments
|
4435
|
+
|
4436
|
+
Returns:
|
4437
|
+
HIP parameter schema.
|
4438
|
+
|
4439
|
+
"""
|
4440
|
+
if param is not None:
|
4441
|
+
opaque = param.opaque
|
4442
|
+
|
4443
|
+
return Schema_EchoRequestUnsignedParameter(
|
4444
|
+
type=code,
|
4445
|
+
len=len(opaque),
|
4446
|
+
opaque=opaque,
|
4447
|
+
)
|
4448
|
+
|
4449
|
+
def _make_param_echo_response_unsigned(self, code: 'Enum_Parameter', param: 'Optional[Data_EchoRequestUnsignedParameter]' = None, *, # pylint: disable=unused-argument
|
4450
|
+
version: 'int',
|
4451
|
+
opaque: 'bytes' = b'',
|
4452
|
+
**kwargs: 'Any') -> 'Schema_EchoRequestUnsignedParameter':
|
4453
|
+
"""Make HIP ``ECHO_RESPONSE_UNSIGNED`` parameter.
|
4454
|
+
|
4455
|
+
Args:
|
4456
|
+
code: parameter code
|
4457
|
+
param: parameter data
|
4458
|
+
version: HIP protocol version
|
4459
|
+
|
4460
|
+
Returns:
|
4461
|
+
HIP parameter schema.
|
4462
|
+
|
4463
|
+
"""
|
4464
|
+
if param is not None:
|
4465
|
+
opaque = param.opaque
|
4466
|
+
|
4467
|
+
return Schema_EchoRequestUnsignedParameter(
|
4468
|
+
type=code,
|
4469
|
+
len=len(opaque),
|
4470
|
+
opaque=opaque,
|
4471
|
+
)
|
4472
|
+
|
4473
|
+
def _make_param_relay_from(self, code: 'Enum_Parameter', param: 'Optional[Data_RelayFromParameter]' = None, *, # pylint: disable=unused-argument
|
4474
|
+
version: 'int',
|
4475
|
+
port: 'int' = 0,
|
4476
|
+
protocol: 'Enum_TransType | StdlibEnum | AenumEnum | str | int' = Enum_TransType.UDP,
|
4477
|
+
protocol_default: 'Optional[int]' = None,
|
4478
|
+
protocol_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
4479
|
+
protocol_reversed: 'bool' = False,
|
4480
|
+
address: 'IPv6Address | str | int | bytes' = '::',
|
4481
|
+
**kwargs: 'Any') -> 'Schema_RelayFromParameter':
|
4482
|
+
"""Make HIP ``RELAY_FROM`` parameter.
|
4483
|
+
|
4484
|
+
Args:
|
4485
|
+
code: parameter code
|
4486
|
+
param: parameter data
|
4487
|
+
version: HIP protocol version
|
4488
|
+
port: port number
|
4489
|
+
protocol: transport protocol
|
4490
|
+
protocol_default: default transport protocol
|
4491
|
+
protocol_namespace: transport protocol namespace
|
4492
|
+
protocol_reversed: reverse transport protocol namespace
|
4493
|
+
address: relay address
|
4494
|
+
|
4495
|
+
Returns:
|
4496
|
+
HIP parameter schema.
|
4497
|
+
|
4498
|
+
"""
|
4499
|
+
if param is not None:
|
4500
|
+
port = param.port
|
4501
|
+
proto = param.protocol
|
4502
|
+
address = param.address
|
4503
|
+
else:
|
4504
|
+
proto = self._make_index(protocol, protocol_default, namespace=protocol_namespace, # type: ignore[assignment]
|
4505
|
+
reversed=protocol_reversed, pack=False)
|
4506
|
+
|
4507
|
+
return Schema_RelayFromParameter(
|
4508
|
+
type=code,
|
4509
|
+
len=20,
|
4510
|
+
port=port,
|
4511
|
+
protocol=proto,
|
4512
|
+
address=address,
|
4513
|
+
)
|
4514
|
+
|
4515
|
+
def _make_param_relay_to(self, code: 'Enum_Parameter', param: 'Optional[Data_RelayToParameter]' = None, *, # pylint: disable=unused-argument
|
4516
|
+
version: 'int',
|
4517
|
+
port: 'int' = 0,
|
4518
|
+
protocol: 'Enum_TransType | StdlibEnum | AenumEnum | str | int' = Enum_TransType.UDP,
|
4519
|
+
protocol_default: 'Optional[int]' = None,
|
4520
|
+
protocol_namespace: 'Optional[dict[str, int] | dict[int, str] | Type[StdlibEnum] | Type[AenumEnum]]' = None, # pylint: disable=line-too-long
|
4521
|
+
protocol_reversed: 'bool' = False,
|
4522
|
+
address: 'IPv6Address | str | int | bytes' = '::',
|
4523
|
+
**kwargs: 'Any') -> 'Schema_RelayToParameter':
|
4524
|
+
"""Make HIP ``RELAY_TO`` parameter.
|
4525
|
+
|
4526
|
+
Args:
|
4527
|
+
code: parameter code
|
4528
|
+
param: parameter data
|
4529
|
+
version: HIP protocol version
|
4530
|
+
port: port number
|
4531
|
+
protocol: transport protocol
|
4532
|
+
protocol_default: default transport protocol
|
4533
|
+
protocol_namespace: transport protocol namespace
|
4534
|
+
protocol_reversed: reverse transport protocol namespace
|
4535
|
+
address: relay address
|
4536
|
+
**kwargs: arbitrary keyword arguments
|
4537
|
+
|
4538
|
+
Returns:
|
4539
|
+
HIP parameter schema.
|
4540
|
+
|
4541
|
+
"""
|
4542
|
+
if param is not None:
|
4543
|
+
port = param.port
|
4544
|
+
proto = param.protocol
|
4545
|
+
address = param.address
|
4546
|
+
else:
|
4547
|
+
proto = self._make_index(protocol, protocol_default, namespace=protocol_namespace, # type: ignore[assignment]
|
4548
|
+
reversed=protocol_reversed, pack=False)
|
4549
|
+
|
4550
|
+
return Schema_RelayToParameter(
|
4551
|
+
type=code,
|
4552
|
+
len=20,
|
4553
|
+
port=port,
|
4554
|
+
protocol=proto,
|
4555
|
+
address=address,
|
4556
|
+
)
|
4557
|
+
|
4558
|
+
def _make_param_overlay_ttl(self, code: 'Enum_Parameter', param: 'Optional[Data_OverlayTTLParameter]' = None, *, # pylint: disable=unused-argument
|
4559
|
+
version: 'int',
|
4560
|
+
ttl: 'int | timedelta' = 0,
|
4561
|
+
**kwargs: 'Any') -> 'Schema_OverlayTTLParameter':
|
4562
|
+
"""Make HIP ``OVERLAY_TTL`` parameter.
|
4563
|
+
|
4564
|
+
Args:
|
4565
|
+
code: parameter code
|
4566
|
+
param: parameter data
|
4567
|
+
version: HIP protocol version
|
4568
|
+
ttl: overlay time-to-live (TTL) value
|
4569
|
+
**kwargs: arbitrary keyword arguments
|
4570
|
+
|
4571
|
+
Returns:
|
4572
|
+
HIP parameter schema.
|
4573
|
+
|
4574
|
+
"""
|
4575
|
+
if param is not None:
|
4576
|
+
ttl_val = math.floor(param.ttl.total_seconds())
|
4577
|
+
else:
|
4578
|
+
ttl_val = ttl if isinstance(ttl, int) else math.floor(ttl.total_seconds())
|
4579
|
+
|
4580
|
+
return Schema_OverlayTTLParameter(
|
4581
|
+
type=code,
|
4582
|
+
len=4,
|
4583
|
+
ttl=ttl_val,
|
4584
|
+
)
|
4585
|
+
|
4586
|
+
def _make_param_route_via(self, code: 'Enum_Parameter', param: 'Optional[Data_RouteViaParameter]' = None, *, # pylint: disable=unused-argument
|
4587
|
+
version: 'int',
|
4588
|
+
symmetric: 'bool' = False,
|
4589
|
+
must_follow: 'bool' = False,
|
4590
|
+
hit: 'Optional[list[IPv6Address | bytes | str | int]]' = None,
|
4591
|
+
**kwargs: 'Any') -> 'Schema_RouteViaParameter':
|
4592
|
+
"""Make HIP ``ROUTE_VIA`` parameter.
|
4593
|
+
|
4594
|
+
Args:
|
4595
|
+
code: parameter code
|
4596
|
+
param: parameter data
|
4597
|
+
version: HIP protocol version
|
4598
|
+
symmetric: symmetric flag
|
4599
|
+
must_follow: must-follow flag
|
4600
|
+
hit: list of HITs
|
4601
|
+
|
4602
|
+
Returns:
|
4603
|
+
HIP parameter schema.
|
4604
|
+
|
4605
|
+
"""
|
4606
|
+
if param is not None:
|
4607
|
+
symmetric = param.flags.symmetric
|
4608
|
+
must_follow = param.flags.must_follow
|
4609
|
+
hit_list = cast('list[IPv6Address | bytes | str | int]', param.hit)
|
4610
|
+
else:
|
4611
|
+
hit_list = hit if hit is not None else []
|
4612
|
+
|
4613
|
+
return Schema_RouteViaParameter(
|
4614
|
+
type=code,
|
4615
|
+
len=4 + 16 * len(hit_list),
|
4616
|
+
flags={
|
4617
|
+
'symmetric': int(symmetric),
|
4618
|
+
'must_follow': int(must_follow),
|
4619
|
+
},
|
4620
|
+
hit=hit_list,
|
4621
|
+
)
|
4622
|
+
|
4623
|
+
def _make_param_from(self, code: 'Enum_Parameter', param: 'Optional[Data_FromParameter]' = None, *, # pylint: disable=unused-argument
|
4624
|
+
version: 'int',
|
4625
|
+
address: 'IPv6Address | str | int | bytes' = '::',
|
4626
|
+
**kwargs: 'Any') -> 'Schema_FromParameter':
|
4627
|
+
"""Make HIP ``FROM`` parameter.
|
4628
|
+
|
4629
|
+
Args:
|
4630
|
+
code: parameter code
|
4631
|
+
param: parameter data
|
4632
|
+
version: HIP protocol version
|
4633
|
+
address: relay address
|
4634
|
+
**kwargs: arbitrary keyword arguments
|
4635
|
+
|
4636
|
+
Returns:
|
4637
|
+
HIP parameter schema.
|
4638
|
+
|
4639
|
+
"""
|
4640
|
+
if param is not None:
|
4641
|
+
address = param.address
|
4642
|
+
|
4643
|
+
return Schema_FromParameter(
|
4644
|
+
type=code,
|
4645
|
+
len=16,
|
4646
|
+
address=address,
|
4647
|
+
)
|
4648
|
+
|
4649
|
+
def _make_param_rvs_hmac(self, code: 'Enum_Parameter', param: 'Optional[Data_RVSHMACParameter]' = None, *, # pylint: disable=unused-argument
|
4650
|
+
version: 'int',
|
4651
|
+
hmac: 'bytes' = b'',
|
4652
|
+
**kwargs: 'Any') -> 'Schema_RVSHMACParameter':
|
4653
|
+
"""Make HIP ``RVS_HMAC`` parameter.
|
4654
|
+
|
4655
|
+
Args:
|
4656
|
+
code: parameter code
|
4657
|
+
param: parameter data
|
4658
|
+
version: HIP protocol version
|
4659
|
+
hmac: HMAC value
|
4660
|
+
**kwargs: arbitrary keyword arguments
|
4661
|
+
|
4662
|
+
Returns:
|
4663
|
+
HIP parameter schema.
|
4664
|
+
|
4665
|
+
"""
|
4666
|
+
if param is not None:
|
4667
|
+
hmac = param.hmac
|
4668
|
+
|
4669
|
+
return Schema_RVSHMACParameter(
|
4670
|
+
type=code,
|
4671
|
+
len=len(hmac),
|
4672
|
+
hmac=hmac,
|
4673
|
+
)
|
4674
|
+
|
4675
|
+
def _make_param_via_rvs(self, code: 'Enum_Parameter', param: 'Optional[Data_ViaRVSParameter]' = None, *, # pylint: disable=unused-argument
|
4676
|
+
version: 'int',
|
4677
|
+
address: 'Optional[list[IPv6Address | bytes | str | int]]' = None,
|
4678
|
+
**kwargs: 'Any') -> 'Schema_ViaRVSParameter':
|
4679
|
+
"""Make HIP ``VIA_RVS`` parameter.
|
4680
|
+
|
4681
|
+
Args:
|
4682
|
+
code: parameter code
|
4683
|
+
param: parameter data
|
4684
|
+
version: HIP protocol version
|
4685
|
+
address: list of relay addresses
|
4686
|
+
**kwargs: arbitrary keyword arguments
|
4687
|
+
|
4688
|
+
Returns:
|
4689
|
+
HIP parameter schema.
|
4690
|
+
|
4691
|
+
"""
|
4692
|
+
if param is not None:
|
4693
|
+
addr_list = cast('list[IPv6Address | bytes | str | int]', param.address)
|
4694
|
+
else:
|
4695
|
+
addr_list = address if address is not None else []
|
4696
|
+
|
4697
|
+
return Schema_ViaRVSParameter(
|
4698
|
+
type=code,
|
4699
|
+
len=16 * len(addr_list),
|
4700
|
+
address=addr_list,
|
4701
|
+
)
|
4702
|
+
|
4703
|
+
def _make_param_relay_hmac(self, code: 'Enum_Parameter', param: 'Optional[Data_RelayHMACParameter]' = None, *, # pylint: disable=unused-argument
|
4704
|
+
version: 'int',
|
4705
|
+
hmac: 'bytes' = b'',
|
4706
|
+
**kwargs: 'Any') -> 'Schema_RelayHMACParameter':
|
4707
|
+
"""Make HIP ``RELAY_HMAC`` parameter.
|
4708
|
+
|
4709
|
+
Args:
|
4710
|
+
code: parameter code
|
4711
|
+
param: parameter data
|
4712
|
+
version: HIP protocol version
|
4713
|
+
hmac: HMAC value
|
4714
|
+
**kwargs: arbitrary keyword arguments
|
4715
|
+
|
4716
|
+
Returns:
|
4717
|
+
HIP parameter schema.
|
4718
|
+
|
4719
|
+
"""
|
4720
|
+
if param is not None:
|
4721
|
+
hmac = param.hmac
|
4722
|
+
|
4723
|
+
return Schema_RelayHMACParameter(
|
4724
|
+
type=code,
|
4725
|
+
len=len(hmac),
|
4726
|
+
hmac=hmac,
|
4727
|
+
)
|