openssl 2.2.1 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +33 -45
- data/History.md +248 -1
- data/README.md +36 -19
- data/ext/openssl/extconf.rb +101 -68
- data/ext/openssl/openssl_missing.c +0 -66
- data/ext/openssl/openssl_missing.h +26 -45
- data/ext/openssl/ossl.c +128 -237
- data/ext/openssl/ossl.h +31 -12
- data/ext/openssl/ossl_asn1.c +26 -13
- data/ext/openssl/ossl_bn.c +213 -139
- data/ext/openssl/ossl_cipher.c +13 -14
- data/ext/openssl/ossl_config.c +412 -41
- data/ext/openssl/ossl_config.h +4 -7
- data/ext/openssl/ossl_digest.c +10 -10
- data/ext/openssl/ossl_engine.c +17 -16
- data/ext/openssl/ossl_hmac.c +57 -136
- data/ext/openssl/ossl_kdf.c +12 -4
- data/ext/openssl/ossl_ns_spki.c +1 -1
- data/ext/openssl/ossl_ocsp.c +11 -59
- data/ext/openssl/ossl_pkcs12.c +22 -4
- data/ext/openssl/ossl_pkcs7.c +45 -62
- data/ext/openssl/ossl_pkey.c +1320 -196
- data/ext/openssl/ossl_pkey.h +36 -73
- data/ext/openssl/ossl_pkey_dh.c +152 -347
- data/ext/openssl/ossl_pkey_dsa.c +157 -413
- data/ext/openssl/ossl_pkey_ec.c +227 -343
- data/ext/openssl/ossl_pkey_rsa.c +159 -491
- data/ext/openssl/ossl_provider.c +211 -0
- data/ext/openssl/ossl_provider.h +5 -0
- data/ext/openssl/ossl_ssl.c +530 -450
- data/ext/openssl/ossl_ssl_session.c +29 -30
- data/ext/openssl/ossl_ts.c +38 -23
- data/ext/openssl/ossl_x509.c +0 -6
- data/ext/openssl/ossl_x509attr.c +1 -1
- data/ext/openssl/ossl_x509cert.c +168 -12
- data/ext/openssl/ossl_x509crl.c +14 -11
- data/ext/openssl/ossl_x509ext.c +14 -9
- data/ext/openssl/ossl_x509name.c +10 -3
- data/ext/openssl/ossl_x509req.c +14 -11
- data/ext/openssl/ossl_x509revoked.c +4 -4
- data/ext/openssl/ossl_x509store.c +166 -75
- data/lib/openssl/buffering.rb +9 -3
- data/lib/openssl/digest.rb +1 -5
- data/lib/openssl/hmac.rb +65 -0
- data/lib/openssl/pkey.rb +429 -0
- data/lib/openssl/ssl.rb +22 -17
- data/lib/openssl/version.rb +1 -1
- data/lib/openssl/x509.rb +22 -0
- data/lib/openssl.rb +0 -1
- metadata +10 -79
- data/ext/openssl/ruby_missing.h +0 -24
- data/lib/openssl/config.rb +0 -501
@@ -0,0 +1,211 @@
|
|
1
|
+
/*
|
2
|
+
* This program is licensed under the same licence as Ruby.
|
3
|
+
* (See the file 'LICENCE'.)
|
4
|
+
*/
|
5
|
+
#include "ossl.h"
|
6
|
+
|
7
|
+
#ifdef OSSL_USE_PROVIDER
|
8
|
+
# include <openssl/provider.h>
|
9
|
+
|
10
|
+
#define NewProvider(klass) \
|
11
|
+
TypedData_Wrap_Struct((klass), &ossl_provider_type, 0)
|
12
|
+
#define SetProvider(obj, provider) do { \
|
13
|
+
if (!(provider)) { \
|
14
|
+
ossl_raise(rb_eRuntimeError, "Provider wasn't initialized."); \
|
15
|
+
} \
|
16
|
+
RTYPEDDATA_DATA(obj) = (provider); \
|
17
|
+
} while(0)
|
18
|
+
#define GetProvider(obj, provider) do { \
|
19
|
+
TypedData_Get_Struct((obj), OSSL_PROVIDER, &ossl_provider_type, (provider)); \
|
20
|
+
if (!(provider)) { \
|
21
|
+
ossl_raise(rb_eRuntimeError, "PROVIDER wasn't initialized."); \
|
22
|
+
} \
|
23
|
+
} while (0)
|
24
|
+
|
25
|
+
static const rb_data_type_t ossl_provider_type = {
|
26
|
+
"OpenSSL/Provider",
|
27
|
+
{
|
28
|
+
0,
|
29
|
+
},
|
30
|
+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
31
|
+
};
|
32
|
+
|
33
|
+
/*
|
34
|
+
* Classes
|
35
|
+
*/
|
36
|
+
/* Document-class: OpenSSL::Provider
|
37
|
+
*
|
38
|
+
* This class is the access to openssl's Provider
|
39
|
+
* See also, https://www.openssl.org/docs/manmaster/man7/provider.html
|
40
|
+
*/
|
41
|
+
static VALUE cProvider;
|
42
|
+
/* Document-class: OpenSSL::Provider::ProviderError
|
43
|
+
*
|
44
|
+
* This is the generic exception for OpenSSL::Provider related errors
|
45
|
+
*/
|
46
|
+
static VALUE eProviderError;
|
47
|
+
|
48
|
+
/*
|
49
|
+
* call-seq:
|
50
|
+
* OpenSSL::Provider.load(name) -> provider
|
51
|
+
*
|
52
|
+
* This method loads and initializes a provider
|
53
|
+
*/
|
54
|
+
static VALUE
|
55
|
+
ossl_provider_s_load(VALUE klass, VALUE name)
|
56
|
+
{
|
57
|
+
OSSL_PROVIDER *provider = NULL;
|
58
|
+
VALUE obj;
|
59
|
+
|
60
|
+
const char *provider_name_ptr = StringValueCStr(name);
|
61
|
+
|
62
|
+
provider = OSSL_PROVIDER_load(NULL, provider_name_ptr);
|
63
|
+
if (provider == NULL) {
|
64
|
+
ossl_raise(eProviderError, "Failed to load %s provider", provider_name_ptr);
|
65
|
+
}
|
66
|
+
obj = NewProvider(klass);
|
67
|
+
SetProvider(obj, provider);
|
68
|
+
|
69
|
+
return obj;
|
70
|
+
}
|
71
|
+
|
72
|
+
struct ary_with_state { VALUE ary; int state; };
|
73
|
+
struct rb_push_provider_name_args { OSSL_PROVIDER *prov; VALUE ary; };
|
74
|
+
|
75
|
+
static VALUE
|
76
|
+
rb_push_provider_name(VALUE rb_push_provider_name_args)
|
77
|
+
{
|
78
|
+
struct rb_push_provider_name_args *args = (struct rb_push_provider_name_args *)rb_push_provider_name_args;
|
79
|
+
|
80
|
+
VALUE name = rb_str_new2(OSSL_PROVIDER_get0_name(args->prov));
|
81
|
+
return rb_ary_push(args->ary, name);
|
82
|
+
}
|
83
|
+
|
84
|
+
static int
|
85
|
+
push_provider(OSSL_PROVIDER *prov, void *cbdata)
|
86
|
+
{
|
87
|
+
struct ary_with_state *ary_with_state = (struct ary_with_state *)cbdata;
|
88
|
+
struct rb_push_provider_name_args args = { prov, ary_with_state->ary };
|
89
|
+
|
90
|
+
rb_protect(rb_push_provider_name, (VALUE)&args, &ary_with_state->state);
|
91
|
+
if (ary_with_state->state) {
|
92
|
+
return 0;
|
93
|
+
} else {
|
94
|
+
return 1;
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
/*
|
99
|
+
* call-seq:
|
100
|
+
* OpenSSL::Provider.provider_names -> [provider_name, ...]
|
101
|
+
*
|
102
|
+
* Returns an array of currently loaded provider names.
|
103
|
+
*/
|
104
|
+
static VALUE
|
105
|
+
ossl_provider_s_provider_names(VALUE klass)
|
106
|
+
{
|
107
|
+
VALUE ary = rb_ary_new();
|
108
|
+
struct ary_with_state cbdata = { ary, 0 };
|
109
|
+
|
110
|
+
int result = OSSL_PROVIDER_do_all(NULL, &push_provider, (void*)&cbdata);
|
111
|
+
if (result != 1 ) {
|
112
|
+
if (cbdata.state) {
|
113
|
+
rb_jump_tag(cbdata.state);
|
114
|
+
} else {
|
115
|
+
ossl_raise(eProviderError, "Failed to load provider names");
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
return ary;
|
120
|
+
}
|
121
|
+
|
122
|
+
/*
|
123
|
+
* call-seq:
|
124
|
+
* provider.unload -> true
|
125
|
+
*
|
126
|
+
* This method unloads this provider.
|
127
|
+
*
|
128
|
+
* if provider unload fails or already unloaded, it raises OpenSSL::Provider::ProviderError
|
129
|
+
*/
|
130
|
+
static VALUE
|
131
|
+
ossl_provider_unload(VALUE self)
|
132
|
+
{
|
133
|
+
OSSL_PROVIDER *prov;
|
134
|
+
if (RTYPEDDATA_DATA(self) == NULL) {
|
135
|
+
ossl_raise(eProviderError, "Provider already unloaded.");
|
136
|
+
}
|
137
|
+
GetProvider(self, prov);
|
138
|
+
|
139
|
+
int result = OSSL_PROVIDER_unload(prov);
|
140
|
+
|
141
|
+
if (result != 1) {
|
142
|
+
ossl_raise(eProviderError, "Failed to unload provider");
|
143
|
+
}
|
144
|
+
RTYPEDDATA_DATA(self) = NULL;
|
145
|
+
return Qtrue;
|
146
|
+
}
|
147
|
+
|
148
|
+
/*
|
149
|
+
* call-seq:
|
150
|
+
* provider.name -> string
|
151
|
+
*
|
152
|
+
* Get the name of this provider.
|
153
|
+
*
|
154
|
+
* if this provider is already unloaded, it raises OpenSSL::Provider::ProviderError
|
155
|
+
*/
|
156
|
+
static VALUE
|
157
|
+
ossl_provider_get_name(VALUE self)
|
158
|
+
{
|
159
|
+
OSSL_PROVIDER *prov;
|
160
|
+
if (RTYPEDDATA_DATA(self) == NULL) {
|
161
|
+
ossl_raise(eProviderError, "Provider already unloaded.");
|
162
|
+
}
|
163
|
+
GetProvider(self, prov);
|
164
|
+
|
165
|
+
return rb_str_new2(OSSL_PROVIDER_get0_name(prov));
|
166
|
+
}
|
167
|
+
|
168
|
+
/*
|
169
|
+
* call-seq:
|
170
|
+
* provider.inspect -> string
|
171
|
+
*
|
172
|
+
* Pretty prints this provider.
|
173
|
+
*/
|
174
|
+
static VALUE
|
175
|
+
ossl_provider_inspect(VALUE self)
|
176
|
+
{
|
177
|
+
OSSL_PROVIDER *prov;
|
178
|
+
if (RTYPEDDATA_DATA(self) == NULL ) {
|
179
|
+
return rb_sprintf("#<%"PRIsVALUE" unloaded provider>", rb_obj_class(self));
|
180
|
+
}
|
181
|
+
GetProvider(self, prov);
|
182
|
+
|
183
|
+
return rb_sprintf("#<%"PRIsVALUE" name=\"%s\">",
|
184
|
+
rb_obj_class(self), OSSL_PROVIDER_get0_name(prov));
|
185
|
+
}
|
186
|
+
|
187
|
+
void
|
188
|
+
Init_ossl_provider(void)
|
189
|
+
{
|
190
|
+
#if 0
|
191
|
+
mOSSL = rb_define_module("OpenSSL");
|
192
|
+
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
193
|
+
#endif
|
194
|
+
|
195
|
+
cProvider = rb_define_class_under(mOSSL, "Provider", rb_cObject);
|
196
|
+
eProviderError = rb_define_class_under(cProvider, "ProviderError", eOSSLError);
|
197
|
+
|
198
|
+
rb_undef_alloc_func(cProvider);
|
199
|
+
rb_define_singleton_method(cProvider, "load", ossl_provider_s_load, 1);
|
200
|
+
rb_define_singleton_method(cProvider, "provider_names", ossl_provider_s_provider_names, 0);
|
201
|
+
|
202
|
+
rb_define_method(cProvider, "unload", ossl_provider_unload, 0);
|
203
|
+
rb_define_method(cProvider, "name", ossl_provider_get_name, 0);
|
204
|
+
rb_define_method(cProvider, "inspect", ossl_provider_inspect, 0);
|
205
|
+
}
|
206
|
+
#else
|
207
|
+
void
|
208
|
+
Init_ossl_provider(void)
|
209
|
+
{
|
210
|
+
}
|
211
|
+
#endif
|