Skip to content
Snippets Groups Projects
Commit 6c43a108 authored by Neeserg Parajuli's avatar Neeserg Parajuli
Browse files

bits checker done

parent 6bb551b9
No related branches found
No related tags found
No related merge requests found
.DS_Store 0 → 100644
File added
No preview for this file type
......@@ -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;
......@@ -190,3 +215,21 @@ 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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment