Skip to content

Commit

Permalink
Add PKCS7 logic to patch
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel40791765 committed Dec 9, 2024
1 parent 53f4657 commit 4049f0b
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ jobs:
- name: Install OS Dependencies
run: |
sudo apt-get update
sudo apt-get -y --no-install-recommends install cmake gcc ninja-build golang make autoconf ruby
sudo apt-get -y --no-install-recommends install cmake gcc ninja-build golang make autoconf ruby libyaml-dev
- uses: actions/checkout@v3
- name: Build AWS-LC, build ruby, run tests
run: |
Expand Down
101 changes: 57 additions & 44 deletions tests/ci/integration/ruby_patch/ruby_3_1/aws-lc-ruby-temp.patch
Original file line number Diff line number Diff line change
Expand Up @@ -47,50 +47,6 @@ index fb947df..969aa25 100644
obj = NewPKCS12(cPKCS12);
x509s = NIL_P(ca) ? NULL : ossl_x509_ary2sk(ca);
p12 = PKCS12_create(passphrase, friendlyname, key, x509, x509s,
diff --git a/ext/openssl/ossl_pkcs7.c b/ext/openssl/ossl_pkcs7.c
index dbe5347..2dd771d 100644
--- a/ext/openssl/ossl_pkcs7.c
+++ b/ext/openssl/ossl_pkcs7.c
@@ -8,6 +8,7 @@
* (See the file 'LICENCE'.)
*/
#include "ossl.h"
+#if !defined(OPENSSL_IS_AWSLC)

#define NewPKCS7si(klass) \
TypedData_Wrap_Struct((klass), &ossl_pkcs7_signer_info_type, 0)
@@ -1079,3 +1080,10 @@ Init_ossl_pkcs7(void)
DefPKCS7Const(NOATTR);
DefPKCS7Const(NOSMIMECAP);
}
+
+#else
+void
+Init_ossl_pkcs7(void)
+{
+}
+#endif
\ No newline at end of file
diff --git a/ext/openssl/ossl_pkcs7.h b/ext/openssl/ossl_pkcs7.h
index 3e1b094..f85efcc 100644
--- a/ext/openssl/ossl_pkcs7.h
+++ b/ext/openssl/ossl_pkcs7.h
@@ -8,6 +8,7 @@
* (See the file 'LICENCE'.)
*/
#if !defined(_OSSL_PKCS7_H_)
+#if !defined(OPENSSL_IS_AWSLC)
#define _OSSL_PKCS7_H_

#define NewPKCS7(klass) \
@@ -30,6 +31,7 @@ extern VALUE cPKCS7;
extern VALUE cPKCS7Signer;
extern VALUE cPKCS7Recipient;
extern VALUE ePKCS7Error;
+#endif

void Init_ossl_pkcs7(void);

diff --git a/ext/openssl/ossl_pkey_ec.c b/ext/openssl/ossl_pkey_ec.c
index 06d59c2..74f41db 100644
--- a/ext/openssl/ossl_pkey_ec.c
Expand Down Expand Up @@ -245,6 +201,63 @@ index ec67674..be21f47 100644
2048
)

diff --git a/test/openssl/test_pkcs7.rb b/test/openssl/test_pkcs7.rb
index ba8b93d..7a23104 100644
--- a/test/openssl/test_pkcs7.rb
+++ b/test/openssl/test_pkcs7.rb
@@ -191,6 +191,8 @@ def test_set_type_encrypted
end

def test_smime
+ pend "AWS-LC has no current support for SMIME with PKCS7" if aws_lc?
+
store = OpenSSL::X509::Store.new
store.add_cert(@ca_cert)
ca_certs = [@ca_cert]
@@ -315,12 +317,42 @@ def test_split_content
AwlEke0Uze1367QKgxM0nc3SZDlptY7zPIJC5saWXb8Rt2bw2JxEBOTavrp+ZwJ8
tcH961onq8Tme2ICaCzk
-----END PKCS7-----
+END
+ # NOTE: below PEM differs very slightly from upstream ruby
+ # in that it encodes the inner EncryptedContent in
+ # definite-length DER OCTET_STRING whereas upstream (i.e.
+ # OpenSSL) encodes EncryptedContent as indefinite-length
+ # BER OCTET_STRING. The discrepancy is due to AWS-LC's lack
+ # of support for indefinite OCTET_STRINGS.
+ pki_message_content_pem_awslc = <<END
+-----BEGIN PKCS7-----
+MIIDcQYJKoZIhvcNAQcDoIIDYjCCA14CAQAxggEQMIIBDAIBADB1MHAxEDAOBgNV
+BAoMB2V4YW1wbGUxFzAVBgNVBAMMDlRBUk1BQyBST09UIENBMSIwIAYJKoZIhvcN
+AQkBFhNzb21lb25lQGV4YW1w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_msg = OpenSSL::PKCS7.new(pki_message_pem)
store = OpenSSL::X509::Store.new
pki_msg.verify(nil, store, nil, OpenSSL::PKCS7::NOVERIFY)
p7enc = OpenSSL::PKCS7.new(pki_msg.data)
- assert_equal(pki_message_content_pem, p7enc.to_pem)
+ assert_equal(pki_message_content_pem, p7enc.to_pem) if !aws_lc?
+ assert_equal(pki_message_content_pem_awslc, p7enc.to_pem) if aws_lc?
end
end

diff --git a/test/openssl/test_pkey_dh.rb b/test/openssl/test_pkey_dh.rb
index 161af18..055131d 100644
--- a/test/openssl/test_pkey_dh.rb
Expand Down
101 changes: 57 additions & 44 deletions tests/ci/integration/ruby_patch/ruby_3_2/aws-lc-ruby-temp.patch
Original file line number Diff line number Diff line change
Expand Up @@ -47,50 +47,6 @@ index fb947df..969aa25 100644
obj = NewPKCS12(cPKCS12);
x509s = NIL_P(ca) ? NULL : ossl_x509_ary2sk(ca);
p12 = PKCS12_create(passphrase, friendlyname, key, x509, x509s,
diff --git a/ext/openssl/ossl_pkcs7.c b/ext/openssl/ossl_pkcs7.c
index dbe5347..2dd771d 100644
--- a/ext/openssl/ossl_pkcs7.c
+++ b/ext/openssl/ossl_pkcs7.c
@@ -8,6 +8,7 @@
* (See the file 'LICENCE'.)
*/
#include "ossl.h"
+#if !defined(OPENSSL_IS_AWSLC)

#define NewPKCS7si(klass) \
TypedData_Wrap_Struct((klass), &ossl_pkcs7_signer_info_type, 0)
@@ -1079,3 +1080,10 @@ Init_ossl_pkcs7(void)
DefPKCS7Const(NOATTR);
DefPKCS7Const(NOSMIMECAP);
}
+
+#else
+void
+Init_ossl_pkcs7(void)
+{
+}
+#endif
\ No newline at end of file
diff --git a/ext/openssl/ossl_pkcs7.h b/ext/openssl/ossl_pkcs7.h
index 3e1b094..f85efcc 100644
--- a/ext/openssl/ossl_pkcs7.h
+++ b/ext/openssl/ossl_pkcs7.h
@@ -8,6 +8,7 @@
* (See the file 'LICENCE'.)
*/
#if !defined(_OSSL_PKCS7_H_)
+#if !defined(OPENSSL_IS_AWSLC)
#define _OSSL_PKCS7_H_

#define NewPKCS7(klass) \
@@ -30,6 +31,7 @@ extern VALUE cPKCS7;
extern VALUE cPKCS7Signer;
extern VALUE cPKCS7Recipient;
extern VALUE ePKCS7Error;
+#endif

void Init_ossl_pkcs7(void);

diff --git a/ext/openssl/ossl_pkey_ec.c b/ext/openssl/ossl_pkey_ec.c
index 92842f9..ad59300 100644
--- a/ext/openssl/ossl_pkey_ec.c
Expand Down Expand Up @@ -245,6 +201,63 @@ index ec67674..be21f47 100644
2048
)

diff --git a/test/openssl/test_pkcs7.rb b/test/openssl/test_pkcs7.rb
index ba8b93d..7a23104 100644
--- a/test/openssl/test_pkcs7.rb
+++ b/test/openssl/test_pkcs7.rb
@@ -191,6 +191,8 @@ def test_set_type_encrypted
end

def test_smime
+ pend "AWS-LC has no current support for SMIME with PKCS7" if aws_lc?
+
store = OpenSSL::X509::Store.new
store.add_cert(@ca_cert)
ca_certs = [@ca_cert]
@@ -315,12 +317,42 @@ def test_split_content
AwlEke0Uze1367QKgxM0nc3SZDlptY7zPIJC5saWXb8Rt2bw2JxEBOTavrp+ZwJ8
tcH961onq8Tme2ICaCzk
-----END PKCS7-----
+END
+ # NOTE: below PEM differs very slightly from upstream ruby
+ # in that it encodes the inner EncryptedContent in
+ # definite-length DER OCTET_STRING whereas upstream (i.e.
+ # OpenSSL) encodes EncryptedContent as indefinite-length
+ # BER OCTET_STRING. The discrepancy is due to AWS-LC's lack
+ # of support for indefinite OCTET_STRINGS.
+ pki_message_content_pem_awslc = <<END
+-----BEGIN PKCS7-----
+MIIDcQYJKoZIhvcNAQcDoIIDYjCCA14CAQAxggEQMIIBDAIBADB1MHAxEDAOBgNV
+BAoMB2V4YW1wbGUxFzAVBgNVBAMMDlRBUk1BQyBST09UIENBMSIwIAYJKoZIhvcN
+AQkBFhNzb21lb25lQGV4YW1wbGUub3JnMQswCQYDVQQGEwJVUzESMBAGA1UEBwwJ
+VG93biBIYWxsAgFmMA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, store, nil, OpenSSL::PKCS7::NOVERIFY)
p7enc = OpenSSL::PKCS7.new(pki_msg.data)
- assert_equal(pki_message_content_pem, p7enc.to_pem)
+ assert_equal(pki_message_content_pem, p7enc.to_pem) if !aws_lc?
+ assert_equal(pki_message_content_pem_awslc, p7enc.to_pem) if aws_lc?
end
end

diff --git a/test/openssl/test_pkey_dh.rb b/test/openssl/test_pkey_dh.rb
index 161af18..055131d 100644
--- a/test/openssl/test_pkey_dh.rb
Expand Down

0 comments on commit 4049f0b

Please sign in to comment.