public byte[] CalculateHa2(ByteArrayPart qop, ByteArrayPart digestUri, ByteArrayPart method, ArraySegment <byte> body) { byte[] bodyHash = null; // if (messageQop.IsValid == true && messageQop.IsEqualValue(AuthInt)) if (qop.Equals(AuthInt)) { if (body.Array != null && body.Count > 0) { bodyHash = md5.ComputeHash(body.Array, body.Offset, body.Count); } } md5.Initialize(); md5.TransformBlock(method); md5.TransformBlock(Colon); if (bodyHash != null) { md5.TransformBlock(digestUri); md5.TransformBlock(Colon); HexEncoding.GetLowerHexChars(bodyHash, bytes32); md5.TransformFinalBlock(bytes32); } else { md5.TransformFinalBlock(digestUri); } return(md5.Hash); }
public byte[] CalculateResponse(ByteArrayPart nonce, ByteArrayPart qop, ByteArrayPart nonceCountBytes, ByteArrayPart cnonce, byte[] ha1, byte[] ha2) { md5.Initialize(); HexEncoding.GetLowerHexChars(ha1, bytes32); md5.TransformBlock(bytes32); md5.TransformBlock(Colon); md5.TransformBlock(nonce); md5.TransformBlock(Colon); if (qop.IsValid) { md5.TransformBlock(nonceCountBytes); md5.TransformBlock(Colon); md5.TransformBlock(cnonce); md5.TransformBlock(Colon); md5.TransformBlock(qop); md5.TransformBlock(Colon); } HexEncoding.GetLowerHexChars(ha2, bytes32); md5.TransformFinalBlock(bytes32); return(md5.Hash); }
//public bool IsResponseValid(ByteArrayPart username, ByteArrayPart realm, // bool isMd5SessAlgorithm, ByteArrayPart nonce, ByteArrayPart cnonce, // ByteArrayPart qop, ByteArrayPart digestUri, ByteArrayPart nonceCountBytes, // ByteArrayPart method, ArraySegment<byte> body, ByteArrayPart password) //{ // byte[] ha1 = CalculateHa1(username, realm, isMd5SessAlgorithm, nonce, cnonce, password); // byte[] ha2 = CalculateHa2(qop, digestUri, method, body); // byte[] response = CalculateResponse(nonce, qop, nonceCountBytes, cnonce, ha1, ha2); // HexEncoding.GetLowerHexChars(response, bytes32); // ?? что если ответ будет в upper case // return cred.Response.Equals(bytes32); //} public byte[] GetResponseHexChars(ByteArrayPart username, ByteArrayPart realm, bool isMd5SessAlgorithm, ByteArrayPart nonce, ByteArrayPart cnonce, ByteArrayPart qop, ByteArrayPart digestUri, ByteArrayPart nonceCountBytes, ByteArrayPart method, ArraySegment <byte> body, ByteArrayPart password) { byte[] ha1 = CalculateHa1(username, realm, isMd5SessAlgorithm, nonce, cnonce, password); byte[] ha2 = CalculateHa2(qop, digestUri, method, body); byte[] response = CalculateResponse(nonce, qop, nonceCountBytes, cnonce, ha1, ha2); HexEncoding.GetLowerHexChars(response, bytes32); // ?? что если ответ будет в upper case return(bytes32); }
public byte[] GetResponseHexChars(ByteArrayPart username, ByteArrayPart realm, bool isMd5SessAlgorithm, ByteArrayPart nonce, int cnonce, int nonceCount, ByteArrayPart password, ByteArrayPart qop, ByteArrayPart digestUri, ByteArrayPart method, ArraySegment <byte> body) { var bytes24 = new byte[24]; var nonceCountBytes = GetDigitChars(bytes24, nonceCount, 15); HexEncoding.GetLowerHexChars(cnonce, bytes24, 16); var cnonceBytes = new ByteArrayPart() { Bytes = bytes24, Begin = 16, End = 24, }; byte[] ha1 = CalculateHa1(username, realm, isMd5SessAlgorithm, nonce, cnonceBytes, password); byte[] ha2 = CalculateHa2(qop, digestUri, method, body); byte[] response = CalculateResponse(nonce, qop, nonceCountBytes, cnonceBytes, ha1, ha2); HexEncoding.GetLowerHexChars(response, bytes32); return(bytes32); }
private readonly int remoteCseq; // why readonly ?! public Dialog(SipMessageReader request, int localTag, ConnectionAddresses connectionAddresses) { this.transport = connectionAddresses.Transport; this.localEndPoint = connectionAddresses.LocalEndPoint; this.remoteEndPoint = connectionAddresses.RemoteEndPoint; localCseq = 0; remoteCseq = request.CSeq.Value; int length = Calculate(request, out routeCount) + 8; bytes = new byte[length]; marker1 = bytes.CopyFrom(request.CallId, 0); HexEncoding.GetLowerHexChars(localTag, bytes, marker1); marker2 = marker1 + 8; marker3 = bytes.CopyFrom(request.From.Tag, marker2); marker4 = bytes.CopyFrom(request.To.AddrSpec.Value, marker3); marker5 = bytes.CopyFrom(request.From.AddrSpec.Value, marker4); marker6 = bytes.CopyFrom(request.From.Epid, marker5); markerN = bytes.CopyFrom(request.Contact[0].AddrSpec.Value, marker6); CopyRecordRoute(request); }