Skip to content

Commit

Permalink
Update to mirage-crypto 1.0.0 API (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zimmi48 authored Oct 22, 2024
2 parents 001a4ca + e720713 commit f4b1980
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 31 deletions.
8 changes: 4 additions & 4 deletions bot-components.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ depends: [
"lwt_ssl" {>= "1.1.3"}
"ssl" {= "0.5.9"}
"stdio" {>= "v0.14.0"}
"hex" {>= "1.4.0"}
"mirage-crypto" {>= "0.8.7"}
"ohex" {>= "0.2.0"}
"mirage-crypto" {>= "1.0.0"}
"eqaf" {>= "0.7"}
"yojson" {>= "1.7.0"}
"graphql_ppx" {>= "1.2.0"}
"x509" {>= "0.11.2"}
"cstruct" {>= "5.0.0"}
"x509" {>= "1.0.0"}
"ISO8601" {>= "0.2.0"}
"camlzip" {>= "1.08"}
"digestif" {>= "1.2.0"}
"odoc" {>= "1.5.2" & with-doc}
]
build: [
Expand Down
7 changes: 3 additions & 4 deletions bot-components/GitHub_app.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ let github_headers token =
; ("authorization", "Bearer " ^ token) ]

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

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

Expand Down
5 changes: 2 additions & 3 deletions bot-components/GitHub_subscriptions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,8 @@ let receive_github ~secret headers body =
match Header.get headers "X-Hub-Signature" with
| Some signature ->
let expected =
Mirage_crypto.Hash.SHA1.hmac ~key:(Cstruct.of_string secret)
(Cstruct.of_string body)
|> Hex.of_cstruct |> Hex.show |> f "sha1=%s"
Digestif.SHA1.(to_raw_string (hmac_string ~key:secret body))
|> Ohex.encode |> f "sha1=%s"
in
if Eqaf.equal signature expected then Ok (Some install_id)
else Error "Webhook signed but with wrong signature."
Expand Down
4 changes: 2 additions & 2 deletions bot-components/dune
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(library
(name Bot_components)
(public_name bot-components)
(libraries base camlzip cohttp-lwt-unix cstruct eqaf hex mirage-crypto stdio
str x509 yojson ISO8601)
(libraries base camlzip cohttp-lwt-unix eqaf ohex mirage-crypto stdio str
x509 yojson ISO8601 digestif)
(private_modules GraphQL_query GitHub_GraphQL Utils)
(modules_without_implementation GitHub_types GitLab_types)
(preprocess
Expand Down
6 changes: 3 additions & 3 deletions coq-bot.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ depends: [
"cohttp-lwt-unix" {>= "2.5.4"}
"lwt_ssl" {>= "1.1.3"}
"ssl" {>= "0.5.9"}
"mirage-crypto" {>= "0.11.0"}
"mirage-crypto-rng" {>= "0.11.0"}
"mirage-crypto-rng-lwt" {>= "0.11.0"}
"mirage-crypto" {>= "1.0.0"}
"mirage-crypto-rng" {>= "1.0.0"}
"mirage-crypto-rng-lwt" {>= "1.0.0"}
"stdio" {>= "v0.14.0"}
"yojson" {>= "1.7.0"}
"bot-components" {dev}
Expand Down
8 changes: 4 additions & 4 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ pkgs ? import (fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/280db3decab4cbeb22a4599bd472229ab74d25e1.tar.gz";
sha256 = "sha256:17n9wji64l7d16s8r100ypwlxkmwrypll4q3wkkfjswbilxkqjr6";
url = "https://github.com/NixOS/nixpkgs/archive/5ea573ca476915e0ccefb99be5687e4150fa049b.tar.gz";
sha256 = "0hsg6xjj4iclfrvplsf0rd9xiwkaazvmlp609qiwka65v7wcjja2";
}) { } }:

pkgs.stdenv.mkDerivation rec {
Expand All @@ -22,7 +22,7 @@ pkgs.stdenv.mkDerivation rec {
camlzip
cohttp
cohttp-lwt-unix
hex
ohex
iso8601
mirage-crypto
mirage-crypto-rng-lwt
Expand All @@ -31,7 +31,7 @@ pkgs.stdenv.mkDerivation rec {
toml
eqaf
x509
cstruct
digestif
ppx_expect
odoc
];
Expand Down
14 changes: 7 additions & 7 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
(cohttp-lwt-unix (>= 2.5.4))
(lwt_ssl (>= 1.1.3))
(ssl (>= 0.5.9))
(mirage-crypto (>= 0.11.0))
(mirage-crypto-rng (>= 0.11.0))
(mirage-crypto-rng-lwt (>= 0.11.0))
(mirage-crypto (>= 1.0.0))
(mirage-crypto-rng (>= 1.0.0))
(mirage-crypto-rng-lwt (>= 1.0.0))
(stdio (>= v0.14.0))
(yojson (>= 1.7.0))
(bot-components :dev)
Expand All @@ -42,14 +42,14 @@
(lwt_ssl (>= 1.1.3))
(ssl (= 0.5.9))
(stdio (>= v0.14.0))
(hex (>= 1.4.0))
(mirage-crypto (>= 0.8.7))
(ohex (>= 0.2.0))
(mirage-crypto (>= 1.0.0))
(eqaf (>= 0.7))
(yojson (>= 1.7.0))
(graphql_ppx (>= 1.2.0))
(x509 (>= 0.11.2))
(cstruct (>= 5.0.0))
(x509 (>= 1.0.0))
(ISO8601 (>= 0.2.0))
(camlzip (>= 1.08))
(digestif (>= 1.2.0))
(odoc (and (>= 1.5.2) :with-doc)))
)
5 changes: 1 addition & 4 deletions src/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,7 @@ let github_app_id toml_data =

let github_private_key () =
(*string_of_file_path "./github.private-key.pem"*)
match
Sys.getenv_exn "GITHUB_PRIVATE_KEY"
|> Cstruct.of_string |> X509.Private_key.decode_pem
with
match Sys.getenv_exn "GITHUB_PRIVATE_KEY" |> X509.Private_key.decode_pem with
| Ok (`RSA priv) ->
priv
| Ok _ ->
Expand Down

0 comments on commit f4b1980

Please sign in to comment.