Giter Site home page Giter Site logo

Comments (19)

oleaasbo avatar oleaasbo commented on September 2, 2024

lib/RTSPClient.ts:317 -> let match = WWW_AUTH_REGEX.exec(authHeader)

returns

nonce="MTU0ODQxODQ4NS45ODA3MjA6SSBhbSBSVFNQIFNFUlZFUg==",nonce,MTU0ODQxODQ4NS45ODA3MjA6SSBhbSBSVFNQIFNFUlZFUg==

from yellowstone.

oleaasbo avatar oleaasbo commented on September 2, 2024

Progress:
The regex work if realm="rtsp server" contains no spaces (realm="rtspserver")

from yellowstone.

RogerHardiman avatar RogerHardiman commented on September 2, 2024

Just adding in some extra info.
HikVision cameras also have a realm with a space in them and it caused the C# based SharpRTSP library to fail too (I'm one of the SharpRTSP authors so had to fix my own bug there).

If you can do a fix in a fork one of us can commit it.

from yellowstone.

oleaasbo avatar oleaasbo commented on September 2, 2024

Solved for my case:
Regex should be:

([a-z]+)=\"([^,]+)\"

Don't know if that breaks something else.

Also had to change the "while loop" that loops through variable "match" to:

let match = WWW_AUTH_REGEX.exec(authHeader)
while (match != null) {
    const prop = match[1];

    if (prop == "realm" && match[2]) {
        realm = match[2];
    }

    if (prop == "nonce" && match[2]) {
        nonce = match[2];
    }

    match = WWW_AUTH_REGEX.exec(authHeader);
}

from yellowstone.

oleaasbo avatar oleaasbo commented on September 2, 2024

The fix can be found here:
https://gitlab.oleaasbo.no/public-projects/nodejs/yellowstone

from yellowstone.

RogerHardiman avatar RogerHardiman commented on September 2, 2024

I think the RegEx needs to be
([a-zA-Z]+)="([^\"]*)"

The RFC says the part before the '=' can be any case.
So this allows for the match[1] to be 1 or more characters of mixed case.

Then it has to match an Equals
This it has to match a Quote

Then it can match zero or mode characters that are Not a Quote - > Match[2]
This allows for empty strings eg realm="" it.
It also allows for commas in the Quoted string eg real="rtsp server, the best in the world"

Then it has to match a Quote

Anyone care to test the Regex ?
([a-zA-Z]+)="([^\"]*)"

from yellowstone.

oleaasbo avatar oleaasbo commented on September 2, 2024

I tested it and it worked ok. But I would like to add:

([a-zA-Z]+)\s?=\s?"?([^,"]*)

Demo

However, it is not perfect because the RFC gives an example i did not manage to fully regex.
RFC Example

WWW-Authenticate: Digest
       realm="[email protected]",
       qop="auth, auth-int",
       algorithm=SHA-256,
       nonce="7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v",
       opaque="FQhe/qaU925kfnzjCev0ciny7QMkPqMAFRtzCUYo5tdS"

Specifically

qop="auth, auth-int",

from yellowstone.

RogerHardiman avatar RogerHardiman commented on September 2, 2024

@oleaasbo Thanks for testing and the are Regex that handles whitespace either side of the Equals

I thought I'd got a solution to handle qop="auth, auth-int" but it is not properly working.
I'd made this change
([a-zA-Z]+)\s*=\s*(\".*\"|[^,\s]+)

  1. I changed the Whitespace \s? to \s* to allow it to pass over multiple spaces
  2. The second Match now has two Alternatives.
    Alternative 1 is to match Quote, characters, Quote.
    Alternative 2 are characters that do not include whitespace or comma

From https://www.debuggex.com
image

But this fails when there are multiple items on one line (ie no Newlines)

So I need another go.

from yellowstone.

RogerHardiman avatar RogerHardiman commented on September 2, 2024

Hi

Fixed it with a Lazy .* when matching between the Quotes

([a-zA-Z]+)\s*=\s*(\".*?\"|[^,\s]+)

But just realised this now requires strings with the quotes back to Javascript.

So needs more work

from yellowstone.

oleaasbo avatar oleaasbo commented on September 2, 2024

Thanks for working more on this. I have expanded on your contribution:

([a-zA-Z]+)\s*=\s*"?((?<=").*?(?=")|.*?(?=\s*[a-zA-Z]+\s*\=)|.+[^=])

This will remove quotes. I also changed the way "no qoutes" get detected. You match with ", \s", but that would not work if "algorithm=SHA-256" (from the example above) is the last element in the header.
I also made sure that "no qoutes"-matches return all values if separated with "," (comma).

from yellowstone.

RogerHardiman avatar RogerHardiman commented on September 2, 2024

That's a clever RegEx.

I was thinking of a simpler RegEx and then some Javascript code.
I had gone back to
([a-zA-Z]+)\s*=\s*(".*?"|[^,\s]+)

and then was going to do the following (in pseudo code)
if (match[2] && match[2].startswith(Quote) && match[2].endswith(Quote) then
Trim the Quote from the start and the finish

I don't mind which way we go.

from yellowstone.

oleaasbo avatar oleaasbo commented on September 2, 2024

This regex will not work in all cases

([a-zA-Z]+)\s*=\s*(".*?"|[^,\s]+)

I might overcomplicate things now :)
Demo of what might happen but probably will not happen.

from yellowstone.

oleaasbo avatar oleaasbo commented on September 2, 2024

I would like to change one last time :)

([a-zA-Z]+)\s*=\s*"?((?<=").*?(?=")|.*?(?=,?\s*[a-zA-Z]+\s*\=)|.+[^=])

To remove "," (comma) from "algorithm=SHA-256, MD5," in the example above this comment.

from yellowstone.

RogerHardiman avatar RogerHardiman commented on September 2, 2024

I had a look at RFC 7616. It has examples where there are two different encryption algorithms in use at the same time. It does that with multiple Digest blocks, and does not try and put two algorithms into the same ``algorithm=xxx``` statement.

So I don't think we would need to cater for algorithm=SHA-256, MD5,

from yellowstone.

oleaasbo avatar oleaasbo commented on September 2, 2024

Yeah, I know :) But the thought that my RegEx theoretically could fail triggers my OCD..

from yellowstone.

mbullington avatar mbullington commented on September 2, 2024

Thank you for your contribution!

So the final RegEx to use is ([a-zA-Z]+)\s*=\s*"?((?<=").*?(?=")|.*?(?=,?\s*[a-zA-Z]+\s*\=)|.+[^=]) ?

from yellowstone.

mbullington avatar mbullington commented on September 2, 2024

Actually closing as it was committed by @RogerHardiman , thanks! Should we update the RegEx again or use the one committed?

from yellowstone.

oleaasbo avatar oleaasbo commented on September 2, 2024

I am using the last RegEx I shared in this issue report.
The Updated RegEX can be found here

from yellowstone.

RogerHardiman avatar RogerHardiman commented on September 2, 2024

I'd not committed the final RegEx

from yellowstone.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.