Module micro

Module micro 

Source
Expand description

Microdescriptor parsing for Tor relay microdescriptors.

Microdescriptors are compact relay descriptors used by Tor clients to reduce bandwidth usage. They contain a subset of server descriptor information and are referenced by their SHA-256 digest.

§Overview

Microdescriptors were introduced to reduce the bandwidth required for clients to learn about the Tor network. Instead of downloading full server descriptors, clients download:

  1. A consensus document containing microdescriptor hashes
  2. The microdescriptors themselves (much smaller than server descriptors)

Microdescriptors contain only the information clients need for circuit building:

  • Onion keys: For circuit creation handshakes
  • Exit policy summary: Compact representation of allowed ports
  • Protocol versions: Supported protocol versions
  • Family: Related relays

§Descriptor Format

Microdescriptors use a compact text format:

onion-key
-----BEGIN RSA PUBLIC KEY-----
<base64 encoded key>
-----END RSA PUBLIC KEY-----
ntor-onion-key <base64 curve25519 key>
a [<ipv6>]:<port>
family <fingerprint> <fingerprint> ...
p accept|reject <port-list>
p6 accept|reject <port-list>
pr <protocol>=<versions> ...
id <type> <digest>

§Annotations

Microdescriptors from CollecTor archives may include annotations (lines starting with @) that provide metadata like when the descriptor was last seen:

@last-listed 2023-01-01 00:00:00
onion-key
...

§Example

use stem_rs::descriptor::{Microdescriptor, Descriptor, DigestHash, DigestEncoding};

let content = r#"onion-key
-----BEGIN RSA PUBLIC KEY-----
MIGJAoGBAMhPQtZPaxP3ukybV5LfofKQr20/ljpRk0e9IlGWWMSTkfVvBcHsa6IM
H2KE6s4uuPHp7FqhakXAzJbODobnPHY8l1E4efyrqMQZXEQk2IMhgSNtG6YqUrVF
CxdSKSSy0mmcBe2TOyQsahlGZ9Pudxfnrey7KcfqnArEOqNH09RpAgMBAAE=
-----END RSA PUBLIC KEY-----
ntor-onion-key r5572HzD+PMPBbXlZwBhsm6YEbxnYgis8vhZ1jmdI2k=
p accept 80,443
"#;

let desc = Microdescriptor::parse(content).unwrap();
println!("Has ntor key: {}", desc.ntor_onion_key.is_some());
println!("Exit policy: {}", desc.exit_policy);

// Compute SHA-256 digest (used for identification)
let digest = desc.digest(DigestHash::Sha256, DigestEncoding::Base64).unwrap();
println!("Digest: {}", digest);

§Digest Computation

Unlike server descriptors which use SHA-1, microdescriptors are identified by their SHA-256 digest. The digest is computed over the entire microdescriptor content (excluding annotations).

§See Also

Structs§

Microdescriptor
A microdescriptor containing compact relay information for clients.