Passing certificate and key as der_bin () to Erlang using ssl

I took the certificate and key from the PEM file and decrypted base64 to binary and put them in Certand Key.

Then, to open the connection, I have the following code.

make_connection(Cert, Key) ->
    Options = [{cert, Cert}, {key, Key}, {mode, binary}],
    Timeout = 1000,
    % {ok, Socket} replaced for debugging...
    Socket = ssl:connect(?PUSH_SERVER_HOST, ?PUSH_SERVER_PORT,
            Options, Timeout),
    Socket.

The call make_connection(Cert, Key)returns {error, {eoptions, {key, <<...>>}}}.

When I replace Certboth Keywith the path to the PEM file and Options = [{certfile, ... keyfile ...}], it works and creates the SSL socket as intended.

So I don’t miss anything using Certand Keyalone?

+3
source share
1 answer

Looking at the ssl.erl file from the application ssl, it seems that you should use a tuple as yours Key, not binary:

validate_option(key, {KeyType, Value}) when is_binary(Value),
                       KeyType == rsa;
                       KeyType == dsa ->
    {KeyType, Value};

. , , , (der_bin()) .

+1

Source: https://habr.com/ru/post/1784405/


All Articles