예제 #1
0
        /// <summary>
        /// <P>Creates a mostly unitialized SHAiButtonUser object.  This constructor
        /// merely copies the coprocessors 7 byte binding code into a local cache
        /// and stores the name of the account service file used for all user
        /// iButtons.</P>
        ///
        /// <P>Since this constructor leaves data unitialized, you should be very
        /// careful with the use of it.  It is expected that after calling this
        /// constructor, the user will call <code>setiButton</code> to finish the
        /// initialization process.  On memory-starved platforms, this should help
        /// optimize memory usage.</P>
        /// </summary>
        /// <param name="copr"> The SHAiButtonCopr to which the user object is tied.  This
        ///        Coprocessor contains the necessary binding code and service
        ///        filename, necessary for both locating a user and recreating his
        ///        unique secret.
        /// </param>
        /// <seealso cref= #SHAiButtonUser18(SHAiButtonCopr,OneWireContainer18,bool,byte[]) </seealso>
        /// <seealso cref= #SHAiButtonUser18(SHAiButtonCopr) </seealso>
        public SHAiButtonUser18(SHAiButtonCopr copr)
        {
            //save a copy of the binding code
            copr.getBindCode(this.fullBindCode, 0);
            Array.Copy(this.fullBindCode, 4, this.fullBindCode, 12, 3);

            //create string representation of service filename
            copr.getFilename(this.serviceFile, 0);
            this.strServiceFilename = Encoding.Unicode.GetString(this.serviceFile) + "." + (int)copr.FilenameExt;
        }
예제 #2
0
        /// <summary>
        /// <P>Initialize a DS1963S as a fresh user iButton for a given SHA service.
        /// This constructor not only creates the service file for the user iButton
        /// using the TMEX file structure, but it also installs the master
        /// authentication secret and binds it to the iButton (making it unique for
        /// a particular button).  Optionally, the device can be formatted before
        /// the service file is installed.</P>
        /// </summary>
        /// <param name="copr"> The SHAiButtonCopr to which the user object is tied.  This
        ///        Coprocessor contains the necessary binding code and service
        ///        filename, necessary for both locating a user and recreating his
        ///        unique secret. </param>
        /// <param name="owc"> The DS1963S iButton that this object will refer to. </param>
        /// <param name="formatDevice"> If <code>true</code>, the TMEX filesystem will be
        ///        formatted before the account service file is created. </param>
        /// <param name="authSecret"> The master authentication secret for the systm.
        /// </param>
        /// <exception cref="OneWireIOException"> on a 1-Wire communication error such as
        ///         reading an incorrect CRC from a 1-Wire device.  This could be
        ///         caused by a physical interruption in the 1-Wire Network due to
        ///         shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. </exception>
        /// <exception cref="OneWireException"> on a communication or setup error with the 1-Wire
        ///         adapter
        /// </exception>
        /// <seealso cref= #SHAiButtonUser18(SHAiButtonCopr,OneWireContainer18) </seealso>
        /// <seealso cref= #SHAiButtonUser18(SHAiButtonCopr) </seealso>
        public SHAiButtonUser18(SHAiButtonCopr copr, OneWireContainer18 owc, bool formatDevice, byte[] authSecret) : this(copr)
        {
            //setup service filename

            //hold container reference
            this.ibc = owc;

            //and address
            this.address = owc.Address;

            if (!createServiceFile(owc, strServiceFilename, formatDevice))
            {
                throw new OneWireException("Failed to create service file.");
            }

            //save a copy of the binding code
            copr.getBindCode(this.fullBindCode, 0);
            Array.Copy(this.fullBindCode, 4, this.fullBindCode, 12, 3);

            //setup the fullBindCode with rest of info
            this.fullBindCode[4] = (byte)this.accountPageNumber;
            Array.Copy(this.address, 0, this.fullBindCode, 5, 7);

            if (!owc.installMasterSecret(accountPageNumber, authSecret, accountPageNumber & 7))
            {
                throw new OneWireException("Install Master Secret failed");
            }

            //not in critical path, so getBindBlah() is okay.
            if (!owc.bindSecretToiButton(accountPageNumber, copr.BindData, this.fullBindCode, accountPageNumber & 7))
            {
                throw new OneWireException("Bind Secret to iButton failed");
            }

            //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
            if (DEBUG)
            {
                IOHelper.writeLine("------------------------------------");
                IOHelper.writeLine("Initialized User");
                IOHelper.writeLine("address");
                IOHelper.writeBytesHex(owc.Address);
                IOHelper.writeLine("serviceFilename: " + strServiceFilename);
                IOHelper.writeLine("accountPageNumber: " + accountPageNumber);
                IOHelper.writeLine("authSecret");
                IOHelper.writeBytesHex(authSecret);
                IOHelper.writeLine("bindData");
                IOHelper.writeBytesHex(copr.bindData);
                IOHelper.writeLine("bindCode");
                IOHelper.writeBytesHex(copr.bindCode);
                IOHelper.writeLine("------------------------------------");
            }
            //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
        }