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

Commit fdd9f691 authored by Yifan Hong's avatar Yifan Hong
Browse files

binder: Delete addTrustedPeerCertificate.

For RpcServer and RpcSession, caller should retain
an ownership of the verifier when creating
RpcTransportCtxFactory, so APIs to addTrustedPeerCertificate
are deleted.

The logic to add certificates should be in the implementation
of RpcCertificateVerifier. See follow-up CLs.

Test: binderRpcTest
Bug: 198833574

Change-Id: If0ed87adfeee2ee48582604881ee335b5d689589
parent 13c90062
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
+0 −6
Original line number Diff line number Diff line
@@ -450,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;
@@ -462,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>
+0 −6
Original line number Diff line number Diff line
@@ -138,12 +138,6 @@ public:
     */
    std::string getCertificate(CertificateFormat);

    /**
     * See RpcTransportCtx::addTrustedPeerCertificate.
     * Thread-safe. This is only possible before the server is join()-ing.
     */
    status_t addTrustedPeerCertificate(CertificateFormat, std::string_view cert);

    /**
     * Runs join() in a background thread. Immediately returns.
     */
Loading