зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1073867, Part 4: Test that DSS end-entity certificates are rejected, r=mmc
--HG-- extra : rebase_source : 7cfdcdf08f2ae8909062b8803de6702ab47ec65a
This commit is contained in:
Родитель
dcacbfd4ce
Коммит
aeda384b1a
|
@ -680,3 +680,4 @@ VFY_VerifyData
|
|||
VFY_VerifyDataDirect
|
||||
VFY_VerifyDataWithAlgorithmID
|
||||
_SGN_VerifyPKCS1DigestInfo
|
||||
PK11_PQG_ParamGenV2
|
||||
|
|
|
@ -361,3 +361,88 @@ TEST_F(pkixbuild, NoRevocationCheckingForExpiredCert)
|
|||
CertPolicyId::anyPolicy,
|
||||
nullptr));
|
||||
}
|
||||
|
||||
class DSSTrustDomain : public TrustDomain
|
||||
{
|
||||
public:
|
||||
virtual Result GetCertTrust(EndEntityOrCA, const CertPolicyId&,
|
||||
Input, /*out*/ TrustLevel& trustLevel)
|
||||
{
|
||||
trustLevel = TrustLevel::TrustAnchor;
|
||||
return Success;
|
||||
}
|
||||
|
||||
virtual Result FindIssuer(Input, IssuerChecker&, Time)
|
||||
{
|
||||
ADD_FAILURE();
|
||||
return Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
}
|
||||
|
||||
virtual Result CheckRevocation(EndEntityOrCA, const CertID&, Time,
|
||||
/*optional*/ const Input*,
|
||||
/*optional*/ const Input*)
|
||||
{
|
||||
ADD_FAILURE();
|
||||
return Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
}
|
||||
|
||||
virtual Result IsChainValid(const DERArray&, Time)
|
||||
{
|
||||
return Success;
|
||||
}
|
||||
|
||||
virtual Result VerifySignedData(const SignedDataWithSignature& signedData,
|
||||
Input subjectPublicKeyInfo)
|
||||
{
|
||||
ADD_FAILURE();
|
||||
return Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
}
|
||||
|
||||
virtual Result DigestBuf(Input, /*out*/uint8_t*, size_t)
|
||||
{
|
||||
ADD_FAILURE();
|
||||
return Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
}
|
||||
|
||||
virtual Result CheckPublicKey(Input subjectPublicKeyInfo)
|
||||
{
|
||||
return TestCheckPublicKey(subjectPublicKeyInfo);
|
||||
}
|
||||
};
|
||||
|
||||
class pkixbuild_DSS : public ::testing::Test { };
|
||||
|
||||
TEST_F(pkixbuild_DSS, DSSEndEntityKeyNotAccepted)
|
||||
{
|
||||
DSSTrustDomain trustDomain;
|
||||
|
||||
ByteString serialNumber(CreateEncodedSerialNumber(1));
|
||||
ASSERT_FALSE(ENCODING_FAILED(serialNumber));
|
||||
|
||||
ByteString subjectDER(CNToDERName("DSS"));
|
||||
ASSERT_FALSE(ENCODING_FAILED(subjectDER));
|
||||
ScopedTestKeyPair subjectKey(GenerateDSSKeyPair());
|
||||
ASSERT_TRUE(subjectKey);
|
||||
|
||||
ByteString issuerDER(CNToDERName("RSA"));
|
||||
ASSERT_FALSE(ENCODING_FAILED(issuerDER));
|
||||
ScopedTestKeyPair issuerKey(CloneReusedKeyPair());
|
||||
ASSERT_TRUE(issuerKey);
|
||||
|
||||
ByteString cert(CreateEncodedCertificate(v3, sha256WithRSAEncryption,
|
||||
serialNumber, issuerDER,
|
||||
oneDayBeforeNow, oneDayAfterNow,
|
||||
subjectDER, *subjectKey, nullptr,
|
||||
*issuerKey, sha256WithRSAEncryption));
|
||||
ASSERT_FALSE(ENCODING_FAILED(cert));
|
||||
Input certDER;
|
||||
ASSERT_EQ(Success, certDER.Init(cert.data(), cert.length()));
|
||||
|
||||
ASSERT_EQ(Result::ERROR_UNSUPPORTED_KEYALG,
|
||||
BuildCertChain(trustDomain, certDER, Now(),
|
||||
EndEntityOrCA::MustBeEndEntity,
|
||||
KeyUsage::noParticularKeyUsageRequired,
|
||||
KeyPurposeId::id_kp_serverAuth,
|
||||
CertPolicyId::anyPolicy,
|
||||
nullptr/*stapledOCSPResponse*/));
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "cryptohi.h"
|
||||
#include "keyhi.h"
|
||||
#include "nss.h"
|
||||
#include "pk11pqg.h"
|
||||
#include "pk11pub.h"
|
||||
#include "pkix/pkixnss.h"
|
||||
#include "pkixder.h"
|
||||
|
@ -241,6 +242,53 @@ CloneReusedKeyPair()
|
|||
return reusedKeyPair->Clone();
|
||||
}
|
||||
|
||||
TestKeyPair*
|
||||
GenerateDSSKeyPair()
|
||||
{
|
||||
InitNSSIfNeeded();
|
||||
|
||||
ScopedPtr<PK11SlotInfo, PK11_FreeSlot> slot(PK11_GetInternalSlot());
|
||||
if (!slot) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PQGParams* pqgParamsTemp = nullptr;
|
||||
PQGVerify* pqgVerify = nullptr;
|
||||
if (PK11_PQG_ParamGenV2(2048u, 256u, 256u / 8u, &pqgParamsTemp, &pqgVerify)
|
||||
!= SECSuccess) {
|
||||
return nullptr;
|
||||
}
|
||||
PK11_PQG_DestroyVerify(pqgVerify);
|
||||
ScopedPtr<PQGParams, PK11_PQG_DestroyParams> params(pqgParamsTemp);
|
||||
|
||||
SECKEYPublicKey* publicKeyTemp = nullptr;
|
||||
ScopedSECKEYPrivateKey
|
||||
privateKey(PK11_GenerateKeyPair(slot.get(), CKM_DSA_KEY_PAIR_GEN,
|
||||
params.get(), &publicKeyTemp, false, true,
|
||||
nullptr));
|
||||
if (!privateKey) {
|
||||
return nullptr;
|
||||
}
|
||||
ScopedSECKEYPublicKey publicKey(publicKeyTemp);
|
||||
|
||||
ScopedSECItem spkiDER(SECKEY_EncodeDERSubjectPublicKeyInfo(publicKey.get()));
|
||||
if (!spkiDER) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ScopedPtr<CERTSubjectPublicKeyInfo, SECKEY_DestroySubjectPublicKeyInfo>
|
||||
spki(SECKEY_CreateSubjectPublicKeyInfo(publicKey.get()));
|
||||
if (!spki) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SECItem spkDER = spki->subjectPublicKey;
|
||||
DER_ConvertBitString(&spkDER); // bits to bytes
|
||||
return CreateTestKeyPair(ByteString(spkiDER->data, spkiDER->len),
|
||||
ByteString(spkDER.data, spkDER.len),
|
||||
privateKey.release());
|
||||
}
|
||||
|
||||
ByteString
|
||||
SHA1(const ByteString& toHash)
|
||||
{
|
||||
|
|
|
@ -253,6 +253,7 @@ protected:
|
|||
|
||||
TestKeyPair* CloneReusedKeyPair();
|
||||
TestKeyPair* GenerateKeyPair();
|
||||
TestKeyPair* GenerateDSSKeyPair();
|
||||
inline void DeleteTestKeyPair(TestKeyPair* keyPair) { delete keyPair; }
|
||||
typedef ScopedPtr<TestKeyPair, DeleteTestKeyPair> ScopedTestKeyPair;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче