]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Skip the implicit trailing `.` in `HumanReadableName`'s domain
authorMatt Corallo <git@bluematt.me>
Tue, 1 Oct 2024 18:06:19 +0000 (18:06 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 8 Oct 2024 19:47:54 +0000 (19:47 +0000)
Domain names implicitly have a trailing `.`, which we require in
bLIP 32 but generally shouldn't be exposing to the user in
`HumanReadableName`s (after all, they're human-readable). Here we
make sure the trailing `.` is dropped in `HumanReadableName`s
before we re-add them when building the bLIP 32 messages.

lightning/src/onion_message/dns_resolution.rs

index af133aa7ab43ea86849d5d249ab1e533fabf2277..aaf809071e4ca3074c4024ffe749eb141e0a5311 100644 (file)
@@ -189,7 +189,12 @@ pub struct HumanReadableName {
 impl HumanReadableName {
        /// Constructs a new [`HumanReadableName`] from the `user` and `domain` parts. See the
        /// struct-level documentation for more on the requirements on each.
-       pub fn new(user: String, domain: String) -> Result<HumanReadableName, ()> {
+       pub fn new(user: String, mut domain: String) -> Result<HumanReadableName, ()> {
+               // First normalize domain and remove the optional trailing `.`
+               if domain.ends_with(".") {
+                       domain.pop();
+               }
+               // Note that `REQUIRED_EXTRA_LEN` includes the (now implicit) trailing `.`
                const REQUIRED_EXTRA_LEN: usize = ".user._bitcoin-payment.".len() + 1;
                if user.len() + domain.len() + REQUIRED_EXTRA_LEN > 255 {
                        return Err(());