createTransportSecurityContext static method

SecurityContext createTransportSecurityContext(
  1. AsymmetricKeyPair<RSAPublicKey, RSAPrivateKey> keyPair
)

Creates a SecurityContext for the post-pairing ADB TLS (STLS) transport.

The certificate issuer/subject is shaped to match adbd's client-CA hinting (O=AdbKey-0, CN=<SHA256(pubkey)>) so dart:io can select the client certificate without AOSP's custom cert-selection callback.

Implementation

static SecurityContext createTransportSecurityContext(
  AsymmetricKeyPair<RSAPublicKey, RSAPrivateKey> keyPair,
) {
  final certPem = generateTransportCertificatePem(keyPair);
  final keyPem = encodePrivateKeyToPem(keyPair.privateKey);

  final context = SecurityContext(withTrustedRoots: false);
  context.useCertificateChainBytes(utf8.encode(certPem));
  context.usePrivateKeyBytes(utf8.encode(keyPem));
  return context;
}