Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
comp30023-2018-project-2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Neeserg Parajuli
comp30023-2018-project-2
Commits
6c43a108
Commit
6c43a108
authored
May 23, 2018
by
Neeserg Parajuli
Browse files
Options
Downloads
Patches
Plain Diff
bits checker done
parent
6bb551b9
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.DS_Store
+0
-0
0 additions, 0 deletions
.DS_Store
certexample
+0
-0
0 additions, 0 deletions
certexample
certexample.c
+48
-5
48 additions, 5 deletions
certexample.c
helper_checker.c
+0
-26
0 additions, 26 deletions
helper_checker.c
with
48 additions
and
31 deletions
.DS_Store
0 → 100644
+
0
−
0
View file @
6c43a108
File added
This diff is collapsed.
Click to expand it.
certexample
+
0
−
0
View file @
6c43a108
No preview for this file type
This diff is collapsed.
Click to expand it.
certexample.c
+
48
−
5
View file @
6c43a108
...
...
@@ -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
This diff is collapsed.
Click to expand it.
helper_checker.c
+
0
−
26
View file @
6c43a108
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment