Skip to content

Commit f1ae430

Browse files
committed
Make aws-lc -Werrror clean
Change-Id: I8ff30785f78fdcda136ef3fe982f8cda2edec059
1 parent cfebde0 commit f1ae430

File tree

5 files changed

+42
-33
lines changed

5 files changed

+42
-33
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ jobs:
498498
OPENSSL_CFLAGS="-I${{ env.AWS_LC_INSTALL }}/include" \
499499
OPENSSL_LIBS="-L${{ env.AWS_LC_INSTALL }}/lib -lssl -lcrypto" \
500500
LDFLAGS="-Wl,-rpath=${{ env.AWS_LC_INSTALL }}/lib" \
501-
./configure --with-crypto-library=openssl
501+
./configure --with-crypto-library=openssl --enable-werror
502502
- name: make all
503503
run: make -j3
504504
- name: Ensure the build uses AWS-LC

src/openvpn/crypto_openssl.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ crypto_clear_error(void)
229229
void
230230
crypto_print_openssl_errors(const unsigned int flags)
231231
{
232-
unsigned long err = 0;
232+
openssl_err_t err = 0;
233233
int line, errflags;
234234
const char *file, *data, *func;
235235

@@ -425,7 +425,7 @@ void
425425
print_digest(EVP_MD *digest, void *unused)
426426
{
427427
printf("%s %d bit digest size\n", md_kt_name(EVP_MD_get0_name(digest)),
428-
EVP_MD_size(digest) * 8);
428+
(int)EVP_MD_size(digest) * 8);
429429
}
430430

431431
void
@@ -1022,7 +1022,7 @@ md_get(const char *digest)
10221022
"Message hash algorithm '%s' uses a default hash "
10231023
"size (%d bytes) which is larger than " PACKAGE_NAME "'s current "
10241024
"maximum hash size (%d bytes)",
1025-
digest, EVP_MD_size(md), MAX_HMAC_KEY_LENGTH);
1025+
digest, (int)EVP_MD_size(md), MAX_HMAC_KEY_LENGTH);
10261026
}
10271027
return md;
10281028
}
@@ -1152,7 +1152,7 @@ md_ctx_cleanup(EVP_MD_CTX *ctx)
11521152
int
11531153
md_ctx_size(const EVP_MD_CTX *ctx)
11541154
{
1155-
return EVP_MD_CTX_size(ctx);
1155+
return (int)EVP_MD_CTX_size(ctx);
11561156
}
11571157

11581158
void
@@ -1201,7 +1201,7 @@ hmac_ctx_init(HMAC_CTX *ctx, const uint8_t *key, const char *mdname)
12011201
evp_md_type *kt = md_get(mdname);
12021202
ASSERT(NULL != kt && NULL != ctx);
12031203

1204-
int key_len = EVP_MD_size(kt);
1204+
size_t key_len = EVP_MD_size(kt);
12051205
HMAC_CTX_reset(ctx);
12061206
if (!HMAC_Init_ex(ctx, key, key_len, kt, NULL))
12071207
{

src/openvpn/openssl_compat.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@
4545
#include <openssl/x509.h>
4646
#include <openssl/err.h>
4747

48+
/* Define the type of error. This is something that is less
49+
* intrusive than casts everywhere */
50+
#if defined(OPENSSL_IS_AWSLC)
51+
typedef uint32_t openssl_err_t;
52+
#else
53+
typedef unsigned long openssl_err_t;
54+
#endif
55+
56+
4857
/* Functionality missing in 1.1.0 */
4958
#if OPENSSL_VERSION_NUMBER < 0x10101000L && !defined(ENABLE_CRYPTO_WOLFSSL)
5059
#define SSL_CTX_set1_groups SSL_CTX_set1_curves
@@ -157,12 +166,12 @@ EVP_MD_free(const EVP_MD *md)
157166
/* OpenSSL 1.1.1 and lower use only const EVP_MD, nothing to free */
158167
}
159168

160-
static inline unsigned long
169+
static inline openssl_err_t
161170
ERR_get_error_all(const char **file, int *line, const char **func, const char **data, int *flags)
162171
{
163172
static const char *empty = "";
164173
*func = empty;
165-
unsigned long err = ERR_get_error_line_data(file, line, data, flags);
174+
openssl_err_t err = ERR_get_error_line_data(file, line, data, flags);
166175
return err;
167176
}
168177

src/openvpn/ssl_openssl.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,9 @@ tls_ctx_restrict_ciphers_tls13(struct tls_root_ctx *ctx, const char *ciphers)
518518
void
519519
tls_ctx_set_cert_profile(struct tls_root_ctx *ctx, const char *profile)
520520
{
521-
#if OPENSSL_VERSION_NUMBER > 0x10100000L \
522-
&& (!defined(LIBRESSL_VERSION_NUMBER) || LIBRESSL_VERSION_NUMBER > 0x3060000fL)
521+
#if OPENSSL_VERSION_NUMBER > 0x10100000L \
522+
&& (!defined(LIBRESSL_VERSION_NUMBER) || LIBRESSL_VERSION_NUMBER > 0x3060000fL) \
523+
&& !defined(OPENSSL_IS_AWSLC)
523524
/* OpenSSL does not have certificate profiles, but a complex set of
524525
* callbacks that we could try to implement to achieve something similar.
525526
* For now, use OpenSSL's security levels to achieve similar (but not equal)
@@ -549,7 +550,7 @@ tls_ctx_set_cert_profile(struct tls_root_ctx *ctx, const char *profile)
549550
if (profile)
550551
{
551552
msg(M_WARN,
552-
"WARNING: OpenSSL 1.1.0 and LibreSSL do not support "
553+
"WARNING: OpenSSL 1.1.0, aws-lc and LibreSSL do not support "
553554
"--tls-cert-profile, ignoring user-set profile: '%s'",
554555
profile);
555556
}
@@ -906,7 +907,6 @@ tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file, bool pkcs
906907
X509 *cert;
907908
STACK_OF(X509) *ca = NULL;
908909
PKCS12 *p12;
909-
int i;
910910
char password[256];
911911

912912
ASSERT(NULL != ctx);
@@ -990,7 +990,7 @@ tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file, bool pkcs
990990
*/
991991
if (ca && sk_X509_num(ca))
992992
{
993-
for (i = 0; i < sk_X509_num(ca); i++)
993+
for (size_t i = 0; i < (size_t)sk_X509_num(ca); i++)
994994
{
995995
X509_STORE *cert_store = SSL_CTX_get_cert_store(ctx->ctx);
996996
if (!X509_STORE_add_cert(cert_store, sk_X509_value(ca, i)))
@@ -1015,7 +1015,7 @@ tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file, bool pkcs
10151015
*/
10161016
if (ca && sk_X509_num(ca))
10171017
{
1018-
for (i = 0; i < sk_X509_num(ca); i++)
1018+
for (size_t i = 0; i < (size_t)sk_X509_num(ca); i++)
10191019
{
10201020
if (!SSL_CTX_add_extra_chain_cert(ctx->ctx, sk_X509_value(ca, i)))
10211021
{
@@ -1331,7 +1331,7 @@ backend_tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_file, b
13311331
* we need to manually find the CRL object from the stack
13321332
* and remove it */
13331333
STACK_OF(X509_OBJECT) *objs = X509_STORE_get0_objects(store);
1334-
for (int i = 0; i < sk_X509_OBJECT_num(objs); i++)
1334+
for (size_t i = 0; i < (size_t)sk_X509_OBJECT_num(objs); i++)
13351335
{
13361336
X509_OBJECT *obj = sk_X509_OBJECT_value(objs, i);
13371337
ASSERT(obj);
@@ -1591,7 +1591,7 @@ static int
15911591
ecdsa_sign(int type, const unsigned char *dgst, int dgstlen, unsigned char *sig,
15921592
unsigned int *siglen, const BIGNUM *kinv, const BIGNUM *r, EC_KEY *ec)
15931593
{
1594-
int capacity = ECDSA_size(ec);
1594+
int capacity = (int)ECDSA_size(ec);
15951595
/*
15961596
* ECDSA does not seem to have proper constants for paddings since
15971597
* there are only signatures without padding at the moment, use
@@ -1607,12 +1607,14 @@ ecdsa_sign(int type, const unsigned char *dgst, int dgstlen, unsigned char *sig,
16071607
return 0;
16081608
}
16091609

1610+
#ifndef OPENSSL_IS_AWSLC
16101611
/* EC_KEY_METHOD callback: sign_setup(). We do no precomputations */
16111612
static int
16121613
ecdsa_sign_setup(EC_KEY *ec, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
16131614
{
16141615
return 1;
16151616
}
1617+
#endif
16161618

16171619
/* EC_KEY_METHOD callback: sign_sig().
16181620
* Sign the hash and return the result as a newly allocated ECDS_SIG
@@ -1623,7 +1625,7 @@ ecdsa_sign_sig(const unsigned char *dgst, int dgstlen, const BIGNUM *in_kinv, co
16231625
EC_KEY *ec)
16241626
{
16251627
ECDSA_SIG *ecsig = NULL;
1626-
unsigned int len = ECDSA_size(ec);
1628+
unsigned int len = (unsigned int)ECDSA_size(ec);
16271629
struct gc_arena gc = gc_new();
16281630

16291631
unsigned char *buf = gc_malloc(len, false, &gc);
@@ -1790,7 +1792,7 @@ tls_ctx_load_ca(struct tls_root_ctx *ctx, const char *ca_file, bool ca_file_inli
17901792
X509_STORE *store = NULL;
17911793
X509_NAME *xn = NULL;
17921794
BIO *in = NULL;
1793-
int i, added = 0, prev = 0;
1795+
size_t added = 0, prev = 0;
17941796

17951797
ASSERT(NULL != ctx);
17961798

@@ -1819,7 +1821,7 @@ tls_ctx_load_ca(struct tls_root_ctx *ctx, const char *ca_file, bool ca_file_inli
18191821

18201822
if (info_stack)
18211823
{
1822-
for (i = 0; i < sk_X509_INFO_num(info_stack); i++)
1824+
for (size_t i = 0; i < (size_t)sk_X509_INFO_num(info_stack); i++)
18231825
{
18241826
X509_INFO *info = sk_X509_INFO_value(info_stack, i);
18251827
if (info->crl)
@@ -1872,19 +1874,19 @@ tls_ctx_load_ca(struct tls_root_ctx *ctx, const char *ca_file, bool ca_file_inli
18721874

18731875
if (tls_server)
18741876
{
1875-
int cnum = sk_X509_NAME_num(cert_names);
1877+
size_t cnum = sk_X509_NAME_num(cert_names);
18761878
if (cnum != (prev + 1))
18771879
{
18781880
crypto_msg(M_WARN,
1879-
"Cannot load CA certificate file %s (entry %d did not validate)",
1881+
"Cannot load CA certificate file %s (entry %zu did not validate)",
18801882
print_key_filename(ca_file, ca_file_inline), added);
18811883
}
18821884
prev = cnum;
18831885
}
18841886
}
18851887
sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
18861888
}
1887-
int cnum;
1889+
size_t cnum;
18881890
if (tls_server)
18891891
{
18901892
cnum = sk_X509_NAME_num(cert_names);
@@ -1902,8 +1904,8 @@ tls_ctx_load_ca(struct tls_root_ctx *ctx, const char *ca_file, bool ca_file_inli
19021904
if (cnum != added)
19031905
{
19041906
crypto_msg(M_FATAL,
1905-
"Cannot load CA certificate file %s (only %d "
1906-
"of %d entries were valid X509 names)",
1907+
"Cannot load CA certificate file %s (only %zu "
1908+
"of %zu entries were valid X509 names)",
19071909
print_key_filename(ca_file, ca_file_inline), cnum, added);
19081910
}
19091911
}
@@ -2552,7 +2554,7 @@ show_available_tls_ciphers_list(const char *cipher_list, const char *tls_cert_pr
25522554
#else
25532555
STACK_OF(SSL_CIPHER) *sk = SSL_get1_supported_ciphers(ssl);
25542556
#endif
2555-
for (int i = 0; i < sk_SSL_CIPHER_num(sk); i++)
2557+
for (size_t i = 0; i < (size_t)sk_SSL_CIPHER_num(sk); i++)
25562558
{
25572559
const SSL_CIPHER *c = sk_SSL_CIPHER_value(sk, i);
25582560

src/openvpn/ssl_verify_openssl.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ extract_x509_extension(X509 *cert, char *fieldname, char *out, size_t size)
138138
* one, but we don't depend on it...
139139
*/
140140

141-
int numalts = sk_GENERAL_NAME_num(extensions);
141+
size_t numalts = sk_GENERAL_NAME_num(extensions);
142142

143143
/* loop through all alternatives */
144-
for (int i = 0; i < numalts; i++)
144+
for (size_t i = 0; i < numalts; i++)
145145
{
146146
/* get a handle to alternative name number i */
147147
const GENERAL_NAME *name = sk_GENERAL_NAME_value(extensions, i);
@@ -344,7 +344,7 @@ x509_get_sha1_fingerprint(X509 *cert, struct gc_arena *gc)
344344
const EVP_MD *sha1 = EVP_sha1();
345345
struct buffer hash = alloc_buf_gc((size_t)EVP_MD_size(sha1), gc);
346346
X509_digest(cert, EVP_sha1(), BPTR(&hash), NULL);
347-
ASSERT(buf_inc_len(&hash, EVP_MD_size(sha1)));
347+
ASSERT(buf_inc_len(&hash, (int)EVP_MD_size(sha1)));
348348
return hash;
349349
}
350350

@@ -354,7 +354,7 @@ x509_get_sha256_fingerprint(X509 *cert, struct gc_arena *gc)
354354
const EVP_MD *sha256 = EVP_sha256();
355355
struct buffer hash = alloc_buf_gc((size_t)EVP_MD_size(sha256), gc);
356356
X509_digest(cert, EVP_sha256(), BPTR(&hash), NULL);
357-
ASSERT(buf_inc_len(&hash, EVP_MD_size(sha256)));
357+
ASSERT(buf_inc_len(&hash, (int)EVP_MD_size(sha256)));
358358
return hash;
359359
}
360360

@@ -739,10 +739,8 @@ x509_verify_cert_eku(X509 *x509, const char *const expected_oid)
739739
}
740740
else
741741
{
742-
int i;
743-
744742
msg(D_HANDSHAKE, "Validating certificate extended key usage");
745-
for (i = 0; SUCCESS != fFound && i < sk_ASN1_OBJECT_num(eku); i++)
743+
for (size_t i = 0; SUCCESS != fFound && i < (size_t)sk_ASN1_OBJECT_num(eku); i++)
746744
{
747745
ASN1_OBJECT *oid = sk_ASN1_OBJECT_value(eku, i);
748746
char szOid[1024];
@@ -791,7 +789,7 @@ tls_verify_crl_missing(const struct tls_options *opt)
791789
}
792790

793791
STACK_OF(X509_OBJECT) *objs = X509_STORE_get0_objects(store);
794-
for (int i = 0; i < sk_X509_OBJECT_num(objs); i++)
792+
for (size_t i = 0; i < (size_t)sk_X509_OBJECT_num(objs); i++)
795793
{
796794
X509_OBJECT *obj = sk_X509_OBJECT_value(objs, i);
797795
ASSERT(obj);

0 commit comments

Comments
 (0)