return 0;
}
- int encrypt(CephContext *cct, const ceph::bufferlist& in,
- ceph::bufferlist& out,
- std::string* /* unused */) const override {
+ int encrypt_ext(CephContext *cct, const ceph::bufferlist& in,
+ const ceph::bufferlist *confounder,
+ ceph::bufferlist& out,
+ std::string* /* unused */) const override {
ldout(cct, 20) << "CryptoAES256KRB5KeyHandler::encrypt()" << dendl;
// encrypted (confounder | data) | hash
ceph::bufferptr out_tmp{static_cast<unsigned>(
char *aes_enc = out_tmp.c_str();
int aes_enc_len = AES256KRB5_BLOCK_LEN + in.length();
- /* plaintext confounder */
- bufferptr confounder(AES256KRB5_BLOCK_LEN);
- cct->random()->get_bytes(confounder.c_str(), confounder.length());
+ ceph::bufferlist incopy;
+ bufferptr confounder_buf(AES256KRB5_BLOCK_LEN);
+
+ if (!confounder) {
+ cct->random()->get_bytes(confounder_buf.c_str(), confounder_buf.length());
+ incopy.append(confounder_buf);
+ } else {
+ if (confounder->length() != AES256KRB5_BLOCK_LEN) {
+ ldout(cct, 0) << "ERROR: confounder length is expected to be equal to block size (" << AES256KRB5_BLOCK_LEN << ")" << dendl;
+ return -EINVAL;
+ }
+ incopy.append(*confounder);
+ }
// combine confounder with input data
- ceph::bufferlist incopy;
- incopy.append(confounder);
incopy.append(in);
// reinitialize IV each time. It might be unnecessary depending on
return 0;
}
+
+ int encrypt(CephContext *cct, const ceph::bufferlist& in,
+ ceph::bufferlist& out,
+ std::string* unused) const override {
+ return encrypt_ext(cct, in, nullptr, out, unused);
+ }
};
};
TEST(AES, ValidateSecret) {
- CryptoHandler *h = g_ceph_context->get_crypto_handler(CEPH_CRYPTO_AES);
+ auto h = g_ceph_context->get_crypto_manager()->get_handler(CEPH_CRYPTO_AES);
int l;
for (l=0; l<16; l++) {
}
TEST(AES, Encrypt) {
- CryptoHandler *h = g_ceph_context->get_crypto_handler(CEPH_CRYPTO_AES);
+ auto h = g_ceph_context->get_crypto_manager()->get_handler(CEPH_CRYPTO_AES);
char secret_s[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
}
TEST(AES, EncryptNoBl) {
- CryptoHandler *h = g_ceph_context->get_crypto_handler(CEPH_CRYPTO_AES);
+ auto h = g_ceph_context->get_crypto_manager()->get_handler(CEPH_CRYPTO_AES);
char secret_s[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
}
TEST(AES, Decrypt) {
- CryptoHandler *h = g_ceph_context->get_crypto_handler(CEPH_CRYPTO_AES);
+ auto h = g_ceph_context->get_crypto_manager()->get_handler(CEPH_CRYPTO_AES);
char secret_s[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
}
TEST(AES, DecryptNoBl) {
- CryptoHandler *h = g_ceph_context->get_crypto_handler(CEPH_CRYPTO_AES);
+ auto h = g_ceph_context->get_crypto_manager()->get_handler(CEPH_CRYPTO_AES);
const char secret_s[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
template <std::size_t TextSizeV>
static void aes_loop_cephx() {
- CryptoHandler *h = g_ceph_context->get_crypto_handler(CEPH_CRYPTO_AES);
+ auto h = g_ceph_context->get_crypto_manager()->get_handler(CEPH_CRYPTO_AES);
CryptoRandom random;
for (int i=0; i<10000; i++) {
bufferlist cipher;
{
- CryptoHandler *h = g_ceph_context->get_crypto_handler(CEPH_CRYPTO_AES);
+ auto h = g_ceph_context->get_crypto_manager()->get_handler(CEPH_CRYPTO_AES);
std::string error;
CryptoKeyHandler *kh = h->get_key_handler(secret, error);
plaintext.clear();
{
- CryptoHandler *h = g_ceph_context->get_crypto_handler(CEPH_CRYPTO_AES);
+ auto h = g_ceph_context->get_crypto_manager()->get_handler(CEPH_CRYPTO_AES);
std::string error;
CryptoKeyHandler *ckh = h->get_key_handler(secret, error);
int r = ckh->decrypt(g_ceph_context, cipher, plaintext, &error);
TEST(AES256KRB5, Encrypt) {
- CryptoHandler *h = g_ceph_context->get_crypto_handler(CEPH_CRYPTO_AES256KRB5);
+ auto h = g_ceph_context->get_crypto_manager()->get_handler(CEPH_CRYPTO_AES256KRB5);
unsigned char secret_s[] = {
0x6D, 0x40, 0x4D, 0x37, 0xFA, 0xF7, 0x9F, 0x9D, 0xF0, 0xD3, 0x35, 0x68, 0xD3, 0x20, 0x66, 0x98,
0x00, 0xEB, 0x48, 0x36, 0x47, 0x2E, 0xA8, 0xA0, 0x26, 0xD1, 0x6B, 0x71, 0x82, 0x46, 0x0C, 0x52 };
bufferlist plaintext;
plaintext.append((char *)plaintext_s, sizeof(plaintext_s));
+ unsigned char confounder_data[] = { 0xB8, 0x0D, 0x32, 0x51, 0xC1, 0xF6, 0x47, 0x14, 0x94, 0x25, 0x6F, 0xFE, 0x71, 0x2D, 0x0B, 0x9A };
+
+ bufferlist confounder;
+ confounder.append((const char *)confounder_data, sizeof(confounder_data));
+
bufferlist cipher;
std::string error;
CryptoKeyHandler *kh = h->get_key_handler(secret, error);
- int r = kh->encrypt(g_ceph_context, plaintext, cipher, &error);
+ int r = kh->encrypt_ext(g_ceph_context, plaintext, &confounder, cipher, &error);
ASSERT_EQ(r, 0);
ASSERT_EQ(error, "");
}
TEST(AES256KRB5, Decrypt) {
- CryptoHandler *h = g_ceph_context->get_crypto_handler(CEPH_CRYPTO_AES256KRB5);
+ auto h = g_ceph_context->get_crypto_manager()->get_handler(CEPH_CRYPTO_AES256KRB5);
unsigned char secret_s[] = {
0x6D, 0x40, 0x4D, 0x37, 0xFA, 0xF7, 0x9F, 0x9D, 0xF0, 0xD3, 0x35, 0x68, 0xD3, 0x20, 0x66, 0x98,
0x00, 0xEB, 0x48, 0x36, 0x47, 0x2E, 0xA8, 0xA0, 0x26, 0xD1, 0x6B, 0x71, 0x82, 0x46, 0x0C, 0x52 };