openssl 2.1.4 → 2.2.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 +4 -4
- data/CONTRIBUTING.md +9 -7
- data/History.md +68 -37
- data/README.md +2 -2
- data/ext/openssl/extconf.rb +43 -41
- data/ext/openssl/openssl_missing.h +36 -1
- data/ext/openssl/ossl.c +49 -23
- data/ext/openssl/ossl.h +7 -4
- data/ext/openssl/ossl_asn1.c +25 -0
- data/ext/openssl/ossl_bn.c +16 -23
- data/ext/openssl/ossl_cipher.c +33 -24
- data/ext/openssl/ossl_digest.c +18 -57
- data/ext/openssl/ossl_engine.c +2 -12
- data/ext/openssl/ossl_hmac.c +5 -11
- data/ext/openssl/ossl_kdf.c +3 -19
- data/ext/openssl/ossl_ns_spki.c +1 -1
- data/ext/openssl/ossl_ocsp.c +6 -11
- data/ext/openssl/ossl_ocsp.h +3 -3
- data/ext/openssl/ossl_pkcs7.c +3 -19
- data/ext/openssl/ossl_pkcs7.h +16 -0
- data/ext/openssl/ossl_pkey.c +180 -14
- data/ext/openssl/ossl_pkey_dsa.c +2 -2
- data/ext/openssl/ossl_pkey_ec.c +37 -8
- data/ext/openssl/ossl_pkey_rsa.c +17 -9
- data/ext/openssl/ossl_rand.c +2 -32
- data/ext/openssl/ossl_ssl.c +78 -72
- data/ext/openssl/ossl_ts.c +1514 -0
- data/ext/openssl/ossl_ts.h +16 -0
- data/ext/openssl/ossl_x509cert.c +2 -2
- data/ext/openssl/ossl_x509ext.c +14 -0
- data/ext/openssl/ossl_x509name.c +7 -3
- data/ext/openssl/ossl_x509store.c +20 -39
- data/lib/openssl/bn.rb +1 -1
- data/lib/openssl/buffering.rb +28 -5
- data/lib/openssl/cipher.rb +1 -1
- data/lib/openssl/config.rb +17 -8
- data/lib/openssl/digest.rb +10 -12
- data/lib/openssl/hmac.rb +13 -0
- data/lib/openssl/marshal.rb +30 -0
- data/lib/openssl/pkcs5.rb +1 -1
- data/lib/openssl/pkey.rb +18 -1
- data/lib/openssl/ssl.rb +40 -2
- data/lib/openssl/version.rb +5 -0
- data/lib/openssl/x509.rb +155 -1
- data/lib/openssl.rb +25 -9
- metadata +13 -24
- data/ext/openssl/deprecation.rb +0 -27
- data/ext/openssl/ossl_version.h +0 -15
data/ext/openssl/ossl_bn.c
CHANGED
@@ -173,7 +173,6 @@ ossl_bn_alloc(VALUE klass)
|
|
173
173
|
|
174
174
|
/*
|
175
175
|
* call-seq:
|
176
|
-
* OpenSSL::BN.new => aBN
|
177
176
|
* OpenSSL::BN.new(bn) => aBN
|
178
177
|
* OpenSSL::BN.new(integer) => aBN
|
179
178
|
* OpenSSL::BN.new(string) => aBN
|
@@ -193,6 +192,10 @@ ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
|
|
193
192
|
base = NUM2INT(bs);
|
194
193
|
}
|
195
194
|
|
195
|
+
if (NIL_P(str)) {
|
196
|
+
ossl_raise(rb_eArgError, "invalid argument");
|
197
|
+
}
|
198
|
+
|
196
199
|
if (RB_INTEGER_TYPE_P(str)) {
|
197
200
|
GetBN(self, bn);
|
198
201
|
integer_to_bnptr(str, bn);
|
@@ -400,7 +403,7 @@ ossl_bn_is_negative(VALUE self)
|
|
400
403
|
if (!(result = BN_new())) { \
|
401
404
|
ossl_raise(eBNError, NULL); \
|
402
405
|
} \
|
403
|
-
if (BN_##func(result, bn, ossl_bn_ctx)
|
406
|
+
if (!BN_##func(result, bn, ossl_bn_ctx)) { \
|
404
407
|
BN_free(result); \
|
405
408
|
ossl_raise(eBNError, NULL); \
|
406
409
|
} \
|
@@ -426,7 +429,7 @@ BIGNUM_1c(sqr)
|
|
426
429
|
if (!(result = BN_new())) { \
|
427
430
|
ossl_raise(eBNError, NULL); \
|
428
431
|
} \
|
429
|
-
if (BN_##func(result, bn1, bn2)
|
432
|
+
if (!BN_##func(result, bn1, bn2)) { \
|
430
433
|
BN_free(result); \
|
431
434
|
ossl_raise(eBNError, NULL); \
|
432
435
|
} \
|
@@ -459,7 +462,7 @@ BIGNUM_2(sub)
|
|
459
462
|
if (!(result = BN_new())) { \
|
460
463
|
ossl_raise(eBNError, NULL); \
|
461
464
|
} \
|
462
|
-
if (BN_##func(result, bn1, bn2, ossl_bn_ctx)
|
465
|
+
if (!BN_##func(result, bn1, bn2, ossl_bn_ctx)) { \
|
463
466
|
BN_free(result); \
|
464
467
|
ossl_raise(eBNError, NULL); \
|
465
468
|
} \
|
@@ -503,21 +506,11 @@ BIGNUM_2c(gcd)
|
|
503
506
|
BIGNUM_2c(mod_sqr)
|
504
507
|
|
505
508
|
/*
|
509
|
+
* Document-method: OpenSSL::BN#mod_inverse
|
506
510
|
* call-seq:
|
507
|
-
*
|
511
|
+
* bn.mod_inverse(bn2) => aBN
|
508
512
|
*/
|
509
|
-
|
510
|
-
ossl_bn_mod_inverse(VALUE self, VALUE other)
|
511
|
-
{
|
512
|
-
BIGNUM *bn1, *bn2 = GetBNPtr(other), *result;
|
513
|
-
VALUE obj;
|
514
|
-
GetBN(self, bn1);
|
515
|
-
obj = NewBN(rb_obj_class(self));
|
516
|
-
if (!(result = BN_mod_inverse(NULL, bn1, bn2, ossl_bn_ctx)))
|
517
|
-
ossl_raise(eBNError, "BN_mod_inverse");
|
518
|
-
SetBN(obj, result);
|
519
|
-
return obj;
|
520
|
-
}
|
513
|
+
BIGNUM_2c(mod_inverse)
|
521
514
|
|
522
515
|
/*
|
523
516
|
* call-seq:
|
@@ -566,7 +559,7 @@ ossl_bn_div(VALUE self, VALUE other)
|
|
566
559
|
if (!(result = BN_new())) { \
|
567
560
|
ossl_raise(eBNError, NULL); \
|
568
561
|
} \
|
569
|
-
if (BN_##func(result, bn1, bn2, bn3, ossl_bn_ctx)
|
562
|
+
if (!BN_##func(result, bn1, bn2, bn3, ossl_bn_ctx)) { \
|
570
563
|
BN_free(result); \
|
571
564
|
ossl_raise(eBNError, NULL); \
|
572
565
|
} \
|
@@ -608,7 +601,7 @@ BIGNUM_3c(mod_exp)
|
|
608
601
|
{ \
|
609
602
|
BIGNUM *bn; \
|
610
603
|
GetBN(self, bn); \
|
611
|
-
if (BN_##func(bn, NUM2INT(bit))
|
604
|
+
if (!BN_##func(bn, NUM2INT(bit))) { \
|
612
605
|
ossl_raise(eBNError, NULL); \
|
613
606
|
} \
|
614
607
|
return self; \
|
@@ -668,7 +661,7 @@ ossl_bn_is_bit_set(VALUE self, VALUE bit)
|
|
668
661
|
if (!(result = BN_new())) { \
|
669
662
|
ossl_raise(eBNError, NULL); \
|
670
663
|
} \
|
671
|
-
if (BN_##func(result, bn, b)
|
664
|
+
if (!BN_##func(result, bn, b)) { \
|
672
665
|
BN_free(result); \
|
673
666
|
ossl_raise(eBNError, NULL); \
|
674
667
|
} \
|
@@ -698,7 +691,7 @@ BIGNUM_SHIFT(rshift)
|
|
698
691
|
int b; \
|
699
692
|
b = NUM2INT(bits); \
|
700
693
|
GetBN(self, bn); \
|
701
|
-
if (BN_##func(bn, bn, b)
|
694
|
+
if (!BN_##func(bn, bn, b)) \
|
702
695
|
ossl_raise(eBNError, NULL); \
|
703
696
|
return self; \
|
704
697
|
}
|
@@ -737,7 +730,7 @@ BIGNUM_SELF_SHIFT(rshift)
|
|
737
730
|
if (!(result = BN_new())) { \
|
738
731
|
ossl_raise(eBNError, NULL); \
|
739
732
|
} \
|
740
|
-
if (BN_##func(result, b, top, bottom)
|
733
|
+
if (!BN_##func(result, b, top, bottom)) { \
|
741
734
|
BN_free(result); \
|
742
735
|
ossl_raise(eBNError, NULL); \
|
743
736
|
} \
|
@@ -766,7 +759,7 @@ BIGNUM_RAND(pseudo_rand)
|
|
766
759
|
if (!(result = BN_new())) { \
|
767
760
|
ossl_raise(eBNError, NULL); \
|
768
761
|
} \
|
769
|
-
if (BN_##func##_range(result, bn)
|
762
|
+
if (!BN_##func##_range(result, bn)) { \
|
770
763
|
BN_free(result); \
|
771
764
|
ossl_raise(eBNError, NULL); \
|
772
765
|
} \
|
data/ext/openssl/ossl_cipher.c
CHANGED
@@ -104,7 +104,7 @@ ossl_cipher_alloc(VALUE klass)
|
|
104
104
|
* call-seq:
|
105
105
|
* Cipher.new(string) -> cipher
|
106
106
|
*
|
107
|
-
* The string must
|
107
|
+
* The string must contain a valid cipher name like "AES-256-CBC".
|
108
108
|
*
|
109
109
|
* A list of cipher names is available by calling OpenSSL::Cipher.ciphers.
|
110
110
|
*/
|
@@ -237,8 +237,7 @@ ossl_cipher_init(int argc, VALUE *argv, VALUE self, int mode)
|
|
237
237
|
ossl_raise(eCipherError, NULL);
|
238
238
|
}
|
239
239
|
|
240
|
-
|
241
|
-
rb_ivar_set(self, id_key_set, Qtrue);
|
240
|
+
rb_ivar_set(self, id_key_set, p_key ? Qtrue : Qfalse);
|
242
241
|
|
243
242
|
return self;
|
244
243
|
}
|
@@ -814,6 +813,31 @@ ossl_cipher_block_size(VALUE self)
|
|
814
813
|
return INT2NUM(EVP_CIPHER_CTX_block_size(ctx));
|
815
814
|
}
|
816
815
|
|
816
|
+
/*
|
817
|
+
* call-seq:
|
818
|
+
* cipher.ccm_data_len = integer -> integer
|
819
|
+
*
|
820
|
+
* Sets the length of the plaintext / ciphertext message that will be
|
821
|
+
* processed in CCM mode. Make sure to call this method after #key= and
|
822
|
+
* #iv= have been set, and before #auth_data=.
|
823
|
+
*
|
824
|
+
* Only call this method after calling Cipher#encrypt or Cipher#decrypt.
|
825
|
+
*/
|
826
|
+
static VALUE
|
827
|
+
ossl_cipher_set_ccm_data_len(VALUE self, VALUE data_len)
|
828
|
+
{
|
829
|
+
int in_len, out_len;
|
830
|
+
EVP_CIPHER_CTX *ctx;
|
831
|
+
|
832
|
+
in_len = NUM2INT(data_len);
|
833
|
+
|
834
|
+
GetCipher(self, ctx);
|
835
|
+
if (EVP_CipherUpdate(ctx, NULL, &out_len, NULL, in_len) != 1)
|
836
|
+
ossl_raise(eCipherError, NULL);
|
837
|
+
|
838
|
+
return data_len;
|
839
|
+
}
|
840
|
+
|
817
841
|
/*
|
818
842
|
* INIT
|
819
843
|
*/
|
@@ -852,22 +876,6 @@ Init_ossl_cipher(void)
|
|
852
876
|
*
|
853
877
|
* cipher = OpenSSL::Cipher.new('AES-128-CBC')
|
854
878
|
*
|
855
|
-
* For each algorithm supported, there is a class defined under the
|
856
|
-
* Cipher class that goes by the name of the cipher, e.g. to obtain an
|
857
|
-
* instance of AES, you could also use
|
858
|
-
*
|
859
|
-
* # these are equivalent
|
860
|
-
* cipher = OpenSSL::Cipher::AES.new(128, :CBC)
|
861
|
-
* cipher = OpenSSL::Cipher::AES.new(128, 'CBC')
|
862
|
-
* cipher = OpenSSL::Cipher::AES.new('128-CBC')
|
863
|
-
*
|
864
|
-
* Finally, due to its wide-spread use, there are also extra classes
|
865
|
-
* defined for the different key sizes of AES
|
866
|
-
*
|
867
|
-
* cipher = OpenSSL::Cipher::AES128.new(:CBC)
|
868
|
-
* cipher = OpenSSL::Cipher::AES192.new(:CBC)
|
869
|
-
* cipher = OpenSSL::Cipher::AES256.new(:CBC)
|
870
|
-
*
|
871
879
|
* === Choosing either encryption or decryption mode
|
872
880
|
*
|
873
881
|
* Encryption and decryption are often very similar operations for
|
@@ -896,7 +904,7 @@ Init_ossl_cipher(void)
|
|
896
904
|
* without processing the password further. A simple and secure way to
|
897
905
|
* create a key for a particular Cipher is
|
898
906
|
*
|
899
|
-
* cipher = OpenSSL::
|
907
|
+
* cipher = OpenSSL::Cipher.new('AES-256-CFB')
|
900
908
|
* cipher.encrypt
|
901
909
|
* key = cipher.random_key # also sets the generated key on the Cipher
|
902
910
|
*
|
@@ -964,14 +972,14 @@ Init_ossl_cipher(void)
|
|
964
972
|
*
|
965
973
|
* data = "Very, very confidential data"
|
966
974
|
*
|
967
|
-
* cipher = OpenSSL::Cipher
|
975
|
+
* cipher = OpenSSL::Cipher.new('AES-128-CBC')
|
968
976
|
* cipher.encrypt
|
969
977
|
* key = cipher.random_key
|
970
978
|
* iv = cipher.random_iv
|
971
979
|
*
|
972
980
|
* encrypted = cipher.update(data) + cipher.final
|
973
981
|
* ...
|
974
|
-
* decipher = OpenSSL::Cipher
|
982
|
+
* decipher = OpenSSL::Cipher.new('AES-128-CBC')
|
975
983
|
* decipher.decrypt
|
976
984
|
* decipher.key = key
|
977
985
|
* decipher.iv = iv
|
@@ -1007,7 +1015,7 @@ Init_ossl_cipher(void)
|
|
1007
1015
|
* not to reuse the _key_ and _nonce_ pair. Reusing an nonce ruins the
|
1008
1016
|
* security guarantees of GCM mode.
|
1009
1017
|
*
|
1010
|
-
* cipher = OpenSSL::Cipher
|
1018
|
+
* cipher = OpenSSL::Cipher.new('AES-128-GCM').encrypt
|
1011
1019
|
* cipher.key = key
|
1012
1020
|
* cipher.iv = nonce
|
1013
1021
|
* cipher.auth_data = auth_data
|
@@ -1023,7 +1031,7 @@ Init_ossl_cipher(void)
|
|
1023
1031
|
* ciphertext with a probability of 1/256.
|
1024
1032
|
*
|
1025
1033
|
* raise "tag is truncated!" unless tag.bytesize == 16
|
1026
|
-
* decipher = OpenSSL::Cipher
|
1034
|
+
* decipher = OpenSSL::Cipher.new('AES-128-GCM').decrypt
|
1027
1035
|
* decipher.key = key
|
1028
1036
|
* decipher.iv = nonce
|
1029
1037
|
* decipher.auth_tag = tag
|
@@ -1060,6 +1068,7 @@ Init_ossl_cipher(void)
|
|
1060
1068
|
rb_define_method(cCipher, "iv_len", ossl_cipher_iv_length, 0);
|
1061
1069
|
rb_define_method(cCipher, "block_size", ossl_cipher_block_size, 0);
|
1062
1070
|
rb_define_method(cCipher, "padding=", ossl_cipher_set_padding, 1);
|
1071
|
+
rb_define_method(cCipher, "ccm_data_len=", ossl_cipher_set_ccm_data_len, 1);
|
1063
1072
|
|
1064
1073
|
id_auth_tag_len = rb_intern_const("auth_tag_len");
|
1065
1074
|
id_key_set = rb_intern_const("key_set");
|
data/ext/openssl/ossl_digest.c
CHANGED
@@ -192,7 +192,7 @@ ossl_digest_reset(VALUE self)
|
|
192
192
|
* be passed individually to the Digest instance.
|
193
193
|
*
|
194
194
|
* === Example
|
195
|
-
* digest = OpenSSL::Digest
|
195
|
+
* digest = OpenSSL::Digest.new('SHA256')
|
196
196
|
* digest.update('First input')
|
197
197
|
* digest << 'Second input' # equivalent to digest.update('Second input')
|
198
198
|
* result = digest.digest
|
@@ -248,7 +248,7 @@ ossl_digest_finish(int argc, VALUE *argv, VALUE self)
|
|
248
248
|
* Returns the sn of this Digest algorithm.
|
249
249
|
*
|
250
250
|
* === Example
|
251
|
-
* digest = OpenSSL::Digest
|
251
|
+
* digest = OpenSSL::Digest.new('SHA512')
|
252
252
|
* puts digest.name # => SHA512
|
253
253
|
*
|
254
254
|
*/
|
@@ -270,7 +270,7 @@ ossl_digest_name(VALUE self)
|
|
270
270
|
* final message digest result.
|
271
271
|
*
|
272
272
|
* === Example
|
273
|
-
* digest = OpenSSL::Digest
|
273
|
+
* digest = OpenSSL::Digest.new('SHA1')
|
274
274
|
* puts digest.digest_length # => 20
|
275
275
|
*
|
276
276
|
*/
|
@@ -294,7 +294,7 @@ ossl_digest_size(VALUE self)
|
|
294
294
|
* consecutively.
|
295
295
|
*
|
296
296
|
* === Example
|
297
|
-
* digest = OpenSSL::Digest
|
297
|
+
* digest = OpenSSL::Digest.new('SHA1')
|
298
298
|
* puts digest.block_length # => 64
|
299
299
|
*/
|
300
300
|
static VALUE
|
@@ -313,6 +313,8 @@ ossl_digest_block_length(VALUE self)
|
|
313
313
|
void
|
314
314
|
Init_ossl_digest(void)
|
315
315
|
{
|
316
|
+
rb_require("digest");
|
317
|
+
|
316
318
|
#if 0
|
317
319
|
mOSSL = rb_define_module("OpenSSL");
|
318
320
|
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
@@ -346,54 +348,19 @@ Init_ossl_digest(void)
|
|
346
348
|
* the integrity of a signed document, it suffices to re-compute the hash
|
347
349
|
* and verify that it is equal to that in the signature.
|
348
350
|
*
|
349
|
-
*
|
350
|
-
*
|
351
|
-
* * MD2, MD4, MDC2 and MD5
|
352
|
-
* * RIPEMD160
|
353
|
-
* * DSS, DSS1 (Pseudo algorithms to be used for DSA signatures. DSS is
|
354
|
-
* equal to SHA and DSS1 is equal to SHA1)
|
351
|
+
* You can get a list of all digest algorithms supported on your system by
|
352
|
+
* running this command in your terminal:
|
355
353
|
*
|
356
|
-
*
|
357
|
-
* can be instantiated as simply as e.g.
|
354
|
+
* openssl list -digest-algorithms
|
358
355
|
*
|
359
|
-
*
|
356
|
+
* Among the OpenSSL 1.1.1 supported message digest algorithms are:
|
357
|
+
* * SHA224, SHA256, SHA384, SHA512, SHA512-224 and SHA512-256
|
358
|
+
* * SHA3-224, SHA3-256, SHA3-384 and SHA3-512
|
359
|
+
* * BLAKE2s256 and BLAKE2b512
|
360
360
|
*
|
361
|
-
*
|
361
|
+
* Each of these algorithms can be instantiated using the name:
|
362
362
|
*
|
363
|
-
*
|
364
|
-
* <openssl/object.h> and <openssl/obj_mac.h>. They are textual
|
365
|
-
* representations of ASN.1 OBJECT IDENTIFIERs. Each supported digest
|
366
|
-
* algorithm has an OBJECT IDENTIFIER associated to it and those again
|
367
|
-
* have short/long names assigned to them.
|
368
|
-
* E.g. the OBJECT IDENTIFIER for SHA-1 is 1.3.14.3.2.26 and its
|
369
|
-
* sn is "SHA1" and its ln is "sha1".
|
370
|
-
* ==== MD2
|
371
|
-
* * sn: MD2
|
372
|
-
* * ln: md2
|
373
|
-
* ==== MD4
|
374
|
-
* * sn: MD4
|
375
|
-
* * ln: md4
|
376
|
-
* ==== MD5
|
377
|
-
* * sn: MD5
|
378
|
-
* * ln: md5
|
379
|
-
* ==== SHA
|
380
|
-
* * sn: SHA
|
381
|
-
* * ln: SHA
|
382
|
-
* ==== SHA-1
|
383
|
-
* * sn: SHA1
|
384
|
-
* * ln: sha1
|
385
|
-
* ==== SHA-224
|
386
|
-
* * sn: SHA224
|
387
|
-
* * ln: sha224
|
388
|
-
* ==== SHA-256
|
389
|
-
* * sn: SHA256
|
390
|
-
* * ln: sha256
|
391
|
-
* ==== SHA-384
|
392
|
-
* * sn: SHA384
|
393
|
-
* * ln: sha384
|
394
|
-
* ==== SHA-512
|
395
|
-
* * sn: SHA512
|
396
|
-
* * ln: sha512
|
363
|
+
* digest = OpenSSL::Digest.new('SHA256')
|
397
364
|
*
|
398
365
|
* "Breaking" a message digest algorithm means defying its one-way
|
399
366
|
* function characteristics, i.e. producing a collision or finding a way
|
@@ -406,7 +373,7 @@ Init_ossl_digest(void)
|
|
406
373
|
* === Hashing a file
|
407
374
|
*
|
408
375
|
* data = File.read('document')
|
409
|
-
* sha256 = OpenSSL::Digest
|
376
|
+
* sha256 = OpenSSL::Digest.new('SHA256')
|
410
377
|
* digest = sha256.digest(data)
|
411
378
|
*
|
412
379
|
* === Hashing several pieces of data at once
|
@@ -414,7 +381,7 @@ Init_ossl_digest(void)
|
|
414
381
|
* data1 = File.read('file1')
|
415
382
|
* data2 = File.read('file2')
|
416
383
|
* data3 = File.read('file3')
|
417
|
-
* sha256 = OpenSSL::Digest
|
384
|
+
* sha256 = OpenSSL::Digest.new('SHA256')
|
418
385
|
* sha256 << data1
|
419
386
|
* sha256 << data2
|
420
387
|
* sha256 << data3
|
@@ -423,7 +390,7 @@ Init_ossl_digest(void)
|
|
423
390
|
* === Reuse a Digest instance
|
424
391
|
*
|
425
392
|
* data1 = File.read('file1')
|
426
|
-
* sha256 = OpenSSL::Digest
|
393
|
+
* sha256 = OpenSSL::Digest.new('SHA256')
|
427
394
|
* digest1 = sha256.digest(data1)
|
428
395
|
*
|
429
396
|
* data2 = File.read('file2')
|
@@ -431,12 +398,6 @@ Init_ossl_digest(void)
|
|
431
398
|
* digest2 = sha256.digest(data2)
|
432
399
|
*
|
433
400
|
*/
|
434
|
-
|
435
|
-
/*
|
436
|
-
* Digest::Class is defined by the digest library. rb_require() cannot be
|
437
|
-
* used here because it bypasses RubyGems.
|
438
|
-
*/
|
439
|
-
rb_funcall(Qnil, rb_intern_const("require"), 1, rb_str_new_cstr("digest"));
|
440
401
|
cDigest = rb_define_class_under(mOSSL, "Digest", rb_path2class("Digest::Class"));
|
441
402
|
/* Document-class: OpenSSL::Digest::DigestError
|
442
403
|
*
|
data/ext/openssl/ossl_engine.c
CHANGED
@@ -93,9 +93,6 @@ static const rb_data_type_t ossl_engine_type = {
|
|
93
93
|
static VALUE
|
94
94
|
ossl_engine_s_load(int argc, VALUE *argv, VALUE klass)
|
95
95
|
{
|
96
|
-
#if !defined(HAVE_ENGINE_LOAD_BUILTIN_ENGINES)
|
97
|
-
return Qnil;
|
98
|
-
#else
|
99
96
|
VALUE name;
|
100
97
|
|
101
98
|
rb_scan_args(argc, argv, "01", &name);
|
@@ -104,10 +101,10 @@ ossl_engine_s_load(int argc, VALUE *argv, VALUE klass)
|
|
104
101
|
return Qtrue;
|
105
102
|
}
|
106
103
|
StringValueCStr(name);
|
107
|
-
#ifndef OPENSSL_NO_STATIC_ENGINE
|
108
104
|
#if HAVE_ENGINE_LOAD_DYNAMIC
|
109
105
|
OSSL_ENGINE_LOAD_IF_MATCH(dynamic, DYNAMIC);
|
110
106
|
#endif
|
107
|
+
#ifndef OPENSSL_NO_STATIC_ENGINE
|
111
108
|
#if HAVE_ENGINE_LOAD_4758CCA
|
112
109
|
OSSL_ENGINE_LOAD_IF_MATCH(4758cca, 4758CCA);
|
113
110
|
#endif
|
@@ -144,20 +141,13 @@ ossl_engine_s_load(int argc, VALUE *argv, VALUE klass)
|
|
144
141
|
#if HAVE_ENGINE_LOAD_GOST
|
145
142
|
OSSL_ENGINE_LOAD_IF_MATCH(gost, GOST);
|
146
143
|
#endif
|
144
|
+
#endif
|
147
145
|
#if HAVE_ENGINE_LOAD_CRYPTODEV
|
148
146
|
OSSL_ENGINE_LOAD_IF_MATCH(cryptodev, CRYPTODEV);
|
149
|
-
#endif
|
150
|
-
#if HAVE_ENGINE_LOAD_AESNI
|
151
|
-
OSSL_ENGINE_LOAD_IF_MATCH(aesni, AESNI);
|
152
|
-
#endif
|
153
|
-
#endif
|
154
|
-
#ifdef HAVE_ENGINE_LOAD_OPENBSD_DEV_CRYPTO
|
155
|
-
OSSL_ENGINE_LOAD_IF_MATCH(openbsd_dev_crypto, OPENBSD_DEV_CRYPTO);
|
156
147
|
#endif
|
157
148
|
OSSL_ENGINE_LOAD_IF_MATCH(openssl, OPENSSL);
|
158
149
|
rb_warning("no such builtin loader for `%"PRIsVALUE"'", name);
|
159
150
|
return Qnil;
|
160
|
-
#endif /* HAVE_ENGINE_LOAD_BUILTIN_ENGINES */
|
161
151
|
}
|
162
152
|
|
163
153
|
/*
|
data/ext/openssl/ossl_hmac.c
CHANGED
@@ -84,18 +84,12 @@ ossl_hmac_alloc(VALUE klass)
|
|
84
84
|
*
|
85
85
|
* === A note about comparisons
|
86
86
|
*
|
87
|
-
* Two instances
|
88
|
-
* same value. Use #to_s or #hexdigest to return the authentication code that
|
89
|
-
* the instance represents. For example:
|
87
|
+
* Two instances can be securely compared with #== in constant time:
|
90
88
|
*
|
91
89
|
* other_instance = OpenSSL::HMAC.new('key', OpenSSL::Digest.new('sha1'))
|
92
|
-
*
|
93
|
-
*
|
94
|
-
*
|
95
|
-
* instance == other_instance
|
96
|
-
* #=> false
|
97
|
-
* instance.to_s == other_instance.to_s
|
98
|
-
* #=> true
|
90
|
+
* #=> f42bb0eeb018ebbd4597ae7213711ec60760843f
|
91
|
+
* instance == other_instance
|
92
|
+
* #=> true
|
99
93
|
*
|
100
94
|
*/
|
101
95
|
static VALUE
|
@@ -359,7 +353,7 @@ Init_ossl_hmac(void)
|
|
359
353
|
* data1 = File.read("file1")
|
360
354
|
* data2 = File.read("file2")
|
361
355
|
* key = "key"
|
362
|
-
* digest = OpenSSL::Digest
|
356
|
+
* digest = OpenSSL::Digest.new('SHA256')
|
363
357
|
* hmac = OpenSSL::HMAC.new(key, digest)
|
364
358
|
* hmac << data1
|
365
359
|
* hmac << data2
|
data/ext/openssl/ossl_kdf.c
CHANGED
@@ -272,7 +272,7 @@ Init_ossl_kdf(void)
|
|
272
272
|
* # store this with the generated value
|
273
273
|
* salt = OpenSSL::Random.random_bytes(16)
|
274
274
|
* iter = 20_000
|
275
|
-
* hash = OpenSSL::Digest
|
275
|
+
* hash = OpenSSL::Digest.new('SHA256')
|
276
276
|
* len = hash.digest_length
|
277
277
|
* # the final value to be stored
|
278
278
|
* value = OpenSSL::KDF.pbkdf2_hmac(pass, salt: salt, iterations: iter,
|
@@ -284,24 +284,8 @@ Init_ossl_kdf(void)
|
|
284
284
|
* Typically, "==" short-circuits on evaluation, and is therefore
|
285
285
|
* vulnerable to timing attacks. The proper way is to use a method that
|
286
286
|
* always takes the same amount of time when comparing two values, thus
|
287
|
-
* not leaking any information to potential attackers. To
|
288
|
-
*
|
289
|
-
*
|
290
|
-
* def eql_time_cmp(a, b)
|
291
|
-
* unless a.length == b.length
|
292
|
-
* return false
|
293
|
-
* end
|
294
|
-
* cmp = b.bytes
|
295
|
-
* result = 0
|
296
|
-
* a.bytes.each_with_index {|c,i|
|
297
|
-
* result |= c ^ cmp[i]
|
298
|
-
* }
|
299
|
-
* result == 0
|
300
|
-
* end
|
301
|
-
*
|
302
|
-
* Please note that the premature return in case of differing lengths
|
303
|
-
* typically does not leak valuable information - when using PBKDF2, the
|
304
|
-
* length of the values to be compared is of fixed size.
|
287
|
+
* not leaking any information to potential attackers. To do this, use
|
288
|
+
* +OpenSSL.fixed_length_secure_compare+.
|
305
289
|
*/
|
306
290
|
mKDF = rb_define_module_under(mOSSL, "KDF");
|
307
291
|
/*
|
data/ext/openssl/ossl_ns_spki.c
CHANGED
@@ -350,7 +350,7 @@ ossl_spki_verify(VALUE self, VALUE key)
|
|
350
350
|
* spki = OpenSSL::Netscape::SPKI.new
|
351
351
|
* spki.challenge = "RandomChallenge"
|
352
352
|
* spki.public_key = key.public_key
|
353
|
-
* spki.sign(key, OpenSSL::Digest
|
353
|
+
* spki.sign(key, OpenSSL::Digest.new('SHA256'))
|
354
354
|
* #send a request containing this to a server generating a certificate
|
355
355
|
* === Verifying an SPKI request
|
356
356
|
* request = #...
|
data/ext/openssl/ossl_ocsp.c
CHANGED
@@ -1489,13 +1489,15 @@ ossl_ocspcid_initialize_copy(VALUE self, VALUE other)
|
|
1489
1489
|
* call-seq:
|
1490
1490
|
* OpenSSL::OCSP::CertificateId.new(subject, issuer, digest = nil) -> certificate_id
|
1491
1491
|
* OpenSSL::OCSP::CertificateId.new(der_string) -> certificate_id
|
1492
|
+
* OpenSSL::OCSP::CertificateId.new(obj) -> certificate_id
|
1492
1493
|
*
|
1493
1494
|
* Creates a new OpenSSL::OCSP::CertificateId for the given _subject_ and
|
1494
1495
|
* _issuer_ X509 certificates. The _digest_ is a digest algorithm that is used
|
1495
1496
|
* to compute the hash values. This defaults to SHA-1.
|
1496
1497
|
*
|
1497
1498
|
* If only one argument is given, decodes it as DER representation of a
|
1498
|
-
* certificate ID
|
1499
|
+
* certificate ID or generates certificate ID from the object that responds to
|
1500
|
+
* the to_der method.
|
1499
1501
|
*/
|
1500
1502
|
static VALUE
|
1501
1503
|
ossl_ocspcid_initialize(int argc, VALUE *argv, VALUE self)
|
@@ -1717,7 +1719,7 @@ Init_ossl_ocsp(void)
|
|
1717
1719
|
* subject certificate so the CA knows which certificate we are asking
|
1718
1720
|
* about:
|
1719
1721
|
*
|
1720
|
-
* digest = OpenSSL::Digest
|
1722
|
+
* digest = OpenSSL::Digest.new('SHA1')
|
1721
1723
|
* certificate_id =
|
1722
1724
|
* OpenSSL::OCSP::CertificateId.new subject, issuer, digest
|
1723
1725
|
*
|
@@ -1734,18 +1736,11 @@ Init_ossl_ocsp(void)
|
|
1734
1736
|
* To submit the request to the CA for verification we need to extract the
|
1735
1737
|
* OCSP URI from the subject certificate:
|
1736
1738
|
*
|
1737
|
-
*
|
1738
|
-
* extension.oid == 'authorityInfoAccess'
|
1739
|
-
* end
|
1740
|
-
*
|
1741
|
-
* descriptions = authority_info_access.value.split "\n"
|
1742
|
-
* ocsp = descriptions.find do |description|
|
1743
|
-
* description.start_with? 'OCSP'
|
1744
|
-
* end
|
1739
|
+
* ocsp_uris = subject.ocsp_uris
|
1745
1740
|
*
|
1746
1741
|
* require 'uri'
|
1747
1742
|
*
|
1748
|
-
* ocsp_uri = URI
|
1743
|
+
* ocsp_uri = URI ocsp_uris[0]
|
1749
1744
|
*
|
1750
1745
|
* To submit the request we'll POST the request to the OCSP URI (per RFC
|
1751
1746
|
* 2560). Note that we only handle HTTP requests and don't handle any
|
data/ext/openssl/ossl_ocsp.h
CHANGED
@@ -13,9 +13,9 @@
|
|
13
13
|
|
14
14
|
#if !defined(OPENSSL_NO_OCSP)
|
15
15
|
extern VALUE mOCSP;
|
16
|
-
extern VALUE
|
17
|
-
extern VALUE
|
18
|
-
extern VALUE
|
16
|
+
extern VALUE cOCSPReq;
|
17
|
+
extern VALUE cOCSPRes;
|
18
|
+
extern VALUE cOCSPBasicRes;
|
19
19
|
#endif
|
20
20
|
|
21
21
|
void Init_ossl_ocsp(void);
|
data/ext/openssl/ossl_pkcs7.c
CHANGED
@@ -9,21 +9,6 @@
|
|
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
|
-
|
27
12
|
#define NewPKCS7si(klass) \
|
28
13
|
TypedData_Wrap_Struct((klass), &ossl_pkcs7_signer_info_type, 0)
|
29
14
|
#define SetPKCS7si(obj, p7si) do { \
|
@@ -75,7 +60,7 @@ ossl_pkcs7_free(void *ptr)
|
|
75
60
|
PKCS7_free(ptr);
|
76
61
|
}
|
77
62
|
|
78
|
-
|
63
|
+
const rb_data_type_t ossl_pkcs7_type = {
|
79
64
|
"OpenSSL/PKCS7",
|
80
65
|
{
|
81
66
|
0, ossl_pkcs7_free,
|
@@ -803,9 +788,9 @@ ossl_pkcs7_decrypt(int argc, VALUE *argv, VALUE self)
|
|
803
788
|
BIO *out;
|
804
789
|
VALUE str;
|
805
790
|
|
806
|
-
rb_scan_args(argc, argv, "
|
791
|
+
rb_scan_args(argc, argv, "12", &pkey, &cert, &flags);
|
807
792
|
key = GetPrivPKeyPtr(pkey); /* NO NEED TO DUP */
|
808
|
-
x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */
|
793
|
+
x509 = NIL_P(cert) ? NULL : GetX509CertPtr(cert); /* NO NEED TO DUP */
|
809
794
|
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
|
810
795
|
GetPKCS7(self, p7);
|
811
796
|
if(!(out = BIO_new(BIO_s_mem())))
|
@@ -1088,7 +1073,6 @@ Init_ossl_pkcs7(void)
|
|
1088
1073
|
rb_define_alloc_func(cPKCS7Signer, ossl_pkcs7si_alloc);
|
1089
1074
|
rb_define_method(cPKCS7Signer, "initialize", ossl_pkcs7si_initialize,3);
|
1090
1075
|
rb_define_method(cPKCS7Signer, "issuer", ossl_pkcs7si_get_issuer, 0);
|
1091
|
-
rb_define_alias(cPKCS7Signer, "name", "issuer");
|
1092
1076
|
rb_define_method(cPKCS7Signer, "serial", ossl_pkcs7si_get_serial,0);
|
1093
1077
|
rb_define_method(cPKCS7Signer,"signed_time",ossl_pkcs7si_get_signed_time,0);
|
1094
1078
|
|
data/ext/openssl/ossl_pkcs7.h
CHANGED
@@ -10,6 +10,22 @@
|
|
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;
|
13
29
|
extern VALUE cPKCS7;
|
14
30
|
extern VALUE cPKCS7Signer;
|
15
31
|
extern VALUE cPKCS7Recipient;
|