diff --git a/certexample b/certexample index 133b4413ab264e369a804e79ee90672329bf6e0f..d1746d435261cd0a4018b32bfe4e346b2ad4dafd 100755 Binary files a/certexample and b/certexample differ diff --git a/certexample.c b/certexample.c index ab7dba11f5a4eb06162b95618e19b56559a40553..b9975030bb566c69550f064270bf3a6c1176fa74 100644 --- a/certexample.c +++ b/certexample.c @@ -36,6 +36,11 @@ int validate_CN_and_SAN(const char *url, X509 *cert); int validate_not_before(X509 *cert); int validate_not_after(X509 *cert); int validate_certificate(const char *url, X509 *cert); +int find_first_instanceof(const char *str, char delim); +char *str_slice_to_end(const char *str, int begin); + + + int main(int argc, char **argv){ int LINE_BUFFER=100; @@ -122,6 +127,7 @@ int main(int argc, char **argv){ } exit(0); } + char* get_basic_constraints(X509 *cert){ X509_EXTENSION *ex = X509_get_ext(cert, X509_get_ext_by_NID(cert, NID_basic_constraints, -1)); @@ -372,17 +378,29 @@ int validate_basic_constraints(char* basic_constraints){ } int validate_wildcard_string(const char *hostname, char*hostname_with_wildcard){ - char **hostname_with_wildcard_split = str_split(hostname_with_wildcard, '.'); - char **hostname_split = str_split(hostname, '.'); - const char *hostname_with_wildcard_right = hostname_with_wildcard_split[1]; - const char *hostname_split_right = hostname_split[1]; + char *hostname_with_wildcard_sliced = str_slice_to_end(hostname_with_wildcard, (find_first_instanceof(hostname_with_wildcard, '.'))); + char *hostname_sliced = str_slice_to_end(hostname, (find_first_instanceof(hostname, '.'))); + + + + + + + + // char **hostname_with_wildcard_split = str_split(hostname_with_wildcard, '.'); + + // char **hostname_split = str_split(hostname, '.'); + + // const char *hostname_with_wildcard_right = hostname_with_wildcard_split[1]; + // const char *hostname_split_right = hostname_split[1]; - if(strcasecmp(hostname_split_right, hostname_with_wildcard_right)==0){ - printf("\t\tWILDCARD FUNCTION\t\t%s == %s\n", hostname_split_right, hostname_with_wildcard_right); + if(strcasecmp(hostname_with_wildcard_sliced, hostname_sliced)==0){ + printf("\t\tWILDCARD FUNCTION\t\t%s == %s\n", hostname_with_wildcard_sliced, hostname_sliced); return 1; } + return 0; } int validate_key_length(int length){ @@ -449,3 +467,24 @@ int validate_certificate(const char *url, X509 *cert){ return 0; } } + +int find_first_instanceof(const char *str, char delim){ + int i; + for (i=0;i<=strlen(str);i++){ + if(str[i]==delim){ + + return i; + } + } + return -1; +} + + +char *str_slice_to_end(const char *str, int begin){ + char *tmp = (char *)str; + + tmp = (tmp+=begin+1); + + printf("\tSLICE: %s\n",tmp); + return tmp; +}