C# 클래스 Universal.Torrent.Client.Encryption.EncryptedSocket

The class that handles.Message Stream Encryption for a connection
상속: IEncryptor.IEncryptor
파일 보기 프로젝트 열기: haroldma/Universal.Torrent

보호된 프로퍼티들

프로퍼티 타입 설명
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[]