Skip to content

Commit 2f30434

Browse files
jsoo1rkaippully
andauthored
Grpc 1.45+ support (#157)
* nixpkgs.nix: Bump to 2022-04-22. * release.nix: Unmark data-diverse as broken. * *.nix: Adjust to nixpkgs update. * cbits: Adjust to removal of insecure build. See grpc/grpc#25586 * Do not make secure connections mandatory Instead of making secure connections mandatory, use insecure credentials to keep existing API unchanged. * release.nix: Make sure .sh scripts are executable before wrapping. It seems as though the `./Setup sdist` now unsets the executable bit. * README: Update supported gRPC version. --------- Co-authored-by: Raghu Kaippully <[email protected]>
1 parent 9adf3b0 commit 2f30434

File tree

10 files changed

+41
-27
lines changed

10 files changed

+41
-27
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ have extended and released under the same [`LICENSE`](./LICENSE)
77
Installation
88
------------
99

10-
**The current version of this library requires gRPC version 1.42.0. Newer versions may work but have not been tested.**
10+
**The current version of this library requires gRPC version 1.45.0. Newer versions may work but have not been tested.**
1111

1212
Usage
1313
-----

core/src/Network/GRPC/LowLevel/Client.hs

+5-3
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,21 @@ addMetadataCreds c (Just create) = do
8484
createChannel :: ClientConfig -> C.GrpcChannelArgs -> IO C.Channel
8585
createChannel ClientConfig{..} chanargs =
8686
case clientSSLConfig of
87-
Nothing -> C.grpcInsecureChannelCreate e chanargs C.reserved
87+
Nothing ->
88+
C.withInsecureChannelCredentials $ \creds ->
89+
C.grpcChannelCreate e creds chanargs
8890
Just (ClientSSLConfig rootCertPath Nothing plugin) ->
8991
do rootCert <- mapM B.readFile rootCertPath
9092
C.withChannelCredentials rootCert Nothing Nothing $ \creds -> do
9193
creds' <- addMetadataCreds creds plugin
92-
C.secureChannelCreate creds' e chanargs C.reserved
94+
C.grpcChannelCreate e creds' chanargs
9395
Just (ClientSSLConfig x (Just (ClientSSLKeyCertPair y z)) plugin) ->
9496
do rootCert <- mapM B.readFile x
9597
privKey <- Just <$> B.readFile y
9698
clientCert <- Just <$> B.readFile z
9799
C.withChannelCredentials rootCert privKey clientCert $ \creds -> do
98100
creds' <- addMetadataCreds creds plugin
99-
C.secureChannelCreate creds' e chanargs C.reserved
101+
C.grpcChannelCreate e creds' chanargs
100102
where (Endpoint e) = clientServerEndpoint
101103

102104
createClient :: GRPC -> ClientConfig -> IO Client

core/src/Network/GRPC/LowLevel/Server.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ serverEndpoint ServerConfig{..} = endpoint host port
143143
addPort :: C.Server -> ServerConfig -> IO Int
144144
addPort server conf@ServerConfig{..} =
145145
case sslConfig of
146-
Nothing -> C.grpcServerAddInsecureHttp2Port server e
146+
Nothing -> C.withInsecureServerCredentials $ C.grpcServerAddHttp2Port server e
147147
Just ServerSSLConfig{..} ->
148148
do crc <- mapM B.readFile clientRootCert
149149
spk <- B.readFile serverPrivateKey
@@ -152,7 +152,7 @@ addPort server conf@ServerConfig{..} =
152152
case customMetadataProcessor of
153153
Just p -> C.setMetadataProcessor creds p
154154
Nothing -> return ()
155-
C.serverAddSecureHttp2Port server e creds
155+
C.grpcServerAddHttp2Port server e creds
156156
where e = unEndpoint $ serverEndpoint conf
157157

158158
startServer :: GRPC -> ServerConfig -> IO Server

core/src/Network/GRPC/Unsafe.chs

-11
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,6 @@ castPeek p = do
189189
useAsCString* `ByteString', useAsCString* `ByteString', `CTimeSpecPtr',unReserved `Reserved'}
190190
-> `Call'#}
191191

192-
-- | Create a channel (on the client) to the server. The first argument is
193-
-- host and port, e.g. @"localhost:50051"@. The gRPC docs say that most clients
194-
-- are expected to pass a 'nullPtr' for the 'ChannelArgsPtr'. We currently don't
195-
-- expose any functions for creating channel args, since they are entirely
196-
-- undocumented.
197-
{#fun grpc_insecure_channel_create as ^
198-
{useAsCString* `ByteString', `GrpcChannelArgs', unReserved `Reserved'} -> `Channel'#}
199-
200192
{#fun grpc_channel_register_call as ^
201193
{`Channel', useAsCString* `ByteString',useAsCString* `ByteString',unReserved `Reserved'}
202194
-> `CallHandle' CallHandle#}
@@ -258,9 +250,6 @@ getPeerPeek cstr = do
258250
{#fun grpc_server_register_completion_queue as ^
259251
{`Server', `CompletionQueue', unReserved `Reserved'} -> `()'#}
260252

261-
{#fun grpc_server_add_insecure_http2_port as ^
262-
{`Server', useAsCString* `ByteString'} -> `Int'#}
263-
264253
-- | Starts a server. To shut down the server, call these in order:
265254
-- 'grpcServerShutdownAndNotify', 'grpcServerCancelAllCalls',
266255
-- 'grpcServerDestroy'. After these are done, shut down and destroy the server's

core/src/Network/GRPC/Unsafe/Security.chs

+13-3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ getAuthProperties ctx = withAuthPropertyIterator ctx $ \i -> do
169169
{#fun unsafe ssl_credentials_create_internal as ^
170170
{`CString', `CString', `CString'} -> `ChannelCredentials'#}
171171

172+
{#fun insecure_credentials_create as ^ {} -> `ChannelCredentials'#}
173+
172174
sslChannelCredentialsCreate :: Maybe ByteString
173175
-> Maybe ByteString
174176
-> Maybe ByteString
@@ -195,6 +197,9 @@ withChannelCredentials :: Maybe ByteString
195197
withChannelCredentials x y z = bracket (sslChannelCredentialsCreate x y z)
196198
channelCredentialsRelease
197199

200+
withInsecureChannelCredentials :: (ChannelCredentials -> IO a) -> IO a
201+
withInsecureChannelCredentials = bracket insecureCredentialsCreate channelCredentialsRelease
202+
198203
-- * Call Credentials
199204

200205
{#fun call_set_credentials as ^
@@ -219,6 +224,8 @@ withChannelCredentials x y z = bracket (sslChannelCredentialsCreate x y z)
219224
`SslClientCertificateRequestType'}
220225
-> `ServerCredentials'#}
221226

227+
{#fun insecure_server_credentials_create as ^ {} -> `ServerCredentials'#}
228+
222229
sslServerCredentialsCreate :: Maybe ByteString
223230
-- ^ PEM encoding of the client root certificates.
224231
-- Can be 'Nothing' if SSL authentication of
@@ -252,13 +259,16 @@ withServerCredentials a b c d = bracket (sslServerCredentialsCreate a b c d)
252259

253260
-- * Creating Secure Clients/Servers
254261

255-
{#fun server_add_secure_http2_port as ^
262+
{#fun grpc_server_add_http2_port as ^
256263
{`Server',useAsCString* `ByteString', `ServerCredentials'} -> `Int'#}
257264

258-
{#fun secure_channel_create as ^
259-
{`ChannelCredentials',useAsCString* `ByteString', `GrpcChannelArgs', unReserved `Reserved'}
265+
{#fun grpc_channel_create as ^
266+
{useAsCString* `ByteString', `ChannelCredentials', `GrpcChannelArgs'}
260267
-> `Channel'#}
261268

269+
withInsecureServerCredentials :: (ServerCredentials -> IO a) -> IO a
270+
withInsecureServerCredentials = bracket insecureServerCredentialsCreate serverCredentialsRelease
271+
262272
-- * Custom metadata processing -- server side
263273

264274
-- | Type synonym for the raw function pointer we pass to C to handle custom

nix/dhall.nix

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ mkDerivation {
2020
sha256 = "f3e95cfa0ef1a89d5ca29591b7925db51551150a27f3fd02717ce69699e8e03c";
2121
revision = "2";
2222
editedCabalFile = "02z0jmzzp20yj46iz6i384xwc6k2anxb33smvc4yhpmhqjs0aq8a";
23+
jailbreak = true;
2324
isLibrary = true;
2425
isExecutable = true;
2526
enableSeparateDataOutput = true;

nix/proto3-suite.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ mkDerivation {
1515
version = "0.6.0";
1616
src = fetchgit {
1717
url = "https://github.com/awakesecurity/proto3-suite.git";
18-
sha256 = "1bvivy1rw84gln3kvb704wcsaz8l5xmgfibbbammbkmnjcgfs1y5";
19-
rev = "1f2c156b1178599d3853dac941beb3f29e2bdf5e";
18+
sha256 = "sha256-1a1ZHlvvtE1urvDL7n984OQ5gbro26RnKAjvDCH/2fs=";
19+
rev = "9f7daef66ba6dfc9574039b1d206c5df126d4b39";
2020
fetchSubmodules = true;
2121
};
2222
isLibrary = true;

nix/proto3-wire.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ mkDerivation {
99
version = "1.4.1";
1010
src = fetchgit {
1111
url = "https://github.com/awakesecurity/proto3-wire.git";
12-
sha256 = "189dzkxdwnfscq8ylfalxkh95x7kkjlawz9wqkwbdblg5a5k1y7i";
13-
rev = "13962d58dbfb3cfbb539702746afe94ec02189ce";
12+
sha256 = "sha256-g15oAYmhfv8DVgmQTZkcCgOYRFkxl2PQi30qXXXhBLs=";
13+
rev = "ee6ca644eef86cc5f31da85fb48e10b20ab0e1a1";
1414
fetchSubmodules = true;
1515
};
1616
libraryHaskellDepends = [

nixpkgs.nix

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# The SHA256 will be printed as the last line of stdout.
88

99
import (builtins.fetchTarball {
10-
# nixos-21.11 as on 2023-06-15
11-
url = "https://github.com/NixOS/nixpkgs/archive/eabc38219184cc3e04a974fe31857d8e0eac098d.tar.gz";
12-
sha256 = "04ffwp2gzq0hhz7siskw6qh9ys8ragp7285vi1zh8xjksxn1msc5";
10+
# "master" as on 2022-04-22
11+
url = "https://github.com/NixOS/nixpkgs/archive/ed3cc9672ad507ca4d00e15b35f3d24edd1dff6c.tar.gz";
12+
sha256 = "1bn55f20kqpdcfz0gsn9j6cyw617izrnwb4yw33bgqhyxlabb4q0";
1313
})

release.nix

+12
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ let
7070

7171
haskellPackages = pkgsOld.haskellPackages.override {
7272
overrides = haskellPackagesNew: haskellPackagesOld: rec {
73+
data-diverse =
74+
pkgsNew.haskell.lib.overrideCabal haskellPackagesOld.data-diverse (old: {
75+
broken = assert !old.broken ->
76+
builtins.trace "remove the data-diverse override in release.nix" false;
77+
false;
78+
doCheck = false;
79+
});
80+
7381
dhall =
7482
haskellPackagesNew.callPackage ./nix/dhall.nix { };
7583

@@ -151,6 +159,10 @@ let
151159
(oldDerivation.patches or [ ]) ++ [ ./tests/tests.patch ];
152160

153161
postPatch = (oldDerivation.postPatch or "") + ''
162+
for bin in tests/*.sh; do
163+
chmod a+x "$bin"
164+
done
165+
154166
patchShebangs tests
155167
substituteInPlace tests/simple-client.sh \
156168
--replace @makeWrapper@ ${pkgsNew.makeWrapper} \

0 commit comments

Comments
 (0)