summaryrefslogtreecommitdiffstats
path: root/src/idevice.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2023-07-05 10:30:52 +0200
committerGravatar Nikias Bassen2023-07-05 10:30:52 +0200
commite57b6e7163277c6a63f22a7e2942cf666cf71a80 (patch)
tree56c083f63bffb238a1aabd8f43a42489c19570d6 /src/idevice.c
parent474fd9284b76d8ddd3a3aec41cbca3cc48271cc1 (diff)
downloadlibimobiledevice-e57b6e7163277c6a63f22a7e2942cf666cf71a80.tar.gz
libimobiledevice-e57b6e7163277c6a63f22a7e2942cf666cf71a80.tar.bz2
Updated OpenSSL-specific code to use OpenSSL 3.0+ API
Diffstat (limited to 'src/idevice.c')
-rw-r--r--src/idevice.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/idevice.c b/src/idevice.c
index 8545317..719cd28 100644
--- a/src/idevice.c
+++ b/src/idevice.c
@@ -1057,18 +1057,33 @@ static void internal_ssl_cleanup(ssl_data_t ssl_data)
1057} 1057}
1058 1058
1059#ifdef HAVE_OPENSSL 1059#ifdef HAVE_OPENSSL
1060#if OPENSSL_VERSION_NUMBER >= 0x30000000L
1061static long ssl_idevice_bio_callback(BIO *b, int oper, const char *argp, size_t len, int argi, long argl, int retvalue, size_t *processed)
1062#else
1060static long ssl_idevice_bio_callback(BIO *b, int oper, const char *argp, int argi, long argl, long retvalue) 1063static long ssl_idevice_bio_callback(BIO *b, int oper, const char *argp, int argi, long argl, long retvalue)
1064#endif
1061{ 1065{
1066 ssize_t bytes = 0;
1062 idevice_connection_t conn = (idevice_connection_t)BIO_get_callback_arg(b); 1067 idevice_connection_t conn = (idevice_connection_t)BIO_get_callback_arg(b);
1068#if OPENSSL_VERSION_NUMBER < 0x30000000L
1063 size_t len = (size_t)argi; 1069 size_t len = (size_t)argi;
1070 size_t *processed = (size_t*)&bytes;
1071#endif
1064 switch (oper) { 1072 switch (oper) {
1065 case (BIO_CB_READ|BIO_CB_RETURN): 1073 case (BIO_CB_READ|BIO_CB_RETURN):
1066 return argp ? (long)internal_ssl_read(conn, (char *)argp, len) : 0; 1074 if (argp) {
1075 bytes = internal_ssl_read(conn, (char *)argp, len);
1076 *processed = bytes;
1077 return (long)bytes;
1078 }
1079 return 0;
1067 case (BIO_CB_PUTS|BIO_CB_RETURN): 1080 case (BIO_CB_PUTS|BIO_CB_RETURN):
1068 len = strlen(argp); 1081 len = strlen(argp);
1069 // fallthrough 1082 // fallthrough
1070 case (BIO_CB_WRITE|BIO_CB_RETURN): 1083 case (BIO_CB_WRITE|BIO_CB_RETURN):
1071 return (long)internal_ssl_write(conn, argp, len); 1084 bytes = internal_ssl_write(conn, argp, len);
1085 *processed = bytes;
1086 return (long)bytes;
1072 default: 1087 default:
1073 return retvalue; 1088 return retvalue;
1074 } 1089 }
@@ -1079,7 +1094,11 @@ static BIO *ssl_idevice_bio_new(idevice_connection_t conn)
1079 BIO *b = BIO_new(BIO_s_null()); 1094 BIO *b = BIO_new(BIO_s_null());
1080 if (!b) return NULL; 1095 if (!b) return NULL;
1081 BIO_set_callback_arg(b, (char *)conn); 1096 BIO_set_callback_arg(b, (char *)conn);
1097#if OPENSSL_VERSION_NUMBER >= 0x30000000L
1098 BIO_set_callback_ex(b, ssl_idevice_bio_callback);
1099#else
1082 BIO_set_callback(b, ssl_idevice_bio_callback); 1100 BIO_set_callback(b, ssl_idevice_bio_callback);
1101#endif
1083 return b; 1102 return b;
1084} 1103}
1085 1104
@@ -1257,6 +1276,16 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_enable_ssl(idevice_conne
1257 X509_free(rootCert); 1276 X509_free(rootCert);
1258 free(root_cert.data); 1277 free(root_cert.data);
1259 1278
1279#if OPENSSL_VERSION_NUMBER >= 0x30000000L
1280 EVP_PKEY* rootPrivKey = NULL;
1281 membp = BIO_new_mem_buf(root_privkey.data, root_privkey.size);
1282 PEM_read_bio_PrivateKey(membp, &rootPrivKey, NULL, NULL);
1283 BIO_free(membp);
1284 if (SSL_CTX_use_PrivateKey(ssl_ctx, rootPrivKey) != 1) {
1285 debug_info("WARNING: Could not load RootPrivateKey");
1286 }
1287 EVP_PKEY_free(rootPrivKey);
1288#else
1260 RSA* rootPrivKey = NULL; 1289 RSA* rootPrivKey = NULL;
1261 membp = BIO_new_mem_buf(root_privkey.data, root_privkey.size); 1290 membp = BIO_new_mem_buf(root_privkey.data, root_privkey.size);
1262 PEM_read_bio_RSAPrivateKey(membp, &rootPrivKey, NULL, NULL); 1291 PEM_read_bio_RSAPrivateKey(membp, &rootPrivKey, NULL, NULL);
@@ -1265,6 +1294,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_enable_ssl(idevice_conne
1265 debug_info("WARNING: Could not load RootPrivateKey"); 1294 debug_info("WARNING: Could not load RootPrivateKey");
1266 } 1295 }
1267 RSA_free(rootPrivKey); 1296 RSA_free(rootPrivKey);
1297#endif
1268 free(root_privkey.data); 1298 free(root_privkey.data);
1269 1299
1270 SSL *ssl = SSL_new(ssl_ctx); 1300 SSL *ssl = SSL_new(ssl_ctx);