⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shaibuttoncoprvm.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*--------------------------------------------------------------------------- * Copyright (C) 1999-2001 Dallas Semiconductor Corporation, All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Except as contained in this notice, the name of Dallas Semiconductor * shall not be used except as stated in the Dallas Semiconductor * Branding Policy. *--------------------------------------------------------------------------- */package com.dalsemi.onewire.application.sha;import com.dalsemi.onewire.OneWireException;import com.dalsemi.onewire.adapter.OneWireIOException;import com.dalsemi.onewire.container.OneWireContainer;import com.dalsemi.onewire.container.OneWireContainer18;import com.dalsemi.onewire.utils.Address;import com.dalsemi.onewire.utils.IOHelper;import com.dalsemi.onewire.utils.SHA;import com.dalsemi.onewire.application.file.OWFile;import com.dalsemi.onewire.application.file.OWFileOutputStream;import com.dalsemi.onewire.application.file.OWFileInputStream;import com.dalsemi.onewire.application.file.OWFileNotFoundException;import java.io.FileOutputStream;import java.io.FileInputStream;import java.io.IOException;/** * <P>Class for simulating an instance of a SHA iButton Coprocessor involved * in SHA Transactions.  The Coprocessor is used for digitally signing transaction * data as well as generating random challenges for users and verifying * their response.</P> * * <p>With this class, no DS1963S SHA iButton is necessary for the coprocessor in * SHA Transactions.  The simulated Coprocessor iButton verifies signatures * and signs data for User iButtons.</P> * * <p>This class makes use of several performance enhancements for TINI. * For instance, most methods are <code>synchronized</code> to access instance variable * byte arrays rather than creating new byte arrays every time a transaction * is performed.  This could hurt performance in multi-threaded * applications, but the usefulness of having several threads contending * to talk to a single iButton is questionable since the methods in * <code>com.dalsemi.onewire.adapter.DSPortAdapter</code> * <code>beginExclusive(boolean)</code> and <code>endExclusive()</code> should be used.</p> * * @see SHATransaction * @see SHAiButtonUser * @see SHAiButtonCopr * * @version 1.00 * @author  SKH */public class SHAiButtonCoprVM   extends SHAiButtonCopr{   /**    * 8 8-byte Secrets for this simulated SHAiButton    */   protected byte[][] secretPage = new byte[8][8];   /**    * 1-Wire Address for this simulated device    */   protected byte[] address = new byte[8];   // ***********************************************************************   // Transient Data Members   // ***********************************************************************   //Temporary 512-bit buffer used for digest computation   private static final byte[] digestBuff = new byte[64];   //used for compute first secret   private static final byte[] NullSecret            = new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};   //used for generate challenge and random RomID   private static java.util.Random rand = new java.util.Random();   // ***********************************************************************   // Class Constructors   // ***********************************************************************   /**    * <P>Sets up this simulated coprocessor based on the provided parameters.    * Then, the system secret and authentication secret are installed on the    * simulated coprocessor iButton.</P>    *    * <P>For the proper format of the coprocessor data file, see the    * document entitled "Implementing Secured D-Identification and E-Payment    * Applications using SHA iButtons".  For the format of TMEX file    * structures, see Application Note 114.</P>    *    * @param RomID The address for the simulated coprocessor.    * @param l_signPageNumber page number used for signing user account data.    *        (Should be page 8, but page 0 is acceptable if you don't need    *        the TMEX directory structure)    * @param l_authPageNumber page number used for recreating user secret.    * @param l_wspcPageNumber page number used for storing user secret and    *        recreating authentication MAC.    * @param l_version version of the service provided by this coprocessor.    * @param l_encCode refers to a type of encryption used for user account    *        data stored on user buttons.    * @param l_serviceFileExt the file extension used for the service file.    *        (An extension of decimal 102 is reserved for Money files).    * @param l_serviceFilename the 4-byte name of the user's account data    *        file.    * @param l_providerName the name of the provider of this service    * @param l_bindData the binding data used to finalize secret installation    *        on user buttons.    * @param l_bindCode the binding code used to finalize secret installation    *        on user buttons.    * @param l_auxData any auxilliary or miscellaneous data to be stored on    *        the coprocessor.    * @param l_initialSignature the 20-byte initial MAC placed in user account    *        data before generating actual MAC.    * @param l_signingChlg the 3-byte challenge used for signing user    *        account data.    * @param l_signingSecret the system signing secret used by the    *        service being installed on this coprocessor.    * @param l_authSecret the system authentication secret used by the    *        service being installed on this coprocessor.    *    * @throws 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'.    * @throws OneWireException on a communication or setup error with the 1-Wire    *         adapter    *    * @see #SHAiButtonCoprVM(String)    * @see #SHAiButtonCoprVM(String,byte[],byte[])    * @see #SHAiButtonCoprVM(OneWireContainer,String)    * @see #SHAiButtonCoprVM(OneWireContainer,String,byte[],byte[])    * @see #SHAiButtonCoprVM(OneWireContainer18,String,byte[],byte[])    */   public SHAiButtonCoprVM(byte[] RomID, int l_signPageNumber,                           int l_authPageNumber, int l_wspcPageNumber,                           int l_version, int l_encCode, byte l_serviceFileExt,                           byte[] l_serviceFilename, byte[] l_providerName,                           byte[] l_bindData, byte[] l_bindCode, byte[] l_auxData,                           byte[] l_initialSignature, byte[] l_signingChlg,                           byte[] l_signingSecret, byte[] l_authSecret)      throws OneWireException, OneWireIOException   {      //clear any errors      this.lastError = this.NO_ERROR;      //set up all the appropriate members      System.arraycopy(RomID,0,this.address,0,8);      this.signPageNumber = l_signPageNumber;      this.authPageNumber = l_authPageNumber;      this.wspcPageNumber = l_wspcPageNumber;      this.version = l_version;      this.encCode = l_encCode;      System.arraycopy(l_serviceFilename,0,this.filename,0,4);      this.filename[4] = l_serviceFileExt;      this.providerName = new String(l_providerName);      System.arraycopy(l_bindData,0,this.bindData,0,32);      System.arraycopy(l_bindCode,0,this.bindCode,0,7);      this.auxData = new String(l_auxData);      System.arraycopy(l_initialSignature,0,this.initialSignature,0,20);      System.arraycopy(l_signingChlg,0,this.signingChallenge,0,3);      //Check to see if this coprocessor's authentication secret      //is appropriately padded to be used with a DS1961S      this.DS1961Scompatible = ((l_authSecret.length%47)==0);      int secretDiv = l_authSecret.length/47;      for(int j=0; j<secretDiv && DS1961Scompatible; j++)      {         int offset = 47*j;         for(int i=32; i<36 && this.DS1961Scompatible; i++)            this.DS1961Scompatible               = (l_authSecret[i + offset] == (byte)0x0FF);         for(int i=44; i<47 && this.DS1961Scompatible; i++)            this.DS1961Scompatible               = (l_authSecret[i + offset] == (byte)0x0FF);      }      //Install the system signing secret, used to sign and validate all user data      if(!installMasterSecret(signPageNumber, l_signingSecret, signPageNumber&7))         throw new OneWireIOException("failed to install system signing secret");      //Install the system authentication secret, used to authenticate users      if(!installMasterSecret(authPageNumber, l_authSecret, authPageNumber&7))         throw new OneWireIOException("failed to install authentication secret");   }   /**    * <p>Loads a simulated DS1963S coprocessor device from disk.  The given    * file name is loaded to get all the parameters of the coprocessor.    * It is assumed that the secrets were stored in the file when    * the simulated coprocessor's data was saved to disk.</p>    *    * @param filename The filename of the simulated coprocessor's data file ("shaCopr.dat")    *    * @throws 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'.    * @throws OneWireException on a communication or setup error with the 1-Wire    *         adapter    *    * @see #SHAiButtonCoprVM(String,byte[],byte[])    * @see #SHAiButtonCoprVM(OneWireContainer,String)    * @see #SHAiButtonCoprVM(OneWireContainer,String,byte[],byte[])    * @see #SHAiButtonCoprVM(OneWireContainer18,String,byte[],byte[])    * @see #SHAiButtonCoprVM(byte[],int,int,int,int,int,byte,byte[],byte[],byte[],byte[],byte[],byte[],byte[],byte[],byte[])    *    */   public SHAiButtonCoprVM(String filename)      throws OneWireException, OneWireIOException   {      if(!load(filename))         throw new OneWireIOException("failed to load config info");   }   /**    * <p>Loads a simulated DS1963S coprocessor device from disk.  The given    * file name is loaded to get all the parameters of the coprocessor.    * After it is loaded, the given secrets are installed.</p>    *    * @param filename The filename of the simulated coprocessor's data file ("shaCopr.dat")    * @param sign_secret The system data signing secret.    * @param auth_secret The system device authentication secret.    *    * @throws 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'.    * @throws OneWireException on a communication or setup error with the 1-Wire    *         adapter    *    * @see #SHAiButtonCoprVM(String)    * @see #SHAiButtonCoprVM(OneWireContainer,String)    * @see #SHAiButtonCoprVM(OneWireContainer,String,byte[],byte[])    * @see #SHAiButtonCoprVM(OneWireContainer18,String,byte[],byte[])    * @see #SHAiButtonCoprVM(byte[],int,int,int,int,int,byte,byte[],byte[],byte[],byte[],byte[],byte[],byte[],byte[],byte[])    */   public SHAiButtonCoprVM(String filename,                           byte[] sign_secret, byte[] auth_secret)      throws OneWireException, OneWireIOException   {      if(!load(filename))         throw new OneWireIOException("failed to load config info");      if(!installMasterSecret(signPageNumber, sign_secret, signPageNumber&7))         throw new OneWireIOException("failed to install system signing secret");      if(!installMasterSecret(authPageNumber, auth_secret, authPageNumber&7))         throw new OneWireIOException("failed to install authentication secret");   }   /**    * <p>Loads a simulated DS1963S coprocessor device from any 1-Wire memory device    * supported by the 1-Wire File I/O API.  The given file name is loaded to get    * all the parameters of the coprocessor.  It is assumed that the secrets were    * stored in the file when the simulated coprocessor's data was saved to disk.</p>    *    * @param owc 1-Wire memory device with valid TMEX file system    * @param filename The filename of the simulated coprocessor's data file ("shaCopr.dat")    *    * @throws 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'.    * @throws OneWireException on a communication or setup error with the 1-Wire    *         adapter    *    * @see #SHAiButtonCoprVM(String)    * @see #SHAiButtonCoprVM(String,byte[],byte[])    * @see #SHAiButtonCoprVM(OneWireContainer,String,byte[],byte[])    * @see #SHAiButtonCoprVM(OneWireContainer18,String,byte[],byte[])    * @see #SHAiButtonCoprVM(byte[],int,int,int,int,int,byte,byte[],byte[],byte[],byte[],byte[],byte[],byte[],byte[],byte[])    */   public SHAiButtonCoprVM(OneWireContainer owc, String filename)      throws OneWireException, OneWireIOException   {      if(!load(owc,filename))         throw new OneWireIOException("failed to load config info");   }   /**    * <p>Loads a simulated DS1963S coprocessor device from any 1-Wire    * memory device supported by the 1-Wire File I/O API.  The given    * file name is loaded to get all the parameters of the coprocessor.    * After it is loaded, the given secrets are installed.</p>    *    * @param owc 1-Wire memory device with valid TMEX file system    * @param filename The filename of the simulated coprocessor's data file ("shaCopr.dat")    * @param sign_secret The system data signing secret.    * @param auth_secret The system device authentication secret.    *    * @throws 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'.    * @throws OneWireException on a communication or setup error with the 1-Wire

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -