Пример #1
0
        void testGetDNSNames() {
            Certificate::ref testling = Certificate::ref(certificateFactory->createCertificateFromDER(certificateData));

            CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(testling->getDNSNames().size()));
            CPPUNIT_ASSERT_EQUAL(std::string("*.jabber.org"), testling->getDNSNames()[0]);
            CPPUNIT_ASSERT_EQUAL(std::string("jabber.org"), testling->getDNSNames()[1]);
        }
Пример #2
0
bool CertificateFileStorage::hasCertificate(Certificate::ref certificate) const {
	boost::filesystem::path certificatePath = getCertificatePath(certificate);
	if (boost::filesystem::exists(certificatePath)) {
		ByteArray data;
		readByteArrayFromFile(data, certificatePath.string());
		Certificate::ref storedCertificate = certificateFactory->createCertificateFromDER(data);
		if (storedCertificate && storedCertificate->toDER() == certificate->toDER()) {
			return true;
		}
		else {
			SWIFT_LOG(warning) << "Stored certificate does not match received certificate" << std::endl;
			return false;
		}
	}
	else {
		return false;
	}
}
Пример #3
0
void CertificateFileStorage::addCertificate(Certificate::ref certificate) {
	boost::filesystem::path certificatePath = getCertificatePath(certificate);
	if (!boost::filesystem::exists(certificatePath.parent_path())) {
		try {
			boost::filesystem::create_directories(certificatePath.parent_path());
		}
		catch (const boost::filesystem::filesystem_error& e) {
			std::cerr << "ERROR: " << e.what() << std::endl;
		}
	}
	boost::filesystem::ofstream file(certificatePath, boost::filesystem::ofstream::binary|boost::filesystem::ofstream::out);
	ByteArray data = certificate->toDER();
	file.write(reinterpret_cast<const char*>(vecptr(data)), boost::numeric_cast<std::streamsize>(data.size()));
	file.close();
}
Пример #4
0
boost::filesystem::path CertificateFileStorage::getCertificatePath(Certificate::ref certificate) const {
	return path / Hexify::hexify(crypto->getSHA1Hash(certificate->toDER()));
}
Пример #5
0
        void testToDER() {
            Certificate::ref testling = Certificate::ref(certificateFactory->createCertificateFromDER(certificateData));

            CPPUNIT_ASSERT_EQUAL(certificateData, testling->toDER());
        }
Пример #6
0
        void testConstructFromDER() {
            Certificate::ref testling = Certificate::ref(certificateFactory->createCertificateFromDER(certificateData));

            CPPUNIT_ASSERT_EQUAL(std::string("*.jabber.org"), testling->getCommonNames()[0]);
        }