agsh / onvif

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

ONVIF Over HTTPS #213

Closed gigincg closed 2 years ago

gigincg commented 2 years ago

Is there a way to use ONVIF on a HTTPS Camera Endpoint. Using Port 443 doesn't seem to be working. The camera endpoint seems to be working fine when I use the curl command

When I run the curl command like this:

curl -i https://mycamera.live/onvif/device_service/ -d '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetSystemDateAndTime xmlns="http://www.onvif.org/ver10/device/wsdl"/></s:Body></s:Envelope>'

I get the following Response

Date: Wed, 24 Nov 2021 05:53:25 GMT
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 2798
Connection: keep-alive
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
CF-Cache-Status: DYNAMIC
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxs%2F5XUpdipAcbDGYZceinYcBmgfdt7IWyne6YeCy9ibiG2zBTrJ1SLCaFb7Ke0ZfRFjKFK8yqhjR%2FuHBrNPuKg%3D%3D"}],"group":"cf-nel","max_age":604800}
NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
Server: cloudflare
CF-RAY: 6b3xxxxxxxxxxxx-SIN
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400, h3-28=":443"; ma=86400, h3-27=":443"; ma=86400

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl" xmlns:tst="http://www.onvif.org/ver10/storage/wsdl" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:dn="http://www.onvif.org/ver10/network/wsdl" xmlns:tns1="http://www.onvif.org/ver10/topics" xmlns:tmd="http://www.onvif.org/ver10/deviceIO/wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl" xmlns:wsoap12="http://schemas.xmlsoap.org/wsdl/soap12" xmlns:http="http://schemas.xmlsoap.org/wsdl/http" xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:wsadis="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:wsrf-bf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:wsntw="http://docs.oasis-open.org/wsn/bw-2" xmlns:wsrf-rw="http://docs.oasis-open.org/wsrf/rw-2" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsrf-r="http://docs.oasis-open.org/wsrf/r-2" xmlns:trc="http://www.onvif.org/ver10/recording/wsdl" xmlns:tse="http://www.onvif.org/ver10/search/wsdl" xmlns:trp="http://www.onvif.org/ver10/replay/wsdl" xmlns:tnshik="http://www.hikvision.com/2011/event/topics" xmlns:hikwsd="http://www.onvifext.com/onvif/ext/ver10/wsdl" xmlns:hikxsd="http://www.onvifext.com/onvif/ext/ver10/schema" xmlns:tas="http://www.onvif.org/ver10/advancedsecurity/wsdl" xmlns:tr2="http://www.onvif.org/ver20/media/wsdl" xmlns:axt="http://www.onvif.org/ver20/analytics"><env:Body><tds:GetSystemDateAndTimeResponse><tds:SystemDateAndTime><tt:DateTimeType>Manual</tt:DateTimeType>
<tt:DaylightSavings>false</tt:DaylightSavings>
<tt:TimeZone><tt:TZ>CST-5:30:00</tt:TZ>
</tt:TimeZone>
<tt:UTCDateTime><tt:Time><tt:Hour>5</tt:Hour>
<tt:Minute>53</tt:Minute>
<tt:Second>24</tt:Second>
</tt:Time>
<tt:Date><tt:Year>2021</tt:Year>
<tt:Month>11</tt:Month>
<tt:Day>24</tt:Day>
</tt:Date>
</tt:UTCDateTime>
<tt:LocalDateTime><tt:Time><tt:Hour>11</tt:Hour>
<tt:Minute>23</tt:Minute>
<tt:Second>24</tt:Second>
</tt:Time>
<tt:Date><tt:Year>2021</tt:Year>
<tt:Month>11</tt:Month>
<tt:Day>24</tt:Day>
</tt:Date>
</tt:LocalDateTime>
</tds:SystemDateAndTime>
</tds:GetSystemDateAndTimeResponse>
</env:Body>
</env:Envelope>

But when I use

new Cam(
  {
    hostname: "mycamera.live",
    username: "user",
    password: "pass",
    port: 443,
  },
  function (err) {
    this.gotoPreset(
      {
        preset: 1,
      },
      () => {
        console.log("Callback");
      }
    );
  }
);

I get the following Error, The same that I get if I give an invalid URL

➜  project git:(master) ✗ node test.js
/home/user/git/project/node_modules/onvif/lib/ptz.js:59
                                '<ProfileToken>' + (options.profileToken || this.activeSource.profileToken) + '</ProfileToken>' +
                                                                                              ^

TypeError: Cannot read property 'profileToken' of undefined
    at Cam.gotoPreset (/home/user/git/project/node_modules/onvif/lib/ptz.js:59:67)
chriswiggins commented 2 years ago

Hi @gigincg - try adding useSecure: true to your options:

new Cam(
  {
    hostname: "mycamera.live",
    username: "user",
    password: "pass",
    port: 443,
    useSecure: true
  },
  function (err) {
    this.gotoPreset(
      {
        preset: 1,
      },
      () => {
        console.log("Callback");
      }
    );
  }
);
gigincg commented 2 years ago

@chriswiggins Thanks that worked! Didn't see the option. My bad.