Split BambuPrinter into BambuGenericPrinter -> BambuV1Printer/BambuV2Printer
Completes the GenericPrinter -> BambuGenericPrinter -> BambuV1/V2 chain this project wanted from the start. BambuGenericPrinter holds the fields and behavior every Bambu printer shares (access code, serial number, CA trust, the TLS test/fetch methods); BambuV1Printer and BambuV2Printer each *have* one (composition) and are now genuinely separate types, ready to carry flavour-specific report-schema fields later. Also threads through a new 'sn' (serial number) field the real MQTT topics will need. Adds real 'fetch the CA automatically' capability, verified against a live TLS server (not just compiled): - BambuGenericPrinter::fetch_certificate() does trust-on-first-connect — connects once with verification disabled, captures the certificate the printer actually presents via native_tls's peer_certificate()/to_der(), and returns it as PEM. Deliberately a method you call once by hand (examples/fetch_bambu_cert.rs), not something connect() falls back to silently, since TOFU trusts whoever's on the network the moment you run it. Verified end-to-end against a local openssl s_server: the fetched PEM's SHA-256 fingerprint exactly matched the server's real certificate. - Verified the other direction too: test_bambu_certs (bundled-CA mode) correctly REJECTS that same test server's cert, since it wasn't signed by the real Bambu CA. Splitting BambuV1Printer/BambuV2Printer into distinct types broke the PrinterHandle::BambuV1(x) | PrinterHandle::BambuV2(x) or-pattern in both examples (or-patterns require every alternative to bind the same type) — fixed by giving each variant its own match arm.
This commit is contained in:
@@ -12,15 +12,23 @@ use continuum_proxy::printer::{GenericPrinter, PrinterHandle};
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let printers = fleet::load(std::path::Path::new("printers.toml"))?;
|
||||
|
||||
// BambuV1Printer and BambuV2Printer are separate types (each *has* a
|
||||
// BambuGenericPrinter rather than being the same struct), so this
|
||||
// needs one arm per variant rather than a single `A(x) | B(x)` pattern.
|
||||
for printer in &printers {
|
||||
if let PrinterHandle::BambuV1(bambu) | PrinterHandle::BambuV2(bambu) = printer {
|
||||
print!("{}: ", bambu.base().name);
|
||||
match bambu.test_tls_handshake() {
|
||||
Ok(()) => println!("OK — certificate verified"),
|
||||
Err(err) => println!("FAILED — {err}"),
|
||||
}
|
||||
match printer {
|
||||
PrinterHandle::BambuV1(bambu) => report(bambu.base().name.as_str(), bambu.test_tls_handshake()),
|
||||
PrinterHandle::BambuV2(bambu) => report(bambu.base().name.as_str(), bambu.test_tls_handshake()),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn report(name: &str, result: anyhow::Result<()>) {
|
||||
match result {
|
||||
Ok(()) => println!("{name}: OK — certificate verified"),
|
||||
Err(err) => println!("{name}: FAILED — {err}"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user