开发者

openssl header ssl

开发者 https://www.devze.com 2022-12-24 19:08 出处:网络
is there additional header which is presented by openssl before sending the message to soc开发者_开发技巧ket ?

is there additional header which is presented by openssl before sending the message to soc开发者_开发技巧ket ?

Thanks


I assume you're talking about TLS ("Secured TCP").

Then yes. Once the handshake between client and server is done, the "data" messages usually start with 3 special bytes (if I remember well) that indicates to the SSL layer that the frame is ciphered.

On the other hand, you cannot assume that the size of a ciphered frame will be the same of the raw frame/data.

Here you get an example function in C/C++.

    bool isCiphered(const char* buf, size_t buflen)
    {
        if (buflen < 3)
        {
            return false;
        }

        uint8_t c = buf[0];

        switch (c)
        {
            case 0x14:
            case 0x15:
            case 0x16:
            case 0x17:
                {
                    uint8_t v1 = buf[1];
                    uint8_t v2 = buf[2];

                    /* TLS v1 */
                    if ((v1 == 0x03) && (v2 == 0x01))
                    {
                        return true;
                    }

                    /* DTLS v1 */
                    if ((v1 == 0xfe) && (v2 == 0xff))
                    {
                        return true;
                    }

                    break;
                }
        }

        return false;
    }

I had to adapt my existing code so i'm not sure that compiles, but you should get the idea.

0

精彩评论

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