From a97bd9c3a6de37a4e09b03767251793db456ceb9 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Thu, 24 Feb 2011 19:51:53 +0100 Subject: [PATCH] Escape SCRAM usernames (authzid and authcid) --- src/XMPPSCRAMAuth.m | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/XMPPSCRAMAuth.m b/src/XMPPSCRAMAuth.m index 523c5c3..5963c52 100644 --- a/src/XMPPSCRAMAuth.m +++ b/src/XMPPSCRAMAuth.m @@ -88,6 +88,44 @@ [super dealloc]; } +- (void)setAuthzid: (OFString*)authzid_ +{ + OFString *old = authzid; + + if (authzid_) { + OFMutableString *new = [[OFMutableString alloc] + initWithString: authzid_]; + [new replaceOccurrencesOfString: @"=" + withString: @"=3D"]; + [new replaceOccurrencesOfString: @"," + withString: @"=2C"]; + authzid = [new copy]; + [new release]; + } else + authzid = nil; + + [old release]; +} + +- (void)setAuthcid: (OFString*)authcid_ +{ + OFString *old = authcid; + + if (authcid_) { + OFMutableString *new = [[OFMutableString alloc] + initWithString: authcid_]; + [new replaceOccurrencesOfString: @"=" + withString: @"=3D"]; + [new replaceOccurrencesOfString: @"," + withString: @"=2C"]; + authcid = [new copy]; + [new release]; + } else + authcid = nil; + + [old release]; +} + - (OFString *)_genNonce { OFMutableString *nonce = [OFMutableString string];