Skip to content

Commit f4b1980

Browse files
authored
Update to mirage-crypto 1.0.0 API (#314)
2 parents 001a4ca + e720713 commit f4b1980

File tree

8 files changed

+26
-31
lines changed

8 files changed

+26
-31
lines changed

bot-components.opam

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ depends: [
1515
"lwt_ssl" {>= "1.1.3"}
1616
"ssl" {= "0.5.9"}
1717
"stdio" {>= "v0.14.0"}
18-
"hex" {>= "1.4.0"}
19-
"mirage-crypto" {>= "0.8.7"}
18+
"ohex" {>= "0.2.0"}
19+
"mirage-crypto" {>= "1.0.0"}
2020
"eqaf" {>= "0.7"}
2121
"yojson" {>= "1.7.0"}
2222
"graphql_ppx" {>= "1.2.0"}
23-
"x509" {>= "0.11.2"}
24-
"cstruct" {>= "5.0.0"}
23+
"x509" {>= "1.0.0"}
2524
"ISO8601" {>= "0.2.0"}
2625
"camlzip" {>= "1.08"}
26+
"digestif" {>= "1.2.0"}
2727
"odoc" {>= "1.5.2" & with-doc}
2828
]
2929
build: [

bot-components/GitHub_app.ml

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ let github_headers token =
1010
; ("authorization", "Bearer " ^ token) ]
1111

1212
let rs256_sign ~key ~data =
13-
(* Taken from https://github.com/mmaker/ocaml-letsencrypt *)
14-
let data = Cstruct.of_string data in
15-
let h = Mirage_crypto.Hash.SHA256.digest data in
13+
(* Taken from https://github.com/robur-coop/ocaml-letsencrypt *)
14+
let h = Digestif.SHA256.(to_raw_string (digest_string data)) in
1615
let pkcs1_digest = X509.Certificate.encode_pkcs1_digest_info (`SHA256, h) in
17-
Mirage_crypto_pk.Rsa.PKCS1.sig_encode ~key pkcs1_digest |> Cstruct.to_string
16+
Mirage_crypto_pk.Rsa.PKCS1.sig_encode ~key pkcs1_digest
1817

1918
let base64 = Base64.encode ~pad:false ~alphabet:Base64.uri_safe_alphabet
2019

bot-components/GitHub_subscriptions.ml

+2-3
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,8 @@ let receive_github ~secret headers body =
240240
match Header.get headers "X-Hub-Signature" with
241241
| Some signature ->
242242
let expected =
243-
Mirage_crypto.Hash.SHA1.hmac ~key:(Cstruct.of_string secret)
244-
(Cstruct.of_string body)
245-
|> Hex.of_cstruct |> Hex.show |> f "sha1=%s"
243+
Digestif.SHA1.(to_raw_string (hmac_string ~key:secret body))
244+
|> Ohex.encode |> f "sha1=%s"
246245
in
247246
if Eqaf.equal signature expected then Ok (Some install_id)
248247
else Error "Webhook signed but with wrong signature."

bot-components/dune

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
(library
22
(name Bot_components)
33
(public_name bot-components)
4-
(libraries base camlzip cohttp-lwt-unix cstruct eqaf hex mirage-crypto stdio
5-
str x509 yojson ISO8601)
4+
(libraries base camlzip cohttp-lwt-unix eqaf ohex mirage-crypto stdio str
5+
x509 yojson ISO8601 digestif)
66
(private_modules GraphQL_query GitHub_GraphQL Utils)
77
(modules_without_implementation GitHub_types GitLab_types)
88
(preprocess

coq-bot.opam

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ depends: [
1515
"cohttp-lwt-unix" {>= "2.5.4"}
1616
"lwt_ssl" {>= "1.1.3"}
1717
"ssl" {>= "0.5.9"}
18-
"mirage-crypto" {>= "0.11.0"}
19-
"mirage-crypto-rng" {>= "0.11.0"}
20-
"mirage-crypto-rng-lwt" {>= "0.11.0"}
18+
"mirage-crypto" {>= "1.0.0"}
19+
"mirage-crypto-rng" {>= "1.0.0"}
20+
"mirage-crypto-rng-lwt" {>= "1.0.0"}
2121
"stdio" {>= "v0.14.0"}
2222
"yojson" {>= "1.7.0"}
2323
"bot-components" {dev}

default.nix

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{ pkgs ? import (fetchTarball {
2-
url = "https://github.com/NixOS/nixpkgs/archive/280db3decab4cbeb22a4599bd472229ab74d25e1.tar.gz";
3-
sha256 = "sha256:17n9wji64l7d16s8r100ypwlxkmwrypll4q3wkkfjswbilxkqjr6";
2+
url = "https://github.com/NixOS/nixpkgs/archive/5ea573ca476915e0ccefb99be5687e4150fa049b.tar.gz";
3+
sha256 = "0hsg6xjj4iclfrvplsf0rd9xiwkaazvmlp609qiwka65v7wcjja2";
44
}) { } }:
55

66
pkgs.stdenv.mkDerivation rec {
@@ -22,7 +22,7 @@ pkgs.stdenv.mkDerivation rec {
2222
camlzip
2323
cohttp
2424
cohttp-lwt-unix
25-
hex
25+
ohex
2626
iso8601
2727
mirage-crypto
2828
mirage-crypto-rng-lwt
@@ -31,7 +31,7 @@ pkgs.stdenv.mkDerivation rec {
3131
toml
3232
eqaf
3333
x509
34-
cstruct
34+
digestif
3535
ppx_expect
3636
odoc
3737
];

dune-project

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
(cohttp-lwt-unix (>= 2.5.4))
2121
(lwt_ssl (>= 1.1.3))
2222
(ssl (>= 0.5.9))
23-
(mirage-crypto (>= 0.11.0))
24-
(mirage-crypto-rng (>= 0.11.0))
25-
(mirage-crypto-rng-lwt (>= 0.11.0))
23+
(mirage-crypto (>= 1.0.0))
24+
(mirage-crypto-rng (>= 1.0.0))
25+
(mirage-crypto-rng-lwt (>= 1.0.0))
2626
(stdio (>= v0.14.0))
2727
(yojson (>= 1.7.0))
2828
(bot-components :dev)
@@ -42,14 +42,14 @@
4242
(lwt_ssl (>= 1.1.3))
4343
(ssl (= 0.5.9))
4444
(stdio (>= v0.14.0))
45-
(hex (>= 1.4.0))
46-
(mirage-crypto (>= 0.8.7))
45+
(ohex (>= 0.2.0))
46+
(mirage-crypto (>= 1.0.0))
4747
(eqaf (>= 0.7))
4848
(yojson (>= 1.7.0))
4949
(graphql_ppx (>= 1.2.0))
50-
(x509 (>= 0.11.2))
51-
(cstruct (>= 5.0.0))
50+
(x509 (>= 1.0.0))
5251
(ISO8601 (>= 0.2.0))
5352
(camlzip (>= 1.08))
53+
(digestif (>= 1.2.0))
5454
(odoc (and (>= 1.5.2) :with-doc)))
5555
)

src/config.ml

+1-4
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,7 @@ let github_app_id toml_data =
123123

124124
let github_private_key () =
125125
(*string_of_file_path "./github.private-key.pem"*)
126-
match
127-
Sys.getenv_exn "GITHUB_PRIVATE_KEY"
128-
|> Cstruct.of_string |> X509.Private_key.decode_pem
129-
with
126+
match Sys.getenv_exn "GITHUB_PRIVATE_KEY" |> X509.Private_key.decode_pem with
130127
| Ok (`RSA priv) ->
131128
priv
132129
| Ok _ ->

0 commit comments

Comments
 (0)