EDCommon/EDMessage: SMTPS using SSL, not TLS

Discussion of the EDMessage and EDCommon frameworks.

EDCommon/EDMessage: SMTPS using SSL, not TLS

Postby patrick » 30 Nov 2011, 13:18

Gmail's SMTPS server typically supports SSL connections on port 465 and TLS connections on port 587. EDMessage v17 supports SMTPS using TLS, but not SSL. It is possible, though unlikely, that you'd need to connect to an SMTPS server that supports only SSL.

Code: Select all
diff -c edmessage-17/Mail.subproj/EDMailAgent.h modified/Mail.subproj/EDMailAgent.h
*** edmessage-17/Mail.subproj/EDMailAgent.h   Mon Nov 24 04:56:06 2008
--- modified/Mail.subproj/EDMailAgent.h   Tue Nov 29 15:16:07 2011
***************
*** 28,33 ****
--- 28,34 ----
     unsigned   usesSecureConnections : 1;
     unsigned   allowsAnyRootCertificate : 1;
     unsigned   allowsExpiredCertificates : 1;
+    unsigned   usesSSLConnections : 1;
  };
 
 
***************
*** 66,71 ****
--- 67,75 ----
  - (void)setAllowsExpiredCertificates:(BOOL)allowed;
  - (BOOL)allowsExpiredCertificates;
 
+ - (void)setUsesSSLConnections:(BOOL)flag;
+ - (BOOL)usesSSLConnections;
+
  - (void)setAuthInfo:(NSDictionary *)infoDictionary;
  - (NSDictionary *)authInfo;
 
diff -c edmessage-17/Mail.subproj/EDMailAgent.m modified/Mail.subproj/EDMailAgent.m
*** edmessage-17/Mail.subproj/EDMailAgent.m   Mon Nov 24 04:56:06 2008
--- modified/Mail.subproj/EDMailAgent.m   Tue Nov 29 15:25:14 2011
***************
*** 30,35 ****
--- 30,36 ----
  #import "EDMultimediaContentCoder.h"
  #import "EDInternetMessage.h"
  #import "EDSecureSMTPStream.h"
+ #import "OSPSSLSMTPStream.h"
  #import "OPSSLSocket.h"
  #import "EDMailAgent.h"
 
***************
*** 249,254 ****
--- 250,270 ----
  }
 
 
+ /*" Sets whether the mail agent should use SSL when delivering messages. "*/
+
+ - (void)setUsesSSLConnections:(BOOL)flag
+ {
+    flags.usesSSLConnections = flag;
+ }
+
+ /*" Returns whether the mail agent should use SSL when delivering messages. "*/
+
+ - (BOOL)usesSSLConnections
+ {
+    return flags.usesSSLConnections;
+ }
+
+
  /*" Sets the authentication information. The dictionary should contain values for the following keys: EDSMTPUserName, EDSMTPPassword. "*/
 
  - (void)setAuthInfo:(NSDictionary *)infoDictionary
***************
*** 279,285 ****
     NSString         *userName, *password;
     NSError            *authError;
 
!    if([self usesSecureConnections])
        {
        stream = secureStream = [EDSecureSMTPStream streamConnectedToHost:relayHost port:port];
        [[secureStream socket] setAllowsAnyRootCertificate:flags.allowsAnyRootCertificate];
--- 295,307 ----
     NSString         *userName, *password;
     NSError            *authError;
 
!    if([self usesSSLConnections])
!       {
!       stream = secureStream = [OSPSSLSMTPStream streamConnectedToHost:relayHost port:port];
!       [[secureStream socket] setAllowsAnyRootCertificate:flags.allowsAnyRootCertificate];
!       [[secureStream socket] setAllowsExpiredCertificates:flags.allowsExpiredCertificates];
!       }
!    else if([self usesSecureConnections])
        {
        stream = secureStream = [EDSecureSMTPStream streamConnectedToHost:relayHost port:port];
        [[secureStream socket] setAllowsAnyRootCertificate:flags.allowsAnyRootCertificate];



Code: Select all
//
//  OSPSSLSMTPStream.h
//  EDMessage
//
//  Created by Patrick Middleton on 29/11/2011.
//  Copyright 2011 OneStep Solutions LLP. All rights reserved.
//

// ad lib...

//---------------------------------------------------------------------------------------
//  EDSMTPSStream.h created by erik on Wed 08-Oct-2008
//  $Id: EDSecureSMTPStream.h 346 2008-10-10 08:20:42Z erik $
//
//  Copyright (c) 2008 by Erik Doernenburg. All rights reserved.
//
//  Permission to use, copy, modify and distribute this software and its documentation
//  is hereby granted, provided that both the copyright notice and this permission
//  notice appear in all copies of the software, derivative works or modified versions,
//  and any portions thereof, and that both notices appear in supporting documentation,
//  and that credit is given to Erik Doernenburg in all documents and publicity
//  pertaining to direct or indirect use of this code or its derivatives.
//
//  THIS IS EXPERIMENTAL SOFTWARE AND IT IS KNOWN TO HAVE BUGS, SOME OF WHICH MAY HAVE
//  SERIOUS CONSEQUENCES. THE COPYRIGHT HOLDER ALLOWS FREE USE OF THIS SOFTWARE IN ITS
//  "AS IS" CONDITION. THE COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY
//  DAMAGES WHATSOEVER RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE
//  OR OF ANY DERIVATIVE WORK.
//---------------------------------------------------------------------------------------

#import "EDSMTPStream.h"

@class OPSSLSocket;

@interface OSPSSLSMTPStream : EDSMTPStream
{
}

- (OPSSLSocket *)socket;

@end


Code: Select all
//
//  OSPSSLSMTPStream.m
//  EDMessage
//
//  Created by Patrick Middleton on 29/11/2011.
//  Copyright 2011 OneStep Solutions LLP. All rights reserved.
//

// ad lib...

//---------------------------------------------------------------------------------------
//  EDSMTPSStream.m created by erik on Wed 08-Oct-2008
//  $Id: EDSecureSMTPStream.m 346 2008-10-10 08:20:42Z erik $
//
//  Copyright (c) 2008 by Erik Doernenburg. All rights reserved.
//
//  Permission to use, copy, modify and distribute this software and its documentation
//  is hereby granted, provided that both the copyright notice and this permission
//  notice appear in all copies of the software, derivative works or modified versions,
//  and any portions thereof, and that both notices appear in supporting documentation,
//  and that credit is given to Erik Doernenburg in all documents and publicity
//  pertaining to direct or indirect use of this code or its derivatives.
//
//  THIS IS EXPERIMENTAL SOFTWARE AND IT IS KNOWN TO HAVE BUGS, SOME OF WHICH MAY HAVE
//  SERIOUS CONSEQUENCES. THE COPYRIGHT HOLDER ALLOWS FREE USE OF THIS SOFTWARE IN ITS
//  "AS IS" CONDITION. THE COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY
//  DAMAGES WHATSOEVER RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE
//  OR OF ANY DERIVATIVE WORK.
//---------------------------------------------------------------------------------------

#import "OSPSSLSMTPStream.h"
#import "OPSSLSocket.h"

@interface EDSMTPStream(PrivateAPI)
- (void)_startProtocol;
@end

//---------------------------------------------------------------------------------------
    @implementation OSPSSLSMTPStream
//---------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------
//   FACTORY
//---------------------------------------------------------------------------------------

+ (id)streamConnectedToHost:(NSHost *)host port:(unsigned short)port
{
    OPSSLSocket *socket;
   
    socket = [OPSSLSocket socket];
    [socket connectToHost:host port:port];
    return [self streamWithFileHandle:socket];
}


//---------------------------------------------------------------------------------------
//   ACCESSOR METHODS
//---------------------------------------------------------------------------------------

- (OPSSLSocket *)socket
{
   return (OPSSLSocket *)[self fileHandle];
}


//---------------------------------------------------------------------------------------
//   OVERRIDES
//---------------------------------------------------------------------------------------

- (void)_startProtocol
{
   if([[self socket] isNotEncrypted]) {
        [[self socket] negotiateEncryption];
    }
   
   if([[self socket] isEncrypted]) {
        [super _startProtocol];
    }  else {
      state = InitFailed;
      [NSException raise:EDSMTPException format:@"Failed to initialize SSL connection for SMTP"];
    }
}

//---------------------------------------------------------------------------------------
//   SMTP EXTENSIONS
//---------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------
    @end
//---------------------------------------------------------------------------------------
patrick
 
Posts: 2
Joined: 29 Sep 2011, 12:04

Return to ED Frameworks



cron