tools
encode_string(origstr)
Encode a string to bytes, ensuring it is UTF-8 encoded.
Source code in pyrad2/tools.py
encode_octets(octetstring)
Encode raw octet string (already in bytes).
Source code in pyrad2/tools.py
encode_address(addr)
Encode an IPv4 address (dotted string) to 4-byte format.
encode_ipv6_prefix(addr, default_prefixlen=128)
Encode an IPv6 address and prefix length to 18-byte format.
Source code in pyrad2/tools.py
encode_ipv6_address(addr)
Encode an IPv6 address (as string) to 16-byte format.
Source code in pyrad2/tools.py
encode_ifid(value)
Encode an 8-byte Interface-Id (RFC 3162) from xxxx:xxxx:xxxx:xxxx form.
Bytes already of length 8 are passed through unchanged so that dictionary VALUE entries — which arrive pre-encoded — round-trip cleanly.
Source code in pyrad2/tools.py
decode_ifid(value)
Decode 8-byte Interface-Id (RFC 3162) into xxxx:xxxx:xxxx:xxxx form.
Source code in pyrad2/tools.py
encode_ether(value)
Encode a 6-byte Ethernet MAC address from hh:hh:hh:hh:hh:hh form.
Accepts both colon and hyphen separators. Bytes of length 6 pass through.
Source code in pyrad2/tools.py
decode_ether(value)
Decode a 6-byte Ethernet MAC address into hh:hh:hh:hh:hh:hh form.
encode_ascend_binary(orig_str)
Encode binary data in Ascend-specific format (length prefixed).
Source code in pyrad2/tools.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
encode_integer(num, format='!I')
Encode a 32-bit unsigned integer to 4-byte big-endian.
Source code in pyrad2/tools.py
encode_integer64(num, format='!Q')
Encode a 64-bit unsigned integer to 8-byte big-endian.
Source code in pyrad2/tools.py
encode_date(num)
Encode a UNIX timestamp (int) to 4-byte format.
decode_string(orig_str)
Decode UTF-8 bytes into a string.
decode_octets(orig_bytes)
decode_address(addr)
decode_ipv6_prefix(addr)
Decode 18-byte IPv6 prefix format into address/prefix tuple.
Source code in pyrad2/tools.py
decode_ipv6_address(addr)
Decode 16-byte IPv6 address into a readable string.
Source code in pyrad2/tools.py
decode_ascend_binary(orig_bytes)
decode_integer(num, format='!I')
decode_integer64(num, format='!Q')
decode_date(num)
encode_attr(datatype, value)
Encode a RADIUS attribute (type, value, length) into bytes.
Source code in pyrad2/tools.py
decode_attr(datatype, value)
Decode a RADIUS attribute from bytes into a type and value.
Source code in pyrad2/tools.py
get_cert_fingerprint(cert)
Generate SHA-256 fingerprint from a certificate.
Source code in pyrad2/tools.py
normalize_cert_fingerprint(fingerprint)
Normalize a SHA-256 certificate fingerprint for comparison.
Accepts plain hex, colon-separated hex, and values prefixed with
sha256:. Raises ValueError when the normalized value is not a 64
character hexadecimal SHA-256 fingerprint.
Source code in pyrad2/tools.py
cert_fingerprint_matches(cert, allowed_fingerprints)
Return True when a DER certificate's SHA-256 fingerprint is allowed.
read_radius_packet(reader)
async
Read a full RADIUS packet from the stream.
There's no built-in framing in RadSec, so we can't read a fixed-size packet. Instead, we read the header first to determine the length of the packet, and then read the rest of the packet based on that length.
RADIUS packets are prefixed with a 4-byte header
- Code (1 byte)
- Identifier (1 byte)
- Length (2 bytes)
The length includes the header, so the minimum length is 20 bytes (4-byte header + 16-byte Authenticator). If the length is less than 20, it is considered invalid.
:param reader: asyncio StreamReader to read from :return: Full RADIUS packet as bytes