Windows Hello Tasting (2)

Source: Internet
Author: User

Then explore

On a Microsoft Official demo, this demo has basically finished what we are going to do.

So based on this demo, I'll say my ideas.

1. First of all, in the interface program to enumerate the Bluetooth device

2. Create an unlocked Windows Hello device for information about using a Bluetooth device

3. When the task receives an unlock event, enumerate the Bluetooth devices again, and then determine if each of the Bluetooth devices enumerated to has a corresponding Windows Hello device

4. Use this Windows Hello device to unlock your computer

So I first use the information of my millet bracelet to create the corresponding unlocking device, when my hand ring near the time the task can be enumerated to unlock it, when the bracelet is not near the time the task will naturally enumerate it, so you can not use Windows Hello unlock.

Start practicing

About enumerating Bluetooth devices, I found the demo in Microsoft's official example

Demo Address: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/DeviceEnumerationAndPairing

This demo shows the use of Devicewatch to enumerate devices

Devicewatcher M_devicewatcher;string[] Requestedproperties = {"System.Devices.Aep.DeviceAddress","System.Devices.Aep.IsConnected"};m_devicewatcher= Deviceinformation.createwatcher ("(system.devices.aep.protocolid:=\ "{bb7bb05e-5972-42b5-94fc-76eaa7084d49}\")",//M_devicewatcher = Deviceinformation.createwatcher ("(system.devices.aep.protocolid:=\" { E0cbf06c-cd8b-4647-bb8a-263b43f0f974}\ ")",Requestedproperties, Deviceinformationkind.associationendpoint); m_devicewatcher.added+=devicewatcher_added;m_devicewatcher.updated+=devicewatcher_updated;m_devicewatcher.removed+=devicewatcher_removed;m_devicewatcher.enumerationcompleted+=devicewatcher_enumerationcompleted;m_devicewatcher.stopped+=Devicewatcher_stopped;m_devicewatcher.start ();

This code should be at a glance, the key is that the parameter {bb7bb05e-5972-42b5-94fc-76eaa7084d49} used in Createwatcher can be enumerated to the millet bracelet, but not the phone { e0cbf06c-cd8b-4647-bb8a-263b43f0f974} instead, it can be enumerated to the phone but not to the millet bracelet.

This class can also be enumerated to many other devices, depending on the createwatcher parameters can be seen in the official demo.

Here is the definition of the interface, where deviceinformation and deviceinformationupdate contain information about the device

Private voiddevicewatcher_added (Devicewatcher Sender, Deviceinformation deviceinfo) {}Private voiddevicewatcher_updated (Devicewatcher Sender, Deviceinformationupdate deviceinfoupdate) {}Private voiddevicewatcher_removed (Devicewatcher Sender, Deviceinformationupdate deviceinfoupdate) {}Private voidDevicewatcher_enumerationcompleted (Devicewatcher Sender,Objecte) {}Private voiddevicewatcher_stopped (Devicewatcher Sender,Objecte) {}

The basic properties have corresponding variables, while I createwatcher the properties string[] requestedproperties = {"System.Devices.Aep.DeviceAddress", " System.Devices.Aep.IsConnected "}; will be stored in the properties of Deviceinformation and deviceinformationupdate in the form of key-value pairs

I first use this interface in the interface program to enumerate into my bracelet, the basic information is this

Deviceid:bluetoothle#bluetoothlexx:xx:xx:xx:xx:xx-xx:xx:xx:xx:xx:xx

Name:mi Band 2

At first I wanted to use the ID of BLUETOOTHLE#BLUETOOTHLEXX:XX:XX:XX:XX:XX-XX:XX:XX:XX:XX:XX to create the unlocked device, but the discovery failed, It might be possible to use GUIDs to create unlocked devices. So I need to put the bluetoothle#bluetoothlexx:xx:xx:xx:xx:xx-xx:xx:xx:xx:xx:xx also stored up, the idea of storage

In fact, the example is also given is the existence of the unlock device deviceconfigurationdata, because I also want to store in the Deviceconfigurationdata unlock two password, so I will simply The data in JSON format is stored in Deviceconfigurationdata, which specifically writes a class that is serialized very deserialized.

 Public classjsondata{ Public stringSign {Get;Set; }  Public stringDeviceID {Get;Set; }  Public stringDevicekey {Get;Set; }  Public stringAuthKey {Get;Set; }  Public BOOLCanunlock {Get;Set; }} Public classcmyhellowinjson{ Public StaticJsondata Parestodata (stringJS) {Jsondata RV=NULL; Try{jsonobject Schoolobject=Jsonobject.parse (JS); if(Schoolobject! =NULL) {RV=NewJsondata (); Rv. Sign= Schoolobject.getnamedstring (" Sign"); Rv. DeviceID= Schoolobject.getnamedstring ("DeviceID"); Rv. Devicekey= Schoolobject.getnamedstring ("Devicekey"); Rv. AuthKey= Schoolobject.getnamedstring ("AuthKey"); Rv. Canunlock= Schoolobject.getnamedboolean ("Canunlock"); }        }Catch(Exception e) {returnRV; }         returnRV; }     Public Static stringParestojson (Jsondata Dat) {jsonobject schoolobject=NewJsonobject (); Schoolobject.setnamedvalue (" Sign", Jsonvalue.createstringvalue (dat.sign)); Schoolobject.setnamedvalue ("DeviceID", Jsonvalue.createstringvalue (Dat.deviceid)); Schoolobject.setnamedvalue ("Devicekey", Jsonvalue.createstringvalue (Dat.devicekey)); Schoolobject.setnamedvalue ("AuthKey", Jsonvalue.createstringvalue (Dat.authkey)); Schoolobject.setnamedvalue ("Canunlock", Jsonvalue.createbooleanvalue (Dat.canunlock)); returnschoolobject.tostring (); }}

So the code that creates the unlock device in the interface becomes the same

stringModelNumber ="Myhellowin";//random number to string may lose informationbyte[] Devicekeyarray =New byte[ +];byte[] Authkeyarray =New byte[ +];ibuffer Devicekey=Cryptographicbuffer.createfrombytearray (Devicekeyarray); IBuffer AuthKey=Cryptographicbuffer.createfrombytearray (Authkeyarray); Jsondata Dat=NewJsondata ();D at. Sign="Myhellowin";D at. Devicekey=System.Text.Encoding.UTF8.GetString (Devicekeyarray);D at. AuthKey=System.Text.Encoding.UTF8.GetString (Authkeyarray);D at. DeviceID=Deviceid;dat. Canunlock=false;stringJS =Cmyhellowinjson.parestojson (Dat);byte[] Signarry =System.Text.Encoding.UTF8.GetBytes (JS); IBuffer Deviceconfigdata=Cryptographicbuffer.createfrombytearray (Signarry); String Deviceguid=System.Guid.NewGuid (). ToString ();intState =awaitWinhello.registerdeviceasync (Deviceguid, Bledevicedisplay.devicename, ModelNumber, DeviceConfigData, DeviceKey , AuthKey);//RegisterSecondaryauthenticationfactordevicecapabilities capabilities =Secondaryauthenticationfactordevicecapabilities.securestorage; Secondaryauthenticationfactorregistrationresult Registrationresult=awaitSecondaryauthenticationfactorregistration.requeststartregisteringdeviceasync (DervicesID, Capabilities, FriendlyName, ModelNumber, Devicekey, AuthKey);if(Registrationresult.status = =secondaryauthenticationfactorregistrationstatus.started) {awaitRegistrationResult.Registration.FinishRegisteringDeviceAsync (Dervicecontext);}return(int) Registrationresult.status;

The interface is written, so the idea of unlocking is roughly the same.

First of all Bluetooth devices, using the same method as above.

private void devicewatcher_added (devicewatcher Sender, deviceinformation deviceinfo) {

await Secondaryauthenticationfactorregistration.findallregistereddeviceinfoasync ( Secondaryauthenticationfactordevicefindscope.allusers);
   for(inti =0; i < Devicelist.count; i++) {Secondaryauthenticationfactorinfo deviceinfo=Devicelist.elementat (i); byte[] combineddataarray; Cryptographicbuffer.copytobytearray (Deviceinfo.deviceconfigurationdata, outCombineddataarray); stringJS =System.Text.Encoding.UTF8.GetString (Combineddataarray); Jsondata Dat=Cmyhellowinjson.parestodata (JS); if(Dat = =NULL) {Continue; }if(String.Equals (Dat.deviceid,DeviceInfo. DeviceID)) {//Use this device to unlock  }
}
}

The specific method of unlocking, the above article has the corresponding introduction. Or you can look directly at the Demo:http://git.oschina.net/alwaysking/myhellowin I wrote.

However, when I was naïve to do so, came a bolt of thunder, because when using Devicewatcher enumeration device in the task, his callback function is not triggered at all. Note that my Bluetooth device is a paired device.

There is a solution, and we'll talk about it in the next article.

Windows Hello Tasting (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.