openssl 3.2.4 → 3.3.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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +180 -29
  3. data/History.md +69 -42
  4. data/README.md +11 -7
  5. data/ext/openssl/extconf.rb +6 -5
  6. data/ext/openssl/openssl_missing.c +1 -2
  7. data/ext/openssl/openssl_missing.h +1 -28
  8. data/ext/openssl/ossl.c +8 -10
  9. data/ext/openssl/ossl.h +13 -10
  10. data/ext/openssl/ossl_asn1.c +77 -273
  11. data/ext/openssl/ossl_asn1.h +1 -19
  12. data/ext/openssl/ossl_bio.c +1 -1
  13. data/ext/openssl/ossl_bio.h +1 -1
  14. data/ext/openssl/ossl_bn.c +12 -12
  15. data/ext/openssl/ossl_bn.h +1 -2
  16. data/ext/openssl/ossl_cipher.c +5 -5
  17. data/ext/openssl/ossl_cipher.h +1 -4
  18. data/ext/openssl/ossl_config.c +10 -9
  19. data/ext/openssl/ossl_config.h +1 -1
  20. data/ext/openssl/ossl_digest.c +39 -21
  21. data/ext/openssl/ossl_digest.h +1 -4
  22. data/ext/openssl/ossl_engine.c +3 -3
  23. data/ext/openssl/ossl_engine.h +1 -4
  24. data/ext/openssl/ossl_hmac.c +3 -3
  25. data/ext/openssl/ossl_hmac.h +1 -4
  26. data/ext/openssl/ossl_kdf.c +5 -5
  27. data/ext/openssl/ossl_ns_spki.c +13 -12
  28. data/ext/openssl/ossl_ns_spki.h +1 -5
  29. data/ext/openssl/ossl_ocsp.c +16 -16
  30. data/ext/openssl/ossl_ocsp.h +1 -8
  31. data/ext/openssl/ossl_pkcs12.c +54 -3
  32. data/ext/openssl/ossl_pkcs12.h +1 -4
  33. data/ext/openssl/ossl_pkcs7.c +69 -22
  34. data/ext/openssl/ossl_pkcs7.h +2 -22
  35. data/ext/openssl/ossl_pkey.c +22 -63
  36. data/ext/openssl/ossl_pkey.h +3 -14
  37. data/ext/openssl/ossl_pkey_dh.c +2 -4
  38. data/ext/openssl/ossl_pkey_dsa.c +2 -4
  39. data/ext/openssl/ossl_pkey_ec.c +6 -8
  40. data/ext/openssl/ossl_pkey_rsa.c +2 -4
  41. data/ext/openssl/ossl_provider.c +3 -1
  42. data/ext/openssl/ossl_rand.c +3 -3
  43. data/ext/openssl/ossl_rand.h +1 -4
  44. data/ext/openssl/ossl_ssl.c +71 -52
  45. data/ext/openssl/ossl_ssl.h +1 -1
  46. data/ext/openssl/ossl_ts.c +77 -19
  47. data/ext/openssl/ossl_ts.h +1 -1
  48. data/ext/openssl/ossl_x509.c +1 -1
  49. data/ext/openssl/ossl_x509.h +7 -26
  50. data/ext/openssl/ossl_x509attr.c +30 -32
  51. data/ext/openssl/ossl_x509cert.c +48 -9
  52. data/ext/openssl/ossl_x509crl.c +13 -9
  53. data/ext/openssl/ossl_x509ext.c +12 -21
  54. data/ext/openssl/ossl_x509name.c +8 -10
  55. data/ext/openssl/ossl_x509req.c +10 -6
  56. data/ext/openssl/ossl_x509revoked.c +5 -6
  57. data/ext/openssl/ossl_x509store.c +21 -14
  58. data/lib/openssl/asn1.rb +188 -0
  59. data/lib/openssl/bn.rb +1 -1
  60. data/lib/openssl/buffering.rb +13 -3
  61. data/lib/openssl/cipher.rb +1 -1
  62. data/lib/openssl/digest.rb +1 -1
  63. data/lib/openssl/marshal.rb +1 -1
  64. data/lib/openssl/ssl.rb +68 -4
  65. data/lib/openssl/version.rb +1 -1
  66. data/lib/openssl/x509.rb +1 -1
  67. data/lib/openssl.rb +2 -1
  68. metadata +9 -4
  69. /data/{LICENSE.txt → COPYING} +0 -0
@@ -6,18 +6,11 @@
6
6
  */
7
7
  /*
8
8
  * This program is licensed under the same licence as Ruby.
9
- * (See the file 'LICENCE'.)
9
+ * (See the file 'COPYING'.)
10
10
  */
11
11
  #if !defined(_OSSL_OCSP_H_)
12
12
  #define _OSSL_OCSP_H_
13
13
 
14
- #if !defined(OPENSSL_NO_OCSP)
15
- extern VALUE mOCSP;
16
- extern VALUE cOCSPReq;
17
- extern VALUE cOCSPRes;
18
- extern VALUE cOCSPBasicRes;
19
- #endif
20
-
21
14
  void Init_ossl_ocsp(void);
22
15
 
23
16
  #endif /* _OSSL_OCSP_H_ */
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * This program is licensed under the same licence as Ruby.
3
- * (See the file 'LICENCE'.)
3
+ * (See the file 'COPYING'.)
4
4
  */
5
5
  #include "ossl.h"
6
6
 
@@ -27,8 +27,8 @@
27
27
  /*
28
28
  * Classes
29
29
  */
30
- VALUE cPKCS12;
31
- VALUE ePKCS12Error;
30
+ static VALUE cPKCS12;
31
+ static VALUE ePKCS12Error;
32
32
 
33
33
  /*
34
34
  * Private
@@ -134,6 +134,10 @@ ossl_pkcs12_s_create(int argc, VALUE *argv, VALUE self)
134
134
  if (!NIL_P(keytype))
135
135
  ktype = NUM2INT(keytype);
136
136
 
137
+ if (ktype != 0 && ktype != KEY_SIG && ktype != KEY_EX) {
138
+ ossl_raise(rb_eArgError, "Unknown key usage type %"PRIsVALUE, INT2NUM(ktype));
139
+ }
140
+
137
141
  obj = NewPKCS12(cPKCS12);
138
142
  x509s = NIL_P(ca) ? NULL : ossl_x509_ary2sk(ca);
139
143
  p12 = PKCS12_create(passphrase, friendlyname, key, x509, x509s,
@@ -247,6 +251,48 @@ ossl_pkcs12_to_der(VALUE self)
247
251
  return str;
248
252
  }
249
253
 
254
+ /*
255
+ * call-seq:
256
+ * pkcs12.set_mac(pass, salt = nil, iter = nil, md_type = nil)
257
+ *
258
+ * Sets MAC parameters and generates MAC over the PKCS #12 structure.
259
+ *
260
+ * This method uses HMAC and the PKCS #12 specific password-based KDF as
261
+ * specified in the original PKCS #12.
262
+ *
263
+ * See also the man page PKCS12_set_mac(3).
264
+ *
265
+ * Added in version 3.3.0.
266
+ */
267
+ static VALUE
268
+ pkcs12_set_mac(int argc, VALUE *argv, VALUE self)
269
+ {
270
+ PKCS12 *p12;
271
+ VALUE pass, salt, iter, md_name;
272
+ int iter_i = 0;
273
+ const EVP_MD *md_type = NULL;
274
+
275
+ rb_scan_args(argc, argv, "13", &pass, &salt, &iter, &md_name);
276
+ rb_check_frozen(self);
277
+ GetPKCS12(self, p12);
278
+
279
+ StringValue(pass);
280
+ if (!NIL_P(salt))
281
+ StringValue(salt);
282
+ if (!NIL_P(iter))
283
+ iter_i = NUM2INT(iter);
284
+ if (!NIL_P(md_name))
285
+ md_type = ossl_evp_get_digestbyname(md_name);
286
+
287
+ if (!PKCS12_set_mac(p12, RSTRING_PTR(pass), RSTRING_LENINT(pass),
288
+ !NIL_P(salt) ? (unsigned char *)RSTRING_PTR(salt) : NULL,
289
+ !NIL_P(salt) ? RSTRING_LENINT(salt) : 0,
290
+ iter_i, md_type))
291
+ ossl_raise(ePKCS12Error, "PKCS12_set_mac");
292
+
293
+ return Qnil;
294
+ }
295
+
250
296
  void
251
297
  Init_ossl_pkcs12(void)
252
298
  {
@@ -272,4 +318,9 @@ Init_ossl_pkcs12(void)
272
318
  rb_attr(cPKCS12, rb_intern("ca_certs"), 1, 0, Qfalse);
273
319
  rb_define_method(cPKCS12, "initialize", ossl_pkcs12_initialize, -1);
274
320
  rb_define_method(cPKCS12, "to_der", ossl_pkcs12_to_der, 0);
321
+ rb_define_method(cPKCS12, "set_mac", pkcs12_set_mac, -1);
322
+
323
+ /* MSIE specific PKCS12 key usage extensions */
324
+ rb_define_const(cPKCS12, "KEY_EX", INT2NUM(KEY_EX));
325
+ rb_define_const(cPKCS12, "KEY_SIG", INT2NUM(KEY_SIG));
275
326
  }
@@ -1,13 +1,10 @@
1
1
  /*
2
2
  * This program is licensed under the same licence as Ruby.
3
- * (See the file 'LICENCE'.)
3
+ * (See the file 'COPYING'.)
4
4
  */
5
5
  #if !defined(_OSSL_PKCS12_H_)
6
6
  #define _OSSL_PKCS12_H_
7
7
 
8
- extern VALUE cPKCS12;
9
- extern VALUE ePKCS12Error;
10
-
11
8
  void Init_ossl_pkcs12(void);
12
9
 
13
10
  #endif /* _OSSL_PKCS12_H_ */
@@ -5,10 +5,25 @@
5
5
  */
6
6
  /*
7
7
  * This program is licensed under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
  #include "ossl.h"
11
11
 
12
+ #define NewPKCS7(klass) \
13
+ TypedData_Wrap_Struct((klass), &ossl_pkcs7_type, 0)
14
+ #define SetPKCS7(obj, pkcs7) do { \
15
+ if (!(pkcs7)) { \
16
+ ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \
17
+ } \
18
+ RTYPEDDATA_DATA(obj) = (pkcs7); \
19
+ } while (0)
20
+ #define GetPKCS7(obj, pkcs7) do { \
21
+ TypedData_Get_Struct((obj), PKCS7, &ossl_pkcs7_type, (pkcs7)); \
22
+ if (!(pkcs7)) { \
23
+ ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \
24
+ } \
25
+ } while (0)
26
+
12
27
  #define NewPKCS7si(klass) \
13
28
  TypedData_Wrap_Struct((klass), &ossl_pkcs7_signer_info_type, 0)
14
29
  #define SetPKCS7si(obj, p7si) do { \
@@ -49,10 +64,10 @@
49
64
  /*
50
65
  * Classes
51
66
  */
52
- VALUE cPKCS7;
53
- VALUE cPKCS7Signer;
54
- VALUE cPKCS7Recipient;
55
- VALUE ePKCS7Error;
67
+ static VALUE cPKCS7;
68
+ static VALUE cPKCS7Signer;
69
+ static VALUE cPKCS7Recipient;
70
+ static VALUE ePKCS7Error;
56
71
 
57
72
  static void
58
73
  ossl_pkcs7_free(void *ptr)
@@ -60,7 +75,7 @@ ossl_pkcs7_free(void *ptr)
60
75
  PKCS7_free(ptr);
61
76
  }
62
77
 
63
- const rb_data_type_t ossl_pkcs7_type = {
78
+ static const rb_data_type_t ossl_pkcs7_type = {
64
79
  "OpenSSL/PKCS7",
65
80
  {
66
81
  0, ossl_pkcs7_free,
@@ -68,6 +83,20 @@ const rb_data_type_t ossl_pkcs7_type = {
68
83
  0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
69
84
  };
70
85
 
86
+ VALUE
87
+ ossl_pkcs7_new(PKCS7 *p7)
88
+ {
89
+ PKCS7 *new;
90
+ VALUE obj = NewPKCS7(cPKCS7);
91
+
92
+ new = PKCS7_dup(p7);
93
+ if (!new)
94
+ ossl_raise(ePKCS7Error, "PKCS7_dup");
95
+ SetPKCS7(obj, new);
96
+
97
+ return obj;
98
+ }
99
+
71
100
  static void
72
101
  ossl_pkcs7_signer_info_free(void *ptr)
73
102
  {
@@ -261,7 +290,14 @@ ossl_pkcs7_s_sign(int argc, VALUE *argv, VALUE klass)
261
290
 
262
291
  /*
263
292
  * call-seq:
264
- * PKCS7.encrypt(certs, data, [, cipher [, flags]]) => pkcs7
293
+ * PKCS7.encrypt(certs, data, cipher, flags = 0) => pkcs7
294
+ *
295
+ * Creates a PKCS #7 enveloped-data structure.
296
+ *
297
+ * Before version 3.3.0, +cipher+ was optional and defaulted to
298
+ * <tt>"RC2-40-CBC"</tt>.
299
+ *
300
+ * See also the man page PKCS7_encrypt(3).
265
301
  */
266
302
  static VALUE
267
303
  ossl_pkcs7_s_encrypt(int argc, VALUE *argv, VALUE klass)
@@ -275,21 +311,12 @@ ossl_pkcs7_s_encrypt(int argc, VALUE *argv, VALUE klass)
275
311
  PKCS7 *p7;
276
312
 
277
313
  rb_scan_args(argc, argv, "22", &certs, &data, &cipher, &flags);
278
- if(NIL_P(cipher)){
279
- #if !defined(OPENSSL_NO_RC2)
280
- ciph = EVP_rc2_40_cbc();
281
- #elif !defined(OPENSSL_NO_DES)
282
- ciph = EVP_des_ede3_cbc();
283
- #elif !defined(OPENSSL_NO_RC2)
284
- ciph = EVP_rc2_40_cbc();
285
- #elif !defined(OPENSSL_NO_AES)
286
- ciph = EVP_EVP_aes_128_cbc();
287
- #else
288
- ossl_raise(ePKCS7Error, "Must specify cipher");
289
- #endif
290
-
314
+ if (NIL_P(cipher)) {
315
+ rb_raise(rb_eArgError,
316
+ "cipher must be specified. Before version 3.3, " \
317
+ "the default cipher was RC2-40-CBC.");
291
318
  }
292
- else ciph = ossl_evp_get_cipherbyname(cipher);
319
+ ciph = ossl_evp_get_cipherbyname(cipher);
293
320
  flg = NIL_P(flags) ? 0 : NUM2INT(flags);
294
321
  ret = NewPKCS7(cPKCS7);
295
322
  in = ossl_obj2bio(&data);
@@ -851,6 +878,25 @@ ossl_pkcs7_to_der(VALUE self)
851
878
  return str;
852
879
  }
853
880
 
881
+ static VALUE
882
+ ossl_pkcs7_to_text(VALUE self)
883
+ {
884
+ PKCS7 *pkcs7;
885
+ BIO *out;
886
+ VALUE str;
887
+
888
+ GetPKCS7(self, pkcs7);
889
+ if(!(out = BIO_new(BIO_s_mem())))
890
+ ossl_raise(ePKCS7Error, NULL);
891
+ if(!PKCS7_print_ctx(out, pkcs7, 0, NULL)) {
892
+ BIO_free(out);
893
+ ossl_raise(ePKCS7Error, NULL);
894
+ }
895
+ str = ossl_membio2str(out);
896
+
897
+ return str;
898
+ }
899
+
854
900
  static VALUE
855
901
  ossl_pkcs7_to_pem(VALUE self)
856
902
  {
@@ -932,7 +978,7 @@ static VALUE
932
978
  ossl_pkcs7si_get_signed_time(VALUE self)
933
979
  {
934
980
  PKCS7_SIGNER_INFO *p7si;
935
- const ASN1_TYPE *asn1obj;
981
+ ASN1_TYPE *asn1obj;
936
982
 
937
983
  GetPKCS7si(self, p7si);
938
984
 
@@ -1060,6 +1106,7 @@ Init_ossl_pkcs7(void)
1060
1106
  rb_define_method(cPKCS7, "to_pem", ossl_pkcs7_to_pem, 0);
1061
1107
  rb_define_alias(cPKCS7, "to_s", "to_pem");
1062
1108
  rb_define_method(cPKCS7, "to_der", ossl_pkcs7_to_der, 0);
1109
+ rb_define_method(cPKCS7, "to_text", ossl_pkcs7_to_text, 0);
1063
1110
 
1064
1111
  cPKCS7Signer = rb_define_class_under(cPKCS7, "SignerInfo", rb_cObject);
1065
1112
  rb_define_const(cPKCS7, "Signer", cPKCS7Signer);
@@ -5,32 +5,12 @@
5
5
  */
6
6
  /*
7
7
  * This program is licensed under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
  #if !defined(_OSSL_PKCS7_H_)
11
11
  #define _OSSL_PKCS7_H_
12
12
 
13
- #define NewPKCS7(klass) \
14
- TypedData_Wrap_Struct((klass), &ossl_pkcs7_type, 0)
15
- #define SetPKCS7(obj, pkcs7) do { \
16
- if (!(pkcs7)) { \
17
- ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \
18
- } \
19
- RTYPEDDATA_DATA(obj) = (pkcs7); \
20
- } while (0)
21
- #define GetPKCS7(obj, pkcs7) do { \
22
- TypedData_Get_Struct((obj), PKCS7, &ossl_pkcs7_type, (pkcs7)); \
23
- if (!(pkcs7)) { \
24
- ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \
25
- } \
26
- } while (0)
27
-
28
- extern const rb_data_type_t ossl_pkcs7_type;
29
- extern VALUE cPKCS7;
30
- extern VALUE cPKCS7Signer;
31
- extern VALUE cPKCS7Recipient;
32
- extern VALUE ePKCS7Error;
33
-
13
+ VALUE ossl_pkcs7_new(PKCS7 *p7);
34
14
  void Init_ossl_pkcs7(void);
35
15
 
36
16
  #endif /* _OSSL_PKCS7_H_ */
@@ -5,7 +5,7 @@
5
5
  */
6
6
  /*
7
7
  * This program is licensed under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
  #include "ossl.h"
11
11
 
@@ -636,30 +636,6 @@ ossl_pkey_initialize_copy(VALUE self, VALUE other)
636
636
  #endif
637
637
 
638
638
  #ifdef HAVE_EVP_PKEY_NEW_RAW_PRIVATE_KEY
639
-
640
- #ifndef OSSL_USE_PROVIDER
641
- static int
642
- lookup_pkey_type(VALUE type)
643
- {
644
- const EVP_PKEY_ASN1_METHOD *ameth;
645
- int pkey_id;
646
-
647
- StringValue(type);
648
- /*
649
- * XXX: EVP_PKEY_asn1_find_str() looks up a PEM type string. Should we use
650
- * OBJ_txt2nid() instead (and then somehow check if the NID is an acceptable
651
- * EVP_PKEY type)?
652
- * It is probably fine, though, since it can handle all algorithms that
653
- * support raw keys in 1.1.1: { X25519, X448, ED25519, ED448, HMAC }.
654
- */
655
- ameth = EVP_PKEY_asn1_find_str(NULL, RSTRING_PTR(type), RSTRING_LENINT(type));
656
- if (!ameth)
657
- ossl_raise(ePKeyError, "algorithm %"PRIsVALUE" not found", type);
658
- EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, ameth);
659
- return pkey_id;
660
- }
661
- #endif
662
-
663
639
  /*
664
640
  * call-seq:
665
641
  * OpenSSL::PKey.new_raw_private_key(algo, string) -> PKey
@@ -671,23 +647,22 @@ static VALUE
671
647
  ossl_pkey_new_raw_private_key(VALUE self, VALUE type, VALUE key)
672
648
  {
673
649
  EVP_PKEY *pkey;
650
+ const EVP_PKEY_ASN1_METHOD *ameth;
651
+ int pkey_id;
674
652
  size_t keylen;
675
653
 
654
+ StringValue(type);
676
655
  StringValue(key);
656
+ ameth = EVP_PKEY_asn1_find_str(NULL, RSTRING_PTR(type), RSTRING_LENINT(type));
657
+ if (!ameth)
658
+ ossl_raise(ePKeyError, "algorithm %"PRIsVALUE" not found", type);
659
+ EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, ameth);
660
+
677
661
  keylen = RSTRING_LEN(key);
678
662
 
679
- #ifdef OSSL_USE_PROVIDER
680
- pkey = EVP_PKEY_new_raw_private_key_ex(NULL, StringValueCStr(type), NULL,
681
- (unsigned char *)RSTRING_PTR(key),
682
- keylen);
683
- if (!pkey)
684
- ossl_raise(ePKeyError, "EVP_PKEY_new_raw_private_key_ex");
685
- #else
686
- int pkey_id = lookup_pkey_type(type);
687
663
  pkey = EVP_PKEY_new_raw_private_key(pkey_id, NULL, (unsigned char *)RSTRING_PTR(key), keylen);
688
664
  if (!pkey)
689
665
  ossl_raise(ePKeyError, "EVP_PKEY_new_raw_private_key");
690
- #endif
691
666
 
692
667
  return ossl_pkey_new(pkey);
693
668
  }
@@ -705,23 +680,22 @@ static VALUE
705
680
  ossl_pkey_new_raw_public_key(VALUE self, VALUE type, VALUE key)
706
681
  {
707
682
  EVP_PKEY *pkey;
683
+ const EVP_PKEY_ASN1_METHOD *ameth;
684
+ int pkey_id;
708
685
  size_t keylen;
709
686
 
687
+ StringValue(type);
710
688
  StringValue(key);
689
+ ameth = EVP_PKEY_asn1_find_str(NULL, RSTRING_PTR(type), RSTRING_LENINT(type));
690
+ if (!ameth)
691
+ ossl_raise(ePKeyError, "algorithm %"PRIsVALUE" not found", type);
692
+ EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, ameth);
693
+
711
694
  keylen = RSTRING_LEN(key);
712
695
 
713
- #ifdef OSSL_USE_PROVIDER
714
- pkey = EVP_PKEY_new_raw_public_key_ex(NULL, StringValueCStr(type), NULL,
715
- (unsigned char *)RSTRING_PTR(key),
716
- keylen);
717
- if (!pkey)
718
- ossl_raise(ePKeyError, "EVP_PKEY_new_raw_public_key_ex");
719
- #else
720
- int pkey_id = lookup_pkey_type(type);
721
696
  pkey = EVP_PKEY_new_raw_public_key(pkey_id, NULL, (unsigned char *)RSTRING_PTR(key), keylen);
722
697
  if (!pkey)
723
698
  ossl_raise(ePKeyError, "EVP_PKEY_new_raw_public_key");
724
- #endif
725
699
 
726
700
  return ossl_pkey_new(pkey);
727
701
  }
@@ -741,10 +715,6 @@ ossl_pkey_oid(VALUE self)
741
715
 
742
716
  GetPKey(self, pkey);
743
717
  nid = EVP_PKEY_id(pkey);
744
- #ifdef OSSL_USE_PROVIDER
745
- if (nid == EVP_PKEY_KEYMGMT)
746
- ossl_raise(ePKeyError, "EVP_PKEY_id");
747
- #endif
748
718
  return rb_str_new_cstr(OBJ_nid2sn(nid));
749
719
  }
750
720
 
@@ -758,23 +728,13 @@ static VALUE
758
728
  ossl_pkey_inspect(VALUE self)
759
729
  {
760
730
  EVP_PKEY *pkey;
731
+ int nid;
761
732
 
762
733
  GetPKey(self, pkey);
763
- VALUE str = rb_sprintf("#<%"PRIsVALUE":%p",
764
- rb_obj_class(self), (void *)self);
765
- int nid = EVP_PKEY_id(pkey);
766
- #ifdef OSSL_USE_PROVIDER
767
- if (nid != EVP_PKEY_KEYMGMT)
768
- #endif
769
- rb_str_catf(str, " oid=%s", OBJ_nid2sn(nid));
770
- #ifdef OSSL_USE_PROVIDER
771
- rb_str_catf(str, " type_name=%s", EVP_PKEY_get0_type_name(pkey));
772
- const OSSL_PROVIDER *prov = EVP_PKEY_get0_provider(pkey);
773
- if (prov)
774
- rb_str_catf(str, " provider=%s", OSSL_PROVIDER_get0_name(prov));
775
- #endif
776
- rb_str_catf(str, ">");
777
- return str;
734
+ nid = EVP_PKEY_id(pkey);
735
+ return rb_sprintf("#<%"PRIsVALUE":%p oid=%s>",
736
+ rb_class_name(CLASS_OF(self)), (void *)self,
737
+ OBJ_nid2sn(nid));
778
738
  }
779
739
 
780
740
  /*
@@ -977,7 +937,6 @@ ossl_pkey_export_spki(VALUE self, int to_der)
977
937
  BIO *bio;
978
938
 
979
939
  GetPKey(self, pkey);
980
- ossl_pkey_check_public_key(pkey);
981
940
  bio = BIO_new(BIO_s_mem());
982
941
  if (!bio)
983
942
  ossl_raise(ePKeyError, "BIO_new");
@@ -5,7 +5,7 @@
5
5
  */
6
6
  /*
7
7
  * This program is licensed under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
  #if !defined(OSSL_PKEY_H)
11
11
  #define OSSL_PKEY_H
@@ -53,35 +53,24 @@ void Init_ossl_pkey(void);
53
53
  * RSA
54
54
  */
55
55
  extern VALUE cRSA;
56
- extern VALUE eRSAError;
57
-
58
56
  void Init_ossl_rsa(void);
59
57
 
60
58
  /*
61
59
  * DSA
62
60
  */
63
61
  extern VALUE cDSA;
64
- extern VALUE eDSAError;
65
-
66
62
  void Init_ossl_dsa(void);
67
63
 
68
64
  /*
69
65
  * DH
70
66
  */
71
67
  extern VALUE cDH;
72
- extern VALUE eDHError;
73
-
74
68
  void Init_ossl_dh(void);
75
69
 
76
70
  /*
77
71
  * EC
78
72
  */
79
73
  extern VALUE cEC;
80
- extern VALUE eECError;
81
- extern VALUE cEC_GROUP;
82
- extern VALUE eEC_GROUP;
83
- extern VALUE cEC_POINT;
84
- extern VALUE eEC_POINT;
85
74
  VALUE ossl_ec_new(EVP_PKEY *);
86
75
  void Init_ossl_ec(void);
87
76
 
@@ -136,7 +125,7 @@ static VALUE ossl_##_keytype##_set_##_group(VALUE self, VALUE v1, VALUE v2, VALU
136
125
  BN_clear_free(bn1); \
137
126
  BN_clear_free(bn2); \
138
127
  BN_clear_free(bn3); \
139
- ossl_raise(eBNError, NULL); \
128
+ ossl_raise(ePKeyError, "BN_dup"); \
140
129
  } \
141
130
  \
142
131
  if (!_type##_set0_##_group(obj, bn1, bn2, bn3)) { \
@@ -164,7 +153,7 @@ static VALUE ossl_##_keytype##_set_##_group(VALUE self, VALUE v1, VALUE v2) \
164
153
  (orig_bn2 && !(bn2 = BN_dup(orig_bn2)))) { \
165
154
  BN_clear_free(bn1); \
166
155
  BN_clear_free(bn2); \
167
- ossl_raise(eBNError, NULL); \
156
+ ossl_raise(ePKeyError, "BN_dup"); \
168
157
  } \
169
158
  \
170
159
  if (!_type##_set0_##_group(obj, bn1, bn2)) { \
@@ -5,7 +5,7 @@
5
5
  */
6
6
  /*
7
7
  * This program is licensed under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
  #include "ossl.h"
11
11
 
@@ -21,15 +21,13 @@
21
21
  EVP_PKEY *_pkey; \
22
22
  GetPKeyDH((obj), _pkey); \
23
23
  (dh) = EVP_PKEY_get0_DH(_pkey); \
24
- if ((dh) == NULL) \
25
- ossl_raise(eDHError, "failed to get DH from EVP_PKEY"); \
26
24
  } while (0)
27
25
 
28
26
  /*
29
27
  * Classes
30
28
  */
31
29
  VALUE cDH;
32
- VALUE eDHError;
30
+ static VALUE eDHError;
33
31
 
34
32
  /*
35
33
  * Private
@@ -5,7 +5,7 @@
5
5
  */
6
6
  /*
7
7
  * This program is licensed under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
  #include "ossl.h"
11
11
 
@@ -21,8 +21,6 @@
21
21
  EVP_PKEY *_pkey; \
22
22
  GetPKeyDSA((obj), _pkey); \
23
23
  (dsa) = EVP_PKEY_get0_DSA(_pkey); \
24
- if ((dsa) == NULL) \
25
- ossl_raise(eDSAError, "failed to get DSA from EVP_PKEY"); \
26
24
  } while (0)
27
25
 
28
26
  static inline int
@@ -43,7 +41,7 @@ DSA_PRIVATE(VALUE obj, OSSL_3_const DSA *dsa)
43
41
  * Classes
44
42
  */
45
43
  VALUE cDSA;
46
- VALUE eDSAError;
44
+ static VALUE eDSAError;
47
45
 
48
46
  /*
49
47
  * Private
@@ -22,8 +22,6 @@ static const rb_data_type_t ossl_ec_point_type;
22
22
  EVP_PKEY *_pkey; \
23
23
  GetPKeyEC(obj, _pkey); \
24
24
  (key) = EVP_PKEY_get0_EC_KEY(_pkey); \
25
- if ((key) == NULL) \
26
- ossl_raise(eECError, "failed to get EC_KEY from EVP_PKEY"); \
27
25
  } while (0)
28
26
 
29
27
  #define GetECGroup(obj, group) do { \
@@ -43,11 +41,11 @@ static const rb_data_type_t ossl_ec_point_type;
43
41
  } while (0)
44
42
 
45
43
  VALUE cEC;
46
- VALUE eECError;
47
- VALUE cEC_GROUP;
48
- VALUE eEC_GROUP;
49
- VALUE cEC_POINT;
50
- VALUE eEC_POINT;
44
+ static VALUE eECError;
45
+ static VALUE cEC_GROUP;
46
+ static VALUE eEC_GROUP;
47
+ static VALUE cEC_POINT;
48
+ static VALUE eEC_POINT;
51
49
 
52
50
  static ID s_GFp, s_GF2m;
53
51
 
@@ -176,7 +174,7 @@ static VALUE ossl_ec_key_initialize(int argc, VALUE *argv, VALUE self)
176
174
  type = EVP_PKEY_base_id(pkey);
177
175
  if (type != EVP_PKEY_EC) {
178
176
  EVP_PKEY_free(pkey);
179
- rb_raise(eDSAError, "incorrect pkey type: %s", OBJ_nid2sn(type));
177
+ rb_raise(eECError, "incorrect pkey type: %s", OBJ_nid2sn(type));
180
178
  }
181
179
  RTYPEDDATA_DATA(self) = pkey;
182
180
  return self;
@@ -5,7 +5,7 @@
5
5
  */
6
6
  /*
7
7
  * This program is licensed under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
  #include "ossl.h"
11
11
 
@@ -21,8 +21,6 @@
21
21
  EVP_PKEY *_pkey; \
22
22
  GetPKeyRSA((obj), _pkey); \
23
23
  (rsa) = EVP_PKEY_get0_RSA(_pkey); \
24
- if ((rsa) == NULL) \
25
- ossl_raise(eRSAError, "failed to get RSA from EVP_PKEY"); \
26
24
  } while (0)
27
25
 
28
26
  static inline int
@@ -44,7 +42,7 @@ RSA_PRIVATE(VALUE obj, OSSL_3_const RSA *rsa)
44
42
  * Classes
45
43
  */
46
44
  VALUE cRSA;
47
- VALUE eRSAError;
45
+ static VALUE eRSAError;
48
46
 
49
47
  /*
50
48
  * Private
@@ -1,10 +1,12 @@
1
1
  /*
2
2
  * This program is licensed under the same licence as Ruby.
3
- * (See the file 'LICENCE'.)
3
+ * (See the file 'COPYING'.)
4
4
  */
5
5
  #include "ossl.h"
6
6
 
7
7
  #ifdef OSSL_USE_PROVIDER
8
+ # include <openssl/provider.h>
9
+
8
10
  #define NewProvider(klass) \
9
11
  TypedData_Wrap_Struct((klass), &ossl_provider_type, 0)
10
12
  #define SetProvider(obj, provider) do { \
@@ -5,12 +5,12 @@
5
5
  * All rights reserved.
6
6
  *
7
7
  * This program is licensed under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
  #include "ossl.h"
11
11
 
12
- VALUE mRandom;
13
- VALUE eRandomError;
12
+ static VALUE mRandom;
13
+ static VALUE eRandomError;
14
14
 
15
15
  /*
16
16
  * call-seq:
@@ -5,14 +5,11 @@
5
5
  */
6
6
  /*
7
7
  * This program is licensed under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
  #if !defined(_OSSL_RAND_H_)
11
11
  #define _OSSL_RAND_H_
12
12
 
13
- extern VALUE mRandom;
14
- extern VALUE eRandomError;
15
-
16
13
  void Init_ossl_rand(void);
17
14
 
18
15
  #endif /* _OSSL_RAND_H_ */