diff options
| author | Remko Tronçon <git@el-tramo.be> | 2009-11-22 10:20:58 (GMT) |
|---|---|---|
| committer | Remko Tronçon <git@el-tramo.be> | 2009-11-22 10:27:01 (GMT) |
| commit | 4e244a9d1967ad416530aa3b9b07faad54097327 (patch) | |
| tree | 413ee864cb85976178eaf9efee7cf6ff92acd4b7 /Swiften/SASL/SCRAMSHA1ClientAuthenticator.cpp | |
| parent | 38fbde49ec4ff77708237d768581a47e6dd7d553 (diff) | |
| download | swift-4e244a9d1967ad416530aa3b9b07faad54097327.zip swift-4e244a9d1967ad416530aa3b9b07faad54097327.tar.bz2 | |
Added SCRAM-SHA-1 unit test.
Diffstat (limited to 'Swiften/SASL/SCRAMSHA1ClientAuthenticator.cpp')
| -rw-r--r-- | Swiften/SASL/SCRAMSHA1ClientAuthenticator.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/Swiften/SASL/SCRAMSHA1ClientAuthenticator.cpp b/Swiften/SASL/SCRAMSHA1ClientAuthenticator.cpp index 41e8f72..15c8ab6 100644 --- a/Swiften/SASL/SCRAMSHA1ClientAuthenticator.cpp +++ b/Swiften/SASL/SCRAMSHA1ClientAuthenticator.cpp @@ -42,53 +42,65 @@ bool SCRAMSHA1ClientAuthenticator::setChallenge(const ByteArray& challenge) { if (step == Initial) { initialServerMessage = challenge; // TODO: Check if these values are correct std::map<char, String> keys = parseMap(String(initialServerMessage.getData(), initialServerMessage.getSize())); salt = Base64::decode(keys['s']); String clientServerNonce = keys['r']; serverNonce = clientServerNonce.getSubstring(clientnonce.getUTF8Size(), clientServerNonce.npos()); iterations = boost::lexical_cast<int>(keys['i'].getUTF8String()); step = Proof; return true; } else { return challenge == Base64::encode(ByteArray("v=") + Base64::encode(serverSignature)); } } std::map<char, String> SCRAMSHA1ClientAuthenticator::parseMap(const String& s) { // TODO: Do some proper checking here std::map<char, String> result; if (s.getUTF8Size() > 0) { char key; String value; size_t i = 0; bool expectKey = true; while (i < s.getUTF8Size()) { if (expectKey) { key = s[i]; expectKey = false; i++; } else if (s[i] == ',') { result[key] = value; value = ""; expectKey = true; } else { value += s[i]; } i++; } result[key] = value; } return result; } ByteArray SCRAMSHA1ClientAuthenticator::getInitialBareClientMessage() const { - // TODO: Replace , and = - return ByteArray(String("n=" + getAuthenticationID() + ",r=" + clientnonce)); + String authenticationID = getAuthenticationID(); + String escapedAuthenticationID; + for (size_t i = 0; i < authenticationID.getUTF8Size(); ++i) { + if (authenticationID[i] == ',') { + escapedAuthenticationID += "=2C"; + } + else if (authenticationID[i] == '=') { + escapedAuthenticationID += "=3D"; + } + else { + escapedAuthenticationID += authenticationID[i]; + } + } + return ByteArray(String("n=" + escapedAuthenticationID + ",r=" + clientnonce)); } } |
Swift