grpc
third_party
boringssl-with-bazel
src
crypto
pem
pem_test.cc
Go to the documentation of this file.
1
/* Copyright (c) 2018, Google Inc.
2
*
3
* Permission to use, copy, modify, and/or distribute this software for any
4
* purpose with or without fee is hereby granted, provided that the above
5
* copyright notice and this permission notice appear in all copies.
6
*
7
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15
#include <
openssl/pem.h
>
16
17
#include <gtest/gtest.h>
18
19
#include <
openssl/bio.h
>
20
#include <
openssl/err.h
>
21
#include <
openssl/rsa.h
>
22
23
24
// Test that implausible ciphers, notably an IV-less RC4, aren't allowed in PEM.
25
// This is a regression test for https://github.com/openssl/openssl/issues/6347,
26
// though our fix differs from upstream.
27
TEST
(PEMTest, NoRC4) {
28
static
const
char
kPEM[] =
29
"-----BEGIN RSA PUBLIC KEY-----\n"
30
"Proc-Type: 4,ENCRYPTED\n"
31
"DEK-Info: RC4 -\n"
32
"extra-info\n"
33
"router-signature\n"
34
"\n"
35
"Z1w=\n"
36
"-----END RSA PUBLIC KEY-----\n"
;
37
bssl::UniquePtr<BIO> bio(
BIO_new_mem_buf
(kPEM,
sizeof
(kPEM) - 1));
38
ASSERT_TRUE
(bio);
39
bssl::UniquePtr<RSA> rsa(
PEM_read_bio_RSAPublicKey
(
40
bio.get(),
nullptr
,
nullptr
,
const_cast<
char
*
>
(
"password"
)));
41
EXPECT_FALSE
(rsa);
42
uint32_t
err
=
ERR_get_error
();
43
EXPECT_EQ
(
ERR_LIB_PEM
,
ERR_GET_LIB
(
err
));
44
EXPECT_EQ
(
PEM_R_UNSUPPORTED_ENCRYPTION
,
ERR_GET_REASON
(
err
));
45
}
EXPECT_FALSE
#define EXPECT_FALSE(condition)
Definition:
bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1970
PEM_R_UNSUPPORTED_ENCRYPTION
#define PEM_R_UNSUPPORTED_ENCRYPTION
Definition:
pem.h:481
bio.h
error_ref_leak.err
err
Definition:
error_ref_leak.py:35
pem.h
PEM_read_bio_RSAPublicKey
#define PEM_read_bio_RSAPublicKey
Definition:
boringssl_prefix_symbols.h:1953
ERR_get_error
#define ERR_get_error
Definition:
boringssl_prefix_symbols.h:1419
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition:
iomgr/time_averaged_stats_test.cc:27
uint32_t
unsigned int uint32_t
Definition:
stdint-msvc2008.h:80
BIO_new_mem_buf
#define BIO_new_mem_buf
Definition:
boringssl_prefix_symbols.h:820
ERR_GET_REASON
#define ERR_GET_REASON(packed_error)
Definition:
err.h:171
ERR_GET_LIB
#define ERR_GET_LIB(packed_error)
Definition:
err.h:166
err.h
rsa.h
ERR_LIB_PEM
@ ERR_LIB_PEM
Definition:
err.h:300
TEST
TEST(PEMTest, NoRC4)
Definition:
pem_test.cc:27
ASSERT_TRUE
#define ASSERT_TRUE(condition)
Definition:
bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1973
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:41