Is there any way to get the tamper-proof date and time on iPhone? - iphone

For various reasons I need to get from the iPhone the current date and time that can't be meddled with by the user. Yes, I've seen how one can check a server (e.g., here), but that's not invulnerable to tampering if you take a moment to reflect.
There are two knee-jerk reactions I'm expecting to hear:
Use the GPS time.
It can't be done.
In answer to another question, I've described my researches into this matter. To summarize them:
The GPS time shifts with the user-defined settings.
The iPhone definitely has an internal tamper-proof time and date, as shown when date-time reverts after Set Automatically in Settings > General > Time & Date is turned back to on even in a fallout shelter.
What I want to know is how to access this tamper-proof time.
Edit
Just to be clear, the server-based solution is not suitable. For one, it could be faked. For another, the app needs to work without a network connection.

Assuming you always have Internet available, you could implement a class or object that connects to a remote Network Time Protocol server.
Here's an open source GitHub project that should get you started, and the related StackOverflow question I found it at.

Related

'Activate' Bluetooth LE Energy Data stream

For a student project, we're working on connecting a Bluetooth LE device (that both transmits and receives) to an iPhone or iPad in order to read data from it to display to the user in realtime. We have proof that this is doable by the company that made the device and we've actually managed to get a connection and get some data.. however it pings every 5-10 seconds and seems to be a random subset of numbers with minimal changes after changing something on the device which is making us none the wiser.
Now, of course, we went to the company that made the device and app first and we do have approval for us to use their hardware, but haven't been able to get a SDK / API from them to use with the application. So, our plan is to make our own way through it and find what we need.
This is where we're getting stuck. We have the following:
Connection based on Name or Bluetooth Device Address
Scan services (and cascading scan in case the services have services within them as specified in the CoreBluetooth documentation)
Read Characteristics from said services.
Decrypt value into 8bit UInt so we get some actual readable data.
This is an example of what we've got with the value still as it comes in.
Service: 0x1c0476440, is Primary = yes. UUID: 058d0001-ca72-4c8b-8084-25e049936b31
value <53636da1 7a616c74 73616c74 73616c74 73616c27>
Now, looking at this all, I presume the service here is some kind of 'staying alive' ping and it's giving some auxiliary info about the device's current state.
The question we have then boils down to this:
How can we further 'explore' the device? We don't seem to be getting any additional output aside from this however looking in the device manager from windows we get a couple of hits that look like this (Example):
{058d0001-ca72-4c8b-8084-25e049936b31}[6]
Which have values in either a hexidecimal value, boolean or datetime without clear identifiers. Is there a way for us to send a message to the device to change the value in that uuid using Swift, or is this impossible?
While solved now, I'm not accepting this as the answer. My solution? Try things. Stupid 'Needle in a haybale' things.
I changed the uuid from 058d0001-ca72-4c8b-8084-25e049936b31 to 058d0002-ca72-4c8b-8084-25e049936b31
and voila. I could do more. I tried 3, and again, a new result and a working data stream...
#Paulw11's comment is also a good way to solve this issue we found out.

Change value after period of time in Firebase

I have a lobby in which I want the users to be in sync. So when a user turns off his internet while the app is running, he should be removed. I know Firebase does not support server side coding, so the coding needs to be client side. The answers from How to delete firebase data after "n" days and Delete firebase data older than 2 hours do not answer this question since they expect that the user is online and they have an internet connection. So my question is if is possible to delete users when they got no internet? I thought maybe it is an idea to let the users update a value every 5 seconds, and when that update is not done, the other users in that lobby remove the player. This way is not good, since every player needs to retrieve and upload alot of data every 5 seconds. What is the best way to solve this?
Edit: to make it short, lets say each user has an image. The image should be green when the user is connected, and grey when disconnected.
Edit 2: after thinking it over, it is really hard to accurate present the connected users on a client-side server. That is why, if nobody has a different solution, I should add another server which can execute server-side codes. Because of the larges amount of servers, I would like to know which server I should use. The server should run a simple function which only checks if the users are connected or disconnected and can communicate with Firebase. If I am correct it should look like this:
But the server also needs to communicate with the users directly. I have absoluty no idea where to start.
If I'm not completely wrong, you should be able to use onDisconnect.
From the Firebase, documentation:
How onDisconnect:Works:
When an onDisconnect() operation is established, it lives on the Firebase Realtime Database server. The server checks security to make sure the user can perform the write event requested, and informs the client if it is invalid. The server then monitors the connection. If at any point it times out, or is actively closed by the client, the server checks security a second time (to make sure the operation is still valid) and then invokes the event.
In app in production I'm using onDisconnectRemoveValue, and when I close the app, the user removes himself from the lobby. Not sure how it works when you turn the device in airplane mode, but from the documentation it seems there should be no problem.
One thing: when you test it better do it on real device, the simulator have issues with turning it off and on, at least the on I have installed.
Edit: So i checked the onDisconnect when you put the device on airplane mode and it works! The question is, that it removes the user in about a 1:30 min, approximately, so if you read the documentation or ask the support, you may be (and only may be) able to find a way to set the time you want.

Can I to know if ipad was rebooted?

I am developing an application that must work online and also offline. This application should sync informations with our server. For this, we need that the device utilize the server clock.
I found a lot of information, and I get the following idea:
When the user logins online I will force him to get the server clock time. In this moment he obrigatory must have internet connection, so it is ok.
When I get the clock server time, I get the systemUptime information that says the interval that the device is turned on, and I store it. I can get systemUptime like this:
[NSProcessInfo processInfo].systemUptime
When the user to create a new local file, I will know the current interval based on systemUptime function, so I know the current time, and I don't depend the iOS system clock.
The problem is: Everytime that device is rebooted, or turned off, the systemUptime is reseted. Until here OK, I can solve it forcing the user to login again, and getting the server clock time again. My problem is to know when the device was rebooted. Can you help me? Thank you guys!
My advice would be to not refer to the device time at all. Get the the files from the server and have the server also answer the server time that the files are retrieved. You can store this in the file, in the file name, or separately on the device.
At some point in the future ask the server if there's a file newer than the server time you recorded earlier.
In this sense, the time isn't really a time at all, it's a version number, and you could make that explicit with the server too, using just an integer from the server that indicates progressing sequence of versions.
If it's important that your app be strong in this way, your only choice is to remain independent of device time. Otherwise, there are too many ways it can break (including small time errors due to latency on the time check, or device factory resets or malicious actions by a user). It's better to remain independent of device time if you can.
When you get the systemUptime the first time, subtract it from the current (iOS) date and time. That's the time the system was last brought up.
Then recalculate this value whenever necessary. If the "time the system was last brought up" has changed, then you know it's time to log in again.
However, as suggested by another commenter, I suspect there's a better way to tackle this from scratch.

iOS "real" time for specific TimeZone while offline

This is the scenario:
I'm writing a medical related program, that would be use while with no connection. When some action act, the program would write the time to CoreData record.
That's the problem, if their device set the time to a diff time like earlier than the real time. That would be a big problem coz it's for medical usage.
So, how can i get the "real" time even if there is no connection?
Or, is it possible to disallow user changing the device time using something like restrictions or DeviceProfile?
It's only because Apple IS the Big Brother they claimed to be fighting in 1984. Welcome to 1984! Otherwise we would have access to real time time, and an English version of ISO date format! :-/
Every iPwn, and now other devices, has a GPS receiver and an Internet capability, from which sub-second accurate time could be derived, yet Apple insists on forcing us to depend on AT&T to automatically set our clocks. It's only recently that AT&T started delivering accurate time, thank god for small favors.
The lack of GPS and NTP time setting, plus the glaring omission of ISO 8601 date formatting with otherwise USA formats and language, is extremely annoying on a daily basis.
So, the answer to your question is, Yes, it is feasible, but not in Apple's Jail, since you cannot set RTC from GPS or NTP without jail breaking.
PS: my guess is that AT&T insists on this for call-timing or something stupid that has to do with charging us more money! ;-)
You get the real time from [NSDate date]. For example, the following:
[[NSDate date] timeIntervalSince1970]
gives the number of seconds since 1/1/1970 midnight UTC. This is independent of timezone and independent of whatever time is set by the user. If you know the timezone, then you can convert that to local time with the NSDateFormatter if you like, but make sure to also record the timezone to make the representation unique.
EDIT: Sorry, this answer is actually not correct. After trying it out, it appears that setting the time by the user also changes the NSDate values.
So, how can i get the "real" time even if there is no connection?
If by "no connection" you mean "no network connection of any sort" the answer is that you can't.
I think the best you can do is disable the functionality if you can't find a way to independently verify the system time (and tell the user why).
NSDate and all associated classes read the date from the system time. Without an internet connection to refer to, the NSDate class is open to user abuse.
I used an example in a comment on fishinear's answer of Farmville. If the user plants some crops that take five hours to grow, you can just change the system time to five hours in the future to harvest. Which, I'm sure, is one of the reasons that Zynga requires an internet connection to play their games.
Without some time-telling hardware, Apple cannot realistically tell time without an internet connection; even if they did have some amazing solution, they'd have to take into account timezones and even travel across timezones in order to make this work.
If I were you, I'd require an internet connection at specified intervals (once a day or the like) in order to draw a reference.
Let us know why you need this and we may be able to suggest some viable alternatives in function.

get data from online once and then viewable offline

Okay, I want to have an app that takes phone numbers from an online database and displays them in a table view. When the user is not online, I want them to still be able to see the numbers they already got from the database in the table view. If the user manages to go back online, the database updates the view. My question is, is this possible to do and if so, what's the best way to approach it? (bit of a newbie, please help me out)
There are many ways to do what you are asking, depending on the complexity of what you are after.
Could I suggest the following steps (I'm not sure which ones you can do, and which ones you are having trouble with).
Connect to the server and retrieve the list of phone numbers
If the database has a web server front end this might be as simple as sending a get request to the server (see NSURLConnection) and parsing the result. Otherwise you will need to know/tell us what type database you are using.
Store the phone numbers on the device
Use SQLite to store the numbers on the device (See iPhone SQLite Resources)
Check for internet connectivity
Periodically check for internet connectivity, and if a specific time has elapsed since you last polled the server, retry. (See Checking iPhone internet connectivity)
Although you’re probably looking for a native app solution, you can also do this with a web app.
http://diveintohtml5.ep.io/offline.html
I am a new developer iPhone developer, "learning" to be precise. I came across the useful NSUserDefaults (a dictionary in which you can store/restore state even after your application relaunches). Problem with this dictionary will be memory in your case. NSUserDefaults is sort of global to all applications and yours may spoil the show for other innocent applications (like Weather :D ).
To work around this, you can have your application declare a property list file where you store a few numbers (best practise would be the most recent but you can use any selector of choice). Look for an appropriate time in your run loop to store these numbers into your property file and load them when the application starts.