Commit e38ea79776
Verified · cmc
Layout: unified · split
DomainDig.xcodeproj/project.pbxproj +4
| @@ -26,6 +26,7 @@ | |||
| 26 | A5AF921BC1C2E6E940CC05DC /* SnapshotFixture.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CA789D3607B55E3612E6FFA /* SnapshotFixture.swift */; }; | 26 | A5AF921BC1C2E6E940CC05DC /* SnapshotFixture.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CA789D3607B55E3612E6FFA /* SnapshotFixture.swift */; }; |
| 27 | C7CA9E02B0DC2708DE7A8563 /* DomainDataPortabilityServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC948A02EC0184228BC4630E /* DomainDataPortabilityServiceTests.swift */; }; | 27 | C7CA9E02B0DC2708DE7A8563 /* DomainDataPortabilityServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC948A02EC0184228BC4630E /* DomainDataPortabilityServiceTests.swift */; }; |
| 28 | E959C4D24DAAB3CB80D854B2 /* DiffServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15A25DF2B8BB52589D49986B /* DiffServiceTests.swift */; }; | 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 | EA12012CDB4C21ABB4217D86 /* LocalAPIContractTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D85A44C5F315A1644AC9073 /* LocalAPIContractTests.swift */; }; | 30 | EA12012CDB4C21ABB4217D86 /* LocalAPIContractTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D85A44C5F315A1644AC9073 /* LocalAPIContractTests.swift */; }; |
| 30 | /* End PBXBuildFile section */ | 31 | /* End PBXBuildFile section */ |
| 31 | 32 | ||
| @@ -96,6 +97,7 @@ | |||
| 96 | 8BDC00010000000000000001 /* DomainDigUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DomainDigUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; | 97 | 8BDC00010000000000000001 /* DomainDigUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DomainDigUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; |
| 97 | 8BF9DA842F9B13FB00EF41D5 /* DomainDataPortabilityService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainDataPortabilityService.swift; sourceTree = "<group>"; }; | 98 | 8BF9DA842F9B13FB00EF41D5 /* DomainDataPortabilityService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainDataPortabilityService.swift; sourceTree = "<group>"; }; |
| 98 | A1B2C3D40000000000000101 /* HistoryEntryCodableTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = HistoryEntryCodableTests.swift; sourceTree = "<group>"; }; | 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 | A77F7ED29E7C6669F5E61C04 /* DomainDigTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DomainDigTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; | 101 | A77F7ED29E7C6669F5E61C04 /* DomainDigTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DomainDigTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; |
| 100 | CC948A02EC0184228BC4630E /* DomainDataPortabilityServiceTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = DomainDataPortabilityServiceTests.swift; sourceTree = "<group>"; }; | 102 | CC948A02EC0184228BC4630E /* DomainDataPortabilityServiceTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = DomainDataPortabilityServiceTests.swift; sourceTree = "<group>"; }; |
| 101 | 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; }; | 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 | 435AFB3F99D579D3D7B58279 /* DataMigrationServiceTests.swift */, | 235 | 435AFB3F99D579D3D7B58279 /* DataMigrationServiceTests.swift */, |
| 234 | 499B99A1866999A38AC475F5 /* AppInfoTests.swift */, | 236 | 499B99A1866999A38AC475F5 /* AppInfoTests.swift */, |
| 235 | A1B2C3D40000000000000101 /* HistoryEntryCodableTests.swift */, | 237 | A1B2C3D40000000000000101 /* HistoryEntryCodableTests.swift */, |
| 238 | A1B2C3D40000000000000201 /* InspectionInputTests.swift */, | ||
| 236 | ); | 239 | ); |
| 237 | path = DomainDigTests; | 240 | path = DomainDigTests; |
| 238 | sourceTree = "<group>"; | 241 | sourceTree = "<group>"; |
| @@ -493,6 +496,7 @@ | |||
| 493 | EA12012CDB4C21ABB4217D86 /* LocalAPIContractTests.swift in Sources */, | 496 | EA12012CDB4C21ABB4217D86 /* LocalAPIContractTests.swift in Sources */, |
| 494 | 4F96CEB875EC3501E784CE39 /* DataMigrationServiceTests.swift in Sources */, | 497 | 4F96CEB875EC3501E784CE39 /* DataMigrationServiceTests.swift in Sources */, |
| 495 | 99024E91EED2275FD80E83A9 /* AppInfoTests.swift in Sources */, | 498 | 99024E91EED2275FD80E83A9 /* AppInfoTests.swift in Sources */, |
| 499 | A1B2C3D40000000000000202 /* InspectionInputTests.swift in Sources */, | ||
| 496 | ); | 500 | ); |
| 497 | runOnlyForDeploymentPostprocessing = 0; | 501 | runOnlyForDeploymentPostprocessing = 0; |
| 498 | }; | 502 | }; |
DomainDig/DomainAvailabilityService.swift +7 −6
| @@ -9,15 +9,16 @@ struct DomainAvailabilityService { | |||
| 9 | return DomainAvailabilityResult(domain: domain, status: .unknown) | 9 | return DomainAvailabilityResult(domain: domain, status: .unknown) |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | if await checkViaRDAP(domain: normalizedDomain) == .registered { | 12 | // RDAP is the registry's own record, so it settles both directions. |
| 13 | return DomainAvailabilityResult(domain: normalizedDomain, status: .registered) | 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 | let fallbackStatus = await checkViaDNSFallback(domain: normalizedDomain) | 21 | let fallbackStatus = await checkViaDNSFallback(domain: normalizedDomain) |
| 17 | if fallbackStatus == .registered { | ||
| 18 | return DomainAvailabilityResult(domain: normalizedDomain, status: .unknown) | ||
| 19 | } | ||
| 20 | |||
| 21 | return DomainAvailabilityResult(domain: normalizedDomain, status: fallbackStatus) | 22 | return DomainAvailabilityResult(domain: normalizedDomain, status: fallbackStatus) |
| 22 | } | 23 | } |
| 23 | 24 | ||
DomainDig/RDAPService.swift +47 −16
| @@ -1,20 +1,34 @@ | |||
| 1 | import Foundation | 1 | import Foundation |
| 2 | 2 | ||
| 3 | enum RDAPService { | 3 | enum RDAPService { |
| 4 | /// The registry's answer about `domain`, or nil when the registry did not | ||
| 5 | /// give one. | ||
| 4 | static func registrationStatus(for domain: String) async -> DomainAvailabilityStatus? { | 6 | static func registrationStatus(for domain: String) async -> DomainAvailabilityStatus? { |
| 5 | let normalizedDomain = normalize(domain) | 7 | let normalizedDomain = normalize(domain) |
| 6 | guard !normalizedDomain.isEmpty else { return nil } | 8 | guard !normalizedDomain.isEmpty else { return nil } |
| 7 | 9 | ||
| 8 | switch await fetchRDAPResponse(for: normalizedDomain) { | 10 | switch await fetchRDAPResponse(for: normalizedDomain) { |
| 9 | case let .success(response): | 11 | case .found: |
| 10 | return response.isDomainRecord ? .registered : nil | 12 | return .registered |
| 11 | case .empty: | 13 | case .notRegistered: |
| 12 | return nil | 14 | return .available |
| 13 | case .error: | 15 | case .empty, .failed: |
| 14 | return nil | 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 | static func ownership(for domain: String) async -> ServiceResult<DomainOwnership> { | 32 | static func ownership(for domain: String) async -> ServiceResult<DomainOwnership> { |
| 19 | let normalizedDomain = normalize(domain) | 33 | let normalizedDomain = normalize(domain) |
| 20 | guard !normalizedDomain.isEmpty else { | 34 | guard !normalizedDomain.isEmpty else { |
| @@ -22,7 +36,7 @@ enum RDAPService { | |||
| 22 | } | 36 | } |
| 23 | 37 | ||
| 24 | switch await fetchRDAPResponse(for: normalizedDomain) { | 38 | switch await fetchRDAPResponse(for: normalizedDomain) { |
| 25 | case let .success(response): | 39 | case let .found(response): |
| 26 | let ownership = DomainOwnership( | 40 | let ownership = DomainOwnership( |
| 27 | registrar: response.registrarName, | 41 | registrar: response.registrarName, |
| 28 | registrant: response.registrantName, | 42 | registrant: response.registrantName, |
| @@ -33,9 +47,11 @@ enum RDAPService { | |||
| 33 | abuseEmail: response.abuseEmail | 47 | abuseEmail: response.abuseEmail |
| 34 | ) | 48 | ) |
| 35 | return .success(ownership) | 49 | return .success(ownership) |
| 50 | case .notRegistered: | ||
| 51 | return .empty("Unavailable") | ||
| 36 | case let .empty(message): | 52 | case let .empty(message): |
| 37 | return .empty(message) | 53 | return .empty(message) |
| 38 | case let .error(message): | 54 | case let .failed(message): |
| 39 | return .error(message) | 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 | let startedAt = DomainDebugLog.signpostStart("RDAP.fetch", domain: domain) | 81 | let startedAt = DomainDebugLog.signpostStart("RDAP.fetch", domain: domain) |
| 52 | guard let url = URL(string: "https://rdap.org/domain/\(domain)") else { | 82 | guard let url = URL(string: "https://\(bootstrapHost)/domain/\(domain)") else { |
| 53 | return .error("Unavailable") | 83 | return .failed("Unavailable") |
| 54 | } | 84 | } |
| 55 | 85 | ||
| 56 | do { | 86 | do { |
| @@ -61,7 +91,7 @@ private func fetchRDAPResponse(for domain: String) async -> ServiceResult<RDAPDo | |||
| 61 | let (data, response) = try await URLSession.shared.data(for: request) | 91 | let (data, response) = try await URLSession.shared.data(for: request) |
| 62 | guard let httpResponse = response as? HTTPURLResponse else { | 92 | guard let httpResponse = response as? HTTPURLResponse else { |
| 63 | DomainDebugLog.error("RDAP.badResponse domain=\(domain) response=nil") | 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 | switch httpResponse.statusCode { | 97 | switch httpResponse.statusCode { |
| @@ -73,19 +103,20 @@ private func fetchRDAPResponse(for domain: String) async -> ServiceResult<RDAPDo | |||
| 73 | return .empty("Unavailable") | 103 | return .empty("Unavailable") |
| 74 | } | 104 | } |
| 75 | DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "status=200 bytes=\(data.count)") | 105 | DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "status=200 bytes=\(data.count)") |
| 76 | return .success(rdapResponse) | 106 | return .found(rdapResponse) |
| 77 | case 404: | 107 | case 404: |
| 78 | DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "status=404") | 108 | let fromRegistry = RDAPService.answeredByRegistry(responseURL: httpResponse.url) |
| 79 | return .empty("Unavailable") | 109 | DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "status=404 registry=\(fromRegistry)") |
| 110 | return fromRegistry ? .notRegistered : .empty("Unavailable") | ||
| 80 | default: | 111 | default: |
| 81 | DomainDebugLog.error("RDAP.httpError domain=\(domain) status=\(httpResponse.statusCode)") | 112 | DomainDebugLog.error("RDAP.httpError domain=\(domain) status=\(httpResponse.statusCode)") |
| 82 | DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "status=\(httpResponse.statusCode)") | 113 | DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "status=\(httpResponse.statusCode)") |
| 83 | return .error("Unavailable") | 114 | return .failed("Unavailable") |
| 84 | } | 115 | } |
| 85 | } catch { | 116 | } catch { |
| 86 | DomainDebugLog.error("RDAP.error domain=\(domain) error=\(error.localizedDescription)") | 117 | DomainDebugLog.error("RDAP.error domain=\(domain) error=\(error.localizedDescription)") |
| 87 | DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "error") | 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 | } | ||