开发者

Passing cert and key as der_bin() in Erlang with ssl

开发者 https://www.devze.com 2023-02-03 13:08 出处:网络
I\'ve taken the certificate and key from the PEM file and decoded the base64 to binary and put them into Cert and Key.

I've taken the certificate and key from the PEM file and decoded the base64 to binary and put them into Cert and Key.

Then I have the following code to open a connection.

make_connection(Cert, Key) ->
    Options = [{cert, Cert}, {key, Key}, {mode, binary}],
    Timeo开发者_如何学运维ut = 1000,
    % {ok, Socket} replaced for debugging...
    Socket = ssl:connect(?PUSH_SERVER_HOST, ?PUSH_SERVER_PORT,
            Options, Timeout),
    Socket.

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

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

So am I missing anything with the usage of cert and key alone?


Looking at the ssl.erl file from the ssl application, it seems like you are supposed to use a tuple as your Key, rather than the binary:

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

Where the type of the key is specified. It seems there's a bug in the documentation for the connect function, where it says that you are supposed to use a binary (der_bin()) as your Key.

0

精彩评论

暂无评论...
验证码 换一张
取 消