From 40ce49ba5202e649899c1f938cfec6b0c5ae97ef Mon Sep 17 00:00:00 2001 From: Andreas Buff Date: Wed, 28 Jul 2021 11:25:47 +0200 Subject: [PATCH] IOS-2888 fixes: truncated password send for SMTP if unicode chars are used in password (caused by messing with data wrongly and needlessly instead of using NSString directly) --- pantomime-lib/Framework/Pantomime/CWSMTP.m | 48 ++++--------------- pantomime-lib/Framework/Pantomime/CWService.m | 2 +- 2 files changed, 11 insertions(+), 39 deletions(-) diff --git a/pantomime-lib/Framework/Pantomime/CWSMTP.m b/pantomime-lib/Framework/Pantomime/CWSMTP.m index c2129e7..893d334 100644 --- a/pantomime-lib/Framework/Pantomime/CWSMTP.m +++ b/pantomime-lib/Framework/Pantomime/CWSMTP.m @@ -570,46 +570,18 @@ static inline CWInternetAddress *next_recipient(NSMutableArray *theRecipients, B // - (void) _parseAUTH_PLAIN { - NSData *aData; - - aData = [_responsesFromServer lastObject]; + NSData *aData = [_responsesFromServer lastObject]; - if ([aData hasCPrefix: "334"]) - { - NSMutableData *aMutableData; - NSUInteger len_username, len_password; - - len_username = [_username length]; - - if (!_password) - { - len_password = 0; - } - else - { - len_password = [_password length]; - } - - // We create our phrase - aMutableData = [NSMutableData dataWithLength: (len_username + len_password + 2)]; - - [aMutableData replaceBytesInRange: NSMakeRange(1,len_username) - withBytes: [[_username dataUsingEncoding: _defaultCStringEncoding] bytes]]; - - - [aMutableData replaceBytesInRange: NSMakeRange(2 + len_username, len_password) - withBytes: [[_password dataUsingEncoding: [NSString defaultCStringEncoding]] bytes]]; - - [self bulkWriteData:@[[aMutableData encodeBase64WithLineLength: 0], - _crlf]]; + if ([aData hasCPrefix: "334"]) { + NSString *stringToSend = [NSString stringWithFormat:@"\0%@\0%@", _username, _password]; + NSData *dataToSend = [stringToSend dataUsingEncoding:_defaultCStringEncoding]; + [self bulkWriteData:@[[dataToSend encodeBase64WithLineLength: 0], + _crlf]]; + } else if ([aData hasCPrefix: "235"]) { + AUTHENTICATION_COMPLETED(_delegate, @"PLAIN"); } - else if ([aData hasCPrefix: "235"]) - { - AUTHENTICATION_COMPLETED(_delegate, @"PLAIN"); - } - else - { - AUTHENTICATION_FAILED(_delegate, @"PLAIN"); + else { + AUTHENTICATION_FAILED(_delegate, @"PLAIN"); } } diff --git a/pantomime-lib/Framework/Pantomime/CWService.m b/pantomime-lib/Framework/Pantomime/CWService.m index bcf172b..620fbed 100644 --- a/pantomime-lib/Framework/Pantomime/CWService.m +++ b/pantomime-lib/Framework/Pantomime/CWService.m @@ -67,7 +67,7 @@ self = [super init]; if (self) { _crlf = [[NSData alloc] initWithBytes: "\r\n" length: 2]; - _defaultCStringEncoding = [NSString defaultCStringEncoding]; + _defaultCStringEncoding = NSUTF8StringEncoding; //[NSString defaultCStringEncoding]; //??? _supportedMechanisms = [[CWThreadSafeArray alloc] init]; _responsesFromServer = [[CWThreadSafeArray alloc] init];