MCPcopy Create free account
hub / github.com/amule-project/amule / SetConnectionEncryption

Method SetConnectionEncryption

src/EncryptedStreamSocket.cpp:142–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140/* External interface */
141
142void CEncryptedStreamSocket::SetConnectionEncryption(bool bEnabled, const uint8_t* pTargetClientHash, bool bServerConnection)
143{
144 if (m_StreamCryptState != ECS_UNKNOWN && m_StreamCryptState != ECS_NONE) {
145 if (bEnabled) {
146 wxFAIL;
147 }
148 return;
149 }
150
151 if (bEnabled && pTargetClientHash != NULL && !bServerConnection) {
152 m_StreamCryptState = ECS_PENDING;
153 // create obfuscation keys, see on top for key format
154
155 // use the crypt random generator
156 m_nRandomKeyPart = GetRandomUint32();
157
158 uint8 achKeyData[21];
159 md4cpy(achKeyData, pTargetClientHash);
160 PokeUInt32(achKeyData + 17, m_nRandomKeyPart);
161
162 achKeyData[16] = MAGICVALUE_REQUESTER;
163 MD5Sum md5(achKeyData, sizeof(achKeyData));
164 m_pfiSendBuffer.SetKey(md5);
165
166 achKeyData[16] = MAGICVALUE_SERVER;
167 md5.Calculate(achKeyData, sizeof(achKeyData));
168 m_pfiReceiveBuffer.SetKey(md5);
169
170 } else if (bServerConnection && bEnabled) {
171 //printf("->Server crypt\n");
172 m_bServerCrypt = true;
173 m_StreamCryptState = ECS_PENDING_SERVER;
174 } else {
175 wxASSERT( !bEnabled );
176 m_StreamCryptState = ECS_NONE;
177 }
178}
179
180/* Internals, common to base class */
181

Callers 1

ConnectMethod · 0.80

Calls 5

GetRandomUint32Function · 0.85
md4cpyFunction · 0.85
PokeUInt32Function · 0.85
SetKeyMethod · 0.80
CalculateMethod · 0.80

Tested by

no test coverage detected