610 Commits
Author SHA1 Message Date
Jure Triglav f3e082c4ea src: replace SetAccessor w/ SetAccessorProperty
Backport-PR-URL: https://github.com/nodejs/node/pull/20456
PR-URL: https://github.com/nodejs/node/pull/17665
Fixes: https://github.com/nodejs/node/issues/17636
Refs: https://github.com/nodejs/node/pull/16482
Refs: https://github.com/nodejs/node/pull/16860
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2018-05-02 14:30:35 -04:00
BufoViridis b48ca0a140 src: fix crypto.pbkdf2 callback error argument
Callbacks should always return `null` instead of `undefined` if no
error occurred.

PR-URL: https://github.com/nodejs/node/pull/18458
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-04-12 23:51:33 -04:00
Tobias Nießen 16bf5fed69 crypto: reuse variable instead of reevaluation
Backport-PR-URL: https://github.com/nodejs/node/pull/19114
PR-URL: https://github.com/nodejs/node/pull/17735
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2018-03-29 23:28:22 -04:00
Ben Noordhuis 6ee4228c1d src: drop CNNIC+StartCom certificate whitelisting
Remove the CNNIC certificates again and remove the whitelist from commit
3beb88071 ("crypto: add cert check to CNNIC Whitelist") from June 2015.

Backport-PR-URL: https://github.com/nodejs/node/pull/19633
PR-URL: https://github.com/nodejs/node/pull/19322
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-03-27 23:49:47 -04:00
David Benjamin 8cc0ea78d7 crypto: do not reach into OpenSSL internals for ThrowCryptoError
There is a perfectly serviceable ERR_get_error function which avoids
having to sniff through the OpenSSL ring buffer like that. It does
return the errors in the opposite order, but that's easily fixed with
std::reverse.

Note this behavior is slightly different in that an ERR_get_error loop
will ultimately clear the error queue, but this is desirable. Leaving
the error queue uncleared means errors in subsequent operations may get
mixed up and cause issues.

PR-URL: https://github.com/nodejs/node/pull/16701
Backport-PR-URL: https://github.com/nodejs/node/pull/18327
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2018-02-20 08:18:06 -08:00
Daniel Bevenius 8a000e8f81 src: add openssl-system-ca-path configure option
The motivation for this commit is that we need to specify system CA
certificates when building node. While we are aware of the environment
variable NODE_EXTRA_CA_CERTS this is not a great solution as we build
an RPM and we also don't want users to be able to unset them.

The suggestion is to add a configure time property like this:

--openssl-system-ca-path=OPENSSL_SYSTEM_CA_PATH
             Use the specified path to system CA (PEM format) in
             addition to the OpenSSL supplied CA store or compiled-
             in Mozilla CA copy.

Usage example:
$ ./configure --openssl-system-ca-path=/etc/pki/tls/certs/ca-bundle.crt

This would add the specified CA certificates in addition to the ones
already being used.

PR-URL: https://github.com/nodejs/node/pull/16790
Backport-PR-URL: https://github.com/nodejs/node/pull/18174
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2018-02-19 01:45:37 +00:00
Myles Borins 072902a258 crypto: remove leftover initialization
Refs: https://src.fedoraproject.org/fork/zvetlik/rpms/nodejs/blob/6141424e6629e53e3e628a16aec98018720ae5f3/f/0027-Fix-leftover-initialised.patch
PR-URL: https://github.com/nodejs/node/pull/18622
2018-02-18 16:09:05 +00:00
David Benjamin b0526ba7f1 crypto: clear some SSL_METHOD deprecation warnings
Fixing the rest will be rather involved. I think the cleanest option is
to deprecate the method string APIs which are weird to begin with.

PR-URL: https://github.com/nodejs/node/pull/16130
Backport-PR-URL: https://github.com/nodejs/node/pull/18622
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
2018-02-18 15:17:54 +00:00
David Benjamin 78738266d6 crypto: make ALPN the same for OpenSSL 1.0.2 & 1.1.0
This is kind of hairy. OpenSSL 1.0.2 ignored the return value and always
treated everything as SSL_TLSEXT_ERR_NOACK (so the comment was wrong and
Node was never sending a warning alert). OpenSSL 1.1.0 honors
SSL_TLSEXT_ERR_NOACK vs SSL_TLSEXT_ERR_FATAL_ALERT and treats everything
unknown as SSL_TLSEXT_ERR_FATAL_ALERT.

Since this is a behavior change (tests break too), start by aligning
everything on SSL_TLSEXT_ERR_NOACK. If sending no_application_protocol
is desirable in the future, this can by changed to
SSL_TLSEXT_ERR_FATAL_ALERT with whatever deprecation process is
appropriate.

However, note that, contrary to
https://rt.openssl.org/Ticket/Display.html?id=3463#txn-54498,
SSL_TLSEXT_ERR_FATAL_ALERT is *not* useful to a server with no fallback
protocol. Even if such mismatches were rejected, such a server must
*still* account for the fallback protocol case when the client does not
advertise ALPN at all. Thus this may not be worth bothering.

PR-URL: https://github.com/nodejs/node/pull/16130
Backport-PR-URL: https://github.com/nodejs/node/pull/18622
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
2018-02-18 15:17:52 +00:00
David Benjamin f1d458be58 crypto: remove deprecated ECDH calls w/ OpenSSL 1.1
These are both no-ops in OpenSSL 1.1.0.

PR-URL: https://github.com/nodejs/node/pull/16130
Backport-PR-URL: https://github.com/nodejs/node/pull/18622
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
2018-02-18 15:17:45 +00:00
David Benjamin f9a597a1d3 crypto: emulate OpenSSL 1.0 ticket scheme in 1.1
OpenSSL 1.0.x used a 48-byte ticket key, but OpenSSL 1.1.x made it
larger by using a larger HMAC-SHA256 key and using AES-256-CBC to
encrypt. However, Node's public API exposes the 48-byte key. Implement
the ticket key callback to restore the OpenSSL 1.0.x behavior.

PR-URL: https://github.com/nodejs/node/pull/16130
Backport-PR-URL: https://github.com/nodejs/node/pull/18622
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
2018-02-18 15:17:37 +00:00
David Benjamin eb377f38f6 crypto: hard-code tlsSocket.getCipher().version
This aligns the documentation with reality. This API never did what Node
claims it did.

The SSL_CIPHER_get_version function just isn't useful. In OpenSSL 1.0.2,
it always returned the string "TLSv1/SSLv3" for anything but SSLv2
ciphers, which Node does not support. Note how test-tls-multi-pfx.js
claims that ECDHE-ECDSA-AES256-GCM-SHA384 was added in TLSv1/SSLv3 which
is not true. That cipher is new as of TLS 1.2. The OpenSSL 1.0.2
implementation is:

char *SSL_CIPHER_get_version(const SSL_CIPHER *c)
{
    int i;

    if (c == NULL)
        return ("(NONE)");
    i = (int)(c->id >> 24L);
    if (i == 3)
        return ("TLSv1/SSLv3");
    else if (i == 2)
        return ("SSLv2");
    else
        return ("unknown");
}

In OpenSSL 1.1.0, SSL_CIPHER_get_version changed to actually behave as
Node documented it, but this changes the semantics of the function and
breaks tests. The cipher's minimum protocol version is not a useful
notion to return to the caller here, so just hardcode the string at
"TLSv1/SSLv3" and document it as legacy.

PR-URL: https://github.com/nodejs/node/pull/16130
Backport-PR-URL: https://github.com/nodejs/node/pull/18622
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
2018-02-18 15:17:26 +00:00
David Benjamin 2efb16b7d7 crypto: add compat logic for "DSS1" and "dss1"
In OpenSSL 1.1.0, EVP_dss1() is removed. These hash names were exposed
in Node's public API, so add compatibility hooks for them.

PR-URL: https://github.com/nodejs/node/pull/16130
Backport-PR-URL: https://github.com/nodejs/node/pull/18622
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
2018-02-18 15:17:23 +00:00
David Benjamin 5e9e4e5bf9 crypto: Make Hmac 1.1.0-compatible
OpenSSL 1.1.0 requries HMAC_CTX be heap-allocated.

PR-URL: https://github.com/nodejs/node/pull/16130
Backport-PR-URL: https://github.com/nodejs/node/pull/18622
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
2018-02-18 15:17:20 +00:00
David Benjamin 2419b8613a crypto: make SignBase compatible with OpenSSL 1.1.0
1.1.0 requires EVP_MD_CTX be heap-allocated. In doing so, move the Init
and Update hooks to shared code because they are the same between Verify
and Sign.

PR-URL: https://github.com/nodejs/node/pull/16130
Backport-PR-URL: https://github.com/nodejs/node/pull/18622
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
2018-02-18 15:17:18 +00:00
David Benjamin 0ef35a137f crypto: make Hash 1.1.0-compatible
OpenSSL 1.1.0 requires EVP_MD_CTX be heap-allocated.

PR-URL: https://github.com/nodejs/node/pull/16130
Backport-PR-URL: https://github.com/nodejs/node/pull/18622
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
2018-02-18 15:17:16 +00:00
David Benjamin e0cbc39668 crypto: make CipherBase 1.1.0-compatible
In OpenSSL 1.1.0, EVP_CIPHER_CTX must be heap-allocated. Once we're
heap-allocating them, there's no need in a separate initialised_ bit.
The presence of ctx_ is sufficient.

PR-URL: https://github.com/nodejs/node/pull/16130
Backport-PR-URL: https://github.com/nodejs/node/pull/18622
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
2018-02-18 15:17:13 +00:00
David Benjamin e21079851f crypto: remove locking callbacks for OpenSSL 1.1.0
The callbacks are all no-ops in OpenSSL 1.1.0. This isn't necessary (the
functions still exist for compatibility), but silences some warnings and
avoids allocating a few unused mutexes.

PR-URL: https://github.com/nodejs/node/pull/16130
Backport-PR-URL: https://github.com/nodejs/node/pull/18622
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
2018-02-18 15:17:11 +00:00
David Benjamin c2106e4037 crypto: use RSA and DH accessors
Parts of this were cherry-picked from PR #8491. Note that this only
works with OpenSSL 1.0.2 or 1.1.0g or later. 1.1.0g is, as of writing,
not yet released, but the fix is on the branch. See
https://github.com/openssl/openssl/pull/4384.

PR-URL: https://github.com/nodejs/node/pull/16130
Backport-PR-URL: https://github.com/nodejs/node/pull/18622
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
2018-02-18 15:17:08 +00:00
David Benjamin f00d758067 crypto: account for new 1.1.0 SSL APIs
This is cherry-picked from PR #8491 and tidied up. This change does
*not* account for the larger ticket key in OpenSSL 1.1.0. That will be
done in a follow-up commit as the 48-byte ticket key is part of Node's
public API.

rvagg: removed BORINGSSL defines before landing

PR-URL: https://github.com/nodejs/node/pull/16130
Backport-PR-URL: https://github.com/nodejs/node/pull/18622
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
2018-02-18 15:17:02 +00:00
David Benjamin 335bbff96d crypto: remove unnecessary SSLerr calls
These are OpenSSL-internal APIs that are no longer accessible in 1.1.0
and weren't necessary. OpenSSL will push its own errors and, if it
doesn't, the calling code would handle it anyway.

PR-URL: https://github.com/nodejs/node/pull/16130
Backport-PR-URL: https://github.com/nodejs/node/pull/18622
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
2018-02-18 15:17:00 +00:00
David Benjamin e28e80d5b8 crypto: use X509_STORE_CTX_new
In OpenSSL 1.1.0, X509_STORE_CTX is opaque and thus cannot be
stack-allocated. This works in OpenSSL 1.1.0 and 1.0.2. Adapted from PR

PR-URL: https://github.com/nodejs/node/pull/16130
Backport-PR-URL: https://github.com/nodejs/node/pull/18622
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
2018-02-18 15:16:11 +00:00
Tobias Nießen 964850a24c crypto: warn on invalid authentication tag length
PR-URL: https://github.com/nodejs/node/pull/17566
Refs: https://github.com/nodejs/node/issues/17523
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-01-24 02:45:24 +00:00
Daniel Bevenius f276cd954e src: rename async-wrap -> async_wrap
This commit renames async-wrap to async_wrap for consitency with other
c++ source files.

Backport-PR-URL: https://github.com/nodejs/node/pull/18179
PR-URL: https://github.com/nodejs/node/pull/17022
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
2018-01-19 13:13:54 -05:00
Yihong Wang e71beba14f src: explicitly register built-in modules
Previously, built-in modules are registered before main() via
__attribute__((constructor)) mechanism in GCC and similiar
mechanism in MSVC. This causes some issues when node is built as
static library. Calling module registration function for built-in
modules in node::Init() helps to avoid the issues.

Signed-off-by: Yihong Wang <yh.wang@ibm.com>
Backport-PR-URL: https://github.com/nodejs/node/pull/18179
PR-URL: https://github.com/nodejs/node/pull/16565
Refs: https://github.com/nodejs/node/pull/14986#issuecomment-332758206
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2018-01-19 13:13:31 -05:00
Daniel Bevenius f52c2b9bce src: use nullptr instead of NULL
PR-URL: https://github.com/nodejs/node/pull/17373
Backport-PR-URL: https://github.com/nodejs/node/pull/17873
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2018-01-03 23:27:56 +00:00
Daniel Bevenius 54f6b294a1 crypto: use SetNull instead of Set
This commit updates the only usage of Set(Null(env->isolate()) to use
SetNull() instead which is used in other places in node_crypto.cc.

PR-URL: https://github.com/nodejs/node/pull/17521
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2017-12-20 02:00:46 +00:00
Joyee Cheung 255fffbbc8 src: do not include x.h if x-inl.h is included
Fixes: https://github.com/nodejs/node/issues/16519
PR-URL: https://github.com/nodejs/node/pull/16548
Backport-PR-URL: https://github.com/nodejs/node/pull/16609
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-11-14 16:34:22 +00:00
Greg Alexander 1ed0c7706f crypto: better crypto error messages
Add openSSL error stack to the exception object thrown from crypto.
The new exception property is only added to the object if the error
stack has not cleared out prior to calling ThrowCryptoError.

PR-URL: https://github.com/nodejs/node/pull/15518
Refs: https://github.com/nodejs/node/issues/5444
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
2017-10-03 14:03:19 -07:00
David Benjamin be4e809af2 crypto: use X509V3_EXT_d2i
There is no need to reach into quite so many internals to decode an
extension.

PR-URL: https://github.com/nodejs/node/pull/15348
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2017-10-03 14:03:18 -07:00
David Benjamin 93d5ead37a crypto: use SSL_SESSION_get_id
This accessor exists in OpenSSL 1.0.2, so it may be used already. This
is cherry-picked from PR #8491.

PR-URL: https://github.com/nodejs/node/pull/15348
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2017-10-03 14:03:18 -07:00
Gibson Fahnestock 9eeaab4ba5 crypto: only try to set FIPS mode if different
Turning FIPS mode on (or off) when it's already on (or off) should be a
no-op, not an error.

PR-URL: https://github.com/nodejs/node/pull/12210
Fixes: https://github.com/nodejs/node/issues/11849
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-10-03 14:03:14 -07:00
David Benjamin c26e93b309 crypto: fix Node_SignFinal
PR #11705 switched Node away from using using OpenSSL's legacy EVP_Sign*
and EVP_Verify* APIs. Instead, it computes a hash normally via
EVP_Digest* and then uses EVP_PKEY_sign and EVP_PKEY_verify to verify
the hash directly. This change corrects two problems:

1. The documentation still recommends the signature algorithm EVP_MD
   names of OpenSSL's legacy APIs. OpenSSL has since moved away from
   thosee, which is why ECDSA was strangely inconsistent. (This is why
   "ecdsa-with-SHA256" was missing.)

2. Node_SignFinal copied some code from EVP_SignFinal's internals. This
   is problematic for OpenSSL 1.1.0 and is missing a critical check
   that prevents pkey->pkey.ptr from being cast to the wrong type.

To resolve this, remove the non-EVP_PKEY_sign codepath. This codepath is
no longer necessary. PR #11705's verify half was already assuming all
EVP_PKEYs supported EVP_PKEY_sign and EVP_PKEY_verify. Also, in the
documentation, point users towards using hash function names which are
more consisent. This avoids an ECDSA special-case and some strangeness
around RSA-PSS ("RSA-SHA256" is the OpenSSL name of the
sha256WithRSAEncryption OID which is not used for RSA-PSS).

PR-URL: https://github.com/nodejs/node/pull/15024
Reviewed-By: Shigeki Ohtsu <ohtsu@ohtsu.org>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2017-09-20 09:32:43 -07:00
Bartek Szczepański 8c480f9d8c src: remove outdated todo from node_crypto.cc
TODO comment from node_crypto is no longer relevant. Unification of
commented code and string_bytes code would bloat the latter. Methods
for hex encoding produce different output in both files (crypto adds
colon and uses uppercase letters.) Common path between those two is
very limited now.

PR-URL: https://github.com/nodejs/node/pull/15104
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-09-20 07:55:44 -07:00
Roga Pria Sembada bd07574718 crypto: support multiple ECDH curves and auto
Using SSL_CTX_set1_curves_list() (OpenSSL 1.0.2+), this allows to set
colon separated ECDH curve names in SecureContext's ecdhCurve option.
The option can also be set to "auto" to select the curve automatically
from list built in OpenSSL by enabling SSL_CTX_set_ecdh_auto()
(OpenSSL 1.0.2+).

PR-URL: https://github.com/nodejs/node/pull/15206
Ref: https://github.com/nodejs/node/issues/15054
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2017-09-20 07:52:59 -07:00
Ben Noordhuis f81812b1ff src: turn key length exception into CHECK
This exception can logically never happen because of the key stretching
that takes place first.  Failure must therefore be a bug in Node.js and
not in the executing script.

PR-URL: https://github.com/nodejs/node/pull/15183
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-09-12 03:18:37 +02:00
Shigeki Ohtsu 78a71aa123 crypto: fix error of createCipher in wrap mode
EVP_CIPHER_CTX_FLAG_WRAP_ALLOW flag needs to be set in using wrap mode
ciphers. In `crypto.createCipher()`, AES key wrap mode does not use a
default IV defined in RFC3394 but a generated IV with
`EVP_BytesToKey()` to be consistent API behaviors with other ciphers.

The built-in AES wrap mode in OpenSSL is not supported in FIPS mode as
http://openssl.6102.n7.nabble.com/AES-Key-Wrap-in-FIPS-Mode-td50238.html
so its tests in FIPS mode are skipped.

Fixes: https://github.com/nodejs/node/issues/15009
PR-URL: https://github.com/nodejs/node/pull/15037
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-09-12 03:18:37 +02:00
Shigeki Ohtsu 41bf40e209 crypto: warn if counter mode used in createCipher
`crypto.createCipher()` sets the fixed IV derived from password and it
leads to a security risk of nonce reuse when counter mode is used.
A warning is emitted when CTR, GCM or CCM is used in
`crypto.createCipher()` to notify users to avoid nonce reuse.

Fixes: https://github.com/nodejs/node/issues/13801
PR-URL: https://github.com/nodejs/node/pull/13821
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2017-09-12 03:18:37 +02:00
James M Snell 8cee5d66bd src: reduce code duplication
Adds `AsyncWrap::AddWrapMethods()` to add common methods
to a `Local<FunctionTemplate>`. Follows same pattern as
stream base.

PR-URL: https://github.com/nodejs/node/pull/14937
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2017-09-12 03:18:32 +02:00
James M Snell 5a05dfe0a7 src: fixup strings, reduce duplication
PR-URL: https://github.com/nodejs/node/pull/14937
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2017-09-12 03:18:32 +02:00
Tobias Nießen 264e4345f8 src: reuse 'ondone' string in node_crypto.cc
PR-URL: https://github.com/nodejs/node/pull/14587
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2017-08-07 15:17:39 +02:00
Ben Noordhuis eb068a0526 src: remove unused Connection::ClearError()
PR-URL: https://github.com/nodejs/node/pull/14514
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Tobias Nie�en <tniessen@tnie.de>
2017-08-07 15:17:37 +02:00
Tobias Nießen 51c1afafa6 crypto: change segmentation faults to CHECKs
PR-URL: https://github.com/nodejs/node/pull/14548
Fixes: https://github.com/nodejs/node/issues/14519
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-08-02 12:03:04 +02:00
Ben Noordhuis eb7faf6734 src: replace ASSERT with CHECK
Builds always have asserts enabled so there is no point distinguishing
between debug-only checks and run-time checks.  Replace calls to ASSERT
and friends with their CHECK counterparts.

Fixes: https://github.com/nodejs/node/issues/14461
PR-URL: https://github.com/nodejs/node/pull/14474
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Nikolai Vavilov <vvnicholas@gmail.com>
Reviewed-By: XadillaX <admin@xcoder.in>
2017-07-27 23:48:54 +02:00
Ben Noordhuis e3ed425da7 src: fix memory leak in DH key setters
Fix a memory leak in dh.setPublicKey() and dh.setPrivateKey() where the
old keys weren't freed.

Fixes: https://github.com/nodejs/node/issues/8377
PR-URL: https://github.com/nodejs/node/pull/14122
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-07-19 15:03:00 -04:00
Ben Noordhuis 83234db1eb src: reduce allocations in exportPublicKey()
PR-URL: https://github.com/nodejs/node/pull/14122
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-07-19 15:02:59 -04:00
Ben Noordhuis 62be8efd83 src: guard against double free in randomBytes()
PR-URL: https://github.com/nodejs/node/pull/14122
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-07-19 15:02:59 -04:00
Ben Noordhuis 5caaf83ee9 src: simplify PBKDF2Request
This also renames a misnamed variable `error_` to `success_`.

PR-URL: https://github.com/nodejs/node/pull/14122
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-07-19 15:02:59 -04:00
Ben Noordhuis 7d445906da src: remove PBKDF2Request::release()
PR-URL: https://github.com/nodejs/node/pull/14122
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-07-19 15:02:58 -04:00
Ben Noordhuis 2d2d75903d src: avoid heap allocation in crypto.pbkdf2()
PR-URL: https://github.com/nodejs/node/pull/14122
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-07-19 15:02:58 -04:00