From ce7f599ead7ec7056e335bfba355011c0b0bc51c Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Fri, 25 Oct 2024 10:59:28 -0700 Subject: [PATCH] Update for http2-5.3 and upcoming tls - In http2, `HeaderList` was replaced with `[Header]`, `SettingsHeaderTableSize` was replaced with `SettingsTokenHeaderTableSize`. - data-default 0.8 deprecates data-default-class by moving the `Default` class from `Data.Default.Class` to `Data.Default`. - tls has replaced some default instances with functions and made some record constructors private. See: https://github.com/haskell-grpc-native/http2-client/pull/97 See: https://github.com/kazu-yamamoto/crypton-certificate/pull/11 See: https://github.com/haskell-tls/hs-tls/pull/486 See: https://github.com/commercialhaskell/stackage/issues/7545 --- push-notify-apn.cabal | 3 ++- src/Network/PushNotify/APN.hs | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/push-notify-apn.cabal b/push-notify-apn.cabal index 303ec33..6500d28 100644 --- a/push-notify-apn.cabal +++ b/push-notify-apn.cabal @@ -29,8 +29,9 @@ library , bytestring , containers , data-default - , http2 >= 3.0 && <= 5.1 + , http2 >= 3.0 && <= 5.4 , http2-client >= 0.10.0.2 + , http-types >= 0.12.4 , lifted-base , mtl , random diff --git a/src/Network/PushNotify/APN.hs b/src/Network/PushNotify/APN.hs index ea45a6d..3a9c161 100644 --- a/src/Network/PushNotify/APN.hs +++ b/src/Network/PushNotify/APN.hs @@ -91,6 +91,7 @@ import qualified Data.Text.Encoding as TE import qualified Network.HPACK as HTTP2 import qualified Network.HTTP2.Frame as HTTP2 +import qualified Network.HTTP.Types as HTTP -- | A session that manages connections to Apple's push notification service data ApnSession = ApnSession @@ -138,7 +139,7 @@ hexEncodedToken = ApnToken . B16.encode . B16.decodeLenient . TE.encodeUtf8 -- | Exceptional responses to a send request data ApnException = ApnExceptionHTTP ErrorCode | ApnExceptionJSON String - | ApnExceptionMissingHeader HTTP2.HeaderName + | ApnExceptionMissingHeader HTTP.HeaderName | ApnExceptionUnexpectedResponse | ApnExceptionConnectionClosed | ApnExceptionSessionClosed @@ -506,16 +507,16 @@ newConnection aci = do clip <- case (aciUseJWT aci) of True -> do castore <- getSystemCertificateStore - let clip = ClientParams + let clip = (defaultParamsClient (T.unpack hostname) undefined) { clientUseMaxFragmentLength=Nothing - , clientServerIdentification=(T.unpack hostname, undefined) , clientUseServerNameIndication=True , clientWantSessionResume=Nothing , clientShared=def { sharedCAStore=castore } , clientHooks=def { onCertificateRequest = const . return $ Nothing } - , clientDebug=DebugParams { debugSeed=Nothing, debugPrintSeed=const $ return (), debugVersionForced=Nothing, debugKeyLogger=const $ return () } + , clientDebug=def + { debugSeed=Nothing, debugPrintSeed=const $ return (), debugVersionForced=Nothing, debugKeyLogger=const $ return () } , clientSupported=def { supportedVersions=[ TLS12 ] , supportedCiphers=ciphersuite_strong } @@ -533,15 +534,15 @@ newConnection aci = do shared = def { sharedCredentials = credentials , sharedCAStore=castore } - clip = ClientParams + clip = (defaultParamsClient (T.unpack hostname) undefined) { clientUseMaxFragmentLength=Nothing - , clientServerIdentification=(T.unpack hostname, undefined) , clientUseServerNameIndication=True , clientWantSessionResume=Nothing , clientShared=shared , clientHooks=def { onCertificateRequest=const . return . Just $ credential } - , clientDebug=DebugParams { debugSeed=Nothing, debugPrintSeed=const $ return (), debugVersionForced=Nothing, debugKeyLogger=const $ return () } + , clientDebug=def + { debugSeed=Nothing, debugPrintSeed=const $ return (), debugVersionForced=Nothing, debugKeyLogger=const $ return () } , clientSupported=def { supportedVersions=[ TLS12 ] , supportedCiphers=ciphersuite_strong } @@ -710,10 +711,10 @@ sendApnRaw connection deviceToken mJwtBearerToken message = bracket_ eitherDecode body >>= parseEither (\obj -> ctor <$> obj .: "reason") - getHeaderEx :: HTTP2.HeaderName -> [HTTP2.Header] -> HTTP2.HeaderValue + getHeaderEx :: HTTP.HeaderName -> [HTTP2.Header] -> ByteString getHeaderEx name headers = fromMaybe (throw $ ApnExceptionMissingHeader name) (DL.lookup name headers) - defaultHeaders :: Text -> ByteString -> ByteString -> [(HTTP2.HeaderName, ByteString)] + defaultHeaders :: Text -> ByteString -> ByteString -> [(HTTP.HeaderName, ByteString)] defaultHeaders hostname token topic = [ ( ":method", "POST" ) , ( ":scheme", "https" ) , ( ":authority", TE.encodeUtf8 hostname )