60 #include "../../3rdparty/des/des.cpp" 361 int separatorPosn = 0;
384 const char *search = isProxy ?
"proxy-authenticate" :
"www-authenticate";
398 for (
int i = 0; i <
values.size(); ++i) {
449 const char *methodString = 0;
460 methodString =
"Basic ";
477 methodString =
"Digest ";
482 methodString =
"NTLM ";
507 const char *
end = d + challenge.
length();
509 while (d < end && (*d ==
' ' || *d ==
'\n' || *d ==
'\r'))
511 const char *start =
d;
512 while (d < end && *d !=
'=')
518 bool quote = (*d ==
'"');
526 bool backslash =
false;
527 if (*d ==
'\\' && d < end - 1) {
543 while (d < end && *d !=
',')
546 options[
key] = value;
561 options[
"qop"] =
"auth";
598 if (alg.
toLower() ==
"md5-sess") {
618 if (qop.
toLower() ==
"auth-int") {
648 while (nonceCountString.
length() < 8)
658 nonce, nonceCountString,
664 credentials +=
"username=\"" +
user.
toLatin1() +
"\", ";
666 credentials +=
"nonce=\"" + nonce +
"\", ";
667 credentials +=
"uri=\"" + path +
"\", ";
669 credentials +=
"opaque=\"" + opaque +
"\", ";
670 credentials +=
"response=\"" + response +
'\"';
672 credentials +=
", algorithm=" + options.
value(
"algorithm");
674 credentials +=
", qop=" + qop +
", ";
675 credentials +=
"nc=" + nonceCountString +
", ";
676 credentials +=
"cnonce=\"" + cnonce +
'\"';
698 #define NTLMSSP_NEGOTIATE_UNICODE 0x00000001 703 #define NTLMSSP_NEGOTIATE_OEM 0x00000002 709 #define NTLMSSP_REQUEST_TARGET 0x00000004 715 #define NTLMSSP_NEGOTIATE_SIGN 0x00000010 721 #define NTLMSSP_NEGOTIATE_SEAL 0x00000020 726 #define NTLMSSP_NEGOTIATE_DATAGRAM 0x00000040 732 #define NTLMSSP_NEGOTIATE_LM_KEY 0x00000080 737 #define NTLMSSP_NEGOTIATE_NTLM 0x00000200 745 #define NTLMSSP_NEGOTIATE_DOMAIN_SUPPLIED 0x00001000 752 #define NTLMSSP_NEGOTIATE_WORKSTATION_SUPPLIED 0x00002000 759 #define NTLMSSP_NEGOTIATE_LOCAL_CALL 0x00004000 765 #define NTLMSSP_NEGOTIATE_ALWAYS_SIGN 0x00008000 771 #define NTLMSSP_TARGET_TYPE_DOMAIN 0x00010000 777 #define NTLMSSP_TARGET_TYPE_SERVER 0x00020000 784 #define NTLMSSP_TARGET_TYPE_SHARE 0x00040000 792 #define NTLMSSP_NEGOTIATE_NTLM2 0x00080000 799 #define NTLMSSP_NEGOTIATE_TARGET_INFO 0x00800000 804 #define NTLMSSP_NEGOTIATE_128 0x20000000 812 #define NTLMSSP_NEGOTIATE_KEY_EXCHANGE 0x40000000 817 #define NTLMSSP_NEGOTIATE_56 0x80000000 822 #define AVTIMESTAMP 7 912 for (
int i = 0; i < s.
length(); ++i)
922 buf.
offset = (offset + 1) & ~1;
933 buf.
offset = (offset + 1) & ~1;
1054 const unsigned short *s = src.
utf16();
1055 unsigned short *
d = (
unsigned short*)rc.data();
1056 for (
int i = 0; i < src.
length(); ++i) {
1066 unsigned short *
d = (
unsigned short*)src.
data();
1067 for (
int i = 0; i < src.
length() / 2; ++i) {
1073 #ifdef NTLMV1_CLIENT 1080 unsigned char md4hash[22];
1081 memset(md4hash, 0,
sizeof(md4hash));
1087 deshash((
unsigned char *)rc.data(), md4hash, (
unsigned char *)ch.
challenge);
1088 deshash((
unsigned char *)rc.data() + 8, md4hash + 7, (
unsigned char *)ch.
challenge);
1089 deshash((
unsigned char *)rc.data() + 16, md4hash + 14, (
unsigned char *)ch.
challenge);
1101 const char *block =
"KGS!@#$%";
1103 deshash((
unsigned char *)hash.
data(), (
unsigned char *)key.
data(), (
unsigned char *)block);
1104 deshash((
unsigned char *)hash.
data() + 8, (
unsigned char *)key.
data() + 7, (
unsigned char *)block);
1108 deshash((
unsigned char *)rc.
data(), (
unsigned char *)hash.
data(), ch.
challenge);
1109 deshash((
unsigned char *)rc.
data() + 8, (
unsigned char *)hash.
data() + 7, ch.
challenge);
1110 deshash((
unsigned char *)rc.
data() + 16, (
unsigned char *)hash.
data() + 14, ch.
challenge);
1165 for(
int i = 0; i<key.
size();i++) {
1166 iKeyPad[i] = key[i]^iKeyPad[i];
1170 for(
int i = 0; i<key.
size();i++) {
1171 oKeyPad[i] = key[i]^oKeyPad[i];
1185 hmacDigest = hash.
result();
1283 if(timeArray.
size()) {
1321 ntChallengeResp.
append(temp);
1323 return ntChallengeResp;
1337 message.
append(clientCh);
1340 lmChallengeResp.
append(clientCh);
1342 return lmChallengeResp;
1356 if (strncmp(ch.
magic,
"NTLMSSP", 8) != 0)
1427 #ifdef NTLMV1_CLIENT 1439 #ifdef NTLMV1_CLIENT The QVariant class acts like a union for the most common Qt data types.
#define NTLMSSP_NEGOTIATE_TARGET_INFO
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static uint hash(const uchar *p, int n)
const unsigned char magic[QSXE_MAGIC_BYTES]
QHash< QString, QVariant > QVariantHash
QByteArray & fill(char c, int size=-1)
Sets every byte in the byte array to character ch.
#define QT_END_NAMESPACE
This macro expands to.
char * data()
Returns a pointer to the data stored in the byte array.
static QByteArray digestMd5ResponseHelper(const QByteArray &alg, const QByteArray &userName, const QByteArray &realm, const QByteArray &password, const QByteArray &nonce, const QByteArray &nonceCount, const QByteArray &cNonce, const QByteArray &qop, const QByteArray &method, const QByteArray &digestUri, const QByteArray &hEntity)
#define it(className, varName)
QByteArray & append(char c)
Appends the character ch to this byte array.
#define NTLMSSP_NEGOTIATE_OEM
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
void parseHttpResponse(const QHttpResponseHeader &, bool isProxy)
The QByteArray class provides an array of bytes.
int length() const
Returns the number of characters in this string.
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
static void qStreamNtlmString(QDataStream &ds, const QString &s, bool unicode)
~QAuthenticator()
Destructs the object.
uint toTime_t() const
Returns the datetime as the number of seconds that have passed since 1970-01-01T00:00:00, Coordinated Universal Time (Qt::UTC).
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
static QByteArray qStringAsUcs2Le(const QString &src)
QByteArray qEncodeHmacMd5(QByteArray &key, const QByteArray &message)
bool operator==(const QAuthenticator &other) const
Returns true if this authenticator is identical to other; otherwise returns false.
QByteArray toLower() const
Returns a lowercase copy of the byte array.
static QString qStringFromUcs2Le(const QByteArray &src)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QByteArray & prepend(char c)
Prepends the character ch to this byte array.
The QString class provides a Unicode character string.
Q_CORE_EXPORT int qrand()
void setUser(const QString &user)
Sets the user used for authentication.
QByteArray toHex() const
Returns a hex encoded copy of the byte array.
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
The QChar class provides a 16-bit Unicode character.
const T value(const Key &key) const
Returns the value associated with the key.
QByteArray targetInfoBuff
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
QByteArray right(int len) const
Returns a byte array that contains the rightmost len bytes of this byte array.
void append(const T &t)
Inserts value at the end of the list.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
QAuthenticator & operator=(const QAuthenticator &other)
Assigns the contents of other to this authenticator.
int readRawData(char *, int len)
Reads at most len bytes from the stream into s and returns the number of bytes read.
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
static QDate currentDate()
Returns the current date, as reported by the system clock.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static QByteArray qNtlmPhase1()
QByteArray trimmed() const
Returns a byte array that has whitespace removed from the start and the end.
QByteArray ntlmResponseBuf
QAuthenticatorPrivate * d
QByteArray leftJustified(int width, char fill=' ', bool truncate=false) const
Returns a byte array of size width that contains this byte array padded by the fill character...
#define NTLMSSP_NEGOTIATE_UNICODE
static const char * data(const QByteArray &arr)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
static QByteArray clientChallenge(const QAuthenticatorPrivate *ctx)
void setByteOrder(ByteOrder)
Sets the serialization byte order to bo.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
static QByteArray qCreatev2Hash(const QAuthenticatorPrivate *ctx, QNtlmPhase3Block *phase3)
friend class QAuthenticatorPrivate
static QByteArray qNtlmPhase3(QAuthenticatorPrivate *ctx, const QByteArray &phase2data)
bool isNull() const
Returns true if this byte array is null; otherwise returns false.
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
const quint8 hirespversion
The QAuthenticator class provides an authentication object.
#define NTLMSSP_NEGOTIATE_NTLM
static QHash< QByteArray, QByteArray > parseDigestAuthenticationChallenge(const QByteArray &challenge)
QAuthenticator()
Constructs an empty authentication object.
int length() const
Same as size().
T & first()
Returns a reference to the first item in the list.
const char * constData() const
Returns a pointer to the data stored in the byte array.
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
static QByteArray fromBase64(const QByteArray &base64)
Returns a decoded copy of the Base64 array base64.
QList< QByteArray > split(char sep) const
Splits the byte array into subarrays wherever sep occurs, and returns the list of those arrays...
#define Q_ASSERT_X(cond, where, what)
QVariant option(const QString &opt) const
Returns the value related to option opt if it was set by the server.
unsigned char challenge[8]
The QDateTime class provides date and time functions.
void clear()
Clears the contents of the string and makes it empty.
static QTime currentTime()
Returns the current time as reported by the system clock.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
bool isNull() const
Returns true if the authenticator is null.
void addData(const char *data, int length)
Adds the first length chars of data to the cryptographic hash.
static QDataStream & operator<<(QDataStream &s, const QNtlmBuffer &b)
void setOption(const QString &opt, const QVariant &value)
Sets the outgoing option opt to value value.
static bool qNtlmDecodePhase2(const QByteArray &data, QNtlmPhase2Block &ch)
QString user() const
returns the user used for authentication.
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
static int qEncodeNtlmString(QNtlmBuffer &buf, int offset, const QString &s, bool unicode)
void resize(int size)
Sets the size of the byte array to size bytes.
QByteArray digestMd5Response(const QByteArray &challenge, const QByteArray &method, const QByteArray &path)
QVariantHash options() const
Returns all incoming options set in this QAuthenticator object by parsing the server reply...
QByteArray result() const
Returns the final hash value.
QByteArray toBase64() const
Returns a copy of the byte array, encoded as Base64.
QByteArray calculateResponse(const QByteArray &method, const QByteArray &path)
static int qEncodeNtlmBuffer(QNtlmBuffer &buf, int offset, const QByteArray &s)
int size() const
Returns the number of bytes in this byte array.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
static QByteArray qEncodeNtlmv2Response(const QAuthenticatorPrivate *ctx, const QNtlmPhase2Block &ch, QNtlmPhase3Block *phase3)
The QDataStream class provides serialization of binary data to a QIODevice.
void setPassword(const QString &password)
Sets the password used for authentication.
static QByteArray qEncodeLmv2Response(const QAuthenticatorPrivate *ctx, const QNtlmPhase2Block &ch, QNtlmPhase3Block *phase3)
QString password() const
returns the password used for authentication.
int skipRawData(int len)
Skips len bytes from the device.
static QDataStream & operator>>(QDataStream &s, QNtlmBuffer &b)
static QByteArray qExtractServerTime(const QByteArray &targetInfoBuff)
static void qStreamNtlmBuffer(QDataStream &ds, const QByteArray &s)
static const KeyPair *const end
#define NTLMSSP_REQUEST_TARGET
T qToLittleEndian(T source)
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
int writeRawData(const char *, int len)
Writes len bytes from s to the stream.
static QByteArray hash(const QByteArray &data, Algorithm method)
Returns the hash of data using method.
Q_CORE_EXPORT char * qstrncpy(char *dst, const char *src, uint len)
QString realm() const
returns the realm requiring authentication.
T qFromLittleEndian(const uchar *src)
void reset()
Resets the object.
The QCryptographicHash class provides a way to generate cryptographic hashes.
QBool contains(char c) const
Returns true if the byte array contains the character ch; otherwise returns false.
The QList class is a template class that provides lists.
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.