openssl 3.3.2 → 4.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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +3 -0
  3. data/History.md +85 -0
  4. data/README.md +12 -11
  5. data/ext/openssl/extconf.rb +30 -69
  6. data/ext/openssl/openssl_missing.h +0 -206
  7. data/ext/openssl/ossl.c +280 -301
  8. data/ext/openssl/ossl.h +15 -10
  9. data/ext/openssl/ossl_asn1.c +598 -406
  10. data/ext/openssl/ossl_asn1.h +15 -1
  11. data/ext/openssl/ossl_bio.c +3 -3
  12. data/ext/openssl/ossl_bn.c +286 -291
  13. data/ext/openssl/ossl_cipher.c +252 -203
  14. data/ext/openssl/ossl_cipher.h +10 -1
  15. data/ext/openssl/ossl_config.c +1 -6
  16. data/ext/openssl/ossl_digest.c +74 -43
  17. data/ext/openssl/ossl_digest.h +9 -1
  18. data/ext/openssl/ossl_engine.c +39 -103
  19. data/ext/openssl/ossl_hmac.c +30 -36
  20. data/ext/openssl/ossl_kdf.c +42 -53
  21. data/ext/openssl/ossl_ns_spki.c +31 -37
  22. data/ext/openssl/ossl_ocsp.c +214 -241
  23. data/ext/openssl/ossl_pkcs12.c +26 -26
  24. data/ext/openssl/ossl_pkcs7.c +175 -145
  25. data/ext/openssl/ossl_pkey.c +162 -178
  26. data/ext/openssl/ossl_pkey.h +99 -99
  27. data/ext/openssl/ossl_pkey_dh.c +31 -68
  28. data/ext/openssl/ossl_pkey_dsa.c +15 -54
  29. data/ext/openssl/ossl_pkey_ec.c +179 -237
  30. data/ext/openssl/ossl_pkey_rsa.c +56 -103
  31. data/ext/openssl/ossl_provider.c +0 -7
  32. data/ext/openssl/ossl_rand.c +7 -14
  33. data/ext/openssl/ossl_ssl.c +478 -353
  34. data/ext/openssl/ossl_ssl.h +8 -8
  35. data/ext/openssl/ossl_ssl_session.c +93 -97
  36. data/ext/openssl/ossl_ts.c +81 -127
  37. data/ext/openssl/ossl_x509.c +9 -28
  38. data/ext/openssl/ossl_x509attr.c +33 -54
  39. data/ext/openssl/ossl_x509cert.c +69 -100
  40. data/ext/openssl/ossl_x509crl.c +78 -89
  41. data/ext/openssl/ossl_x509ext.c +45 -66
  42. data/ext/openssl/ossl_x509name.c +63 -88
  43. data/ext/openssl/ossl_x509req.c +55 -62
  44. data/ext/openssl/ossl_x509revoked.c +27 -41
  45. data/ext/openssl/ossl_x509store.c +38 -56
  46. data/lib/openssl/buffering.rb +30 -24
  47. data/lib/openssl/digest.rb +1 -1
  48. data/lib/openssl/pkey.rb +71 -49
  49. data/lib/openssl/ssl.rb +12 -79
  50. data/lib/openssl/version.rb +2 -1
  51. data/lib/openssl/x509.rb +9 -0
  52. data/lib/openssl.rb +9 -6
  53. metadata +1 -3
  54. data/ext/openssl/openssl_missing.c +0 -40
  55. data/lib/openssl/asn1.rb +0 -188
@@ -14,7 +14,7 @@
14
14
  #define GetHMAC(obj, ctx) do { \
15
15
  TypedData_Get_Struct((obj), EVP_MD_CTX, &ossl_hmac_type, (ctx)); \
16
16
  if (!(ctx)) { \
17
- ossl_raise(rb_eRuntimeError, "HMAC wasn't initialized"); \
17
+ ossl_raise(rb_eRuntimeError, "HMAC wasn't initialized"); \
18
18
  } \
19
19
  } while (0)
20
20
 
@@ -23,6 +23,7 @@
23
23
  */
24
24
  static VALUE cHMAC;
25
25
  static VALUE eHMACError;
26
+ static ID id_md_holder;
26
27
 
27
28
  /*
28
29
  * Public
@@ -40,7 +41,7 @@ ossl_hmac_free(void *ctx)
40
41
  static const rb_data_type_t ossl_hmac_type = {
41
42
  "OpenSSL/HMAC",
42
43
  {
43
- 0, ossl_hmac_free,
44
+ 0, ossl_hmac_free,
44
45
  },
45
46
  0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
46
47
  };
@@ -73,17 +74,17 @@ ossl_hmac_alloc(VALUE klass)
73
74
  *
74
75
  * === Example
75
76
  *
76
- * key = 'key'
77
- * instance = OpenSSL::HMAC.new(key, 'SHA1')
78
- * #=> f42bb0eeb018ebbd4597ae7213711ec60760843f
79
- * instance.class
80
- * #=> OpenSSL::HMAC
77
+ * key = 'key'
78
+ * instance = OpenSSL::HMAC.new(key, 'SHA1')
79
+ * #=> f42bb0eeb018ebbd4597ae7213711ec60760843f
80
+ * instance.class
81
+ * #=> OpenSSL::HMAC
81
82
  *
82
83
  * === A note about comparisons
83
84
  *
84
85
  * Two instances can be securely compared with #== in constant time:
85
86
  *
86
- * other_instance = OpenSSL::HMAC.new('key', 'SHA1')
87
+ * other_instance = OpenSSL::HMAC.new('key', 'SHA1')
87
88
  * #=> f42bb0eeb018ebbd4597ae7213711ec60760843f
88
89
  * instance == other_instance
89
90
  * #=> true
@@ -94,33 +95,29 @@ ossl_hmac_initialize(VALUE self, VALUE key, VALUE digest)
94
95
  {
95
96
  EVP_MD_CTX *ctx;
96
97
  EVP_PKEY *pkey;
98
+ const EVP_MD *md;
99
+ VALUE md_holder;
97
100
 
98
101
  GetHMAC(self, ctx);
99
102
  StringValue(key);
100
- #ifdef HAVE_EVP_PKEY_NEW_RAW_PRIVATE_KEY
103
+ md = ossl_evp_md_fetch(digest, &md_holder);
101
104
  pkey = EVP_PKEY_new_raw_private_key(EVP_PKEY_HMAC, NULL,
102
105
  (unsigned char *)RSTRING_PTR(key),
103
106
  RSTRING_LENINT(key));
104
107
  if (!pkey)
105
108
  ossl_raise(eHMACError, "EVP_PKEY_new_raw_private_key");
106
- #else
107
- pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL,
108
- (unsigned char *)RSTRING_PTR(key),
109
- RSTRING_LENINT(key));
110
- if (!pkey)
111
- ossl_raise(eHMACError, "EVP_PKEY_new_mac_key");
112
- #endif
113
- if (EVP_DigestSignInit(ctx, NULL, ossl_evp_get_digestbyname(digest),
114
- NULL, pkey) != 1) {
109
+ if (EVP_DigestSignInit(ctx, NULL, md, NULL, pkey) != 1) {
115
110
  EVP_PKEY_free(pkey);
116
111
  ossl_raise(eHMACError, "EVP_DigestSignInit");
117
112
  }
113
+ rb_ivar_set(self, id_md_holder, md_holder);
118
114
  /* Decrement reference counter; EVP_MD_CTX still keeps it */
119
115
  EVP_PKEY_free(pkey);
120
116
 
121
117
  return self;
122
118
  }
123
119
 
120
+ /* :nodoc: */
124
121
  static VALUE
125
122
  ossl_hmac_copy(VALUE self, VALUE other)
126
123
  {
@@ -145,13 +142,13 @@ ossl_hmac_copy(VALUE self, VALUE other)
145
142
  *
146
143
  * === Example
147
144
  *
148
- * first_chunk = 'The quick brown fox jumps '
149
- * second_chunk = 'over the lazy dog'
145
+ * first_chunk = 'The quick brown fox jumps '
146
+ * second_chunk = 'over the lazy dog'
150
147
  *
151
- * instance.update(first_chunk)
152
- * #=> 5b9a8038a65d571076d97fe783989e52278a492a
153
- * instance.update(second_chunk)
154
- * #=> de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9
148
+ * instance.update(first_chunk)
149
+ * #=> 5b9a8038a65d571076d97fe783989e52278a492a
150
+ * instance.update(second_chunk)
151
+ * #=> de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9
155
152
  *
156
153
  */
157
154
  static VALUE
@@ -229,14 +226,14 @@ ossl_hmac_hexdigest(VALUE self)
229
226
  *
230
227
  * === Example
231
228
  *
232
- * data = "The quick brown fox jumps over the lazy dog"
233
- * instance = OpenSSL::HMAC.new('key', 'SHA1')
234
- * #=> f42bb0eeb018ebbd4597ae7213711ec60760843f
229
+ * data = "The quick brown fox jumps over the lazy dog"
230
+ * instance = OpenSSL::HMAC.new('key', 'SHA1')
231
+ * #=> f42bb0eeb018ebbd4597ae7213711ec60760843f
235
232
  *
236
- * instance.update(data)
237
- * #=> de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9
238
- * instance.reset
239
- * #=> f42bb0eeb018ebbd4597ae7213711ec60760843f
233
+ * instance.update(data)
234
+ * #=> de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9
235
+ * instance.reset
236
+ * #=> f42bb0eeb018ebbd4597ae7213711ec60760843f
240
237
  *
241
238
  */
242
239
  static VALUE
@@ -259,11 +256,6 @@ ossl_hmac_reset(VALUE self)
259
256
  void
260
257
  Init_ossl_hmac(void)
261
258
  {
262
- #if 0
263
- mOSSL = rb_define_module("OpenSSL");
264
- eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
265
- #endif
266
-
267
259
  /*
268
260
  * Document-class: OpenSSL::HMAC
269
261
  *
@@ -307,4 +299,6 @@ Init_ossl_hmac(void)
307
299
  rb_define_method(cHMAC, "hexdigest", ossl_hmac_hexdigest, 0);
308
300
  rb_define_alias(cHMAC, "inspect", "hexdigest");
309
301
  rb_define_alias(cHMAC, "to_s", "hexdigest");
302
+
303
+ id_md_holder = rb_intern_const("EVP_MD_holder");
310
304
  }
@@ -3,9 +3,7 @@
3
3
  * Copyright (C) 2007, 2017 Ruby/OpenSSL Project Authors
4
4
  */
5
5
  #include "ossl.h"
6
- #if OSSL_OPENSSL_PREREQ(1, 1, 0) || OSSL_LIBRESSL_PREREQ(3, 6, 0)
7
- # include <openssl/kdf.h>
8
- #endif
6
+ #include <openssl/kdf.h>
9
7
 
10
8
  static VALUE mKDF, eKDF;
11
9
 
@@ -37,16 +35,16 @@ static VALUE mKDF, eKDF;
37
35
  static VALUE
38
36
  kdf_pbkdf2_hmac(int argc, VALUE *argv, VALUE self)
39
37
  {
40
- VALUE pass, salt, opts, kwargs[4], str;
38
+ VALUE pass, salt, opts, kwargs[4], str, md_holder;
41
39
  static ID kwargs_ids[4];
42
40
  int iters, len;
43
41
  const EVP_MD *md;
44
42
 
45
43
  if (!kwargs_ids[0]) {
46
- kwargs_ids[0] = rb_intern_const("salt");
47
- kwargs_ids[1] = rb_intern_const("iterations");
48
- kwargs_ids[2] = rb_intern_const("length");
49
- kwargs_ids[3] = rb_intern_const("hash");
44
+ kwargs_ids[0] = rb_intern_const("salt");
45
+ kwargs_ids[1] = rb_intern_const("iterations");
46
+ kwargs_ids[2] = rb_intern_const("length");
47
+ kwargs_ids[3] = rb_intern_const("hash");
50
48
  }
51
49
  rb_scan_args(argc, argv, "1:", &pass, &opts);
52
50
  rb_get_kwargs(opts, kwargs_ids, 4, 0, kwargs);
@@ -55,14 +53,14 @@ kdf_pbkdf2_hmac(int argc, VALUE *argv, VALUE self)
55
53
  salt = StringValue(kwargs[0]);
56
54
  iters = NUM2INT(kwargs[1]);
57
55
  len = NUM2INT(kwargs[2]);
58
- md = ossl_evp_get_digestbyname(kwargs[3]);
56
+ md = ossl_evp_md_fetch(kwargs[3], &md_holder);
59
57
 
60
58
  str = rb_str_new(0, len);
61
59
  if (!PKCS5_PBKDF2_HMAC(RSTRING_PTR(pass), RSTRING_LENINT(pass),
62
- (unsigned char *)RSTRING_PTR(salt),
63
- RSTRING_LENINT(salt), iters, md, len,
64
- (unsigned char *)RSTRING_PTR(str)))
65
- ossl_raise(eKDF, "PKCS5_PBKDF2_HMAC");
60
+ (unsigned char *)RSTRING_PTR(salt),
61
+ RSTRING_LENINT(salt), iters, md, len,
62
+ (unsigned char *)RSTRING_PTR(str)))
63
+ ossl_raise(eKDF, "PKCS5_PBKDF2_HMAC");
66
64
 
67
65
  return str;
68
66
  }
@@ -109,11 +107,11 @@ kdf_scrypt(int argc, VALUE *argv, VALUE self)
109
107
  uint64_t N, r, p, maxmem;
110
108
 
111
109
  if (!kwargs_ids[0]) {
112
- kwargs_ids[0] = rb_intern_const("salt");
113
- kwargs_ids[1] = rb_intern_const("N");
114
- kwargs_ids[2] = rb_intern_const("r");
115
- kwargs_ids[3] = rb_intern_const("p");
116
- kwargs_ids[4] = rb_intern_const("length");
110
+ kwargs_ids[0] = rb_intern_const("salt");
111
+ kwargs_ids[1] = rb_intern_const("N");
112
+ kwargs_ids[2] = rb_intern_const("r");
113
+ kwargs_ids[3] = rb_intern_const("p");
114
+ kwargs_ids[4] = rb_intern_const("length");
117
115
  }
118
116
  rb_scan_args(argc, argv, "1:", &pass, &opts);
119
117
  rb_get_kwargs(opts, kwargs_ids, 5, 0, kwargs);
@@ -133,15 +131,14 @@ kdf_scrypt(int argc, VALUE *argv, VALUE self)
133
131
 
134
132
  str = rb_str_new(0, len);
135
133
  if (!EVP_PBE_scrypt(RSTRING_PTR(pass), RSTRING_LEN(pass),
136
- (unsigned char *)RSTRING_PTR(salt), RSTRING_LEN(salt),
137
- N, r, p, maxmem, (unsigned char *)RSTRING_PTR(str), len))
138
- ossl_raise(eKDF, "EVP_PBE_scrypt");
134
+ (unsigned char *)RSTRING_PTR(salt), RSTRING_LEN(salt),
135
+ N, r, p, maxmem, (unsigned char *)RSTRING_PTR(str), len))
136
+ ossl_raise(eKDF, "EVP_PBE_scrypt");
139
137
 
140
138
  return str;
141
139
  }
142
140
  #endif
143
141
 
144
- #if OSSL_OPENSSL_PREREQ(1, 1, 0) || OSSL_LIBRESSL_PREREQ(3, 6, 0)
145
142
  /*
146
143
  * call-seq:
147
144
  * KDF.hkdf(ikm, salt:, info:, length:, hash:) -> String
@@ -175,7 +172,7 @@ kdf_scrypt(int argc, VALUE *argv, VALUE self)
175
172
  static VALUE
176
173
  kdf_hkdf(int argc, VALUE *argv, VALUE self)
177
174
  {
178
- VALUE ikm, salt, info, opts, kwargs[4], str;
175
+ VALUE ikm, salt, info, opts, kwargs[4], str, md_holder;
179
176
  static ID kwargs_ids[4];
180
177
  int saltlen, ikmlen, infolen;
181
178
  size_t len;
@@ -183,10 +180,10 @@ kdf_hkdf(int argc, VALUE *argv, VALUE self)
183
180
  EVP_PKEY_CTX *pctx;
184
181
 
185
182
  if (!kwargs_ids[0]) {
186
- kwargs_ids[0] = rb_intern_const("salt");
187
- kwargs_ids[1] = rb_intern_const("info");
188
- kwargs_ids[2] = rb_intern_const("length");
189
- kwargs_ids[3] = rb_intern_const("hash");
183
+ kwargs_ids[0] = rb_intern_const("salt");
184
+ kwargs_ids[1] = rb_intern_const("info");
185
+ kwargs_ids[2] = rb_intern_const("length");
186
+ kwargs_ids[3] = rb_intern_const("hash");
190
187
  }
191
188
  rb_scan_args(argc, argv, "1:", &ikm, &opts);
192
189
  rb_get_kwargs(opts, kwargs_ids, 4, 0, kwargs);
@@ -199,55 +196,49 @@ kdf_hkdf(int argc, VALUE *argv, VALUE self)
199
196
  infolen = RSTRING_LENINT(info);
200
197
  len = (size_t)NUM2LONG(kwargs[2]);
201
198
  if (len > LONG_MAX)
202
- rb_raise(rb_eArgError, "length must be non-negative");
203
- md = ossl_evp_get_digestbyname(kwargs[3]);
199
+ rb_raise(rb_eArgError, "length must be non-negative");
200
+ md = ossl_evp_md_fetch(kwargs[3], &md_holder);
204
201
 
205
202
  str = rb_str_new(NULL, (long)len);
206
203
  pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL);
207
204
  if (!pctx)
208
- ossl_raise(eKDF, "EVP_PKEY_CTX_new_id");
205
+ ossl_raise(eKDF, "EVP_PKEY_CTX_new_id");
209
206
  if (EVP_PKEY_derive_init(pctx) <= 0) {
210
- EVP_PKEY_CTX_free(pctx);
211
- ossl_raise(eKDF, "EVP_PKEY_derive_init");
207
+ EVP_PKEY_CTX_free(pctx);
208
+ ossl_raise(eKDF, "EVP_PKEY_derive_init");
212
209
  }
213
210
  if (EVP_PKEY_CTX_set_hkdf_md(pctx, md) <= 0) {
214
- EVP_PKEY_CTX_free(pctx);
215
- ossl_raise(eKDF, "EVP_PKEY_CTX_set_hkdf_md");
211
+ EVP_PKEY_CTX_free(pctx);
212
+ ossl_raise(eKDF, "EVP_PKEY_CTX_set_hkdf_md");
216
213
  }
217
214
  if (EVP_PKEY_CTX_set1_hkdf_salt(pctx, (unsigned char *)RSTRING_PTR(salt),
218
- saltlen) <= 0) {
219
- EVP_PKEY_CTX_free(pctx);
220
- ossl_raise(eKDF, "EVP_PKEY_CTX_set_hkdf_salt");
215
+ saltlen) <= 0) {
216
+ EVP_PKEY_CTX_free(pctx);
217
+ ossl_raise(eKDF, "EVP_PKEY_CTX_set_hkdf_salt");
221
218
  }
222
219
  if (EVP_PKEY_CTX_set1_hkdf_key(pctx, (unsigned char *)RSTRING_PTR(ikm),
223
- ikmlen) <= 0) {
224
- EVP_PKEY_CTX_free(pctx);
225
- ossl_raise(eKDF, "EVP_PKEY_CTX_set_hkdf_key");
220
+ ikmlen) <= 0) {
221
+ EVP_PKEY_CTX_free(pctx);
222
+ ossl_raise(eKDF, "EVP_PKEY_CTX_set_hkdf_key");
226
223
  }
227
224
  if (EVP_PKEY_CTX_add1_hkdf_info(pctx, (unsigned char *)RSTRING_PTR(info),
228
- infolen) <= 0) {
229
- EVP_PKEY_CTX_free(pctx);
230
- ossl_raise(eKDF, "EVP_PKEY_CTX_set_hkdf_info");
225
+ infolen) <= 0) {
226
+ EVP_PKEY_CTX_free(pctx);
227
+ ossl_raise(eKDF, "EVP_PKEY_CTX_set_hkdf_info");
231
228
  }
232
229
  if (EVP_PKEY_derive(pctx, (unsigned char *)RSTRING_PTR(str), &len) <= 0) {
233
- EVP_PKEY_CTX_free(pctx);
234
- ossl_raise(eKDF, "EVP_PKEY_derive");
230
+ EVP_PKEY_CTX_free(pctx);
231
+ ossl_raise(eKDF, "EVP_PKEY_derive");
235
232
  }
236
233
  rb_str_set_len(str, (long)len);
237
234
  EVP_PKEY_CTX_free(pctx);
238
235
 
239
236
  return str;
240
237
  }
241
- #endif
242
238
 
243
239
  void
244
240
  Init_ossl_kdf(void)
245
241
  {
246
- #if 0
247
- mOSSL = rb_define_module("OpenSSL");
248
- eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
249
- #endif
250
-
251
242
  /*
252
243
  * Document-module: OpenSSL::KDF
253
244
  *
@@ -305,7 +296,5 @@ Init_ossl_kdf(void)
305
296
  #if defined(HAVE_EVP_PBE_SCRYPT)
306
297
  rb_define_module_function(mKDF, "scrypt", kdf_scrypt, -1);
307
298
  #endif
308
- #if OSSL_OPENSSL_PREREQ(1, 1, 0) || OSSL_LIBRESSL_PREREQ(3, 6, 0)
309
299
  rb_define_module_function(mKDF, "hkdf", kdf_hkdf, -1);
310
- #endif
311
300
  }
@@ -13,14 +13,14 @@
13
13
  TypedData_Wrap_Struct((klass), &ossl_netscape_spki_type, 0)
14
14
  #define SetSPKI(obj, spki) do { \
15
15
  if (!(spki)) { \
16
- ossl_raise(rb_eRuntimeError, "SPKI wasn't initialized!"); \
16
+ ossl_raise(rb_eRuntimeError, "SPKI wasn't initialized!"); \
17
17
  } \
18
18
  RTYPEDDATA_DATA(obj) = (spki); \
19
19
  } while (0)
20
20
  #define GetSPKI(obj, spki) do { \
21
21
  TypedData_Get_Struct((obj), NETSCAPE_SPKI, &ossl_netscape_spki_type, (spki)); \
22
22
  if (!(spki)) { \
23
- ossl_raise(rb_eRuntimeError, "SPKI wasn't initialized!"); \
23
+ ossl_raise(rb_eRuntimeError, "SPKI wasn't initialized!"); \
24
24
  } \
25
25
  } while (0)
26
26
 
@@ -48,7 +48,7 @@ ossl_netscape_spki_free(void *spki)
48
48
  static const rb_data_type_t ossl_netscape_spki_type = {
49
49
  "OpenSSL/NETSCAPE_SPKI",
50
50
  {
51
- 0, ossl_netscape_spki_free,
51
+ 0, ossl_netscape_spki_free,
52
52
  },
53
53
  0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
54
54
  };
@@ -61,7 +61,7 @@ ossl_spki_alloc(VALUE klass)
61
61
 
62
62
  obj = NewSPKI(klass);
63
63
  if (!(spki = NETSCAPE_SPKI_new())) {
64
- ossl_raise(eSPKIError, NULL);
64
+ ossl_raise(eSPKIError, NULL);
65
65
  }
66
66
  SetSPKI(obj, spki);
67
67
 
@@ -83,15 +83,15 @@ ossl_spki_initialize(int argc, VALUE *argv, VALUE self)
83
83
  const unsigned char *p;
84
84
 
85
85
  if (rb_scan_args(argc, argv, "01", &buffer) == 0) {
86
- return self;
86
+ return self;
87
87
  }
88
88
  StringValue(buffer);
89
89
  if (!(spki = NETSCAPE_SPKI_b64_decode(RSTRING_PTR(buffer), RSTRING_LENINT(buffer)))) {
90
- ossl_clear_error();
91
- p = (unsigned char *)RSTRING_PTR(buffer);
92
- if (!(spki = d2i_NETSCAPE_SPKI(NULL, &p, RSTRING_LEN(buffer)))) {
93
- ossl_raise(eSPKIError, NULL);
94
- }
90
+ ossl_clear_error();
91
+ p = (unsigned char *)RSTRING_PTR(buffer);
92
+ if (!(spki = d2i_NETSCAPE_SPKI(NULL, &p, RSTRING_LEN(buffer)))) {
93
+ ossl_raise(eSPKIError, NULL);
94
+ }
95
95
  }
96
96
  NETSCAPE_SPKI_free(DATA_PTR(self));
97
97
  SetSPKI(self, spki);
@@ -140,7 +140,7 @@ ossl_spki_to_pem(VALUE self)
140
140
 
141
141
  GetSPKI(self, spki);
142
142
  if (!(data = NETSCAPE_SPKI_b64_encode(spki))) {
143
- ossl_raise(eSPKIError, NULL);
143
+ ossl_raise(eSPKIError, NULL);
144
144
  }
145
145
  str = ossl_buf2str(data, rb_long2int(strlen(data)));
146
146
 
@@ -162,11 +162,11 @@ ossl_spki_print(VALUE self)
162
162
 
163
163
  GetSPKI(self, spki);
164
164
  if (!(out = BIO_new(BIO_s_mem()))) {
165
- ossl_raise(eSPKIError, NULL);
165
+ ossl_raise(eSPKIError, NULL);
166
166
  }
167
167
  if (!NETSCAPE_SPKI_print(out, spki)) {
168
- BIO_free(out);
169
- ossl_raise(eSPKIError, NULL);
168
+ BIO_free(out);
169
+ ossl_raise(eSPKIError, NULL);
170
170
  }
171
171
 
172
172
  return ossl_membio2str(out);
@@ -187,10 +187,10 @@ ossl_spki_get_public_key(VALUE self)
187
187
 
188
188
  GetSPKI(self, spki);
189
189
  if (!(pkey = NETSCAPE_SPKI_get_pubkey(spki))) { /* adds an reference */
190
- ossl_raise(eSPKIError, NULL);
190
+ ossl_raise(eSPKIError, NULL);
191
191
  }
192
192
 
193
- return ossl_pkey_new(pkey); /* NO DUP - OK */
193
+ return ossl_pkey_wrap(pkey);
194
194
  }
195
195
 
196
196
  /*
@@ -214,7 +214,7 @@ ossl_spki_set_public_key(VALUE self, VALUE key)
214
214
  pkey = GetPKeyPtr(key);
215
215
  ossl_pkey_check_public_key(pkey);
216
216
  if (!NETSCAPE_SPKI_set_pubkey(spki, pkey))
217
- ossl_raise(eSPKIError, "NETSCAPE_SPKI_set_pubkey");
217
+ ossl_raise(eSPKIError, "NETSCAPE_SPKI_set_pubkey");
218
218
  return key;
219
219
  }
220
220
 
@@ -230,13 +230,12 @@ ossl_spki_get_challenge(VALUE self)
230
230
  NETSCAPE_SPKI *spki;
231
231
 
232
232
  GetSPKI(self, spki);
233
- if (spki->spkac->challenge->length <= 0) {
234
- OSSL_Debug("Challenge.length <= 0?");
235
- return rb_str_new(0, 0);
233
+ if (ASN1_STRING_length(spki->spkac->challenge) <= 0) {
234
+ OSSL_Debug("Challenge.length <= 0?");
235
+ return rb_str_new(0, 0);
236
236
  }
237
237
 
238
- return rb_str_new((const char *)spki->spkac->challenge->data,
239
- spki->spkac->challenge->length);
238
+ return asn1str_to_str(spki->spkac->challenge);
240
239
  }
241
240
 
242
241
  /*
@@ -257,8 +256,8 @@ ossl_spki_set_challenge(VALUE self, VALUE str)
257
256
  StringValue(str);
258
257
  GetSPKI(self, spki);
259
258
  if (!ASN1_STRING_set(spki->spkac->challenge, RSTRING_PTR(str),
260
- RSTRING_LENINT(str))) {
261
- ossl_raise(eSPKIError, NULL);
259
+ RSTRING_LENINT(str))) {
260
+ ossl_raise(eSPKIError, NULL);
262
261
  }
263
262
 
264
263
  return str;
@@ -283,13 +282,13 @@ ossl_spki_sign(VALUE self, VALUE key, VALUE digest)
283
282
  NETSCAPE_SPKI *spki;
284
283
  EVP_PKEY *pkey;
285
284
  const EVP_MD *md;
285
+ VALUE md_holder;
286
286
 
287
287
  pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
288
- md = ossl_evp_get_digestbyname(digest);
288
+ md = ossl_evp_md_fetch(digest, &md_holder);
289
289
  GetSPKI(self, spki);
290
- if (!NETSCAPE_SPKI_sign(spki, pkey, md)) {
291
- ossl_raise(eSPKIError, NULL);
292
- }
290
+ if (!NETSCAPE_SPKI_sign(spki, pkey, md))
291
+ ossl_raise(eSPKIError, "NETSCAPE_SPKI_sign");
293
292
 
294
293
  return self;
295
294
  }
@@ -315,12 +314,12 @@ ossl_spki_verify(VALUE self, VALUE key)
315
314
  ossl_pkey_check_public_key(pkey);
316
315
  switch (NETSCAPE_SPKI_verify(spki, pkey)) {
317
316
  case 0:
318
- ossl_clear_error();
319
- return Qfalse;
317
+ ossl_clear_error();
318
+ return Qfalse;
320
319
  case 1:
321
- return Qtrue;
320
+ return Qtrue;
322
321
  default:
323
- ossl_raise(eSPKIError, "NETSCAPE_SPKI_verify");
322
+ ossl_raise(eSPKIError, "NETSCAPE_SPKI_verify");
324
323
  }
325
324
  }
326
325
 
@@ -378,11 +377,6 @@ ossl_spki_verify(VALUE self, VALUE key)
378
377
  void
379
378
  Init_ossl_ns_spki(void)
380
379
  {
381
- #if 0
382
- mOSSL = rb_define_module("OpenSSL");
383
- eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
384
- #endif
385
-
386
380
  mNetscape = rb_define_module_under(mOSSL, "Netscape");
387
381
 
388
382
  eSPKIError = rb_define_class_under(mNetscape, "SPKIError", eOSSLError);