Skip to content

Commit ed3a9a3

Browse files
authored
Merge branch 'main' into ocsp-tighten-url-parsing
2 parents 72dc1b6 + 9651480 commit ed3a9a3

8 files changed

Lines changed: 62 additions & 12 deletions

File tree

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ if(ENABLE_DIST_PKG)
8686
else()
8787
set(SET_LIB_SONAME 1)
8888
set(COHABITANT_HEADERS 1)
89+
set(COHABITANT_BINARIES 1)
8990
if(ENABLE_DIST_PKG_OPENSSL_SHIM)
9091
set(INSTALL_OPENSSL_SHIM 1)
9192
else()
@@ -95,15 +96,18 @@ if(ENABLE_DIST_PKG)
9596
elseif(NOT ENABLE_PRE_SONAME_BUILD AND BUILD_SHARED_LIBS AND UNIX AND NOT APPLE)
9697
set(SET_LIB_SONAME 1)
9798
set(COHABITANT_HEADERS 0)
99+
set(COHABITANT_BINARIES 0)
98100
set(INSTALL_OPENSSL_SHIM 1)
99101
else()
100102
set(SET_LIB_SONAME 0)
101103
set(COHABITANT_HEADERS 0)
104+
set(COHABITANT_BINARIES 0)
102105
set(INSTALL_OPENSSL_SHIM 1)
103106
endif()
104107

105108
message(STATUS "SET_LIB_SONAME: ${SET_LIB_SONAME}")
106109
message(STATUS "COHABITANT_HEADERS: ${COHABITANT_HEADERS}")
110+
message(STATUS "COHABITANT_BINARIES: ${COHABITANT_BINARIES}")
107111
message(STATUS "INSTALL_OPENSSL_SHIM: ${INSTALL_OPENSSL_SHIM}")
108112

109113
if(SET_LIB_SONAME)
@@ -134,6 +138,13 @@ else()
134138
set(AWSLC_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
135139
endif()
136140

141+
# Set the install bin prefix based on whether cohabitation is desired
142+
if(COHABITANT_BINARIES)
143+
set(AWSLC_BIN_PREFIX "aws-lc-")
144+
else()
145+
set(AWSLC_BIN_PREFIX "")
146+
endif()
147+
137148
function(target_add_awslc_include_paths)
138149
set(options EXCLUDE_PREFIX_HEADERS)
139150
set(oneValueArgs TARGET SCOPE)

crypto/ecdh_extra/ecdh_extra.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ int ECDH_compute_key(void *out, size_t out_len, const EC_POINT *pub_key,
2727
const EC_KEY *priv_key,
2828
void *(*kdf)(const void *in, size_t inlen, void *out,
2929
size_t *out_len)) {
30-
30+
int ret = -1;
3131
uint8_t buf[EC_MAX_BYTES];
3232
size_t buf_len = sizeof(buf);
3333

3434
if (!ECDH_compute_shared_secret(buf, &buf_len, pub_key, priv_key)) {
35-
return -1;
35+
goto end;
3636
}
3737

3838
if (kdf != NULL) {
3939
if (kdf(buf, buf_len, out, &out_len) == NULL) {
4040
OPENSSL_PUT_ERROR(ECDH, ECDH_R_KDF_FAILED);
41-
return -1;
41+
goto end;
4242
}
4343
} else {
4444
// no KDF, just copy as much as we can
@@ -50,8 +50,11 @@ int ECDH_compute_key(void *out, size_t out_len, const EC_POINT *pub_key,
5050

5151
if (out_len > INT_MAX) {
5252
OPENSSL_PUT_ERROR(ECDH, ERR_R_OVERFLOW);
53-
return -1;
53+
goto end;
5454
}
5555

56-
return (int)out_len;
56+
ret = (int)out_len;
57+
end:
58+
OPENSSL_cleanse(buf, sizeof(buf));
59+
return ret;
5760
}

crypto/fipsmodule/evp/p_ec.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ static int pkey_ec_verify(EVP_PKEY_CTX *ctx, const uint8_t *sig, size_t siglen,
8888

8989
static int pkey_ec_derive(EVP_PKEY_CTX *ctx, uint8_t *key,
9090
size_t *keylen) {
91+
int ret = 0;
9192
const EC_POINT *pubkey = NULL;
9293
EC_KEY *eckey;
9394
uint8_t buf[EC_MAX_BYTES];
@@ -115,7 +116,7 @@ static int pkey_ec_derive(EVP_PKEY_CTX *ctx, uint8_t *key,
115116
// Note: This is an internal function which will not update
116117
// the service indicator.
117118
if (!ECDH_compute_shared_secret(buf, &buflen, pubkey, eckey)) {
118-
return 0;
119+
goto end;
119120
}
120121

121122
if (buflen < *keylen) {
@@ -127,7 +128,11 @@ static int pkey_ec_derive(EVP_PKEY_CTX *ctx, uint8_t *key,
127128
// referenced from the higher level function |EVP_PKEY_derive|. |EC_KEY| is
128129
// is the only possible key that can do derivations.
129130
ECDH_verify_service_indicator(eckey);
130-
return 1;
131+
ret = 1;
132+
133+
end:
134+
OPENSSL_cleanse(buf, sizeof(buf));
135+
return ret;
131136
}
132137

133138
static int pkey_ec_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {

crypto/fipsmodule/pbkdf/pbkdf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <string.h>
88

99
#include <openssl/hmac.h>
10+
#include <openssl/mem.h>
1011

1112
#include "../../internal.h"
1213
#include "../service_indicator/internal.h"
@@ -21,6 +22,7 @@ int PKCS5_PBKDF2_HMAC(const char *password, size_t password_len,
2122
uint32_t i = 1;
2223
HMAC_CTX hctx;
2324
HMAC_CTX_init(&hctx);
25+
uint8_t digest_tmp[EVP_MAX_MD_SIZE];
2426

2527
// We have to avoid the underlying SHA services updating the indicator
2628
// state, so we lock the state here.
@@ -43,7 +45,6 @@ int PKCS5_PBKDF2_HMAC(const char *password, size_t password_len,
4345
i_buf[3] = (uint8_t)(i & 0xff);
4446

4547
// Compute U_1.
46-
uint8_t digest_tmp[EVP_MAX_MD_SIZE];
4748
if (!HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL) ||
4849
!HMAC_Update(&hctx, salt, salt_len) ||
4950
!HMAC_Update(&hctx, i_buf, 4) ||
@@ -87,6 +88,7 @@ int PKCS5_PBKDF2_HMAC(const char *password, size_t password_len,
8788
ret = 1;
8889

8990
err:
91+
OPENSSL_cleanse(digest_tmp, sizeof(digest_tmp));
9092
FIPS_service_indicator_unlock_state();
9193
HMAC_CTX_cleanup(&hctx);
9294
if (ret) {

crypto/hpke/hpke.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <openssl/err.h>
1414
#include <openssl/evp_errors.h>
1515
#include <openssl/hkdf.h>
16+
#include <openssl/mem.h>
1617
#include <openssl/rand.h>
1718
#include <openssl/sha.h>
1819

@@ -126,11 +127,13 @@ static int dhkem_extract_and_expand(uint16_t kem_id, const EVP_MD *hkdf_md,
126127
uint8_t suite_id[5] = {'K', 'E', 'M', kem_id >> 8, kem_id & 0xff};
127128
uint8_t prk[EVP_MAX_MD_SIZE];
128129
size_t prk_len;
129-
return hpke_labeled_extract(hkdf_md, prk, &prk_len, NULL, 0, suite_id,
130+
int ret = hpke_labeled_extract(hkdf_md, prk, &prk_len, NULL, 0, suite_id,
130131
sizeof(suite_id), "eae_prk", dh, dh_len) &&
131132
hpke_labeled_expand(hkdf_md, out_key, out_len, prk, prk_len, suite_id,
132133
sizeof(suite_id), "shared_secret", kem_context,
133134
kem_context_len);
135+
OPENSSL_cleanse(prk, sizeof(prk));
136+
return ret;
134137
}
135138

136139
static int x25519_init_key(EVP_HPKE_KEY *key, const uint8_t *priv_key,

crypto/pem/pem_lib.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,13 @@ int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
722722
*header = headerB->data;
723723
*data = (unsigned char *)dataB->data;
724724
*len = bl;
725+
OPENSSL_cleanse(buf, sizeof(buf));
725726
OPENSSL_free(nameB);
726727
OPENSSL_free(headerB);
727728
OPENSSL_free(dataB);
728729
return 1;
729730
err:
731+
OPENSSL_cleanse(buf, sizeof(buf));
730732
BUF_MEM_free(nameB);
731733
BUF_MEM_free(headerB);
732734
BUF_MEM_free(dataB);

tool-openssl/CMakeLists.txt

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ endif()
5858

5959
target_add_awslc_include_paths(TARGET openssl SCOPE PRIVATE)
6060

61+
if(COHABITANT_BINARIES)
62+
set_target_properties(openssl PROPERTIES OUTPUT_NAME "${AWSLC_BIN_PREFIX}openssl")
63+
endif()
64+
6165
install(TARGETS openssl
6266
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
6367
BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
@@ -76,10 +80,16 @@ file(INSTALL
7680
c_rehash
7781
)
7882

83+
set(C_REHASH_INSTALL_NAME "c_rehash")
84+
85+
if(COHABITANT_BINARIES)
86+
set(C_REHASH_INSTALL_NAME "${AWSLC_BIN_PREFIX}c_rehash")
87+
endif()
88+
7989
install(
80-
PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/c_rehash.sh
81-
RENAME c_rehash
82-
DESTINATION ${CMAKE_INSTALL_BINDIR}
90+
PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/c_rehash.sh
91+
RENAME ${C_REHASH_INSTALL_NAME}
92+
DESTINATION ${CMAKE_INSTALL_BINDIR}
8393
)
8494

8595
if(MSVC AND CMAKE_BUILD_TYPE_LOWER MATCHES "relwithdebinfo" AND FIPS)
@@ -165,3 +175,13 @@ if(BUILD_TESTING)
165175
add_dependencies(tool_openssl_test openssl)
166176
set_test_location(tool_openssl_test)
167177
endif()
178+
179+
# Create binary symlinks for OpenSSL compatibility
180+
if(INSTALL_OPENSSL_SHIM AND COHABITANT_BINARIES)
181+
install(CODE "
182+
execute_process(COMMAND \${CMAKE_COMMAND} -E create_symlink
183+
\"${AWSLC_BIN_PREFIX}openssl\" \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/openssl\")
184+
execute_process(COMMAND \${CMAKE_COMMAND} -E create_symlink
185+
\"${AWSLC_BIN_PREFIX}c_rehash\" \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/c_rehash\")
186+
")
187+
endif()

tool/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ else()
4141
endif()
4242
endif()
4343

44+
if(COHABITANT_BINARIES)
45+
set_target_properties(bssl PROPERTIES OUTPUT_NAME "${AWSLC_BIN_PREFIX}bssl")
46+
endif()
47+
4448
install(TARGETS bssl
4549
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
4650
BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}

0 commit comments

Comments
 (0)