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

Commit dde4598f authored by Steven Moreland's avatar Steven Moreland
Browse files

libbinder: limit RpcTransport visibility

I always wanted to restrict the visibility of this
class, but it proved difficult in the original RPC
transport implementation. Now that we are considering
adding more transports, I'm adding an explicit list of
transports here. The reasoning is in the code.

Bug: N/A
Test: compile
Change-Id: Ib841e6c1c7cb6b59a6ca3aa15bbd94e66be3f6e8
parent 265e9e28
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -29,8 +29,6 @@

namespace android {

namespace {

// RpcTransport with TLS disabled.
class RpcTransportRaw : public RpcTransport {
public:
@@ -96,8 +94,6 @@ public:
    std::vector<uint8_t> getCertificate(RpcCertificateFormat) const override { return {}; }
};

} // namespace

std::unique_ptr<RpcTransportCtx> RpcTransportCtxFactoryRaw::newServerCtx() const {
    return std::make_unique<RpcTransportCtxRaw>();
}
+0 −4
Original line number Diff line number Diff line
@@ -31,8 +31,6 @@ using android::base::Result;

namespace android {

namespace {

// RpcTransport for writing Trusty IPC clients in Android.
class RpcTransportTipcAndroid : public RpcTransport {
public:
@@ -217,8 +215,6 @@ public:
    std::vector<uint8_t> getCertificate(RpcCertificateFormat) const override { return {}; }
};

} // namespace

std::unique_ptr<RpcTransportCtx> RpcTransportCtxFactoryTipcAndroid::newServerCtx() const {
    return std::make_unique<RpcTransportCtxTipcAndroid>();
}
+4 −3
Original line number Diff line number Diff line
@@ -275,6 +275,8 @@ private:
    bssl::UniquePtr<SSL> mSsl;
};

} // namespace

class RpcTransportTls : public RpcTransport {
public:
    RpcTransportTls(RpcTransportFd socket, Ssl ssl)
@@ -411,7 +413,8 @@ status_t RpcTransportTls::interruptableReadFully(
}

// For |ssl|, set internal FD to |fd|, and do handshake. Handshake is triggerable by |fdTrigger|.
bool setFdAndDoHandshake(Ssl* ssl, const android::RpcTransportFd& socket, FdTrigger* fdTrigger) {
static bool setFdAndDoHandshake(Ssl* ssl, const android::RpcTransportFd& socket,
                                FdTrigger* fdTrigger) {
    bssl::UniquePtr<BIO> bio = newSocketBio(socket.fd);
    TEST_AND_RETURN(false, bio != nullptr);
    auto [_, errorQueue] = ssl->call(SSL_set_bio, bio.get(), bio.get());
@@ -540,8 +543,6 @@ protected:
    }
};

} // namespace

std::unique_ptr<RpcTransportCtx> RpcTransportCtxFactoryTls::newServerCtx() const {
    return android::RpcTransportCtxTls::create<RpcTransportCtxTlsServer>(mCertVerifier,
                                                                         mAuth.get());
+33 −3
Original line number Diff line number Diff line
@@ -39,6 +39,16 @@ namespace android {
class FdTrigger;
struct RpcTransportFd;

// for 'friend'
class RpcTransportRaw;
class RpcTransportTls;
class RpcTransportTipcAndroid;
class RpcTransportTipcTrusty;
class RpcTransportCtxRaw;
class RpcTransportCtxTls;
class RpcTransportCtxTipcAndroid;
class RpcTransportCtxTipcTrusty;

// Represents a socket connection.
// No thread-safety is guaranteed for these APIs.
class RpcTransport {
@@ -92,7 +102,21 @@ public:
     */
    [[nodiscard]] virtual bool isWaiting() = 0;

protected:
private:
    // limit the classes which can implement RpcTransport. Being able to change this
    // interface is important to allow development of RPC binder. In the past, we
    // changed this interface to use iovec for efficiency, and we added FDs to the
    // interface. If another transport is needed, it should be added directly here.
    // non-socket FDs likely also need changes in RpcSession in order to get
    // connected, and similarly to how addrinfo was type-erased from RPC binder
    // interfaces when RpcTransportTipc* was added, other changes may be needed
    // to add more transports.

    friend class ::android::RpcTransportRaw;
    friend class ::android::RpcTransportTls;
    friend class ::android::RpcTransportTipcAndroid;
    friend class ::android::RpcTransportTipcTrusty;

    RpcTransport() = default;
};

@@ -117,7 +141,13 @@ public:
    [[nodiscard]] virtual std::vector<uint8_t> getCertificate(
            RpcCertificateFormat format) const = 0;

protected:
private:
    // see comment on RpcTransport
    friend class ::android::RpcTransportCtxRaw;
    friend class ::android::RpcTransportCtxTls;
    friend class ::android::RpcTransportCtxTipcAndroid;
    friend class ::android::RpcTransportCtxTipcTrusty;

    RpcTransportCtx() = default;
};

@@ -140,7 +170,7 @@ protected:
    RpcTransportCtxFactory() = default;
};

struct RpcTransportFd {
struct RpcTransportFd final {
private:
    mutable bool isPolling{false};

+0 −4
Original line number Diff line number Diff line
@@ -29,8 +29,6 @@

namespace android {

namespace {

// RpcTransport for Trusty.
class RpcTransportTipcTrusty : public RpcTransport {
public:
@@ -282,8 +280,6 @@ public:
    std::vector<uint8_t> getCertificate(RpcCertificateFormat) const override { return {}; }
};

} // namespace

std::unique_ptr<RpcTransportCtx> RpcTransportCtxFactoryTipcTrusty::newServerCtx() const {
    return std::make_unique<RpcTransportCtxTipcTrusty>();
}