From 9c20e2b6e947f46cc1009c53828c5dd9d7bb664a Mon Sep 17 00:00:00 2001 From: Jesper Louis Andersen Date: Fri, 1 Sep 2017 14:31:18 +0200 Subject: [PATCH 1/3] Make the location of OpenSSL configurable Apple devices as well as older software installations of Linux are likely to have too old OpenSSLs for the token signing to work. Fix this by making the location of the OpenSSL binary configurable in the configuration knobs. --- src/apns.app.src | 3 +++ src/apns_utils.erl | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/apns.app.src b/src/apns.app.src index 0c3efec..ca44b23 100644 --- a/src/apns.app.src +++ b/src/apns.app.src @@ -13,6 +13,9 @@ ]}, {modules, []}, {mod, {apns_app, []}}, + {env, [ + {openssl_path, "openssl"} + ]}, {maintainers,["Inaka"]}, {licenses,["Apache 2.0"]}, {links,[{"Github","https://github.com/inaka/apns4erl"}]}, diff --git a/src/apns_utils.erl b/src/apns_utils.erl index 4050cb9..2b3143c 100644 --- a/src/apns_utils.erl +++ b/src/apns_utils.erl @@ -35,9 +35,10 @@ -spec sign(binary()) -> binary(). sign(Data) -> {ok, KeyPath} = application:get_env(apns, token_keyfile), + {ok, Openssl} = application:get_env(apns, openssl_path), Command = "printf '" ++ binary_to_list(Data) ++ - "' | openssl dgst -binary -sha256 -sign " ++ KeyPath ++ " | base64", + "' | " ++ Openssl ++ " dgst -binary -sha256 -sign " ++ KeyPath ++ " | base64", {0, Result} = apns_os:cmd(Command), strip_b64(list_to_binary(Result)). @@ -67,3 +68,4 @@ seconds_to_timestamp(Secs) -> -spec strip_b64(binary()) -> binary(). strip_b64(BS) -> binary:list_to_bin(binary:split(BS, [<<"\n">>, <<"=">>], [global])). + From 2e062e2f83720b1bc19c38150a79bc6b5f752356 Mon Sep 17 00:00:00 2001 From: Jesper Louis Andersen Date: Thu, 7 Sep 2017 13:33:47 +0200 Subject: [PATCH 2/3] Use openssl_command over _path Using openssl_path could be interpreted as a directory to the bin-directory, not the `openssl(1)` command itself. Correct this by using a better name. --- src/apns.app.src | 2 +- src/apns_utils.erl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apns.app.src b/src/apns.app.src index ca44b23..5050d37 100644 --- a/src/apns.app.src +++ b/src/apns.app.src @@ -14,7 +14,7 @@ {modules, []}, {mod, {apns_app, []}}, {env, [ - {openssl_path, "openssl"} + {openssl_command, "openssl"} ]}, {maintainers,["Inaka"]}, {licenses,["Apache 2.0"]}, diff --git a/src/apns_utils.erl b/src/apns_utils.erl index 2b3143c..793a88d 100644 --- a/src/apns_utils.erl +++ b/src/apns_utils.erl @@ -35,7 +35,7 @@ -spec sign(binary()) -> binary(). sign(Data) -> {ok, KeyPath} = application:get_env(apns, token_keyfile), - {ok, Openssl} = application:get_env(apns, openssl_path), + {ok, Openssl} = application:get_env(apns, openssl_command), Command = "printf '" ++ binary_to_list(Data) ++ "' | " ++ Openssl ++ " dgst -binary -sha256 -sign " ++ KeyPath ++ " | base64", From fe3cf200ce537f122177bb5eaa99f080a997a31f Mon Sep 17 00:00:00 2001 From: Jesper Louis Andersen Date: Thu, 7 Sep 2017 13:35:25 +0200 Subject: [PATCH 3/3] Make Elvis happy and avoid a too long line --- src/apns_utils.erl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/apns_utils.erl b/src/apns_utils.erl index 793a88d..65881d5 100644 --- a/src/apns_utils.erl +++ b/src/apns_utils.erl @@ -36,9 +36,9 @@ sign(Data) -> {ok, KeyPath} = application:get_env(apns, token_keyfile), {ok, Openssl} = application:get_env(apns, openssl_command), - Command = "printf '" ++ - binary_to_list(Data) ++ - "' | " ++ Openssl ++ " dgst -binary -sha256 -sign " ++ KeyPath ++ " | base64", + Command = "printf '" ++ binary_to_list(Data) ++ + "' | " ++ Openssl ++ " dgst -binary -sha256 -sign " ++ + KeyPath ++ " | base64", {0, Result} = apns_os:cmd(Command), strip_b64(list_to_binary(Result)).