| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 57b8b8e commit ceb1d5e
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,14 +21,6 @@ | |||
| 21 | 21 | #include <string> | |
| 22 | 22 | #include <unordered_map> | |
| 23 | 23 | ||
| 24 | - // Some OpenSSL 1.1.1 functions unnecessarily operate on and return non-const | ||
| 25 | - // pointers, whereas the same functions in OpenSSL 3 use const pointers. | ||
| 26 | - #if OPENSSL_VERSION_MAJOR >= 3 | ||
| 27 | - #define OSSL3_CONST const | ||
| 28 | - #else | ||
| 29 | - #define OSSL3_CONST | ||
| 30 | - #endif | ||
| 31 | - | ||
| 32 | 24 | namespace node { | |
| 33 | 25 | ||
| 34 | 26 | using v8::Array; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,14 @@ | |||
| 10 | 10 | ||
| 11 | 11 | #include <string> | |
| 12 | 12 | ||
| 13 | + // Some OpenSSL 1.1.1 functions unnecessarily operate on and return non-const | ||
| 14 | + // pointers, whereas the same functions in OpenSSL 3 use const pointers. | ||
| 15 | + #if OPENSSL_VERSION_MAJOR >= 3 | ||
| 16 | + #define OSSL3_CONST const | ||
| 17 | + #else | ||
| 18 | + #define OSSL3_CONST | ||
| 19 | + #endif | ||
| 20 | + | ||
| 13 | 21 | namespace node { | |
| 14 | 22 | namespace crypto { | |
| 15 | 23 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -289,11 +289,9 @@ MaybeLocal<Value> BIOToStringOrBuffer( | |||
| 289 | 289 | } | |
| 290 | 290 | } | |
| 291 | 291 | ||
| 292 | - | ||
| 293 | - MaybeLocal<Value> WritePrivateKey( | ||
| 294 | - Environment* env, | ||
| 295 | - EVP_PKEY* pkey, | ||
| 296 | - const PrivateKeyEncodingConfig& config) { | ||
| 292 | + MaybeLocal<Value> WritePrivateKey(Environment* env, | ||
| 293 | + OSSL3_CONST EVP_PKEY* pkey, | ||
| 294 | + const PrivateKeyEncodingConfig& config) { | ||
| 297 | 295 | BIOPointer bio(BIO_new(BIO_s_mem())); | |
| 298 | 296 | CHECK(bio); | |
| 299 | 297 | ||
@@ -327,20 +325,21 @@ MaybeLocal<Value> WritePrivateKey( | |||
| 327 | 325 | // PKCS#1 is only permitted for RSA keys. | |
| 328 | 326 | CHECK_EQ(EVP_PKEY_id(pkey), EVP_PKEY_RSA); | |
| 329 | 327 | ||
| 330 | - RSAPointer rsa(EVP_PKEY_get1_RSA(pkey)); | ||
| 328 | + OSSL3_CONST RSA* rsa = EVP_PKEY_get0_RSA(pkey); | ||
| 331 | 329 | if (config.format_ == kKeyFormatPEM) { | |
| 332 | 330 | // Encode PKCS#1 as PEM. | |
| 333 | - err = PEM_write_bio_RSAPrivateKey( | ||
| 334 | - bio.get(), rsa.get(), | ||
| 335 | - config.cipher_, | ||
| 336 | - reinterpret_cast<unsigned char*>(pass), | ||
| 337 | - pass_len, | ||
| 338 | - nullptr, nullptr) != 1; | ||
| 331 | + err = PEM_write_bio_RSAPrivateKey(bio.get(), | ||
| 332 | + rsa, | ||
| 333 | + config.cipher_, | ||
| 334 | + reinterpret_cast<unsigned char*>(pass), | ||
| 335 | + pass_len, | ||
| 336 | + nullptr, | ||
| 337 | + nullptr) != 1; | ||
| 339 | 338 | } else { | |
| 340 | 339 | // Encode PKCS#1 as DER. This does not permit encryption. | |
| 341 | 340 | CHECK_EQ(config.format_, kKeyFormatDER); | |
| 342 | 341 | CHECK_NULL(config.cipher_); | |
| 343 | - err = i2d_RSAPrivateKey_bio(bio.get(), rsa.get()) != 1; | ||
| 342 | + err = i2d_RSAPrivateKey_bio(bio.get(), rsa) != 1; | ||
| 344 | 343 | } | |
| 345 | 344 | } else if (encoding_type == kKeyEncodingPKCS8) { | |
| 346 | 345 | if (config.format_ == kKeyFormatPEM) { | |
@@ -367,20 +366,21 @@ MaybeLocal<Value> WritePrivateKey( | |||
| 367 | 366 | // SEC1 is only permitted for EC keys. | |
| 368 | 367 | CHECK_EQ(EVP_PKEY_id(pkey), EVP_PKEY_EC); | |
| 369 | 368 | ||
| 370 | - ECKeyPointer ec_key(EVP_PKEY_get1_EC_KEY(pkey)); | ||
| 369 | + OSSL3_CONST EC_KEY* ec_key = EVP_PKEY_get0_EC_KEY(pkey); | ||
| 371 | 370 | if (config.format_ == kKeyFormatPEM) { | |
| 372 | 371 | // Encode SEC1 as PEM. | |
| 373 | - err = PEM_write_bio_ECPrivateKey( | ||
| 374 | - bio.get(), ec_key.get(), | ||
| 375 | - config.cipher_, | ||
| 376 | - reinterpret_cast<unsigned char*>(pass), | ||
| 377 | - pass_len, | ||
| 378 | - nullptr, nullptr) != 1; | ||
| 372 | + err = PEM_write_bio_ECPrivateKey(bio.get(), | ||
| 373 | + ec_key, | ||
| 374 | + config.cipher_, | ||
| 375 | + reinterpret_cast<unsigned char*>(pass), | ||
| 376 | + pass_len, | ||
| 377 | + nullptr, | ||
| 378 | + nullptr) != 1; | ||
| 379 | 379 | } else { | |
| 380 | 380 | // Encode SEC1 as DER. This does not permit encryption. | |
| 381 | 381 | CHECK_EQ(config.format_, kKeyFormatDER); | |
| 382 | 382 | CHECK_NULL(config.cipher_); | |
| 383 | - err = i2d_ECPrivateKey_bio(bio.get(), ec_key.get()) != 1; | ||
| 383 | + err = i2d_ECPrivateKey_bio(bio.get(), ec_key) != 1; | ||
| 384 | 384 | } | |
| 385 | 385 | } | |
| 386 | 386 | ||
@@ -391,20 +391,20 @@ MaybeLocal<Value> WritePrivateKey( | |||
| 391 | 391 | return BIOToStringOrBuffer(env, bio.get(), config.format_); | |
| 392 | 392 | } | |
| 393 | 393 | ||
| 394 | - bool WritePublicKeyInner(EVP_PKEY* pkey, | ||
| 394 | + bool WritePublicKeyInner(OSSL3_CONST EVP_PKEY* pkey, | ||
| 395 | 395 | const BIOPointer& bio, | |
| 396 | 396 | const PublicKeyEncodingConfig& config) { | |
| 397 | 397 | if (config.type_.ToChecked() == kKeyEncodingPKCS1) { | |
| 398 | 398 | // PKCS#1 is only valid for RSA keys. | |
| 399 | 399 | CHECK_EQ(EVP_PKEY_id(pkey), EVP_PKEY_RSA); | |
| 400 | - RSAPointer rsa(EVP_PKEY_get1_RSA(pkey)); | ||
| 400 | + OSSL3_CONST RSA* rsa = EVP_PKEY_get0_RSA(pkey); | ||
| 401 | 401 | if (config.format_ == kKeyFormatPEM) { | |
| 402 | 402 | // Encode PKCS#1 as PEM. | |
| 403 | - return PEM_write_bio_RSAPublicKey(bio.get(), rsa.get()) == 1; | ||
| 403 | + return PEM_write_bio_RSAPublicKey(bio.get(), rsa) == 1; | ||
| 404 | 404 | } else { | |
| 405 | 405 | // Encode PKCS#1 as DER. | |
| 406 | 406 | CHECK_EQ(config.format_, kKeyFormatDER); | |
| 407 | - return i2d_RSAPublicKey_bio(bio.get(), rsa.get()) == 1; | ||
| 407 | + return i2d_RSAPublicKey_bio(bio.get(), rsa) == 1; | ||
| 408 | 408 | } | |
| 409 | 409 | } else { | |
| 410 | 410 | CHECK_EQ(config.type_.ToChecked(), kKeyEncodingSPKI); | |
@@ -420,7 +420,7 @@ bool WritePublicKeyInner(EVP_PKEY* pkey, | |||
| 420 | 420 | } | |
| 421 | 421 | ||
| 422 | 422 | MaybeLocal<Value> WritePublicKey(Environment* env, | |
| 423 | - EVP_PKEY* pkey, | ||
| 423 | + OSSL3_CONST EVP_PKEY* pkey, | ||
| 424 | 424 | const PublicKeyEncodingConfig& config) { | |
| 425 | 425 | BIOPointer bio(BIO_new(BIO_s_mem())); | |
| 426 | 426 | CHECK(bio); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments