10
0
Fork 0
mirror of https://github.com/ZeusWPI/ZNS.git synced 2024-11-22 05:41:11 +01:00

Working state

This commit is contained in:
Xander Bil 2024-05-03 17:46:42 +02:00
parent 0dc43e2d11
commit 77698525d4
No known key found for this signature in database
GPG key ID: EC9706B54A278598
8 changed files with 401 additions and 314 deletions

454
Cargo.lock generated
View file

@ -33,10 +33,64 @@ dependencies = [
] ]
[[package]] [[package]]
name = "bytes" name = "base64"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
[[package]]
name = "base64"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51"
[[package]]
name = "base64ct"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
[[package]]
name = "block-buffer"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b"
dependencies = [
"block-padding",
"byte-tools",
"byteorder",
"generic-array 0.12.4",
]
[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
"generic-array 0.14.7",
]
[[package]]
name = "block-padding"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5"
dependencies = [
"byte-tools",
]
[[package]]
name = "byte-tools"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
[[package]]
name = "byteorder"
version = "1.5.0" version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]] [[package]]
name = "cc" name = "cc"
@ -53,6 +107,69 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "const-oid"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8"
[[package]]
name = "cpufeatures"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504"
dependencies = [
"libc",
]
[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array 0.14.7",
"typenum",
]
[[package]]
name = "curve25519-dalek"
version = "4.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348"
dependencies = [
"cfg-if",
"cpufeatures",
"curve25519-dalek-derive",
"digest 0.10.7",
"fiat-crypto",
"platforms",
"rustc_version",
"subtle",
"zeroize",
]
[[package]]
name = "curve25519-dalek-derive"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "der"
version = "0.7.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0"
dependencies = [
"const-oid",
"zeroize",
]
[[package]] [[package]]
name = "deranged" name = "deranged"
version = "0.3.11" version = "0.3.11"
@ -94,6 +211,25 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "digest"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
dependencies = [
"generic-array 0.12.4",
]
[[package]]
name = "digest"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer 0.10.4",
"crypto-common",
]
[[package]] [[package]]
name = "dotenvy" name = "dotenvy"
version = "0.15.7" version = "0.15.7"
@ -101,51 +237,69 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
[[package]] [[package]]
name = "fnv" name = "ed25519"
version = "1.0.7" version = "2.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53"
[[package]]
name = "form_urlencoded"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456"
dependencies = [ dependencies = [
"percent-encoding", "pkcs8",
"signature",
] ]
[[package]] [[package]]
name = "futures-channel" name = "ed25519-dalek"
version = "0.3.30" version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871"
dependencies = [ dependencies = [
"futures-core", "curve25519-dalek",
"ed25519",
"serde",
"sha2 0.10.8",
"subtle",
"zeroize",
] ]
[[package]] [[package]]
name = "futures-core" name = "fake-simd"
version = "0.3.30" version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
[[package]] [[package]]
name = "futures-task" name = "fiat-crypto"
version = "0.3.30" version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f"
[[package]] [[package]]
name = "futures-util" name = "generic-array"
version = "0.3.30" version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd"
dependencies = [ dependencies = [
"futures-core", "typenum",
"futures-task", ]
"pin-project-lite",
"pin-utils", [[package]]
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"typenum",
"version_check",
]
[[package]]
name = "getrandom"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c"
dependencies = [
"cfg-if",
"libc",
"wasi",
] ]
[[package]] [[package]]
@ -160,87 +314,6 @@ version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
[[package]]
name = "http"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258"
dependencies = [
"bytes",
"fnv",
"itoa",
]
[[package]]
name = "http-body"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643"
dependencies = [
"bytes",
"http",
]
[[package]]
name = "http-body-util"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840"
dependencies = [
"bytes",
"futures-util",
"http",
"http-body",
"pin-project-lite",
]
[[package]]
name = "httparse"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904"
[[package]]
name = "httpdate"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
[[package]]
name = "hyper"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "186548d73ac615b32a73aafe38fb4f56c0d340e110e5a200bcadbaf2e199263a"
dependencies = [
"bytes",
"futures-channel",
"futures-util",
"http",
"http-body",
"httparse",
"httpdate",
"itoa",
"pin-project-lite",
"smallvec",
"tokio",
]
[[package]]
name = "hyper-util"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa"
dependencies = [
"bytes",
"futures-util",
"http",
"http-body",
"hyper",
"pin-project-lite",
"socket2",
"tokio",
]
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "1.0.10" version = "1.0.10"
@ -315,10 +388,10 @@ dependencies = [
] ]
[[package]] [[package]]
name = "percent-encoding" name = "opaque-debug"
version = "2.3.1" version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
@ -327,10 +400,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
[[package]] [[package]]
name = "pin-utils" name = "pkcs8"
version = "0.1.0" version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7"
dependencies = [
"der",
"spki",
]
[[package]] [[package]]
name = "pkg-config" name = "pkg-config"
@ -338,6 +415,12 @@ version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
[[package]]
name = "platforms"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db23d408679286588f4d4644f965003d056e3dd5abcaaa938116871d7ce2fee7"
[[package]] [[package]]
name = "powerfmt" name = "powerfmt"
version = "0.2.0" version = "0.2.0"
@ -362,6 +445,30 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "ring"
version = "0.17.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d"
dependencies = [
"cc",
"cfg-if",
"getrandom",
"libc",
"spin",
"untrusted",
"windows-sys 0.52.0",
]
[[package]] [[package]]
name = "rustc-demangle" name = "rustc-demangle"
version = "0.1.23" version = "0.1.23"
@ -369,10 +476,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
[[package]] [[package]]
name = "ryu" name = "rustc_version"
version = "1.0.17" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
dependencies = [
"semver",
]
[[package]]
name = "semver"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca"
[[package]] [[package]]
name = "serde" name = "serde"
@ -395,21 +511,36 @@ dependencies = [
] ]
[[package]] [[package]]
name = "serde_json" name = "sha2"
version = "1.0.114" version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69"
dependencies = [ dependencies = [
"itoa", "block-buffer 0.7.3",
"ryu", "digest 0.8.1",
"serde", "fake-simd",
"opaque-debug",
] ]
[[package]] [[package]]
name = "smallvec" name = "sha2"
version = "1.13.1" version = "0.10.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
dependencies = [
"cfg-if",
"cpufeatures",
"digest 0.10.7",
]
[[package]]
name = "signature"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"
dependencies = [
"rand_core",
]
[[package]] [[package]]
name = "socket2" name = "socket2"
@ -421,6 +552,39 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "spin"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
[[package]]
name = "spki"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d"
dependencies = [
"base64ct",
"der",
]
[[package]]
name = "sshkeys"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c926cb006a77964474a13a86aa0135ea82c9fd43e6793a1151cc54143db6637c"
dependencies = [
"base64 0.12.3",
"byteorder",
"sha2 0.8.2",
]
[[package]]
name = "subtle"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.49" version = "2.0.49"
@ -490,18 +654,36 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "typenum"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.12" version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "untrusted"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
[[package]] [[package]]
name = "vcpkg" name = "vcpkg"
version = "0.2.15" version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.11.0+wasi-snapshot-preview1" version = "0.11.0+wasi-snapshot-preview1"
@ -640,17 +822,21 @@ version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8"
[[package]]
name = "zeroize"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d"
[[package]] [[package]]
name = "zeusns" name = "zeusns"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"base64 0.22.0",
"diesel", "diesel",
"dotenvy", "dotenvy",
"form_urlencoded", "ed25519-dalek",
"http-body-util", "ring",
"hyper", "sshkeys",
"hyper-util",
"serde",
"serde_json",
"tokio", "tokio",
] ]

View file

@ -7,10 +7,8 @@ edition = "2021"
[dependencies] [dependencies]
diesel = { version = "2.1.4", features = ["sqlite"] } diesel = { version = "2.1.4", features = ["sqlite"] }
dotenvy = "0.15" dotenvy = "0.15"
form_urlencoded = "1.2" tokio = {version = "1.36.0", features = ["macros","rt-multi-thread","net"], default-features = false}
tokio = {version = "1.36.0", features = ["macros","rt-multi-thread"], default-features = false} sshkeys = "0.3.2"
hyper = {version = "1.2.0", features = ["server", "http1"], default-features = false} ring = "0.17.8"
hyper-util = { version = "0.1", features = ["server","http1", "tokio"], default-features = false} base64 = "0.22.0"
http-body-util = "0.1" ed25519-dalek = "2.1.1"
serde_json = {version="^1.0", default-features = false, features=["std"]}
serde = {version="^1.0", features = ["derive"]}

View file

@ -1,120 +0,0 @@
use std::collections::HashMap;
use std::net::SocketAddr;
use http_body_util::{BodyExt, Full};
use hyper::body::{Buf, Bytes};
use hyper::server::conn::http1;
use hyper::service::service_fn;
use hyper::{Method, Request, Response, StatusCode};
use hyper_util::rt::TokioIo;
use serde::Deserialize;
use tokio::net::TcpListener;
use crate::db::models::insert_into_database;
use crate::structs::{Class, RRClass, Type, RR};
type GenericError = Box<dyn std::error::Error + Send + Sync>;
type Result<T> = std::result::Result<T, GenericError>;
type BoxBody = http_body_util::combinators::BoxBody<Bytes, hyper::Error>;
static INTERNAL_SERVER_ERROR: &[u8] = b"Internal Server Error";
static NOTFOUND: &[u8] = b"Not Found";
#[derive(Deserialize)]
struct Record {
name: Vec<String>,
#[serde(rename = "type")]
_type: Type,
ttl: i32,
data: String,
}
async fn create_record(req: Request<hyper::body::Incoming>) -> Result<Response<BoxBody>> {
let whole_body = req.collect().await?.aggregate();
match serde_json::from_reader::<_, Record>(whole_body.reader()) {
Ok(record) => {
let rdata = record
._type
.to_data(&record.data)
.map_err(|e| e.to_string())?;
match insert_into_database(RR {
name: record.name,
_type: record._type,
class: Class::Class(RRClass::IN),
ttl: record.ttl,
rdlength: rdata.len() as u16,
rdata,
})
.await
{
Ok(_) => Ok(Response::builder()
.status(StatusCode::OK)
.body(full("Successfully Created"))?),
Err(e) => {
eprintln!("{}", e.to_string());
Ok(Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(full(INTERNAL_SERVER_ERROR))?)
}
}
}
Err(e) => Ok(Response::builder()
.status(StatusCode::UNPROCESSABLE_ENTITY)
.body(full(e.to_string()))?),
}
}
async fn get_record(req: Request<hyper::body::Incoming>) -> Result<Response<BoxBody>> {
if let Some(q) = req.uri().query() {
let params = form_urlencoded::parse(q.as_bytes())
.into_owned()
.collect::<HashMap<String, String>>();
if let Some(domain) = params.get("domain_name") {
return Ok(Response::builder()
.status(StatusCode::OK)
.body(full(domain.to_owned()))?);
}
}
Ok(Response::builder()
.status(StatusCode::UNPROCESSABLE_ENTITY)
.body(full("Missing domain_name query parameter"))?)
}
async fn routes(req: Request<hyper::body::Incoming>) -> Result<Response<BoxBody>> {
match (req.method(), req.uri().path()) {
(&Method::POST, "/add") => create_record(req).await,
(&Method::GET, "/get") => get_record(req).await,
_ => Ok(Response::builder()
.status(StatusCode::NOT_FOUND)
.body(full(NOTFOUND))
.unwrap()),
}
}
fn full<T: Into<Bytes>>(chunk: T) -> BoxBody {
Full::new(chunk.into())
.map_err(|never| match never {})
.boxed()
}
pub async fn api_listener_loop(
addr: SocketAddr,
) -> Result<Box<dyn std::error::Error + Send + Sync>> {
let listener = TcpListener::bind(addr).await?;
loop {
let (stream, _) = listener.accept().await?;
let io = TokioIo::new(stream);
tokio::task::spawn(async move {
if let Err(err) = http1::Builder::new()
.serve_connection(io, service_fn(routes))
.await
{
println!("Error serving connection: {:?}", err);
}
});
}
}

39
src/auth.rs Normal file
View file

@ -0,0 +1,39 @@
use std::{
fs::{read_to_string, File},
io::{Read, Write},
};
use base64::prelude::*;
use ring::signature::Ed25519KeyPair;
pub fn verify(user: String, signature: &[u8], message: &[u8]) -> bool {
let str = read_to_string("/home/xander/Desktop/dnsclient/dns.pub").unwrap();
let key_split: Vec<&str> = str.split_ascii_whitespace().collect();
let blob = BASE64_STANDARD.decode(key_split[1]).unwrap();
let mut prev = vec![ 0x30, 0x2a, 0x30,0x05, 0x06,0x03,0x2b,0x65, 0x70, 0x03, 0x21, 0x00];
prev.extend_from_slice(&blob.as_slice()[19..]);
let s = prev.as_slice();
println!("{:#?}", &blob.as_slice()[19..]);
let mut file = File::create("foo.txt").unwrap();
file.write_all(s);
let mut pem = File::open("/home/xander/Desktop/dnsclient/cert.der").unwrap();
let mut pem_buf = Vec::<u8>::new();
pem.read_to_end(&mut pem_buf).unwrap();
let key = Ed25519KeyPair::from_pkcs8_maybe_unchecked(&pem_buf).unwrap();
let mut pem = File::open("/home/xander/Desktop/dnsclient/der").unwrap();
let mut pem_buf = Vec::<u8>::new();
pem.read_to_end(&mut pem_buf).unwrap();
// let rng = rand::SystemRandom::new();
// let mut signature = vec![];
// key.sign(&signature::RSA_PKCS1_SHA256, &rng, MESSAGE, &mut signature);
let k = ring::signature::UnparsedPublicKey::new(&ring::signature::ED25519, &blob.as_slice()[19..]);
println!("{:#?}",k.verify(message, signature.as_ref()));
return false;
}

View file

@ -1,22 +1,21 @@
use std::{error::Error, net::SocketAddr}; use std::{error::Error, net::SocketAddr};
use crate::{api::api_listener_loop, resolver::resolver_listener_loop}; use crate::resolver::resolver_listener_loop;
mod api;
mod db; mod db;
mod errors; mod errors;
mod parser; mod parser;
mod resolver; mod resolver;
mod auth;
mod structs; mod structs;
mod utils; mod utils;
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> { async fn main() -> Result<(), Box<dyn Error>> {
let api_addr = SocketAddr::from(([127, 0, 0, 1], 3000));
let resolver_add = SocketAddr::from(([127, 0, 0, 1], 8080)); let resolver_add = SocketAddr::from(([127, 0, 0, 1], 8080));
let (_, _) = tokio::join!( let _ = tokio::join!(
resolver_listener_loop(resolver_add), resolver_listener_loop(resolver_add),
api_listener_loop(api_addr)
); );
Ok(()) Ok(())
} }

View file

@ -3,7 +3,7 @@ use std::{mem::size_of, vec};
use crate::{ use crate::{
errors::ParseError, errors::ParseError,
structs::{ structs::{
Class, Header, KeyRData, LabelString, Message, Opcode, OptRR, Question, RRClass, RRType, Class, Header, KeyRData, LabelString, Message, Opcode, Question, RRClass, RRType,
Type, RR, Type, RR,
}, },
}; };
@ -85,27 +85,6 @@ pub trait FromBytes {
Self: Sized; Self: Sized;
} }
pub fn parse_opt_type(bytes: &[u8]) -> Result<Vec<OptRR>> {
let mut pairs: Vec<OptRR> = vec![];
let mut i: usize = 0;
while i + 4 <= bytes.len() {
let length = u16::from_be_bytes(bytes[i + 2..i + 4].try_into().unwrap());
pairs.push(OptRR {
code: u16::from_be_bytes(bytes[i..i + 2].try_into().unwrap()),
length,
rdata: bytes[i + 4..i + 4 + length as usize]
.try_into()
.map_err(|_| ParseError {
object: String::from("Type::OPT"),
message: String::from("Invalid OPT DATA"),
})?,
});
i += 4 + length as usize;
}
Ok(pairs)
}
impl Type { impl Type {
pub fn to_data(&self, text: &String) -> Result<Vec<u8>> { pub fn to_data(&self, text: &String) -> Result<Vec<u8>> {
match self { match self {
@ -180,34 +159,35 @@ impl FromBytes for Header {
impl FromBytes for LabelString { impl FromBytes for LabelString {
fn from_bytes(bytes: &[u8], i: &mut usize) -> Result<Self> { fn from_bytes(bytes: &[u8], i: &mut usize) -> Result<Self> {
let mut qname = vec![]; let mut out = vec![];
// Parse qname labels // Parse qname labels
while bytes[*i] != 0 while bytes[*i] != 0
&& (bytes[*i] & 0b11000000 == 0) && (bytes[*i] & 0b11000000 == 0)
&& bytes[*i] as usize + *i < bytes.len() && bytes[*i] as usize + *i < bytes.len()
{ {
qname.push( out.push(
String::from_utf8(bytes[*i + 1..bytes[*i] as usize + 1 + *i].to_vec()).unwrap(), String::from_utf8(bytes[*i + 1..bytes[*i] as usize + 1 + *i].to_vec()).unwrap(),
); );
*i += bytes[*i] as usize + 1; *i += bytes[*i] as usize + 1;
} }
if bytes[*i] & 0b11000000 != 0 { if bytes[*i] & 0b11000000 != 0 {
let offset = u16::from_be_bytes(bytes[*i..*i + 2].try_into().unwrap()) & 0b00111111; println!("YOOW");
let offset = u16::from_be_bytes(bytes[*i..*i + 2].try_into().unwrap()) & 0b0011111111111111;
if *i <= offset as usize { if *i <= offset as usize {
return Err(ParseError { return Err(ParseError {
object: String::from("Label"), object: String::from("Label"),
message: String::from("Invalid PTR"), message: String::from("Invalid PTR"),
}); });
} else { } else {
qname.extend(LabelString::from_bytes(bytes, &mut (offset as usize))?); out.extend(LabelString::from_bytes(bytes, &mut (offset as usize))?);
*i += 1; *i += 1;
} }
} }
*i += 1; *i += 1;
Ok(qname) Ok(out)
} }
fn to_bytes(name: Self) -> Vec<u8> { fn to_bytes(name: Self) -> Vec<u8> {
@ -307,7 +287,7 @@ impl FromBytes for RR {
result.extend(u16::to_be_bytes(rr._type.into())); result.extend(u16::to_be_bytes(rr._type.into()));
result.extend(u16::to_be_bytes(rr.class.into())); result.extend(u16::to_be_bytes(rr.class.into()));
result.extend(i32::to_be_bytes(rr.ttl.to_owned())); result.extend(i32::to_be_bytes(rr.ttl.to_owned()));
result.extend(u16::to_be_bytes(4 as u16)); result.extend(u16::to_be_bytes(rr.rdata.len() as u16));
result.extend(rr.rdata); result.extend(rr.rdata);
result result
} }
@ -370,14 +350,14 @@ impl FromBytes for Message {
} }
impl FromBytes for KeyRData { impl FromBytes for KeyRData {
fn from_bytes(bytes: &[u8], _: &mut usize) -> Result<Self> { fn from_bytes(bytes: &[u8], i: &mut usize) -> Result<Self> {
if bytes.len() < 18 { if bytes.len() < 18 {
Err(ParseError { Err(ParseError {
object: String::from("KeyRData"), object: String::from("KeyRData"),
message: String::from("invalid rdata"), message: String::from("invalid rdata"),
}) })
} else { } else {
let mut i = 18; *i = 18;
Ok(KeyRData { Ok(KeyRData {
type_covered: u16::from_be_bytes(bytes[0..2].try_into().unwrap()), type_covered: u16::from_be_bytes(bytes[0..2].try_into().unwrap()),
algo: bytes[2], algo: bytes[2],
@ -386,8 +366,8 @@ impl FromBytes for KeyRData {
signature_expiration: u32::from_be_bytes(bytes[8..12].try_into().unwrap()), signature_expiration: u32::from_be_bytes(bytes[8..12].try_into().unwrap()),
signature_inception: u32::from_be_bytes(bytes[12..16].try_into().unwrap()), signature_inception: u32::from_be_bytes(bytes[12..16].try_into().unwrap()),
key_tag: u16::from_be_bytes(bytes[16..18].try_into().unwrap()), key_tag: u16::from_be_bytes(bytes[16..18].try_into().unwrap()),
signer: LabelString::from_bytes(bytes, &mut i)?, signer: LabelString::from_bytes(bytes, i)?,
signature: bytes[i..bytes.len()].to_vec(), signature: bytes[*i..bytes.len()].to_vec(),
}) })
} }
} }

View file

@ -4,6 +4,7 @@ use std::sync::Arc;
use tokio::net::UdpSocket; use tokio::net::UdpSocket;
use crate::auth::verify;
use crate::db::models::{delete_from_database, get_from_database, insert_into_database}; use crate::db::models::{delete_from_database, get_from_database, insert_into_database};
use crate::errors::ParseError; use crate::errors::ParseError;
use crate::parser::FromBytes; use crate::parser::FromBytes;
@ -69,8 +70,14 @@ async fn handle_update(message: Message) -> Message {
// Check Requestor Permission // Check Requestor Permission
for rr in &message.additional { for rr in &message.additional {
if rr._type == Type::Type(RRType::KEY) { if rr._type == Type::Type(RRType::KEY) {
let key = KeyRData::from_bytes(&rr.rdata, &mut 0).unwrap(); let mut data = message.clone();
println!("{:#?}",key); data.header.arcount -= 1;
data.additional = vec![data.additional[0].clone()];
let mut i = 0;
let key = KeyRData::from_bytes(&rr.rdata, &mut i).unwrap();
let mut bytes = rr.rdata[0..i].to_vec();
bytes.extend(Message::to_bytes(data).to_vec());
let _ = verify(String::from("xander"), &key.signature, &bytes.as_slice());
} }
} }
@ -169,6 +176,8 @@ pub async fn resolver_listener_loop(addr: SocketAddr) -> Result<(), Box<dyn Erro
let socket = socket_shared.clone(); let socket = socket_shared.clone();
tokio::spawn(async move { tokio::spawn(async move {
let response = get_response(&data[..len]).await; let response = get_response(&data[..len]).await;
println!("{:?}",Message::to_bytes(Message::from_bytes(&data[..len], &mut 0).unwrap()));
println!("{:?}",&data[..len]);
let _ = socket let _ = socket
.send_to(Message::to_bytes(response).as_slice(), addr) .send_to(Message::to_bytes(response).as_slice(), addr)
.await; .await;

View file

@ -1,14 +1,11 @@
use serde::Deserialize; #[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, Deserialize, PartialEq)]
pub enum Type { pub enum Type {
Type(RRType), Type(RRType),
Other(u16) Other(u16),
} }
#[repr(u16)] #[repr(u16)]
#[derive(Debug, Clone, Deserialize, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub enum RRType { pub enum RRType {
A = 1, A = 1,
SOA = 6, SOA = 6,
@ -17,11 +14,10 @@ pub enum RRType {
ANY = 255, ANY = 255,
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub enum Class { pub enum Class {
Class(RRClass), Class(RRClass),
Other(u16) Other(u16),
} }
#[repr(u16)] #[repr(u16)]
@ -45,17 +41,17 @@ pub enum RCODE {
YXRRSET = 7, YXRRSET = 7,
NXRRSET = 8, NXRRSET = 8,
NOTAUTH = 9, NOTAUTH = 9,
NOTZONE = 10 NOTZONE = 10,
} }
pub enum Opcode { pub enum Opcode {
QUERY = 0, QUERY = 0,
UPDATE = 5 UPDATE = 5,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Question { pub struct Question {
pub qname: Vec<String>, pub qname: LabelString,
pub qtype: Type, // NOTE: should be QTYPE, right now not really needed pub qtype: Type, // NOTE: should be QTYPE, right now not really needed
pub qclass: Class, //NOTE: should be QCLASS, right now not really needed pub qclass: Class, //NOTE: should be QCLASS, right now not really needed
} }
@ -81,7 +77,7 @@ pub struct Message {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct RR { pub struct RR {
pub name: Vec<String>, pub name: LabelString,
pub _type: Type, pub _type: Type,
pub class: Class, pub class: Class,
pub ttl: i32, pub ttl: i32,
@ -93,7 +89,7 @@ pub struct RR {
pub struct OptRR { pub struct OptRR {
pub code: u16, pub code: u16,
pub length: u16, pub length: u16,
pub rdata: Vec<u8> pub rdata: Vec<u8>,
} }
pub type LabelString = Vec<String>; pub type LabelString = Vec<String>;
@ -108,5 +104,5 @@ pub struct KeyRData {
pub signature_inception: u32, pub signature_inception: u32,
pub key_tag: u16, pub key_tag: u16,
pub signer: LabelString, pub signer: LabelString,
pub signature: Vec<u8> pub signature: Vec<u8>,
} }