lewisje / growl

Automatically exported from code.google.com/p/growl
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

Domain Name validation error when entering host in the subscription preference. #625

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Steps will reproduce the problem
1. go to Growl prefereces, Network, Subscription
2. add a host and try to enter demers.name

What is the expected output?
It is a valid domain so it should be accepted

What do you see instead?
you'll get "Please enter a valid IPv4 or IPv6 address, or a valid domain name"

What version of the product are you using? On what operating system?
Growl 2.1.4, many different OSX

Additional info:
the validation in the method (BOOL)Growl_isLikelyDomainName des not include 
latest TLD like .name (which is where my server is located).

With all the new legitimate TLD appearing, validation probably should be 
relaxed.

Original issue reported on code.google.com by scientif...@videotron.ca on 9 Feb 2014 at 9:02

GoogleCodeExporter commented 8 years ago
We'd accept a patch on this sort of thing to help expedite it getting done, if 
you're so inclined. :)

Original comment by ch...@growl.info on 9 Feb 2014 at 11:05

GoogleCodeExporter commented 8 years ago
I can't compile Growl because I can't sign… Since I only do in-house dev, I'm 
not sure how to turn it off.  I propose to include in the bundle a file 
extracted from http://data.iana.org/TLD/tlds-alpha-by-domain.txt which is 
supposed to be up to date. I've attached a copy. An array of valid domain tads 
could be lazily generated and then checked against a domain name. I tested the 
following code which can called against even more generic strings like 
"bozo.toto.com":

- (BOOL)Growl_isLikelyDomainName
{
    static NSArray *tldArray = nil;
    NSString *lowerSelf = [[[domain lowercaseString] componentsSeparatedByString:@"."] lastObject]  ;

    if ( tldArray == nil){
        NSString * tldFile;
        NSString * tldString;

        NSBundle* myBundle = [NSBundle mainBundle];
        tldFile = [myBundle pathForResource:@"tlds-alpha-by-domain"  ofType:@"txt" ];
        tldString = [[NSString stringWithContentsOfFile:tldFile encoding: NSUTF8StringEncoding error:nil] lowercaseString];
        tldArray = [[tldString componentsSeparatedByString:@"\n"] retain];

        NSRange range;
        range.location = 1;
        range.length = [tldArray count ] - 1 ; // Remove the first line which contains the version
        tldArray = [tldArray subarrayWithRange:  range]; // This may still include a last emply line
    }

    if ([tldArray containsObject: lowerSelf] ) {
        if ([lowerSelf compare:@""] != NSOrderedSame){  // Check fo the file ending with empty lines
            return YES;
        };
    }
    return NO;
}

Original comment by scientif...@videotron.ca on 10 Feb 2014 at 5:34

Attachments:

GoogleCodeExporter commented 8 years ago
Create a self signed certificate in keychain with the same name and then you'll 
be able to build. :)

Original comment by ch...@growl.info on 10 Feb 2014 at 6:24

GoogleCodeExporter commented 8 years ago
Well, I got it to compile after playing with a few project settings and 
commenting the error warning about the wrong toolchain. The code above seems to 
 fail the second time it's called for reason I don't' get.   the following code 
however seems reliable.

- (BOOL)Growl_isLikelyDomainName
{
    NSArray *tldArray = nil;
    NSString *lowerSelf = [[[self lowercaseString] componentsSeparatedByString:@"."] lastObject]  ;

    NSString * tldFile;
    NSString * tldString;

    NSBundle* myBundle = [NSBundle mainBundle];
    tldFile = [myBundle pathForResource:@"tlds-alpha-by-domain"  ofType:@"txt" ];
    tldString = [[NSString stringWithContentsOfFile:tldFile encoding: NSUTF8StringEncoding error:nil] lowercaseString];
    tldArray = [tldString componentsSeparatedByString:@"\n"] ;

    NSRange range;
    range.location = 1;
    range.length = [tldArray count ] - 1 ; // Remove the first line which contains the version
    tldArray = [tldArray subarrayWithRange:  range]; // This may still include a last emply line

    if ([tldArray containsObject: lowerSelf] ) {
        if ([lowerSelf compare:@""] != NSOrderedSame){  // Check fo the file ending with empty lines
            return YES;
        };
    }
    return NO;
}

Add to the resources the file attached in my proviso message and we got a 
solution. When the ICANN updates the file just pop in the new version in the 
resources and rebuild.  Should be easier to maintain. I don't know if signed 
applications would allow it, but a user could even open the bundle to update 
the file themselves.

Original comment by scientif...@videotron.ca on 11 Feb 2014 at 2:43

GoogleCodeExporter commented 8 years ago

Original comment by rarich...@gmail.com on 12 Mar 2014 at 5:20

GoogleCodeExporter commented 8 years ago
this is slightly more complicated than just reading in that file, i'm 
evaluating some code to do punycode/IDNA conversions as the TLD file itself has 
xm-- TLD designations in it.  I'm pretty sure the correct thing to do for those 
is to accept both the xm-- encoding as well as the translated unicode character 
encoding. I should hopefully have a response from Wevah about some code he has 
on github and its suitability for this ticket.

I have also augmented the non-TLD line stripping to be more tolerant of comment 
lines places other than the first line, as well as empty lines.

Original comment by rarich...@gmail.com on 12 Mar 2014 at 6:30

GoogleCodeExporter commented 8 years ago
But overall, what are you trying to protect the user from ? Seems a lot of work 
with unclear objectives... It's not because the TLD is valid that the host is, 
so the user can still configure some bogus host and have the system fail...

Original comment by scientif...@videotron.ca on 12 Mar 2014 at 1:56