I have an iPhone 5 running IOS 7.0.4. I have the same problem you reported and it is still not resolved. I am commenting on your forum to just let others know it is in fact possible that it cannot be resolved. This device works just fine when I'm at the Apple store (Genius desk) which makes it hard to convince them especially if you are dealing with someone who may not have seen the problem before. I have tried EVERYTHING mentioned on this forum (except sticking it in the freezer-- that just seems too whacky). If I put my device one inch from the wireless router it will sort of work. I cannot get an internet connection to a web site even though it shows connected. But in reality, how many public hotspots are going to let you put your device an inch from the router?
I am also a bit of a tech person so I know how to watch the log files from my router. I can see the 6 other iPhones in my home (including my wife's iPhone 5) connect and get a secure link. This phone does not even connect (unless an inch from the router). I should also point out that besides the 6 other iPhones we have 2 android phones, 1 android tablet, an apple TV module, Roku, XBox, BlueRay player-- all connect fine (yes, technology overload, I admit).
Where has it worked? In the Mac store and the Apple Store. I also got it to work once with my wi-fi at work. The Apple Genius did some diagnostics on it and said the hardware was ok. My theory is its a firmware problem meaning the chip on the phone probably has some sort of bad encryption setting (firmware) and resetting to factory default doesn't do much for it. I say this because of another odd behavior I noticed with regard to https web sites. If you hit an http url that has an https embeded iframe the device picks up an IP address from a totally different location (different state). My wife's iPhone does not have the problem and she is running the same IOS version which makes me think the difference is deeper.
What do the networks that don't work have in common? Not sure. At my church (and I've tried several buildings) I'm quite certain they have firewall settings and block certain sites. My home network uses OpenDNS as well as firewall settings. So is it possible part of the handshaking involves connecting to a remote site and if it cannot connect the handshake fails? Not likely... but you have to wonder.
A few other things you should be aware of, that I was not. My carrier is AT&T and their policy does not allow a plan cancellation after 14 days-- so if your resort is to cancel, do it quick. They also state that Apple does not let them (AT&T) do exchanges or warranty. AT&T will go through the "simple" stuff with you up to resetting the phone to factory defaults, asking you to reset the router, making sure you have latest firmware on the router, etc. Apple tech support (on the phone) did the same sort of thing then eventually sent me to the Apple store (about an hour away). The Apple store experience was pleasant (kind and courteous) but also painful (not very helpful). I got there early and literally sat out in the mall on a bench connected to their wi-fi and wondered if I should even bother. I wish I had read the post above where the person was smart enough to go to a coffee shop and prove to the Genius that he could not connect there.
So where am I? I was dealing with a manager at Apple on Monday and plan to call him back tomorrow and see what he can do. My advice: do the "normal" procedures that a typical non-techy person should be expected to do and if that doesn't work, be prepared to discuss this issue with Apple. I would suspect we are dealing with a small batch of devices that have the problem and are probably not a big priority. The quick solution, in my mind, is for Apple to provide a replacement device then for them to take the defective device and trace it back to the batch it was created from, track down those devices not yet sold and take them out of commission, then be ready to immediately assist customers who come in with a defective device. I'll make those recommendations to the manager I talk to tomorrow. However, I find it hard to believe a company like Apple is not already aware of this and working on a solution.
Good luck!