




















@@ -276,7 +276,20 @@ final class PushRelayClient: @unchecked Sendable {
276276}
277277278278func register(_ input: PushRelayRegistrationInput) async throws -> PushRelayRegisterResponse {
279-let challenge = try await self.fetchChallenge()
279+GatewayDiagnostics.pushRelay.stage(
280+"registration start origin=\(self.normalizedBaseURLString) "
281++ "apns=\(input.environment.rawValue) "
282++ "profile=\(input.relayProfile.rawValue) "
283++ "proof=\(input.proofPolicy.rawValue)")
284+let challenge: PushRelayChallengeResponse
285+do {
286+GatewayDiagnostics.pushRelay.stage("challenge request start")
287+ challenge = try await self.fetchChallenge()
288+GatewayDiagnostics.pushRelay.stage("challenge received")
289+} catch {
290+GatewayDiagnostics.pushRelay.failed("challenge request", error: error)
291+throw error
292+}
280293let signedPayload = PushRelayRegisterSignedPayload(
281294 challengeId: challenge.challengeId,
282295 installationId: input.installationId,
@@ -295,15 +308,38 @@ final class PushRelayClient: @unchecked Sendable {
295308 apnsEnvironment: input.environment.rawValue,
296309 relayProfile: input.relayProfile.rawValue,
297310 proofPolicy: input.proofPolicy.rawValue)
298-let appAttest = try await self.createAppAttestProofIfNeeded(
299- proofPolicy: input.proofPolicy,
300- challenge: challenge.challenge,
301- signedPayloadData: signedPayloadData,
302- scope: appAttestScope)
303-let receipt = try await self.createReceiptIfNeeded(proofPolicy: input.proofPolicy)
304-let simulatorProof = try self.createSimulatorProofIfNeeded(
305- proofPolicy: input.proofPolicy,
306- signedPayloadData: signedPayloadData)
311+let appAttest: PushRelayAppAttestProof?
312+do {
313+GatewayDiagnostics.pushRelay.stage("app attest proof start")
314+ appAttest = try await self.createAppAttestProofIfNeeded(
315+ proofPolicy: input.proofPolicy,
316+ challenge: challenge.challenge,
317+ signedPayloadData: signedPayloadData,
318+ scope: appAttestScope)
319+GatewayDiagnostics.pushRelay.stage("app attest proof complete included=\(appAttest != nil)")
320+} catch {
321+GatewayDiagnostics.pushRelay.failed("app attest proof", error: error)
322+throw error
323+}
324+let receipt: PushRelayReceiptPayload?
325+do {
326+GatewayDiagnostics.pushRelay.stage("receipt proof start")
327+ receipt = try await self.createReceiptIfNeeded(proofPolicy: input.proofPolicy)
328+GatewayDiagnostics.pushRelay.stage("receipt proof complete included=\(receipt != nil)")
329+} catch {
330+GatewayDiagnostics.pushRelay.failed("receipt proof", error: error)
331+throw error
332+}
333+let simulatorProof: PushRelaySimulatorProofPayload?
334+do {
335+ simulatorProof = try self.createSimulatorProofIfNeeded(
336+ proofPolicy: input.proofPolicy,
337+ signedPayloadData: signedPayloadData)
338+GatewayDiagnostics.pushRelay.stage("simulator proof complete included=\(simulatorProof != nil)")
339+} catch {
340+GatewayDiagnostics.pushRelay.failed("simulator proof", error: error)
341+throw error
342+}
307343let requestBody = PushRelayRegisterRequest(
308344 challengeId: signedPayload.challengeId,
309345 installationId: signedPayload.installationId,
@@ -334,20 +370,38 @@ final class PushRelayClient: @unchecked Sendable {
334370 request.setValue("application/json", forHTTPHeaderField: "Content-Type")
335371 request.httpBody = try self.jsonEncoder.encode(requestBody)
336372337-let (data, response) = try await self.session.data(for: request)
373+let data: Data
374+let response: URLResponse
375+do {
376+GatewayDiagnostics.pushRelay.stage("register request start")
377+(data, response) = try await self.session.data(for: request)
378+} catch {
379+GatewayDiagnostics.pushRelay.failed("register request", error: error)
380+throw error
381+}
338382let status = Self.statusCode(from: response)
383+GatewayDiagnostics.pushRelay.stage("register response status=\(status)")
339384guard (200..<300).contains(status) else {
340385if status == 401 {
341386 // If the relay rejects registration, drop local App Attest state so the next
342387 // attempt re-attests instead of getting stuck without an attestation object.
343388 _ = PushRelayRegistrationStore.clearAppAttestKeyID(scope: appAttestScope)
344389 _ = PushRelayRegistrationStore.clearAttestedKeyID(scope: appAttestScope)
345390}
346-throw PushRelayError.requestFailed(
391+let relayError = PushRelayError.requestFailed(
347392 status: status,
348393 message: Self.decodeErrorMessage(data: data))
394+GatewayDiagnostics.pushRelay.stage("register response failed status=\(status)")
395+throw relayError
396+}
397+do {
398+let decoded = try self.decode(PushRelayRegisterResponse.self, from: data)
399+GatewayDiagnostics.pushRelay.stage("registration response decoded")
400+return decoded
401+} catch {
402+GatewayDiagnostics.pushRelay.failed("registration response decode", error: error)
403+throw error
349404}
350-return try self.decode(PushRelayRegisterResponse.self, from: data)
351405}
352406353407private func createAppAttestProofIfNeeded(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。