Making secure connection in Iphone

Hi all,
I need to perform a secure connection with the server . I have used the following code which is documented.
NSString *urlStr = MW_URL_TO_CONNECT;
if (![urlStr isEqualToString:@""])
NSURL *website = [NSURL URLWithString:urlStr];
if (!website) {
NSLog(@"%@ is not a valid URL");
return NO;
NSHost *host_ = [NSHost hostWithName:MW_URL_TO_CONNECT];
// iStream and oStream are instance variables
[NSStream getStreamsToHost:host_ port:MW_PORT_NUMBER inputStream:&iStream outputStream:&oStream];
[iStream retain];
[oStream retain];
[iStream setDelegate:self];
[oStream setDelegate:self];
[iStream setProperty:NSStreamSocketSecurityLevelKey forKey:NSStreamSocketSecurityLevelSSLv3];
[oStream setProperty:NSStreamSocketSecurityLevelKey forKey:NSStreamSocketSecurityLevelSSLv3];
[iStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[oStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[iStream open];
[oStream open];
--- Using the above code the callback method is called. In my call back method I have the following
- (void)readFromNSStreamIntoIncomingBuffer
// Temporary buffer to read data into
UInt8 buf[1024];
// Try reading while there is data
while( [iStream hasBytesAvailable])
int len = [iStream read:buf maxLength:1024];
if ( len <= 0 )
// Either stream was closed or error occurred. Close everything up and treat this as "connection terminated"
// [self close];
// [delegate connectionTerminated:self];
// return;
NSError *err = [iStream streamError];
// NSLog(@"error desp: %@", [err description]);
NSLog(@"error Localized descp: %@", [err localizedDescription]);
NSLog(@"error Recovery Suggestion: %@", [err localizedRecoverySuggestion]);
NSLog(@"error failure reason : %@", [err localizedFailureReason]);
else
[incomingDataBuffer appendBytes:buf length:len];
if([incomingDataBuffer length] > 0)
[reader setDataRead:incomingDataBuffer];
in above code "[iStream hasBytesAvailable]" returns YES , but when i tried to read as "int len = [iStream read:buf maxLength:1024];" , it gives -1 as value.
I tried and I couldn't fix the error. any help would be greatly appreciated.
Regards,
Mohammed Sadiq.

Great news, thank you!
Do you know if I can change the password to access a secure note? Does it have to be the computer password?
It's your Keychain Password, which by default is the same as your Login Password, but can be changed if you wish, but...
Mac OS X 10.4: Keychain Access asks for keychain "login" after changing login password...
http://support.apple.com/kb/HT1631

Similar Messages

  • Using secure tranport for making ssl connection with server using iPhone

    HI all,
    I need to estabilish a secured connection using tcp with sslv3 to the server. I tried using
    [inputStream setProperty:NSStreamSocketSecurityLevelKey forKey:NSStreamSocketSecurityLevelSSLv3];
    [outputStream setProperty:NSStreamSocketSecurityLevelKey forKey:NSStreamSocketSecurityLevelSSLv3];
    I have explained the problem in detail in the following link
    http://www.iphonedevsdk.com/forum/iphone-sdk-development/25721-creating-ssl-conn ection-using-sockets.html
    But it makes only a tcp connection wth the server and the server sends the "Connection Reset by peer " error.
    So I have planned to use Secure Tranport. But i didnt find a suitable sample code in the internet. I found a sample in apple 's docs. But thats too confusing. Any sample code available for making tcp with ssl connection with the server ????
    Regards,
    Mohammed Sadiq.

    You must select if you use certificates for the SSL.
    If you are not, here is an example
    // server is the ip address for the server and hostport the port to use
    CFReadStreamRef readStream = NULL;
    CFWriteStreamRef writeStream = NULL;
    CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (CFStringRef ) server, hostport, &readStream, &writeStream);
    if (readStream && writeStream) {
    CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket , kCFBooleanTrue);
    CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
    iStream = (NSInputStream *)readStream;
    [iStream retain];
    [iStream setDelegate:self];
    oStream = (NSOutputStream *)writeStream;
    [oStream retain];
    [oStream setDelegate:self];
    if (Iwill_use_ssltoday == true)
    int res1 = [iStream setProperty:NSStreamSocketSecurityLevelNegotiatedSSL forKey:NSStreamSocketSecurityLevelKey];
    int res2 = [oStream setProperty:NSStreamSocketSecurityLevelNegotiatedSSL forKey:NSStreamSocketSecurityLevelKey];
    NSLog(@"SEC TEST %d %d",res1,res2);
    NSDictionary *settings = [[NSDictionary alloc] initWithObjectsAndKeys:
    [NSNumber numberWithBool:YES], kCFStreamSSLAllowsExpiredCertificates,
    [NSNumber numberWithBool:YES], kCFStreamSSLAllowsAnyRoot,
    [NSNumber numberWithBool:NO], kCFStreamSSLValidatesCertificateChain,
    kCFNull,kCFStreamSSLPeerName,
    // kCFStreamSocketSecurityLevelTLSv1, kCFStreamSSLLevel,
    nil];
    CFReadStreamSetProperty((CFReadStreamRef)iStream, kCFStreamPropertySSLSettings, (CFTypeRef)settings);
    CFWriteStreamSetProperty((CFWriteStreamRef)oStream, kCFStreamPropertySSLSettings, (CFTypeRef)settings);
    [iStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [iStream open];
    [oStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [oStream open];
    if (readStream)
    CFRelease(readStream);
    if (writeStream)
    CFRelease(writeStream);

  • I'm on an iphone that is no longer connected to the network, using it as an ipod touch. I can't download apps, however... it tells me that there is no secure connection and to update the date and the time. I'm not on a public network though...

    I am using an old iPhone 3 as an iPod touch. It's no longer connected to a network. I am trying to download apps while using a secure internet connection, however, it's not allowing me to do so. The message is gives is: "Cannot Connect to the Store" A secure connection could not be established. Please check your date and time settings."  I'm confused as to how I can fix this. The time seems to be correct, and I'm not using public internet.... Any suggestions??

    The warranty entitles you to complimentary phone support for the first 90 days of ownership.

  • Not able to connect my Iphone to my WRT54GS router with security enabled

    As the subject line states, I'm not able to connect my Iphone to my WRT54GS router when the security is enabled. When ever I attempt to connect to my network with my phone it always tells me the password is incorrect. I have double checked the password in the easylink advisor and it matches up. I have also tried both WPA and WEP with the same result, I know that the wireless is working on the router as I turned the security off and was able to connect to it. I updated the firmware this evening also with no changes. If anyone could help me with this issue it would be much appreciated.

    First of all, in the router, give your network a unique SSID. Do not use "linksys". If you are using "linksys" you may be trying to connect to your neighbor's router. Also, in the router, set "SSID Broadcast" to "enabled". This will help your iPhone find and lock on to your router's signal.
    To connect using WEP, enter WEP "key 1"  (found in the router)  into the iPhone, not the WEP password or passphrase.
    To connect using WPA, make sure that there is not an encryption nomenclature problem.  For example, WPA is not the same as WPA with AES.  Please note the following:
    WPA    =   PSK    =   WPA with TKIP  =  WPA   personal
    WPA2  =   PSK2  =   WPA with AES   =  WPA2 personal
    I am not certain, but your iPhone probably does just ordinary WPA  (not WPA with AES).  Assuming that this is correct, then the router should be set to:
    "WPA personal"  with  "TKIP"
    Also, in the iPhone, be sure to delete the entry for your unsecured connection to your router, before you try to input info regarding the secured connection to the router.
    Hope this helps.
    Message Edited by toomanydonuts on 07-16-2008 03:12 AM

  • IPhone: Secure Connection Failed...what to do?

    Hi,
    I'm trying to set up my email account on my iPhone and I'm having difficulties doing it. I have entered the information correctly many times now and I get the same result. The account is a POP account, I believe associated with squirrlemail some how, at least that who my webmail comes through.
    The message I get from my iPhone is the following:
    "Secure Connection Failed
    The certificate for 'Nick Hall Photography' may not be valid"
    If anyone can help me I would be most greatful.
    Warm regards,
    Nick

    Yahoo mail? They have had problems today.

  • After updating my iPhone 4s to iOS 6.1, Verification Failed: An SSL error has occurred and a secure connection to the server cannot be made. My wifi connection works; the icon is present at the top left. But Internet won't connect, be it Safari, App Store

    After updating my iPhone 4s to iOS 6.1, Verification Failed: "An SSL error has occurred and a secure connection to the server cannot be made." My wifi connection works; the icon is present at the top left. But Internet apps won't connect, be it Safari, App Store or Facebook & instagram. Push notifications also work so posts from Facebook and Instagram still pop-up. Does any one have any ideas? Thanks.

    I have the same problem.  Worked fine on Friday.  My VPN or any ssl site do not work on my iPhone 5.  Both work perfect on iPhone 4 and 4s

  • TS1424 itunes could connect to this iphone could not establish a secure connection to this device

    itunes could not connect to this iphone could not establish a secure connection to this device

    Same problem with my iPhone 4S on iMac and MacBook Pro with OSX Mountain Lion
    iPod work fine...
    USB is connectet directly to computer not HUB.
    Battery is on 88%
    No updates available on App Store...
    God back Steve for few more years please

  • How to update to ios6 when "could not establish a secure connection to the device" message appears with Jailbroken iPhone 4

    Hi all,
    I've been trying to update my Jailbroken iPhone 4 to ios6 but, unfortunately, I keep getting the "could not establish a secure connection to the device" when connecting it to iTunes. I've tried updating "over the air" but this flags up an error too. Finally, I can't restore to a previous backup because, the backups I previously had, were stored on my old (broken) computer.
    CAn anyone help? Any suggestions would be greatly appreciated!
    Thanks,
    Rakesh.

    You jailbroke your phone.
    Only google may help now.
    You'll find no help here.
    If Haiku you don't like,
    Then to Google you should hike,
    You jailbroke your phone,
    Now on these forums you are alone,
    'Tis a day of no cheer,
    For we cannot help here.
    In non-poem; You jailbroke your phone, which is not support by Apple, meaning updates will not work on it as they would if you were running official software.
    As per the ToC for the device, and for these Discussion Boards (both you agreed too), you will not get support either from the discussion board, or from Apple directly.
    Your best bet is to Google for help and learn a valuable lesson; Jailbreaking can definitely brick your phone.

  • Making my connection "Secure"

    I've just recently moved and rehooked up my wireless router.  I'm connected to the internet but my connection is unsecure.  I would really like to know how to create a secure connection with a password like I used to have.  If anyone could give me some step by step directions that'd be great.  Thanks.

    Which router are you using?
    To set up wireless security, you must use a computer that is wired to the router.
    Where to find the router settings: The router's login password is usually on one of the "Administration" pages. The other settings are all found in the "Wireless" section of the router's setup pages, located at 192.168.1.1
    First, give your router a unique SSID. Don't use "linksys".
    Make sure "SSID Broadcast" is set to "enabled".
    Next, leave the router at its default settings (except for the unique SSID), and then use your pc to connect wirelessly to the router. Test your wireless Internet connection and make sure it is working correctly. You must have a properly working wireless connection before setting up wireless security.
    To implement wireless security, you need to do one step at a time, then verify that you can still connect your wireless computer to the router.
    Next, encrypt your wireless system using the highest level of encryption that all of your wireless devices will support. Common encryption methods are:
    WEP - poor (see note below)
    WPA (sometimes called PSK) - good
    WPA2 (sometimes called PSK2) - best
    WPA and WPA2 sometimes come in versions of "personal" and "enterprise". Most home users should use "personal". Also, if you have a choice between AES and TKIP, and your wireless equipment is capable of both, choose AES. With any encryption method, you will need to supply a key (sometimes called a "password" ).
    The wireless devices (computers, printers, etc.) that you have will need to be set up with the SSID, encryption method, and key that matches what you entered in the router.
    Retest your system and verify that your wireless Internet connection is still working correctly.
    For additional security, on many routers, you can limit wireless access to just the MAC addresses of the wireless devices that you own. If possible, you should also use this feature.
    And don't forget to give your router a new login password.
    Picking Passwords (keys): You should never use a dictionary word as a password. If you use a dictionary word as a password, even WPA2 can be cracked in a few minutes. When you pick your login password and encryption key (or password or passphrase) you should use a random combination of capital letters, small letters, and numbers, but no spaces. A login password, should be 12 characters or more. WPA and WPA2 passwords should be at least 24 characters. Note: Your key, password, or passphrase must not have any spaces in it.
    Most home users should have their routers set so that "remote management" of the router is disabled. If you must have this option enabled, then your login password must be increased to a minumum of 24 random characters.
    One additional issue is that Windows XP requires a patch to run WPA2. Go to Microsoft Knowledge base, article ID=893357 and it will direct you to the patch.
    Sadly, the patch is not part of the automatic Windows XP updates, so lots of people are missing the patch.
    Note:
    WEP is no longer recommended. The FBI has demonstrated that WEP can be cracked in just a few minutes using software tools that are readily available over the Internet. Even a long random character password will not protect you with WEP. You should be using WPA or preferably WPA2 encryption.

  • How to connect my iPhone to my iMac trough bluetooth?

    How to connect my iPhone to my iMac trough bluetooth?

    If you have a wifi router you can set up/turn on the wifi... set the user name and password wifi in your router... open wifi in general settings on the iPhone... log into your router, user name and password. (If your don't know how to turn on the router wifi. Google the router make and model and you will find instructions on how to do this.)
    If you don't have a wifi router and your Mac has wifi capabilities you can hookup to the internet over wifi from your Mac to your iPhone.
    System Preferences on the Mac... Network... Wifi... Advanced tab... Hit the '+' to add a user name and password...
    Make sure you use WPA2 Personal for Security... Hit ok... Turn on the wifi... Same as above with the iPhone, log into your wifi settings on the iPhone.
    *Important point... Use WPA2 for the encryption/Security setting. If you use anything else for this setting, your wifi can be hacked.

  • How to connect my iphone to imac on wifi

    Hi
    I want to connect my iphone to imac on wifi. Actually i want to use internet on my iphone. So how can i do this ?

    If you have a wifi router you can set up/turn on the wifi... set the user name and password wifi in your router... open wifi in general settings on the iPhone... log into your router, user name and password. (If your don't know how to turn on the router wifi. Google the router make and model and you will find instructions on how to do this.)
    If you don't have a wifi router and your Mac has wifi capabilities you can hookup to the internet over wifi from your Mac to your iPhone.
    System Preferences on the Mac... Network... Wifi... Advanced tab... Hit the '+' to add a user name and password...
    Make sure you use WPA2 Personal for Security... Hit ok... Turn on the wifi... Same as above with the iPhone, log into your wifi settings on the iPhone.
    *Important point... Use WPA2 for the encryption/Security setting. If you use anything else for this setting, your wifi can be hacked.

  • I get error message 42032 when trying to connect an iPhone to iTunes. Any ideas how to fix it?

    I get error message 42032 when trying to connect an iPhone to iTunes. Any ideas how to fix it?

    Did you already try these suggestions?
    Check USB connections
    Related errors: 13, 14, 1600-1629, 1643-1650, 2000-2009, 4000, 4005, 4013, 4014, 4016, “invalid response,” and being prompted to restore again after a restore completes.
    If there’s an issue with the USB port, cable, dock, or hub, or if the device becomes disconnected during restore, try troubleshooting the USB connection, then troubleshooting your security software.
    To narrow down the issue, you can also change up your hardware:
    Use another USB cable.
    Plug your cable into a different USB port on your computer.
    Try a different dock connector (or no dock).
    Add (or remove) a USB hub between your device and computer.
    Connect your computer directly to your Internet source, with no routers, hubs, or switches.
    If you checked your connections and are still seeing the error message, check for hardware issues.
    copied from Resolve specific iTunes update and restore errors

  • I get an error message when I try to connect my iphone 4 to my MacBook

    I have a MacBook pro (2006) and I keep trying to connect my iphone 4 so I can add music to the phone and get my pictures from my phone to the laptop, every time I plug the phone in I get an error message that reads "iTunes could not connect to the iPhone 'Kianna's Phone' Beause it is locked with a passcode. You must enter your passcode on the iPhone before it can be used with iTunes." I don't have a lock code on my phone so I tried to just slide it to unlock it and I get a messages on the phone asking if I trust this computer so I click yes but it continues to pop up. I tried to turn on the passcode and type it in to unlock it then plug it in and also while it is plugged in then I tried taking it off again, nothing worked. I would really appreciate it if someone could help me. My phone is all updated there is no available software update.

    Presumably you have some sort of wired or wireless router.
    You will hopefully have a manual for that. There should be a login/password to let you change the way the router works usually via a web page interface, as chances are if you can see your network name but not connect it's a configuration issue.
    Perhaps someone set it up for you. What sort is it?
    If you can see the network name then (if wireless) the router is broadcasting the SSID (name essentially) - in theory you should have a password set to access that wireless network - if not then anyone will be able to tap into your network which is not ideal from a security viewpoint. It's often best to disable broadcasting the name so no one sees your network, but it's easier to configure automatically when you don't have to enter it manually into a device like AppleTV.
    AC

  • Secure connection to iTunes store failed and could not update to ios 6

    I tried in 4 different pcs with windows 7 installed to update my iphone 4 to latest version of ios (ios6) my current version is 5.1.1. I never had this issue ever before.. My iphone is jailbroken and so i couldnt update with OTA. I also tried to install a fresh copy of ios 5.1.1 to update my phone via OTA.. But the same problem now in itunes 10.5 and 10.7 too.. "iTunes could not connect to iphone software update server or is temporarily unavailable". I checked iTunes itunes diagnostics and the secure connection to itunes storo fail is the only thing which doesnt work.. I tried almost everything from here.. Starting from "internet option", changing the hosts file and the firewall thing.. But couldnt get it better.. What shoud i do?
    Here is my iTunes diagnostics report:
    Microsoft Windows 7 Ultimate Edition (Build 7600)
    eMachines ET1861
    iTunes 10.7.0.21
    QuickTime 7.6.9
    FairPlay 2.2.19
    Apple Application Support 2.2.2
    iPod Updater Library 10.0d2
    CD Driver 2.2.3.0
    CD Driver DLL 2.1.3.1
    Apple Mobile Device 6.0.0.59
    Apple Mobile Device Driver 1.62.0.0
    Bonjour 3.0.0.10 (333.10)
    Gracenote SDK 1.9.6.502
    Gracenote MusicID 1.9.6.115
    Gracenote Submit 1.9.6.143
    Gracenote DSP 1.9.6.45
    iTunes Serial Number 0023AEC4028E1440
    Current user is an administrator.
    The current local date and time is 2012-09-23 09:00:21.
    iTunes is not running in safe mode.
    WebKit accelerated compositing is enabled.
    HDCP is not supported.
    Core Media is supported.
    Video Display Information
    Intel Corporation, Intel(R) HD Graphics
    **** External Plug-ins Information ****
    No external plug-ins installed.
    iPodService 10.7.0.21 is currently running.
    iTunesHelper 10.7.0.21 is currently running.
    Apple Mobile Device service 3.3.0.0 is currently running.
    **** Network Connectivity Tests ****
    Network Adapter Information
    Adapter Name:    {A11C5D80-134D-4FA9-BF81-1C4A418C0F4A}
    Description:    Dhiraagu
    IP Address:    10.151.15.47
    Subnet Mask:    255.255.255.255
    Default Gateway:    0.0.0.0
    DHCP Enabled:    No
    DHCP Server:   
    Lease Obtained:    Thu Jan 01 05:00:00 1970
    Lease Expires:    Thu Jan 01 05:00:00 1970
    DNS Servers:    27.114.138.4
            27.114.140.62
    Adapter Name:    {1EAA0EEE-E778-4884-B030-1AFF603AEC57}
    Description:    Realtek RTL8168D/8111D Family PCI-E Gigabit Ethernet NIC (NDIS 6.20)
    IP Address:    0.0.0.0
    Subnet Mask:    0.0.0.0
    Default Gateway:    0.0.0.0
    DHCP Enabled:    Yes
    DHCP Server:   
    Lease Obtained:    Thu Jan 01 05:00:00 1970
    Lease Expires:    Thu Jan 01 05:00:00 1970
    DNS Servers:   
    Active Connection:    Dhiraagu
    Connected:    Yes
    Online:        Yes
    Using Modem:    Yes
    Using LAN:    No
    Using Proxy:    No
    Firewall Information
    Windows Firewall is off.
    Connection attempt to Apple web site was successful.
    Connection attempt to browsing iTunes Store was successful.
    Connection attempt to purchasing from iTunes Store was successful.
    Connection attempt to iPhone activation server was successful.
    Connection attempt to firmware update server was unsuccessful.
    The network connection timed out.
    Connection attempt to Gracenote server was successful.
    The network connection timed out.
    Last successful iTunes Store access was 2012-09-23 08:57:21.
    PLEASE HELP ME...!!!

    Hi msahed,
    Welcome to Apple Support Communities.
    It sounds like there is an issue with your PC establishing a secure connection to the iTunes Store and the firmware update server. Try following along with the articles below, as they should resolve the issues that you described.
    iTunes: About the "A secure network connection could not be established" alert
    http://support.apple.com/kb/ts1470
    iTunes for Windows: iTunes can't contact the iPhone, iPad, or iPod software update server
    http://support.apple.com/kb/TS1814
    I hope this helps.
    -Jason

  • I have a 3rd gen Ipod touch and when i connect it to my Macbook pro to sync it with itunes, it doesn't show up on iTunes. When I connect my iPhone 6 to my computer it syncs, backs up, ect. How do I connect this older iPod to my iTunes?

    I have a 3rd gen Ipod touch. When I connect it to my Macbook pro to sync it with itunes, it doesn't show up on iTunes. When I connect my iPhone 6 to my computer it syncs, backs up, ect. How do I make this older iPod show up on my iTunes?

    Hi ChristianHelpplz,
    Thanks for visiting Apple Support Communities.
    It seems like your iPod touch is not recognized by iTunes on your Mac, but your iPhone 6 is working normally.
    I recommend starting with these steps to troubleshoot your iPod touch and connection with your Mac:
    Check your USB connections
    Unplug other USB devices from your Mac and try again.
    Try a different USB port.
    Try a different USB cable.
    Restart your device
    Restart your iOS device or reset your iPod.
    Restart your Mac
    Turn your Mac off and back on.
    Update your software
    Check for software updates on your Mac.
    Check for an iTunes update.
    Check your security software
    If you have security software installed, learn how to resolve issues between iTunes and your security software.
    From:
    If you don't see your connected device in iTunes for Mac - Apple Support
    If you've tried these steps and your iPod touch is still not recognized, try placing it into Recovery Mode next:
    If you can't update or restore your iPhone, iPad, or iPod touch - Apple Support
    Sincerely,
    Jeremy

Maybe you are looking for