Forum Xamarin.iOS

NetworkInterface.GetAllNetworkInterfaces() Diffrent Mac Than Obj-C IORegistryEntryCreateCFProperty

pmhart83pmhart83 USMember ✭✭✭

I have 4 of the 5 steps working in my receipt validation code in C# to get the app into the App Store:

  1. Check that receipt exists
  2. Check that it's signed by apple
  3. Check that Bundle ID matches receipt
  4. Check that Bundle Ver matches receipt
  5. Check that payload GUID matches device GUID

I am stuck on #5 but very very close. You obtain the expected GUID just like you obtain the expected Bundle ID / Bundle Version from the receipt payload.

The expected receipt GUID form the payload is as follows:

80e4ca3265a24b54129ebbf7178d4943375492b7

Using the following function in C#:

`List<byte[]> getMacAddressesCSharp()
{

List<byte[]> addresses = new List<byte[]>();

foreach(NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
    if(nic.NetworkInterfaceType != NetworkInterfaceType.Loopback && nic.OperationalStatus == OperationalStatus.Up && nic.GetPhysicalAddress().GetAddressBytes().Length >= 6)
    {
        addresses.Add(nic.GetPhysicalAddress().GetAddressBytes());
    }
}

return addresses;

}`

I get each possible mac address and create a byte array which I append the "opaque" and "bundle id" data to make one large byte array. With this byte array I use SHA1Managed to create a SHA1 hash which should equal what I see in the payload as a GUID.

I am getting the correct "opaque" bytes as well as the correct "bundle id" bytes. However, in C# the closest mac address byte[] is not the same address I get using CFDataRef copy_mac_address(void) found on Apples website.

In C# I get the mac address: 001D4F4B1D3D

In Obj-C I get the mac address: 001d4f4b1d3c
Note: uses CFDataRef copy_mac_address(void) found on apples web site
https://developer.apple.com/library/mac/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateLocally.html#//apple_ref/doc/uid/TP40010573-CH1-SW14

When I combine the mac address from the Obj-C results with the opaque / bundle byte[] data, I get the expected SHA1.

If you compare the two mac address in question, they are only off by the last char. C# gives a "D" on the end and Obj-C gives a "C" on the end. If you convert this to a decimal 3D = 61 and 3C = 60.

I am creating a binding for just this function in Obj-C now, but I don't like relying on manually binding that is not even supported by Xamarin.Mac yet.

Can someone help me get the right MAC address in C#??

Sign In or Register to comment.