Skip to content

Commit bbc5d10

Browse files
authored
Merge pull request #16 from ethomson/subsystems_refactor
Subsystems refactor
2 parents 7d0b2c8 + a6b2a39 commit bbc5d10

19 files changed

+654
-370
lines changed

.github/workflows/main.yml

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,97 @@ jobs:
1111
strategy:
1212
matrix:
1313
config:
14-
# Linux (amd64, Trusty, GCC, OpenSSL)
14+
# Linux (amd64, Xenial, GCC, OpenSSL)
1515
- platform: 'ubuntu-latest'
16-
container: 'libgit2/trusty-amd64:latest'
16+
container: 'ghcr.io/libgit2/libgit2/xenial:latest'
1717
env: { CC: 'gcc', CMAKE_OPTIONS: '-DCRYPT=openssl -DUNICODE=builtin', LEAK_CHECK: 'valgrind' }
1818

19-
# Linux (amd64, Trusty, GCC, mbedTLS)
19+
# Linux (amd64, Xenial, GCC, mbedTLS)
2020
- platform: 'ubuntu-latest'
21-
container: 'libgit2/trusty-amd64:latest'
21+
container: 'ghcr.io/libgit2/libgit2/xenial:latest'
2222
env: { CC: 'gcc', CMAKE_OPTIONS: '-DCRYPT=mbedtls -DUNICODE=iconv', LEAK_CHECK: 'valgrind' }
2323

24-
# Linux (amd64, Trusty, Clang, OpenSSL)
24+
# Linux (amd64, Xenial, Clang, OpenSSL)
2525
- platform: 'ubuntu-latest'
26-
container: 'libgit2/trusty-amd64:latest'
26+
container: 'ghcr.io/libgit2/libgit2/xenial:latest'
2727
env: { CC: 'clang', CMAKE_OPTIONS: '-DCRYPT=openssl -DUNICODE=iconv', LEAK_CHECK: 'valgrind' }
2828

29-
# Linux (amd64, Trusty, Clang, mbedTLS)
29+
# Linux (amd64, Xenial, Clang, OpenSSL Dynamic)
3030
- platform: 'ubuntu-latest'
31-
container: 'libgit2/trusty-amd64:latest'
31+
container: 'ghcr.io/libgit2/libgit2/xenial:latest'
32+
env: { CC: 'clang', CMAKE_OPTIONS: '-DCRYPT=openssl-dynamic -DUNICODE=iconv', LEAK_CHECK: 'valgrind' }
33+
34+
# Linux (amd64, Xenial, Clang, mbedTLS)
35+
- platform: 'ubuntu-latest'
36+
container: 'ghcr.io/libgit2/libgit2/xenial:latest'
3237
env: { CC: 'clang', CMAKE_OPTIONS: '-DCRYPT=mbedtls -DUNICODE=builtin', LEAK_CHECK: 'valgrind' }
3338

3439
# Linux (x86, Bionic, gcc, OpenSSL)
3540
- platform: 'ubuntu-latest'
36-
container: 'libgit2/bionic-x86:latest'
41+
container: 'ghcr.io/libgit2/libgit2/bionic-x86:latest'
3742
qemu: true
38-
env: { CC: 'gcc', CMAKE_OPTIONS: '-DCRYPT=openssl -DUNICODE=builtin', LEAK_CHECK: 'valgrind' }
43+
env: { CC: 'gcc', CMAKE_GENERATOR: 'Ninja', CMAKE_OPTIONS: '-DCRYPT=openssl -DUNICODE=builtin', LEAK_CHECK: 'valgrind' }
44+
45+
# Linux (x86, Bionic, gcc, OpenSSL Dynamic)
46+
- platform: 'ubuntu-latest'
47+
container: 'ghcr.io/libgit2/libgit2/bionic-x86:latest'
48+
qemu: true
49+
env: { CC: 'gcc', CMAKE_GENERATOR: 'Ninja', CMAKE_OPTIONS: '-DCRYPT=openssl-dynamic -DUNICODE=builtin', LEAK_CHECK: 'valgrind' }
3950

4051
# Linux (x86, Bionic, clang, OpenSSL)
4152
- platform: 'ubuntu-latest'
42-
container: 'libgit2/bionic-x86:latest'
53+
container: 'ghcr.io/libgit2/libgit2/bionic-x86:latest'
4354
qemu: true
44-
env: { CC: 'clang', CMAKE_OPTIONS: '-DCRYPT=openssl -DUNICODE=iconv', LEAK_CHECK: 'valgrind' }
55+
env: { CC: 'clang', CMAKE_GENERATOR: 'Ninja', CMAKE_OPTIONS: '-DCRYPT=openssl -DUNICODE=iconv', LEAK_CHECK: 'valgrind' }
4556

4657
# Linux (arm32, Bionic, gcc, OpenSSL)
4758
- platform: 'ubuntu-latest'
48-
container: 'libgit2/bionic-arm32:latest'
59+
container: 'ghcr.io/libgit2/libgit2/bionic-arm32:latest'
4960
qemu: true
50-
env: { CC: 'gcc', CMAKE_OPTIONS: '-DCRYPT=openssl -DUNICODE=builtin' }
61+
env: { CC: 'gcc', CMAKE_GENERATOR: 'Ninja', CMAKE_OPTIONS: '-DCRYPT=openssl -DUNICODE=builtin' }
62+
63+
# Linux (arm32, Bionic, gcc, OpenSSL Dynamic)
64+
- platform: 'ubuntu-latest'
65+
container: 'ghcr.io/libgit2/libgit2/bionic-arm32:latest'
66+
qemu: true
67+
env: { CC: 'gcc', CMAKE_GENERATOR: 'Ninja', CMAKE_OPTIONS: '-DCRYPT=openssl-dynamic -DUNICODE=builtin' }
5168

5269
# Linux (arm64, Bionic, gcc, OpenSSL)
5370
- platform: 'ubuntu-latest'
54-
container: 'libgit2/bionic-arm64:latest'
71+
container: 'ghcr.io/libgit2/libgit2/bionic-arm64:latest'
72+
qemu: true
73+
env: { CC: 'gcc', CMAKE_GENERATOR: 'Ninja', CMAKE_OPTIONS: '-DCRYPT=openssl -DUNICODE=builtin' }
74+
75+
# Linux (arm64, Bionic, gcc, OpenSSL Dynamic)
76+
- platform: 'ubuntu-latest'
77+
container: 'ghcr.io/libgit2/libgit2/bionic-arm64:latest'
78+
qemu: true
79+
env: { CC: 'gcc', CMAKE_GENERATOR: 'Ninja', CMAKE_OPTIONS: '-DCRYPT=openssl-dynamic -DUNICODE=builtin' }
80+
81+
# Linux (amd64, CentOS 7, gcc, OpenSSL)
82+
- platform: 'ubuntu-latest'
83+
container: 'ghcr.io/libgit2/libgit2/centos7:latest'
5584
qemu: true
5685
env: { CC: 'gcc', CMAKE_OPTIONS: '-DCRYPT=openssl -DUNICODE=builtin' }
5786

87+
# Linux (arm64, CentOS 7, gcc, OpenSSL Dynamic)
88+
- platform: 'ubuntu-latest'
89+
container: 'ghcr.io/libgit2/libgit2/centos7:latest'
90+
qemu: true
91+
env: { CC: 'gcc', CMAKE_OPTIONS: '-DCRYPT=openssl-dynamic -DUNICODE=builtin' }
92+
93+
# Linux (amd64, CentOS 8, gcc, OpenSSL)
94+
- platform: 'ubuntu-latest'
95+
container: 'ghcr.io/libgit2/libgit2/centos8:latest'
96+
qemu: true
97+
env: { CC: 'gcc', CMAKE_OPTIONS: '-DCRYPT=openssl -DUNICODE=builtin' }
98+
99+
# Linux (arm64, CentOS 8, gcc, OpenSSL Dynamic)
100+
- platform: 'ubuntu-latest'
101+
container: 'ghcr.io/libgit2/libgit2/centos8:latest'
102+
qemu: true
103+
env: { CC: 'gcc', CMAKE_OPTIONS: '-DCRYPT=openssl-dynamic -DUNICODE=builtin' }
104+
58105
# macOS
59106
- platform: 'macos-latest'
60107
container: ''

CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ OPTION(ENABLE_ASAN "Enable AddressSanitizer" OFF)
1919
OPTION(ENABLE_WERROR "Treat warnings as errors" ON)
2020

2121
SET(UNICODE "default" CACHE STRING "Unicode implementation to use; may be 'iconv' or 'builtin'.")
22-
SET(CRYPT "default" CACHE STRING "Cryptographic implementation to use; may be 'commoncrypto', 'mbedtls' or 'openssl'.")
22+
SET(CRYPT "default" CACHE STRING "Cryptographic implementation to use; may be 'commoncrypto', 'mbedtls', 'openssl', or 'openssl-dynamic'.")
2323

2424
SET(PATH_SRC "${NTLM_SOURCE_DIR}/src")
2525
SET(PATH_INCLUDE "${NTLM_SOURCE_DIR}/include")
@@ -119,11 +119,19 @@ ELSEIF(CRYPT STREQUAL "openssl")
119119
LIST(APPEND NTLM_PC_LIBS ${OPENSSL_LIBRARIES})
120120

121121
ADD_FEATURE_INFO(CRYPT ON "using OpenSSL")
122+
ELSEIF(CRYPT STREQUAL "openssl-dynamic")
123+
ADD_DEFINITIONS(-DCRYPT_OPENSSL)
124+
ADD_DEFINITIONS(-DCRYPT_OPENSSL_DYNAMIC)
125+
FILE(GLOB NTLM_SRC_CRYPT "${PATH_SRC}/crypt_openssl.c")
126+
127+
LIST(APPEND NTLM_LIBS dl)
128+
129+
ADD_FEATURE_INFO(CRYPT ON "using OpenSSL (dynamic)")
122130
ELSE()
123131
MESSAGE(FATAL_ERROR "invalid cryptographic support requested: ${CRYPT}")
124132
ENDIF()
125133

126-
SET(CMAKE_C_FLAGS "-std=c99 -D_DEFAULT_SOURCE")
134+
SET(CMAKE_C_FLAGS "-std=gnu99 -D_DEFAULT_SOURCE")
127135

128136
ENABLE_WARNINGS(all)
129137
ENABLE_WARNINGS(extra)
@@ -186,6 +194,9 @@ IF(BUILD_LIBRARY)
186194
ENDIF()
187195

188196
IF(BUILD_TESTS)
197+
SET(Python_ADDITIONAL_VERSIONS 3 2.7)
198+
FIND_PACKAGE(PythonInterp)
199+
189200
FILE(GLOB NTLM_TEST "${PATH_TESTS}/*.c")
190201

191202
ADD_CUSTOM_COMMAND(

ci/build.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set -e
55
SOURCE_DIR=${SOURCE_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && dirname $( pwd ) )}
66
BUILD_DIR=$(pwd)
77
CC=${CC:-cc}
8+
CMAKE_GENERATOR=${CMAKE_GENERATOR:-Unix Makefiles}
89

910
indent() { sed "s/^/ /"; }
1011

@@ -35,8 +36,8 @@ echo "##########################################################################
3536
echo "## Configuring build environment"
3637
echo "##############################################################################"
3738

38-
echo cmake ${SOURCE_DIR} -DENABLE_WERROR=ON ${CMAKE_OPTIONS}
39-
cmake ${SOURCE_DIR} -DENABLE_WERROR=ON ${CMAKE_OPTIONS}
39+
echo cmake ${SOURCE_DIR} -DENABLE_WERROR=ON -G ${CMAKE_GENERATOR} ${CMAKE_OPTIONS}
40+
cmake ${SOURCE_DIR} -DENABLE_WERROR=ON -G "${CMAKE_GENERATOR}" ${CMAKE_OPTIONS}
4041

4142
echo ""
4243
echo "##############################################################################"

src/crypt.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,42 @@
2525

2626
typedef unsigned char ntlm_des_block[CRYPT_DES_BLOCKSIZE];
2727

28+
typedef struct ntlm_crypt_ctx ntlm_crypt_ctx;
29+
30+
extern bool ntlm_crypt_init(ntlm_client *ntlm);
31+
2832
extern bool ntlm_random_bytes(
29-
ntlm_client *ntlm,
3033
unsigned char *out,
34+
ntlm_client *ntlm,
3135
size_t len);
3236

3337
extern bool ntlm_des_encrypt(
3438
ntlm_des_block *out,
39+
ntlm_client *ntlm,
3540
ntlm_des_block *plaintext,
3641
ntlm_des_block *key);
3742

3843
extern bool ntlm_md4_digest(
3944
unsigned char out[CRYPT_MD4_DIGESTSIZE],
45+
ntlm_client *ntlm,
4046
const unsigned char *in,
4147
size_t in_len);
4248

43-
extern ntlm_hmac_ctx *ntlm_hmac_ctx_init(void);
44-
45-
extern bool ntlm_hmac_ctx_reset(ntlm_hmac_ctx *ctx);
46-
4749
extern bool ntlm_hmac_md5_init(
48-
ntlm_hmac_ctx *ctx,
50+
ntlm_client *ntlm,
4951
const unsigned char *key,
5052
size_t key_len);
5153

5254
extern bool ntlm_hmac_md5_update(
53-
ntlm_hmac_ctx *ctx,
55+
ntlm_client *ntlm,
5456
const unsigned char *data,
5557
size_t data_len);
5658

5759
extern bool ntlm_hmac_md5_final(
5860
unsigned char *out,
5961
size_t *out_len,
60-
ntlm_hmac_ctx *ctx);
62+
ntlm_client *ntlm);
6163

62-
extern void ntlm_hmac_ctx_free(ntlm_hmac_ctx *ctx);
64+
extern void ntlm_crypt_shutdown(ntlm_client *ntlm);
6365

6466
#endif /* PRIVATE_CRYPT_COMMON_H__ */

src/crypt_commoncrypto.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@
1818
#include "ntlm.h"
1919
#include "crypt.h"
2020

21+
bool ntlm_crypt_init(ntlm_client *ntlm)
22+
{
23+
memset(&ntlm->crypt_ctx, 0, sizeof(ntlm_crypt_ctx));
24+
return true;
25+
}
26+
2127
bool ntlm_random_bytes(
22-
ntlm_client *ntlm,
2328
unsigned char *out,
29+
ntlm_client *ntlm,
2430
size_t len)
2531
{
2632
int fd, ret;
@@ -49,11 +55,14 @@ bool ntlm_random_bytes(
4955

5056
bool ntlm_des_encrypt(
5157
ntlm_des_block *out,
58+
ntlm_client *ntlm,
5259
ntlm_des_block *plaintext,
5360
ntlm_des_block *key)
5461
{
5562
size_t written;
5663

64+
NTLM_UNUSED(ntlm);
65+
5766
CCCryptorStatus result = CCCrypt(kCCEncrypt,
5867
kCCAlgorithmDES, kCCOptionECBMode,
5968
key, sizeof(ntlm_des_block), NULL,
@@ -65,56 +74,47 @@ bool ntlm_des_encrypt(
6574

6675
bool ntlm_md4_digest(
6776
unsigned char out[CRYPT_MD4_DIGESTSIZE],
77+
ntlm_client *ntlm,
6878
const unsigned char *in,
6979
size_t in_len)
7080
{
81+
NTLM_UNUSED(ntlm);
7182
return !!CC_MD4(in, in_len, out);
7283
}
7384

74-
ntlm_hmac_ctx *ntlm_hmac_ctx_init(void)
75-
{
76-
return calloc(1, sizeof(ntlm_hmac_ctx));
77-
}
78-
79-
bool ntlm_hmac_ctx_reset(ntlm_hmac_ctx *ctx)
80-
{
81-
memset(ctx, 0, sizeof(ntlm_hmac_ctx));
82-
return true;
83-
}
84-
8585
bool ntlm_hmac_md5_init(
86-
ntlm_hmac_ctx *ctx,
86+
ntlm_client *ntlm,
8787
const unsigned char *key,
8888
size_t key_len)
8989
{
90-
CCHmacInit(&ctx->native, kCCHmacAlgMD5, key, key_len);
90+
CCHmacInit(&ntlm->crypt_ctx.hmac, kCCHmacAlgMD5, key, key_len);
9191
return true;
9292
}
9393

9494
bool ntlm_hmac_md5_update(
95-
ntlm_hmac_ctx *ctx,
95+
ntlm_client *ntlm,
9696
const unsigned char *data,
9797
size_t data_len)
9898
{
99-
CCHmacUpdate(&ctx->native, data, data_len);
99+
CCHmacUpdate(&ntlm->crypt_ctx.hmac, data, data_len);
100100
return true;
101101
}
102102

103103
bool ntlm_hmac_md5_final(
104104
unsigned char *out,
105105
size_t *out_len,
106-
ntlm_hmac_ctx *ctx)
106+
ntlm_client *ntlm)
107107
{
108108
if (*out_len < CRYPT_MD5_DIGESTSIZE)
109109
return false;
110110

111-
CCHmacFinal(&ctx->native, out);
111+
CCHmacFinal(&ntlm->crypt_ctx.hmac, out);
112112

113113
*out_len = CRYPT_MD5_DIGESTSIZE;
114114
return true;
115115
}
116116

117-
void ntlm_hmac_ctx_free(ntlm_hmac_ctx *ctx)
117+
void ntlm_crypt_shutdown(ntlm_client *ntlm)
118118
{
119-
free(ctx);
119+
NTLM_UNUSED(ntlm);
120120
}

src/crypt_commoncrypto.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
#include <CommonCrypto/CommonCrypto.h>
1313

14-
typedef struct {
15-
CCHmacContext native;
16-
} ntlm_hmac_ctx;
14+
struct ntlm_crypt_ctx {
15+
CCHmacContext hmac;
16+
};
1717

1818
#endif /* PRIVATE_CRYPT_COMMONCRYPTO_H__ */

0 commit comments

Comments
 (0)