diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d5e0a6428dc8765cd85a6dbeeffa32ba01fd23f1 Binary files /dev/null and b/.DS_Store differ diff --git a/certexample b/certexample index 7c7b8043af04b11a7e9263c9c231912791aca2dd..846f93a4a6f291f1bcb633c3917453db801a64b4 100755 Binary files a/certexample and b/certexample differ diff --git a/certexample.c b/certexample.c index ab97ebb2db2d9288711131c19a21035157b4f3e3..fdda0bfba537bc82b0557c9ed5b9bf36165e8180 100644 --- a/certexample.c +++ b/certexample.c @@ -7,6 +7,8 @@ #include <openssl/bio.h> #include <openssl/pem.h> #include <openssl/err.h> +#include <openssl/rsa.h> +#include <openssl/evp.h> #include <stdio.h> #include <string.h> @@ -15,14 +17,14 @@ int check_san_valid(X509* cert, char* URL, int in_host); int check_if_url_valid(char* URL, char* domain); int check_name_valid(X509* cert, char* URL); void printTime(X509* cert); - +int check_public_key(X509 *cert); int main() { char* URL = "mega.google.com"; - const char test_cert_example[] = "./cert-file2.pem"; + const char test_cert_example[] = "./sample_certs/testtwo.crt"; BIO *certificate_bio = NULL; X509 *cert = NULL; X509_CINF *cert_inf = NULL; @@ -64,6 +66,7 @@ int main() } printTime(cert); + check_public_key(cert); //********************* // End of Example code @@ -78,7 +81,14 @@ int main() void printTime(X509* cert){ ASN1_TIME *after = X509_get_notBefore(cert); - printf("%s\n", after->data); + + int day; + int sec; + + ASN1_TIME_diff(&day, &sec, after, NULL); + + printf("%d -- %d\n", day, sec); + BUF_MEM *bptr = NULL; char *buf = NULL; @@ -100,6 +110,17 @@ void printTime(X509* cert){ BIO_free_all(bio); free(buf); + + ASN1_TIME *tm; + time_t t; + BIO *b; + t = time(NULL); + tm = ASN1_TIME_adj(NULL, t, 0, 0); + b = BIO_new_fp(stdout, BIO_NOCLOSE); + ASN1_TIME_print(b, tm); + ASN1_STRING_free(tm); + BIO_free(b); + } int check_name_valid(X509* cert, char* URL){ @@ -119,9 +140,13 @@ int check_san_valid(X509* cert, char* URL, int in_host){ return 1; } X509_EXTENSION *ex = X509_get_ext(cert, X509_get_ext_by_NID(cert, NID_subject_alt_name, -1)); + if (ex == NULL) + { + return 0; + } ASN1_OBJECT *obj = X509_EXTENSION_get_object(ex); - char buff[1024]; - OBJ_obj2txt(buff, 1024, obj, 0); + char buff[2048]; + OBJ_obj2txt(buff, 2048, obj, 0); printf("Extension:%s\n", buff); BUF_MEM *bptr = NULL; @@ -189,4 +214,22 @@ else return 0; +} + + + + +int check_public_key(X509 *cert){ + EVP_PKEY *key = X509_get_pubkey(cert); + RSA *rsa = NULL; + + if ((rsa = EVP_PKEY_get1_RSA(key)) == NULL) + { + return 0; + } + if(8*RSA_size(rsa)==2048){ + return 1; + } + + return 1; } \ No newline at end of file diff --git a/helper_checker.c b/helper_checker.c index af8b66cecae981631a9734675b233e235e9a54c4..a9d6b9834fb37d894a732906a1a548c3d78c72c4 100644 --- a/helper_checker.c +++ b/helper_checker.c @@ -12,29 +12,3 @@ int main(int argc, char const *argv[]) return 0; } -int check_if_url_valid(char* URL, char* domain){ -if (domain[0] == '*'){ - char* domain_1 = domain+1; - char *sub_url = strstr(URL, domain_1); - - if (sub_url == NULL) - { - return 0; - } - - else{ - return (strcmp(sub_url, domain_1) == 0); - } - -} -else -{ - return (strcmp(URL, domain) == 0); - - -} - -return 0; - - -} \ No newline at end of file