Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 07cc86ac authored by Yifan Hong's avatar Yifan Hong Committed by Automerger Merge Worker
Browse files

Merge changes If0ed87ad,I6e63bc84,I0847ffe4,I1429c66f am: b0afedb6

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1823369

Change-Id: I3dc5cc8d207d69458b9078c781a1263a71b70cb3
parents 63174f78 b0afedb6
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -144,15 +144,6 @@ std::string RpcServer::getCertificate(CertificateFormat format) {
    return mCtx->getCertificate(format);
}

status_t RpcServer::addTrustedPeerCertificate(CertificateFormat format, std::string_view cert) {
    std::lock_guard<std::mutex> _l(mLock);
    // Ensure that join thread is not running or shutdown trigger is not set up. In either case,
    // it means there are child threads running. It is invalid to add trusted peer certificates
    // after join thread and/or child threads are running to avoid race condition.
    if (mJoinThreadRunning || mShutdownTrigger != nullptr) return INVALID_OPERATION;
    return mCtx->addTrustedPeerCertificate(format, cert);
}

static void joinRpcServer(sp<RpcServer>&& thiz) {
    thiz->join();
}
+2 −13
Original line number Diff line number Diff line
@@ -64,23 +64,12 @@ RpcSession::~RpcSession() {

sp<RpcSession> RpcSession::make() {
    // Default is without TLS.
    return make(RpcTransportCtxFactoryRaw::make(), std::nullopt, std::nullopt);
    return make(RpcTransportCtxFactoryRaw::make());
}

sp<RpcSession> RpcSession::make(std::unique_ptr<RpcTransportCtxFactory> rpcTransportCtxFactory,
                                std::optional<CertificateFormat> serverCertificateFormat,
                                std::optional<std::string> serverCertificate) {
sp<RpcSession> RpcSession::make(std::unique_ptr<RpcTransportCtxFactory> rpcTransportCtxFactory) {
    auto ctx = rpcTransportCtxFactory->newClientCtx();
    if (ctx == nullptr) return nullptr;
    LOG_ALWAYS_FATAL_IF(serverCertificateFormat.has_value() != serverCertificate.has_value());
    if (serverCertificateFormat.has_value() && serverCertificate.has_value()) {
        status_t status =
                ctx->addTrustedPeerCertificate(*serverCertificateFormat, *serverCertificate);
        if (status != OK) {
            ALOGE("Cannot add trusted server certificate: %s", statusToString(status).c_str());
            return nullptr;
        }
    }
    return sp<RpcSession>::make(std::move(ctx));
}

+0 −1
Original line number Diff line number Diff line
@@ -112,7 +112,6 @@ public:
        return std::make_unique<RpcTransportRaw>(std::move(fd));
    }
    std::string getCertificate(CertificateFormat) const override { return {}; }
    status_t addTrustedPeerCertificate(CertificateFormat, std::string_view) override { return OK; }
};

} // namespace
+9 −16
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@

#include "FdTrigger.h"
#include "RpcState.h"
#include "Utils.h"

#define SHOULD_LOG_TLS_DETAIL false

@@ -35,14 +36,6 @@
#define LOG_TLS_DETAIL(...) ALOGV(__VA_ARGS__) // for type checking
#endif

#define TEST_AND_RETURN(value, expr)            \
    do {                                        \
        if (!(expr)) {                          \
            ALOGE("Failed to call: %s", #expr); \
            return value;                       \
        }                                       \
    } while (0)

using android::base::ErrnoError;
using android::base::Error;
using android::base::Result;
@@ -457,7 +450,6 @@ public:
    std::unique_ptr<RpcTransport> newTransport(android::base::unique_fd fd,
                                               FdTrigger* fdTrigger) const override;
    std::string getCertificate(CertificateFormat) const override;
    status_t addTrustedPeerCertificate(CertificateFormat, std::string_view cert) override;

protected:
    virtual void preHandshake(Ssl* ssl) const = 0;
@@ -469,11 +461,6 @@ std::string RpcTransportCtxTls::getCertificate(CertificateFormat) const {
    return {};
}

status_t RpcTransportCtxTls::addTrustedPeerCertificate(CertificateFormat, std::string_view) {
    // TODO(b/195166979): set certificate here
    return OK;
}

// Common implementation for creating server and client contexts. The child class, |Impl|, is
// provided as a template argument so that this function can initialize an |Impl| object.
template <typename Impl, typename>
@@ -544,8 +531,14 @@ const char* RpcTransportCtxFactoryTls::toCString() const {
    return "tls";
}

std::unique_ptr<RpcTransportCtxFactory> RpcTransportCtxFactoryTls::make() {
    return std::unique_ptr<RpcTransportCtxFactoryTls>(new RpcTransportCtxFactoryTls());
std::unique_ptr<RpcTransportCtxFactory> RpcTransportCtxFactoryTls::make(
        std::shared_ptr<RpcCertificateVerifier> verifier) {
    if (verifier == nullptr) {
        ALOGE("%s: Must provide a certificate verifier", __PRETTY_FUNCTION__);
        return nullptr;
    }
    return std::unique_ptr<RpcTransportCtxFactoryTls>(
            new RpcTransportCtxFactoryTls(std::move(verifier)));
}

} // namespace android
+9 −0
Original line number Diff line number Diff line
@@ -19,6 +19,15 @@

#include <android-base/result.h>
#include <android-base/unique_fd.h>
#include <log/log.h>

#define TEST_AND_RETURN(value, expr)            \
    do {                                        \
        if (!(expr)) {                          \
            ALOGE("Failed to call: %s", #expr); \
            return value;                       \
        }                                       \
    } while (0)

namespace android {

Loading