rubysl-openssl 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rubysl/openssl/deprecation.rb +1 -0
  3. data/ext/rubysl/openssl/extconf.rb +6 -8
  4. data/ext/rubysl/openssl/openssl_missing.c +1 -3
  5. data/ext/rubysl/openssl/openssl_missing.h +1 -3
  6. data/ext/rubysl/openssl/ossl.c +15 -3
  7. data/ext/rubysl/openssl/ossl.h +5 -4
  8. data/ext/rubysl/openssl/ossl_asn1.c +19 -13
  9. data/ext/rubysl/openssl/ossl_asn1.h +1 -2
  10. data/ext/rubysl/openssl/ossl_bio.c +1 -2
  11. data/ext/rubysl/openssl/ossl_bio.h +1 -3
  12. data/ext/rubysl/openssl/ossl_bn.c +227 -90
  13. data/ext/rubysl/openssl/ossl_bn.h +1 -3
  14. data/ext/rubysl/openssl/ossl_cipher.c +5 -11
  15. data/ext/rubysl/openssl/ossl_cipher.h +1 -3
  16. data/ext/rubysl/openssl/ossl_config.c +1 -2
  17. data/ext/rubysl/openssl/ossl_config.h +1 -3
  18. data/ext/rubysl/openssl/ossl_digest.c +6 -7
  19. data/ext/rubysl/openssl/ossl_digest.h +1 -3
  20. data/ext/rubysl/openssl/ossl_engine.c +11 -7
  21. data/ext/rubysl/openssl/ossl_engine.h +1 -2
  22. data/ext/rubysl/openssl/ossl_hmac.c +1 -2
  23. data/ext/rubysl/openssl/ossl_hmac.h +1 -2
  24. data/ext/rubysl/openssl/ossl_ns_spki.c +7 -6
  25. data/ext/rubysl/openssl/ossl_ns_spki.h +1 -3
  26. data/ext/rubysl/openssl/ossl_ocsp.c +39 -25
  27. data/ext/rubysl/openssl/ossl_ocsp.h +1 -2
  28. data/ext/rubysl/openssl/ossl_pkcs12.c +10 -6
  29. data/ext/rubysl/openssl/ossl_pkcs12.h +1 -3
  30. data/ext/rubysl/openssl/ossl_pkcs5.c +0 -1
  31. data/ext/rubysl/openssl/ossl_pkcs7.c +29 -16
  32. data/ext/rubysl/openssl/ossl_pkcs7.h +1 -3
  33. data/ext/rubysl/openssl/ossl_pkey.c +10 -8
  34. data/ext/rubysl/openssl/ossl_pkey.h +5 -6
  35. data/ext/rubysl/openssl/ossl_pkey_dh.c +5 -74
  36. data/ext/rubysl/openssl/ossl_pkey_dsa.c +7 -6
  37. data/ext/rubysl/openssl/ossl_pkey_ec.c +4 -2
  38. data/ext/rubysl/openssl/ossl_pkey_rsa.c +5 -5
  39. data/ext/rubysl/openssl/ossl_rand.c +13 -5
  40. data/ext/rubysl/openssl/ossl_rand.h +1 -3
  41. data/ext/rubysl/openssl/ossl_ssl.c +334 -265
  42. data/ext/rubysl/openssl/ossl_ssl.h +1 -5
  43. data/ext/rubysl/openssl/ossl_ssl_session.c +5 -1
  44. data/ext/rubysl/openssl/ossl_version.h +1 -2
  45. data/ext/rubysl/openssl/ossl_x509.c +1 -3
  46. data/ext/rubysl/openssl/ossl_x509.h +1 -2
  47. data/ext/rubysl/openssl/ossl_x509attr.c +9 -6
  48. data/ext/rubysl/openssl/ossl_x509cert.c +14 -12
  49. data/ext/rubysl/openssl/ossl_x509crl.c +15 -13
  50. data/ext/rubysl/openssl/ossl_x509ext.c +13 -8
  51. data/ext/rubysl/openssl/ossl_x509name.c +9 -6
  52. data/ext/rubysl/openssl/ossl_x509req.c +12 -10
  53. data/ext/rubysl/openssl/ossl_x509revoked.c +12 -10
  54. data/ext/rubysl/openssl/ossl_x509store.c +17 -10
  55. data/ext/rubysl/openssl/ruby_missing.h +1 -2
  56. data/lib/openssl/bn.rb +2 -8
  57. data/lib/openssl/buffering.rb +3 -7
  58. data/lib/openssl/cipher.rb +3 -9
  59. data/lib/openssl/config.rb +2 -1
  60. data/lib/openssl/digest.rb +3 -10
  61. data/lib/openssl/pkey.rb +37 -0
  62. data/lib/openssl/ssl.rb +128 -17
  63. data/lib/openssl/x509.rb +2 -8
  64. data/lib/rubysl/openssl.rb +4 -7
  65. data/lib/rubysl/openssl/version.rb +1 -1
  66. metadata +12 -11
@@ -1,12 +1,11 @@
1
1
  /*
2
- * $Id: ossl_ocsp.h 25189 2009-10-02 12:04:37Z akr $
3
2
  * 'OpenSSL for Ruby' project
4
3
  * Copyright (C) 2003 Michal Rokos <m.rokos@sh.cvut.cz>
5
4
  * Copyright (C) 2003 GOTOU Yuuzou <gotoyuzo@notwork.org>
6
5
  * All rights reserved.
7
6
  */
8
7
  /*
9
- * This program is licenced under the same licence as Ruby.
8
+ * This program is licensed under the same licence as Ruby.
10
9
  * (See the file 'LICENCE'.)
11
10
  */
12
11
  #if !defined(_OSSL_OCSP_H_)
@@ -1,13 +1,15 @@
1
1
  /*
2
- * This program is licenced under the same licence as Ruby.
2
+ * This program is licensed under the same licence as Ruby.
3
3
  * (See the file 'LICENCE'.)
4
- * $Id: ossl_pkcs12.c 48802 2014-12-12 22:37:53Z nobu $
5
4
  */
6
5
  #include "ossl.h"
7
6
 
8
- #define WrapPKCS12(klass, obj, p12) do { \
7
+ #define NewPKCS12(klass) \
8
+ TypedData_Wrap_Struct((klass), &ossl_pkcs12_type, 0)
9
+
10
+ #define SetPKCS12(obj, p12) do { \
9
11
  if(!(p12)) ossl_raise(rb_eRuntimeError, "PKCS12 wasn't initialized."); \
10
- (obj) = TypedData_Wrap_Struct((klass), &ossl_pkcs12_type, (p12)); \
12
+ RTYPEDDATA_DATA(obj) = (p12); \
11
13
  } while (0)
12
14
 
13
15
  #define GetPKCS12(obj, p12) do { \
@@ -56,8 +58,9 @@ ossl_pkcs12_s_allocate(VALUE klass)
56
58
  PKCS12 *p12;
57
59
  VALUE obj;
58
60
 
61
+ obj = NewPKCS12(klass);
59
62
  if(!(p12 = PKCS12_new())) ossl_raise(ePKCS12Error, NULL);
60
- WrapPKCS12(klass, obj, p12);
63
+ SetPKCS12(obj, p12);
61
64
 
62
65
  return obj;
63
66
  }
@@ -118,11 +121,12 @@ ossl_pkcs12_s_create(int argc, VALUE *argv, VALUE self)
118
121
  if (!NIL_P(keytype))
119
122
  ktype = NUM2INT(keytype);
120
123
 
124
+ obj = NewPKCS12(cPKCS12);
121
125
  p12 = PKCS12_create(passphrase, friendlyname, key, x509, x509s,
122
126
  nkey, ncert, kiter, miter, ktype);
123
127
  sk_X509_pop_free(x509s, X509_free);
124
128
  if(!p12) ossl_raise(ePKCS12Error, NULL);
125
- WrapPKCS12(cPKCS12, obj, p12);
129
+ SetPKCS12(obj, p12);
126
130
 
127
131
  ossl_pkcs12_set_key(obj, pkey);
128
132
  ossl_pkcs12_set_cert(obj, cert);
@@ -1,7 +1,6 @@
1
1
  /*
2
- * This program is licenced under the same licence as Ruby.
2
+ * This program is licensed under the same licence as Ruby.
3
3
  * (See the file 'LICENCE'.)
4
- * $Id: ossl_pkcs12.h 25189 2009-10-02 12:04:37Z akr $
5
4
  */
6
5
  #if !defined(_OSSL_PKCS12_H_)
7
6
  #define _OSSL_PKCS12_H_
@@ -12,4 +11,3 @@ extern VALUE ePKCS12Error;
12
11
  void Init_ossl_pkcs12(void);
13
12
 
14
13
  #endif /* _OSSL_PKCS12_H_ */
15
-
@@ -1,5 +1,4 @@
1
1
  /*
2
- * $Id$
3
2
  * Copyright (C) 2007 Technorama Ltd. <oss-ruby@technorama.net>
4
3
  */
5
4
  #include "ossl.h"
@@ -1,20 +1,21 @@
1
1
  /*
2
- * $Id: ossl_pkcs7.c 48805 2014-12-12 22:38:01Z nobu $
3
2
  * 'OpenSSL for Ruby' project
4
3
  * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
5
4
  * All rights reserved.
6
5
  */
7
6
  /*
8
- * This program is licenced under the same licence as Ruby.
7
+ * This program is licensed under the same licence as Ruby.
9
8
  * (See the file 'LICENCE'.)
10
9
  */
11
10
  #include "ossl.h"
12
11
 
13
- #define WrapPKCS7(klass, obj, pkcs7) do { \
12
+ #define NewPKCS7(klass) \
13
+ TypedData_Wrap_Struct((klass), &ossl_pkcs7_type, 0)
14
+ #define SetPKCS7(obj, pkcs7) do { \
14
15
  if (!(pkcs7)) { \
15
16
  ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \
16
17
  } \
17
- (obj) = TypedData_Wrap_Struct((klass), &ossl_pkcs7_type, (pkcs7)); \
18
+ RTYPEDDATA_DATA(obj) = (pkcs7); \
18
19
  } while (0)
19
20
  #define GetPKCS7(obj, pkcs7) do { \
20
21
  TypedData_Get_Struct((obj), PKCS7, &ossl_pkcs7_type, (pkcs7)); \
@@ -27,11 +28,13 @@
27
28
  GetPKCS7((obj), (pkcs7)); \
28
29
  } while (0)
29
30
 
30
- #define WrapPKCS7si(klass, obj, p7si) do { \
31
+ #define NewPKCS7si(klass) \
32
+ TypedData_Wrap_Struct((klass), &ossl_pkcs7_signer_info_type, 0)
33
+ #define SetPKCS7si(obj, p7si) do { \
31
34
  if (!(p7si)) { \
32
35
  ossl_raise(rb_eRuntimeError, "PKCS7si wasn't initialized."); \
33
36
  } \
34
- (obj) = TypedData_Wrap_Struct((klass), &ossl_pkcs7_signer_info_type, (p7si)); \
37
+ RTYPEDDATA_DATA(obj) = (p7si); \
35
38
  } while (0)
36
39
  #define GetPKCS7si(obj, p7si) do { \
37
40
  TypedData_Get_Struct((obj), PKCS7_SIGNER_INFO, &ossl_pkcs7_signer_info_type, (p7si)); \
@@ -44,11 +47,13 @@
44
47
  GetPKCS7si((obj), (p7si)); \
45
48
  } while (0)
46
49
 
47
- #define WrapPKCS7ri(klass, obj, p7ri) do { \
50
+ #define NewPKCS7ri(klass) \
51
+ TypedData_Wrap_Struct((klass), &ossl_pkcs7_recip_info_type, 0)
52
+ #define SetPKCS7ri(obj, p7ri) do { \
48
53
  if (!(p7ri)) { \
49
54
  ossl_raise(rb_eRuntimeError, "PKCS7ri wasn't initialized."); \
50
55
  } \
51
- (obj) = TypedData_Wrap_Struct((klass), &ossl_pkcs7_recip_info_type, (p7ri)); \
56
+ RTYPEDDATA_DATA(obj) = (p7ri); \
52
57
  } while (0)
53
58
  #define GetPKCS7ri(obj, p7ri) do { \
54
59
  TypedData_Get_Struct((obj), PKCS7_RECIP_INFO, &ossl_pkcs7_recip_info_type, (p7ri)); \
@@ -128,9 +133,10 @@ ossl_pkcs7si_new(PKCS7_SIGNER_INFO *p7si)
128
133
  PKCS7_SIGNER_INFO *pkcs7;
129
134
  VALUE obj;
130
135
 
136
+ obj = NewPKCS7si(cPKCS7Signer);
131
137
  pkcs7 = p7si ? PKCS7_SIGNER_INFO_dup(p7si) : PKCS7_SIGNER_INFO_new();
132
138
  if (!pkcs7) ossl_raise(ePKCS7Error, NULL);
133
- WrapPKCS7si(cPKCS7Signer, obj, pkcs7);
139
+ SetPKCS7si(obj, pkcs7);
134
140
 
135
141
  return obj;
136
142
  }
@@ -154,9 +160,10 @@ ossl_pkcs7ri_new(PKCS7_RECIP_INFO *p7ri)
154
160
  PKCS7_RECIP_INFO *pkcs7;
155
161
  VALUE obj;
156
162
 
163
+ obj = NewPKCS7ri(cPKCS7Recipient);
157
164
  pkcs7 = p7ri ? PKCS7_RECIP_INFO_dup(p7ri) : PKCS7_RECIP_INFO_new();
158
165
  if (!pkcs7) ossl_raise(ePKCS7Error, NULL);
159
- WrapPKCS7ri(cPKCS7Recipient, obj, pkcs7);
166
+ SetPKCS7ri(obj, pkcs7);
160
167
 
161
168
  return obj;
162
169
  }
@@ -185,13 +192,14 @@ ossl_pkcs7_s_read_smime(VALUE klass, VALUE arg)
185
192
  PKCS7 *pkcs7;
186
193
  VALUE ret, data;
187
194
 
195
+ ret = NewPKCS7(cPKCS7);
188
196
  in = ossl_obj2bio(arg);
189
197
  out = NULL;
190
198
  pkcs7 = SMIME_read_PKCS7(in, &out);
191
199
  BIO_free(in);
192
200
  if(!pkcs7) ossl_raise(ePKCS7Error, NULL);
193
201
  data = out ? ossl_membio2str(out) : Qnil;
194
- WrapPKCS7(cPKCS7, ret, pkcs7);
202
+ SetPKCS7(ret, pkcs7);
195
203
  ossl_pkcs7_set_data(ret, data);
196
204
  ossl_pkcs7_set_err_string(ret, Qnil);
197
205
 
@@ -253,6 +261,7 @@ ossl_pkcs7_s_sign(int argc, VALUE *argv, VALUE klass)
253
261
  x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */
254
262
  pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
255
263
  flg = NIL_P(flags) ? 0 : NUM2INT(flags);
264
+ ret = NewPKCS7(cPKCS7);
256
265
  in = ossl_obj2bio(data);
257
266
  if(NIL_P(certs)) x509s = NULL;
258
267
  else{
@@ -267,7 +276,7 @@ ossl_pkcs7_s_sign(int argc, VALUE *argv, VALUE klass)
267
276
  sk_X509_pop_free(x509s, X509_free);
268
277
  ossl_raise(ePKCS7Error, NULL);
269
278
  }
270
- WrapPKCS7(cPKCS7, ret, pkcs7);
279
+ SetPKCS7(ret, pkcs7);
271
280
  ossl_pkcs7_set_data(ret, data);
272
281
  ossl_pkcs7_set_err_string(ret, Qnil);
273
282
  BIO_free(in);
@@ -308,6 +317,7 @@ ossl_pkcs7_s_encrypt(int argc, VALUE *argv, VALUE klass)
308
317
  }
309
318
  else ciph = GetCipherPtr(cipher); /* NO NEED TO DUP */
310
319
  flg = NIL_P(flags) ? 0 : NUM2INT(flags);
320
+ ret = NewPKCS7(cPKCS7);
311
321
  in = ossl_obj2bio(data);
312
322
  x509s = ossl_protect_x509_ary2sk(certs, &status);
313
323
  if(status){
@@ -320,7 +330,7 @@ ossl_pkcs7_s_encrypt(int argc, VALUE *argv, VALUE klass)
320
330
  ossl_raise(ePKCS7Error, NULL);
321
331
  }
322
332
  BIO_free(in);
323
- WrapPKCS7(cPKCS7, ret, p7);
333
+ SetPKCS7(ret, p7);
324
334
  ossl_pkcs7_set_data(ret, data);
325
335
  sk_X509_pop_free(x509s, X509_free);
326
336
 
@@ -333,10 +343,11 @@ ossl_pkcs7_alloc(VALUE klass)
333
343
  PKCS7 *pkcs7;
334
344
  VALUE obj;
335
345
 
346
+ obj = NewPKCS7(klass);
336
347
  if (!(pkcs7 = PKCS7_new())) {
337
348
  ossl_raise(ePKCS7Error, NULL);
338
349
  }
339
- WrapPKCS7(klass, obj, pkcs7);
350
+ SetPKCS7(obj, pkcs7);
340
351
 
341
352
  return obj;
342
353
  }
@@ -886,10 +897,11 @@ ossl_pkcs7si_alloc(VALUE klass)
886
897
  PKCS7_SIGNER_INFO *p7si;
887
898
  VALUE obj;
888
899
 
900
+ obj = NewPKCS7si(klass);
889
901
  if (!(p7si = PKCS7_SIGNER_INFO_new())) {
890
902
  ossl_raise(ePKCS7Error, NULL);
891
903
  }
892
- WrapPKCS7si(klass, obj, p7si);
904
+ SetPKCS7si(obj, p7si);
893
905
 
894
906
  return obj;
895
907
  }
@@ -965,10 +977,11 @@ ossl_pkcs7ri_alloc(VALUE klass)
965
977
  PKCS7_RECIP_INFO *p7ri;
966
978
  VALUE obj;
967
979
 
980
+ obj = NewPKCS7ri(klass);
968
981
  if (!(p7ri = PKCS7_RECIP_INFO_new())) {
969
982
  ossl_raise(ePKCS7Error, NULL);
970
983
  }
971
- WrapPKCS7ri(klass, obj, p7ri);
984
+ SetPKCS7ri(obj, p7ri);
972
985
 
973
986
  return obj;
974
987
  }
@@ -1,11 +1,10 @@
1
1
  /*
2
- * $Id: ossl_pkcs7.h 25189 2009-10-02 12:04:37Z akr $
3
2
  * 'OpenSSL for Ruby' project
4
3
  * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
5
4
  * All rights reserved.
6
5
  */
7
6
  /*
8
- * This program is licenced under the same licence as Ruby.
7
+ * This program is licensed under the same licence as Ruby.
9
8
  * (See the file 'LICENCE'.)
10
9
  */
11
10
  #if !defined(_OSSL_PKCS7_H_)
@@ -19,4 +18,3 @@ extern VALUE ePKCS7Error;
19
18
  void Init_ossl_pkcs7(void);
20
19
 
21
20
  #endif /* _OSSL_PKCS7_H_ */
22
-
@@ -1,11 +1,10 @@
1
1
  /*
2
- * $Id: ossl_pkey.c 48806 2014-12-12 23:19:07Z nobu $
3
2
  * 'OpenSSL for Ruby' project
4
3
  * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
5
4
  * All rights reserved.
6
5
  */
7
6
  /*
8
- * This program is licenced under the same licence as Ruby.
7
+ * This program is licensed under the same licence as Ruby.
9
8
  * (See the file 'LICENCE'.)
10
9
  */
11
10
  #include "ossl.h"
@@ -199,7 +198,7 @@ GetPrivPKeyPtr(VALUE obj)
199
198
  {
200
199
  EVP_PKEY *pkey;
201
200
 
202
- if (rb_funcall(obj, id_private_q, 0, NULL) != Qtrue) {
201
+ if (rb_funcallv(obj, id_private_q, 0, NULL) != Qtrue) {
203
202
  ossl_raise(rb_eArgError, "Private key is needed.");
204
203
  }
205
204
  SafeGetPKey(obj, pkey);
@@ -223,7 +222,7 @@ DupPrivPKeyPtr(VALUE obj)
223
222
  {
224
223
  EVP_PKEY *pkey;
225
224
 
226
- if (rb_funcall(obj, id_private_q, 0, NULL) != Qtrue) {
225
+ if (rb_funcallv(obj, id_private_q, 0, NULL) != Qtrue) {
227
226
  ossl_raise(rb_eArgError, "Private key is needed.");
228
227
  }
229
228
  SafeGetPKey(obj, pkey);
@@ -241,10 +240,11 @@ ossl_pkey_alloc(VALUE klass)
241
240
  EVP_PKEY *pkey;
242
241
  VALUE obj;
243
242
 
243
+ obj = NewPKey(klass);
244
244
  if (!(pkey = EVP_PKEY_new())) {
245
245
  ossl_raise(ePKeyError, NULL);
246
246
  }
247
- WrapPKey(klass, obj, pkey);
247
+ SetPKey(obj, pkey);
248
248
 
249
249
  return obj;
250
250
  }
@@ -289,8 +289,9 @@ ossl_pkey_sign(VALUE self, VALUE digest, VALUE data)
289
289
  EVP_MD_CTX ctx;
290
290
  unsigned int buf_len;
291
291
  VALUE str;
292
+ int result;
292
293
 
293
- if (rb_funcall(self, id_private_q, 0, NULL) != Qtrue) {
294
+ if (rb_funcallv(self, id_private_q, 0, NULL) != Qtrue) {
294
295
  ossl_raise(rb_eArgError, "Private key is needed.");
295
296
  }
296
297
  GetPKey(self, pkey);
@@ -298,7 +299,9 @@ ossl_pkey_sign(VALUE self, VALUE digest, VALUE data)
298
299
  StringValue(data);
299
300
  EVP_SignUpdate(&ctx, RSTRING_PTR(data), RSTRING_LEN(data));
300
301
  str = rb_str_new(0, EVP_PKEY_size(pkey)+16);
301
- if (!EVP_SignFinal(&ctx, (unsigned char *)RSTRING_PTR(str), &buf_len, pkey))
302
+ result = EVP_SignFinal(&ctx, (unsigned char *)RSTRING_PTR(str), &buf_len, pkey);
303
+ EVP_MD_CTX_cleanup(&ctx);
304
+ if (!result)
302
305
  ossl_raise(ePKeyError, NULL);
303
306
  assert((long)buf_len <= RSTRING_LEN(str));
304
307
  rb_str_set_len(str, buf_len);
@@ -450,4 +453,3 @@ Init_ossl_pkey(void)
450
453
  Init_ossl_dh();
451
454
  Init_ossl_ec();
452
455
  }
453
-
@@ -1,11 +1,10 @@
1
1
  /*
2
- * $Id: ossl_pkey.h 48806 2014-12-12 23:19:07Z nobu $
3
2
  * 'OpenSSL for Ruby' project
4
3
  * Copyright (C) 2001 Michal Rokos <m.rokos@sh.cvut.cz>
5
4
  * All rights reserved.
6
5
  */
7
6
  /*
8
- * This program is licenced under the same licence as Ruby.
7
+ * This program is licensed under the same licence as Ruby.
9
8
  * (See the file 'LICENCE'.)
10
9
  */
11
10
  #if !defined(_OSSL_PKEY_H_)
@@ -21,11 +20,13 @@ extern const rb_data_type_t ossl_evp_pkey_type;
21
20
  #define OSSL_PKEY_SET_PUBLIC(obj) rb_iv_set((obj), "private", Qfalse)
22
21
  #define OSSL_PKEY_IS_PRIVATE(obj) (rb_iv_get((obj), "private") == Qtrue)
23
22
 
24
- #define WrapPKey(klass, obj, pkey) do { \
23
+ #define NewPKey(klass) \
24
+ TypedData_Wrap_Struct((klass), &ossl_evp_pkey_type, 0)
25
+ #define SetPKey(obj, pkey) do { \
25
26
  if (!(pkey)) { \
26
27
  rb_raise(rb_eRuntimeError, "PKEY wasn't initialized!"); \
27
28
  } \
28
- (obj) = TypedData_Wrap_Struct((klass), &ossl_evp_pkey_type, (pkey)); \
29
+ RTYPEDDATA_DATA(obj) = (pkey); \
29
30
  OSSL_PKEY_SET_PUBLIC(obj); \
30
31
  } while (0)
31
32
  #define GetPKey(obj, pkey) do {\
@@ -82,8 +83,6 @@ void Init_ossl_dsa(void);
82
83
  */
83
84
  extern VALUE cDH;
84
85
  extern VALUE eDHError;
85
- extern DH *OSSL_DEFAULT_DH_512;
86
- extern DH *OSSL_DEFAULT_DH_1024;
87
86
 
88
87
  VALUE ossl_dh_new(EVP_PKEY *);
89
88
  void Init_ossl_dh(void);
@@ -1,11 +1,10 @@
1
1
  /*
2
- * $Id: ossl_pkey_dh.c 47744 2014-09-30 05:25:32Z nobu $
3
2
  * 'OpenSSL for Ruby' project
4
3
  * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
5
4
  * All rights reserved.
6
5
  */
7
6
  /*
8
- * This program is licenced under the same licence as Ruby.
7
+ * This program is licensed under the same licence as Ruby.
9
8
  * (See the file 'LICENCE'.)
10
9
  */
11
10
  #if !defined(OPENSSL_NO_DH)
@@ -46,6 +45,7 @@ dh_instance(VALUE klass, DH *dh)
46
45
  if (!dh) {
47
46
  return Qfalse;
48
47
  }
48
+ obj = NewPKey(klass);
49
49
  if (!(pkey = EVP_PKEY_new())) {
50
50
  return Qfalse;
51
51
  }
@@ -53,7 +53,7 @@ dh_instance(VALUE klass, DH *dh)
53
53
  EVP_PKEY_free(pkey);
54
54
  return Qfalse;
55
55
  }
56
- WrapPKey(klass, obj, pkey);
56
+ SetPKey(obj, pkey);
57
57
 
58
58
  return obj;
59
59
  }
@@ -66,10 +66,11 @@ ossl_dh_new(EVP_PKEY *pkey)
66
66
  if (!pkey) {
67
67
  obj = dh_instance(cDH, DH_new());
68
68
  } else {
69
+ obj = NewPKey(cDH);
69
70
  if (EVP_PKEY_type(pkey->type) != EVP_PKEY_DH) {
70
71
  ossl_raise(rb_eTypeError, "Not a DH key!");
71
72
  }
72
- WrapPKey(cDH, obj, pkey);
73
+ SetPKey(obj, pkey);
73
74
  }
74
75
  if (obj == Qfalse) {
75
76
  ossl_raise(eDHError, NULL);
@@ -521,69 +522,6 @@ OSSL_PKEY_BN(dh, g)
521
522
  OSSL_PKEY_BN(dh, pub_key)
522
523
  OSSL_PKEY_BN(dh, priv_key)
523
524
 
524
- /*
525
- * -----BEGIN DH PARAMETERS-----
526
- * MEYCQQD0zXHljRg/mJ9PYLACLv58Cd8VxBxxY7oEuCeURMiTqEhMym16rhhKgZG2
527
- * zk2O9uUIBIxSj+NKMURHGaFKyIvLAgEC
528
- * -----END DH PARAMETERS-----
529
- */
530
- static unsigned char DEFAULT_DH_512_PRIM[] = {
531
- 0xf4, 0xcd, 0x71, 0xe5, 0x8d, 0x18, 0x3f, 0x98,
532
- 0x9f, 0x4f, 0x60, 0xb0, 0x02, 0x2e, 0xfe, 0x7c,
533
- 0x09, 0xdf, 0x15, 0xc4, 0x1c, 0x71, 0x63, 0xba,
534
- 0x04, 0xb8, 0x27, 0x94, 0x44, 0xc8, 0x93, 0xa8,
535
- 0x48, 0x4c, 0xca, 0x6d, 0x7a, 0xae, 0x18, 0x4a,
536
- 0x81, 0x91, 0xb6, 0xce, 0x4d, 0x8e, 0xf6, 0xe5,
537
- 0x08, 0x04, 0x8c, 0x52, 0x8f, 0xe3, 0x4a, 0x31,
538
- 0x44, 0x47, 0x19, 0xa1, 0x4a, 0xc8, 0x8b, 0xcb,
539
- };
540
- static unsigned char DEFAULT_DH_512_GEN[] = { 0x02 };
541
- DH *OSSL_DEFAULT_DH_512 = NULL;
542
-
543
- /*
544
- * -----BEGIN DH PARAMETERS-----
545
- * MIGHAoGBAJ0lOVy0VIr/JebWn0zDwY2h+rqITFOpdNr6ugsgvkDXuucdcChhYExJ
546
- * AV/ZD2AWPbrTqV76mGRgJg4EddgT1zG0jq3rnFdMj2XzkBYx3BVvfR0Arnby0RHR
547
- * T4h7KZ/2zmjvV+eF8kBUHBJAojUlzxKj4QeO2x20FP9X5xmNUXeDAgEC
548
- * -----END DH PARAMETERS-----
549
- */
550
- static unsigned char DEFAULT_DH_1024_PRIM[] = {
551
- 0x9d, 0x25, 0x39, 0x5c, 0xb4, 0x54, 0x8a, 0xff,
552
- 0x25, 0xe6, 0xd6, 0x9f, 0x4c, 0xc3, 0xc1, 0x8d,
553
- 0xa1, 0xfa, 0xba, 0x88, 0x4c, 0x53, 0xa9, 0x74,
554
- 0xda, 0xfa, 0xba, 0x0b, 0x20, 0xbe, 0x40, 0xd7,
555
- 0xba, 0xe7, 0x1d, 0x70, 0x28, 0x61, 0x60, 0x4c,
556
- 0x49, 0x01, 0x5f, 0xd9, 0x0f, 0x60, 0x16, 0x3d,
557
- 0xba, 0xd3, 0xa9, 0x5e, 0xfa, 0x98, 0x64, 0x60,
558
- 0x26, 0x0e, 0x04, 0x75, 0xd8, 0x13, 0xd7, 0x31,
559
- 0xb4, 0x8e, 0xad, 0xeb, 0x9c, 0x57, 0x4c, 0x8f,
560
- 0x65, 0xf3, 0x90, 0x16, 0x31, 0xdc, 0x15, 0x6f,
561
- 0x7d, 0x1d, 0x00, 0xae, 0x76, 0xf2, 0xd1, 0x11,
562
- 0xd1, 0x4f, 0x88, 0x7b, 0x29, 0x9f, 0xf6, 0xce,
563
- 0x68, 0xef, 0x57, 0xe7, 0x85, 0xf2, 0x40, 0x54,
564
- 0x1c, 0x12, 0x40, 0xa2, 0x35, 0x25, 0xcf, 0x12,
565
- 0xa3, 0xe1, 0x07, 0x8e, 0xdb, 0x1d, 0xb4, 0x14,
566
- 0xff, 0x57, 0xe7, 0x19, 0x8d, 0x51, 0x77, 0x83
567
- };
568
- static unsigned char DEFAULT_DH_1024_GEN[] = { 0x02 };
569
- DH *OSSL_DEFAULT_DH_1024 = NULL;
570
-
571
- static DH*
572
- ossl_create_dh(unsigned char *p, size_t plen, unsigned char *g, size_t glen)
573
- {
574
- DH *dh;
575
-
576
- if ((dh = DH_new()) == NULL) ossl_raise(eDHError, NULL);
577
- dh->p = BN_bin2bn(p, rb_long2int(plen), NULL);
578
- dh->g = BN_bin2bn(g, rb_long2int(glen), NULL);
579
- if (dh->p == NULL || dh->g == NULL){
580
- DH_free(dh);
581
- ossl_raise(eDHError, NULL);
582
- }
583
-
584
- return dh;
585
- }
586
-
587
525
  /*
588
526
  * INIT
589
527
  */
@@ -649,13 +587,6 @@ Init_ossl_dh(void)
649
587
  DEF_OSSL_PKEY_BN(cDH, dh, pub_key);
650
588
  DEF_OSSL_PKEY_BN(cDH, dh, priv_key);
651
589
  rb_define_method(cDH, "params", ossl_dh_get_params, 0);
652
-
653
- OSSL_DEFAULT_DH_512 = ossl_create_dh(
654
- DEFAULT_DH_512_PRIM, sizeof(DEFAULT_DH_512_PRIM),
655
- DEFAULT_DH_512_GEN, sizeof(DEFAULT_DH_512_GEN));
656
- OSSL_DEFAULT_DH_1024 = ossl_create_dh(
657
- DEFAULT_DH_1024_PRIM, sizeof(DEFAULT_DH_1024_PRIM),
658
- DEFAULT_DH_1024_GEN, sizeof(DEFAULT_DH_1024_GEN));
659
590
  }
660
591
 
661
592
  #else /* defined NO_DH */