【问题标题】:Passing cert and key as der_bin() in Erlang with ssl使用 ssl 在 Erlang 中将证书和密钥作为 der_bin() 传递
【发布时间】:2011-06-06 04:23:16
【问题描述】:

我已从 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 单独使用的任何内容?

【问题讨论】:

    标签: ssl erlang


    【解决方案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()) 作为您的密钥。

    【讨论】:

      猜你喜欢
      • 2011-08-17
      • 2013-01-02
      • 2013-10-01
      • 2018-09-13
      • 2017-06-18
      • 1970-01-01
      • 2016-07-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多