Skip to content

Conversation

flaribbit
Copy link
Member

demo

function love.run()
    print('love.run()')
    local https = require('Zenitha.luasec.https')
    local ssl = require('Zenitha.luasec.ssl')
    local socket = require('socket')

    ---------------------------------------------------------------------------
    -- https
    print(https.request('https://localhost:443'))

    ---------------------------------------------------------------------------
    -- tls
    local body = '' ..
        'GET / HTTP/1.1\r\n' ..
        'Host: localhost:443\r\n\r\n'

    local params = {
        mode = 'client',
        protocol = 'any',
    }
    local conn = socket.tcp()
    conn:connect('localhost', 443)
    -- TLS/SSL initialization
    conn = ssl.wrap(conn, params)
    conn:dohandshake()
    --
    conn:send(body)
    print(conn:receive('*l'))
    conn:close()
end

以上代码已测试可用

至于websocket,把下面的代码放到tcp握手之后,websocket握手之前,就好了

    -- TLS/SSL initialization
    conn = ssl.wrap(conn, params)
    conn:dohandshake()

还有一个问题是,我只能保证同步的websocket程序中能用。

具体原因是我不确定luasec是否支持异步,他可能没考虑。一种可能的结果是localhost没事,远程延迟导致ssl握手炸了。

@flaribbit
Copy link
Member Author

flaribbit commented May 15, 2022

至于iOS系统,需要静态链接luasec库,然后在love2d源码中调用以下代码,理论上就可以用了。具体位置是 luaL_newstate 之后,载入游戏代码之前。@ParticleG

luaopen_ssl_core(L);
luaopen_ssl_context(L);
luaopen_ssl_x509(L);
luaopen_ssl_config(L);

@ParticleG
Copy link
Member

好的,websocket目前没有解决方案么

@flaribbit
Copy link
Member Author

好的,websocket目前没有解决方案么

说完了啊

用旧的同步版本的自己开线程的程序,加上两行握手就行。

@MrZ626
Copy link
Collaborator

MrZ626 commented May 15, 2022

ssl是要自己加的dll还是新love自带来着

@ParticleG
Copy link
Member

要自己加,love没带

@MrZ626
Copy link
Collaborator

MrZ626 commented May 15, 2022

希望框架只靠这堆lua文件就能用,还是pr到具体应用里吧,再加一个子模块

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants