使用ssl将证书和密钥作为der_bin()传递给Erlang

时间:2011-01-09 19:10:22

标签: ssl erlang

我从PEM文件中获取了证书和密钥,并将base64解码为二进制文件并将其放入CertKey

然后我有以下代码来打开连接。

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.

致电make_connection(Cert, Key)会返回{error, {eoptions, {key, <<...>>}}}

当我将CertKey替换为PEM文件的路径和Options = [{certfile, ... keyfile ...}]时,它可以正常工作并创建SSL套接字。

因此,我错过了仅使用certkey的任何内容吗?

1 个答案:

答案 0 :(得分:1)

查看ssl应用程序中的ssl.erl文件,您似乎应该使用元组作为Key,而不是二进制文件:

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

指定键的类型。似乎the documentation for the connect function中存在一个错误,它表示你应该使用二进制文件(der_bin())作为你的密钥。