summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2012-12-13 13:35:53 (GMT)
committerRemko Tronçon <git@el-tramo.be>2013-04-06 20:22:02 (GMT)
commit9eff25182d1bea576d1910200909384ce79d90fe (patch)
treef5dadbce5fa2c37c34fcc6bb32550e6930abce14 /Swiften/TLS
parente9f2f7675b11ce36b3f66250156b78fae524a351 (diff)
downloadswift-9eff25182d1bea576d1910200909384ce79d90fe.zip
swift-9eff25182d1bea576d1910200909384ce79d90fe.tar.bz2
Make IDN implementation abstract.
Change-Id: I4c64f954ddeca7147d729b8be07237baa15c1795
Diffstat (limited to 'Swiften/TLS')
-rw-r--r--Swiften/TLS/ServerIdentityVerifier.cpp6
-rw-r--r--Swiften/TLS/ServerIdentityVerifier.h4
-rw-r--r--Swiften/TLS/UnitTest/ServerIdentityVerifierTest.cpp40
3 files changed, 30 insertions, 20 deletions
diff --git a/Swiften/TLS/ServerIdentityVerifier.cpp b/Swiften/TLS/ServerIdentityVerifier.cpp
index 59c0614..cc6e68a 100644
--- a/Swiften/TLS/ServerIdentityVerifier.cpp
+++ b/Swiften/TLS/ServerIdentityVerifier.cpp
@@ -9,13 +9,13 @@
#include <boost/algorithm/string.hpp>
#include <Swiften/Base/foreach.h>
-#include <Swiften/IDN/IDNA.h>
+#include <Swiften/IDN/IDNConverter.h>
namespace Swift {
-ServerIdentityVerifier::ServerIdentityVerifier(const JID& jid) {
+ServerIdentityVerifier::ServerIdentityVerifier(const JID& jid, IDNConverter* idnConverter) {
domain = jid.getDomain();
- encodedDomain = IDNA::getEncoded(domain);
+ encodedDomain = idnConverter->getIDNAEncoded(domain);
}
bool ServerIdentityVerifier::certificateVerifies(Certificate::ref certificate) {
diff --git a/Swiften/TLS/ServerIdentityVerifier.h b/Swiften/TLS/ServerIdentityVerifier.h
index 730ee74..4167ce8 100644
--- a/Swiften/TLS/ServerIdentityVerifier.h
+++ b/Swiften/TLS/ServerIdentityVerifier.h
@@ -14,9 +14,11 @@
#include <Swiften/TLS/Certificate.h>
namespace Swift {
+ class IDNConverter;
+
class SWIFTEN_API ServerIdentityVerifier {
public:
- ServerIdentityVerifier(const JID& jid);
+ ServerIdentityVerifier(const JID& jid, IDNConverter* idnConverter);
bool certificateVerifies(Certificate::ref);
diff --git a/Swiften/TLS/UnitTest/ServerIdentityVerifierTest.cpp b/Swiften/TLS/UnitTest/ServerIdentityVerifierTest.cpp
index bd68c84..e974eb7 100644
--- a/Swiften/TLS/UnitTest/ServerIdentityVerifierTest.cpp
+++ b/Swiften/TLS/UnitTest/ServerIdentityVerifierTest.cpp
@@ -12,6 +12,8 @@
#include <Swiften/TLS/ServerIdentityVerifier.h>
#include <Swiften/TLS/SimpleCertificate.h>
+#include <Swiften/IDN/IDNConverter.h>
+#include <Swiften/IDN/PlatformIDNConverter.h>
using namespace Swift;
@@ -36,8 +38,12 @@ class ServerIdentityVerifierTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE_END();
public:
+ void setUp() {
+ idnConverter = boost::shared_ptr<IDNConverter>(PlatformIDNConverter::create());
+ }
+
void testCertificateVerifies_WithoutMatchingDNSName() {
- ServerIdentityVerifier testling(JID("foo@bar.com/baz"));
+ ServerIdentityVerifier testling(JID("foo@bar.com/baz"), idnConverter.get());
SimpleCertificate::ref certificate(new SimpleCertificate());
certificate->addDNSName("foo.com");
@@ -45,7 +51,7 @@ class ServerIdentityVerifierTest : public CppUnit::TestFixture {
}
void testCertificateVerifies_WithMatchingDNSName() {
- ServerIdentityVerifier testling(JID("foo@bar.com/baz"));
+ ServerIdentityVerifier testling(JID("foo@bar.com/baz"), idnConverter.get());
SimpleCertificate::ref certificate(new SimpleCertificate());
certificate->addDNSName("bar.com");
@@ -53,7 +59,7 @@ class ServerIdentityVerifierTest : public CppUnit::TestFixture {
}
void testCertificateVerifies_WithSecondMatchingDNSName() {
- ServerIdentityVerifier testling(JID("foo@bar.com/baz"));
+ ServerIdentityVerifier testling(JID("foo@bar.com/baz"), idnConverter.get());
SimpleCertificate::ref certificate(new SimpleCertificate());
certificate->addDNSName("foo.com");
certificate->addDNSName("bar.com");
@@ -62,7 +68,7 @@ class ServerIdentityVerifierTest : public CppUnit::TestFixture {
}
void testCertificateVerifies_WithMatchingInternationalDNSName() {
- ServerIdentityVerifier testling(JID("foo@tron\xc3\xa7on.com/baz"));
+ ServerIdentityVerifier testling(JID("foo@tron\xc3\xa7on.com/baz"), idnConverter.get());
SimpleCertificate::ref certificate(new SimpleCertificate());
certificate->addDNSName("xn--tronon-zua.com");
@@ -70,7 +76,7 @@ class ServerIdentityVerifierTest : public CppUnit::TestFixture {
}
void testCertificateVerifies_WithMatchingDNSNameWithWildcard() {
- ServerIdentityVerifier testling(JID("foo@im.bar.com/baz"));
+ ServerIdentityVerifier testling(JID("foo@im.bar.com/baz"), idnConverter.get());
SimpleCertificate::ref certificate(new SimpleCertificate());
certificate->addDNSName("*.bar.com");
@@ -78,7 +84,7 @@ class ServerIdentityVerifierTest : public CppUnit::TestFixture {
}
void testCertificateVerifies_WithMatchingDNSNameWithWildcardMatchingNoComponents() {
- ServerIdentityVerifier testling(JID("foo@bar.com/baz"));
+ ServerIdentityVerifier testling(JID("foo@bar.com/baz"), idnConverter.get());
SimpleCertificate::ref certificate(new SimpleCertificate());
certificate->addDNSName("*.bar.com");
@@ -86,7 +92,7 @@ class ServerIdentityVerifierTest : public CppUnit::TestFixture {
}
void testCertificateVerifies_WithDNSNameWithWildcardMatchingTwoComponents() {
- ServerIdentityVerifier testling(JID("foo@xmpp.im.bar.com/baz"));
+ ServerIdentityVerifier testling(JID("foo@xmpp.im.bar.com/baz"), idnConverter.get());
SimpleCertificate::ref certificate(new SimpleCertificate());
certificate->addDNSName("*.bar.com");
@@ -94,7 +100,7 @@ class ServerIdentityVerifierTest : public CppUnit::TestFixture {
}
void testCertificateVerifies_WithMatchingSRVNameWithoutService() {
- ServerIdentityVerifier testling(JID("foo@bar.com/baz"));
+ ServerIdentityVerifier testling(JID("foo@bar.com/baz"), idnConverter.get());
SimpleCertificate::ref certificate(new SimpleCertificate());
certificate->addSRVName("bar.com");
@@ -102,7 +108,7 @@ class ServerIdentityVerifierTest : public CppUnit::TestFixture {
}
void testCertificateVerifies_WithMatchingSRVNameWithService() {
- ServerIdentityVerifier testling(JID("foo@bar.com/baz"));
+ ServerIdentityVerifier testling(JID("foo@bar.com/baz"), idnConverter.get());
SimpleCertificate::ref certificate(new SimpleCertificate());
certificate->addSRVName("_xmpp-client.bar.com");
@@ -110,7 +116,7 @@ class ServerIdentityVerifierTest : public CppUnit::TestFixture {
}
void testCertificateVerifies_WithMatchingSRVNameWithServiceAndWildcard() {
- ServerIdentityVerifier testling(JID("foo@im.bar.com/baz"));
+ ServerIdentityVerifier testling(JID("foo@im.bar.com/baz"), idnConverter.get());
SimpleCertificate::ref certificate(new SimpleCertificate());
certificate->addSRVName("_xmpp-client.*.bar.com");
@@ -118,7 +124,7 @@ class ServerIdentityVerifierTest : public CppUnit::TestFixture {
}
void testCertificateVerifies_WithMatchingSRVNameWithDifferentService() {
- ServerIdentityVerifier testling(JID("foo@bar.com/baz"));
+ ServerIdentityVerifier testling(JID("foo@bar.com/baz"), idnConverter.get());
SimpleCertificate::ref certificate(new SimpleCertificate());
certificate->addSRVName("_xmpp-server.bar.com");
@@ -126,7 +132,7 @@ class ServerIdentityVerifierTest : public CppUnit::TestFixture {
}
void testCertificateVerifies_WithMatchingXmppAddr() {
- ServerIdentityVerifier testling(JID("foo@bar.com/baz"));
+ ServerIdentityVerifier testling(JID("foo@bar.com/baz"), idnConverter.get());
SimpleCertificate::ref certificate(new SimpleCertificate());
certificate->addXMPPAddress("bar.com");
@@ -134,7 +140,7 @@ class ServerIdentityVerifierTest : public CppUnit::TestFixture {
}
void testCertificateVerifies_WithMatchingXmppAddrWithWildcard() {
- ServerIdentityVerifier testling(JID("foo@im.bar.com/baz"));
+ ServerIdentityVerifier testling(JID("foo@im.bar.com/baz"), idnConverter.get());
SimpleCertificate::ref certificate(new SimpleCertificate());
certificate->addXMPPAddress("*.bar.com");
@@ -142,7 +148,7 @@ class ServerIdentityVerifierTest : public CppUnit::TestFixture {
}
void testCertificateVerifies_WithMatchingInternationalXmppAddr() {
- ServerIdentityVerifier testling(JID("foo@tron\xc3\xa7.com/baz"));
+ ServerIdentityVerifier testling(JID("foo@tron\xc3\xa7.com/baz"), idnConverter.get());
SimpleCertificate::ref certificate(new SimpleCertificate());
certificate->addXMPPAddress("tron\xc3\xa7.com");
@@ -150,7 +156,7 @@ class ServerIdentityVerifierTest : public CppUnit::TestFixture {
}
void testCertificateVerifies_WithMatchingCNWithoutSAN() {
- ServerIdentityVerifier testling(JID("foo@bar.com/baz"));
+ ServerIdentityVerifier testling(JID("foo@bar.com/baz"), idnConverter.get());
SimpleCertificate::ref certificate(new SimpleCertificate());
certificate->addCommonName("bar.com");
@@ -158,13 +164,15 @@ class ServerIdentityVerifierTest : public CppUnit::TestFixture {
}
void testCertificateVerifies_WithMatchingCNWithSAN() {
- ServerIdentityVerifier testling(JID("foo@bar.com/baz"));
+ ServerIdentityVerifier testling(JID("foo@bar.com/baz"), idnConverter.get());
SimpleCertificate::ref certificate(new SimpleCertificate());
certificate->addSRVName("foo.com");
certificate->addCommonName("bar.com");
CPPUNIT_ASSERT(!testling.certificateVerifies(certificate));
}
+
+ boost::shared_ptr<IDNConverter> idnConverter;
};
CPPUNIT_TEST_SUITE_REGISTRATION(ServerIdentityVerifierTest);