


























@@ -71,10 +71,10 @@ actor PushRegistrationManager {
7171throw PushRelayError.relayMisconfigured(
7272"Relay transport requires OpenClawPushDistribution=official")
7373}
74-guard self.buildConfig.apnsEnvironment == .production else {
75-throw PushRelayError.relayMisconfigured(
76- "Relay transport requires OpenClawPushAPNsEnvironment=production")
77-}
74+try Self.validateRelayContract(
75+relayProfile: self.buildConfig.relayProfile,
76+apnsEnvironment: self.buildConfig.apnsEnvironment,
77+ proofPolicy: self.buildConfig.proofPolicy)
7878guard let relayClient = self.relayClient else {
7979throw PushRelayError.relayBaseURLMissing
8080}
@@ -96,6 +96,9 @@ actor PushRegistrationManager {
9696 stored.installationId == installationId,
9797 stored.gatewayDeviceId == gatewayIdentity.deviceId,
9898 stored.relayOrigin == relayOrigin,
99+ stored.apnsEnvironment == self.buildConfig.apnsEnvironment.rawValue,
100+ stored.relayProfile == self.buildConfig.relayProfile.rawValue,
101+ stored.proofPolicy == self.buildConfig.proofPolicy.rawValue,
99102 stored.lastAPNsTokenHashHex == tokenHashHex,
100103 !Self.isExpired(stored.relayHandleExpiresAtMs)
101104{
@@ -112,14 +115,16 @@ actor PushRegistrationManager {
112115 tokenDebugSuffix: stored.tokenDebugSuffix))
113116}
114117115-let response = try await relayClient.register(
118+let response = try await relayClient.register(PushRelayRegistrationInput(
116119 installationId: installationId,
117120 bundleId: bundleId,
118121 appVersion: DeviceInfoHelper.appVersion(),
119122 environment: self.buildConfig.apnsEnvironment,
123+ relayProfile: self.buildConfig.relayProfile,
124+ proofPolicy: self.buildConfig.proofPolicy,
120125 distribution: self.buildConfig.distribution,
121126 apnsTokenHex: apnsTokenHex,
122- gatewayIdentity: gatewayIdentity)
127+ gatewayIdentity: gatewayIdentity))
123128let registrationState = PushRelayRegistrationStore.RegistrationState(
124129 relayHandle: response.relayHandle,
125130 sendGrant: response.sendGrant,
@@ -129,7 +134,10 @@ actor PushRegistrationManager {
129134 tokenDebugSuffix: Self.normalizeTokenSuffix(response.tokenSuffix),
130135 lastAPNsTokenHashHex: tokenHashHex,
131136 installationId: installationId,
132- lastTransport: self.buildConfig.transport.rawValue)
137+ lastTransport: self.buildConfig.transport.rawValue,
138+ apnsEnvironment: self.buildConfig.apnsEnvironment.rawValue,
139+ relayProfile: self.buildConfig.relayProfile.rawValue,
140+ proofPolicy: self.buildConfig.proofPolicy.rawValue)
133141 _ = PushRelayRegistrationStore.saveRegistrationState(registrationState)
134142return try Self.encodePayload(
135143RelayGatewayPushRegistrationPayload(
@@ -151,6 +159,30 @@ actor PushRegistrationManager {
151159return expiresAtMs <= nowMs + 60000
152160}
153161162+private static func validateRelayContract(
163+ relayProfile: PushRelayProfile,
164+ apnsEnvironment: PushAPNsEnvironment,
165+ proofPolicy: PushProofPolicy)
166+throws {
167+switch relayProfile {
168+case .production:
169+guard apnsEnvironment == .production, proofPolicy == .appleStrict else {
170+throw PushRelayError.relayMisconfigured(
171+"production relay profile requires production APNs and appleStrict proof")
172+}
173+case .deviceSandbox:
174+guard apnsEnvironment == .sandbox, proofPolicy == .appleDevelopment else {
175+throw PushRelayError.relayMisconfigured(
176+"deviceSandbox relay profile requires sandbox APNs and appleDevelopment proof")
177+}
178+case .simulatorSandbox:
179+guard apnsEnvironment == .sandbox, proofPolicy == .internalSimulator else {
180+throw PushRelayError.relayMisconfigured(
181+"simulatorSandbox relay profile requires sandbox APNs and internalSimulator proof")
182+}
183+}
184+}
185+154186private static func sha256Hex(_ value: String) -> String {
155187let digest = SHA256.hash(data: Data(value.utf8))
156188return digest.map { String(format: "%02x", $0) }.joined()
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。