text
stringlengths 12
786k
|
---|
let test_valid_ca c ( ) = cert_public_is_pub c ; Alcotest . ( check int " CA is valid " 1 ( List . length ( Validation . valid_cas [ c ] ) ) ) |
let valid_ca_tests = [ " valid CA cacert " , ` Quick , test_valid_ca cacert ; " valid CA cacert_pathlen0 " , ` Quick , test_valid_ca cacert_pathlen0 ; " valid CA cacert_ext " , ` Quick , test_valid_ca cacert_ext ; " valid CA cacert_v1 " , ` Quick , test_valid_ca cacert_v1 ] |
let first_cert name = with_loaded_file ( " first " / ^ name ) ~ f : Certificate . decode_pem |
let first_certs = [ ( " first " , true , [ " foo . foobar . com " ; " foobar . com " ] , [ ` Digital_signature ; ` Content_commitment ; ` Key_encipherment ] , None ) ; ( " first - basicconstraint - true " , false , [ " ca . foobar . com " ] , [ ` Digital_signature ; ` Content_commitment ; ` Key_encipherment ] , None ) ; ( " first - keyusage - and - timestamping " , true , [ " ext . foobar . com " ] , [ ` Digital_signature ; ` Content_commitment ; ` Key_encipherment ] , Some [ ` Time_stamping ] ) ; ( " first - keyusage - any " , true , [ " any . foobar . com " ] , [ ` Digital_signature ; ` Content_commitment ; ` Key_encipherment ] , Some [ ` Time_stamping ; ` Any ] ) ; ( " first - keyusage - nonrep " , true , [ " key . foobar . com " ] , [ ` Content_commitment ] , None ) ; ( " first - unknown - critical - extension " , false , [ " foo . foobar . com " ; " foobar . com " ] , [ ` Digital_signature ; ` Content_commitment ; ` Key_encipherment ] , None ) ; ( " first - unknown - extension " , true , [ " foobar . com " ] , [ ` Digital_signature ; ` Content_commitment ; ` Key_encipherment ] , None ) ; ] |
let allowed_hashes = [ ` MD5 ; ` SHA1 ; ` SHA224 ; ` SHA256 ; ` SHA384 ; ` SHA512 ] |
let test_valid_ca_cert ( ? allowed_hashes = allowed_hashes ) server chain valid name ca ( ) = let anchors = ca and host = Some ( host name ) and full_chain = server :: chain in match valid , Validation . verify_chain_of_trust ~ time ~ allowed_hashes ~ host ~ anchors full_chain with | false , Ok _ -> Alcotest . fail " expected to fail , but didn ' t " | false , Error _ -> ( ) | true , Ok _ -> ( ) | true , Error c -> Alcotest . failf " valid certificate % a " Validation . pp_validation_error c |
let test_cert c usages extusage ( ) = let ku , eku = let exts = Certificate . extensions c in let ku = match Extension . ( find Key_usage exts ) with | None -> [ ] | Some ( _crit , ku ) -> ku and eku = match Extension . ( find Ext_key_usage exts ) with | None -> [ ] | Some ( _crit , eku ) -> eku in ku , eku in ( if List . for_all ( fun u -> List . mem u ku ) usages then ( ) else Alcotest . fail " key usage is different " ) ; ( match extusage with | None -> ( ) | Some x when List . for_all ( fun u -> List . mem u eku ) x -> ( ) | _ -> Alcotest . fail " extended key usage is broken " ) |
let first_cert_tests = List . mapi ( fun i ( name , _ , _ , us , eus ) -> " certificate property testing " ^ string_of_int i , ` Quick , test_cert ( first_cert name ) us eus ) first_certs |
let first_cert_ca_test ( ca , x ) = List . flatten ( List . map ( fun ( name , valid , cns , _ , _ ) -> let c = first_cert name in ( " verification CA " ^ x ^ " cn blablbalbala " , ` Quick , test_valid_ca_cert c [ ] false " blablabalbal " [ ca ] ) :: List . mapi ( fun i cn -> " certificate verification testing using CA " ^ x ^ " and CN " ^ cn ^ " " ^ string_of_int i , ` Quick , test_valid_ca_cert c [ ] valid cn [ ca ] ) cns ) first_certs ) |
let ca_tests f = List . flatten ( List . map f [ ( cacert , " cacert " ) ; ( cacert_pathlen0 , " cacert_pathlen0 " ) ; ( cacert_ext , " cacert_ext " ) ; ( cacert_ext_ku , " cacert_ext_ku " ) ; ( cacert_v1 , " cacert_v1 " ) ] ) |
let first_wildcard_certs = [ ( " first - wildcard - subjaltname " , [ ` Digital_signature ; ` Content_commitment ; ` Key_encipherment ] , None ) ; ( " first - wildcard " , [ ` Digital_signature ; ` Content_commitment ; ` Key_encipherment ] , None ) ; ] |
let first_wildcard_cert_tests = List . mapi ( fun i ( name , us , eus ) -> " wildcard certificate property testing " ^ string_of_int i , ` Quick , test_cert ( first_cert name ) us eus ) first_wildcard_certs |
let first_wildcard_cert_ca_test ( ca , x ) = List . flatten ( List . map ( fun ( name , _ , _ ) -> let c = first_cert name in ( " verification CA " ^ x ^ " cn blablbalbala " , ` Quick , test_valid_ca_cert c [ ] false " blablabalbal " [ ca ] ) :: List . mapi ( fun i cn -> " wildcard certificate CA " ^ x ^ " and CN " ^ cn ^ " " ^ string_of_int i , ` Quick , test_valid_ca_cert c [ ] true cn [ ca ] ) [ " foo . foobar . com " ; " bar . foobar . com " ; " www . foobar . com " ] @ List . mapi ( fun i cn -> " wildcard certificate CA " ^ x ^ " and CN " ^ cn ^ " " ^ string_of_int i , ` Quick , test_valid_ca_cert c [ ] false cn [ ca ] ) [ " foo . foo . foobar . com " ; " bar . fbar . com " ; " foobar . com " ; " com " ; " foobar . com . bla " ] ) first_wildcard_certs ) |
let intermediate_cas = [ ( true , " cacert " ) ; ( true , " cacert - any - ext " ) ; ( false , " cacert - ba - false " ) ; ( false , " cacert - no - bc " ) ; ( false , " cacert - no - keyusage " ) ; ( true , " cacert - ku - critical " ) ; ( true , " cacert - timestamp " ) ; ( false , " cacert - unknown " ) ; ( false , " cacert - v1 " ) ] |
let im_cert name = with_loaded_file ( " intermediate " / ^ name ) ~ f : Certificate . decode_pem |
let second_certs = [ ( " second " , [ " second . foobar . com " ] , true , [ ` Digital_signature ; ` Content_commitment ; ` Key_encipherment ] , None ) ; ( " second - any " , [ " second . foobar . com " ] , true , [ ` Digital_signature ; ` Content_commitment ; ` Key_encipherment ] , Some [ ` Any ] ) ; ( " second - subj " , [ " foobar . com " ; " foo . foobar . com " ] , true , [ ` Digital_signature ; ` Content_commitment ; ` Key_encipherment ] , None ) ; ( " second - unknown - noncrit " , [ " second . foobar . com " ] , true , [ ` Digital_signature ; ` Content_commitment ; ` Key_encipherment ] , None ) ; ( " second - nonrepud " , [ " second . foobar . com " ] , true , [ ` Content_commitment ] , None ) ; ( " second - time " , [ " second . foobar . com " ] , true , [ ` Digital_signature ; ` Content_commitment ; ` Key_encipherment ] , Some [ ` Time_stamping ] ) ; ( " second - subj - wild " , [ " foo . foobar . com " ] , true , [ ` Digital_signature ; ` Content_commitment ; ` Key_encipherment ] , None ) ; ( " second - bc - true " , [ " second . foobar . com " ] , false , [ ` Digital_signature ; ` Content_commitment ; ` Key_encipherment ] , None ) ; ( " second - unknown " , [ " second . foobar . com " ] , false , [ ` Digital_signature ; ` Content_commitment ; ` Key_encipherment ] , None ) ; ( " second - no - cn " , [ ] , false , [ ` Digital_signature ; ` Content_commitment ; ` Key_encipherment ] , None ) ; ( " second - subjaltemail " , [ ] , false , [ ` Digital_signature ; ` Content_commitment ; ` Key_encipherment ] , None ) ; ] |
let second_cert name = with_loaded_file ( " intermediate / second " / ^ name ) ~ f : Certificate . decode_pem |
let second_cert_tests = List . mapi ( fun i ( name , _ , _ , us , eus ) -> " second certificate property testing " ^ string_of_int i , ` Quick , test_cert ( second_cert name ) us eus ) second_certs |
let second_cert_ca_test ( cavalid , ca , x ) = List . flatten ( List . flatten ( List . map ( fun ( imvalid , im ) -> let chain = [ im_cert im ] in List . map ( fun ( name , cns , valid , _ , _ ) -> let c = second_cert name in ( " verification CA " ^ x ^ " cn blablbalbala " , ` Quick , test_valid_ca_cert c chain false " blablabalbal " [ ca ] ) :: List . mapi ( fun i cn -> " strict certificate verification testing using CA " ^ x ^ " and CN " ^ cn ^ " " ^ string_of_int i , ` Quick , test_valid_ca_cert c chain ( cavalid && imvalid && valid ) cn [ ca ] ) cns ) second_certs ) intermediate_cas ) ) |
let im_ca_tests f = List . flatten ( List . map f [ ( true , cacert , " cacert " ) ; ( true , cacert_ext , " cacert_ext " ) ; ( true , cacert_ext_ku , " cacert_ext_ku " ) ; ( true , cacert_v1 , " cacert_v1 " ) ; ( false , cacert_pathlen0 , " cacert_pathlen0 " ) ] ) |
let second_wildcard_cert_ca_test ( cavalid , ca , x ) = List . flatten ( List . map ( fun ( imvalid , im ) -> let chain = [ im_cert im ] in let c = second_cert " second - subj - wild " in ( " verification CA " ^ x ^ " cn blablbalbala " , ` Quick , test_valid_ca_cert c chain false " blablabalbal " [ ca ] ) :: List . mapi ( fun i cn -> " wildcard certificate verification CA " ^ x ^ " and CN " ^ cn ^ " " ^ string_of_int i , ` Quick , test_valid_ca_cert c chain ( cavalid && imvalid ) cn [ ca ] ) [ " a . foobar . com " ; " foo . foobar . com " ; " foobar . foobar . com " ; " www . foobar . com " ] @ List . mapi ( fun i cn -> " wildcard certificate verification CA " ^ x ^ " and CN " ^ cn ^ " " ^ string_of_int i , ` Quick , test_valid_ca_cert c chain false cn [ ca ] ) [ " a . b . foobar . com " ; " f . foobar . com . com " ; " f . f . f . " ; " foobar . com . uk " ; " foooo . bar . com " ; " foobar . com " ] ) intermediate_cas ) |
let second_no_cn_cert_ca_test ( _ , ca , x ) = List . flatten ( List . map ( fun ( _ , im ) -> let chain = [ im_cert im ] in let c = second_cert " second - no - cn " in ( " verification CA " ^ x ^ " cn blablbalbala " , ` Quick , test_valid_ca_cert c chain false " blablabalbal " [ ca ] ) :: List . mapi ( fun i cn -> " certificate verification CA " ^ x ^ " and CN " ^ cn ^ " " ^ string_of_int i , ` Quick , test_valid_ca_cert c chain false cn [ ca ] ) [ " a . foobar . com " ; " foo . foobar . com " ; " foobar . foobar . com " ; " foobar . com " ; " www . foobar . com " ] @ List . mapi ( fun i cn -> " certificate verification CA " ^ x ^ " and CN " ^ cn ^ " " ^ string_of_int i , ` Quick , test_valid_ca_cert c chain false cn [ ca ] ) [ " a . b . foobar . com " ; " f . foobar . com . com " ; " f . f . f . " ; " foobar . com . uk " ; " foooo . bar . com " ] ) intermediate_cas ) |
let invalid_tests = let c = second_cert " second " in let h = " second . foobar . com " in let allowed_hashes = [ ` SHA256 ; ` SHA384 ; ` SHA512 ] in [ " invalid chain " , ` Quick , test_valid_ca_cert c [ ] false h [ cacert ] ; " broken chain " , ` Quick , test_valid_ca_cert c [ cacert ] false h [ cacert ] ; " no trust anchor " , ` Quick , test_valid_ca_cert c [ im_cert " cacert " ] false h [ ] ; " 2chain invalid " , ` Quick , test_valid_ca_cert ~ allowed_hashes c [ im_cert " cacert " ; cacert ] false h [ cacert ] ; " 2chain valid " , ` Quick , test_valid_ca_cert c [ im_cert " cacert " ; cacert ] true h [ cacert ] ; " 3chain invalid " , ` Quick , test_valid_ca_cert ~ allowed_hashes c [ im_cert " cacert " ; cacert ; cacert ] false h [ cacert ] ; " 3chain valid " , ` Quick , test_valid_ca_cert c [ im_cert " cacert " ; cacert ; cacert ] true h [ cacert ] ; " chain - order invalid " , ` Quick , test_valid_ca_cert ~ allowed_hashes c [ im_cert " cacert " ; im_cert " cacert " ; cacert ] false h [ cacert ] ; " chain - order valid " , ` Quick , test_valid_ca_cert c [ im_cert " cacert " ; im_cert " cacert " ; cacert ] true h [ cacert ] ; " not a CA " , ` Quick , ( fun _ -> Alcotest . ( check int " is not a CA " 0 ( List . length ( Validation . valid_cas [ im_cert " cacert " ] ) ) ) ) ; " not a CA " , ` Quick , ( fun _ -> Alcotest . ( check int " is also not a CA " 0 ( List . length ( Validation . valid_cas [ c ] ) ) ) ) ; ] |
let x509_tests = [ " Invalid CA " , invalid_ca_tests ; " Valid CA " , valid_ca_tests ; " Certificate " , first_cert_tests ; " CA tests with certificate " , ca_tests first_cert_ca_test ; " Wildcard certificate " , first_wildcard_cert_tests ; " CA tests with wildcard certificate " , ca_tests first_wildcard_cert_ca_test ; " Second certificate test " , second_cert_tests ; " Intermediate CA with second certificate " , im_ca_tests second_cert_ca_test ; " Intermediate CA with CA and second " , im_ca_tests second_wildcard_cert_ca_test ; " Intermediate CA with second no common name " , im_ca_tests second_no_cn_cert_ca_test ; " Tests with invalid data " , invalid_tests ] |
let file_contents file = Deferred . Or_error . try_with ~ name ( : sprintf " read % s " file ) ( fun ( ) -> Reader . file_contents file ) ; ; |
let load_all_in_directory ~ directory ~ f = let open Deferred . Or_error . Let_syntax in let % bind files = Deferred . Or_error . try_with ( fun ( ) -> Sys . ls_dir directory ) in Deferred . Or_error . List . map files ~ f ( : fun file -> let % bind contents = file_contents ( directory ^/ file ) in f ~ contents ) ; ; |
module Or_error = struct include Or_error let of_result ~ to_string = Result . map_error ~ f ( : Fn . compose Error . of_string to_string ) let of_result_msg x = of_result x ~ to_string ( : fun ( ` Msg msg ) -> msg ) let lift_result_msg_of_cstruct f ~ contents = f ( Cstruct . of_string contents ) |> of_result_msg ; ; let lift_asn_error_of_cstruct f ~ contents = f ( Cstruct . of_string contents ) |> of_result ~ to_string ( : fun ( ` Parse msg ) -> msg ) ; ; end |
module CRL = struct include X509 . CRL let decode_der = Or_error . lift_result_msg_of_cstruct decode_der let revoke ? digest ~ issuer ~ this_update ? next_update ? extensions revoked_certs key = revoke ? digest ~ issuer ~ this_update ? next_update ? extensions revoked_certs key |> Or_error . of_result_msg ; ; let revoke_certificate revoked ~ this_update ? next_update crl key = revoke_certificate revoked ~ this_update ? next_update crl key |> Or_error . of_result_msg ; ; let revoke_certificates revoked ~ this_update ? next_update crl key = revoke_certificates revoked ~ this_update ? next_update crl key |> Or_error . of_result_msg ; ; let of_pem_dir ~ directory = load_all_in_directory ~ directory ~ f ( : fun ~ contents -> decode_der ~ contents |> Deferred . return ) ; ; end |
module Certificate = struct include X509 . Certificate open Deferred . Or_error . Let_syntax let decode_pem_multiple = Or_error . lift_result_msg_of_cstruct decode_pem_multiple let decode_pem = Or_error . lift_result_msg_of_cstruct decode_pem let decode_der = Or_error . lift_result_msg_of_cstruct decode_der let of_pem_file ca_file = let % bind contents = file_contents ca_file in decode_pem_multiple ~ contents |> Deferred . return ; ; let of_pem_directory ~ directory = load_all_in_directory ~ directory ~ f ( : fun ~ contents -> decode_pem_multiple ~ contents |> Deferred . return ) >>| List . concat ; ; end |
module Authenticator = struct include X509 . Authenticator module Param = struct module Chain_of_trust = struct type t = { trust_anchors : [ ` File of Filename . t | ` Directory of Filename . t ] ; allowed_hashes : Mirage_crypto . Hash . hash list option ; crls : Filename . t option } let to_certs = function | ` File file -> Certificate . of_pem_file file | ` Directory directory -> Certificate . of_pem_directory ~ directory ; ; end type t = | Chain_of_trust of Chain_of_trust . t | Cert_fingerprint of Mirage_crypto . Hash . hash * string | Key_fingerprint of Mirage_crypto . Hash . hash * string let ca_file ? allowed_hashes ? crls filename ( ) = let trust_anchors = ` File filename in Chain_of_trust { trust_anchors ; allowed_hashes ; crls } ; ; let ca_dir ? allowed_hashes ? crls directory_name ( ) = let trust_anchors = ` Directory directory_name in Chain_of_trust { trust_anchors ; allowed_hashes ; crls } ; ; let cert_fingerprint hash fingerprint = Cert_fingerprint ( hash , fingerprint ) let key_fingerprint hash fingerprint = Key_fingerprint ( hash , fingerprint ) let cleanup_fingerprint fingerprint = let known_delimiters = [ ' ' ; : ' ' ] in String . filter fingerprint ~ f ( : fun c -> not ( List . exists known_delimiters ~ f ( : Char . equal c ) ) ) |> Cstruct . of_hex ; ; let of_cas ~ time ( { trust_anchors ; allowed_hashes ; crls } : Chain_of_trust . t ) = let open Deferred . Or_error . Let_syntax in let % bind cas = Chain_of_trust . to_certs trust_anchors in let % map crls = match crls with | Some directory -> let % map crls = CRL . of_pem_dir ~ directory in Some crls | None -> return None in X509 . Authenticator . chain_of_trust ? allowed_hashes ? crls ~ time cas ; ; let of_cert_fingerprint ~ time hash fingerprint = let fingerprint = cleanup_fingerprint fingerprint in X509 . Authenticator . server_cert_fingerprint ~ time ~ hash ~ fingerprint ; ; let of_key_fingerprint ~ time hash fingerprint = let fingerprint = cleanup_fingerprint fingerprint in X509 . Authenticator . server_key_fingerprint ~ time ~ hash ~ fingerprint ; ; let time = Fn . compose Ptime . of_float_s Unix . gettimeofday let to_authenticator ~ time param = match param with | Chain_of_trust chain_of_trust -> of_cas ~ time chain_of_trust | Cert_fingerprint ( hash , fingerprint ) -> of_cert_fingerprint ~ time hash fingerprint |> Deferred . Or_error . return | Key_fingerprint ( hash , fingerprint ) -> of_key_fingerprint ~ time hash fingerprint |> Deferred . Or_error . return ; ; end end |
module Distinguished_name = struct include X509 . Distinguished_name let decode_der = Or_error . lift_result_msg_of_cstruct decode_der end |
module OCSP = struct include X509 . OCSP module Request = struct include Request let create ? certs ? digest ? requestor_name ? key cert_ids = create ? certs ? digest ? requestor_name ? key cert_ids |> Or_error . of_result_msg ; ; let decode_der = Or_error . lift_asn_error_of_cstruct decode_der end module Response = struct include Response let create_success ? digest ? certs ? response_extensions private_key responderID producedAt responses = create_success ? digest ? certs ? response_extensions private_key responderID producedAt responses |> Or_error . of_result_msg ; ; let responses t = responses t |> Or_error . of_result_msg let decode_der = Or_error . lift_asn_error_of_cstruct decode_der end end |
module PKCS12 = struct include X509 . PKCS12 let decode_der = Or_error . lift_result_msg_of_cstruct decode_der let verify password t = verify password t |> Or_error . of_result_msg end |
module Private_key = struct include X509 . Private_key let sign hash ? scheme key data = sign hash ? scheme key data |> Or_error . of_result_msg |> Or_error . map ~ f : Cstruct . to_string ; ; let decode_der = Or_error . lift_result_msg_of_cstruct decode_der let decode_pem = Or_error . lift_result_msg_of_cstruct decode_pem let of_pem_file file = let % map contents = Reader . file_contents file in decode_pem ~ contents ; ; end |
module Public_key = struct include X509 . Public_key let verify hash ? scheme ~ signature key data = let signature = Cstruct . of_string signature in let data = match data with | ` Digest data -> ` Digest ( Cstruct . of_string data ) | ` Message data -> ` Message ( Cstruct . of_string data ) in verify hash ? scheme ~ signature key data |> Or_error . of_result_msg ; ; let decode_der = Or_error . lift_result_msg_of_cstruct decode_der let decode_pem = Or_error . lift_result_msg_of_cstruct decode_pem end |
module Signing_request = struct include X509 . Signing_request let decode_der ? allowed_hashes der = Cstruct . of_string der |> decode_der ? allowed_hashes |> Or_error . of_result_msg ; ; let decode_pem pem = Cstruct . of_string pem |> decode_pem |> Or_error . of_result_msg let create subject ? digest ? extensions key = create subject ? digest ? extensions key |> Or_error . of_result_msg ; ; let sign ? allowed_hashes ? digest ? serial ? extensions t key issuer ~ valid_from ~ valid_until = sign ? allowed_hashes ? digest ? serial ? extensions t key issuer ~ valid_from ~ valid_until |> Or_error . of_result ~ to_string ( : Fmt . to_to_string X509 . Validation . pp_signature_error ) ; ; end |
let failure msg = fail @@ Failure msg |
let catch_invalid_arg th h = Lwt . catch ( fun ( ) -> th ) ( function | Invalid_argument msg -> h msg | exn -> fail exn ) |
let ( ) </> a b = a ^ " " / ^ b |
let o f g x = f ( g x ) |
let read_file path = let open Lwt_io in open_file ~ mode : Input path >>= fun file -> read file >|= Cstruct . of_string >>= fun cs -> close file >|= fun ( ) -> cs |
let read_dir path = let open Lwt_unix in let rec collect acc d = readdir_n d 10 >>= function | [ ] || -> return acc | xs -> collect ( Array . to_list xs @ acc ) d in opendir path >>= fun dir -> collect [ ] dir >>= fun entries -> closedir dir >|= fun ( ) -> entries |
let extension str = let n = String . length str in let rec scan = function | i when i = 0 -> None | i when str . [ i - 1 ] = ' . ' -> Some ( String . sub str i ( n - i ) ) | i -> scan ( pred i ) in scan n |
let private_of_pems ~ cert ~ priv_key = catch_invalid_arg ( read_file cert >|= fun pem -> match X509 . Certificate . decode_pem_multiple pem with | Ok cs -> cs | Error ( ` Msg m ) -> invalid_arg ( " failed to parse certificates " ^ m ) ) ( o failure @@ Printf . sprintf " Private certificates ( % s ) : % s " cert ) >>= fun certs -> catch_invalid_arg ( read_file priv_key >|= fun pem -> match X509 . Private_key . decode_pem pem with | Ok key -> key | Error ( ` Msg m ) -> invalid_arg ( " failed to parse private key " ^ m ) ) ( o failure @@ Printf . sprintf " Private key ( % s ) : % s " priv_key ) >>= fun pk -> return ( certs , pk ) |
let certs_of_pem path = catch_invalid_arg ( read_file path >|= fun pem -> match X509 . Certificate . decode_pem_multiple pem with | Ok cs -> cs | Error ( ` Msg m ) -> invalid_arg ( " failed to parse certificates " ^ m ) ) ( o failure @@ Printf . sprintf " Certificates in % s : % s " path ) |
let certs_of_pem_dir path = read_dir path >|= List . filter ( fun file -> extension file = Some " crt " ) >>= Lwt_list . map_p ( fun file -> certs_of_pem ( path </> file ) ) >|= List . concat |
let crl_of_pem path = catch_invalid_arg ( read_file path >|= fun data -> match X509 . CRL . decode_der data with | Ok cs -> cs | Error ( ` Msg m ) -> invalid_arg ( " failed to parse CRL " ^ m ) ) ( o failure @@ Printf . sprintf " CRL in % s : % s " path ) |
let crls_of_pem_dir = function | None -> Lwt . return None | Some path -> read_dir path >>= fun files -> Lwt_list . map_p ( fun file -> crl_of_pem ( path </> file ) ) files >|= fun crls -> Some crls |
let authenticator ? allowed_hashes ? crls param = let time ( ) = Some ( Ptime_clock . now ( ) ) in let of_cas cas = crls_of_pem_dir crls >|= fun crls -> X509 . Authenticator . chain_of_trust ? allowed_hashes ? crls ~ time cas and dotted_hex_to_cs hex = Cstruct . of_hex ( String . map ( function ' ' : -> ' ' | x -> x ) hex ) and fingerp hash fingerprint = X509 . Authenticator . server_key_fingerprint ~ time ~ hash ~ fingerprint and cert_fingerp hash fingerprint = X509 . Authenticator . server_cert_fingerprint ~ time ~ hash ~ fingerprint in match param with | ` Ca_file path -> certs_of_pem path >>= of_cas | ` Ca_dir path -> certs_of_pem_dir path >>= of_cas | ` Key_fingerprint ( hash , fp ) -> return ( fingerp hash fp ) | ` Hex_key_fingerprint ( hash , fp ) -> let fp = dotted_hex_to_cs fp in return ( fingerp hash fp ) | ` Cert_fingerprint ( hash , fp ) -> return ( cert_fingerp hash fp ) | ` Hex_cert_fingerprint ( hash , fp ) -> let fp = dotted_hex_to_cs fp in return ( cert_fingerp hash fp ) |
let cint i = " " $ ^ ( string_of_int i ) |
let off i a = String . concat [ string_of_int i ; " ( " ; a ; " ) " ] |
let my_print_string s ctx = Out_channel . output_string ctx . out s ; ctx |
let nacmd c = String . concat [ " \ t " ; c ; " \ n " ] |> my_print_string |
let slcmd c a = String . concat [ " \ t " ; c ; " \ t " ; a ; " \ n " ] |> my_print_string |
let bicmd c a b = String . concat [ " \ t " ; c ; " \ t " ; a ; " , " ; b ; " \ n " ] |> my_print_string |
let dot_string s = " \ t . string " " \ ^ s ^ " " \\ n " |> my_print_string |
let globl f = " \ t . globl " ^ f ^ " \ n " |> my_print_string |
let label f = f ^ " :\ n " |> my_print_string |
let movb = bicmd " movb " |
let movl = bicmd " movl " |
let movq = bicmd " movq " |
let pushq = slcmd " pushq " |
let popq = slcmd " popq " |
let leaq = bicmd " leaq " |
let sete = slcmd " sete " |
let setne = slcmd " setne " |
let setl = slcmd " setl " |
let setle = slcmd " setle " |
let setg = slcmd " setg " |
let setge = slcmd " setge " |
let cmpl = bicmd " cmpl " |
let addl = bicmd " addl " |
let addq = bicmd " addq " |
let subl = bicmd " subl " |
let subq = bicmd " subq " |
let imul = bicmd " imul " |
let imulq = bicmd " imulq " |
let mulq = bicmd " mulq " |
let idivl = slcmd " idivl " |
let idivq = slcmd " idivq " |
let divq = slcmd " divq " |
let ands = bicmd " and " |
let andb = bicmd " andb " |
let ors = bicmd " or " |
let orl = bicmd " orl " |
let xor = bicmd " xor " |
let sall = bicmd " sall " |
let sarl = bicmd " sarl " |
let neg = slcmd " neg " |
let nnot = slcmd " nnot " |
let jz = slcmd " jz " |
let je = slcmd " je " |
let jmp = slcmd " jmp " |
let call = slcmd " call " |
let nop = nacmd " nop " |
let enter = bicmd " enter " |
let leave = nacmd " leave " |
let ret = nacmd " ret " |
let retq = nacmd " retq " |
type condition = X86_ast . condition = | L | GE | LE | G | B | AE | BE | A | E | NE | O | NO | S | NS | P | NP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.