Skip to content

Commit

Permalink
Merge pull request #14 from sg2342/update_dependencies
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
sg2342 authored Feb 13, 2023
2 parents 19f2a33 + e8c64c0 commit 5b0e3a6
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 48 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: ocaml-rfc6287

on: [push, pull_request]

jobs:
tests:
name: Tests

strategy:
fail-fast: false
matrix:
ocaml-version: ["4.14.0", "4.13.1", "4.12.0", "4.11.1", "4.10.1"]
operating-system: [ubuntu-latest]

runs-on: ${{ matrix.operating-system }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Use OCaml ${{ matrix.ocaml-version }}
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: ${{ matrix.ocaml-version }}

- name: Install dependencies
run: opam install --deps-only -t .

- name: Build
run: opam exec -- dune build

- name: Test
run: opam exec -- dune runtest
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

52 changes: 31 additions & 21 deletions examples/ocra_tool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ let initx i_f i_s i_k i_c i_p i_ph i_cw i_tw =
try Cstruct.of_hex (strip_0x x) with Invalid_argument _ ->
e "invalid pin_hash"
in
if Cstruct.len w = Mirage_crypto.Hash.digest_size dgst then Some w
if Cstruct.length w = Mirage_crypto.Hash.digest_size dgst then Some w
else e "invalid pin_hash"
in
let cw =
Expand Down Expand Up @@ -198,7 +198,7 @@ let infox i_f =

(** "challenge" command *)
let challengex i_f =
let () = Mirage_crypto_rng_unix.initialize () in
let () = Mirage_crypto_rng_unix.initialize (module Mirage_crypto_rng.Fortuna) in
try
let t = of_file (cred_file i_f) in
let _ = Printf.printf "%s\n" (Rfc6287.challenge t.s) in
Expand Down Expand Up @@ -339,8 +339,10 @@ let init_cmd =
options to credential file ..." ]
@ help_secs
in
( Term.(ret (pure initx $ i_f $ i_s $ i_k $ i_c $ i_p $ i_ph $ i_cw $ i_tw))
, Term.info "init" ~sdocs:copts_sect ~doc ~man )
let term = Term.(ret (const initx $ i_f $ i_s $ i_k $ i_c $ i_p $ i_ph $ i_cw $ i_tw))
and info = Cmd.info "init" ~sdocs:copts_sect ~doc ~man
in
Cmd.v info term

let info_cmd =
let doc = "Show content of OCRA credential file." in
Expand All @@ -351,7 +353,10 @@ let info_cmd =
options in credential file ..." ]
@ help_secs
in
(Term.(ret (pure infox $ i_f)), Term.info "info" ~doc ~sdocs:copts_sect ~man)
let term = Term.(ret (const infox $ i_f))
and info = Cmd.info "info" ~doc ~sdocs:copts_sect ~man
in
Cmd.v info term

let challenge_cmd =
let doc = "Generate OCRA challenge" in
Expand All @@ -362,8 +367,10 @@ let challenge_cmd =
the credential file ..." ]
@ help_secs
in
( Term.(ret (pure challengex $ i_f))
, Term.info "challenge" ~doc ~sdocs:copts_sect ~man )
let term = Term.(ret (const challengex $ i_f))
and info = Cmd.info "challenge" ~doc ~sdocs:copts_sect ~man
in
Cmd.v info term

let verify_cmd =
let i_q =
Expand All @@ -383,8 +390,10 @@ let verify_cmd =
credential file if the OCRA suite specifies C." ]
@ help_secs
in
( Term.(ret (pure verifyx $ i_f $ i_q $ i_a))
, Term.info "verify" ~doc ~sdocs:copts_sect ~man )
let term = Term.(ret (const verifyx $ i_f $ i_q $ i_a))
and info = Cmd.info "verify" ~doc ~sdocs:copts_sect ~man
in
Cmd.v info term

let response_cmd =
let i_q =
Expand All @@ -399,21 +408,22 @@ let response_cmd =
incremented." ]
@ help_secs
in
( Term.(ret (pure responsex $ i_f $ i_q))
, Term.info "response" ~doc ~sdocs:copts_sect ~man )
let term = Term.(ret (const responsex $ i_f $ i_q))
and info = Cmd.info "response" ~doc ~sdocs:copts_sect ~man
in
Cmd.v info term

let help_cmd =
Term.(ret (const (fun _ -> `Help (`Pager, None)) $ i_f))

let default_cmd =
let cmds = [init_cmd; info_cmd; challenge_cmd; verify_cmd; response_cmd]

let () =
let doc =
"create and view OCRA credential files, generate challenges,\n \
calculate and verify responses"
in
let man = help_secs in
( Term.(ret (pure (fun _ -> `Help (`Pager, None)) $ i_f))
, Term.info "ocra_tool" ~sdocs:copts_sect ~doc ~man )

let cmds = [init_cmd; info_cmd; challenge_cmd; verify_cmd; response_cmd]

let () =
match Term.eval_choice ~catch:false default_cmd cmds with
| `Error _ -> exit 1
| _ -> exit 0
let info = Cmd.info "ocra_tool" ~sdocs:copts_sect ~doc ~man in
let group = Cmd.group ~default:help_cmd info cmds in
exit (Cmd.eval group)
12 changes: 6 additions & 6 deletions lib/rfc6287.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ let crypto_function cf key buf =
| Some x ->
let v =
let open Cstruct in
let o = get_uint8 hmac (len hmac - 1) land 0x0f in
let o = get_uint8 hmac (length hmac - 1) land 0x0f in
BE.get_uint32 hmac o
in
let s0 =
Expand Down Expand Up @@ -204,14 +204,14 @@ let format_data_input ?time (di, ss) c q p s t =
| `N -> dec2bin q
| `H -> hex2bin q
in
blit y 0 qbuf 0 (len y) ;
blit y 0 qbuf 0 (length y) ;
qbuf
in
(* P, optional *)
let fp =
match (di.p, p) with
| None, None -> create 0
| Some dgst, Some (`Digest y) when Mirage_crypto.Hash.digest_size dgst = len y -> y
| Some dgst, Some (`Digest y) when Mirage_crypto.Hash.digest_size dgst = length y -> y
| Some _, Some (`Digest _) -> failwith "P length conflicts suite"
| Some dgst, Some (`String s) -> Mirage_crypto.Hash.digest dgst (Cstruct.of_string s)
| None, Some _ -> failwith "no P in suite"
Expand All @@ -221,7 +221,7 @@ let format_data_input ?time (di, ss) c q p s t =
let fs =
match (di.s, s) with
| None, None -> create 0
| Some n, Some y when len y = n -> y
| Some n, Some y when length y = n -> y
| Some _, Some _ -> failwith "S length conflicts suite"
| None, Some _ -> failwith "no S in suite"
| Some _, None -> failwith "suite requires S"
Expand All @@ -240,12 +240,12 @@ let format_data_input ?time (di, ss) c q p s t =
| None, Some _, _ -> failwith "no T in suite"
| Some _, None, _ -> failwith "suite requires T"
in
let c_off = match c with None -> None | Some _ -> Some (len fss) in
let c_off = match c with None -> None | Some _ -> Some (length fss) in
let t_off =
match t with
| None -> None
| Some _ ->
Some (List.fold_left (fun a y -> a + len y) 0 [fss; fc; fq; fp; fs])
Some (List.fold_left (fun a y -> a + length y) 0 [fss; fc; fq; fp; fs])
in
(Cstruct.concat [fss; fc; fq; fp; fs; ft], (c_off, t_off))

Expand Down
4 changes: 2 additions & 2 deletions rfc6287.opam
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ depends: [
"dune" {>= "1.1"}
"mirage-crypto"
"mirage-crypto-pk"
"mirage-crypto-rng"
"cstruct" {>= "3.2.0"}
"mirage-crypto-rng" {>= "0.11.0"}
"cstruct" {>= "6.0.0"}
"astring"
"hex"
"rresult"
Expand Down
2 changes: 1 addition & 1 deletion test/test_rfc6287.ml
Original file line number Diff line number Diff line change
Expand Up @@ -326,5 +326,5 @@ let suite =
"coverage" >::: coverage]

let () =
Mirage_crypto_rng_unix.initialize () ;
Mirage_crypto_rng_unix.initialize (module Mirage_crypto_rng.Fortuna) ;
run_test_tt_main suite

0 comments on commit 5b0e3a6

Please sign in to comment.