Skip to content

Commit d2c0b6a

Browse files
pks-tgitster
authored andcommitted
meson: wire up unsafe SHA1 backend
In 06c92da (Makefile: allow specifying a SHA-1 for non-cryptographic uses, 2024-09-26), we have introduced a cryptographically-insecure backend for SHA1 that can optionally be used in some contexts where the processed data is not security relevant. This effort was in-flight with the effort to introduce Meson, so we don't have an equivalent here. Wire up a new build option that lets users pick an unsafe SHA1 backend. Note that for simplicity's sake we have to drop the error condition around an unhandled SHA1 backend. This should be fine though given that Meson verifies the value for combo-options for us. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 12068bd commit d2c0b6a

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

meson.build

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,15 +1327,16 @@ endif
13271327

13281328
https_backend = get_option('https_backend')
13291329
sha1_backend = get_option('sha1_backend')
1330+
sha1_unsafe_backend = get_option('sha1_unsafe_backend')
13301331
sha256_backend = get_option('sha256_backend')
13311332

1332-
security_framework = dependency('Security', required: 'CommonCrypto' in [https_backend, sha1_backend])
1333+
security_framework = dependency('Security', required: 'CommonCrypto' in [https_backend, sha1_backend, sha1_unsafe_backend])
13331334
core_foundation_framework = dependency('CoreFoundation', required: security_framework.found())
13341335
if https_backend == 'auto' and security_framework.found()
13351336
https_backend = 'CommonCrypto'
13361337
endif
13371338

1338-
openssl_required = 'openssl' in [https_backend, sha1_backend, sha256_backend]
1339+
openssl_required = 'openssl' in [https_backend, sha1_backend, sha1_unsafe_backend, sha256_backend]
13391340
openssl = dependency('openssl', required: openssl_required, default_options: ['default_library=static'])
13401341
if https_backend == 'auto' and openssl.found()
13411342
https_backend = 'openssl'
@@ -1368,19 +1369,38 @@ if sha1_backend == 'sha1dc'
13681369
'sha1dc/sha1.c',
13691370
'sha1dc/ubc_check.c',
13701371
]
1371-
elif sha1_backend == 'CommonCrypto'
1372+
endif
1373+
if sha1_backend == 'CommonCrypto' or sha1_unsafe_backend == 'CommonCrypto'
1374+
if sha1_backend == 'CommonCrypto'
1375+
libgit_c_args += '-DSHA1_APPLE'
1376+
endif
1377+
if sha1_unsafe_backend == 'CommonCrypto'
1378+
libgit_c_args += '-DSHA1_APPLE_UNSAFE'
1379+
endif
1380+
13721381
libgit_c_args += '-DCOMMON_DIGEST_FOR_OPENSSL'
1373-
libgit_c_args += '-DSHA1_APPLE'
13741382
# Apple CommonCrypto requires chunking
13751383
libgit_c_args += '-DSHA1_MAX_BLOCK_SIZE=1024L*1024L*1024L'
1376-
elif sha1_backend == 'openssl'
1377-
libgit_c_args += '-DSHA1_OPENSSL'
1384+
endif
1385+
if sha1_backend == 'openssl' or sha1_unsafe_backend == 'openssl'
1386+
if sha1_backend == 'openssl'
1387+
libgit_c_args += '-DSHA1_OPENSSL'
1388+
endif
1389+
if sha1_unsafe_backend == 'openssl'
1390+
libgit_c_args += '-DSHA1_OPENSSL_UNSAFE'
1391+
endif
1392+
13781393
libgit_dependencies += openssl
1379-
elif sha1_backend == 'block'
1380-
libgit_c_args += '-DSHA1_BLK'
1394+
endif
1395+
if sha1_backend == 'block' or sha1_unsafe_backend == 'block'
1396+
if sha1_backend == 'block'
1397+
libgit_c_args += '-DSHA1_BLK'
1398+
endif
1399+
if sha1_unsafe_backend == 'block'
1400+
libgit_c_args += '-DSHA1_BLK_UNSAFE'
1401+
endif
1402+
13811403
libgit_sources += 'block-sha1/sha1.c'
1382-
else
1383-
error('Unhandled SHA1 backend ' + sha1_backend)
13841404
endif
13851405

13861406
if sha256_backend == 'openssl'

meson_options.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ option('https_backend', type: 'combo', value: 'auto', choices: ['auto', 'openssl
5151
description: 'The HTTPS backend to use when connecting to remotes.')
5252
option('sha1_backend', type: 'combo', choices: ['openssl', 'block', 'sha1dc', 'CommonCrypto'], value: 'sha1dc',
5353
description: 'The backend used for hashing objects with the SHA1 object format.')
54+
option('sha1_unsafe_backend', type: 'combo', choices: ['openssl', 'block', 'CommonCrypto', 'none'], value: 'none',
55+
description: 'The backend used for hashing data with the SHA1 object format in case no cryptographic security is needed.')
5456
option('sha256_backend', type: 'combo', choices: ['openssl', 'nettle', 'gcrypt', 'block'], value: 'block',
5557
description: 'The backend used for hashing objects with the SHA256 object format.')
5658

0 commit comments

Comments
 (0)