Skip to content

Commit 697d449

Browse files
authored
Merge pull request #852 from samuel40791765/aws-lc-support-1
Add build support for AWS-LC
2 parents 41e07af + e53ec5a commit 697d449

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
lines changed

.github/workflows/test.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ jobs:
7373
# http://www.libressl.org/releases.html
7474
- libressl-3.9.2 # Supported until 2025-04-05
7575
- libressl-4.0.0 # Supported until 2025-10-08
76+
# https://github.com/aws/aws-lc/tags
77+
- aws-lc-latest
7678
include:
7779
- { name-extra: 'with fips provider', openssl: openssl-3.0.15, fips-enabled: true }
7880
- { name-extra: 'with fips provider', openssl: openssl-3.1.7, fips-enabled: true }
@@ -81,6 +83,7 @@ jobs:
8183
- { name-extra: 'with fips provider', openssl: openssl-3.4.0, fips-enabled: true }
8284
- { name-extra: 'with fips provider', openssl: openssl-master, fips-enabled: true }
8385
- { name-extra: 'without legacy provider', openssl: openssl-3.4.0, append-configure: 'no-legacy' }
86+
- { openssl: aws-lc-latest, skip-warnings: true, skip-tests: true } # Remove "skip-tests" once AWS-LC tests are working.
8487
steps:
8588
- name: repo checkout
8689
uses: actions/checkout@v4
@@ -120,6 +123,13 @@ jobs:
120123
./configure --prefix=$HOME/openssl
121124
make -j4 && make install
122125
;;
126+
aws-lc-*)
127+
git clone https://github.com/aws/aws-lc.git .
128+
AWS_LC_RELEASE=$(git tag --sort=-creatordate --list "v*" | head -1)
129+
git checkout $AWS_LC_RELEASE
130+
cmake -DCMAKE_INSTALL_PREFIX=$HOME/openssl
131+
make -j4 && make install
132+
;;
123133
*)
124134
false
125135
;;
@@ -150,7 +160,7 @@ jobs:
150160
- name: rake test
151161
run: bundle exec rake test TESTOPTS="-v --no-show-detail-immediately"
152162
timeout-minutes: 5
153-
if: ${{ !matrix.fips-enabled }}
163+
if: ${{ !matrix.fips-enabled && !matrix.skip-tests }}
154164

155165
# Run only the passing tests on the FIPS module as a temporary workaround.
156166
# TODO Fix other tests, and run all the tests on FIPS module.

ext/openssl/ossl.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ ossl_fips_mode_get(VALUE self)
404404
VALUE enabled;
405405
enabled = EVP_default_properties_is_fips_enabled(NULL) ? Qtrue : Qfalse;
406406
return enabled;
407-
#elif defined(OPENSSL_FIPS)
407+
#elif defined(OPENSSL_FIPS) || defined(OPENSSL_IS_AWSLC)
408408
VALUE enabled;
409409
enabled = FIPS_mode() ? Qtrue : Qfalse;
410410
return enabled;
@@ -439,7 +439,7 @@ ossl_fips_mode_set(VALUE self, VALUE enabled)
439439
}
440440
}
441441
return enabled;
442-
#elif defined(OPENSSL_FIPS)
442+
#elif defined(OPENSSL_FIPS) || defined(OPENSSL_IS_AWSLC)
443443
if (RTEST(enabled)) {
444444
int mode = FIPS_mode();
445445
if(!mode && !FIPS_mode_set(1)) /* turning on twice leads to an error */
@@ -1004,6 +1004,8 @@ Init_openssl(void)
10041004
Qtrue
10051005
#elif defined(OPENSSL_FIPS)
10061006
Qtrue
1007+
#elif defined(OPENSSL_IS_AWSLC) // AWS-LC FIPS can only be enabled during compile time.
1008+
FIPS_mode() ? Qtrue : Qfalse
10071009
#else
10081010
Qfalse
10091011
#endif

ext/openssl/ossl_pkcs12.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,15 @@ ossl_pkcs12_s_create(int argc, VALUE *argv, VALUE self)
134134
if (!NIL_P(keytype))
135135
ktype = NUM2INT(keytype);
136136

137+
#if defined(OPENSSL_IS_AWSLC)
138+
if (ktype != 0) {
139+
ossl_raise(rb_eArgError, "Unknown key usage type %"PRIsVALUE, INT2NUM(ktype));
140+
}
141+
#else
137142
if (ktype != 0 && ktype != KEY_SIG && ktype != KEY_EX) {
138143
ossl_raise(rb_eArgError, "Unknown key usage type %"PRIsVALUE, INT2NUM(ktype));
139144
}
145+
#endif
140146

141147
obj = NewPKCS12(cPKCS12);
142148
x509s = NIL_P(ca) ? NULL : ossl_x509_ary2sk(ca);
@@ -316,7 +322,9 @@ Init_ossl_pkcs12(void)
316322
rb_define_method(cPKCS12, "to_der", ossl_pkcs12_to_der, 0);
317323
rb_define_method(cPKCS12, "set_mac", pkcs12_set_mac, -1);
318324

325+
#if !defined(OPENSSL_IS_AWSLC)
319326
/* MSIE specific PKCS12 key usage extensions */
320327
rb_define_const(cPKCS12, "KEY_EX", INT2NUM(KEY_EX));
321328
rb_define_const(cPKCS12, "KEY_SIG", INT2NUM(KEY_SIG));
329+
#endif
322330
}

ext/openssl/ossl_pkey_ec.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,11 @@ static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
657657
ossl_clear_error(); /* ignore errors in d2i_ECPKParameters_bio() */
658658
if (nid == NID_undef)
659659
ossl_raise(eEC_GROUP, "unknown curve name (%"PRIsVALUE")", arg1);
660-
660+
#if !defined(OPENSSL_IS_AWSLC)
661661
group = EC_GROUP_new_by_curve_name(nid);
662+
#else /* EC_GROUPs are static and immutable by default in AWS-LC. */
663+
group = EC_GROUP_new_by_curve_name_mutable(nid);
664+
#endif
662665
if (group == NULL)
663666
ossl_raise(eEC_GROUP, "unable to create curve (%"PRIsVALUE")", arg1);
664667

@@ -1367,7 +1370,7 @@ static VALUE ossl_ec_point_make_affine(VALUE self)
13671370
GetECPointGroup(self, group);
13681371

13691372
rb_warn("OpenSSL::PKey::EC::Point#make_affine! is deprecated");
1370-
#if !OSSL_OPENSSL_PREREQ(3, 0, 0)
1373+
#if !OSSL_OPENSSL_PREREQ(3, 0, 0) && !defined(OPENSSL_IS_AWSLC)
13711374
if (EC_POINT_make_affine(group, point, ossl_bn_ctx) != 1)
13721375
ossl_raise(eEC_POINT, "EC_POINT_make_affine");
13731376
#endif

ext/openssl/ossl_ssl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,9 @@ ossl_sslctx_setup(VALUE self)
705705
SSL_CTX_set_tmp_dh_callback(ctx, ossl_tmp_dh_callback);
706706
#endif
707707

708+
#if !defined(OPENSSL_IS_AWSLC) /* AWS-LC has no support for TLS 1.3 PHA. */
708709
SSL_CTX_set_post_handshake_auth(ctx, 1);
710+
#endif
709711

710712
val = rb_attr_get(self, id_i_cert_store);
711713
if (!NIL_P(val)) {

test/openssl/utils.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def get_subject_key_id(cert, hex: true)
103103
end
104104

105105
def openssl?(major = nil, minor = nil, fix = nil, patch = 0, status = 0)
106-
return false if OpenSSL::OPENSSL_VERSION.include?("LibreSSL")
106+
return false if OpenSSL::OPENSSL_VERSION.include?("LibreSSL") || OpenSSL::OPENSSL_VERSION.include?("AWS-LC")
107107
return true unless major
108108
OpenSSL::OPENSSL_VERSION_NUMBER >=
109109
major * 0x10000000 + minor * 0x100000 + fix * 0x1000 + patch * 0x10 +
@@ -115,6 +115,10 @@ def libressl?(major = nil, minor = nil, fix = nil)
115115
return false unless version
116116
!major || (version.map(&:to_i) <=> [major, minor, fix]) >= 0
117117
end
118+
119+
def aws_lc?
120+
OpenSSL::OPENSSL_VERSION.include?("AWS-LC")
121+
end
118122
end
119123

120124
class OpenSSL::TestCase < Test::Unit::TestCase

0 commit comments

Comments
 (0)