443 }
444
445 hostname = host;
446
447 // is this a domain wildcard specification
448 if (host.lastIndexOf('*') > 0) {
449 throw new
450 IllegalArgumentException("invalid host wildcard specification");
451 } else if (host.startsWith("*")) {
452 wildcard = true;
453 if (host.equals("*")) {
454 cname = "";
455 } else if (host.startsWith("*.")) {
456 cname = host.substring(1).toLowerCase();
457 } else {
458 throw new
459 IllegalArgumentException("invalid host wildcard specification");
460 }
461 return;
462 } else {
463 if (host.length() > 0) {
464 // see if we are being initialized with an IP address.
465 char ch = host.charAt(0);
466 if (ch == ':' || Character.digit(ch, 16) != -1) {
467 byte ip[] = IPAddressUtil.textToNumericFormatV4(host);
468 if (ip == null) {
469 ip = IPAddressUtil.textToNumericFormatV6(host);
470 }
471 if (ip != null) {
472 try {
473 addresses =
474 new InetAddress[]
475 {InetAddress.getByAddress(ip) };
476 init_with_ip = true;
477 } catch (UnknownHostException uhe) {
478 // this shouldn't happen
479 invalid = true;
480 }
481 }
482 }
483 }
688 }
689
690 private boolean match(String cname, String hname) {
691 String a = checkForIDN(cname.toLowerCase());
692 String b = checkForIDN(hname.toLowerCase());
693 if (a.startsWith(b) &&
694 ((a.length() == b.length()) || (a.charAt(b.length()) == '.'))) {
695 return true;
696 }
697 if (cdomain == null) {
698 cdomain = RegisteredDomain.from(a)
699 .map(RegisteredDomain::name)
700 .orElse(a);
701 }
702 if (hdomain == null) {
703 hdomain = RegisteredDomain.from(b)
704 .map(RegisteredDomain::name)
705 .orElse(b);
706 }
707
708 return cdomain.length() != 0 && hdomain.length() != 0
709 && cdomain.equals(hdomain);
710 }
711
712 private boolean authorized(String cname, byte[] addr) {
713 if (addr.length == 4)
714 return authorizedIPv4(cname, addr);
715 else if (addr.length == 16)
716 return authorizedIPv6(cname, addr);
717 else
718 return false;
719 }
720
721 private boolean authorizedIPv4(String cname, byte[] addr) {
722 String authHost = "";
723 InetAddress auth;
724
725 try {
726 authHost = "auth." +
727 (addr[3] & 0xff) + "." + (addr[2] & 0xff) + "." +
728 (addr[1] & 0xff) + "." + (addr[0] & 0xff) +
729 ".in-addr.arpa";
|
443 }
444
445 hostname = host;
446
447 // is this a domain wildcard specification
448 if (host.lastIndexOf('*') > 0) {
449 throw new
450 IllegalArgumentException("invalid host wildcard specification");
451 } else if (host.startsWith("*")) {
452 wildcard = true;
453 if (host.equals("*")) {
454 cname = "";
455 } else if (host.startsWith("*.")) {
456 cname = host.substring(1).toLowerCase();
457 } else {
458 throw new
459 IllegalArgumentException("invalid host wildcard specification");
460 }
461 return;
462 } else {
463 if (!host.isEmpty()) {
464 // see if we are being initialized with an IP address.
465 char ch = host.charAt(0);
466 if (ch == ':' || Character.digit(ch, 16) != -1) {
467 byte ip[] = IPAddressUtil.textToNumericFormatV4(host);
468 if (ip == null) {
469 ip = IPAddressUtil.textToNumericFormatV6(host);
470 }
471 if (ip != null) {
472 try {
473 addresses =
474 new InetAddress[]
475 {InetAddress.getByAddress(ip) };
476 init_with_ip = true;
477 } catch (UnknownHostException uhe) {
478 // this shouldn't happen
479 invalid = true;
480 }
481 }
482 }
483 }
688 }
689
690 private boolean match(String cname, String hname) {
691 String a = checkForIDN(cname.toLowerCase());
692 String b = checkForIDN(hname.toLowerCase());
693 if (a.startsWith(b) &&
694 ((a.length() == b.length()) || (a.charAt(b.length()) == '.'))) {
695 return true;
696 }
697 if (cdomain == null) {
698 cdomain = RegisteredDomain.from(a)
699 .map(RegisteredDomain::name)
700 .orElse(a);
701 }
702 if (hdomain == null) {
703 hdomain = RegisteredDomain.from(b)
704 .map(RegisteredDomain::name)
705 .orElse(b);
706 }
707
708 return !cdomain.isEmpty() && !hdomain.isEmpty() && cdomain.equals(hdomain);
709 }
710
711 private boolean authorized(String cname, byte[] addr) {
712 if (addr.length == 4)
713 return authorizedIPv4(cname, addr);
714 else if (addr.length == 16)
715 return authorizedIPv6(cname, addr);
716 else
717 return false;
718 }
719
720 private boolean authorizedIPv4(String cname, byte[] addr) {
721 String authHost = "";
722 InetAddress auth;
723
724 try {
725 authHost = "auth." +
726 (addr[3] & 0xff) + "." + (addr[2] & 0xff) + "." +
727 (addr[1] & 0xff) + "." + (addr[0] & 0xff) +
728 ".in-addr.arpa";
|