Esempio n. 1
0
        public static AdbConnection Create(String host, int port, AdbCrypto crypto)
        {
            TcpClient client = new TcpClient();

            client.Connect(host, port);
            return(Create(client, crypto));
        }
Esempio n. 2
0
        /**
         * Creates a new AdbCrypto object from a key pair loaded from files.
         * @param base64 Implementation of base 64 conversion interface required by ADB
         * @param privateKey File containing the RSA private key
         * @param publicKey File containing the RSA public key
         * @return New AdbCrypto object
         */
        public static AdbCrypto LoadAdbKeyPair(FileInfo privateKey, FileInfo publicKey)
        {
            AdbCrypto crypto = new AdbCrypto();

            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();

            rsa.FromXmlString(File.ReadAllText(privateKey.FullName));
            crypto.rsa = rsa;

            /*int privKeyLength = (int)privateKey.length();
             * int pubKeyLength = (int)publicKey.length();
             * byte[] privKeyBytes = new byte[privKeyLength];
             * byte[] pubKeyBytes = new byte[pubKeyLength];
             *
             * FileInputStream privIn = new FileInputStream(privateKey);
             * FileInputStream pubIn = new FileInputStream(publicKey);
             *
             * privIn.read(privKeyBytes);
             *  pubIn.read(pubKeyBytes);
             *
             *  privIn.close();
             *  pubIn.close();
             *
             *  KeyFactory keyFactory = KeyFactory.getInstance("RSA");
             * EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(privKeyBytes);
             * EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(pubKeyBytes);
             *
             * crypto.keyPair = new KeyPair(keyFactory.generatePublic(publicKeySpec),
             *    keyFactory.generatePrivate(privateKeySpec));
             *
             *  crypto.base64 = base64;*/

            return(crypto);
        }
Esempio n. 3
0
        /**
         * Internal constructor to initialize some internal state
         */
        private AdbConnection(TcpClient socket, AdbCrypto crypto)
        {
            openStreams = new Dictionary <uint, AdbSessionBase>();
            lastLocalId = 0;
            this.crypto = crypto;

            this.socket = socket;
            this.stream = new BinaryStream(socket.GetStream());
        }
Esempio n. 4
0
        /**
         * Creates a AdbConnection object associated with the socket and
         * crypto object specified.
         * @param socket The socket that the connection will use for communcation.
         * @param crypto The crypto object that stores the key pair for authentication.
         * @return A new AdbConnection object.
         */
        public static AdbConnection Create(TcpClient socket, AdbCrypto crypto)
        {
            /* Disable Nagle because we're sending tiny packets */
            socket.NoDelay = true;
            AdbConnection newConn = new AdbConnection(socket, crypto);


            return(newConn);
        }
Esempio n. 5
0
        /**
         * Creates a new AdbCrypto object by generating a new key pair.
         * @param base64 Implementation of base 64 conversion interface required by ADB
         * @return A new AdbCrypto object
         */
        public static AdbCrypto GenerateAdbKeyPair()
        {
            AdbCrypto crypto = new AdbCrypto
            {
                rsa = new RSACryptoServiceProvider(KEY_LENGTH_BITS)
            };

            return(crypto);
        }
Esempio n. 6
0
        public static AdbConnection Create(String host, int port)
        {
            FileInfo  privateKeyFile = new FileInfo("private.key");
            FileInfo  publicKeyFile  = new FileInfo("public.key");
            AdbCrypto adbCryto;

            if (privateKeyFile.Exists)
            {
                adbCryto = AdbCrypto.LoadAdbKeyPair(privateKeyFile, publicKeyFile);
            }
            else
            {
                adbCryto = AdbCrypto.GenerateAdbKeyPair();
                adbCryto.SaveAdbKeyPair(privateKeyFile, publicKeyFile);
            }
            return(Create(host, port, adbCryto));
        }