Anyone got SSL over NSStreams to work?

  • Hi. I'm doing the following in an attempt to establish an SSL
    connection over NSStreams, per the NSStream documentation:

    { ...
    [NSStream getStreamsToHost:@"blah.blah.com"
      port:1234
      inputStream:&mInStream
      outputStream:&mOutStream];

    [mInStream retain];
    [mOutStream retain];

    [mInStream setDelegate:self];
    [mOutStream setDelegate:self];

    [mInStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
    forMode:NSDefaultRunLoopMode];
    [mOutStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
    forMode:NSDefaultRunLoopMode];

    assert([mInStream setProperty:NSStreamSocketSecurityLevelNegotiatedSSL
    forKey:NSStreamSocketSecurityLevelKey]);
    assert([mOutStream
    setProperty:NSStreamSocketSecurityLevelNegotiatedSSL
    forKey:NSStreamSocketSecurityLevelKey]);

    [mInStream open];
    [mOutStream open];
    }

    In my stream:handleEvent: delegate method,  I always get back an
    NSStreamEventErrorOccurred event with an NSUnknownErrorDomain (-9812)
    error.  It doesn't matter which SSL property I set the socket to.
    Always the same error. Turning off SSL on the output stream doesn't
    change things either. On the server side, the machine's log is
    indicating that an SSL connection is being made. I'm running this on
    Mac OS X 10.3.7

    Has anyone gotten this stuff to work? A search of the Net shows very
    few mentions of using SSL with NSStreams, and there are unanswered
    NSStreams+SSL questions in the cocoa-dev archive. I sure hope someone
    could shed so light on what I may be missing.
  • On Jan 13, 2005, at 7:45 PM, Jay Koutavas wrote:

    > Hi. I'm doing the following in an attempt to establish an SSL
    > connection over NSStreams, per the NSStream documentation:
    >
    >
    > { ...
    > [NSStream getStreamsToHost:@"blah.blah.com"
    > port:1234
    > inputStream:&mInStream
    > outputStream:&mOutStream];
    >
    > [mInStream retain];
    > [mOutStream retain];
    >
    > [mInStream setDelegate:self];
    > [mOutStream setDelegate:self];
    >
    > [mInStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
    > forMode:NSDefaultRunLoopMode];
    > [mOutStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
    > forMode:NSDefaultRunLoopMode];
    >
    > assert([mInStream
    > setProperty:NSStreamSocketSecurityLevelNegotiatedSSL
    > forKey:NSStreamSocketSecurityLevelKey]);
    > assert([mOutStream
    > setProperty:NSStreamSocketSecurityLevelNegotiatedSSL
    > forKey:NSStreamSocketSecurityLevelKey]);
    >
    > [mInStream open];
    > [mOutStream open];
    > }
    >
    > In my stream:handleEvent: delegate method,  I always get back an
    > NSStreamEventErrorOccurred event with an NSUnknownErrorDomain (-9812)
    > error.  It doesn't matter which SSL property I set the socket to.
    > Always the same error. Turning off SSL on the output stream doesn't
    > change things either. On the server side, the machine's log is
    > indicating that an SSL connection is being made. I'm running this on
    > Mac OS X 10.3.7
    >
    > Has anyone gotten this stuff to work? A search of the Net shows very
    > few mentions of using SSL with NSStreams, and there are unanswered
    > NSStreams+SSL questions in the cocoa-dev archive. I sure hope someone
    > could shed so light on what I may be missing.

    You're passing a NSString instead of the required NSHost to
    getStreamsToHost:port:inputStream:outputStream: .

    Go to
    http://developer.apple.com/documentation/Cocoa/Conceptual/Streams/
    index.html, see "Setting Up Socket Streams," and take a look at Listing
    1 there. It will show you exactly what to do.

    Fred
  • That's just my example text. In my real code I have host there. I
    over simplified the code for the example.

    Have you gotten SSL to work using NSStreams?

    /Jay

    At 2:18 AM -0800 on 2/15/05, Fred Baker wrote:

    > On Jan 13, 2005, at 7:45 PM, Jay Koutavas wrote:
    >
    >> Hi. I'm doing the following in an attempt to establish an SSL
    >> connection over NSStreams, per the NSStream documentation:
    >>
    >>
    >> { ...
    >> [NSStream getStreamsToHost:@"blah.blah.com"
    >> port:1234
    >> inputStream:&mInStream
    >> outputStream:&mOutStream];
    >>
    >> [mInStream retain];
    >> [mOutStream retain];
    >>
    >> [mInStream setDelegate:self];
    >> [mOutStream setDelegate:self];
    >>
    >> [mInStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
    >> forMode:NSDefaultRunLoopMode];
    >> [mOutStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
    >> forMode:NSDefaultRunLoopMode];
    >>
    >> assert([mInStream
    >> setProperty:NSStreamSocketSecurityLevelNegotiatedSSL
    >> forKey:NSStreamSocketSecurityLevelKey]);
    >> assert([mOutStream
    >> setProperty:NSStreamSocketSecurityLevelNegotiatedSSL
    >> forKey:NSStreamSocketSecurityLevelKey]);
    >>
    >> [mInStream open];
    >> [mOutStream open];
    >> }
    >>
    >> In my stream:handleEvent: delegate method,  I always get back an
    >> NSStreamEventErrorOccurred event with an NSUnknownErrorDomain
    >> (-9812) error.  It doesn't matter which SSL property I set the
    >> socket to. Always the same error. Turning off SSL on the output
    >> stream doesn't change things either. On the server side, the
    >> machine's log is indicating that an SSL connection is being made.
    >> I'm running this on Mac OS X 10.3.7
    >>
    >> Has anyone gotten this stuff to work? A search of the Net shows
    >> very few mentions of using SSL with NSStreams, and there are
    >> unanswered NSStreams+SSL questions in the cocoa-dev archive. I sure
    >> hope someone could shed so light on what I may be missing.
    >
    > You're passing a NSString instead of the required NSHost to
    > getStreamsToHost:port:inputStream:outputStream: .
    >
    > Go to
    > http://developer.apple.com/documentation/Cocoa/Conceptual/Streams/index.ht
    ml
    ,
    > see "Setting Up Socket Streams," and take a look at Listing 1 there.
    > It will show you exactly what to do.
    >
    > Fred

    --
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      Jay Koutavas                        mailto:<jay...>
      Heynow Software                      http://www.heynow.com
      Windham, New Hampshire, USA
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
previous month january 2005 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today
MindNode
MindNode offered a free license !