CN105678152A - Method and device for communication with intelligent secret key device - Google Patents
Method and device for communication with intelligent secret key device Download PDFInfo
- Publication number
- CN105678152A CN105678152A CN201610032912.6A CN201610032912A CN105678152A CN 105678152 A CN105678152 A CN 105678152A CN 201610032912 A CN201610032912 A CN 201610032912A CN 105678152 A CN105678152 A CN 105678152A
- Authority
- CN
- China
- Prior art keywords
- module
- smart key
- mobile terminal
- communication
- permission
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/30—Authentication, i.e. establishing the identity or authorisation of security principals
- G06F21/31—User authentication
- G06F21/34—User authentication involving the use of external additional devices, e.g. dongles or smart cards
Landscapes
- Engineering & Computer Science (AREA)
- Computer Security & Cryptography (AREA)
- Theoretical Computer Science (AREA)
- Computer Hardware Design (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Mobile Radio Communication Systems (AREA)
- Telephone Function (AREA)
Abstract
本发明公开了一种与智能密钥设备通讯的方法及装置;所述方法包括:监控流程和通讯流程;在监控流程中,移动终端采用广播或者枚举的方式,监控是否有智能密钥设备插入;当移动终端监控到智能密钥设备插入后,移动终端获取与智能密钥设备对应的设备对象,判断设备对象是否具有设备权限,当判定智能密钥设备具有设备权限后,获取与设备对象对应的设备连接句柄和设备接口对象,根据设备接口对象获取与设备对象对应的设备通讯端点;在通讯流程中,移动终端根据与智能密钥设备对应的设备对象、设备连接句柄和设备通讯端点与智能密钥设备通信。
The invention discloses a method and device for communicating with an intelligent key device; the method includes: a monitoring process and a communication process; in the monitoring process, a mobile terminal monitors whether there is an intelligent key device by means of broadcasting or enumeration Insertion; when the mobile terminal monitors the insertion of the smart key device, the mobile terminal obtains the device object corresponding to the smart key device, and judges whether the device object has device authority. According to the corresponding device connection handle and device interface object, the device communication endpoint corresponding to the device object is obtained according to the device interface object; Smart key device communication.
Description
技术领域technical field
本发明涉及通信技术领域,特别涉及一种与智能密钥设备通讯的方法及装置。The invention relates to the technical field of communication, in particular to a method and device for communicating with an intelligent key device.
背景技术Background technique
随着电子信息的快速发展,在日常生活中网上银行交易日渐普及。USBKEY是为保证网上银行交易的安全性而提出的一种安全且便捷的具有USB接口的智能密钥设备。移动终端是指可以在移动中使用的计算机设备,和传统计算机相比更具便携性。并且近些年来,随着网络技术以及集成电路技术的飞速发展,移动终端已进入智能化发展阶段,其自身拥有强大的处理能力,已成为一个综合信息处理平台,是人们生活和工作中不可或缺的一个重要工具。With the rapid development of electronic information, online banking transactions are becoming more and more popular in daily life. USBKEY is a safe and convenient smart key device with USB interface proposed to ensure the security of online banking transactions. A mobile terminal refers to a computer device that can be used on the move, and is more portable than a traditional computer. And in recent years, with the rapid development of network technology and integrated circuit technology, mobile terminals have entered the stage of intelligent development. With their powerful processing capabilities, they have become a comprehensive information processing platform, which is an indispensable part of people's life and work. An important tool is missing.
OTG(On-The-Go)技术是一种能够在没有主机的情况下,实现从设备间的数据传输的现有技术,为USBKEY在移动终端上使用奠定了技术基础。但是现有技术中,具体如何利用OTG技术实现移动终端和USBKEY之间的通讯还是一个亟需解决的技术问题。OTG (On-The-Go) technology is an existing technology that can realize data transmission between slave devices without a host, and it has laid a technical foundation for the use of USBKEY on mobile terminals. However, in the prior art, how to use the OTG technology to realize the communication between the mobile terminal and the USBKEY is still a technical problem that needs to be solved urgently.
发明内容Contents of the invention
本发明提供了一种与智能密钥设备通讯的方法及装置,解决了现有技术中的上述技术问题。The invention provides a method and device for communicating with an intelligent key device, which solves the above-mentioned technical problems in the prior art.
本发明提供了一种与智能密钥设备通讯的方法,包括:监控流程和通讯流程;The invention provides a method for communicating with an intelligent key device, including: a monitoring process and a communication process;
所述监控流程包括:The monitoring process includes:
步骤s1:移动终端初始化;Step s1: mobile terminal initialization;
步骤s2:所述移动终端采用广播或者枚举的方式,监控是否有智能密钥设备插入;当所述移动终端监控到智能密钥设备插入后,执行步骤s3;Step s2: The mobile terminal monitors whether a smart key device is inserted by broadcasting or enumerating; when the mobile terminal monitors the insertion of the smart key device, execute step s3;
步骤s3:所述移动终端获取与所述智能密钥设备对应的设备对象,判断所述设备对象是否具有设备权限,如果是,则执行步骤s5;否则,执行步骤s4;Step s3: The mobile terminal obtains the device object corresponding to the smart key device, and judges whether the device object has device authority, and if so, executes step s5; otherwise, executes step s4;
步骤s4:所述移动终端为所述设备对象申请设备权限,判断所述设备对象是否具有设备权限,如果是,则执行步骤s5,否则,返回步骤s2;Step s4: The mobile terminal applies for the device permission for the device object, and judges whether the device object has the device permission, if yes, execute step s5, otherwise, return to step s2;
步骤s5:所述移动终端获取与所述设备对象对应的设备连接句柄和设备接口对象,根据所述设备接口对象获取与所述设备对象对应的设备通讯端点;Step s5: The mobile terminal obtains a device connection handle and a device interface object corresponding to the device object, and obtains a device communication endpoint corresponding to the device object according to the device interface object;
所述通讯流程包括:The communication process includes:
步骤r1:所述移动终端生成第一通讯指令,根据所述设备对象获取USB协议标识,根据所述USB协议标识对所述第一通讯指令进行封装;Step r1: the mobile terminal generates a first communication command, acquires a USB protocol identifier according to the device object, and encapsulates the first communication command according to the USB protocol identifier;
步骤r2:所述移动终端通过所述设备连接句柄和所述设备通讯端点将封装后的第一通讯指令,发送给对应的所述智能密钥设备;Step r2: the mobile terminal sends the encapsulated first communication command to the corresponding smart key device through the device connection handle and the device communication endpoint;
步骤r3:所述移动终端通过所述设备连接句柄和所述设备通讯端点接收来自所述智能密钥设备的与所述封装后的第一通讯指令对应的第一应答;Step r3: the mobile terminal receives a first response corresponding to the encapsulated first communication command from the smart key device through the device connection handle and the device communication endpoint;
步骤r4:所述移动终端根据所述USB协议标识对所述第一应答进行解封,得到解封后的第一应答,通讯成功。Step r4: The mobile terminal decapsulates the first response according to the USB protocol identifier, obtains the decapsulated first response, and communicates successfully.
本发明还提供了一种与智能密钥设备通讯的装置,包括:初始化模块、监控模块、第一获取模块、第一判断模块、申请权限模块、第二判断模块、第二获取模块、第一封装模块、第一发送模块、第一接收模块和第一解封模块;The present invention also provides a device for communicating with smart key equipment, including: an initialization module, a monitoring module, a first acquisition module, a first judgment module, an application authority module, a second judgment module, a second acquisition module, a first Encapsulation module, first sending module, first receiving module and first decapsulating module;
所述初始化模块,用于初始化;The initialization module is used for initialization;
所述监控模块,用于当所述初始化模块进行初始化后,采用广播或者枚举的方式,监控是否有智能密钥设备插入;以及当所述第二判断模块判定为否后,采用广播或者枚举的方式,监控是否有智能密钥设备插入;The monitoring module is used to monitor whether a smart key device is inserted by broadcasting or enumerating after the initialization module is initialized; For example, monitor whether there is a smart key device inserted;
所述第一获取模块,用于当所述监控模块监控到智能密钥设备插入后,获取与所述智能密钥设备对应的设备对象;The first obtaining module is configured to obtain a device object corresponding to the smart key device when the monitoring module monitors that the smart key device is inserted;
所述第一判断模块,用于判断第一获取模块获取到的所述设备对象是否具有设备权限;The first judging module is configured to judge whether the device object obtained by the first obtaining module has device authority;
所述申请权限模块,用于当所述第一判断模块判定为否后,为所述设备对象申请设备权限;The application permission module is used to apply for the device permission for the device object after the first judging module judges no;
所述第二判断模块,用于当所述申请权限模块为所述第一获取模块获取到的设备对象申请设备权限后,判断所述设备对象是否具有设备权限;The second judging module is configured to judge whether the device object has device permission after the permission application module applies for the device permission for the device object acquired by the first obtaining module;
所述第二获取模块,用于当所述第一判断模块判定为是后或当所述第二判断模块判定为是后,获取与所述设备对象对应的设备连接句柄和设备接口对象,根据所述设备接口对象获取与所述设备对象对应的设备通讯端点;The second obtaining module is configured to obtain the device connection handle and the device interface object corresponding to the device object when the first judging module judges yes or when the second judging module judges yes, according to The device interface object acquires a device communication endpoint corresponding to the device object;
第一封装模块,用于当所述第二获取模块根据所述设备接口对象获取与所述设备对象对应的设备通讯端点后,生成第一通讯指令,根据所述设备对象获取所述USB协议标识,根据所述USB协议标识对所述第一通讯指令进行封装;The first encapsulation module is configured to generate a first communication instruction after the second obtaining module obtains the device communication endpoint corresponding to the device object according to the device interface object, and obtain the USB protocol identifier according to the device object , encapsulating the first communication command according to the USB protocol identifier;
所述第一发送模块,用于通过所述第二获取模块获取到的设备连接句柄和所述设备通讯端点将所述第一封装模块封装的第一通讯指令发送给对应的所述智能密钥设备;The first sending module is configured to send the first communication command encapsulated by the first encapsulation module to the corresponding smart key through the device connection handle obtained by the second obtaining module and the device communication endpoint equipment;
所述第一接收模块,用于通过所述第二获取模块获取到的设备连接句柄和所述设备通讯端点接收来自所述智能密钥设备的与所述封装后的第一通讯指令对应的第一应答;The first receiving module is configured to use the device connection handle obtained by the second obtaining module and the device communication endpoint to receive the first communication command corresponding to the encapsulated first communication command from the smart key device. a response;
所述第一解封模块,用于根据所述USB协议标识对所述第一接收模块接收到的第一应答进行解封,得到解封后的第一应答。The first decapsulation module is configured to decapsulate the first response received by the first receiving module according to the USB protocol identifier, to obtain the decapsulated first response.
本发明的有益效果是:本发明通过:当监控到智能密钥设备插入后,获取与智能密钥设备对应的设备对象,判断设备对象是否具有设备权限,当判定智能密钥设备具有设备权限后,获取与设备对象对应的设备连接句柄和设备接口对象,根据设备接口对象获取与设备对象对应的设备通讯端点;根据与智能密钥设备对应的设备对象、设备连接句柄和设备通讯端点与智能密钥设备通信,在利用OTG技术的基础上实现了移动终端和智能密钥设备之间的通讯。The beneficial effects of the present invention are: the present invention obtains the device object corresponding to the smart key device after monitoring the insertion of the smart key device, and judges whether the device object has device authority; , to obtain the device connection handle and device interface object corresponding to the device object, and obtain the device communication endpoint corresponding to the device object according to the device interface object; according to the device object corresponding to the smart key device, the device connection handle and the device communication endpoint The communication between the mobile terminal and the smart key device is realized on the basis of using OTG technology.
附图说明Description of drawings
图1为本发明实施例1提供的一种监控流程的操作流程图;FIG. 1 is an operation flowchart of a monitoring process provided by Embodiment 1 of the present invention;
图2为本发明实施例1提供的一种通讯流程的操作流程图;FIG. 2 is an operation flowchart of a communication process provided by Embodiment 1 of the present invention;
图3为本发明实施例1提供的一种监控流程的具体操作流程图;FIG. 3 is a specific operation flowchart of a monitoring process provided by Embodiment 1 of the present invention;
图4为本发明实施例1提供的另一种监控流程的具体操作流程图;FIG. 4 is a specific operation flowchart of another monitoring process provided by Embodiment 1 of the present invention;
图5为本发明实施例1提供的又一种监控流程的具体操作流程图;FIG. 5 is a specific operation flowchart of another monitoring process provided by Embodiment 1 of the present invention;
图6为本发明实施例2提供的一种与智能密钥设备通讯的装置的结构图。FIG. 6 is a structural diagram of an apparatus for communicating with a smart key device provided in Embodiment 2 of the present invention.
具体实施方法Specific implementation method
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some, not all, embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the protection scope of the present invention.
实施例1Example 1
本实施例提供了一种与智能密钥设备通讯的方法,包括:监控流程和通讯流程;This embodiment provides a method for communicating with a smart key device, including: a monitoring process and a communication process;
其中,监控流程,如图1所示,包括:Among them, the monitoring process, as shown in Figure 1, includes:
步骤A1:移动终端开启监控流程,初始化;Step A1: The mobile terminal starts the monitoring process and initializes;
本实施例中,移动终端支持OTG技术。In this embodiment, the mobile terminal supports OTG technology.
步骤A2:移动终端采用广播或者枚举的方式,监控是否有USBKEY插入或者拔出;当移动终端监控到USBKEY插入后,执行步骤A3;当移动终端监控到USBKEY拔出后,执行步骤A7;Step A2: The mobile terminal monitors whether a USBKEY is inserted or pulled out by means of broadcasting or enumeration; when the mobile terminal monitors that the USBKEY is inserted, perform step A3; when the mobile terminal monitors that the USBKEY is pulled out, perform step A7;
步骤A3:移动终端获取与USBKEY对应的设备对象,判断设备对象是否具有设备权限,如果是,则执行步骤A4;否则,执行步骤A6;Step A3: The mobile terminal obtains the device object corresponding to the USBKEY, and judges whether the device object has device authority, and if so, executes step A4; otherwise, executes step A6;
步骤A4:移动终端获取与设备对象对应的设备连接句柄和设备接口对象,根据设备接口对象获取与设备对象对应的设备通讯端点;Step A4: The mobile terminal obtains the device connection handle and the device interface object corresponding to the device object, and obtains the device communication endpoint corresponding to the device object according to the device interface object;
步骤A5:移动终端生成与设备对象对应的设备通讯句柄,将设备通讯句柄与设备连接句柄、设备通讯端点及设备对象分别建立对应关系并保存,移动终端和USBKEY连接成功,返回步骤A2;Step A5: The mobile terminal generates a device communication handle corresponding to the device object, establishes a corresponding relationship between the device communication handle and the device connection handle, the device communication endpoint, and the device object, and saves it. The mobile terminal and the USBKEY are successfully connected, and return to step A2;
步骤A6:移动终端为设备对象申请设备权限,判断设备对象是否具有设备权限,如果是,则返回步骤A4,否则,返回步骤A2。Step A6: The mobile terminal applies for the device authority for the device object, and judges whether the device object has the device authority. If yes, return to step A4; otherwise, return to step A2.
步骤A7:移动终端判断与USBKEY对应的设备对象是否存在对应的设备通讯句柄,如果是,则执行步骤A8;否则,执行步骤A9;Step A7: The mobile terminal judges whether there is a corresponding device communication handle for the device object corresponding to the USBKEY, if yes, execute step A8; otherwise, execute step A9;
步骤A8:移动终端销毁与USBKEY对应的设备对象,及与其分别对应的设备通讯句柄、设备连接句柄和设备通讯端点,移动终端和USBKEY连接失败,返回步骤A2;Step A8: The mobile terminal destroys the device object corresponding to the USBKEY, and the corresponding device communication handle, device connection handle and device communication endpoint, and the connection between the mobile terminal and the USBKEY fails, and returns to step A2;
步骤A9:移动终端销毁与USBKEY对应的设备对象,移动终端和USBKEY连接失败,返回步骤A2;Step A9: The mobile terminal destroys the device object corresponding to the USBKEY, and the connection between the mobile terminal and the USBKEY fails, and returns to step A2;
通讯流程,如图2所示,包括:The communication process, as shown in Figure 2, includes:
步骤B1:移动终端获取与USBKEY对应的设备通讯句柄,根据与USBKEY对应的设备通讯句柄获取对应的设备对象、设备连接句柄和设备通讯端点;Step B1: The mobile terminal obtains the device communication handle corresponding to the USBKEY, and obtains the corresponding device object, device connection handle and device communication endpoint according to the device communication handle corresponding to the USBKEY;
具体地,移动终端获取与USBKEY对应的设备通讯句柄,如果获取到的设备通讯句柄不为空,则判定和USBKEY连接成功,根据与USBKEY对应的设备通讯句柄获取对应的设备对象、设备连接句柄和设备通讯端点;否则,判定和USBKEY连接失败,继续获取与USBKEY对应的设备通讯句柄,或者结束当前操作。Specifically, the mobile terminal obtains the device communication handle corresponding to the USBKEY, and if the obtained device communication handle is not empty, it determines that the connection with the USBKEY is successful, and obtains the corresponding device object, device connection handle and Device communication endpoint; otherwise, it is determined that the connection with the USBKEY has failed, continue to obtain the device communication handle corresponding to the USBKEY, or end the current operation.
步骤B2:移动终端判断是否获取到对应的设备对象、设备连接句柄和设备通讯端点,如果是,则执行步骤B3;否则,通讯失败,结束。Step B2: The mobile terminal judges whether the corresponding device object, device connection handle and device communication endpoint have been acquired, and if yes, execute step B3; otherwise, the communication fails and ends.
步骤B3:移动终端生成第一通讯指令,根据设备对象获取USB协议标识,根据USB协议标识对第一通讯指令进行封装;Step B3: The mobile terminal generates the first communication command, obtains the USB protocol identifier according to the device object, and encapsulates the first communication command according to the USB protocol identifier;
其中,根据USB协议标识对第一通讯指令进行封装,具体为:在第一通讯指令前添加与USB协议标识对应的USB协议头,得到封装后的第一通讯指令。其中,封装后的第一通讯指令可以包括多包数据,每包数据中均包括USB协议头。Wherein, encapsulating the first communication command according to the USB protocol identifier is specifically: adding a USB protocol header corresponding to the USB protocol identifier before the first communication command to obtain the encapsulated first communication command. Wherein, the encapsulated first communication command may include multiple packets of data, and each packet of data includes a USB protocol header.
本实施例中,第一通讯指令可以具体为取随机数指令、验PIN指令、生成密钥对指令或签名指令等;USB协议标识可以具体为CCID协议标识或HID协议标识或SCSI协议标识。封装后的第一通讯指令可以包括一包数据或者多包数据。In this embodiment, the first communication instruction may specifically be a random number fetch instruction, a PIN verification instruction, a key pair generation instruction, or a signature instruction, etc.; the USB protocol identifier may specifically be a CCID protocol identifier, an HID protocol identifier, or a SCSI protocol identifier. The encapsulated first communication instruction may include one packet of data or multiple packets of data.
例如,当第一通讯指令具体为签名指令,USB协议标识为HID协议标识后,第一通讯指令为:0x000x2A0x860x800x800x000x010xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0x000x550x730x620x540x6F0x6B0x650x6E0x200x520x750x6E0x520x730x610x4B0x650x790x470x650x6E0x650x720x610x740x690x6F0x6E0x540x650x730x740x2E0x2E0x2E0x550x730x620x540x6F0x6B0x650x6E0x200x520x750x6E0x520x730x610x4B0x650x790x470x650x6E0x650x720x610x740x690x6F0x6E0x540x650x730x740x2E0x2E0x2E0x550x730x620x540x6F0x6B0x650x6E0x200x520x750x6E0x520x730x610x4B0x650x790x470x650x6E0x650x720x610x740x690x6F0x6E0x540x650x730x740x2E0x2E0x2E;例如,当第一通讯指令具体为签名指令,USB协议标识为HID协议标识后,第一通讯指令为:0x000x2A0x860x800x800x000x010xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0x000x550x730x620x540x6F0x6B0x650x6E0x200x520x750x6E0x520x730x610x4B0x650x790x470x650x6E0x650x720x610x740x690x6F0x6E0x540x650x730x740x2E0x2E0x2E0x550x730x620x540x6F0x6B0x650x6E0x200x520x750x6E0x520x730x610x4B0x650x790x470x650x6E0x650x720x610x740x690x6F0x6E0x540x650x730x740x2E0x2E0x2E0x550x730x620x540x6F0x6B0x650x6E0x200x520x750x6E0x520x730x610x4B0x650x790x470x650x6E0x650x720x610x740x690x6F0x6E0x540x650x730x740x2E0x2E0x2E;
根据USB协议标识对第一通讯指令进行封装,得到封装后的第一通讯指令,封装后的第一通讯指令包括三包数据,其中,第一包数据为:0x000x850x000x000x000x3A0x000x2A0x860x800x800x000x010xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0x000x550x730x620x540x6F0x6B0x650x6E0x200x520x750x6E0x520x730x610x4B0x650x790x470x650x6E0x650x720x610x740x690x6F0x6E0x540x65;根据USB协议标识对第一通讯指令进行封装,得到封装后的第一通讯指令,封装后的第一通讯指令包括三包数据,其中,第一包数据为:0x000x850x000x000x000x3A0x000x2A0x860x800x800x000x010xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0x000x550x730x620x540x6F0x6B0x650x6E0x200x520x750x6E0x520x730x610x4B0x650x790x470x650x6E0x650x720x610x740x690x6F0x6E0x540x65;
第二包数据为:0x000x850x000x3A0x000x3A0x730x740x2E0x2E0x2E0x550x730x620x540x6F0x6B0x650x6E0x200x520x750x6E0x520x730x610x4B0x650x790x470x650x6E0x650x720x610x740x690x6F0x6E0x540x650x730x740x2E0x2E0x2E0x550x730x620x540x6F0x6B0x650x6E0x200x520x750x6E0x520x730x610x4B0x650x79;第二包数据为:0x000x850x000x3A0x000x3A0x730x740x2E0x2E0x2E0x550x730x620x540x6F0x6B0x650x6E0x200x520x750x6E0x520x730x610x4B0x650x790x470x650x6E0x650x720x610x740x690x6F0x6E0x540x650x730x740x2E0x2E0x2E0x550x730x620x540x6F0x6B0x650x6E0x200x520x750x6E0x520x730x610x4B0x650x79;
第三包数据为:0x000x850x000x740x000x110x000x0D0xC80x0E0x100x400xCA0x190x000xD00xCE0x190x000x000xE00xFD0x7F;The third packet of data is: 0x000x850x000x740x000x110x000x0D0xC80x0E0x100x400xCA0x190x000xD00xCE0x190x000x000xE00xFD0x7F;
其中,每包数据的前六个字节为HID协议头,HID协议头中的第二字节为第一通讯指令的数据长度,第四字节为已经发送的数据长度,最后一个字节为当前包发送的数据长度。以第三包数据为例,HID协议头具体为:“0x000x850x000x740x000x11”;HID协议头的第二字节为“0x85”,表示第一通讯指令的数据长度为133个字节,第四字节“0x74”表示已经发送的数据长度为116个字节,最后一个字节“0x11”表示当前包发送的数据长度为17个字节。Among them, the first six bytes of each packet of data are the HID protocol header, the second byte in the HID protocol header is the data length of the first communication command, the fourth byte is the data length that has been sent, and the last byte is The length of data sent by the current packet. Taking the third packet of data as an example, the HID protocol header is specifically: "0x000x850x000x740x000x11"; the second byte of the HID protocol header is "0x85", indicating that the data length of the first communication command is 133 bytes, and the fourth byte " 0x74" indicates that the length of the data sent is 116 bytes, and the last byte "0x11" indicates that the length of the data sent by the current packet is 17 bytes.
步骤B4:移动终端通过设备连接句柄和设备通讯端点将封装后的第一通讯指令发送给对应的USBKEY;Step B4: The mobile terminal sends the encapsulated first communication command to the corresponding USBKEY through the device connection handle and the device communication endpoint;
具体地,移动终端使用设备输出端点和封装后的第一通讯指令,调用设备连接句柄的数据传输函数,将封装后的第一通讯指令发送给对应的USBKEY。Specifically, the mobile terminal uses the device output endpoint and the encapsulated first communication command, calls the data transfer function of the device connection handle, and sends the encapsulated first communication command to the corresponding USBKEY.
其中,数据传输函数可以为intbulkTransfer(UsbEndpointendpoint,byte[]buffer,intlength,inttimeout);Among them, the data transfer function can be intbulkTransfer(UsbEndpointendpoint,byte[]buffer,intlength,inttimeout);
步骤B5:移动终端通过设备连接句柄和设备通讯端点接收来自USBKEY的第一应答;Step B5: The mobile terminal receives the first response from the USBKEY through the device connection handle and the device communication endpoint;
具体地,移动终端使用设备输入端点和设备连接句柄,调用设备连接句柄的数据传输函数,接收来自USBKEY的与封装后的第一通讯指令,对应的第一应答。其中,第一应答可以包括一包数据或者多包数据。Specifically, the mobile terminal uses the device input endpoint and the device connection handle to call the data transfer function of the device connection handle, and receives the first response corresponding to the encapsulated first communication command from the USBKEY. Wherein, the first response may include one packet of data or multiple packets of data.
当第一应答具体为与封装后的签名指令对应的应答后,第一应答包括三包数据,其中,第一应答包为:0x000x820x000x000x000x3A0x960x2B0x0E0x420x700x270x230x7E0x960x160xBD0x520xD90x0E0x7E0x530xB40x650xB90xF10x5B0x440xCF0x3E0x170xAE0xC50x580x830x2D0x5E0xDC0xA60xF80x4F0x880x4F0x750x760x130xDE0xCB0x580x160x7A0x5F0x050x3F0x800x430x980x3B0x850x4D0x3A0x490x5C0xC8;当第一应答具体为与封装后的签名指令对应的应答后,第一应答包括三包数据,其中,第一应答包为:0x000x820x000x000x000x3A0x960x2B0x0E0x420x700x270x230x7E0x960x160xBD0x520xD90x0E0x7E0x530xB40x650xB90xF10x5B0x440xCF0x3E0x170xAE0xC50x580x830x2D0x5E0xDC0xA60xF80x4F0x880x4F0x750x760x130xDE0xCB0x580x160x7A0x5F0x050x3F0x800x430x980x3B0x850x4D0x3A0x490x5C0xC8;
第二应答包为:0x000x820x000x3A0x000x3A0x480x000xC10x990x240x760x2F0xCC0xF10x080x1A0x730x780x330xCA0x360x080x8B0x480x730x3C0xFF0x960xB30xC50x800x150xA40x5B0x7E0x7C0xE60x3E0x970x750xB60xBA0xC80x510xDC0xB20x770xDC0x240xE90x300xA90x070x040x1F0x2B0x3A0xBE0x300xA80x6A0x700xE0;第二应答包为:0x000x820x000x3A0x000x3A0x480x000xC10x990x240x760x2F0xCC0xF10x080x1A0x730x780x330xCA0x360x080x8B0x480x730x3C0xFF0x960xB30xC50x800x150xA40x5B0x7E0x7C0xE60x3E0x970x750xB60xBA0xC80x510xDC0xB20x770xDC0x240xE90x300xA90x070x040x1F0x2B0x3A0xBE0x300xA80x6A0x700xE0;
第三应答包为:0x000x820x000x740x000x0E0xB60x860x1E0xC90x6C0x4B0x5B0xF20x030xA20x330x6B0x900x00;The third response packet is: 0x000x820x000x740x000x0E0xB60x860x1E0xC90x6C0x4B0x5B0xF20x030xA20x330x6B0x900x00;
其中,每个应答包的前六个字节为应答头,应答头中的第二字节为需要接收的有效数据总长度,第四字节为已经接收的有效数据长度,最后一个字节为当前包接收的有效数据长度。以第三应答包为例,应答头具体为:“0x000x820x000x740x000x0E”;应答头中的第二字节为“0x82”,表示需要接收的有效数据总长度为130个字节,第四字节“0x74”表示已经接收的有效据长度为116个字节,最后一个字节“0x0E”表示当前包接收的有效数据长度为14个字节。Among them, the first six bytes of each response packet are the response header, the second byte in the response header is the total length of valid data to be received, the fourth byte is the length of valid data that has been received, and the last byte is The valid data length received by the current packet. Taking the third response packet as an example, the response header is specifically: "0x000x820x000x740x000x0E"; the second byte in the response header is "0x82", indicating that the total length of valid data to be received is 130 bytes, and the fourth byte is "0x74 "Indicates that the length of valid data received is 116 bytes, and the last byte "0x0E" indicates that the length of valid data received by the current packet is 14 bytes.
步骤B6:移动终端根据USB协议标识对第一应答进行解封,得到解封后的第一应答,通讯成功。Step B6: The mobile terminal decapsulates the first response according to the USB protocol identifier, obtains the decapsulated first response, and communicates successfully.
具体地,移动终端根据USB协议标识处理第一应答,去除第一应答中的与USB协议标识对应的应答头,得到与第一通讯指令对应的第一应答,通讯成功。Specifically, the mobile terminal processes the first response according to the USB protocol identifier, removes the response header corresponding to the USB protocol identifier in the first response, obtains the first response corresponding to the first communication command, and communicates successfully.
当第一应答为与封装后的签名指令相对应时,解封后的第一应答具体为:0x960x2B0x0E0x420x700x270x230x7E0x960x160xBD0x520xD90x0E0x7E0x530xB40x650xB90xF10x5B0x440xCF0x3E0x170xAE0xC50x580x830x2D0x5E0xDC0xA60xF80x4F0x880x4F0x750x760x130xDE0xCB0x580x160x7A0x5F0x050x3F0x800x430x980x3B0x850x4D0x3A0x490x5C0xC80x480x000xC10x990x240x760x2F0xCC0xF10x080x1A0x730x780x330xCA0x360x080x8B0x480x730x3C0xFF0x960xB30xC50x800x150xA40x5B0x7E0x7C0xE60x3E0x970x750xB60xBA0xC80x510xDC0xB20x770xDC0x240xE90x300xA90x070x040x1F0x2B0x3A0xBE0x300xA80x6A0x700xE00xB60x860x1E0xC90x6C0x4B0x5B0xF20x030xA20x330x6B0x900x00。当第一应答为与封装后的签名指令相对应时,解封后的第一应答具体为:0x960x2B0x0E0x420x700x270x230x7E0x960x160xBD0x520xD90x0E0x7E0x530xB40x650xB90xF10x5B0x440xCF0x3E0x170xAE0xC50x580x830x2D0x5E0xDC0xA60xF80x4F0x880x4F0x750x760x130xDE0xCB0x580x160x7A0x5F0x050x3F0x800x430x980x3B0x850x4D0x3A0x490x5C0xC80x480x000xC10x990x240x760x2F0xCC0xF10x080x1A0x730x780x330xCA0x360x080x8B0x480x730x3C0xFF0x960xB30xC50x800x150xA40x5B0x7E0x7C0xE60x3E0x970x750xB60xBA0xC80x510xDC0xB20x770xDC0x240xE90x300xA90x070x040x1F0x2B0x3A0xBE0x300xA80x6A0x700xE00xB60x860x1E0xC90x6C0x4B0x5B0xF20x030xA20x330x6B0x900x00。
需说明的是,解封后的第一应答的数据长度,即为本实施例中需要接收的有效数据总长度。It should be noted that the data length of the first response after decapsulation is the total length of valid data to be received in this embodiment.
本实施例中,监控流程,可以如图3所示,移动终端具体执行:In this embodiment, the monitoring process can be as shown in Figure 3, and the mobile terminal specifically executes:
步骤101:开启监控流程,初始化USB管理对象和权限许可对象;Step 101: start the monitoring process, initialize the USB management object and the permission object;
具体地,移动终端开启监控流程,调用初始化函数初始化USB管理对象和权限许可对象。其中,初始化函数包括第一初始化函数和第二初始化函数。Specifically, the mobile terminal starts the monitoring process, and calls the initialization function to initialize the USB management object and the permission object. Wherein, the initialization function includes a first initialization function and a second initialization function.
其中,移动终端调用第一初始化函数初始化USB管理对象具体为:mUsbManager=(UsbManager)getSystemService(Context.USB_SERVICE);其中,mUsbManager为USB管理对象;Wherein, the mobile terminal calls the first initialization function to initialize the USB management object specifically: mUsbManager=(UsbManager)getSystemService(Context.USB_SERVICE); wherein, mUsbManager is the USB management object;
移动终端调用第二初始化函数初始化权限许可对象具体为:The mobile terminal calls the second initialization function to initialize the permission permission object specifically as follows:
mPermissionIntent=PendingIntent.getBroadcast(this,0,newIntent(ACTION_USB_PERMISSION),0);其中,mPermissionIntent为权限许可对象,进一步地说明,权限许可对象是一个待处理的事件对象;mPermissionIntent=PendingIntent.getBroadcast(this, 0, newIntent(ACTION_USB_PERMISSION), 0); wherein, mPermissionIntent is the permission object, and it is further explained that the permission object is an event object to be processed;
ACTION_USB_PERMISSION具体为设备权限消息,ACTION_USB_PERMISSION is specifically the device permission message,
ACTION_USB_PERMISSION可以具体为ACTION_USB_PERMISSION can be specified as
"com.android.example.USB_PERMISSION"。"com.android.example.USB_PERMISSION".
步骤102:在预设时间内获取与USBKEY对应的设备对象,当在预设时间内获取到与USBKEY对应的设备对象后,执行步骤104;当在预设时间内没有获取到与USBKEY对应的设备对象后,执行步骤103;Step 102: Obtain the device object corresponding to the USBKEY within the preset time, when the device object corresponding to the USBKEY is obtained within the preset time, execute step 104; when the device object corresponding to the USBKEY is not obtained within the preset time After object, execute step 103;
具体地,JAVA调用USB管理对象的获取设备列表函数在预设时间内对USBKEY进行枚举,获取与USBKEY对应的设备对象,当在预设时间内获取到与USBKEY对应的设备对象后,执行步骤104;当在预设时间内没有获取到与USBKEY对应的设备对象后,执行步骤103。Specifically, JAVA calls the acquisition device list function of the USB management object to enumerate the USBKEY within the preset time, and obtain the device object corresponding to the USBKEY. When the device object corresponding to the USBKEY is obtained within the preset time, perform the steps 104: When the device object corresponding to the USBKEY is not acquired within the preset time, execute step 103.
优选地,预设时间为2秒。Preferably, the preset time is 2 seconds.
其中,移动终端调用USB管理对象的获取设备列表函数在预设时间内对USBKEY进行枚举,获取与USBKEY对应的设备对象,具体为:Wherein, the mobile terminal calls the function of obtaining the device list of the USB management object to enumerate the USBKEY within a preset time, and obtain the device object corresponding to the USBKEY, specifically:
HashMap<String,UsbDevice>deviceMap=m_UsbManager.getDeviceList();HashMap<String, UsbDevice>deviceMap=m_UsbManager.getDeviceList();
其中,设备对象中具体包括:USBKEY的厂商标识信息。其中,USBKEY的厂商标识信息可以具体为USBKEY的PID(ProductID,产品识别码)和VID(VendorID,供应商身份)。Wherein, the device object specifically includes: vendor identification information of the USBKEY. Wherein, the manufacturer identification information of the USBKEY may specifically be a PID (ProductID, product identification code) and VID (VendorID, supplier identity) of the USBKEY.
步骤103:清空第一设备列表,执行步骤106;Step 103: clear the first device list, and execute step 106;
步骤104:判断是否存在与预设厂商标识对应的设备对象,如果是,则执行步骤105;否则,返回步骤102;Step 104: Judging whether there is a device object corresponding to the preset manufacturer identifier, if yes, then execute step 105; otherwise, return to step 102;
具体地,移动终端获取设备对象中的厂商标识信息,判断获取到的设备对象中的厂商标识信息是否和预设厂商标识对应,如果是,则执行步骤105;否则,返回步骤102。Specifically, the mobile terminal acquires the vendor identification information in the device object, and judges whether the obtained vendor identification information in the device object corresponds to the preset vendor identification, and if so, executes step 105; otherwise, returns to step 102.
步骤105:将与预设厂商标识相对应的设备对象存储到第一设备列表中,执行步骤106;Step 105: Store the device object corresponding to the preset manufacturer identifier in the first device list, and execute step 106;
步骤106:判断第一设备列表中是否有新增的设备对象,如果是,则执行步骤107;否则,执行步骤115;Step 106: Judging whether there is a newly added device object in the first device list, if yes, execute step 107; otherwise, execute step 115;
具体地,移动终端判断是否有设备对象存储在第一设备列表中且没有存储在第二设备列表中,如果是,则判定第一设备列表中具有新增的设备对象并将存储在第一设备列表中且没有存储在第二设备列表中的设备对象作为新增的设备对象,执行步骤107;否则,判定第一设备列表中没有新增的设备对象,执行步骤115。Specifically, the mobile terminal judges whether there is a device object stored in the first device list and not stored in the second device list, and if so, determines that there is a new device object in the first device list and stores it in the first device list. The device objects in the list and not stored in the second device list are regarded as newly added device objects, and step 107 is performed; otherwise, it is determined that there is no newly added device object in the first device list, and step 115 is performed.
需说明的是,步骤101中还包括初始化第二设备列表,其中,初始化第二设备列表具体为:创建空的第二设备列表。It should be noted that, step 101 also includes initializing a second device list, wherein the initialization of the second device list specifically includes: creating an empty second device list.
步骤107:保存新增的设备对象;Step 107: save the newly added device object;
具体地,移动终端将新增的设备对象存储在第二设备列表中。Specifically, the mobile terminal stores the newly added device object in the second device list.
步骤108:判断新增的设备对象是否具有设备权限,如果是,则执行步骤111;否则,执行步骤109;Step 108: Determine whether the newly added device object has device authority, if yes, execute step 111; otherwise, execute step 109;
具体地,移动终端使用新增的设备对象调用USB管理对象的获取设备权限函数获取新增的设备对象的设备权限标识,判断新增的设备对象的设备权限标识是否为TRUE,如果是,则执行步骤111;否则,执行步骤109。Specifically, the mobile terminal uses the newly-added device object to call the device permission function of the USB management object to obtain the device permission identifier of the newly-added device object, and judges whether the device permission identifier of the newly-added device object is TRUE, and if so, executes Step 111; otherwise, go to step 109.
其中,移动终端使用新增的设备对象调用USB管理对象的获取设备权限函数获取新增的设备对象的设备权限标识具体为:Wherein, the mobile terminal uses the newly-added device object to call the acquisition device permission function of the USB management object to obtain the device permission identifier of the newly-added device object, specifically:
BooleanbHasPermissionm=m_UsbManager.hasPermission(device);BooleanbHasPermissionm = m_UsbManager.hasPermission(device);
步骤109:为新增的设备对象申请设备权限;Step 109: apply for device permission for the newly added device object;
具体地,移动终端使用设备对象和权限许可对象调用USB管理对象的申请权限函数为设备对象申请设备权限。Specifically, the mobile terminal uses the device object and the permission object to call the application permission function of the USB management object to apply for the device permission for the device object.
具体为:m_UsbManager.requestPermission(device,mPermissionIntent);Specifically: m_UsbManager.requestPermission(device, mPermissionIntent);
更加详细地,移动终端使用设备对象和权限许可对象调用USB管理对象的申请权限函数为设备对象申请设备权限,在移动终端的显示界面提示用户是否为USBKEY授权,当USBKEY获取到用户授权后,与USBKEY对应的设备对象的设备权限标识为TRUE。In more detail, the mobile terminal uses the device object and the permission permission object to call the application permission function of the USB management object to apply for the device permission for the device object, and prompts the user on the display interface of the mobile terminal whether the user is authorized by the USBKEY. The device permission flag of the device object corresponding to the USBKEY is TRUE.
步骤110:判断新增的设备对象是否具有设备权限,如果是,则执行步骤111;否则,返回步骤106;Step 110: Determine whether the newly added device object has device authority, if yes, execute step 111; otherwise, return to step 106;
步骤111:获取与新增的设备对象对应的设备连接句柄和设备接口对象;Step 111: Obtain the device connection handle and device interface object corresponding to the newly added device object;
具体地,移动终端使用新增的设备对象调用USB管理对象的打开设备函数获取与新增的设备对象对应的设备连接句柄;调用新增的设备对象的获取接口函数获取与新增的设备对象对应的设备接口对象。Specifically, the mobile terminal uses the newly-added device object to call the open device function of the USB management object to obtain the device connection handle corresponding to the newly-added device object; The device interface object.
其中,移动终端使用新增的设备对象调用USB管理对象的打开设备函数获取与新增的设备对象对应的设备连接句柄,具体为:Wherein, the mobile terminal uses the newly-added device object to call the open device function of the USB management object to obtain the device connection handle corresponding to the newly-added device object, specifically:
UsbDeviceConnectionhconnection=m_UsbManager.openDevice(device)UsbDeviceConnectionhconnection=m_UsbManager.openDevice(device)
移动终端调用新增的设备对象的获取接口函数获取与新增的设备对象对应的设备接口对象,具体为:The mobile terminal calls the acquisition interface function of the newly added device object to obtain the device interface object corresponding to the newly added device object, specifically:
UsbInterfacem_usbInterface=m_device.getInterface(0);UsbInterface m_usbInterface = m_device.getInterface(0);
步骤112:根据设备连接句柄初始化设备接口对象;Step 112: Initialize the device interface object according to the device connection handle;
具体地,移动终端调用设备连接句柄的声明接口函数初始化设备接口对象;Specifically, the mobile terminal calls the declared interface function of the device connection handle to initialize the device interface object;
具体为:m_connection.claimInterface(m_usbInterface,true);Specifically: m_connection.claimInterface(m_usbInterface,true);
步骤113:根据设备接口对象获取与新增的设备对象对应的设备通讯端点;Step 113: Obtain the device communication endpoint corresponding to the newly added device object according to the device interface object;
具体地,移动终端调用设备接口对象的获取端点函数得到与新增的设备对象对应的设备通讯端点。具体为:Specifically, the mobile terminal calls the endpoint acquisition function of the device interface object to obtain the device communication endpoint corresponding to the newly added device object. Specifically:
其中,设备通讯端点具体包括:设备输入端点和设备输出端点。Wherein, the device communication endpoint specifically includes: a device input endpoint and a device output endpoint.
步骤114:生成设备通讯句柄,将设备通讯句柄和新增的设备对象、设备连接句柄和设备通讯端点分别建立对应关系并保存,返回步骤106;Step 114: Generate a device communication handle, establish a corresponding relationship with the newly added device object, device connection handle and device communication endpoint respectively and save the device communication handle, and return to step 106;
步骤115:判断第一设备列表中是否有减少的设备对象,如果是,则执行步骤116;否则,执行步骤119;Step 115: Determine whether there are reduced device objects in the first device list, if yes, execute step 116; otherwise, execute step 119;
具体地,移动终端判断是否有设备对象存储在第二设备列表中且没有存储在第一设列表中,如果是,则判定第一设备列表中有减少的设备对象并将存储在第二设备列表中且没有存储在第一设备列表中的设备对象作为减少的设备对象,执行步骤116;否则,判定第一设备列表中没有减少的设备对象,执行步骤119;Specifically, the mobile terminal judges whether there are device objects stored in the second device list and not stored in the first device list, and if so, determines that there are reduced device objects in the first device list and stores them in the second device list. and not stored in the first device list as reduced device objects, execute step 116; otherwise, determine that there is no reduced device object in the first device list, execute step 119;
步骤116:判断是否存在与减少的设备对象对应的设备通讯句柄,如果是,则执行步骤117;否则,执行步骤118;Step 116: Determine whether there is a device communication handle corresponding to the reduced device object, if yes, execute step 117; otherwise, execute step 118;
步骤117:销毁减少的设备对象,及与其分别对应的设备通讯句柄、设备连接句柄和设备通讯端点,返回步骤115;Step 117: Destroy the reduced device objects, and their corresponding device communication handles, device connection handles and device communication endpoints, and return to step 115;
步骤118:销毁减少的设备对象,返回步骤115;Step 118: Destroy the reduced device objects and return to Step 115;
步骤119:判断是否退出监控流程,如果是,则退出监控流程;否则,返回步骤102。Step 119: Determine whether to exit the monitoring process, if yes, exit the monitoring process; otherwise, return to step 102.
其中,步骤105和步骤103之后,还可以执行步骤115;相应的当步骤115中判定为否后,返回步骤106,当步骤106中判定为否后执行步骤119。Wherein, after step 105 and step 103, step 115 may also be executed; correspondingly, when step 115 is judged as no, return to step 106, and when step 106 is judged as no, step 119 is executed.
另外,步骤102中当在预设时间内获取到与USBKEY对应的设备对象后,还可以直接将获取到的设备对象存储在第一设备列表中之后,执行步骤106;相应地,步骤112和步骤113之间还可以包括:移动终端根据设备连接句柄通过控制传输端点获取USBKEY的设备识别标识,判断设备识别标识是否是预设识别标识,如果是,则继续;否则,返回步骤102。In addition, in step 102, after obtaining the device object corresponding to the USBKEY within the preset time, the obtained device object can also be directly stored in the first device list, and then step 106 is executed; correspondingly, step 112 and step Between 113 may also include: the mobile terminal obtains the device identification of the USBKEY through the control transmission endpoint according to the device connection handle, and judges whether the device identification is a preset identification, and if so, continues; otherwise, returns to step 102.
具体地,移动终端调用设备连接句柄的控制传输函数通过控制传输端点获取USBKEY的设备识别标识,判断设备识别标识是否是预设识别标识,如果是,则继续;否则,返回步骤102。Specifically, the mobile terminal calls the control transfer function of the device connection handle to obtain the device identification of the USBKEY through the control transfer endpoint, and judges whether the device identification is a preset identification, and if so, continues; otherwise, returns to step 102.
其中,预设识别标识为支持FIDO协议的USBKEY的预设识别标识,具体包括:第一预设识别标识和第二预设识别标识,第一预设识别标识可以具体为0xf1d0;第二预设识别标识可以具体为0x01。设备识别标识具体包括第一标识和第二标识。Wherein, the preset identification mark is the preset identification mark of the USBKEY supporting the FIDO protocol, specifically comprising: a first preset identification mark and a second preset identification mark, the first preset identification mark can be specifically 0xf1d0; the second preset identification mark The identification mark can be specifically 0x01. The device identification identifier specifically includes a first identifier and a second identifier.
相应地,更加具体地,移动终端调用设备连接句柄的控制传输函数通过控制传输端点获取USBKEY的第一标识和第二标识,判断第一标识是否和第一预设识别标识匹配且第二标识是否是和第二预设识别标识匹配,如果是,则继续;否则,返回步骤102。Correspondingly, more specifically, the mobile terminal calls the control transfer function of the device connection handle to obtain the first identification and the second identification of the USBKEY through the control transfer endpoint, and judges whether the first identification matches the first preset identification identification and whether the second identification is If yes, it matches the second preset identifier, if yes, continue; otherwise, return to step 102 .
其中,控制传输函数为intcontrolTransfer(intrequestType,intrequest,intvalue,intindex,byte[]buffer,intlength,inttimeout);第一标识和第二标识可以分别为USBKEY的报告描述符中的HID_UsagePage和HID_Usage。Wherein, the control transfer function is intcontrolTransfer(intrequestType, intrequest, intvalue, intindex, byte[]buffer, intlength, inttimeout); the first identifier and the second identifier can be HID_UsagePage and HID_Usage in the report descriptor of USBKEY respectively.
本实施例中,监控流程,也可以如图4所示,移动终端具体执行:In this embodiment, the monitoring process can also be shown in Figure 4, and the mobile terminal specifically executes:
步骤201:开启监控流程,初始化USB管理对象和权限许可对象;Step 201: start the monitoring process, initialize the USB management object and the permission object;
具体地,移动终端开启监控流程,调用初始化函数初始化USB管理对象和权限许可对象。其中,初始化函数包括第一初始化函数和第二初始化函数。Specifically, the mobile terminal starts the monitoring process, and calls the initialization function to initialize the USB management object and the permission object. Wherein, the initialization function includes a first initialization function and a second initialization function.
其中,移动终端调用第一初始化函数初始化USB管理对象具体为:Wherein, the mobile terminal calls the first initialization function to initialize the USB management object specifically as follows:
mUsbManager=(UsbManager)getSystemService(Context.USB_SERVICE);其中,mUsbManager为USB管理对象;mUsbManager=(UsbManager)getSystemService(Context.USB_SERVICE); Among them, mUsbManager is the USB management object;
移动终端调用第二初始化函数初始化权限许可对象具体为:The mobile terminal calls the second initialization function to initialize the permission permission object specifically as follows:
mPermissionIntent=PendingIntent.getBroadcast(this,0,newIntent(ACTION_USB_PERMISSION),0);其中mPermissionIntent为权限许可对象;mPermissionIntent=PendingIntent.getBroadcast(this,0,newIntent(ACTION_USB_PERMISSION),0); where mPermissionIntent is the permission object;
步骤202:在预设时间内获取与USBKEY对应的设备对象,当在预设时间内获取到与USBKEY对应的设备对象后,执行步骤204;当在预设时间内没有获取到与USBKEY对应的设备对象后,执行步骤203;Step 202: Obtain the device object corresponding to the USBKEY within the preset time, when the device object corresponding to the USBKEY is obtained within the preset time, perform step 204; when the device object corresponding to the USBKEY is not obtained within the preset time After object, execute step 203;
具体地,JAVA调用USB管理对象的获取设备列表函数在预设时间内对USBKEY进行枚举,获取与USBKEY对应的设备对象,当在预设时间内获取到与USBKEY对应的设备对象后,执行步骤204;当在预设时间内没有获取到与USBKEY对应的设备对象后,执行步骤203。Specifically, JAVA calls the acquisition device list function of the USB management object to enumerate the USBKEY within the preset time, and obtain the device object corresponding to the USBKEY. When the device object corresponding to the USBKEY is obtained within the preset time, perform the steps 204: When the device object corresponding to the USBKEY is not acquired within the preset time, execute step 203.
优选地,预设时间为2秒。Preferably, the preset time is 2 seconds.
其中,移动终端调用USB管理对象的获取设备列表函数在预设时间内对USBKEY进行枚举,获取与USBKEY对应的设备对象,具体为:HashMap<String,UsbDevice>deviceMap=m_UsbManager.getDeviceList();Wherein, the mobile terminal calls the acquisition device list function of the USB management object to enumerate the USBKEY within a preset time, and obtains the device object corresponding to the USBKEY, specifically: HashMap<String, UsbDevice>deviceMap=m_UsbManager.getDeviceList();
其中,设备对象中具体包括:USBKEY的厂商标识信息。其中,USBKEY的厂商标识信息可以具体为USBKEY的PID(ProductID,产品识别码)和VID(VendorID,供应商身份)。Wherein, the device object specifically includes: vendor identification information of the USBKEY. Wherein, the manufacturer identification information of the USBKEY may specifically be a PID (ProductID, product identification code) and VID (VendorID, supplier identity) of the USBKEY.
步骤203:清空第一设备列表,执行步骤206;Step 203: clear the first device list, and execute step 206;
步骤204:判断是否存在与预设厂商标识相对应的设备对象,如果是,则执行步骤205;否则,返回步骤202;Step 204: Judging whether there is a device object corresponding to the preset manufacturer ID, if yes, execute step 205; otherwise, return to step 202;
具体地,移动终端获取设备对象中的厂商标识信息,判断获取到的设备对象的厂商标识信息是否和预设厂商标识对应,如果是,则执行步骤205;否则,返回步骤202。Specifically, the mobile terminal acquires the vendor identification information in the device object, and judges whether the obtained vendor identification information of the device object corresponds to the preset vendor ID, and if yes, executes step 205; otherwise, returns to step 202.
步骤205:将与预设厂商标识相对应的设备对象存储到第一设备列表中,执行步骤206;Step 205: Store the device object corresponding to the preset manufacturer identifier in the first device list, and execute step 206;
步骤206:判断第一设备列表中是否有新增的设备对象,如果是,则执行步骤207;否则,执行步骤210;Step 206: Judging whether there is a newly added device object in the first device list, if yes, execute step 207; otherwise, execute step 210;
具体地,移动终端判断是否有设备对象存储在第一设备列表中且没有存储在第二设备列表中,如果是,则判定第一设备列表中具有新增的设备对象并将存储在第一设备列表中且没有存储在第二设备列表中的设备对象作为新增的设备对象,执行步骤207;否则,判定第一设备列表中没有新增的设备对象,执行步骤210。Specifically, the mobile terminal judges whether there is a device object stored in the first device list and not stored in the second device list, and if so, determines that there is a new device object in the first device list and stores it in the first device list. The device objects in the list and not stored in the second device list are regarded as newly added device objects, and step 207 is executed; otherwise, it is determined that there is no newly added device object in the first device list, and step 210 is executed.
需说明的是,步骤201中还包括初始化第二设备列表,其中,初始化第二设备列表具体为:创建空的第二设备列表。It should be noted that, step 201 also includes initializing a second device list, wherein the initialization of the second device list specifically includes: creating an empty second device list.
步骤207:将新增的设备对象存储在第二设备列表中;Step 207: Store the newly added device object in the second device list;
步骤208:判断第二设备列表中的设备对象是否具有设备权限,如果是,则返回步骤206;否则,执行步骤209;Step 208: Determine whether the device object in the second device list has device authority, if yes, return to step 206; otherwise, execute step 209;
具体地,移动终端使用第二设备列表中的设备对象调用USB管理对象的获取设备权限函数获取新增的设备对象的设备权限标识,判断新增的设备对象的设备权限标识是否为TRUE,如果是,则返回步骤206;否则,执行步骤209。Specifically, the mobile terminal uses the device object in the second device list to call the device permission function of the USB management object to obtain the device permission identifier of the newly added device object, and judges whether the device permission identifier of the newly added device object is TRUE. , return to step 206; otherwise, execute step 209.
其中,移动终端使用第二设备列表中的设备对象调用USB管理对象的获取设备权限函数获取新增的设备对象的设备权限标识,具体为:Wherein, the mobile terminal uses the device object in the second device list to call the device permission function of the USB management object to obtain the device permission identifier of the newly added device object, specifically:
BooleanbHasPermissionm=m_UsbManager.hasPermission(device);BooleanbHasPermissionm = m_UsbManager.hasPermission(device);
步骤209:为第二设备列表中的设备对象申请设备权限,返回步骤206;Step 209: apply for device permissions for the device objects in the second device list, and return to step 206;
具体地,移动终端使用设备对象和权限许可对象调用USB管理对象的申请权限函数为为第二设备列表中的设备对象申请设备权限。Specifically, the mobile terminal uses the device object and the permission permission object to call the permission application function of the USB management object to apply for the device permission for the device object in the second device list.
具体为:m_UsbManager.requestPermission(device,mPermissionIntent);Specifically: m_UsbManager.requestPermission(device, mPermissionIntent);
更加详细地,移动终端使用设备对象和权限许可对象调用USB管理对象的申请权限函数为设备对象申请设备权限,在移动终端的显示界面提示用户是否为USBKEY授权,当USBKEY获取到用户授权后,与USBKEY对应的设备对象的设备权限标识为TRUE。In more detail, the mobile terminal uses the device object and the permission permission object to call the application permission function of the USB management object to apply for the device permission for the device object, and prompts the user on the display interface of the mobile terminal whether the user is authorized by the USBKEY. The device permission flag of the device object corresponding to the USBKEY is TRUE.
步骤210:判断第一设备列表中是否有减少的设备对象,如果是,则执行步骤211;否则,执行步骤214;Step 210: Determine whether there are reduced device objects in the first device list, if yes, execute step 211; otherwise, execute step 214;
具体地,移动终端判断是否有设备对象存储在第二设备列表中且没有存储在第一设列表中,如果是,则判定第一设备列表中有减少的设备对象并将存储在第二设备列表中且没有存储在第一设备列表中的设备对象作为减少的设备对象,执行步骤211;否则,判定第一设备列表中没有减少的设备对象,执行步骤214;Specifically, the mobile terminal judges whether there are device objects stored in the second device list and not stored in the first device list, and if so, determines that there are reduced device objects in the first device list and stores them in the second device list. and not stored in the first device list as reduced device objects, execute step 211; otherwise, determine that there is no reduced device object in the first device list, execute step 214;
步骤211:判断是否存在与减少的设备对象对应的设备通讯句柄,如果是,则执行步骤212;否则,执行步骤213;Step 211: Determine whether there is a device communication handle corresponding to the reduced device object, if yes, execute step 212; otherwise, execute step 213;
步骤212:销毁减少的设备对象,及与其分别对应的设备通讯句柄、设备连接句柄和设备通讯端点,返回步骤210;Step 212: Destroy the reduced device objects and their corresponding device communication handles, device connection handles and device communication endpoints, and return to step 210;
步骤213:销毁减少的设备对象,返回步骤210;Step 213: Destroy the reduced device objects and return to Step 210;
步骤214:判断第二设备列表中的设备对象是否具有设备权限且不存在设备通讯句柄,如果是,则执行步骤215;否则,执行步骤219;Step 214: Determine whether the device object in the second device list has device authority and does not have a device communication handle, if yes, perform step 215; otherwise, perform step 219;
步骤215:获取与第二设备列表中的设备对象对应的设备连接句柄和设备接口对象;Step 215: Obtain the device connection handle and device interface object corresponding to the device object in the second device list;
具体地,移动终端使用第二设备列表中的设备对象调用USB管理对象的打开设备函数获取与第二设备列表中的设备对象对应的设备连接句柄;调用第二设备列表中的设备对象的获取接口函数获取与第二设备列表中的设备对象对应的设备接口对象。Specifically, the mobile terminal uses the device object in the second device list to call the open device function of the USB management object to obtain the device connection handle corresponding to the device object in the second device list; call the acquisition interface of the device object in the second device list The function obtains device interface objects corresponding to the device objects in the second device list.
其中,移动终端使用第二设备列表中的设备对象调用USB管理对象的打开设备函数获取与第二设备列表中的设备对象对应的设备连接句柄,具体为:Wherein, the mobile terminal uses the device object in the second device list to call the open device function of the USB management object to obtain the device connection handle corresponding to the device object in the second device list, specifically:
UsbDeviceConnectionhconnection=m_UsbManager.openDevice(device)UsbDeviceConnectionhconnection=m_UsbManager.openDevice(device)
移动终端调用第二设备列表中的设备对象的获取接口函数获取与第二设备列表中的设备对象对应的设备接口对象,具体为:UsbInterfacem_usbInterface=m_device.getInterface(0);The mobile terminal calls the acquisition interface function of the device object in the second device list to obtain the device interface object corresponding to the device object in the second device list, specifically: UsbInterfacem_usbInterface=m_device.getInterface(0);
步骤216:根据设备连接句柄初始化设备接口对象;Step 216: Initialize the device interface object according to the device connection handle;
具体地,移动终端调用设备连接句柄的声明接口函数初始化设备接口对象;Specifically, the mobile terminal calls the declared interface function of the device connection handle to initialize the device interface object;
声明接口函数具体为:m_connection.claimInterface(m_usbInterface,true);The declaration interface function is specifically: m_connection.claimInterface(m_usbInterface,true);
217:根据设备接口对象获取与第二设备列表中的设备对象对应的设备通讯端点;217: Obtain the device communication endpoint corresponding to the device object in the second device list according to the device interface object;
具体地,移动终端调用设备接口对象的获取端点函数得到与新增的设备对象对应的设备通讯端点。具体为:Specifically, the mobile terminal calls the endpoint acquisition function of the device interface object to obtain the device communication endpoint corresponding to the newly added device object. Specifically:
其中,设备通讯端点具体包括:设备输入端点和设备输出端点。Wherein, the device communication endpoint specifically includes: a device input endpoint and a device output endpoint.
步骤218:生成设备通讯句柄,将设备通讯句柄和第二设备列表中的设备对象、设备连接句柄和设备通讯端点分别建立对应关系并保存,返回步骤214;Step 218: Generate a device communication handle, establish a corresponding relationship between the device communication handle and the device object in the second device list, the device connection handle and the device communication endpoint, and save it, and return to step 214;
步骤219:判断是否退出监控流程,如果是,则退出监控流程;否则,返回步骤202。Step 219: Determine whether to exit the monitoring process, if yes, exit the monitoring process; otherwise, return to step 202.
其中,步骤205和步骤203之后还可以执行步骤210,相应的,当步骤210中判定为否后,执行步骤206,步骤206中判定为否后,执行步骤214。Wherein, after step 205 and step 203, step 210 may also be executed. Correspondingly, when step 210 is judged as no, step 206 is executed, and after step 206 is judged as no, step 214 is executed.
另外,步骤202中当在预设时间内获取到与USBKEY对应的设备对象后,还可以直接将获取到的设备对象存储在第一设备列表中之后,执行步骤206;相应地,步骤216和步骤217之间还可以包括:移动终端根据设备连接句柄通过控制传输端点获取USBKEY的设备识别标识,判断设备识别标识是否是预设识别标识,如果是,则继续;否则,返回步骤202。In addition, in step 202, after the device object corresponding to the USBKEY is obtained within the preset time, step 206 may be executed after the obtained device object is directly stored in the first device list; correspondingly, step 216 and step 217 may also include: the mobile terminal obtains the device identification of the USBKEY through the control transmission endpoint according to the device connection handle, and judges whether the device identification is a preset identification, if yes, continue; otherwise, return to step 202.
具体地,移动终端调用设备连接句柄的控制传输函数通过控制传输端点获取USBKEY的设备识别标识,判断设备识别标识是否是预设识别标识,如果是,则继续;否则,返回步骤202。Specifically, the mobile terminal calls the control transfer function of the device connection handle to obtain the device identification of the USBKEY through the control transfer endpoint, and judges whether the device identification is a preset identification, and if so, continues; otherwise, returns to step 202.
其中,预设识别标识为支持FIDO协议的USBKEY的预设识别标识,具体包括:第一预设识别标识和第二预设识别标识,第一预设识别标识可以具体为0xf1d0;第二预设识别标识可以具体为:0x01。设备识别标识具体包括第一标识和第二标识。Wherein, the preset identification mark is the preset identification mark of the USBKEY supporting the FIDO protocol, specifically comprising: a first preset identification mark and a second preset identification mark, the first preset identification mark can be specifically 0xf1d0; the second preset identification mark The identification mark may specifically be: 0x01. The device identification identifier specifically includes a first identifier and a second identifier.
相应地,更加具体地,移动终端调用设备连接句柄的控制传输函数通过控制传输端点获取USBKEY的第一标识和第二标识,判断第一标识是否和第一预设识别标识匹配且第二标识是否是和第二预设识别标识匹配,如果是,则继续;否则,返回步骤202。Correspondingly, more specifically, the mobile terminal calls the control transfer function of the device connection handle to obtain the first identification and the second identification of the USBKEY through the control transfer endpoint, and judges whether the first identification matches the first preset identification identification and whether the second identification is Yes, it matches the second preset identifier, if yes, continue; otherwise, return to step 202 .
其中,控制传输函数为controlTransfer();第一标识和第二标识可以分别为USBKEY的报告描述符中的HID_UsagePage和HID_Usage。Wherein, the control transfer function is controlTransfer(); the first identifier and the second identifier may be HID_UsagePage and HID_Usage in the report descriptor of the USBKEY respectively.
本实施例中,监控流程,还可以如图5所示,移动终端具体执行:In this embodiment, the monitoring process can also be specifically executed by the mobile terminal as shown in Figure 5:
步骤301:开启监控流程,初始化USB管理对象、广播接收对象、权限许可对象和广播过滤对象;Step 301: start the monitoring process, initialize the USB management object, the broadcast receiving object, the permission object and the broadcast filtering object;
具体地,移动终端调用初始化函数初始化USB管理对象、权限许可对象、广播接收对象和广播过滤对象。其中,初始化函数包括第一初始化函数、第二初始化函数、第三初始化函数和第四初始化函数。Specifically, the mobile terminal calls the initialization function to initialize the USB management object, the permission permission object, the broadcast receiving object and the broadcast filtering object. Wherein, the initialization function includes a first initialization function, a second initialization function, a third initialization function and a fourth initialization function.
其中,移动终端调用第一初始化函数初始化USB管理对象具体为:Wherein, the mobile terminal calls the first initialization function to initialize the USB management object specifically as follows:
mUsbManager=(UsbManager)getSystemService(Context.USB_SERVICE);其中,mUsbManager为USB管理对象;mUsbManager=(UsbManager)getSystemService(Context.USB_SERVICE); Among them, mUsbManager is the USB management object;
移动终端调用第二初始化函数初始化权限许可对象具体为:The mobile terminal calls the second initialization function to initialize the permission permission object specifically as follows:
mPermissionIntent=PendingIntent.getBroadcast(this,0,newIntent(ACTION_USB_PERMISSION),0);其中,:mPermissionIntent为权限许可对象;进一步地说明,权限许可对象是一个待处理的事件对象;mPermissionIntent=PendingIntent.getBroadcast(this,0,newIntent(ACTION_USB_PERMISSION),0); Among them, mPermissionIntent is the permission object; further description, the permission object is an event object to be processed;
ACTION_USB_PERMISSION为设备权限消息,ACTION_USB_PERMISSION可以具体为"com.android.example.USB_PERMISSION"。ACTION_USB_PERMISSION is the device permission message, and ACTION_USB_PERMISSION can be specifically "com.android.example.USB_PERMISSION".
移动终端调用第三初始化函数初始化广播接收对象具体为:privatefinalBroadcastReceivermUsbReceiver=newBroadcastReceiver();其中,mUsbReceiver为广播接收对象;The mobile terminal calls the third initialization function to initialize the broadcast receiving object specifically: privatefinalBroadcastReceivermUsbReceiver=newBroadcastReceiver(); wherein, mUsbReceiver is the broadcast receiving object;
移动终端调用第四初始化函数初始化广播过滤对象具体为:IntentFilterfilter=newIntentFilter();其中,filter为广播过滤对象。The mobile terminal calls the fourth initialization function to initialize the broadcast filter object specifically: IntentFilterfilter=newIntentFilter(); wherein, filter is the broadcast filter object.
步骤302:向广播过滤对象中添加关心消息;Step 302: Add a concern message to the broadcast filter object;
具体地,移动终端调用添加消息函数向过滤对象中添加关心消息,其中,关心消息包括设备插入消息、设备拔出消息和设备权限消息。Specifically, the mobile terminal calls the adding message function to add the concerned message to the filter object, wherein the concerned message includes a device insertion message, a device removal message and a device permission message.
其中,移动终端调用添加消息函数向过滤对象中添加关心消息具体为:Among them, the mobile terminal calls the add message function to add the concerned message to the filter object, specifically:
filter.addAction(ACTION_USB_PERMISSION);filter.addAction(ACTION_USB_PERMISSION);
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);其中,filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); among them,
ACTION_USB_PERMISSION为设备权限消息;ACTION_USB_PERMISSION is the device permission message;
UsbManager.ACTION_USB_DEVICE_ATTACHED为设备插入消息;UsbManager.ACTION_USB_DEVICE_ATTACHED inserts messages for the device;
UsbManager.ACTION_USB_DEVICE_DETACHED为设备拔出消息。UsbManager.ACTION_USB_DEVICE_DETACHED message for device unplugged.
步骤303:根据USB管理对象和广播过滤对象注册广播接收器;Step 303: Register the broadcast receiver according to the USB management object and the broadcast filter object;
具体地,移动终端使用USB管理对象和广播过滤对象调用注册广播函数注册广播接收器;Specifically, the mobile terminal uses the USB management object and the broadcast filter object to call the register broadcast function to register the broadcast receiver;
注册广播函数为registerReceiver(mUsbReceiver,filter);The registered broadcast function is registerReceiver(mUsbReceiver, filter);
步骤304:根据广播接收对象等待获取消息通知对象,当获取到消息通知对象后,根据消息通知对象获取与USBKEY对应的设备对象;Step 304: Waiting to obtain the message notification object according to the broadcast receiving object, and after obtaining the message notification object, obtain the device object corresponding to the USBKEY according to the message notification object;
具体地,移动终端调用广播接收对象的接收消息通知函数等待获取消息通讯对象,当获取到消息通知对象后,调用消息通知对象的第一打包函数获取与USBKEY对应的设备对象;Specifically, the mobile terminal calls the receiving message notification function of the broadcast receiving object and waits to obtain the message communication object. After the message notification object is obtained, the first packaging function of the message notification object is called to obtain the device object corresponding to the USBKEY;
其中,移动终端调用广播接收对象的接收消息通知函数等待获取消息通讯对象,接收消息通知函数具体为:Among them, the mobile terminal calls the receiving message notification function of the broadcast receiving object and waits to obtain the message communication object, and the receiving message notification function is specifically:
publicvoidonReceive(Contextcontext,Intentintent),其中,intent为消息通讯对象;publicvoidonReceive(Contextcontext,Intentintent), where intent is the message communication object;
移动终端调用消息通知对象的第一打包函数获取与USBKEY对应的设备对象,具体为:UsbDevicedevice=(UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);其中,device为设备对象。The mobile terminal calls the first packaging function of the message notification object to obtain the device object corresponding to the USBKEY, specifically: UsbDevicedevice=(UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); wherein, device is the device object.
其中,设备对象中具体包括:USBKEY的厂商标识信息,其中,USBKEY的厂商标识信息可以具体为USBKEY的PID(ProductID,产品识别码)和VID(VendorID,供应商身份)。Wherein, the device object specifically includes: the vendor identification information of the USBKEY, wherein the vendor identification information of the USBKEY may specifically be a PID (Product ID, product identification code) and a VID (Vendor ID, vendor identity) of the USB KEY.
步骤305:判断设备对象是否和预设厂商标识对应,如果是,则执行步骤306;否则,返回步骤304;Step 305: Determine whether the device object corresponds to the preset manufacturer ID, if yes, execute step 306; otherwise, return to step 304;
具体地,移动终端获取设备对象中的厂商标识信息,判断获取到的设备对象中的厂商标识信息是否和预设厂商标识对应,如果是,则执行步骤306;否则,返回步骤304。Specifically, the mobile terminal obtains the vendor identification information in the device object, and judges whether the obtained vendor identification information in the device object corresponds to the preset vendor identification, and if yes, executes step 306; otherwise, returns to step 304.
步骤306:根据消息通知对象获取设备对象的设备权限标识,根据消息通知对象获取消息通知,根据关心消息判断消息通知的类型,当消息通知的类型为设备权限消息时,执行步骤307;当消息通知的类型为设备插入消息时,执行步骤308;当消息通知的类型为设备拔出消息时,执行步骤314;Step 306: Obtain the device permission identifier of the device object according to the message notification object, obtain the message notification according to the message notification object, and judge the type of message notification according to the concerned message. When the type of message notification is a device permission message, perform step 307; when the message notification When the type of the message is a device insertion message, perform step 308; when the type of the message notification is a device pull out message, perform step 314;
具体地,移动终端调用消息通知对象的第二打包函数获取USBKEY的设备权限,调用消息通知对象的获取消息函数获取消息通知,根据关心消息判断消息通知的类型,当消息通知的类型为设备权限消息时,执行步骤307;当消息通知的类型为设备插入消息时,执行步骤308;当消息通知的类型为设备拔出消息时,执行步骤314;Specifically, the mobile terminal calls the second packaging function of the message notification object to obtain the device authority of the USBKEY, calls the message acquisition function of the message notification object to obtain the message notification, and judges the type of the message notification according to the concerned message. When the type of the message notification is a device permission message , execute step 307; when the type of message notification is a device insertion message, execute step 308; when the type of message notification is a device pull out message, execute step 314;
其中,移动终端调用消息通知对象的第二打包函数获取USBKEY的设备权限标识,具体为:Wherein, the mobile terminal calls the second packaging function of the message notification object to obtain the device authority identifier of the USBKEY, specifically:
BooleanBoolean
bHasPermission=intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED,false);其中,bHasPermission为设备权限标识;bHasPermission=intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED,false); where, bHasPermission is the device permission identifier;
移动终端调用消息通知对象的获取消息函数获取消息通知,具体为:The mobile terminal calls the get message function of the message notification object to get the message notification, specifically:
Stringaction=intent.getAction();其中,action为消息通知。Stringaction=intent.getAction(); wherein, action is a message notification.
步骤307:根据设备权限标识判断设备对象是否具有设备权限,如果是,则执行步骤309;否则,执行步骤317;Step 307: Determine whether the device object has device permissions according to the device permission identifier, if yes, go to step 309; otherwise, go to step 317;
具体地,移动终端判断设备权限标识是否为TRUE,如果是,则判定设备对象具有设备权限;否则,判定设备对象不具有设备权限。Specifically, the mobile terminal determines whether the device authority flag is TRUE, and if so, determines that the device object has the device authority; otherwise, determines that the device object does not have the device authority.
步骤308:根据设备权限标识判断设备对象是否具有设备权限,如果是,则执行步骤309;否则,执行步骤313;Step 308: Determine whether the device object has device permissions according to the device permission identifier, if yes, go to step 309; otherwise, go to step 313;
具体地,移动终端判断设备权限标识是否为TRUE,如果是,则判定设备对象具有设备权限;否则,判定设备对象不具有设备权限。Specifically, the mobile terminal determines whether the device authority flag is TRUE, and if so, determines that the device object has the device authority; otherwise, determines that the device object does not have the device authority.
步骤309:获取与设备对象对应的设备连接句柄和设备接口对象;Step 309: Obtain the device connection handle and device interface object corresponding to the device object;
具体地,移动终端使用设备对象调用USB管理对象的打开设备函数获取与设备对象对应的设备连接句柄;调用设备对象的获取接口函数获取与设备对象对应的设备接口对象。Specifically, the mobile terminal uses the device object to call the open device function of the USB management object to obtain the device connection handle corresponding to the device object; calls the device object's obtain interface function to obtain the device interface object corresponding to the device object.
其中,移动终端使用设备对象调用USB管理对象的打开设备函数获取与设备对象对应的设备连接句柄,具体为:Wherein, the mobile terminal uses the device object to call the open device function of the USB management object to obtain the device connection handle corresponding to the device object, specifically:
UsbDeviceConnectionhconnection=m_UsbManager.openDevice(device)UsbDeviceConnectionhconnection=m_UsbManager.openDevice(device)
调用设备对象的获取接口函数获取与设备对象对应的设备接口对象,具体为:UsbInterfacem_usbInterface=m_device.getInterface(0);Call the acquisition interface function of the device object to obtain the device interface object corresponding to the device object, specifically: UsbInterfacem_usbInterface=m_device.getInterface(0);
步骤310:根据设备连接句柄初始化设备接口对象;Step 310: Initialize the device interface object according to the device connection handle;
具体地,移动终端调用设备连接句柄的声明接口函数初始化设备接口对象;Specifically, the mobile terminal calls the declared interface function of the device connection handle to initialize the device interface object;
具体为:m_connection.claimInterface(m_usbInterface,true);Specifically: m_connection.claimInterface(m_usbInterface,true);
步骤311:根据设备接口对象获取与设备对象对应的设备通讯端点;Step 311: Obtain the device communication endpoint corresponding to the device object according to the device interface object;
具体地,移动终端调用设备接口对象的获取端点函数得到与设备对象对应的设备通讯端点。具体为: Specifically, the mobile terminal calls the endpoint acquisition function of the device interface object to obtain the device communication endpoint corresponding to the device object. Specifically:
步骤312:生成设备通讯句柄,将设备通讯句柄和设备对象、设备连接句柄和设备通讯端点分别建立对应关系并保存,执行步骤317;Step 312: Generate a device communication handle, establish and save corresponding relationships between the device communication handle and the device object, the device connection handle and the device communication endpoint, and execute step 317;
步骤313:为设备对象申请设备权限,执行步骤317;Step 313: Apply for the device permission for the device object, go to step 317;
具体地,移动终端使用设备对象和权限许可对象调用USB管理对象的申请权限函数为设备对象申请设备权限。Specifically, the mobile terminal uses the device object and the permission object to call the application permission function of the USB management object to apply for the device permission for the device object.
具体为:m_UsbManager.requestPermission(device,mPermissionIntent);Specifically: m_UsbManager.requestPermission(device, mPermissionIntent);
更加详细地,移动终端使用设备对象和权限许可对象调用USB管理对象的申请权限函数为设备对象申请设备权限,在移动终端的显示界面提示用户是否为USBKEY授权,当USBKEY获取到用户授权后,与USBKEY对应的设备对象的设备权限标识为TRUE。In more detail, the mobile terminal uses the device object and the permission permission object to call the application permission function of the USB management object to apply for the device permission for the device object, and prompts the user on the display interface of the mobile terminal whether the user is authorized by the USBKEY. The device permission flag of the device object corresponding to the USBKEY is TRUE.
步骤314:判断是否存在与设备对象对应的设备通讯句柄,如果是,则执行步骤315;否则,执行步骤316;Step 314: Determine whether there is a device communication handle corresponding to the device object, if yes, execute step 315; otherwise, execute step 316;
步骤315:销毁设备对象,及与其分别对应的设备通讯句柄、设备连接句柄和设备通讯端点,执行步骤317;Step 315: Destroy the device object, and its corresponding device communication handle, device connection handle and device communication endpoint, and execute step 317;
步骤316:销毁设备对象,执行步骤317;Step 316: Destroy the device object, go to step 317;
步骤317:判断是否退出监控流程,如果是,则退出监控流程;否则,返回步骤304;Step 317: Determine whether to exit the monitoring process, if yes, then exit the monitoring process; otherwise, return to step 304;
另外,移动终端执行步骤304之后还可以直接执行步骤306;相应地,步骤310和步骤311之间还可以包括:移动终端根据设备连接句柄通过控制传输端点获取USBKEY的设备识别标识,判断设备识别标识是否是预设识别标识,如果是,则继续;否则,返回步骤304。In addition, after the mobile terminal executes step 304, it can also directly execute step 306; correspondingly, between step 310 and step 311 may also include: the mobile terminal obtains the device identification of the USBKEY by controlling the transmission endpoint according to the device connection handle, and determines the device identification Whether it is a preset identification mark, if yes, continue; otherwise, return to step 304 .
具体地,移动终端调用设备连接句柄的控制传输函数通过控制传输端点获取USBKEY的设备识别标识,判断设备识别标识是否是预设识别标识,如果是,则继续;否则,返回步骤304。Specifically, the mobile terminal calls the control transfer function of the device connection handle to obtain the device identification of the USBKEY through the control transfer endpoint, and judges whether the device identification is a preset identification, and if so, continues; otherwise, returns to step 304.
其中,预设识别标识为支持FIDO协议的USBKEY的预设识别标识,具体包括:第一预设识别标识和第二预设识别标识,第一预设识别标识可以具体为0xf1d0;第二预设识别标识可以具体为0x01。设备识别标识具体包括第一标识和第二标识。Wherein, the preset identification mark is the preset identification mark of the USBKEY supporting the FIDO protocol, specifically comprising: a first preset identification mark and a second preset identification mark, the first preset identification mark can be specifically 0xf1d0; the second preset identification mark The identification mark can be specifically 0x01. The device identification identifier specifically includes a first identifier and a second identifier.
相应地,更加具体地,移动终端调用设备连接句柄的控制传输函数通过控制传输端点获取USBKEY的第一标识和第二标识,判断第一标识是否和第一预设识别标识匹配且第二标识是否是和第二预设识别标识匹配,如果是,则继续;否则,返回步骤304。Correspondingly, more specifically, the mobile terminal calls the control transfer function of the device connection handle to obtain the first identification and the second identification of the USBKEY through the control transfer endpoint, and judges whether the first identification matches the first preset identification identification and whether the second identification is Yes, it matches the second preset identifier, if yes, continue; otherwise, return to step 304 .
其中,控制传输函数为controlTransfer();第一标识和第二标识可以分别为USBKEY的报告描述符中的HID_UsagePage和HID_Usage。Wherein, the control transfer function is controlTransfer(); the first identifier and the second identifier may be HID_UsagePage and HID_Usage in the report descriptor of the USBKEY respectively.
实施例2Example 2
本实施例提供了一种与智能密钥设备通讯的装置,如图6所示,包括:初始化模块01、监控模块02、第一获取模块03、第一判断模块04、申请权限模块05、第二判断模块06、第二获取模块07、第一封装模块08、第一发送模块09、第一接收模块10和第一解封模块11;This embodiment provides a device for communicating with a smart key device, as shown in FIG. Two judging module 06, the second acquiring module 07, the first packaging module 08, the first sending module 09, the first receiving module 10 and the first unpacking module 11;
初始化模块01,用于初始化;Initialization module 01, used for initialization;
监控模块02,用于当初始化模块01进行初始化后,采用广播或者枚举的方式,监控是否有智能密钥设备插入;以及当第二判断模块06判定为否后,采用广播或者枚举的方式,监控是否有智能密钥设备插入;The monitoring module 02 is used to monitor whether a smart key device is inserted by broadcasting or enumerating after the initialization module 01 is initialized; , to monitor whether there is a smart key device inserted;
第一获取模块03,用于当监控模块02监控到智能密钥设备插入后,获取与智能密钥设备对应的设备对象;The first obtaining module 03 is used to obtain the device object corresponding to the smart key device when the monitoring module 02 monitors that the smart key device is inserted;
第一获取模块03具体用于当监控模块02采用枚举的方式,监控到有智能密钥设备插入后,调用设备列表函数对智能密钥设备进行枚举,获取与智能密钥设备对应的设备对象。The first acquisition module 03 is specifically used to call the device list function to enumerate the smart key device when the monitoring module 02 adopts an enumeration method to monitor that a smart key device is inserted, and obtain the device corresponding to the smart key device object.
或者第一获取模块03具体用于当监控模块02采用广播的方式,监控到有智能密钥设备插入后,调用第一打包函数获取与智能密钥设备对应的设备对象。Or the first obtaining module 03 is specifically used to call the first packaging function to obtain the device object corresponding to the smart key device after the monitoring module 02 detects that the smart key device is inserted by means of broadcasting.
第一判断模块04,用于判断第一获取模块03获取到的设备对象是否具有设备权限;The first judging module 04 is used to judge whether the device object obtained by the first obtaining module 03 has device authority;
第一判断模块04具体用于当第一获取模块03,调用设备列表函数对智能密钥设备进行枚举,获取与智能密钥设备对应的设备对象之后,调用获取设备权限函数获取设备对象的设备权限标识,根据设备权限标识判断设备对象是否具有设备权限;The first judging module 04 is specifically used for when the first obtaining module 03 calls the device list function to enumerate the smart key device, and after obtaining the device object corresponding to the smart key device, calls the device permission function to obtain the device of the device object Authorization ID, judging whether the device object has device authorization according to the device authorization ID;
或者当第一获取模块03调用第一打包函数获取与智能密钥设备对应的设备对象后,调用第二打包函数获取设备对象的设备权限标识,根据设备权限标识判断设备对象是否具有设备权限。Or when the first obtaining module 03 calls the first packaging function to obtain the device object corresponding to the smart key device, it calls the second packaging function to obtain the device permission identifier of the device object, and judges whether the device object has device permission according to the device permission identifier.
申请权限模块05,用于当第一判断模块04判定为否后,为设备对象申请设备权限;The application authority module 05 is used to apply for the equipment authority for the equipment object after the first judging module 04 judges as no;
申请权限模块05具体用于当第一判断模块04判定为否后,调用申请权限函数为设备对象申请设备权限。The permission application module 05 is specifically used to call the permission application function to apply for the device permission for the device object after the first judging module 04 judges no.
第二判断模块06,用于当申请权限模块05为第一获取模块03获取到的设备对象申请设备权限后,判断设备对象是否具有设备权限;The second judging module 06 is used for judging whether the device object has the device permission after the permission application module 05 applies for the device permission for the device object acquired by the first obtaining module 03;
第二判断模块06具体用于当申请权限模块05为第一获取模块03通过调用设备列表函数对智能密钥设备进行枚举,获取到的与智能密钥设备对应的设备对象,申请设备权限后,调用获取设备权限函数获取设备对象的设备权限标识,根据设备权限标识判断设备对象是否具有设备权限。The second judgment module 06 is specifically used to enumerate the smart key device by calling the device list function when the application permission module 05 is the first acquisition module 03, and obtain the device object corresponding to the smart key device, after applying for the device permission , call the obtain device permission function to obtain the device permission ID of the device object, and judge whether the device object has the device permission according to the device permission ID.
或者具体用于当申请权限模块05为第一获取模块03通过调用第一打包函数获取到的与智能密钥设备对应的设备对象,申请设备权限后,调用第二打包函数获取设备对象的设备权限标识,根据设备权限标识判断设备对象是否具有设备权限。Or it is specifically used when the permission application module 05 is the device object corresponding to the smart key device obtained by the first acquisition module 03 by calling the first packaging function. After applying for the device permission, call the second packaging function to obtain the device permission of the device object ID, and judge whether the device object has the device authorization according to the device authorization ID.
第二获取模块07,用于当第一判断模块04判定为是后或当第二判断模块06判定为是后,获取与设备对象对应的设备连接句柄和设备接口对象,根据设备接口对象获取与设备对象对应的设备通讯端点。The second acquisition module 07 is used to obtain the device connection handle and the device interface object corresponding to the device object when the first judgment module 04 judges to be yes or when the second judgment module 06 judges to be yes, and obtain the corresponding device interface object according to the device interface object. The device communication endpoint corresponding to the device object.
第二获取模块07,具体用于当第一判断模块04判定为是后或当第二判断模块06判定为是后,调用打开设备函数获取与设备对象对应的设备连接句柄;调用获取接口函数获取与设备对象对应的设备接口对象;调用获取端点函数得到与设备对象对应的设备通讯端点。The second acquisition module 07 is specifically used to call the open device function to obtain the device connection handle corresponding to the device object when the first judgment module 04 judges to be or when the second judgment module 06 judges to be yes; call the acquisition interface function to obtain The device interface object corresponding to the device object; call the get endpoint function to get the device communication endpoint corresponding to the device object.
第一封装模块08,用于当第二获取模块07根据设备接口对象获取与设备对象对应的设备通讯端点后,生成第一通讯指令,根据设备对象获取USB协议标识,根据USB协议标识对第一通讯指令进行封装;The first encapsulation module 08 is used to generate the first communication instruction after the second obtaining module 07 obtains the device communication endpoint corresponding to the device object according to the device interface object, obtains the USB protocol identifier according to the device object, and performs the first communication according to the USB protocol identifier. Encapsulation of communication instructions;
第一封装模块08包括第一获取单元和第一组织单元;The first packaging module 08 includes a first acquisition unit and a first organization unit;
第一获取单元用于生成第一通讯指令,根据第一获取模块03获取到的设备对象获取USB协议标识;The first obtaining unit is used to generate the first communication instruction, and obtain the USB protocol identifier according to the device object obtained by the first obtaining module 03;
其中,第一通讯指令具体为验PIN指令或取随机数指令或生产密钥对指令或签名指令;USB协议标识具体为CCID协议标识或HID协议标识或SCSI协议标识。Wherein, the first communication command is specifically a PIN verification command or a random number command or a key pair production command or a signature command; the USB protocol identifier is specifically a CCID protocol identifier, an HID protocol identifier, or a SCSI protocol identifier.
第一组织单元具体用于在第一获取单元生成的第一通讯指令前添加与USB协议标识对应的USB协议头,得到封装后的第一通讯指令。The first organizing unit is specifically configured to add a USB protocol header corresponding to the USB protocol identifier before the first communication command generated by the first acquisition unit, so as to obtain the encapsulated first communication command.
第一发送模块09,用于通过第二获取模块07获取到的设备连接句柄和设备通讯端点将第一封装模块08封装的第一通讯指令发送给对应的智能密钥设备;The first sending module 09 is configured to send the first communication command encapsulated by the first encapsulation module 08 to the corresponding smart key device through the device connection handle and the device communication endpoint obtained by the second obtaining module 07;
第一接收模块10,用于通过第二获取模块07获取到的设备连接句柄和设备通讯端点接收来自智能密钥设备的与封装后的第一通讯指令对应的第一应答;The first receiving module 10 is configured to receive the first response corresponding to the encapsulated first communication command from the smart key device through the device connection handle and the device communication endpoint obtained by the second obtaining module 07;
第一解封模块11,用于根据USB协议标识对第一接收模块10接收到的第一应答进行解封,得到解封后的第一应答。The first decapsulation module 11 is configured to decapsulate the first response received by the first receiving module 10 according to the USB protocol identifier, and obtain the decapsulated first response.
第一解封模块11具体用于根据第一封装模块08去除第一接收模块10接收到的第一应答中的与USB协议标识对应的应答头,得到解封后的第一应答。The first decapsulation module 11 is specifically configured to remove the response header corresponding to the USB protocol identifier in the first response received by the first receiving module 10 according to the first encapsulation module 08, to obtain the decapsulated first response.
本实施例中,设备通讯端点包括设备输出端点和设备输入端点;相应地:In this embodiment, the device communication endpoints include device output endpoints and device input endpoints; correspondingly:
第一发送模块09具体用于通过第二获取模块07获取到的设备连接句柄调用数据传输函数将封装后的第一通讯指令通过第二获取模块07获取到的设备输出端点发送给对应的智能密钥设备;The first sending module 09 is specifically used to call the data transfer function through the device connection handle obtained by the second obtaining module 07 to send the encapsulated first communication command through the device output endpoint obtained by the second obtaining module 07 to the corresponding smart key. key device;
第一接收模块10具体用于通过第二获取模块07获取到的设备通讯句柄调用数据传输函数通过设备输入端点接收来自智能密钥设备的与所述封装后的第一通讯指令对应的第一应答。The first receiving module 10 is specifically used to call the data transfer function through the device communication handle obtained by the second obtaining module 07 and receive the first response corresponding to the encapsulated first communication command from the smart key device through the device input endpoint. .
本实施例中,通讯装置还可以包括第三判断模块;相应地:In this embodiment, the communication device may further include a third judging module; correspondingly:
第三判断模块用于当第一获取模块03获取与智能密钥设备对应的设备对象后,第一判断模块04判断设备对象是否具有设备权限之前,判断第一获取模块03获取到的设备对象是否与预设厂商标识对应;The third judging module is used to judge whether the device object obtained by the first obtaining module 03 is Corresponding to the default manufacturer logo;
第一判断模块04具体用于当第三判断模块判定为是后,判断第一获取模块03获取到的设备对象是否具有设备权限;The first judging module 04 is specifically used to judge whether the device object obtained by the first obtaining module 03 has device authority after the third judging module judges as yes;
监控模块02还用于当第三判断模块判定为否后,采用广播或者枚举的方式,监控是否有智能密钥设备插入。The monitoring module 02 is also used to monitor whether there is a smart key device inserted by broadcasting or enumerating after the third judging module judges no.
本实施例中,通讯装置还可以包括第四判断模块;相应地:In this embodiment, the communication device may further include a fourth judging module; correspondingly:
第四判断模块用于当第二获取模块07获取到与设备对象对应的设备连接句柄和设备接口对象之后,根据设备接口对象获取与设备对象对应的设备通讯端点之前,根据设备连接句柄使用控制传输端点获取智能密钥设备的设备识别标识,判断设备识别标识是否是预设识别标识;The fourth judging module is used to use the control transmission according to the device connection handle after the second obtaining module 07 obtains the device connection handle and the device interface object corresponding to the device object, and before obtaining the device communication endpoint corresponding to the device object according to the device interface object. The endpoint obtains the device identification of the smart key device, and determines whether the device identification is a preset identification;
第二获取模块07具体用于当第一判断模块04判定为是后,获取与设备对象对应的设备连接句柄和设备接口对象;当第四判断模块判定为是后,根据设备接口对象获取与设备对象对应的设备通讯端点;以及当第二判断模块06判定为是后,获取与设备对象对应的设备连接句柄和设备接口对象,当第四判断模块判定为是后,根据设备接口对象获取与设备对象对应的设备通讯端点;The second obtaining module 07 is specifically used to obtain the device connection handle and the device interface object corresponding to the device object when the first judgment module 04 judges to be yes; The device communication endpoint corresponding to the object; and when the second judging module 06 is judged to be yes, obtain the device connection handle and the device interface object corresponding to the device object; The device communication endpoint corresponding to the object;
监控模块02还用于当第四判断模块判定为否后,采用广播或者枚举的方式,监控是否有智能密钥设备插入。The monitoring module 02 is also used to monitor whether there is a smart key device plugged in by broadcasting or enumerating after the fourth judging module judges no.
本实施例中,通讯装置还可以包括第五判断模块和第一销毁模块;相应地:In this embodiment, the communication device may also include a fifth judging module and a first destroying module; correspondingly:
监控模块02还用于当初始化模块01初始化后,采用广播或者枚举的方式,监控是否有智能密钥设备拔出;The monitoring module 02 is also used to monitor whether the smart key device is pulled out by broadcasting or enumerating after the initialization module 01 is initialized;
第五判断模块用于当监控模块02监控到智能密钥设备拔出后,判断与智能密钥设备对应的设备对象是否存在对应的设备连接句柄和设备通讯端点;The fifth judging module is used to judge whether the device object corresponding to the smart key device has a corresponding device connection handle and device communication endpoint after the monitoring module 02 monitors that the smart key device is pulled out;
第一销毁模块用于当第五判断模块判定为是后,销毁与智能密钥设备对应的设备对象,及与其分别对应的设备连接句柄和设备通讯端点;以及当第五判断模块判定为否后,销毁与智能密钥设备对应的设备对象。The first destruction module is used to destroy the device object corresponding to the smart key device, the device connection handle and the device communication endpoint corresponding to it when the fifth judgment module judges yes; and when the fifth judgment module judges no , to destroy the device object corresponding to the smart key device.
本实施例中,通讯装置还可以包括保存模块和第三获取模块;相应地:In this embodiment, the communication device may further include a storage module and a third acquisition module; correspondingly:
保存模块用于生成设备通讯句柄,将设备通讯句柄与第二获取模块07获取到的设备连接句柄、设备通讯端点及第一获取模块03获取到的设备对象分别建立对应关系并保存;The saving module is used to generate a device communication handle, establish a corresponding relationship with the device connection handle obtained by the second obtaining module 07, the device communication endpoint and the device object obtained by the first obtaining module 03, and save the corresponding relationship;
第三获取模块用于当第一封装模块08生成第一通讯指令,根据设备对象获取USB协议标识,根据USB协议标识和第一通讯指令得到第二通讯指令之前,根据设备通讯句柄获取对应的设备对象、设备连接句柄和设备通讯端点;The third obtaining module is used to obtain the USB protocol identifier according to the device object when the first encapsulation module 08 generates the first communication instruction, and obtain the corresponding device according to the device communication handle before obtaining the second communication instruction according to the USB protocol identifier and the first communication instruction Objects, device connection handles and device communication endpoints;
第一发送模块09具体用于通过第三获取模块获取到的设备连接句柄和设备通讯端点将第一封装模块08获取到的第二通讯指令发送给对应的智能密钥设备。The first sending module 09 is specifically configured to send the second communication instruction obtained by the first encapsulation module 08 to the corresponding smart key device through the device connection handle and device communication endpoint obtained by the third obtaining module.
当通讯装置初始化模块01、监控模块02、第一获取模块03、第一判断模块04、申请权限模块05、第二判断模块06、第二获取模块07、第一封装模块08、第一发送模块09、第一接收模块10、第一解封模块11、保存模块和第三获取模块时,通讯装置还可以包括第六判断模块和第二销毁模块;相应地:When the communication device initialization module 01, monitoring module 02, first acquisition module 03, first judgment module 04, application authority module 05, second judgment module 06, second acquisition module 07, first encapsulation module 08, first sending module 09. When the first receiving module 10, the first unsealing module 11, the saving module and the third acquiring module, the communication device may also include a sixth judging module and a second destroying module; correspondingly:
监控模块02还用于当初始化模块01初始化后,采用广播或者枚举的方式,监控是否有智能密钥设备拔出;The monitoring module 02 is also used to monitor whether the smart key device is pulled out by broadcasting or enumerating after the initialization module 01 is initialized;
第六判断模块用于当监控模块02监控到智能密钥设备拔出后,判断与智能密钥设备对应的设备对象是否存在对应的设备连接句柄和设备通讯端点;The sixth judging module is used to judge whether the device object corresponding to the smart key device has a corresponding device connection handle and device communication endpoint after the monitoring module 02 monitors that the smart key device is pulled out;
第二销毁模块用于当第六判断模块判定为是后,销毁与智能密钥设备对应的设备对象,及与其分别对应的设备通讯句柄、设备连接句柄和设备通讯端点;以及当第六判断模块判定为否后,销毁与智能密钥设备对应的设备对象。The second destruction module is used to destroy the device object corresponding to the smart key device, the device communication handle, the device connection handle and the device communication endpoint respectively corresponding to it when the sixth judging module judges yes; and when the sixth judging module After the judgment is no, destroy the device object corresponding to the smart key device.
还需说明的是,尽管现有技术中,已经存在其他接口的智能密钥设备(如蓝牙接口的智能密钥设备或音频接口的智能密钥设备等)可以和移动终端进行通讯,但是本发明实施例中提供的利用OTG技术实现的移动终端和USB接口的智能密钥设备的通讯方法及通讯装置能够在降低成本的同时,实现更快的通讯速度,更加便捷。It should also be noted that although in the prior art, smart key devices with other interfaces (such as smart key devices with Bluetooth interfaces or smart key devices with audio interfaces, etc.) can communicate with mobile terminals, the present invention The communication method and communication device between the mobile terminal and the smart key device with USB interface provided in the embodiment can achieve faster communication speed and more convenience while reducing the cost.
以上所述,仅为本发明较佳的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明公开的技术范围内,可轻易想到的变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应该以权利要求的保护范围为准。The above is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto, any changes or variations that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention Replacement should be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention should be determined by the protection scope of the claims.
Claims (34)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610032912.6A CN105678152B (en) | 2016-01-19 | 2016-01-19 | A kind of method and device with intelligent cipher key equipment communication |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610032912.6A CN105678152B (en) | 2016-01-19 | 2016-01-19 | A kind of method and device with intelligent cipher key equipment communication |
Publications (2)
Publication Number | Publication Date |
---|---|
CN105678152A true CN105678152A (en) | 2016-06-15 |
CN105678152B CN105678152B (en) | 2018-06-05 |
Family
ID=56301418
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610032912.6A Active CN105678152B (en) | 2016-01-19 | 2016-01-19 | A kind of method and device with intelligent cipher key equipment communication |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN105678152B (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106534112A (en) * | 2016-11-09 | 2017-03-22 | 百望金赋科技有限公司 | Tax-control key and communication protocol management method thereof |
CN108174376A (en) * | 2017-12-28 | 2018-06-15 | 飞天诚信科技股份有限公司 | A kind of method and system for preventing interference |
CN108347440A (en) * | 2018-02-07 | 2018-07-31 | 飞天诚信科技股份有限公司 | A kind of method and device for making scsi device support application of IC cards |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102882871A (en) * | 2012-09-28 | 2013-01-16 | 深圳市赛蓝科技有限公司 | Mobile terminal USB (universal serial bus) virtualized mapping method |
CN103514123A (en) * | 2012-12-26 | 2014-01-15 | Tcl数码科技(深圳)有限责任公司 | Identification method and system of USB equipment connection port |
US8832441B2 (en) * | 2005-11-18 | 2014-09-09 | Felica Networks, Inc. | Mobile terminal, data communication method, and computer program |
US8966275B2 (en) * | 2010-03-10 | 2015-02-24 | Giesecke & Devrient Gmbh | Method for authenticating a portable data carrier |
CN104468116A (en) * | 2014-11-06 | 2015-03-25 | 飞天诚信科技股份有限公司 | Method for achieving multi-application of intelligent secret key equipment |
-
2016
- 2016-01-19 CN CN201610032912.6A patent/CN105678152B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8832441B2 (en) * | 2005-11-18 | 2014-09-09 | Felica Networks, Inc. | Mobile terminal, data communication method, and computer program |
US8966275B2 (en) * | 2010-03-10 | 2015-02-24 | Giesecke & Devrient Gmbh | Method for authenticating a portable data carrier |
CN102882871A (en) * | 2012-09-28 | 2013-01-16 | 深圳市赛蓝科技有限公司 | Mobile terminal USB (universal serial bus) virtualized mapping method |
CN103514123A (en) * | 2012-12-26 | 2014-01-15 | Tcl数码科技(深圳)有限责任公司 | Identification method and system of USB equipment connection port |
CN104468116A (en) * | 2014-11-06 | 2015-03-25 | 飞天诚信科技股份有限公司 | Method for achieving multi-application of intelligent secret key equipment |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106534112A (en) * | 2016-11-09 | 2017-03-22 | 百望金赋科技有限公司 | Tax-control key and communication protocol management method thereof |
CN108174376A (en) * | 2017-12-28 | 2018-06-15 | 飞天诚信科技股份有限公司 | A kind of method and system for preventing interference |
CN108347440A (en) * | 2018-02-07 | 2018-07-31 | 飞天诚信科技股份有限公司 | A kind of method and device for making scsi device support application of IC cards |
CN108347440B (en) * | 2018-02-07 | 2020-08-18 | 飞天诚信科技股份有限公司 | Method and device for enabling SCSI equipment to support smart card application |
Also Published As
Publication number | Publication date |
---|---|
CN105678152B (en) | 2018-06-05 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
JP6002260B2 (en) | Method and system for authenticating accessories | |
TWI338222B (en) | Method and system for allowing a media player to transfer digital audio to an accessory | |
WO2019214444A1 (en) | Data transmission method, device and computer readable storage medium | |
EP3944588B1 (en) | Method for uwb transaction and electronic device therefor | |
TW201013404A (en) | Device for connection with a storage device and a host | |
WO2014206284A1 (en) | Device for supporting communication between multiple types of safety carriers and communication method therefor | |
CN110167192B (en) | Bluetooth connection management method and device, electronic equipment and non-transient storage medium | |
CN105678152A (en) | Method and device for communication with intelligent secret key device | |
CN109213530A (en) | A kind of communication connecting method based on USB, mobile terminal and storage medium | |
CN110716831A (en) | Terminal, debugging system of USB (universal serial bus) equipment and debugging method of USB equipment | |
CN104778143B (en) | The method and apple equipment appurtenance for being actively connected and communicating with apple equipment | |
CN104573591B (en) | A kind of secure readers and its method of work | |
CN106357607A (en) | Method and device for connection, security verification, communication, communication monitoring of electronic equipment | |
CN115834115A (en) | Equipment authentication networking method, device, equipment and storage medium | |
CN105933428A (en) | Method and device for communicating with apple terminal | |
CN106126446A (en) | A USB device and its method for identifying MacOS system | |
CN103873256B (en) | Working method of NFC token | |
EP2557755B1 (en) | Securely Performing Commands from a Remote Source | |
CN104714760B (en) | Method and device for reading and writing storage devices | |
CN114595437A (en) | Access control method, electronic device, and computer-readable storage medium | |
CN105809002A (en) | Charging method of user terminal and user terminal | |
TW201447592A (en) | Display with moving high-definition connection and signal processing method thereof | |
JP2001177599A (en) | Radio communication unit system, radio communication unit and exchange method of authentication information | |
CN104750630B (en) | A kind of method of work of PC/SC Driver Libraries in ios device | |
CN110035308A (en) | Data processing method, equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
OL01 | Intention to license declared | ||
OL01 | Intention to license declared | ||
OL01 | Intention to license declared | ||
OL01 | Intention to license declared |