Title: Message.toWire(Message.MAXLENGTH) can generate byte[] > Message.MAXLENGTH · Issue #355 · dnsjava/dnsjava · GitHub
Open Graph Title: Message.toWire(Message.MAXLENGTH) can generate byte[] > Message.MAXLENGTH · Issue #355 · dnsjava/dnsjava
X Title: Message.toWire(Message.MAXLENGTH) can generate byte[] > Message.MAXLENGTH · Issue #355 · dnsjava/dnsjava
Description: Hello! So I was investigating a failed update to a BIND nameserver that returned FORMERR. Looking with the debugger, I've noticed that the generated wire format was > 65535 here. After more investigation, I think I identified the issue: ...
Open Graph Description: Hello! So I was investigating a failed update to a BIND nameserver that returned FORMERR. Looking with the debugger, I've noticed that the generated wire format was > 65535 here. After more investi...
X Description: Hello! So I was investigating a failed update to a BIND nameserver that returned FORMERR. Looking with the debugger, I've noticed that the generated wire format was > 65535 here. After more ...
Opengraph URL: https://github.com/dnsjava/dnsjava/issues/355
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Message.toWire(Message.MAXLENGTH) can generate byte[] \u003e Message.MAXLENGTH","articleBody":"Hello!\r\n\r\nSo I was investigating a failed update to a BIND nameserver that returned FORMERR. Looking with the debugger, I've noticed that the generated wire format was \u003e 65535 [here](https://github.com/dnsjava/dnsjava/blob/master/src/main/java/org/xbill/DNS/SimpleResolver.java#L356).\r\n\r\nAfter more investigation, I think I identified the issue: I am using a resolver with tsig with algorithm `HMAC_SHA384`, and the calculation that is made in [TSIG.recordLength()](https://github.com/dnsjava/dnsjava/blob/master/src/main/java/org/xbill/DNS/TSIG.java#L761) is wrong. More specifically, it considers a MAC size of 16 bytes. While this is true for MD5, it doesn't work for other algorithms such as `HMAC_SHA384`, where the hash is greater in length.\r\n\r\nThis is a small repro (in Kotlin) showing the generated message is higher than the allowed DNS message size of 65535:\r\n\r\n```kotlin\r\nimport org.xbill.DNS.DClass\r\nimport org.xbill.DNS.Message\r\nimport org.xbill.DNS.Name\r\nimport org.xbill.DNS.SimpleResolver\r\nimport org.xbill.DNS.TSIG\r\nimport org.xbill.DNS.TXTRecord\r\nimport org.xbill.DNS.Update\r\nimport org.xbill.DNS.io.IoClientFactory\r\nimport org.xbill.DNS.io.TcpIoClient\r\nimport org.xbill.DNS.io.UdpIoClient\r\nimport java.util.concurrent.CompletableFuture\r\n\r\n\r\nfun main() {\r\n val update = Update(Name.fromConstantString(\"zone.example.com.\"))\r\n\r\n repeat(2000) { i -\u003e\r\n val record = TXTRecord(\r\n Name.fromConstantString(\"name-$i.zone.example.com.\"),\r\n DClass.IN,\r\n 900,\r\n \"a\",\r\n )\r\n update.absent(record.name, record.type)\r\n update.add(record)\r\n }\r\n\r\n val resolver = SimpleResolver().apply {\r\n tsigKey = TSIG(TSIG.HMAC_SHA384, \"zone.example.com.\", \"c2VjcmU=\")\r\n ioClientFactory = object : IoClientFactory {\r\n override fun createOrGetTcpClient(): TcpIoClient {\r\n return TcpIoClient { local, remote, query, data, timeout -\u003e\r\n println(\"Sending data of length: ${data.size}\")\r\n println(\"Is data \u003e max message size (${Message.MAXLENGTH})? ${data.size \u003e Message.MAXLENGTH}\")\r\n CompletableFuture.failedFuture(Exception())\r\n }\r\n }\r\n\r\n override fun createOrGetUdpClient(): UdpIoClient {\r\n TODO(\"Not yet implemented\")\r\n }\r\n }\r\n }\r\n\r\n resolver.send(update)\r\n}\r\n``` \r\n\r\nThis outputs:\r\n```\r\nSending data of length: 65544\r\nIs data \u003e max message size (65535)? true\r\n```\r\n\r\nThe FORMERR we got is because the data of 65544 bytes exceeds what can be stored in two bytes so [this computation](https://github.com/dnsjava/dnsjava/blob/master/src/main/java/org/xbill/DNS/NioTcpClient.java#L101,L102) rolls over, so the message gets truncated at a random point and cannot be interpreted by the receiver.\r\n\r\n---\r\n\r\nI believe an easy fix for this would be to either give more slack in the calculation and put the max of all supported algorithms, or put the correct number based on the algorithm used.","author":{"url":"https://github.com/MMauro94","@type":"Person","name":"MMauro94"},"datePublished":"2024-12-05T17:10:56.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/355/dnsjava/issues/355"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b380fbdf-3bc5-9bb6-39ff-bf0a4cc7da32 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A6BC:3DC8AB:124E813:18EEFBE:69700542 |
| html-safe-nonce | 40b0025de9aee46086718065da9a005f13bd95d7a1a1ab031bfd73a69b7b9248 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNkJDOjNEQzhBQjoxMjRFODEzOjE4RUVGQkU6Njk3MDA1NDIiLCJ2aXNpdG9yX2lkIjoiMzYyMDM0MjY1ODQzODc5MjUxNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e9fb2fa5783e5399ed0935984596fd5b2a1e1037a295661855f6e212ee860fc1 |
| hovercard-subject-tag | issue:2720973617 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/dnsjava/dnsjava/355/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e63a3877c517af2e475f39ee750ec0d56c2abeb3f550ea505609f880502bf594/dnsjava/dnsjava/issues/355 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e63a3877c517af2e475f39ee750ec0d56c2abeb3f550ea505609f880502bf594/dnsjava/dnsjava/issues/355 |
| og:image:alt | Hello! So I was investigating a failed update to a BIND nameserver that returned FORMERR. Looking with the debugger, I've noticed that the generated wire format was > 65535 here. After more investi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | MMauro94 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0366807b865cee6776368231232f84d6c8096e6bce43f701a4fb28ea795ec427 |
| turbo-cache-control | no-preview |
| go-import | github.com/dnsjava/dnsjava git https://github.com/dnsjava/dnsjava.git |
| octolytics-dimension-user_id | 6755615 |
| octolytics-dimension-user_login | dnsjava |
| octolytics-dimension-repository_id | 17084567 |
| octolytics-dimension-repository_nwo | dnsjava/dnsjava |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 17084567 |
| octolytics-dimension-repository_network_root_nwo | dnsjava/dnsjava |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 33f356bb2fb58726ccb2f26395bf8ddc9a2d9eaa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width