Skip to content

TLS is broken when using Bun #1112

@michei69

Description

@michei69

Describe the bug

For some reason, connecting to an xmpp:// server, then upgrading to tls automatically seems to fail when using Bun. There's no problems in nodeJS though.

Note: I know this is technically an issue with Bun's implementation of node:tls, and not necessarily of xmpp.js's use of it, but im creating the issue over here because i honestly have no internal idea on how node:tls is truly used inside the project. Once it's discovered, we can move/migrate/create a new issue at Bun's side (if it's not reported already)

I wonder if it's related to bun#23556 or bun#24374 as well, although this appears to be happening both on Arch and on Windows 11. (Logs are from Arch)

Logs

Node.js

status connecting xmpp://jc.smule.com
status connect 
status opening 
status open <stream:stream id="15846425431735129396" version="1.0" xml:lang="en" xmlns:stream="http://etherx.jabber.org/streams" from="jc.smule.com" xmlns="jabber:client"/>
IN
<stream:features>
    <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">
        <required/>
    </starttls>
</stream:features>
OUT
<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
IN
<proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
status opening 
status open <stream:stream id="3213348643858085085" version="1.0" xml:lang="en" xmlns:stream="http://etherx.jabber.org/streams" to="[REDACTED]@jc.smule.com" from="jc.smule.com" xmlns="jabber:client"/>
IN
<stream:features>
    <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
        <mechanism>PLAIN</mechanism>
        <mechanism>X-OAUTH2</mechanism>
    </mechanisms>
    <sasl-channel-binding xmlns="urn:xmpp:sasl-cb:0">
        <channel-binding type="tls-exporter"/>
        <channel-binding type="tls-server-end-point"/>
    </sasl-channel-binding>
    <authentication xmlns="urn:xmpp:sasl:2">
        <inline>
            <bind xmlns="urn:xmpp:bind:0">
                <inline>
                    <feature var="urn:xmpp:sm:3"/>
                </inline>
            </bind>
            <sm xmlns="urn:xmpp:sm:3"/>
        </inline>
        <mechanism>PLAIN</mechanism>
        <mechanism>X-OAUTH2</mechanism>
    </authentication>
</stream:features>
OUT
<authenticate xmlns="urn:xmpp:sasl:2" mechanism="PLAIN">
    <initial-response>
        <hidden xmlns="xmpp.js"/>
    </initial-response>
    <user-agent id="81caa81a-940e-4c98-b455-e5882bc944e9"/>
    <bind xmlns="urn:xmpp:bind:0">
        <tag>smule855c34</tag>
        <enable xmlns="urn:xmpp:sm:3" resume="true"/>
    </bind>
</authenticate>
IN
<success xmlns="urn:xmpp:sasl:2">
    <bound xmlns="urn:xmpp:bind:0">
        <enabled resume="true" max="10" id="g2gCbQAAABZzbXVsZTg1NWMzNC5sQ3M1YVV0d2x1bQAAAAiDYiwN1i6REw==" xmlns="urn:xmpp:sm:3"/>
    </bound>
    <authorization-identifier>[REDACTED]@jc.smule.com/smule855c34.lCs5aUtwlu</authorization-identifier>
    <additional-data>
        <hidden xmlns="xmpp.js"/>
    </additional-data>
</success>
status online [REDACTED]@jc.smule.com/smule855c34.lCs5aUtwlu
IN
<stream:features>
    <sm xmlns="urn:xmpp:sm:2"/>
    <sm xmlns="urn:xmpp:sm:3"/>
</stream:features>
OUT
<presence to="cf[REDACTED]@conference.jc.smule.com/[REDACTED]">
    <x xmlns="http://jabber.org/protocol/muc">
        <password/>
        <history maxstanzas="1"/>
    </x>
</presence>
OUT
<resume xmlns="urn:xmpp:sm:3" h="0" previd="g2gCbQAAABZzbXVsZTg1NWMzNC5sQ3M1YVV0d2x1bQAAAAiDYiwN1i6REw=="/>
IN
<presence to="[REDACTED]@jc.smule.com/smule855c34.lCs5aUtwlu" from="cf[REDACTED]@conference.jc.smule.com" id="14541335985161252543">
    <c ver="ikPzXtDtEk8LWW8Hppy81GTflcE=" node="http://www.process-one.net/en/ejabberd/" hash="sha-1" xmlns="http://jabber.org/protocol/caps"/>
</presence>
IN
<r xmlns="urn:xmpp:sm:3"/>
IN
<presence xml:lang="en-IR" to="[REDACTED]@jc.smule.com/smule855c34.lCs5aUtwlu" from="cf[REDACTED]@conference.jc.smule.com/[REDACTED]">
    <x xmlns="http://jabber.org/protocol/muc#user">
        <item jid="[REDACTED]@jc.smule.com/UWZuSpAvuwygzoF+Vvi5bQ" role="participant" affiliation="none"/>
    </x>
    <priority>0</priority>
</presence>
IN
<presence xml:lang="en" to="[REDACTED]@jc.smule.com/smule855c34.lCs5aUtwlu" from="cf[REDACTED]@conference.jc.smule.com/[REDACTED]">
    <x xmlns="http://jabber.org/protocol/muc#user">
        <item jid="[REDACTED]@jc.smule.com/Jpmcyx/SQDGY9TTr8SqSdQ" role="participant" affiliation="none"/>
    </x>
</presence>
OUT
<a xmlns="urn:xmpp:sm:3" h="1"/>
IN
<presence xml:lang="en-NL" to="[REDACTED]@jc.smule.com/smule855c34.lCs5aUtwlu" from="cf[REDACTED]@conference.jc.smule.com/[REDACTED]">
    <x xmlns="http://jabber.org/protocol/muc#user">
        <item jid="[REDACTED]@jc.smule.com/ZA+8UwU+5F94QgzLUThqzQ" role="participant" affiliation="none"/>
    </x>
    <priority>0</priority>
</presence>
IN
<presence xml:lang="en" to="[REDACTED]@jc.smule.com/smule855c34.lCs5aUtwlu" from="cf[REDACTED]@conference.jc.smule.com/[REDACTED]">
    <x xmlns="http://jabber.org/protocol/muc#user">
        <item jid="[REDACTED]@jc.smule.com/sR7y3sqtQxyaplILDHeIJg" role="moderator" affiliation="owner"/>
    </x>
</presence>
IN
<presence xml:lang="en" to="[REDACTED]@jc.smule.com/smule855c34.lCs5aUtwlu" from="cf[REDACTED]@conference.jc.smule.com/[REDACTED]">
    <x xmlns="http://jabber.org/protocol/muc#user">
        <item jid="[REDACTED]@jc.smule.com/smule855c34.lCs5aUtwlu" role="participant" affiliation="none"/>
        <status code="100"/>
        <status code="110"/>
    </x>
</presence>
IN
<message to="[REDACTED]@jc.smule.com/smule855c34.lCs5aUtwlu" from="cf[REDACTED]@conference.jc.smule.com" type="groupchat">
    <subject/>
</message>
OUT
<r xmlns="urn:xmpp:sm:3"/>
IN
<failed xmlns="urn:xmpp:sm:3">
    <unexpected-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
    <text xml:lang="en" xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Stream management is already enabled</text>
</failed>
OUT
<enable xmlns="urn:xmpp:sm:3" resume="true"/>
IN
<r xmlns="urn:xmpp:sm:3"/>
OUT
<a xmlns="urn:xmpp:sm:3" h="7"/>
IN
<a h="1" xmlns="urn:xmpp:sm:3"/>

Bun

status connecting xmpp://jc.smule.com
status connect 
status opening 
status open <stream:stream id="18297535536692171957" version="1.0" xml:lang="en" xmlns:stream="http://etherx.jabber.org/streams" from="jc.smule.com" xmlns="jabber:client"/>
IN
<stream:features>
    <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">
        <required/>
    </starttls>
</stream:features>
OUT
<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
IN
<proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
status opening 
57 |   }
58 | 
59 |   onText(str) {
60 |     const { cursor } = this;
61 |     if (!cursor) {
62 |       this.emit("error", new XMLError(`${str} must be a child.`));
^
XMLError: J▒�0��9{h��zad�=31��@i�S must be a child.
at onText (/windows/Users/miki/Desktop/projects/smule-api/node_modules/@xmpp/xml/lib/Parser.js:62:26)
at emit (node:events:95:22)
at write (/windows/Users/miki/Desktop/projects/smule-api/node_modules/ltx/lib/parsers/ltx.js:121:22)
at write (/windows/Users/miki/Desktop/projects/smule-api/node_modules/@xmpp/xml/lib/Parser.js:70:17)
at _onData (/windows/Users/miki/Desktop/projects/smule-api/node_modules/@xmpp/connection/index.js:50:17)
at emit (node:events:95:22)
at addChunk (internal:streams/readable:265:47)
at readableAddChunkPushByteMode (internal:streams/readable:243:18)
at data (node:net:280:52)

OUT
<stream:error>
    <bad-format xmlns="urn:ietf:params:xml:ns:xmpp-streams"/>
</stream:error>
57 |   }
58 | 
59 |   onText(str) {
60 |     const { cursor } = this;
61 |     if (!cursor) {
62 |       this.emit("error", new XMLError(`${str} must be a child.`));
^
XMLError: J▒�0��9{h��zad�=31��@i�S must be a child.
at onText (/windows/Users/miki/Desktop/projects/smule-api/node_modules/@xmpp/xml/lib/Parser.js:62:26)
at emit (node:events:95:22)
at write (/windows/Users/miki/Desktop/projects/smule-api/node_modules/ltx/lib/parsers/ltx.js:121:22)
at write (/windows/Users/miki/Desktop/projects/smule-api/node_modules/@xmpp/xml/lib/Parser.js:70:17)
at _onData (/windows/Users/miki/Desktop/projects/smule-api/node_modules/@xmpp/connection/index.js:50:17)
at emit (node:events:95:22)
at addChunk (internal:streams/readable:265:47)
at readableAddChunkPushByteMode (internal:streams/readable:243:18)
at data (node:net:280:52)

status closing 
status close [object Object]
status disconnecting 
57 |   }
58 | 
59 |   onText(str) {
60 |     const { cursor } = this;
61 |     if (!cursor) {
62 |       this.emit("error", new XMLError(`${str} must be a child.`));
^
XMLError: J▒�0��9{h��zad�=31��@i�S must be a child.
at onText (/windows/Users/miki/Desktop/projects/smule-api/node_modules/@xmpp/xml/lib/Parser.js:62:26)
at emit (node:events:95:22)
at write (/windows/Users/miki/Desktop/projects/smule-api/node_modules/ltx/lib/parsers/ltx.js:121:22)
at write (/windows/Users/miki/Desktop/projects/smule-api/node_modules/@xmpp/xml/lib/Parser.js:70:17)
at _onData (/windows/Users/miki/Desktop/projects/smule-api/node_modules/@xmpp/connection/index.js:50:17)
at emit (node:events:95:22)
at addChunk (internal:streams/readable:265:47)
at readableAddChunkPushByteMode (internal:streams/readable:243:18)
at data (node:net:280:52)
status disconnect [object Object]

Environment

@xmpp/client: 0.14.0
@xmpp/debug: 0.14.0
@xmpp/jid: 0.14.0
@xmpp/resolve: 0.14.0
@xmpp/starttls: 0.14.0

Running bun v1.3.5, nodejs v25.2.1 on CachyOS (Linux 6.18.2-3-cachyos)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions