Exemplo n.º 1
0
        public static String getPasswordDigest(String nonceBase64, String createTime, String password)
        {
            byte[] nonceBinary   = EncodingHelper.Base64Decode(nonceBase64);
            byte[] utctimeBinary = EncodingHelper.String2Byte(createTime);
            byte[] pwdBinary     = EncodingHelper.String2Byte(password);

            byte[] combined = new byte[nonceBinary.Length + utctimeBinary.Length + pwdBinary.Length];

            System.Buffer.BlockCopy(nonceBinary, 0, combined, 0, nonceBinary.Length);
            System.Buffer.BlockCopy(utctimeBinary, 0, combined, nonceBinary.Length, utctimeBinary.Length);
            System.Buffer.BlockCopy(pwdBinary, 0, combined, nonceBinary.Length + utctimeBinary.Length, pwdBinary.Length);

            SHA1Managed sha1 = new SHA1Managed();

            byte[] passwordHash = sha1.ComputeHash(combined);

            String hashValue = System.Convert.ToBase64String(passwordHash);

            return(hashValue);
        }
Exemplo n.º 2
0
        public String ONVIF_GetSystemLog()
        {
            setNonce();
            /* get synced-time using base time */
            baseDateTime = DigestPassword.getCurrentTime(startDate, baseDateTime);
            /* make createTime string */
            _wsdUsernameToken.Create = DigestPassword.getCreatedTimeString(baseDateTime);
            /* make digest password */
            //_wsdUsernameToken.Password = DigestPassword.getPasswordDigest("LKqI6G/AikKCQrN0zqZFlg==", "2010-09-16T07:50:45Z", "userpassword");
            _wsdUsernameToken.Password = DigestPassword.getPasswordDigest(_wsdUsernameToken.Nonce,
                                                                          _wsdUsernameToken.Create,
                                                                          _wsdUsernameToken.plainPassword);
            /* set packet */
            StringBuilder reqMessage = new StringBuilder();

            reqMessage.Append("<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\">");
            reqMessage.Append("<s:Header>");
            reqMessage.Append("<Security ");
            reqMessage.Append("s:mustUnderstand=\"1\" ");
            reqMessage.Append("xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">");
            reqMessage.Append("<UsernameToken><Username>" + _wsdUsernameToken.Username + "</Username>");
            reqMessage.Append("<Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\">" + _wsdUsernameToken.Password + "</Password>");
            reqMessage.Append("<Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">" + _wsdUsernameToken.Nonce + "</Nonce>");
            reqMessage.Append("<Created xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">" + _wsdUsernameToken.Create + "</Created>");
            reqMessage.Append("</UsernameToken></Security></s:Header>");
            reqMessage.Append("<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");
            reqMessage.Append("<GetSystemLog xmlns=\"http://www.onvif.org/ver10/device/wsdl\"><LogType>System</LogType></GetSystemLog></s:Body></s:Envelope>");

            /* encoding */
            byte[] reqMessageBinary = EncodingHelper.String2Byte(reqMessage.ToString());

            /* Get Url */
            String Url = onvifdev.devicexaddr;

            try
            {
                _http.Connect(Url);
                _http.setONVIFHeader("\"http://www.onvif.org/ver10/device/wsdl/GetSystemLog\"");
                _http.Write(reqMessageBinary);

                String paramStr = _http.Read();
                parentForm.settbLogBox("\r\nFunction OK : " + System.Reflection.MethodBase.GetCurrentMethod().Name + "\n");

                /* parser soap response */
                XmlDocument xdoc = new XmlDocument();
                xdoc.LoadXml(paramStr.ToString());

                XmlNamespaceManager xnamespace = XMLControl.getAllNamespaces(xdoc);
                onvifdev.schemaPrefix = xnamespace.LookupPrefix(ONVIFNamespace.schema);
                onvifdev.devicePrefix = xnamespace.LookupPrefix(ONVIFNamespace.device);
                /* get function xaddr in document */

                /*
                 *   <SOAP-ENV:Header></SOAP-ENV:Header>
                 *    <SOAP-ENV:Body>
                 *      <tds:GetSystemLogResponse>
                 *        <tds:SystemLog>
                 *          <tds2:String>Mar 13 08:08:27 VB-
                 */
                String logStr = XMLControl.getLogStr(xdoc, onvifdev);
                return(logStr);
            }
            catch (XmlException xe)
            {
                parentForm.settbLogBox("\r\nXml Exception : " + xe.Message + System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
            catch (WebException we)
            {
                parentForm.settbLogBox("\r\nWeb Exception : " + we.Message + System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
            return("test");
        }
Exemplo n.º 3
0
        /* global value get/set I/F */

        /* ONVIF Control API */
        #region ONVIFControlAPI
        public void ONVIF_GetSystemDateAndTime()
        {
            XmlDocument soapEnvXml = new XmlDocument();

            /* set packet */
            StringBuilder reqMessage = new StringBuilder();

            reqMessage.Append("<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\">");
            reqMessage.Append("<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");
            reqMessage.Append("<GetSystemDateAndTime xmlns=\"http://www.onvif.org/ver10/device/wsdl\"/></s:Body></s:Envelope>");

            /* encoding */
            byte[] reqMessageBinary = EncodingHelper.String2Byte(reqMessage.ToString());

            /* Get Url */
            String Url = deviceURL + "/onvif/device_service";

            _http.Connect(Url);

            _http.setONVIFHeader("\"http://www.onvif.org/ver10/device/wsdl/GetSystemDateAndTime\"");
            _http.Write(reqMessageBinary);

            String paramStr = _http.Read();

            /* parser soap response */
            XmlDocument xdoc = new XmlDocument();

            xdoc.LoadXml(paramStr.ToString());

            XmlNamespaceManager xnamespace = XMLControl.getAllNamespaces(xdoc);

            onvifdev.schemaPrefix = xnamespace.LookupPrefix(ONVIFNamespace.schema);
            /* test */
#if false
            XmlElement             xelements  = xdoc.DocumentElement;
            XmlAttributeCollection xAttribute = xdoc.DocumentElement.Attributes;
            /* need to find prefix of namespace:/ver10/schema */
            foreach (XmlAttribute attr in xAttribute)
            {
                /* need to find  prefix schema of "http://www.onvif.org/ver10/schema" */
                bool result = attr.Value.Equals("http://www.onvif.org/ver10/schema", StringComparison.Ordinal);

                if (result == true)
                {
                    String[] split_word = attr.Name.Split(':');
                    schemaPrefix = split_word[(split_word.Length) - 1];
                    break;
                }
            }
#endif
            try
            {
                /* Onvif Application Programmers Guide - Created – The UtcTime when the request is made. */
                XmlNodeList xnode_list = xdoc.GetElementsByTagName(onvifdev.schemaPrefix + ":UTCDateTime");

                XmlNode time_node = xnode_list[0].FirstChild;
                XmlNode date_node = xnode_list[0].LastChild;

                String _hour = time_node[onvifdev.schemaPrefix + ":Hour"].InnerText;
                String _min  = time_node[onvifdev.schemaPrefix + ":Minute"].InnerText;
                String _sec  = time_node[onvifdev.schemaPrefix + ":Second"].InnerText;

                String _year  = date_node[onvifdev.schemaPrefix + ":Year"].InnerText;
                String _month = date_node[onvifdev.schemaPrefix + ":Month"].InnerText;
                String _day   = date_node[onvifdev.schemaPrefix + ":Day"].InnerText;

                DateTime currentTime = new DateTime(Int32.Parse(_year), Int32.Parse(_month), Int32.Parse(_day)
                                                    , Int32.Parse(_hour), Int32.Parse(_min), Int32.Parse(_sec));

                /* deviceTime is UTC/GMT time */
                baseDateTime        = currentTime;
                onvifdev.timeoffset = baseDateTime;
                /* save current time for calcurate passedTime */
                startDate = DateTime.Now;
                parentForm.settbLogBox("\r\nFunction OK : " + System.Reflection.MethodBase.GetCurrentMethod().Name + "\n");
            }
            catch (NullReferenceException nre)
            {
                parentForm.settbLogBox("\r\nNull 참조 에러 : " + nre.Message + "\n" + System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }