Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Implement PKCS7_verify, update PKCS7_sign #1993

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,15 @@ jobs:
- name: Run accp build
run: |
./tests/ci/integration/run_accp_integration.sh
ruby-releases:
if: github.repository_owner == 'aws'
runs-on: ubuntu-latest
steps:
- 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
- uses: actions/checkout@v3
- name: Build AWS-LC, build ruby, run tests
run: |
./tests/ci/integration/run_ruby_integration.sh ruby_3_1
13 changes: 7 additions & 6 deletions crypto/asn1/tasn_dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,12 +681,13 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in,
cont = *in;
len = p - cont + plen;
p += plen;
} else if (cst) {
// This parser historically supported BER constructed strings. We no
// longer do and will gradually tighten this parser into a DER
// parser. BER types should use |CBS_asn1_ber_to_der|.
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE);
return 0;
// TODO [childw] any further error handling we need to do here??
// } else if (cst) {
// // This parser historically supported BER constructed strings. We no
// // longer do and will gradually tighten this parser into a DER
// // parser. BER types should use |CBS_asn1_ber_to_der|.
// OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE);
// return 0;
} else {
cont = p;
len = plen;
Expand Down
22 changes: 22 additions & 0 deletions crypto/err/pkcs7.errordata
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
PKCS7,100,BAD_PKCS7_VERSION
PKCS7,113,CERTIFICATE_VERIFY_ERROR
PKCS7,123,CIPHER_HAS_NO_OBJECT_IDENTIFIER
PKCS7,106,CIPHER_NOT_INITIALIZED
PKCS7,111,CONTENT_AND_DATA_PRESENT
PKCS7,121,DECRYPT_ERROR
PKCS7,119,ERROR_ADDING_RECIPIENT
PKCS7,118,ERROR_SETTING_CIPHER
PKCS7,104,INVALID_NULL_POINTER
PKCS7,101,NOT_PKCS7_SIGNED_DATA
PKCS7,102,NO_CERTIFICATES_INCLUDED
PKCS7,105,NO_CONTENT
PKCS7,103,NO_CRLS_INCLUDED
PKCS7,112,NO_SIGNATURES_ON_DATA
PKCS7,116,NO_SIGNERS
PKCS7,122,PKCS7_DATASIGN
PKCS7,120,PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE
PKCS7,115,SIGNATURE_FAILURE
PKCS7,117,SIGNER_CERTIFICATE_NOT_FOUND
PKCS7,124,SIGNING_NOT_SUPPORTED_FOR_THIS_KEY_TYPE
PKCS7,114,SMIME_TEXT_ERROR
PKCS7,109,UNABLE_TO_FIND_MEM_BIO
PKCS7,108,UNABLE_TO_FIND_MESSAGE_DIGEST
PKCS7,125,UNKNOWN_DIGEST_TYPE
PKCS7,107,UNSUPPORTED_CONTENT_TYPE
PKCS7,110,WRONG_CONTENT_TYPE
9 changes: 9 additions & 0 deletions crypto/fipsmodule/evp/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,15 @@ int EVP_RSA_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int optype, int cmd, int p1, void *
// 2. |ctx->keygen_info[1]| -> |n|
#define EVP_PKEY_CTX_KEYGEN_INFO_COUNT 2

// EVP_PKEY_CTX_KEYGEN_INFO_COUNT is the maximum array length for
// |EVP_PKEY_CTX->keygen_info|. The array length corresponds to the number of
// arguments |BN_GENCB|'s callback function handles.
//
// |ctx->keygen_info| map to the following values in |BN_GENCB|:
// 1. |ctx->keygen_info[0]| -> |event|
// 2. |ctx->keygen_info[1]| -> |n|
#define EVP_PKEY_CTX_KEYGEN_INFO_COUNT 2

struct evp_pkey_ctx_st {
// Method associated with this operation
const EVP_PKEY_METHOD *pmeth;
Expand Down
10 changes: 10 additions & 0 deletions crypto/fipsmodule/rsa/rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,16 @@ int rsa_verify_no_self_test(int hash_nid, const uint8_t *digest,

// Check that the computed hash matches the expected hash
if (OPENSSL_memcmp(buf, signed_msg, len) != 0) {
printf("BUF 1: ");
for (size_t ii = 0; ii < len; ii++) {
printf("%02X", (unsigned)buf[ii]);
}
printf("\n");
printf("BUF 2: ");
for (size_t ii = 0; ii < len; ii++) {
printf("%02X", (unsigned)signed_msg[ii]);
}
printf("\n");
OPENSSL_PUT_ERROR(RSA, RSA_R_MISMATCHED_SIGNATURE);
goto out;
}
Expand Down
2 changes: 2 additions & 0 deletions crypto/pkcs7/bio/bio_cipher_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ static const struct CipherParams Ciphers[] = {
{"AES_256_CTR", EVP_aes_256_ctr},
{"AES_256_OFB", EVP_aes_256_ofb},
{"ChaCha20Poly1305", EVP_chacha20_poly1305},
{"DES_EDE3_CBC", EVP_des_ede3_cbc},
};

class BIOCipherTest : public testing::TestWithParam<CipherParams> {};
Expand Down Expand Up @@ -68,6 +69,7 @@ TEST_P(BIOCipherTest, Basic) {
EXPECT_FALSE(BIO_ctrl(bio_cipher.get(), BIO_C_GET_CIPHER_CTX, 0, NULL));
EXPECT_FALSE(BIO_ctrl(bio_cipher.get(), BIO_C_SSL_MODE, 0, NULL));
EXPECT_FALSE(BIO_set_cipher(bio_cipher.get(), EVP_rc4(), key, iv, /*enc*/ 1));
ASSERT_TRUE(BIO_set_cipher(bio_cipher.get(), cipher, key, iv, /*enc*/ 1));

// Round-trip using |BIO_write| for encryption with same BIOs, reset between
// encryption/decryption using |BIO_reset|. Fixed size IO.
Expand Down
15 changes: 9 additions & 6 deletions crypto/pkcs7/bio/cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,9 @@ static int enc_write(BIO *b, const char *in, int inl) {

static long enc_ctrl(BIO *b, int cmd, long num, void *ptr) {
GUARD_PTR(b);
EVP_CIPHER_CTX **cipher_ctx;
long ret = 1;

BIO_ENC_CTX *ctx = BIO_get_data(b);
EVP_CIPHER_CTX **cipher_ctx;
BIO *next = BIO_next(b);
if (ctx == NULL) {
return 0;
Expand Down Expand Up @@ -239,9 +238,6 @@ static long enc_ctrl(BIO *b, int cmd, long num, void *ptr) {
ret = BIO_ctrl(next, cmd, num, ptr);
BIO_copy_next_retry(b);
break;
case BIO_C_GET_CIPHER_STATUS:
ret = (long)ctx->ok;
break;
case BIO_C_GET_CIPHER_CTX:
cipher_ctx = (EVP_CIPHER_CTX **)ptr;
if (!cipher_ctx) {
Expand All @@ -251,6 +247,9 @@ static long enc_ctrl(BIO *b, int cmd, long num, void *ptr) {
*cipher_ctx = ctx->cipher;
BIO_set_init(b, 1);
break;
case BIO_C_GET_CIPHER_STATUS:
ret = (long)ctx->ok;
break;
// OpenSSL implements these, but because we don't need them and cipher BIO
// is internal, we can fail loudly if they're called. If this case is hit,
// it likely means you're making a change that will require implementing
Expand Down Expand Up @@ -284,7 +283,7 @@ int BIO_set_cipher(BIO *b, const EVP_CIPHER *c, const unsigned char *key,
const EVP_CIPHER *kSupportedCiphers[] = {
EVP_aes_128_cbc(), EVP_aes_128_ctr(), EVP_aes_128_ofb(),
EVP_aes_256_cbc(), EVP_aes_256_ctr(), EVP_aes_256_ofb(),
EVP_chacha20_poly1305(),
EVP_chacha20_poly1305(), EVP_des_ede3_cbc(),
};
const size_t kSupportedCiphersCount =
sizeof(kSupportedCiphers) / sizeof(EVP_CIPHER *);
Expand Down Expand Up @@ -326,3 +325,7 @@ const BIO_METHOD *BIO_f_cipher(void) { return &methods_enc; }
int BIO_get_cipher_ctx(BIO *b, EVP_CIPHER_CTX **ctx) {
return BIO_ctrl(b, BIO_C_GET_CIPHER_CTX, 0, ctx);
}

int BIO_get_cipher_status(BIO *b) {
return BIO_ctrl(b, BIO_C_GET_CIPHER_STATUS, 0, NULL);
}
Loading
Loading