+ // Check for invalid characters
+ if (QRegExp("[^a-zA-Z0-9\\.\\*\\-]").match(cn) >= 0) {
+ kdDebug(7029) << "CN contains invalid characters! Failing." << endl;
+ return false;
+ }
+
+ // Domains can legally end with '.'s. We don't need them though.
+ while(cn.right(1) == ".")
+ cn.truncate(cn.length()-1);
+
+ // Do not let empty CN's get by!!
+ if (cn.isEmpty())
+ return false;
+
+ // Check for IPv4 address
+ rx.setPattern("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}");
+ int tmp;
+ if (rx.match(d->peerHost, 0, &tmp) == 0 && tmp == d->peerHost.length())
+ return d->peerHost == cn;
+
+ // Check for IPv6 address here...
+ rx.setPattern("^\\[.*\\]$");
+ if (rx.match(d->peerHost, 0, &tmp) == 0 && tmp == d->peerHost.length())
+ return d->peerHost == cn;
+
+ if (cn.contains('*')) {
+ // First make sure that there are at least two valid parts
+ // after the wildcard (*).
+ QStringList parts = QStringList::split('.', cn, false);
+
+ while(parts.count() > 2)
+ parts.remove(parts.begin());
+
+ if (parts.count() != 2) {
+ return false; // we don't allow *.root - that's bad
+ }
+
+ if (parts[0].contains('*') || parts[1].contains('*')) {
+ return false;
+ }
+
+ // RFC2818 says that *.example.com should match against
+ // foo.example.com but not bar.foo.example.com
+ // (ie. they must have the same number of parts)
+ if (QRegExp(cn, false, true).match(d->peerHost, 0, &tmp) == 0 &&
+ tmp == d->peerHost.length() &&
+ QStringList::split('.', cn, false).count() ==
+ QStringList::split('.', d->peerHost, false).count())
+ return true;
+
+ return false;
+ }
+
+ // We must have an exact match in this case (insensitive though)
+ // (note we already did .lower())
+ if (cn == d->peerHost)
+ return true;
#endif
- return false;
+ return false;
}
-void KSSLPeerInfo::extractDomains(const QString &fqdn, QStringList &domains)
-{
- domains.clear();
-
- // If fqdn is an IP address, then only use
- // the entire IP address to find a match! (DA)
- if (fqdn[0] >= '0' && fqdn[0] <= '9') {
- domains.append(fqdn);
- return;
- }
-
- QStringList partList = QStringList::split('.', fqdn, false);
-
- if (partList.count())
- partList.remove(partList.begin()); // Remove hostname
-
- while(partList.count()) {
- if (partList.count() == 1)
- break; // We only have a TLD left.
-
- if (partList.count() == 2) {
- // If this is a TLD, we should stop. (e.g. co.uk)
- // We assume this is a TLD if it ends with .xx.yy or .x.yy
- if (partList[0].length() <= 2 && partList[1].length() == 2)
- break; // This is a TLD.
- }
-
- QString domain = partList.join(".");
- domains.append(domain);
- partList.remove(partList.begin());
- }
-
- // Add the entire FQDN at the end of the
- // list for fqdn == CN checks
- domains.append(fqdn);
-}
+
diff -u -3 -p -r1.50.2.3 -r1.50.2.4
--- kssl.cc 7 Nov 2001 05:47:37 -0000 1.50.2.3
+++ kssl.cc 14 May 2003 16:30:23 -0000 1.50.2.4
@@ -336,25 +336,19 @@ void KSSL::setConnectionInfo() {
}