agsh / onvif

ONVIF node.js implementation
http://agsh.github.io/onvif/
MIT License
696 stars 237 forks source link

ONVIF SOAP Fault during connect with Vivotek camera's #301

Closed svk23 closed 1 year ago

svk23 commented 1 year ago

Cam.getSystemDateAndTime() fails for some Vivotek camera's with:

ONVIF SOAP Fault: An error was discovered processing the <wsse:Security> header.

This seems to be a similar problem to the Panasonic and Digital Barriers camera's where authorization is required to retrieve the system date and time. The difference is that these Vivotek's return a slightly different message: NotAuthorized:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xs="http://www.w3.org/2000/10/XMLSchema"
              xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
              xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:ter="http://www.onvif.org/ver10/error"
              xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:wsrf-bf="http://docs.oasis-open.org/wsrf/bf-2"
              xmlns:wsrf-r="http://docs.oasis-open.org/wsrf/r-2">
    <env:Body>
        <env:Fault>
            <env:Code>
                <env:Value>env:Sender</env:Value>
                <env:Subcode>
                    <env:Value>ter:NotAuthorized</env:Value>
                </env:Subcode>
            </env:Code>
            <env:Reason>
                <env:Text xml:lang="en">An error was discovered processing the &lt;wsse:Security&gt; header.</env:Text>
            </env:Reason>
        </env:Fault>
    </env:Body>
</env:Envelope>

If I extend the check in cam.js to include the test for notauthorized the connection to the camera works as expected. For example:

if ((xml && (xml.toLowerCase().includes('sender not authorized') || xml.toLowerCase().includes('unauthorized') 
        || xml.toLowerCase().includes('notauthorized'))) || (statusCode && statusCode === 401)
)
RogerHardiman commented 1 year ago

Could you see what the StatusCode is when you get 'notauthorized'. String matching is fine and I can add in your fix, but I wondered what the Status Code was it may be worth adding to the 401 check

(in the mean time, I've applied your patch)

svk23 commented 1 year ago

Could you see what the StatusCode is when you get 'notauthorized'. String matching is fine and I can add in your fix, but I wondered what the Status Code was it may be worth adding to the 401 check

(in the mean time, I've applied your patch)

Good question, but the value of the statusCode when the XML contains notauthorized is 500, so personally I would not add that to status code part of the condition.

(thanks for applying the change!)

RogerHardiman commented 1 year ago

500 - internal server error. What a weird Error Code to return.

As luck was have it I was testing some other changes in the ONVIF library today so have bumped it (including your fix) to 0.6.9 and it is now on NPM