websocat icon indicating copy to clipboard operation
websocat copied to clipboard

Authentication

Open alfredneu opened this issue 5 years ago • 13 comments

Great tool, but I cannot find a way to do authenticated connects with basic auth. Could you please tell me how to archive this or add this option?

I am working in a business environment where no server allows anonymous connections. I am quite surprised nobody missed this before.

Thanks!

alfredneu avatar Jun 26 '19 15:06 alfredneu

OK, as usual: Having searched for an hour and written the request I immediately find the solution ;-)

websocat -H="Authorization: Basic "

That does the trick. Still, a command line option would be nice

alfredneu avatar Jun 26 '19 15:06 alfredneu

Hi, Does anyone know how I can authenticate using WWW-Authenticate? I have tried adding the headers manually similar to @alfredneu however that does not work.

tony1661 avatar Jun 27 '19 21:06 tony1661

@tony1661 , Do you mean requesting authentication as a server?

That would be something like

websocat -s 1234 --server-header 'WWW-Authenticate: Basic realm="Hello from Websocat", charset="UTF-8"'

But that does not work currently, as it just allows connection without authentication.

Checking if client-supplied Basic auth is valid or not is not implemented yet.


Or do you mean interpreting WWW-Authenticate response from server and interactively asking for username and password?

Maybe a customized error message suggesting to use a new command line with auth header would happen in some future version of Websocat.

vi avatar Jun 27 '19 21:06 vi

@vi Thanks for your response. What I am trying to do is authenticate to a web socket as a client. I am able to authenticate using curl however I cannot send and receive data. My curl command is below and I was wondering if I could do something similar with websocat.

curl -A "Avaya-IPOSysMonitor" --verbose --digest --user Username:Password --header 'Connection: Upgrade' --header 'Host: 36.103.125.5' --header 'Upgrade: websocket' --header 'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==' --header 'Sec-WebSocket-Protocol: sysmonitor' --header 'Sec-WebSocket-Version: 13' 192.168.222.10/sysmonitor/

tony1661 avatar Jun 28 '19 11:06 tony1661

--digest is non-basic HTTP authentication. It requires repeated request and is not supported yet in Websocat.

vi avatar Jun 28 '19 13:06 vi

@vi Gotcha. Thanks for the info!

tony1661 avatar Jun 28 '19 14:06 tony1661

I just submitted https://github.com/websockets-rs/rust-websocket/pull/236 (low-level websocket crate used by this project). This is where the user credentials should be handled. Nothing should be necessary for websocat if this gets merged.

zopieux avatar Jul 13 '19 01:07 zopieux

WebSocat 2.0 will be based on websocket-lowlevel. websocket depends on legacy hyper 0.10, which is not going to be packaged for Debian, so it's a dependency to be removed.

Fortunately, the HTTP handling part of someday's Websocat 2.0 already turns username:password into a Authentication: Basic header.

vi avatar Jul 13 '19 06:07 vi

On the other hand, I can publish some additional Websocat 1.5.0 with the pull request in if you would find that useful.

vi avatar Jul 13 '19 06:07 vi

That would definitely solve the immediate issue at hand, yes. Thanks for your concern!

zopieux avatar Jul 13 '19 13:07 zopieux

Released v1.5.0.

vi avatar Jul 14 '19 12:07 vi

Unfortunately embedding auth in the URL does not work if the username contains an @. Compare e.g.

curl -u [email protected]:s3cr3t https://some.server/

Workaround:

websocat -H="Authorization: Basic $(echo -n [email protected]:s3cr3t | base64)" wss://some.server/

jglick avatar Feb 23 '21 19:02 jglick

Dupe of #115? Sounds like this was resolved in c320d7970e5d6a1b8f97fd7eeccfdec6bd0851d9?

jglick avatar Apr 29 '21 11:04 jglick