diff options
| author | 2023-07-05 10:30:52 +0200 | |
|---|---|---|
| committer | 2023-07-05 10:30:52 +0200 | |
| commit | e57b6e7163277c6a63f22a7e2942cf666cf71a80 (patch) | |
| tree | 56c083f63bffb238a1aabd8f43a42489c19570d6 /common | |
| parent | 474fd9284b76d8ddd3a3aec41cbca3cc48271cc1 (diff) | |
| download | libimobiledevice-e57b6e7163277c6a63f22a7e2942cf666cf71a80.tar.gz libimobiledevice-e57b6e7163277c6a63f22a7e2942cf666cf71a80.tar.bz2 | |
Updated OpenSSL-specific code to use OpenSSL 3.0+ API
Diffstat (limited to 'common')
| -rw-r--r-- | common/userpref.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/common/userpref.c b/common/userpref.c index 11e28ba..b64c703 100644 --- a/common/userpref.c +++ b/common/userpref.c | |||
| @@ -435,6 +435,10 @@ userpref_error_t pair_record_generate_keys_and_certs(plist_t pair_record, key_da | |||
| 435 | debug_info("Generating keys and certificates..."); | 435 | debug_info("Generating keys and certificates..."); |
| 436 | 436 | ||
| 437 | #if defined(HAVE_OPENSSL) | 437 | #if defined(HAVE_OPENSSL) |
| 438 | #if OPENSSL_VERSION_NUMBER >= 0x30000000L | ||
| 439 | EVP_PKEY* root_pkey = EVP_RSA_gen(2048); | ||
| 440 | EVP_PKEY* host_pkey = EVP_RSA_gen(2048); | ||
| 441 | #else | ||
| 438 | BIGNUM *e = BN_new(); | 442 | BIGNUM *e = BN_new(); |
| 439 | RSA* root_keypair = RSA_new(); | 443 | RSA* root_keypair = RSA_new(); |
| 440 | RSA* host_keypair = RSA_new(); | 444 | RSA* host_keypair = RSA_new(); |
| @@ -451,6 +455,7 @@ userpref_error_t pair_record_generate_keys_and_certs(plist_t pair_record, key_da | |||
| 451 | 455 | ||
| 452 | EVP_PKEY* host_pkey = EVP_PKEY_new(); | 456 | EVP_PKEY* host_pkey = EVP_PKEY_new(); |
| 453 | EVP_PKEY_assign_RSA(host_pkey, host_keypair); | 457 | EVP_PKEY_assign_RSA(host_pkey, host_keypair); |
| 458 | #endif | ||
| 454 | 459 | ||
| 455 | /* generate root certificate */ | 460 | /* generate root certificate */ |
| 456 | X509* root_cert = X509_new(); | 461 | X509* root_cert = X509_new(); |
| @@ -561,12 +566,22 @@ userpref_error_t pair_record_generate_keys_and_certs(plist_t pair_record, key_da | |||
| 561 | } | 566 | } |
| 562 | } | 567 | } |
| 563 | 568 | ||
| 564 | RSA *pubkey = NULL; | 569 | EVP_PKEY *pubkey = NULL; |
| 565 | { | 570 | { |
| 566 | BIO *membp = BIO_new_mem_buf(public_key.data, public_key.size); | 571 | BIO *membp = BIO_new_mem_buf(public_key.data, public_key.size); |
| 567 | if (!PEM_read_bio_RSAPublicKey(membp, &pubkey, NULL, NULL)) { | 572 | #if OPENSSL_VERSION_NUMBER >= 0x30000000L |
| 573 | if (!PEM_read_bio_PUBKEY(membp, &pubkey, NULL, NULL)) { | ||
| 568 | debug_info("WARNING: Could not read public key"); | 574 | debug_info("WARNING: Could not read public key"); |
| 569 | } | 575 | } |
| 576 | #else | ||
| 577 | RSA *rsa_pubkey = NULL; | ||
| 578 | if (!PEM_read_bio_RSAPublicKey(membp, &rsa_pubkey, NULL, NULL)) { | ||
| 579 | debug_info("WARNING: Could not read public key"); | ||
| 580 | } else { | ||
| 581 | pubkey = EVP_PKEY_new(); | ||
| 582 | EVP_PKEY_assign_RSA(pubkey, rsa_pubkey); | ||
| 583 | } | ||
| 584 | #endif | ||
| 570 | BIO_free(membp); | 585 | BIO_free(membp); |
| 571 | } | 586 | } |
| 572 | 587 | ||
| @@ -588,10 +603,7 @@ userpref_error_t pair_record_generate_keys_and_certs(plist_t pair_record, key_da | |||
| 588 | X509_set1_notAfter(dev_cert, asn1time); | 603 | X509_set1_notAfter(dev_cert, asn1time); |
| 589 | ASN1_TIME_free(asn1time); | 604 | ASN1_TIME_free(asn1time); |
| 590 | 605 | ||
| 591 | EVP_PKEY* pkey = EVP_PKEY_new(); | 606 | X509_set_pubkey(dev_cert, pubkey); |
| 592 | EVP_PKEY_assign_RSA(pkey, pubkey); | ||
| 593 | X509_set_pubkey(dev_cert, pkey); | ||
| 594 | EVP_PKEY_free(pkey); | ||
| 595 | 607 | ||
| 596 | X509_add_ext_helper(dev_cert, NID_subject_key_identifier, (char*)"hash"); | 608 | X509_add_ext_helper(dev_cert, NID_subject_key_identifier, (char*)"hash"); |
| 597 | X509_add_ext_helper(dev_cert, NID_key_usage, (char*)"critical,digitalSignature,keyEncipherment"); | 609 | X509_add_ext_helper(dev_cert, NID_key_usage, (char*)"critical,digitalSignature,keyEncipherment"); |
| @@ -618,6 +630,7 @@ userpref_error_t pair_record_generate_keys_and_certs(plist_t pair_record, key_da | |||
| 618 | X509V3_EXT_cleanup(); | 630 | X509V3_EXT_cleanup(); |
| 619 | X509_free(dev_cert); | 631 | X509_free(dev_cert); |
| 620 | 632 | ||
| 633 | EVP_PKEY_free(pubkey); | ||
| 621 | EVP_PKEY_free(root_pkey); | 634 | EVP_PKEY_free(root_pkey); |
| 622 | EVP_PKEY_free(host_pkey); | 635 | EVP_PKEY_free(host_pkey); |
| 623 | 636 | ||
