Here's an update to megatools-1.12.2.20261116, but it's not working yet.

To quote the NEWS file:

"This is a major update that brings megatools up to date with the modern
mega.nz protocol and encryption standards. The mega.nz protocol evolved
significantly since 2013 while remaining backwards compatible; this release
adds support for all the additive changes made over the past decade."

So the code has changed significantly since the last release, and the
openssl parts are, imo, infeasible to revert.

The build looks for openssl >=3.0.0, which fails. meson.build says this:

# The code needs [...] OpenSSL 3.0 (EVP_PKEY_fromdata, EVP_MAC, OSSL_PARAM).

lib/crypto.h includes openssl/core_names.h and openssl/param_build.h.
I have no idea how to convert this to something LibreSSL would support.

The port builds fine with OpenSSL 3.5, 4.0, and 4.1, but megadl crashes
for all three versions. I assume this is because curl pulls in LibreSSL,
though given the SIGILL maybe BTI is a factor here? Here's the backtrace
for 4.1 (megadl run with no arguments, seems to crash the same way with
arguments).

Program received signal SIGILL, Illegal instruction.
0x00000ec148b5bff0 in aesni_set_encrypt_key () at crypto/aes/aesni-x86_64.s:4083
⚠ warning: 4083    crypto/aes/aesni-x86_64.s: No such file or directory
(gdb) bt
#0  0x00000ec148b5bff0 in aesni_set_encrypt_key ()
    at crypto/aes/aesni-x86_64.s:4083
#1  0x00000ec148e65910 in ossl_cipher_set_aes_initkey (ctx=0xec1a8c928c0, 
    key=0xec148ab3830 <drbg_ctr_init.df_key> "", keylen=<optimized out>, 
    fn_set_key=0xec148b5bff0 <aesni_set_encrypt_key>, 
    fn_block=0xec148b58260 <aesni_encrypt>, fn_ecb=0x0, 
    fn_cbc=0xec148b5b610 <aesni_cbc_encrypt>, 
    fn_ctr=0xec148b59160 <aesni_ctr32_encrypt_blocks>)
    at providers/implementations/ciphers/cipher_aes_hw.c:27
#2  0x00000ec148e6611a in cipher_hw_aesni_initkey (
    ctx=0xec148ab3830 <drbg_ctr_init.df_key>, 
    key=0x100 <error: Cannot access memory at address 0x100>, 
    keylen=16224923232640)
    at providers/implementations/ciphers/cipher_aes_hw_aesni.c:34
#3  0x00000ec148e767b5 in cipher_generic_init_internal (ctx=0xec1a8c928c0, 
    key=0xec148ab3830 <drbg_ctr_init.df_key> "", keylen=32, iv=0x0, ivlen=0, 
    params=0x0, enc=1) at providers/implementations/ciphers/ciphercommon.c:204
#4  0x00000ec148e76682 in ossl_cipher_generic_einit (
    vctx=0xec148ab3830 <drbg_ctr_init.df_key>, 
    key=0x100 <error: Cannot access memory at address 0x100>, 
    keylen=16224923232640, 
    iv=0xec148b5bff0 <aesni_set_encrypt_key> 
"H\203\354\bH\307\300\377\377\377\377H\205\377\017\204c\004", 
ivlen=16223311331936, params=0x0)
    at providers/implementations/ciphers/ciphercommon.c:215
#5  0x00000ec148c69644 in evp_cipher_init_internal (ctx=0xec1a8ca2cc0, 
    cipher=<optimized out>, key=0xec148ab3830 <drbg_ctr_init.df_key> "", 
    iv=0x0, enc=1, is_pipeline=<optimized out>, params=0x0)
    at crypto/evp/evp_enc.c:252
#6  0x00000ec148c69774 in EVP_CipherInit_ex (
    ctx=0xec148ab3830 <drbg_ctr_init.df_key>, cipher=0x100, 
    impl=<optimized out>, key=0xec1a8c92980 "", 
    iv=0xec148b5bff0 <aesni_set_encrypt_key> 
"H\203\354\bH\307\300\377\377\377\377H\205\377\017\204c\004", enc=1219854944) 
at crypto/evp/evp_enc.c:416
#7  0x00000ec148ee6c0d in drbg_ctr_init (drbg=0xec17ef09000)
    at providers/implementations/rands/drbg_ctr.c:630
#8  drbg_ctr_set_ctx_params_locked (ctx=0xec17ef09000, p=0x7057dc98ec48)
    at providers/implementations/rands/drbg_ctr.c:793
#9  0x00000ec148ee3ff2 in drbg_ctr_instantiate_wrapper (vdrbg=0xec17ef09000, 
    strength=0, prediction_resistance=0, pstr=0x0, pstr_len=0, 
    params=<optimized out>) at providers/implementations/rands/drbg_ctr.c:357
#10 0x00000ec148c72764 in evp_rand_instantiate_locked (ctx=0xec17ef10e70, 
    strength=256, prediction_resistance=-1463211648, 
    pstr=0xec148b5bff0 <aesni_set_encrypt_key> 
"H\203\354\bH\307\300\377\377\377\377H\205\377\017\204c\004", 
pstr_len=16223311331936, params=0x0)
    at crypto/evp/evp_rand.c:531
#11 EVP_RAND_instantiate (ctx=0xec17ef10e70, strength=256, 
    prediction_resistance=-1463211648, 
    pstr=0xec148b5bff0 <aesni_set_encrypt_key> 
"H\203\354\bH\307\300\377\377\377\377H\205\377\017\204c\004", 
pstr_len=16223311331936, params=0x0)
    at crypto/evp/evp_rand.c:544
#12 0x00000ec148db0f0e in rand_new_drbg (libctx=<optimized out>, 
    parent=<optimized out>, reseed_interval=256, reseed_time_interval=3600)
    at crypto/rand/rand_lib.c:803
#13 0x00000ec148dafee4 in rand_get0_primary (ctx=0x0, dgbl=0xec17ef44540)
    at crypto/rand/rand_lib.c:874
#14 0x00000ec148daf213 in RAND_get0_primary (ctx=0x0)
    at crypto/rand/rand_lib.c:917
#15 RAND_status () at crypto/rand/rand_lib.c:347
#16 0x00000ec1905dec3c in rand_enough () at vtls/openssl.c:808
#17 ossl_random (data=0xec148ab3830 <drbg_ctr_init.df_key>, 
    entropy=0x7057dc98ef9c "", length=4) at vtls/openssl.c:5488
#18 0x00000ec1905a8d76 in randit (data=0x0, rnd=<optimized out>, 
    env_override=<error reading variable: Cannot access memory at address 0x0>)
    at rand.c:118
#19 Curl_rand_bytes (data=0x0, rnd=0x7057dc98efe0 "", num=8) at rand.c:156
#20 0x00000ec190575e85 in Curl_hash_global_init () at hash.c:70
#21 0x00000ec1905676ee in global_init (flags=<optimized out>, 
    memoryfuncs=<optimized out>) at easy.c:180
#22 0x00000ec190567608 in curl_global_init (flags=<optimized out>) at easy.c:238
#23 0x00000ebeadcb192a in init ()
    at ../megatools-1.12.2.20261116/lib/tools.c:188
#24 tool_init (ac=0x7057dc98f16c, av=0x7057dc98f0d8, 
    tool_name=0xebeadc88224 "- download exported files from mega.nz", 
    tool_entries=0xebeadcbe710 <entries>, 
    flags=(TOOL_INIT_AUTH_OPTIONAL | TOOL_INIT_DOWNLOAD_OPTS))
    at ../megatools-1.12.2.20261116/lib/tools.c:910
#25 0x00000ebeadcb2f63 in dl_main (ac=1, av=0xec17ef2ad10)
    at ../megatools-1.12.2.20261116/tools/dl.c:638
#26 0x00000ebeadcb7d36 in main (ac=<optimized out>, av=<optimized out>)
    at ../megatools-1.12.2.20261116/tools/shell.c:110


--- net/megatools/Makefile
+++ net/megatools/Makefile
@@ -2,7 +2,7 @@ PORTROACH =             limit:[0-9]\.tar\.gz
 
 COMMENT =              command line client application for Mega
 
-DISTNAME =             megatools-1.11.5.20250706
+DISTNAME =             megatools-1.12.2.20261116
 
 CATEGORIES =           net
 
@@ -13,7 +13,8 @@ MAINTAINER =          Anthony J. Bentley <[email protected]>
 # GPLv2+
 PERMIT_PACKAGE =       Yes
 
-WANTLIB += c crypto curl gio-2.0 glib-2.0 gobject-2.0
+WANTLIB += c curl gio-2.0 glib-2.0 gobject-2.0
+WANTLIB += lib/eopenssl41/crypto
 
 SITES =                        https://xff.cz/megatools/builds/
 
@@ -23,10 +24,13 @@ BUILD_DEPENDS =             devel/gobject-introspection \
                        textproc/asciidoc \
                        textproc/docbook2x
 LIB_DEPENDS =          devel/glib2 \
-                       net/curl
+                       net/curl \
+                       security/openssl/4.1
 
 MODULES =              devel/meson
 
+CONFIGURE_ARGS =       -Dc_link_args=-Wl,-rpath,${LOCALBASE}/lib/eopenssl41
+
 DEBUG_PACKAGES = ${BUILD_PACKAGES}
 
 # tests require network access
commit - 5fcc7973ed121b61af4ba0baca020f6df67dd0e1
blob - 7a8bae336c9ba238f031ec471287babe9515bd3a
file + net/megatools/distinfo
--- net/megatools/distinfo
+++ net/megatools/distinfo
@@ -1,2 +1,2 @@
-SHA256 (megatools-1.11.5.20250706.tar.gz) = 
UfeKA3SKZLEGbOKKLKddmNvvXwD+l4nciUgn+akTs2I=
-SIZE (megatools-1.11.5.20250706.tar.gz) = 106670
+SHA256 (megatools-1.12.2.20261116.tar.gz) = 
LIz7tB6r8f+skvCPWzrss2G8+5wCrCWHafteO6LxW4Q=
+SIZE (megatools-1.12.2.20261116.tar.gz) = 174658
commit - 5fcc7973ed121b61af4ba0baca020f6df67dd0e1
blob - 8fdb5df336937caaf740b2a7f633b4ecc70f2b5a
file + /dev/null
--- net/megatools/patches/patch-lib_mega_c
+++ /dev/null
@@ -1,14 +0,0 @@
-Fix build with opaque RSA in LibreSSL 3.5.
-
-Index: lib/mega.c
---- lib/mega.c.orig
-+++ lib/mega.c
-@@ -787,7 +787,7 @@ static gboolean rsa_key_gen(struct rsa_key *k)
-               return FALSE;
-       }
- 
--#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
-+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
-       const BIGNUM *p, *q, *d, *u, *m, *_e;
-       RSA_get0_key(key, &m, &_e, &d);
-       RSA_get0_factors(key, &q, &p);
commit - 5fcc7973ed121b61af4ba0baca020f6df67dd0e1
blob - /dev/null
file + net/megatools/patches/patch-meson_build (mode 644)
--- /dev/null
+++ net/megatools/patches/patch-meson_build
@@ -0,0 +1,12 @@
+Index: meson.build
+--- meson.build.orig
++++ meson.build
+@@ -24,7 +24,7 @@ deps = [
+   dependency('threads'),
+   dependency('gio-2.0', version: '>=2.68.0'),
+   dependency('libcurl', version: '>=7.85.0'),
+-  dependency('openssl', version: '>=3.0.0'),
++  dependency('libecrypto41', version: '>=3.0.0'),
+ ]
+ 
+ #if host_machine.system() == 'windows'
commit - 5fcc7973ed121b61af4ba0baca020f6df67dd0e1
blob - acf546cefe4878cf9b0966fe2871095d17298537
file + net/megatools/pkg/PLIST
--- net/megatools/pkg/PLIST
+++ net/megatools/pkg/PLIST
@@ -1,3 +1,4 @@
+bin/mega2fa
 bin/megacopy
 bin/megadf
 bin/megadl
@@ -5,11 +6,13 @@ bin/megaexport
 bin/megaget
 bin/megals
 bin/megamkdir
+bin/megapasswd
 bin/megaput
 bin/megareg
 bin/megarm
 bin/megatest
 @bin bin/megatools
+@man man/man1/megatools-2fa.1
 @man man/man1/megatools-copy.1
 @man man/man1/megatools-df.1
 @man man/man1/megatools-dl.1
@@ -17,12 +20,14 @@ bin/megatest
 @man man/man1/megatools-get.1
 @man man/man1/megatools-ls.1
 @man man/man1/megatools-mkdir.1
+@man man/man1/megatools-passwd.1
 @man man/man1/megatools-put.1
 @man man/man1/megatools-reg.1
 @man man/man1/megatools-rm.1
 @man man/man1/megatools-test.1
 @man man/man1/megatools.1
 @man man/man5/megarc.5
+share/bash-completion/completions/megatools
 share/doc/megatools/
 share/doc/megatools/LICENSE
 share/doc/megatools/NEWS

Reply via email to