/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set ts=4 et sw=4 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2 . 0 . If a copy of the MPL was not distributed with this file ,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "gtest/gtest.h"
#include "nss.h"
#include "nss_scoped_ptrs.h"
#include "pk11sdr.h"
#include "prerror.h"
namespace nss_test {
class PK11SDRTest : public ::testing::Test {
public:
void SetUp() override {
// Ensure there exists an AES key in the default key slot.
ScopedPK11SlotInfo slot(PK11_GetInternalKeySlot());
ASSERT_NE(slot.get(), nullptr);
SECItem keyid = {siBuffer, nullptr,
0 };
unsigned char plaintextBytes[] = {
'a' ,
'b' ,
'c' };
SECItem plaintext = {siBuffer, &plaintextBytes[
0 ],
sizeof (plaintextBytes)};
StackSECItem ciphertext;
SECStatus rv = PK11SDR_EncryptWithMechanism(
slot.get(), &keyid, CKM_AES_CBC, &plaintext, &ciphertext, nullptr);
ASSERT_EQ(rv, SECSuccess);
}
};
const std::vector<uint8_t> kUnsupportedAlgorithmDER = {
0 x30,
0 x5B,
0 x04,
0 x10,
0 xF8,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x01,
0 x30,
0 x35,
0 x06,
0 x09,
0 x60,
0 x86,
0 x48,
0 x01,
0 x65,
0 x03,
0 x04,
0 x01,
0 x06,
0 x04,
0 x28,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 x0C,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 x10,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x80,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x04,
0 x10,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF,
0 xFF};
TEST_F(PK11SDRTest, RejectUnsupportedAlgorithmDecrypt) {
SECItem data = {siBuffer,
const_cast <
unsigned char *>(kUnsupportedAlgorithmDER.data()),
(
unsigned int )kUnsupportedAlgorithmDER.size()};
SECItem result = {siBuffer, nullptr,
0 };
EXPECT_EQ(PK11SDR_Decrypt(&data, &result, nullptr), SECFailure);
EXPECT_EQ(PR_GetError(), SEC_ERROR_INVALID_ARGS);
}
TEST_F(PK11SDRTest, RejectUnsupportedAlgorithmEncrypt) {
ScopedPK11SlotInfo slot(PK11_GetInternalKeySlot());
ASSERT_NE(slot.get(), nullptr);
SECItem keyid = {siBuffer, nullptr,
0 };
unsigned char plaintextBytes[] = {
'a' ,
'b' ,
'c' };
SECItem plaintext = {siBuffer, &plaintextBytes[
0 ],
sizeof (plaintextBytes)};
StackSECItem ciphertext;
SECStatus rv = PK11SDR_EncryptWithMechanism(slot.get(), &keyid, CKM_AES_GCM,
&plaintext, &ciphertext, nullptr);
EXPECT_EQ(rv, SECFailure);
EXPECT_EQ(PR_GetError(), SEC_ERROR_INVALID_ARGS);
}
}
// namespace nss_test
Messung V0.5 in Prozent C=93 H=100 G=96
¤ Dauer der Verarbeitung: 0.3 Sekunden
¤
*© Formatika GbR, Deutschland