ssl_stat 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ext/ssl_stat/extconf.rb +8 -0
- data/ext/ssl_stat/ssl_stat.c +118 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7a132b261066eb74ec18e4bfefde74f8ef9c08c84c544a30e69b2a060578894c
|
4
|
+
data.tar.gz: cc823ae46ecb3e5cff6728a7a702cc653c2096ebf8f42a39126414cf078c3aaf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 360de91dfdd7d6973b6bfc3444047303d3db60fe63c49fc7031f01f25bcb2369d461cea4a3c787b0048a4bc17d39e25bbf940c027650eb858899f65ea2ed99f5
|
7
|
+
data.tar.gz: b4aba70a6b94cc356eea54eb9d5b06c857382568de7c36c0b42c3d972e96a9c8074395d7e76dca89b4798f7922c09ebc72e275015ced3960500d44d2eca952de
|
@@ -0,0 +1,118 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <stdlib.h>
|
4
|
+
#include <curl/curl.h>
|
5
|
+
#include <string.h>
|
6
|
+
|
7
|
+
char *get_second_part(char *str) {
|
8
|
+
char * token = strtok(str, ":");
|
9
|
+
token = strtok(NULL, ":");
|
10
|
+
return token;
|
11
|
+
}
|
12
|
+
|
13
|
+
char *get_datetime(char *str) {
|
14
|
+
char * retstr = (char *) malloc(30);
|
15
|
+
char * token = strtok(str, ":");
|
16
|
+
strcpy(retstr, "");
|
17
|
+
int ignore_first = 1;
|
18
|
+
while( token != NULL ) {
|
19
|
+
if (ignore_first) {
|
20
|
+
ignore_first = 0;
|
21
|
+
token = strtok(NULL, " ");
|
22
|
+
continue;
|
23
|
+
}
|
24
|
+
strcat(retstr, token);
|
25
|
+
strcat(retstr, " ");
|
26
|
+
token = strtok(NULL, " ");
|
27
|
+
}
|
28
|
+
return retstr;
|
29
|
+
}
|
30
|
+
|
31
|
+
static size_t wrfu(void *ptr, size_t size, size_t nmemb, void *stream) {
|
32
|
+
(void)stream;
|
33
|
+
(void)ptr;
|
34
|
+
return size * nmemb;
|
35
|
+
}
|
36
|
+
|
37
|
+
VALUE SSLStat = Qnil;
|
38
|
+
void Init_ssl_stat();
|
39
|
+
VALUE method_check(VALUE, VALUE);
|
40
|
+
|
41
|
+
void Init_ssl_stat(){
|
42
|
+
VALUE SSLStat = rb_define_module("SSLStat");
|
43
|
+
rb_define_method(SSLStat, "check", method_check, 1);
|
44
|
+
}
|
45
|
+
|
46
|
+
VALUE method_check(VALUE self, VALUE arg_url) {
|
47
|
+
char *url_to_check = StringValueCStr(arg_url);
|
48
|
+
|
49
|
+
CURL *curl;
|
50
|
+
CURLcode res;
|
51
|
+
|
52
|
+
curl_global_init(CURL_GLOBAL_DEFAULT);
|
53
|
+
|
54
|
+
curl = curl_easy_init();
|
55
|
+
if(curl) {
|
56
|
+
curl_easy_setopt(curl, CURLOPT_URL, url_to_check);
|
57
|
+
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wrfu);
|
58
|
+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
59
|
+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
60
|
+
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
|
61
|
+
curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L);
|
62
|
+
|
63
|
+
res = curl_easy_perform(curl);
|
64
|
+
|
65
|
+
if(!res) {
|
66
|
+
struct curl_certinfo *certinfo;
|
67
|
+
int need_break = 0;
|
68
|
+
char *serial_number, *expire_date, *start_date;
|
69
|
+
|
70
|
+
res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &certinfo);
|
71
|
+
|
72
|
+
if(!res && certinfo) {
|
73
|
+
int i;
|
74
|
+
|
75
|
+
for(i = 0; i < certinfo->num_of_certs; i++) {
|
76
|
+
struct curl_slist *slist;
|
77
|
+
|
78
|
+
for(slist = certinfo->certinfo[i]; slist; slist = slist->next) {
|
79
|
+
if (strstr(slist->data, "Serial Number:") != NULL) {
|
80
|
+
serial_number = get_second_part(slist->data);
|
81
|
+
}
|
82
|
+
|
83
|
+
if(strstr(slist->data, "Start date:") != NULL) {
|
84
|
+
start_date = get_datetime(slist->data);
|
85
|
+
}
|
86
|
+
|
87
|
+
if(strstr(slist->data, "Expire date:") != NULL) {
|
88
|
+
expire_date = get_datetime(slist->data);
|
89
|
+
}
|
90
|
+
if(strstr(slist->data, "Subject Alternative Name") != NULL) {
|
91
|
+
need_break = 1;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
if (need_break) {
|
96
|
+
VALUE hash = rb_hash_new();
|
97
|
+
|
98
|
+
rb_hash_aset(hash, rb_str_new2("serial_number"), rb_str_new_cstr(serial_number));
|
99
|
+
rb_hash_aset(hash, rb_str_new2("start_date"), rb_str_new_cstr(start_date));
|
100
|
+
rb_hash_aset(hash, rb_str_new2("expire_date"), rb_str_new_cstr(expire_date));
|
101
|
+
|
102
|
+
curl_easy_cleanup(curl);
|
103
|
+
curl_global_cleanup();
|
104
|
+
return hash;
|
105
|
+
}
|
106
|
+
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
}
|
111
|
+
|
112
|
+
curl_easy_cleanup(curl);
|
113
|
+
}
|
114
|
+
|
115
|
+
curl_global_cleanup();
|
116
|
+
|
117
|
+
return rb_hash_new();
|
118
|
+
}
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ssl_stat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ferdinand E. Silva
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ruby C Language Extension To Get SSL Certificate Information From URL
|
14
|
+
email: ferdinandsilva@ferdinandsilva.com
|
15
|
+
executables: []
|
16
|
+
extensions:
|
17
|
+
- ext/ssl_stat/extconf.rb
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ext/ssl_stat/extconf.rb
|
21
|
+
- ext/ssl_stat/ssl_stat.c
|
22
|
+
homepage: http://ferdinandsilva.com
|
23
|
+
licenses: []
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubygems_version: 3.1.2
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Ruby C Language Extension To Get SSL Certificate Information From URL
|
44
|
+
test_files: []
|