openssl 2.0.9 → 2.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of openssl might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/History.md +28 -69
- data/README.md +1 -1
- data/ext/openssl/deprecation.rb +0 -3
- data/ext/openssl/extconf.rb +8 -52
- data/ext/openssl/openssl_missing.c +0 -67
- data/ext/openssl/openssl_missing.h +3 -50
- data/ext/openssl/ossl.c +81 -74
- data/ext/openssl/ossl.h +14 -27
- data/ext/openssl/ossl_asn1.c +287 -374
- data/ext/openssl/ossl_asn1.h +0 -4
- data/ext/openssl/ossl_bio.c +5 -20
- data/ext/openssl/ossl_bio.h +0 -2
- data/ext/openssl/ossl_bn.c +70 -28
- data/ext/openssl/ossl_cipher.c +18 -42
- data/ext/openssl/ossl_cipher.h +1 -1
- data/ext/openssl/ossl_digest.c +8 -12
- data/ext/openssl/ossl_digest.h +1 -1
- data/ext/openssl/ossl_engine.c +47 -47
- data/ext/openssl/ossl_hmac.c +19 -22
- data/ext/openssl/ossl_kdf.c +221 -0
- data/ext/openssl/ossl_kdf.h +6 -0
- data/ext/openssl/ossl_ns_spki.c +17 -21
- data/ext/openssl/ossl_ocsp.c +85 -80
- data/ext/openssl/ossl_pkcs12.c +15 -21
- data/ext/openssl/ossl_pkcs7.c +8 -21
- data/ext/openssl/ossl_pkey.c +24 -48
- data/ext/openssl/ossl_pkey.h +1 -6
- data/ext/openssl/ossl_pkey_dh.c +11 -11
- data/ext/openssl/ossl_pkey_dsa.c +16 -22
- data/ext/openssl/ossl_pkey_ec.c +43 -56
- data/ext/openssl/ossl_pkey_rsa.c +19 -19
- data/ext/openssl/ossl_rand.c +12 -12
- data/ext/openssl/ossl_ssl.c +291 -243
- data/ext/openssl/ossl_ssl.h +0 -5
- data/ext/openssl/ossl_ssl_session.c +7 -9
- data/ext/openssl/ossl_version.h +1 -1
- data/ext/openssl/ossl_x509.c +0 -15
- data/ext/openssl/ossl_x509.h +0 -7
- data/ext/openssl/ossl_x509attr.c +3 -7
- data/ext/openssl/ossl_x509cert.c +17 -54
- data/ext/openssl/ossl_x509crl.c +15 -25
- data/ext/openssl/ossl_x509ext.c +9 -14
- data/ext/openssl/ossl_x509name.c +76 -41
- data/ext/openssl/ossl_x509req.c +10 -47
- data/ext/openssl/ossl_x509revoked.c +8 -8
- data/ext/openssl/ossl_x509store.c +15 -45
- data/ext/openssl/ruby_missing.h +2 -13
- data/lib/openssl.rb +1 -0
- data/lib/openssl/bn.rb +2 -1
- data/lib/openssl/buffering.rb +24 -23
- data/lib/openssl/config.rb +12 -11
- data/lib/openssl/digest.rb +3 -6
- data/lib/openssl/pkcs5.rb +22 -0
- data/lib/openssl/pkey.rb +0 -41
- data/lib/openssl/ssl.rb +118 -16
- data/lib/openssl/x509.rb +7 -1
- metadata +8 -7
- data/ext/openssl/ossl_pkcs5.c +0 -180
- data/ext/openssl/ossl_pkcs5.h +0 -6
data/ext/openssl/ossl_asn1.h
CHANGED
@@ -14,15 +14,11 @@
|
|
14
14
|
* ASN1_DATE conversions
|
15
15
|
*/
|
16
16
|
VALUE asn1time_to_time(const ASN1_TIME *);
|
17
|
-
#if defined(HAVE_ASN1_TIME_ADJ)
|
18
17
|
/* Splits VALUE to seconds and offset days. VALUE is typically a Time or an
|
19
18
|
* Integer. This is used when updating ASN1_*TIME with ASN1_TIME_adj() or
|
20
19
|
* X509_time_adj_ex(). We can't use ASN1_TIME_set() and X509_time_adj() because
|
21
20
|
* they have the Year 2038 issue on sizeof(time_t) == 4 environment */
|
22
21
|
void ossl_time_split(VALUE, time_t *, int *);
|
23
|
-
#else
|
24
|
-
time_t time_to_time_t(VALUE);
|
25
|
-
#endif
|
26
22
|
|
27
23
|
/*
|
28
24
|
* ASN1_STRING conversions
|
data/ext/openssl/ossl_bio.c
CHANGED
@@ -26,32 +26,17 @@ ossl_obj2bio(volatile VALUE *pobj)
|
|
26
26
|
}
|
27
27
|
|
28
28
|
VALUE
|
29
|
-
|
29
|
+
ossl_membio2str(BIO *bio)
|
30
30
|
{
|
31
31
|
VALUE ret;
|
32
|
+
int state;
|
32
33
|
BUF_MEM *buf;
|
33
34
|
|
34
35
|
BIO_get_mem_ptr(bio, &buf);
|
35
|
-
ret =
|
36
|
-
|
37
|
-
return ret;
|
38
|
-
}
|
39
|
-
|
40
|
-
VALUE
|
41
|
-
ossl_protect_membio2str(BIO *bio, int *status)
|
42
|
-
{
|
43
|
-
return rb_protect((VALUE (*)(VALUE))ossl_membio2str0, (VALUE)bio, status);
|
44
|
-
}
|
45
|
-
|
46
|
-
VALUE
|
47
|
-
ossl_membio2str(BIO *bio)
|
48
|
-
{
|
49
|
-
VALUE ret;
|
50
|
-
int status = 0;
|
51
|
-
|
52
|
-
ret = ossl_protect_membio2str(bio, &status);
|
36
|
+
ret = ossl_str_new(buf->data, buf->length, &state);
|
53
37
|
BIO_free(bio);
|
54
|
-
if
|
38
|
+
if (state)
|
39
|
+
rb_jump_tag(state);
|
55
40
|
|
56
41
|
return ret;
|
57
42
|
}
|
data/ext/openssl/ossl_bio.h
CHANGED
data/ext/openssl/ossl_bn.c
CHANGED
@@ -26,11 +26,6 @@
|
|
26
26
|
} \
|
27
27
|
} while (0)
|
28
28
|
|
29
|
-
#define SafeGetBN(obj, bn) do { \
|
30
|
-
OSSL_Check_Kind((obj), cBN); \
|
31
|
-
GetBN((obj), (bn)); \
|
32
|
-
} while (0)
|
33
|
-
|
34
29
|
static void
|
35
30
|
ossl_bn_free(void *ptr)
|
36
31
|
{
|
@@ -176,8 +171,7 @@ ossl_bn_alloc(VALUE klass)
|
|
176
171
|
return obj;
|
177
172
|
}
|
178
173
|
|
179
|
-
/*
|
180
|
-
*
|
174
|
+
/*
|
181
175
|
* call-seq:
|
182
176
|
* OpenSSL::BN.new => aBN
|
183
177
|
* OpenSSL::BN.new(bn) => aBN
|
@@ -185,7 +179,7 @@ ossl_bn_alloc(VALUE klass)
|
|
185
179
|
* OpenSSL::BN.new(string) => aBN
|
186
180
|
* OpenSSL::BN.new(string, 0 | 2 | 10 | 16) => aBN
|
187
181
|
*
|
188
|
-
* Construct a new OpenSSL
|
182
|
+
* Construct a new OpenSSL BIGNUM object.
|
189
183
|
*/
|
190
184
|
static VALUE
|
191
185
|
ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
|
@@ -250,7 +244,7 @@ ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
|
|
250
244
|
* bn.to_s(base) => string
|
251
245
|
*
|
252
246
|
* === Parameters
|
253
|
-
* *
|
247
|
+
* * _base_ - Integer
|
254
248
|
* Valid values:
|
255
249
|
* * 0 - MPI
|
256
250
|
* * 2 - binary
|
@@ -377,6 +371,21 @@ BIGNUM_BOOL1(is_one)
|
|
377
371
|
*/
|
378
372
|
BIGNUM_BOOL1(is_odd)
|
379
373
|
|
374
|
+
/*
|
375
|
+
* call-seq:
|
376
|
+
* bn.negative? => true | false
|
377
|
+
*/
|
378
|
+
static VALUE
|
379
|
+
ossl_bn_is_negative(VALUE self)
|
380
|
+
{
|
381
|
+
BIGNUM *bn;
|
382
|
+
|
383
|
+
GetBN(self, bn);
|
384
|
+
if (BN_is_zero(bn))
|
385
|
+
return Qfalse;
|
386
|
+
return BN_is_negative(bn) ? Qtrue : Qfalse;
|
387
|
+
}
|
388
|
+
|
380
389
|
#define BIGNUM_1c(func) \
|
381
390
|
static VALUE \
|
382
391
|
ossl_bn_##func(VALUE self) \
|
@@ -498,7 +507,6 @@ BIGNUM_2c(mod_sqr)
|
|
498
507
|
BIGNUM_2c(mod_inverse)
|
499
508
|
|
500
509
|
/*
|
501
|
-
* Document-method: OpenSSL::BN#/
|
502
510
|
* call-seq:
|
503
511
|
* bn1 / bn2 => [result, remainder]
|
504
512
|
*
|
@@ -614,12 +622,11 @@ BIGNUM_BIT(clear_bit)
|
|
614
622
|
*/
|
615
623
|
BIGNUM_BIT(mask_bits)
|
616
624
|
|
617
|
-
/*
|
625
|
+
/*
|
618
626
|
* call-seq:
|
619
627
|
* bn.bit_set?(bit) => true | false
|
620
628
|
*
|
621
|
-
*
|
622
|
-
* Bitwise operations for openssl BIGNUMs.
|
629
|
+
* Tests bit _bit_ in _bn_ and returns +true+ if set, +false+ if not set.
|
623
630
|
*/
|
624
631
|
static VALUE
|
625
632
|
ossl_bn_is_bit_set(VALUE self, VALUE bit)
|
@@ -774,15 +781,15 @@ BIGNUM_RAND_RANGE(pseudo_rand)
|
|
774
781
|
* call-seq:
|
775
782
|
* BN.generate_prime(bits, [, safe [, add [, rem]]]) => bn
|
776
783
|
*
|
777
|
-
* Generates a random prime number of bit length
|
778
|
-
* generates a safe prime. If
|
784
|
+
* Generates a random prime number of bit length _bits_. If _safe_ is set to
|
785
|
+
* +true+, generates a safe prime. If _add_ is specified, generates a prime that
|
779
786
|
* fulfills condition <tt>p % add = rem</tt>.
|
780
787
|
*
|
781
788
|
* === Parameters
|
782
|
-
* *
|
783
|
-
* *
|
784
|
-
* *
|
785
|
-
* *
|
789
|
+
* * _bits_ - integer
|
790
|
+
* * _safe_ - boolean
|
791
|
+
* * _add_ - BN
|
792
|
+
* * _rem_ - BN
|
786
793
|
*/
|
787
794
|
static VALUE
|
788
795
|
ossl_bn_s_generate_prime(int argc, VALUE *argv, VALUE klass)
|
@@ -856,6 +863,37 @@ ossl_bn_copy(VALUE self, VALUE other)
|
|
856
863
|
return self;
|
857
864
|
}
|
858
865
|
|
866
|
+
/*
|
867
|
+
* call-seq:
|
868
|
+
* +bn -> aBN
|
869
|
+
*/
|
870
|
+
static VALUE
|
871
|
+
ossl_bn_uplus(VALUE self)
|
872
|
+
{
|
873
|
+
return self;
|
874
|
+
}
|
875
|
+
|
876
|
+
/*
|
877
|
+
* call-seq:
|
878
|
+
* -bn -> aBN
|
879
|
+
*/
|
880
|
+
static VALUE
|
881
|
+
ossl_bn_uminus(VALUE self)
|
882
|
+
{
|
883
|
+
VALUE obj;
|
884
|
+
BIGNUM *bn1, *bn2;
|
885
|
+
|
886
|
+
GetBN(self, bn1);
|
887
|
+
obj = NewBN(cBN);
|
888
|
+
bn2 = BN_dup(bn1);
|
889
|
+
if (!bn2)
|
890
|
+
ossl_raise(eBNError, "BN_dup");
|
891
|
+
SetBN(obj, bn2);
|
892
|
+
BN_set_negative(bn2, !BN_is_negative(bn2));
|
893
|
+
|
894
|
+
return obj;
|
895
|
+
}
|
896
|
+
|
859
897
|
#define BIGNUM_CMP(func) \
|
860
898
|
static VALUE \
|
861
899
|
ossl_bn_##func(VALUE self, VALUE other) \
|
@@ -888,7 +926,7 @@ BIGNUM_CMP(ucmp)
|
|
888
926
|
* call-seq:
|
889
927
|
* bn == obj => true or false
|
890
928
|
*
|
891
|
-
* Returns +true+ only if
|
929
|
+
* Returns +true+ only if _obj_ has the same value as _bn_. Contrast this
|
892
930
|
* with OpenSSL::BN#eql?, which requires obj to be OpenSSL::BN.
|
893
931
|
*/
|
894
932
|
static VALUE
|
@@ -913,7 +951,7 @@ ossl_bn_eq(VALUE self, VALUE other)
|
|
913
951
|
* bn.eql?(obj) => true or false
|
914
952
|
*
|
915
953
|
* Returns <code>true</code> only if <i>obj</i> is a
|
916
|
-
* <code>OpenSSL::BN</code> with the same value as <i>
|
954
|
+
* <code>OpenSSL::BN</code> with the same value as <i>bn</i>. Contrast this
|
917
955
|
* with OpenSSL::BN#==, which performs type conversions.
|
918
956
|
*/
|
919
957
|
static VALUE
|
@@ -953,7 +991,7 @@ ossl_bn_hash(VALUE self)
|
|
953
991
|
ossl_raise(eBNError, NULL);
|
954
992
|
}
|
955
993
|
|
956
|
-
hash =
|
994
|
+
hash = INT2FIX(rb_memhash(buf, len));
|
957
995
|
xfree(buf);
|
958
996
|
|
959
997
|
return hash;
|
@@ -964,12 +1002,12 @@ ossl_bn_hash(VALUE self)
|
|
964
1002
|
* bn.prime? => true | false
|
965
1003
|
* bn.prime?(checks) => true | false
|
966
1004
|
*
|
967
|
-
* Performs a Miller-Rabin probabilistic primality test with
|
968
|
-
* iterations. If
|
1005
|
+
* Performs a Miller-Rabin probabilistic primality test with _checks_
|
1006
|
+
* iterations. If _checks_ is not specified, a number of iterations is used
|
969
1007
|
* that yields a false positive rate of at most 2^-80 for random input.
|
970
1008
|
*
|
971
1009
|
* === Parameters
|
972
|
-
* *
|
1010
|
+
* * _checks_ - integer
|
973
1011
|
*/
|
974
1012
|
static VALUE
|
975
1013
|
ossl_bn_is_prime(int argc, VALUE *argv, VALUE self)
|
@@ -1004,8 +1042,8 @@ ossl_bn_is_prime(int argc, VALUE *argv, VALUE self)
|
|
1004
1042
|
* first attempts trial divisions with some small primes.
|
1005
1043
|
*
|
1006
1044
|
* === Parameters
|
1007
|
-
* *
|
1008
|
-
* *
|
1045
|
+
* * _checks_ - integer
|
1046
|
+
* * _trial_div_ - boolean
|
1009
1047
|
*/
|
1010
1048
|
static VALUE
|
1011
1049
|
ossl_bn_is_prime_fasttest(int argc, VALUE *argv, VALUE self)
|
@@ -1059,7 +1097,7 @@ Init_ossl_bn(void)
|
|
1059
1097
|
rb_define_alloc_func(cBN, ossl_bn_alloc);
|
1060
1098
|
rb_define_method(cBN, "initialize", ossl_bn_initialize, -1);
|
1061
1099
|
|
1062
|
-
|
1100
|
+
rb_define_method(cBN, "initialize_copy", ossl_bn_copy, 1);
|
1063
1101
|
rb_define_method(cBN, "copy", ossl_bn_copy, 1);
|
1064
1102
|
|
1065
1103
|
/* swap (=coerce?) */
|
@@ -1068,6 +1106,9 @@ Init_ossl_bn(void)
|
|
1068
1106
|
rb_define_method(cBN, "num_bits", ossl_bn_num_bits, 0);
|
1069
1107
|
/* num_bits_word */
|
1070
1108
|
|
1109
|
+
rb_define_method(cBN, "+@", ossl_bn_uplus, 0);
|
1110
|
+
rb_define_method(cBN, "-@", ossl_bn_uminus, 0);
|
1111
|
+
|
1071
1112
|
rb_define_method(cBN, "+", ossl_bn_add, 1);
|
1072
1113
|
rb_define_method(cBN, "-", ossl_bn_sub, 1);
|
1073
1114
|
rb_define_method(cBN, "*", ossl_bn_mul, 1);
|
@@ -1101,6 +1142,7 @@ Init_ossl_bn(void)
|
|
1101
1142
|
rb_define_method(cBN, "one?", ossl_bn_is_one, 0);
|
1102
1143
|
/* is_word */
|
1103
1144
|
rb_define_method(cBN, "odd?", ossl_bn_is_odd, 0);
|
1145
|
+
rb_define_method(cBN, "negative?", ossl_bn_is_negative, 0);
|
1104
1146
|
|
1105
1147
|
/* zero
|
1106
1148
|
* one
|
data/ext/openssl/ossl_cipher.c
CHANGED
@@ -26,10 +26,6 @@
|
|
26
26
|
ossl_raise(rb_eRuntimeError, "Cipher not initialized!"); \
|
27
27
|
} \
|
28
28
|
} while (0)
|
29
|
-
#define SafeGetCipher(obj, ctx) do { \
|
30
|
-
OSSL_Check_Kind((obj), cCipher); \
|
31
|
-
GetCipher((obj), (ctx)); \
|
32
|
-
} while (0)
|
33
29
|
|
34
30
|
/*
|
35
31
|
* Classes
|
@@ -53,7 +49,7 @@ static const rb_data_type_t ossl_cipher_type = {
|
|
53
49
|
* PUBLIC
|
54
50
|
*/
|
55
51
|
const EVP_CIPHER *
|
56
|
-
|
52
|
+
ossl_evp_get_cipherbyname(VALUE obj)
|
57
53
|
{
|
58
54
|
if (rb_obj_is_kind_of(obj, cCipher)) {
|
59
55
|
EVP_CIPHER_CTX *ctx;
|
@@ -108,7 +104,7 @@ ossl_cipher_alloc(VALUE klass)
|
|
108
104
|
* call-seq:
|
109
105
|
* Cipher.new(string) -> cipher
|
110
106
|
*
|
111
|
-
* The string must
|
107
|
+
* The string must be a valid cipher name like "AES-128-CBC" or "3DES".
|
112
108
|
*
|
113
109
|
* A list of cipher names is available by calling OpenSSL::Cipher.ciphers.
|
114
110
|
*/
|
@@ -146,7 +142,7 @@ ossl_cipher_copy(VALUE self, VALUE other)
|
|
146
142
|
if (!ctx1) {
|
147
143
|
AllocCipher(self, ctx1);
|
148
144
|
}
|
149
|
-
|
145
|
+
GetCipher(other, ctx2);
|
150
146
|
if (EVP_CIPHER_CTX_copy(ctx1, ctx2) != 1)
|
151
147
|
ossl_raise(eCipherError, NULL);
|
152
148
|
|
@@ -296,9 +292,9 @@ ossl_cipher_decrypt(int argc, VALUE *argv, VALUE self)
|
|
296
292
|
* OpenSSL::PKCS5 instead.
|
297
293
|
*
|
298
294
|
* === Parameters
|
299
|
-
* *
|
300
|
-
* *
|
301
|
-
* *
|
295
|
+
* * _salt_ must be an 8 byte string if provided.
|
296
|
+
* * _iterations_ is an integer with a default of 2048.
|
297
|
+
* * _digest_ is a Digest object that defaults to 'MD5'
|
302
298
|
*
|
303
299
|
* A minimum of 1000 iterations is recommended.
|
304
300
|
*
|
@@ -321,9 +317,7 @@ ossl_cipher_pkcs5_keyivgen(int argc, VALUE *argv, VALUE self)
|
|
321
317
|
salt = (unsigned char *)RSTRING_PTR(vsalt);
|
322
318
|
}
|
323
319
|
iter = NIL_P(viter) ? 2048 : NUM2INT(viter);
|
324
|
-
|
325
|
-
rb_raise(rb_eArgError, "iterations must be a positive integer");
|
326
|
-
digest = NIL_P(vdigest) ? EVP_md5() : GetDigestPtr(vdigest);
|
320
|
+
digest = NIL_P(vdigest) ? EVP_md5() : ossl_evp_get_digestbyname(vdigest);
|
327
321
|
GetCipher(self, ctx);
|
328
322
|
EVP_BytesToKey(EVP_CIPHER_CTX_cipher(ctx), digest, salt,
|
329
323
|
(unsigned char *)RSTRING_PTR(vpass), RSTRING_LENINT(vpass), iter, key, iv);
|
@@ -367,12 +361,12 @@ ossl_cipher_update_long(EVP_CIPHER_CTX *ctx, unsigned char *out, long *out_len_p
|
|
367
361
|
* cipher.update(data [, buffer]) -> string or buffer
|
368
362
|
*
|
369
363
|
* Encrypts data in a streaming fashion. Hand consecutive blocks of data
|
370
|
-
* to the
|
364
|
+
* to the #update method in order to encrypt it. Returns the encrypted
|
371
365
|
* data chunk. When done, the output of Cipher#final should be additionally
|
372
366
|
* added to the result.
|
373
367
|
*
|
374
|
-
* If
|
375
|
-
* it.
|
368
|
+
* If _buffer_ is given, the encryption/decryption result will be written to
|
369
|
+
* it. _buffer_ will be resized automatically.
|
376
370
|
*/
|
377
371
|
static VALUE
|
378
372
|
ossl_cipher_update(int argc, VALUE *argv, VALUE self)
|
@@ -514,10 +508,8 @@ ossl_cipher_set_iv(VALUE self, VALUE iv)
|
|
514
508
|
StringValue(iv);
|
515
509
|
GetCipher(self, ctx);
|
516
510
|
|
517
|
-
#if defined(HAVE_AUTHENTICATED_ENCRYPTION)
|
518
511
|
if (EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_FLAG_AEAD_CIPHER)
|
519
512
|
iv_len = (int)(VALUE)EVP_CIPHER_CTX_get_app_data(ctx);
|
520
|
-
#endif
|
521
513
|
if (!iv_len)
|
522
514
|
iv_len = EVP_CIPHER_CTX_iv_length(ctx);
|
523
515
|
if (RSTRING_LEN(iv) != iv_len)
|
@@ -543,14 +535,9 @@ ossl_cipher_is_authenticated(VALUE self)
|
|
543
535
|
|
544
536
|
GetCipher(self, ctx);
|
545
537
|
|
546
|
-
#if defined(HAVE_AUTHENTICATED_ENCRYPTION)
|
547
538
|
return (EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_FLAG_AEAD_CIPHER) ? Qtrue : Qfalse;
|
548
|
-
#else
|
549
|
-
return Qfalse;
|
550
|
-
#endif
|
551
539
|
}
|
552
540
|
|
553
|
-
#ifdef HAVE_AUTHENTICATED_ENCRYPTION
|
554
541
|
/*
|
555
542
|
* call-seq:
|
556
543
|
* cipher.auth_data = string -> string
|
@@ -582,8 +569,6 @@ ossl_cipher_set_auth_data(VALUE self, VALUE data)
|
|
582
569
|
in_len = RSTRING_LEN(data);
|
583
570
|
|
584
571
|
GetCipher(self, ctx);
|
585
|
-
if (!(EVP_CIPHER_flags(EVP_CIPHER_CTX_cipher(ctx)) & EVP_CIPH_FLAG_AEAD_CIPHER))
|
586
|
-
ossl_raise(eCipherError, "AEAD not supported by this cipher");
|
587
572
|
|
588
573
|
if (!ossl_cipher_update_long(ctx, NULL, &out_len, in, in_len))
|
589
574
|
ossl_raise(eCipherError, "couldn't set additional authenticated data");
|
@@ -598,8 +583,8 @@ ossl_cipher_set_auth_data(VALUE self, VALUE data)
|
|
598
583
|
* Gets the authentication tag generated by Authenticated Encryption Cipher
|
599
584
|
* modes (GCM for example). This tag may be stored along with the ciphertext,
|
600
585
|
* then set on the decryption cipher to authenticate the contents of the
|
601
|
-
* ciphertext against changes. If the optional integer parameter
|
602
|
-
* given, the returned tag will be
|
586
|
+
* ciphertext against changes. If the optional integer parameter _tag_len_ is
|
587
|
+
* given, the returned tag will be _tag_len_ bytes long. If the parameter is
|
603
588
|
* omitted, the default length of 16 bytes or the length previously set by
|
604
589
|
* #auth_tag_len= will be used. For maximum security, the longest possible
|
605
590
|
* should be chosen.
|
@@ -724,13 +709,6 @@ ossl_cipher_set_iv_length(VALUE self, VALUE iv_length)
|
|
724
709
|
|
725
710
|
return iv_length;
|
726
711
|
}
|
727
|
-
#else
|
728
|
-
#define ossl_cipher_set_auth_data rb_f_notimplement
|
729
|
-
#define ossl_cipher_get_auth_tag rb_f_notimplement
|
730
|
-
#define ossl_cipher_set_auth_tag rb_f_notimplement
|
731
|
-
#define ossl_cipher_set_auth_tag_len rb_f_notimplement
|
732
|
-
#define ossl_cipher_set_iv_length rb_f_notimplement
|
733
|
-
#endif
|
734
712
|
|
735
713
|
/*
|
736
714
|
* call-seq:
|
@@ -808,10 +786,8 @@ ossl_cipher_iv_length(VALUE self)
|
|
808
786
|
int len = 0;
|
809
787
|
|
810
788
|
GetCipher(self, ctx);
|
811
|
-
#if defined(HAVE_AUTHENTICATED_ENCRYPTION)
|
812
789
|
if (EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_FLAG_AEAD_CIPHER)
|
813
790
|
len = (int)(VALUE)EVP_CIPHER_CTX_get_app_data(ctx);
|
814
|
-
#endif
|
815
791
|
if (!len)
|
816
792
|
len = EVP_CIPHER_CTX_iv_length(ctx);
|
817
793
|
|
@@ -1022,9 +998,9 @@ Init_ossl_cipher(void)
|
|
1022
998
|
* encryption and later decryption, the OpenSSL library still requires a
|
1023
999
|
* value to be set - "" may be used in case none is available.
|
1024
1000
|
*
|
1025
|
-
* An example using the GCM (Galois/Counter Mode). You have 16 bytes
|
1026
|
-
* 12 bytes (96 bits)
|
1027
|
-
* not to reuse the
|
1001
|
+
* An example using the GCM (Galois/Counter Mode). You have 16 bytes _key_,
|
1002
|
+
* 12 bytes (96 bits) _nonce_ and the associated data _auth_data_. Be sure
|
1003
|
+
* not to reuse the _key_ and _nonce_ pair. Reusing an nonce ruins the
|
1028
1004
|
* security guarantees of GCM mode.
|
1029
1005
|
*
|
1030
1006
|
* cipher = OpenSSL::Cipher::AES.new(128, :GCM).encrypt
|
@@ -1035,8 +1011,8 @@ Init_ossl_cipher(void)
|
|
1035
1011
|
* encrypted = cipher.update(data) + cipher.final
|
1036
1012
|
* tag = cipher.auth_tag # produces 16 bytes tag by default
|
1037
1013
|
*
|
1038
|
-
* Now you are the receiver. You know the
|
1039
|
-
*
|
1014
|
+
* Now you are the receiver. You know the _key_ and have received _nonce_,
|
1015
|
+
* _auth_data_, _encrypted_ and _tag_ through an untrusted network. Note
|
1040
1016
|
* that GCM accepts an arbitrary length tag between 1 and 16 bytes. You may
|
1041
1017
|
* additionally need to check that the received tag has the correct length,
|
1042
1018
|
* or you allow attackers to forge a valid single byte tag for the tampered
|
@@ -1057,7 +1033,7 @@ Init_ossl_cipher(void)
|
|
1057
1033
|
eCipherError = rb_define_class_under(cCipher, "CipherError", eOSSLError);
|
1058
1034
|
|
1059
1035
|
rb_define_alloc_func(cCipher, ossl_cipher_alloc);
|
1060
|
-
|
1036
|
+
rb_define_method(cCipher, "initialize_copy", ossl_cipher_copy, 1);
|
1061
1037
|
rb_define_module_function(cCipher, "ciphers", ossl_s_ciphers, 0);
|
1062
1038
|
rb_define_method(cCipher, "initialize", ossl_cipher_initialize, 1);
|
1063
1039
|
rb_define_method(cCipher, "reset", ossl_cipher_reset, 0);
|