diff --git a/rebar.config b/rebar.config index 7def98c79..b2f6ab4d7 100644 --- a/rebar.config +++ b/rebar.config @@ -90,6 +90,7 @@ {if_var_true, erlang_deprecated_types, {d, 'ERL_DEPRECATED_TYPES'}}, {if_version_above, "18", {d, 'STRONG_RAND_BYTES'}}, {if_version_above, "17", {d, 'GB_SETS_ITERATOR_FROM'}}, + {if_have_fun, {public_key, short_name_hash, 1}, {d, 'SHORT_NAME_HASH'}}, {if_var_true, hipe, native}, {src_dirs, [asn1, src, {if_var_true, tools, tools}, diff --git a/rebar.config.script b/rebar.config.script index 19142b9ee..d2ee31213 100644 --- a/rebar.config.script +++ b/rebar.config.script @@ -141,6 +141,15 @@ ProcessVars = fun(_F, [], Acc) -> _ -> F(F, Tail, Acc) end; + (F, [{if_have_fun, MFA, Value} | Tail], Acc) -> + {Mod, Fun, Arity} = MFA, + code:ensure_loaded(Mod), + case erlang:function_exported(Mod, Fun, Arity) of + true -> + F(F, Tail, ProcessSingleVar(F, Value, Acc)); + false -> + F(F, Tail, Acc) + end; (F, [Other1 | Tail1], Acc) -> F(F, Tail1, [F(F, Other1, []) | Acc]); (F, Val, Acc) when is_tuple(Val) -> diff --git a/src/ejabberd_pkix.erl b/src/ejabberd_pkix.erl index f99a2c12e..7c03f1772 100644 --- a/src/ejabberd_pkix.erl +++ b/src/ejabberd_pkix.erl @@ -393,7 +393,7 @@ check_ca_dir() -> -spec find_local_issuer(cert()) -> {ok, cert()} | {error, {bad_cert, unknown_ca}}. find_local_issuer(Cert) -> {ok, {_, IssuerID}} = public_key:pkix_issuer_id(Cert, self), - Hash = public_key:short_name_hash(IssuerID), + Hash = short_name_hash(IssuerID), filelib:fold_files( ca_dir(), Hash ++ "\\.[0-9]+", false, fun(_, {ok, IssuerCert}) -> @@ -514,3 +514,11 @@ get_cert_path(G, [Root|_] = Acc) -> get_cert_path(G, [V|Acc]) end, Es) end. + +-ifdef(SHORT_NAME_HASH). +short_name_hash(IssuerID) -> + public_key:short_name_hash(IssuerID). +-else. +short_name_hash(_) -> + "". +-endif.