C# Класс Universal.Torrent.Client.Encryption.EncryptedSocket

The class that handles.Message Stream Encryption for a connection
Наследование: IEncryptor.IEncryptor
Показать файл Открыть проект

Защищенные свойства (Protected)

Свойство Тип Описание
AsyncResult AsyncResult
CryptoProvide byte[]
CryptoSelect byte[]
InitialPayload byte[]
PadC byte[]
PadD byte[]
RemoteInitialPayload byte[]
S byte[]
Skey InfoHash
VerificationConstant byte[]

Открытые методы

Метод Описание
AddPayload ( byte buffer ) : void
AddPayload ( byte buffer, int offset, int count ) : void
BeginHandshake ( IConnection socket, AsyncCallback callback, object state ) : IAsyncResult

Begins the message stream encryption handshaking process

BeginHandshake ( IConnection socket, byte initialBuffer, int offset, int count, AsyncCallback callback, object state ) : IAsyncResult

Begins the message stream encryption handshaking process, beginning with some data already received from the socket.

Decrypt ( byte data, int offset, int length ) : void

Decrypts some data (should only be called after onEncryptorReady)

Encrypt ( byte data, int offset, int length ) : void

Encrypts some data (should only be called after onEncryptorReady)

EncryptedSocket ( EncryptionTypes allowedEncryption ) : System
EndHandshake ( IAsyncResult result ) : void

Защищенные методы

Метод Описание
Combine ( ) : byte[]

Concatenates several byte buffers

CreateCryptors ( string encryptionSalt, string decryptionSalt ) : void

Instantiate the cryptors with the keys: Hash(encryptionSalt, S, SKEY) for the encryptor and Hash(encryptionSalt, S, SKEY) for the decryptor. (encryptionSalt should be "keyA" if you're A, "keyB" if you're B, and reverse for decryptionSalt)

DeLen ( byte data ) : int

Converts a 2-byte big endian integer into an int (reverses operation of Len())

DoDecrypt ( byte data ) : byte[]

Decrypts some data with the RC4 encryptor used in handshaking

DoDecrypt ( byte data, int offset, int length ) : void

Decrypts some data with the RC4 decryptor used in handshaking

DoEncrypt ( byte data ) : byte[]
DoEncrypt ( byte data, int offset, int length ) : void

Encrypts some data with the RC4 encryptor used in handshaking

DoneReceiveY ( ) : void
DoneSynchronize ( ) : void
FillSynchronizeBytes ( bool succeeded, int count, object state ) : void
GeneratePad ( ) : byte[]

Returns a 0 to 512 byte 0-filled pad.

Hash ( ) : byte[]

Hash some data with SHA1

Len ( byte data ) : byte[]

Returns a 2-byte buffer with the length of data

Ready ( ) : void

Signal that the cryptor is now in a state ready to encrypt and decrypt payload data

ReceiveMessage ( byte buffer, int length, AsyncCallback callback ) : void
ReceiveY ( ) : void

Receive the first 768 bits of the transmission from the remote client, which is Y in the protocol (Either "1 A->B: Diffie Hellman Ya, PadA" or "2 B->A: Diffie Hellman Yb, PadB")

SelectCrypto ( byte remoteCryptoBytes, bool replace ) : int

Sets CryptoSelect and initializes the stream encryptor and decryptor based on the selected method.

SendMessage ( byte toSend ) : void
SendY ( ) : void

Send Y to the remote client, with a random padding that is 0 to 512 bytes long (Either "1 A->B: Diffie Hellman Ya, PadA" or "2 B->A: Diffie Hellman Yb, PadB")

SetMinCryptoAllowed ( EncryptionTypes allowedEncryption ) : void
Synchronize ( byte syncData, int syncStopPoint ) : void

Read data from the socket until the byte string in syncData is read, or until syncStopPoint is reached (in that case, there is an EncryptionError). (Either "3 A->B: HASH('req1', S)" or "4 B->A: ENCRYPT(VC)")

Приватные методы

Метод Описание
DoneReceive ( bool succeeded, int count, object state ) : void
DoneSend ( bool succeeded, int count, object state ) : void
GenerateX ( ) : void

Generate a 160 bit random number for X

GenerateY ( ) : void

Calculate 2^X mod P

RandomNumber ( int max ) : int

Описание методов

AddPayload() публичный Метод

public AddPayload ( byte buffer ) : void
buffer byte
Результат void

AddPayload() публичный Метод

public AddPayload ( byte buffer, int offset, int count ) : void
buffer byte
offset int
count int
Результат void

BeginHandshake() публичный Метод

Begins the message stream encryption handshaking process
public BeginHandshake ( IConnection socket, AsyncCallback callback, object state ) : IAsyncResult
socket IConnection The socket to perform handshaking with
callback AsyncCallback The callback.
state object The state.
Результат IAsyncResult

BeginHandshake() публичный Метод

Begins the message stream encryption handshaking process, beginning with some data already received from the socket.
public BeginHandshake ( IConnection socket, byte initialBuffer, int offset, int count, AsyncCallback callback, object state ) : IAsyncResult
socket IConnection The socket to perform handshaking with
initialBuffer byte Buffer containing soome data already received from the socket
offset int Offset to begin reading in initialBuffer
count int Number of bytes to read from initialBuffer
callback AsyncCallback The callback.
state object The state.
Результат IAsyncResult

Combine() защищенный Метод

Concatenates several byte buffers
protected Combine ( ) : byte[]
Результат byte[]

CreateCryptors() защищенный Метод

Instantiate the cryptors with the keys: Hash(encryptionSalt, S, SKEY) for the encryptor and Hash(encryptionSalt, S, SKEY) for the decryptor. (encryptionSalt should be "keyA" if you're A, "keyB" if you're B, and reverse for decryptionSalt)
protected CreateCryptors ( string encryptionSalt, string decryptionSalt ) : void
encryptionSalt string The salt to calculate the encryption key with
decryptionSalt string The salt to calculate the decryption key with
Результат void

DeLen() защищенный Метод

Converts a 2-byte big endian integer into an int (reverses operation of Len())
protected DeLen ( byte data ) : int
data byte 2 byte buffer
Результат int

Decrypt() публичный Метод

Decrypts some data (should only be called after onEncryptorReady)
public Decrypt ( byte data, int offset, int length ) : void
data byte The data.
offset int Offset to begin decryption
length int The length.
Результат void

DoDecrypt() защищенный Метод

Decrypts some data with the RC4 encryptor used in handshaking
protected DoDecrypt ( byte data ) : byte[]
data byte Buffers with the data to decrypt
Результат byte[]

DoDecrypt() защищенный Метод

Decrypts some data with the RC4 decryptor used in handshaking
protected DoDecrypt ( byte data, int offset, int length ) : void
data byte The data.
offset int Offset to begin decryption
length int The length.
Результат void

DoEncrypt() защищенный Метод

protected DoEncrypt ( byte data ) : byte[]
data byte
Результат byte[]

DoEncrypt() защищенный Метод

Encrypts some data with the RC4 encryptor used in handshaking
protected DoEncrypt ( byte data, int offset, int length ) : void
data byte The data.
offset int Offset to begin encryption
length int The length.
Результат void

DoneReceiveY() защищенный Метод

protected DoneReceiveY ( ) : void
Результат void

DoneSynchronize() защищенный Метод

protected DoneSynchronize ( ) : void
Результат void

Encrypt() публичный Метод

Encrypts some data (should only be called after onEncryptorReady)
public Encrypt ( byte data, int offset, int length ) : void
data byte The data.
offset int Offset to begin encryption
length int The length.
Результат void

EncryptedSocket() публичный Метод

public EncryptedSocket ( EncryptionTypes allowedEncryption ) : System
allowedEncryption EncryptionTypes
Результат System

EndHandshake() публичный Метод

public EndHandshake ( IAsyncResult result ) : void
result IAsyncResult
Результат void

FillSynchronizeBytes() защищенный Метод

protected FillSynchronizeBytes ( bool succeeded, int count, object state ) : void
succeeded bool
count int
state object
Результат void

GeneratePad() защищенный Метод

Returns a 0 to 512 byte 0-filled pad.
protected GeneratePad ( ) : byte[]
Результат byte[]

Hash() защищенный Метод

Hash some data with SHA1
protected Hash ( ) : byte[]
Результат byte[]

Len() защищенный Метод

Returns a 2-byte buffer with the length of data
protected Len ( byte data ) : byte[]
data byte
Результат byte[]

Ready() защищенный Метод

Signal that the cryptor is now in a state ready to encrypt and decrypt payload data
protected Ready ( ) : void
Результат void

ReceiveMessage() защищенный Метод

protected ReceiveMessage ( byte buffer, int length, AsyncCallback callback ) : void
buffer byte
length int
callback AsyncCallback
Результат void

ReceiveY() защищенный Метод

Receive the first 768 bits of the transmission from the remote client, which is Y in the protocol (Either "1 A->B: Diffie Hellman Ya, PadA" or "2 B->A: Diffie Hellman Yb, PadB")
protected ReceiveY ( ) : void
Результат void

SelectCrypto() защищенный Метод

Sets CryptoSelect and initializes the stream encryptor and decryptor based on the selected method.
protected SelectCrypto ( byte remoteCryptoBytes, bool replace ) : int
remoteCryptoBytes byte /// The cryptographic methods supported/wanted by the remote client in CryptoProvide /// format. The highest order one available will be selected ///
replace bool if set to true [replace].
Результат int

SendMessage() защищенный Метод

protected SendMessage ( byte toSend ) : void
toSend byte
Результат void

SendY() защищенный Метод

Send Y to the remote client, with a random padding that is 0 to 512 bytes long (Either "1 A->B: Diffie Hellman Ya, PadA" or "2 B->A: Diffie Hellman Yb, PadB")
protected SendY ( ) : void
Результат void

SetMinCryptoAllowed() защищенный Метод

protected SetMinCryptoAllowed ( EncryptionTypes allowedEncryption ) : void
allowedEncryption EncryptionTypes
Результат void

Synchronize() защищенный Метод

Read data from the socket until the byte string in syncData is read, or until syncStopPoint is reached (in that case, there is an EncryptionError). (Either "3 A->B: HASH('req1', S)" or "4 B->A: ENCRYPT(VC)")
protected Synchronize ( byte syncData, int syncStopPoint ) : void
syncData byte Buffer with the data to synchronize to
syncStopPoint int /// Maximum number of bytes (measured from the total received from the socket since connection) /// to read before giving up ///
Результат void

Описание свойств

AsyncResult защищенное свойство

protected AsyncResult AsyncResult
Результат AsyncResult

CryptoProvide защищенное свойство

protected byte[] CryptoProvide
Результат byte[]

CryptoSelect защищенное свойство

protected byte[] CryptoSelect
Результат byte[]

InitialPayload защищенное свойство

protected byte[] InitialPayload
Результат byte[]

PadC защищенное свойство

protected byte[] PadC
Результат byte[]

PadD защищенное свойство

protected byte[] PadD
Результат byte[]

RemoteInitialPayload защищенное свойство

protected byte[] RemoteInitialPayload
Результат byte[]

S защищенное свойство

protected byte[] S
Результат byte[]

Skey защищенное свойство

protected InfoHash Skey
Результат InfoHash

VerificationConstant защищенное свойство

protected byte[] VerificationConstant
Результат byte[]