Commit e38ea79776
Verified · cmc
Layout: unified · split
DomainDig.xcodeproj/project.pbxproj +4
| @@ -26,6 +26,7 @@ | ||
| 26 | 26 | A5AF921BC1C2E6E940CC05DC /* SnapshotFixture.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CA789D3607B55E3612E6FFA /* SnapshotFixture.swift */; }; |
| 27 | 27 | C7CA9E02B0DC2708DE7A8563 /* DomainDataPortabilityServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC948A02EC0184228BC4630E /* DomainDataPortabilityServiceTests.swift */; }; |
| 28 | 28 | E959C4D24DAAB3CB80D854B2 /* DiffServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15A25DF2B8BB52589D49986B /* DiffServiceTests.swift */; }; |
| 29 | A1B2C3D40000000000000202 /* InspectionInputTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C3D40000000000000201 /* InspectionInputTests.swift */; }; | |
| 29 | 30 | EA12012CDB4C21ABB4217D86 /* LocalAPIContractTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D85A44C5F315A1644AC9073 /* LocalAPIContractTests.swift */; }; |
| 30 | 31 | /* End PBXBuildFile section */ |
| 31 | 32 | |
| @@ -96,6 +97,7 @@ | ||
| 96 | 97 | 8BDC00010000000000000001 /* DomainDigUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DomainDigUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; |
| 97 | 98 | 8BF9DA842F9B13FB00EF41D5 /* DomainDataPortabilityService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainDataPortabilityService.swift; sourceTree = "<group>"; }; |
| 98 | 99 | A1B2C3D40000000000000101 /* HistoryEntryCodableTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = HistoryEntryCodableTests.swift; sourceTree = "<group>"; }; |
| 100 | A1B2C3D40000000000000201 /* InspectionInputTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = InspectionInputTests.swift; sourceTree = "<group>"; }; | |
| 99 | 101 | A77F7ED29E7C6669F5E61C04 /* DomainDigTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DomainDigTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; |
| 100 | 102 | CC948A02EC0184228BC4630E /* DomainDataPortabilityServiceTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = DomainDataPortabilityServiceTests.swift; sourceTree = "<group>"; }; |
| 101 | 103 | DE8B269A01CC5E593DA3DFC2 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS26.0.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; |
| @@ -233,6 +235,7 @@ | ||
| 233 | 235 | 435AFB3F99D579D3D7B58279 /* DataMigrationServiceTests.swift */, |
| 234 | 236 | 499B99A1866999A38AC475F5 /* AppInfoTests.swift */, |
| 235 | 237 | A1B2C3D40000000000000101 /* HistoryEntryCodableTests.swift */, |
| 238 | A1B2C3D40000000000000201 /* InspectionInputTests.swift */, | |
| 236 | 239 | ); |
| 237 | 240 | path = DomainDigTests; |
| 238 | 241 | sourceTree = "<group>"; |
| @@ -493,6 +496,7 @@ | ||
| 493 | 496 | EA12012CDB4C21ABB4217D86 /* LocalAPIContractTests.swift in Sources */, |
| 494 | 497 | 4F96CEB875EC3501E784CE39 /* DataMigrationServiceTests.swift in Sources */, |
| 495 | 498 | 99024E91EED2275FD80E83A9 /* AppInfoTests.swift in Sources */, |
| 499 | A1B2C3D40000000000000202 /* InspectionInputTests.swift in Sources */, | |
| 496 | 500 | ); |
| 497 | 501 | runOnlyForDeploymentPostprocessing = 0; |
| 498 | 502 | }; |
DomainDig/DomainAvailabilityService.swift +7 −6
| @@ -9,15 +9,16 @@ struct DomainAvailabilityService { | ||
| 9 | 9 | return DomainAvailabilityResult(domain: domain, status: .unknown) |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | if await checkViaRDAP(domain: normalizedDomain) == .registered { | |
| 13 | return DomainAvailabilityResult(domain: normalizedDomain, status: .registered) | |
| 12 | // RDAP is the registry's own record, so it settles both directions. | |
| 13 | if let registryStatus = await checkViaRDAP(domain: normalizedDomain) { | |
| 14 | return DomainAvailabilityResult(domain: normalizedDomain, status: registryStatus) | |
| 14 | 15 | } |
| 15 | 16 | |
| 17 | // Without a registry answer only "registered" is decidable: a name that | |
| 18 | // resolves is registered. Absence of records is not evidence of | |
| 19 | // availability, because the DoH layer drops the response code, so | |
| 20 | // NXDOMAIN and a resolver failure arrive here identically. | |
| 16 | 21 | let fallbackStatus = await checkViaDNSFallback(domain: normalizedDomain) |
| 17 | if fallbackStatus == .registered { | |
| 18 | return DomainAvailabilityResult(domain: normalizedDomain, status: .unknown) | |
| 19 | } | |
| 20 | ||
| 21 | 22 | return DomainAvailabilityResult(domain: normalizedDomain, status: fallbackStatus) |
| 22 | 23 | } |
| 23 | 24 | |
DomainDig/RDAPService.swift +47 −16
| @@ -1,20 +1,34 @@ | ||
| 1 | 1 | import Foundation |
| 2 | 2 | |
| 3 | 3 | enum RDAPService { |
| 4 | /// The registry's answer about `domain`, or nil when the registry did not | |
| 5 | /// give one. | |
| 4 | 6 | static func registrationStatus(for domain: String) async -> DomainAvailabilityStatus? { |
| 5 | 7 | let normalizedDomain = normalize(domain) |
| 6 | 8 | guard !normalizedDomain.isEmpty else { return nil } |
| 7 | 9 | |
| 8 | 10 | switch await fetchRDAPResponse(for: normalizedDomain) { |
| 9 | case let .success(response): | |
| 10 | return response.isDomainRecord ? .registered : nil | |
| 11 | case .empty: | |
| 12 | return nil | |
| 13 | case .error: | |
| 11 | case .found: | |
| 12 | return .registered | |
| 13 | case .notRegistered: | |
| 14 | return .available | |
| 15 | case .empty, .failed: | |
| 14 | 16 | return nil |
| 15 | 17 | } |
| 16 | 18 | } |
| 17 | 19 | |
| 20 | /// Whether an RDAP response came from a registry's own server rather than | |
| 21 | /// from the `rdap.org` bootstrap redirector. | |
| 22 | /// | |
| 23 | /// `rdap.org` answers 404 both for a domain its registry does not hold and | |
| 24 | /// for a TLD it knows no RDAP server for; only the first says anything about | |
| 25 | /// registration. `URLSession` follows the bootstrap redirect, so a response | |
| 26 | /// URL on another host is the registry's own answer. | |
| 27 | static func answeredByRegistry(responseURL: URL?) -> Bool { | |
| 28 | guard let host = responseURL?.host?.lowercased() else { return false } | |
| 29 | return host != bootstrapHost && !host.hasSuffix(".\(bootstrapHost)") | |
| 30 | } | |
| 31 | ||
| 18 | 32 | static func ownership(for domain: String) async -> ServiceResult<DomainOwnership> { |
| 19 | 33 | let normalizedDomain = normalize(domain) |
| 20 | 34 | guard !normalizedDomain.isEmpty else { |
| @@ -22,7 +36,7 @@ enum RDAPService { | ||
| 22 | 36 | } |
| 23 | 37 | |
| 24 | 38 | switch await fetchRDAPResponse(for: normalizedDomain) { |
| 25 | case let .success(response): | |
| 39 | case let .found(response): | |
| 26 | 40 | let ownership = DomainOwnership( |
| 27 | 41 | registrar: response.registrarName, |
| 28 | 42 | registrant: response.registrantName, |
| @@ -33,9 +47,11 @@ enum RDAPService { | ||
| 33 | 47 | abuseEmail: response.abuseEmail |
| 34 | 48 | ) |
| 35 | 49 | return .success(ownership) |
| 50 | case .notRegistered: | |
| 51 | return .empty("Unavailable") | |
| 36 | 52 | case let .empty(message): |
| 37 | 53 | return .empty(message) |
| 38 | case let .error(message): | |
| 54 | case let .failed(message): | |
| 39 | 55 | return .error(message) |
| 40 | 56 | } |
| 41 | 57 | } |
| @@ -47,10 +63,24 @@ enum RDAPService { | ||
| 47 | 63 | } |
| 48 | 64 | } |
| 49 | 65 | |
| 50 | private func fetchRDAPResponse(for domain: String) async -> ServiceResult<RDAPDomainResponse> { | |
| 66 | private let bootstrapHost = "rdap.org" | |
| 67 | ||
| 68 | /// What a single RDAP fetch established. | |
| 69 | private enum RDAPFetchOutcome { | |
| 70 | /// A domain record, from whichever server answered. | |
| 71 | case found(RDAPDomainResponse) | |
| 72 | /// The registry's own RDAP server reported no such domain. | |
| 73 | case notRegistered | |
| 74 | /// An answer that settles nothing: a non-domain record, or a 404 from the | |
| 75 | /// bootstrap redirector rather than from a registry. | |
| 76 | case empty(String) | |
| 77 | case failed(String) | |
| 78 | } | |
| 79 | ||
| 80 | private func fetchRDAPResponse(for domain: String) async -> RDAPFetchOutcome { | |
| 51 | 81 | let startedAt = DomainDebugLog.signpostStart("RDAP.fetch", domain: domain) |
| 52 | guard let url = URL(string: "https://rdap.org/domain/\(domain)") else { | |
| 53 | return .error("Unavailable") | |
| 82 | guard let url = URL(string: "https://\(bootstrapHost)/domain/\(domain)") else { | |
| 83 | return .failed("Unavailable") | |
| 54 | 84 | } |
| 55 | 85 | |
| 56 | 86 | do { |
| @@ -61,7 +91,7 @@ private func fetchRDAPResponse(for domain: String) async -> ServiceResult<RDAPDo | ||
| 61 | 91 | let (data, response) = try await URLSession.shared.data(for: request) |
| 62 | 92 | guard let httpResponse = response as? HTTPURLResponse else { |
| 63 | 93 | DomainDebugLog.error("RDAP.badResponse domain=\(domain) response=nil") |
| 64 | return .error(URLError(.badServerResponse).localizedDescription) | |
| 94 | return .failed(URLError(.badServerResponse).localizedDescription) | |
| 65 | 95 | } |
| 66 | 96 | |
| 67 | 97 | switch httpResponse.statusCode { |
| @@ -73,19 +103,20 @@ private func fetchRDAPResponse(for domain: String) async -> ServiceResult<RDAPDo | ||
| 73 | 103 | return .empty("Unavailable") |
| 74 | 104 | } |
| 75 | 105 | DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "status=200 bytes=\(data.count)") |
| 76 | return .success(rdapResponse) | |
| 106 | return .found(rdapResponse) | |
| 77 | 107 | case 404: |
| 78 | DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "status=404") | |
| 79 | return .empty("Unavailable") | |
| 108 | let fromRegistry = RDAPService.answeredByRegistry(responseURL: httpResponse.url) | |
| 109 | DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "status=404 registry=\(fromRegistry)") | |
| 110 | return fromRegistry ? .notRegistered : .empty("Unavailable") | |
| 80 | 111 | default: |
| 81 | 112 | DomainDebugLog.error("RDAP.httpError domain=\(domain) status=\(httpResponse.statusCode)") |
| 82 | 113 | DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "status=\(httpResponse.statusCode)") |
| 83 | return .error("Unavailable") | |
| 114 | return .failed("Unavailable") | |
| 84 | 115 | } |
| 85 | 116 | } catch { |
| 86 | 117 | DomainDebugLog.error("RDAP.error domain=\(domain) error=\(error.localizedDescription)") |
| 87 | 118 | DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "error") |
| 88 | return .error(error.localizedDescription) | |
| 119 | return .failed(error.localizedDescription) | |
| 89 | 120 | } |
| 90 | 121 | } |
| 91 | 122 | |
DomainDigTests/InspectionInputTests.swift added +38
| @@ -0,0 +1,38 @@ | ||
| 1 | import XCTest | |
| 2 | @testable import DomainDig | |
| 3 | ||
| 4 | /// `rdap.org` answers 404 both for a domain its registry does not hold and for a | |
| 5 | /// TLD it knows no RDAP server for. Only the first means "available", so the | |
| 6 | /// availability check turns on which server answered. | |
| 7 | final class RDAPRegistryOriginTests: XCTestCase { | |
| 8 | ||
| 9 | func testRegistryResponseCountsAsAnAnswer() { | |
| 10 | let url = URL(string: "https://rdap.verisign.com/com/v1/domain/example.com") | |
| 11 | XCTAssertTrue(RDAPService.answeredByRegistry(responseURL: url)) | |
| 12 | } | |
| 13 | ||
| 14 | func testBootstrapResponseDoesNotCountAsAnAnswer() { | |
| 15 | let url = URL(string: "https://rdap.org/domain/example.invalidtld") | |
| 16 | XCTAssertFalse(RDAPService.answeredByRegistry(responseURL: url)) | |
| 17 | } | |
| 18 | ||
| 19 | func testBootstrapSubdomainDoesNotCountAsAnAnswer() { | |
| 20 | let url = URL(string: "https://www.rdap.org/domain/example.invalidtld") | |
| 21 | XCTAssertFalse(RDAPService.answeredByRegistry(responseURL: url)) | |
| 22 | } | |
| 23 | ||
| 24 | func testHostMatchIsCaseInsensitive() { | |
| 25 | let url = URL(string: "https://RDAP.ORG/domain/example.com") | |
| 26 | XCTAssertFalse(RDAPService.answeredByRegistry(responseURL: url)) | |
| 27 | } | |
| 28 | ||
| 29 | func testMissingResponseURLDoesNotCountAsAnAnswer() { | |
| 30 | XCTAssertFalse(RDAPService.answeredByRegistry(responseURL: nil)) | |
| 31 | } | |
| 32 | ||
| 33 | /// A host that merely ends in the bootstrap name is a different domain. | |
| 34 | func testLookalikeHostCountsAsAnAnswer() { | |
| 35 | let url = URL(string: "https://notrdap.org/domain/example.com") | |
| 36 | XCTAssertTrue(RDAPService.answeredByRegistry(responseURL: url)) | |
| 37 | } | |
| 38 | } | |