-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IPv6 support to fwknop #285
base: master
Are you sure you want to change the base?
Changes from all commits
07693a9
b8252db
460bd8c
a0dda67
b3494dc
aea56f5
f7b18d6
2f6ea52
72a50b9
2367bc2
ce9b5fb
3dc6116
1a813bb
a525734
37a8000
6bcaf4f
8ecd10b
89c7d6f
bd1c488
a2462c6
82a5eec
17549b9
d1c1373
baed23c
f61a308
b070e80
da1ab05
76d609b
587a4fb
11e9b29
d6ce22b
32cdd11
f35c1d7
7437039
a2902cb
c753215
d260f50
c8670aa
3e329a5
9878756
1fd5fe1
6405398
08e805d
15dfc94
bbb341c
3a8e01a
13dee2c
9923fc0
c5994a3
e3aeb46
e29d62e
956e1df
edeea23
a7a9ecb
7f9d09e
576eb11
81e2255
fa664db
dd0597f
ba4d095
282aa2d
68cacee
d28d1cb
f97214b
0bbbd13
2bdaeff
fd6def0
561ba96
159c62c
70df56f
c1d3656
73d7b79
460774c
f3895bb
46d4d77
3f3b304
a2edaec
91f3842
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,8 +87,8 @@ typedef struct fko_cli_options | |
int no_save_args; | ||
int use_hmac; | ||
char spa_server_str[MAX_SERVER_STR_LEN]; /* may be a hostname */ | ||
char allow_ip_str[MAX_IPV4_STR_LEN]; | ||
char spoof_ip_src_str[MAX_IPV4_STR_LEN]; | ||
char allow_ip_str[MAX_IPV46_STR_LEN]; | ||
char spoof_ip_src_str[MAX_IPV46_STR_LEN]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use INET6_ADDRSTRLEN |
||
char spoof_user[MAX_USERNAME_LEN]; | ||
int rand_port; | ||
char gpg_recipient_key[MAX_GPG_KEY_ID]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,13 +58,12 @@ struct url | |
static int | ||
try_url(struct url *url, fko_cli_options_t *options) | ||
{ | ||
int sock=-1, sock_success=0, res, error, http_buf_len, i; | ||
int sock=-1, sock_success=0, i, res, error, http_buf_len; | ||
int bytes_read = 0, position = 0; | ||
int o1, o2, o3, o4; | ||
struct addrinfo *result=NULL, *rp, hints; | ||
char http_buf[HTTP_MAX_REQUEST_LEN] = {0}; | ||
char http_response[HTTP_MAX_RESPONSE_LEN] = {0}; | ||
char *ndx; | ||
char *ndx, c; | ||
|
||
#ifdef WIN32 | ||
WSADATA wsa_data; | ||
|
@@ -197,45 +196,47 @@ try_url(struct url *url, fko_cli_options_t *options) | |
} | ||
ndx += 4; | ||
|
||
/* Walk along the content to try to find the end of the IP address. | ||
* Note: We are expecting the content to be just an IP address | ||
* (possibly followed by whitespace or other not-digit value). | ||
/* Walk along the content to try to find the end of the IP address. | ||
* Note: We are expecting the content to be just an IP address | ||
* (possibly followed by whitespace or other not-digit value). | ||
*/ | ||
for(i=0; i<MAX_IPV46_STR_LEN; i++) { | ||
c = *(ndx+i); | ||
if(! isdigit((int)(unsigned char)c) && ! ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) && c != '.' && c != ':') | ||
break; | ||
} | ||
|
||
/* Terminate at the first non-digit and non-dot. | ||
*/ | ||
for(i=0; i<MAX_IPV4_STR_LEN; i++) { | ||
if(! isdigit((int)(unsigned char)*(ndx+i)) && *(ndx+i) != '.') | ||
break; | ||
} | ||
|
||
/* Terminate at the first non-digit and non-dot. | ||
*/ | ||
*(ndx+i) = '\0'; | ||
|
||
/* Now that we have what we think is an IP address string. We make | ||
* sure the format and values are sane. | ||
*/ | ||
if((sscanf(ndx, "%u.%u.%u.%u", &o1, &o2, &o3, &o4)) == 4 | ||
&& o1 >= 0 && o1 <= 255 | ||
&& o2 >= 0 && o2 <= 255 | ||
&& o3 >= 0 && o3 <= 255 | ||
&& o4 >= 0 && o4 <= 255) | ||
{ | ||
strlcpy(options->allow_ip_str, ndx, sizeof(options->allow_ip_str)); | ||
|
||
log_msg(LOG_VERBOSITY_INFO, | ||
"\n[+] Resolved external IP (via http://%s%s) as: %s", | ||
url->host, | ||
url->path, | ||
options->allow_ip_str); | ||
*(ndx+i) = '\0'; | ||
|
||
return(1); | ||
} | ||
else | ||
/* Try to parse the content as an IP address. */ | ||
memset(&hints, 0, sizeof(struct addrinfo)); | ||
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ | ||
hints.ai_flags = AI_NUMERICHOST | AI_CANONNAME; | ||
error = getaddrinfo(ndx, NULL, &hints, &result); | ||
if (error != 0) | ||
{ | ||
log_msg(LOG_VERBOSITY_ERROR, | ||
"[-] From http://%s%s\n Invalid IP (%s) in HTTP response:\n\n%s", | ||
url->host, url->path, ndx, http_response); | ||
return(-1); | ||
} | ||
for (rp = result; rp != NULL; rp = rp->ai_next) { | ||
/* the canonical value is in the first structure returned */ | ||
strlcpy(options->allow_ip_str, | ||
rp->ai_canonname, sizeof(options->allow_ip_str)); | ||
break; | ||
} | ||
freeaddrinfo(result); | ||
|
||
log_msg(LOG_VERBOSITY_INFO, | ||
"\n[+] Resolved external IP (via http://%s%s) as: %s", | ||
url->host, | ||
url->path, | ||
options->allow_ip_str); | ||
|
||
return(1); | ||
} | ||
|
||
static int | ||
|
@@ -323,8 +324,9 @@ parse_url(char *res_url, struct url* url) | |
int | ||
resolve_ip_https(fko_cli_options_t *options) | ||
{ | ||
int o1, o2, o3, o4, got_resp=0, i=0; | ||
char *ndx, resp[MAX_IPV4_STR_LEN+1] = {0}; | ||
int got_resp=0, error; | ||
char resp[MAX_IPV4_STR_LEN+1] = {0}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MAX_IPV46_STR_LEN ? |
||
struct addrinfo *result=NULL, *rp, hints; | ||
struct url url; /* for validation only */ | ||
char wget_ssl_cmd[MAX_URL_PATH_LEN] = {0}; /* for verbose logging only */ | ||
|
||
|
@@ -493,32 +495,35 @@ resolve_ip_https(fko_cli_options_t *options) | |
pclose(wget); | ||
#endif | ||
|
||
if(got_resp) | ||
if(! got_resp) | ||
{ | ||
ndx = resp; | ||
for(i=0; i<MAX_IPV4_STR_LEN; i++) { | ||
if(! isdigit((int)(unsigned char)*(ndx+i)) && *(ndx+i) != '.') | ||
break; | ||
} | ||
*(ndx+i) = '\0'; | ||
|
||
if((sscanf(ndx, "%u.%u.%u.%u", &o1, &o2, &o3, &o4)) == 4 | ||
&& o1 >= 0 && o1 <= 255 | ||
&& o2 >= 0 && o2 <= 255 | ||
&& o3 >= 0 && o3 <= 255 | ||
&& o4 >= 0 && o4 <= 255) | ||
{ | ||
strlcpy(options->allow_ip_str, ndx, sizeof(options->allow_ip_str)); | ||
log_msg(LOG_VERBOSITY_ERROR, | ||
"[-] Could not resolve IP via: '%s'", wget_ssl_cmd); | ||
return -1; | ||
} | ||
|
||
log_msg(LOG_VERBOSITY_INFO, | ||
"\n[+] Resolved external IP (via '%s') as: %s", | ||
wget_ssl_cmd, options->allow_ip_str); | ||
return 1; | ||
} | ||
memset(&hints, 0, sizeof(struct addrinfo)); | ||
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ | ||
hints.ai_flags = AI_NUMERICHOST | AI_CANONNAME; | ||
error = getaddrinfo(resp, NULL, &hints, &result); | ||
if (error != 0) | ||
{ | ||
log_msg(LOG_VERBOSITY_ERROR, | ||
"[-] Could not resolve IP via: '%s'", wget_ssl_cmd); | ||
return(-1); | ||
} | ||
log_msg(LOG_VERBOSITY_ERROR, | ||
"[-] Could not resolve IP via: '%s'", wget_ssl_cmd); | ||
return -1; | ||
for (rp = result; rp != NULL; rp = rp->ai_next) { | ||
/* the canonical value is in the first structure returned */ | ||
strlcpy(options->allow_ip_str, | ||
rp->ai_canonname, sizeof(options->allow_ip_str)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why getting last entry ? |
||
break; | ||
} | ||
freeaddrinfo(result); | ||
|
||
log_msg(LOG_VERBOSITY_INFO, | ||
"\n[+] Resolved external IP (via '%s') as: %s", | ||
wget_ssl_cmd, options->allow_ip_str); | ||
return 1; | ||
} | ||
|
||
int | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use INET6_ADDRSTRLEN
While you are right that longtest IPv6 address takes 39 bytes, with IPv4 tunneling, the longest form can be 45 bytes: