#include "cast/sender/channel/cast_auth_util.h"
#include <openssl/rand.h>
#include <algorithm>
#include <memory>
#include "cast/common/certificate/cast_cert_validator.h"
#include "cast/common/certificate/cast_crl.h"
#include "cast/common/certificate/date_time.h"
#include "cast/common/channel/proto/cast_channel.pb.h"
#include "cast/common/public/parsed_certificate.h"
#include "cast/common/public/trust_store.h"
#include "platform/api/time.h"
#include "platform/base/error.h"
#include "util/osp_logging.h"
#include "util/span_util.h"
#include "util/string_util.h"
namespace openscreen::cast {
AuthResponse;
CastMessage;
DeviceAuthMessage;
HashAlgorithm;
namespace {
#define PARSE_ERROR_PREFIX …
constexpr int kMaxSelfSignedCertLifetimeInDays = …;
constexpr int kNonceSizeInBytes = …;
constexpr int kNonceExpirationTimeInHours = …;
Error ParseAuthMessage(const CastMessage& challenge_reply,
DeviceAuthMessage* auth_message) { … }
class CastNonce { … };
Error MapToOpenscreenError(const Error& verify_error, bool crl_required) { … }
Error VerifyAndMapDigestAlgorithm(HashAlgorithm response_digest_algorithm,
DigestAlgorithm* digest_algorithm,
bool enforce_sha256_checking) { … }
}
AuthContext AuthContext::Create() { … }
AuthContext AuthContext::CreateForTest(const std::string& nonce_data) { … }
AuthContext::AuthContext(const std::string& nonce) : … { … }
AuthContext::~AuthContext() { … }
Error AuthContext::VerifySenderNonce(const std::string& nonce_response,
bool enforce_nonce_checking) const { … }
Error VerifyTLSCertificateValidity(const ParsedCertificate& peer_cert,
std::chrono::seconds verification_time) { … }
ErrorOr<CastDeviceCertPolicy> VerifyCredentialsImpl(
const AuthResponse& response,
const std::vector<uint8_t>& signature_input,
const CRLPolicy& crl_policy,
TrustStore* cast_trust_store,
TrustStore* crl_trust_store,
const DateTime& verification_time,
bool enforce_sha256_checking);
ErrorOr<CastDeviceCertPolicy> AuthenticateChallengeReplyImpl(
const CastMessage& challenge_reply,
const ParsedCertificate& peer_cert,
const AuthContext& auth_context,
const CRLPolicy& crl_policy,
TrustStore* cast_trust_store,
TrustStore* crl_trust_store,
const DateTime& verification_time) { … }
ErrorOr<CastDeviceCertPolicy> AuthenticateChallengeReply(
const CastMessage& challenge_reply,
const ParsedCertificate& peer_cert,
const AuthContext& auth_context,
TrustStore* cast_trust_store,
TrustStore* crl_trust_store) { … }
ErrorOr<CastDeviceCertPolicy> AuthenticateChallengeReplyForTest(
const CastMessage& challenge_reply,
const ParsedCertificate& peer_cert,
const AuthContext& auth_context,
CRLPolicy crl_policy,
TrustStore* cast_trust_store,
TrustStore* crl_trust_store,
const DateTime& verification_time) { … }
ErrorOr<CastDeviceCertPolicy> VerifyCredentialsImpl(
const AuthResponse& response,
const std::vector<uint8_t>& signature_input,
const CRLPolicy& crl_policy,
TrustStore* cast_trust_store,
TrustStore* crl_trust_store,
const DateTime& verification_time,
bool enforce_sha256_checking) { … }
ErrorOr<CastDeviceCertPolicy> VerifyCredentials(
const AuthResponse& response,
const std::vector<uint8_t>& signature_input,
TrustStore* cast_trust_store,
TrustStore* crl_trust_store,
bool enforce_revocation_checking,
bool enforce_sha256_checking) { … }
ErrorOr<CastDeviceCertPolicy> VerifyCredentialsForTest(
const AuthResponse& response,
const std::vector<uint8_t>& signature_input,
CRLPolicy crl_policy,
TrustStore* cast_trust_store,
TrustStore* crl_trust_store,
const DateTime& verification_time,
bool enforce_sha256_checking) { … }
}