Skip to content

Commit 353fcae

Browse files
committed
Update dependencies
Update for breaking changes in tls, mirage-crypto and mirage-flow. capnp-rpc-mirage is gone for now as there were further changes needed there and once the conversion to Eio is done we won't need a separate API for unikernels anyway.
1 parent 71f688a commit 353fcae

17 files changed

+41
-588
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
default: test build-fuzz
44

55
all:
6-
dune build @install test/test.exe test-lwt/test_lwt.exe test-bin/calc.exe test-mirage/test_mirage.exe
6+
dune build @install test/test.exe test-lwt/test_lwt.exe test-bin/calc.exe
77
rm -rf _build/_tests
88
dune runtest --no-buffer -j 1
99

@@ -19,7 +19,7 @@ clean:
1919

2020
test:
2121
rm -rf _build/_tests
22-
dune build test/test.exe test-lwt/test_lwt.exe test-bin/calc.exe test-mirage/test_mirage.exe test-bin/echo/echo_bench.exe @install
22+
dune build test/test.exe test-lwt/test_lwt.exe test-bin/calc.exe test-bin/echo/echo_bench.exe @install
2323
#./_build/default/test/test.bc test core -ev 36
2424
#./_build/default/test-lwt/test.bc test lwt -ev 3
2525
dune build @runtest --no-buffer -j 1

README.md

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ See [LICENSE.md](LICENSE.md) for details.
3838
* [How can I release other resources when my service is released?](#how-can-i-release-other-resources-when-my-service-is-released)
3939
* [Is there an interactive version I can use for debugging?](#is-there-an-interactive-version-i-can-use-for-debugging)
4040
* [Can I set up a direct 2-party connection over a pre-existing channel?](#can-i-set-up-a-direct-2-party-connection-over-a-pre-existing-channel)
41-
* [How can I use this with Mirage?](#how-can-i-use-this-with-mirage)
4241
* [Contributing](#contributing)
4342
* [Conceptual model](#conceptual-model)
4443
* [Building](#building)
@@ -108,8 +107,6 @@ The code is split into several packages:
108107
- `capnp-rpc-unix` adds helper functions for parsing command-line arguments and setting up connections over Unix sockets.
109108
The tests in `test-lwt` test this by sending Cap'n Proto messages over a Unix-domain socket.
110109

111-
- `capnp-rpc-mirage` is an alternative to `-unix` that works with [Mirage][] unikernels.
112-
113110
**Libraries** that consume or provide Cap'n Proto services should normally depend only on `capnp-rpc-lwt`,
114111
since they shouldn't care whether the services they use are local or accessed over some kind of network.
115112

@@ -1356,58 +1353,6 @@ parent: application: Waiting for child to exit...
13561353
parent: application: Done
13571354
```
13581355

1359-
### How can I use this with Mirage?
1360-
1361-
Note: `capnp` uses the `stdint` library, which has C stubs and
1362-
[might need patching](https://github.com/mirage/mirage/issues/885) to work with the Xen backend.
1363-
<https://github.com/ocaml/ocaml/pull/1201#issuecomment-333941042> explains why OCaml doesn't have unsigned integer support.
1364-
1365-
Here is a suitable `config.ml`:
1366-
1367-
<!-- $MDX skip -->
1368-
```ocaml
1369-
open Mirage
1370-
1371-
let main =
1372-
foreign
1373-
~packages:[package "capnp-rpc-mirage"; package "mirage-dns"]
1374-
"Unikernel.Make" (random @-> mclock @-> stackv4 @-> job)
1375-
1376-
let stack = generic_stackv4 default_network
1377-
1378-
let () =
1379-
register "test" [main $ default_random $ default_monotonic_clock $ stack]
1380-
```
1381-
1382-
This should work as the `unikernel.ml`:
1383-
1384-
<!-- $MDX skip -->
1385-
```ocaml
1386-
open Lwt.Infix
1387-
1388-
open Capnp_rpc_lwt
1389-
1390-
module Make (R : Mirage_random.S) (C : Mirage_clock.MCLOCK) (Stack : Mirage_stack.V4) = struct
1391-
module Mirage_capnp = Capnp_rpc_mirage.Make (R) (C) (Stack)
1392-
1393-
let secret_key = `Ephemeral
1394-
1395-
let listen_address = `TCP 7000
1396-
let public_address = `TCP ("localhost", 7000)
1397-
1398-
let start () () stack =
1399-
let dns = Mirage.Network.Dns.create stack in
1400-
let net = Mirage_capnp.network ~dns stack in
1401-
let config = Mirage_capnp.Vat_config.create ~secret_key ~public_address listen_address in
1402-
let service_id = Mirage_capnp.Vat_config.derived_id config "main" in
1403-
let restore = Restorer.single service_id Echo.local in
1404-
Mirage_capnp.serve net config ~restore >>= fun vat ->
1405-
let uri = Mirage_capnp.Vat.sturdy_uri vat service_id in
1406-
Logs.app (fun f -> f "Main service: %a" Uri.pp_hum uri);
1407-
Lwt.wait () |> fst
1408-
end
1409-
```
1410-
14111356
## Contributing
14121357

14131358
### Conceptual model
@@ -1543,7 +1488,6 @@ We should also test with some malicious vats (that don't follow the protocol cor
15431488
[E Reference Mechanics]: http://www.erights.org/elib/concurrency/refmech.html
15441489
[pycapnp]: http://jparyani.github.io/pycapnp/
15451490
[Persistence API]: https://github.com/capnproto/capnproto/blob/master/c%2B%2B/src/capnp/persistent.capnp
1546-
[Mirage]: https://mirage.io/
15471491
[ocaml-ci]: https://github.com/ocurrent/ocaml-ci
15481492
[api]: https://mirage.github.io/capnp-rpc/
15491493
[NETWORK]: https://mirage.github.io/capnp-rpc/capnp-rpc-net/Capnp_rpc_net/S/module-type-NETWORK/index.html

capnp-rpc-mirage.opam

Lines changed: 0 additions & 36 deletions
This file was deleted.

capnp-rpc-net.opam

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ depends: [
2121
"logs"
2222
"asetmap"
2323
"cstruct" {>= "6.0.0"}
24-
"mirage-flow" {>= "2.0.0"}
25-
"tls" {>= "0.13.1"}
24+
"mirage-flow" {>= "4.0.2"}
25+
"tls" {>= "1.0.2"}
2626
"base64" {>= "3.0.0"}
2727
"uri" {>= "1.6.0"}
2828
"ptime"
2929
"prometheus" {>= "0.5"}
3030
"asn1-combinators" {>= "0.2.0"}
31-
"x509" {>= "0.15.0"}
31+
"x509" {>= "1.0.3"}
3232
"tls-mirage"
3333
"dune" {>= "3.0"}
34-
"mirage-crypto"
35-
"mirage-crypto-rng"
34+
"mirage-crypto" {>= "1.1.0"}
35+
"mirage-crypto-rng" {>= "1.1.0"}
3636
]
3737
build: [
3838
["dune" "build" "-p" name "-j" jobs]

capnp-rpc-net/auth.ml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module Digest = struct
4747
let of_certificate cert : t =
4848
let hash = default_hash in
4949
let digest = X509.Public_key.fingerprint ~hash (X509.Certificate.public_key cert) in
50-
`Fingerprint (hash, Cstruct.to_string digest)
50+
`Fingerprint (hash, digest)
5151

5252
let add_to_uri t uri =
5353
match t with
@@ -76,9 +76,8 @@ module Digest = struct
7676
let authenticator = function
7777
| `Insecure -> None
7878
| `Fingerprint (hash, digest) ->
79-
let hash = (hash :> Mirage_crypto.Hash.hash) in
80-
let fingerprint = Cstruct.of_string digest in
81-
Some (X509.Authenticator.server_key_fingerprint ~hash ~fingerprint ~time:(fun _ -> None))
79+
let hash = (hash :> Digestif.hash') in
80+
Some (X509.Authenticator.key_fingerprint ~hash ~fingerprint:digest ~time:(fun _ -> None))
8281

8382
module Map = Map.Make(struct
8483
type nonrec t = t
@@ -98,12 +97,14 @@ module Secret_key = struct
9897
let tls_server_config t = t.tls_server_config
9998

10099
let tls_client_config t ~authenticator =
101-
Tls.Config.client ~certificates:t.certificates ~authenticator ()
100+
match Tls.Config.client ~certificates:t.certificates ~authenticator () with
101+
| Ok x -> x
102+
| Error (`Msg msg) -> Fmt.failwith "tls_client_config: %s" msg
102103

103104
let digest ?(hash=default_hash) t =
104-
let nc_hash = (hash :> Mirage_crypto.Hash.hash) in
105+
let nc_hash = (hash :> Digestif.hash') in
105106
let pub = X509.Private_key.public t.priv in
106-
let value = X509.Public_key.fingerprint ~hash:nc_hash pub |> Cstruct.to_string in
107+
let value = X509.Public_key.fingerprint ~hash:nc_hash pub in
107108
`Fingerprint (hash, value)
108109

109110
let pp_fingerprint hash f t =
@@ -139,8 +140,9 @@ module Secret_key = struct
139140
if we later need to resolve a sturdy ref hosted at the client, we can
140141
reuse this connection. *)
141142
let authenticator ?ip:_ ~host:_ _ = Ok None in
142-
let tls_server_config = Tls.Config.server ~certificates ~authenticator () in
143-
{ priv; certificates; tls_server_config }
143+
match Tls.Config.server ~certificates ~authenticator () with
144+
| Ok tls_server_config -> { priv; certificates; tls_server_config }
145+
| Error (`Msg m) -> Fmt.failwith "Invalid TLS configuration: %s" m
144146

145147
let generate () =
146148
Log.info (fun f -> f "Generating new private key...");
@@ -150,10 +152,10 @@ module Secret_key = struct
150152
t
151153

152154
let of_pem_data data =
153-
match X509.Private_key.decode_pem (Cstruct.of_string data) with
155+
match X509.Private_key.decode_pem data with
154156
| Ok priv -> of_priv priv
155157
| Error (`Msg msg) -> Fmt.failwith "Failed to parse secret key!@ %s" msg
156158

157159
let to_pem_data t =
158-
X509.Private_key.encode_pem t.priv |> Cstruct.to_string
160+
X509.Private_key.encode_pem t.priv
159161
end

capnp-rpc-net/restorer.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ module Id = struct
88
type t = string
99

1010
let generate () =
11-
Mirage_crypto_rng.generate 20 |> Cstruct.to_string
11+
Mirage_crypto_rng.generate 20
1212

1313
let public x = x
1414

1515
let derived ~secret name =
16-
Mirage_crypto.Hash.mac `SHA256 ~key:(Cstruct.of_string secret) (Cstruct.of_string name)
17-
|> Cstruct.to_string
16+
Digestif.SHA256.hmac_string ~key:secret name
17+
|> Digestif.SHA256.to_raw_string
1818

1919
let digest alg t =
20-
let alg = (alg :> Mirage_crypto.Hash.hash) in
21-
Mirage_crypto.Hash.digest alg (Cstruct.of_string t)
22-
|> Cstruct.to_string
20+
let alg = (alg :> Digestif.hash') in
21+
let module H = (val Digestif.module_of_hash' alg : Digestif.S) in
22+
H.digest_string t |> H.to_raw_string
2323

2424
let to_string x = x
2525

@@ -64,10 +64,10 @@ let none : t = fun _ ->
6464
let single id cap =
6565
let cap = Cast.cap_to_raw cap in
6666
(* Hash the ID to prevent timing attacks. *)
67-
let id = Mirage_crypto.Hash.digest `SHA256 (Cstruct.of_string id) in
67+
let id = Digestif.SHA256.digest_string id |> Digestif.SHA256.to_raw_string in
6868
fun requested_id ->
69-
let requested_id = Mirage_crypto.Hash.digest `SHA256 (Cstruct.of_string requested_id) in
70-
if Cstruct.equal id requested_id then (
69+
let requested_id = Digestif.SHA256.digest_string requested_id |> Digestif.SHA256.to_raw_string in
70+
if String.equal id requested_id then (
7171
Core_types.inc_ref cap;
7272
Lwt.return (Ok cap)
7373
) else Lwt.return unknown_service_id
@@ -80,7 +80,7 @@ module Table = struct
8080
| Manual of Core_types.cap (* We hold a ref on the cap *)
8181

8282
type t = {
83-
hash : Mirage_crypto.Hash.hash;
83+
hash : Digestif.hash';
8484
cache : (digest, entry) Hashtbl.t;
8585
load : Id.t -> digest -> resolution Lwt.t;
8686
make_sturdy : Id.t -> Uri.t;
@@ -131,7 +131,7 @@ module Table = struct
131131
)
132132

133133
let of_loader (type l) (module L : LOADER with type t = l) loader =
134-
let hash = (L.hash loader :> Mirage_crypto.Hash.hash) in
134+
let hash = (L.hash loader :> Digestif.hash') in
135135
let cache = Hashtbl.create 53 in
136136
let rec load id digest =
137137
let sr : Private.Capnp_core.sturdy_ref = object

mirage/capnp_rpc_mirage.ml

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)