2010-10-27 18:03:31 +04:00
|
|
|
/*
|
2014-06-11 16:11:01 +04:00
|
|
|
* Copyright 2010-2014 Haiku Inc. All rights reserved.
|
2010-10-27 18:03:31 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef _B_HTTP_AUTHENTICATION_H_
|
|
|
|
#define _B_HTTP_AUTHENTICATION_H_
|
|
|
|
|
|
|
|
|
2014-06-11 16:11:01 +04:00
|
|
|
#include <Locker.h>
|
2010-10-27 18:03:31 +04:00
|
|
|
#include <String.h>
|
2014-06-11 16:11:01 +04:00
|
|
|
#include <Url.h>
|
2010-10-27 18:03:31 +04:00
|
|
|
|
|
|
|
// HTTP authentication method
|
|
|
|
enum BHttpAuthenticationMethod {
|
|
|
|
B_HTTP_AUTHENTICATION_NONE = 0,
|
|
|
|
// No authentication
|
|
|
|
B_HTTP_AUTHENTICATION_BASIC = 1,
|
|
|
|
// Basic base64 authentication method (unsecure)
|
|
|
|
B_HTTP_AUTHENTICATION_DIGEST = 2,
|
|
|
|
// Digest authentication
|
|
|
|
B_HTTP_AUTHENTICATION_IE_DIGEST = 4
|
|
|
|
// Slightly modified digest authentication to mimic old IE one
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum BHttpAuthenticationAlgorithm {
|
|
|
|
B_HTTP_AUTHENTICATION_ALGORITHM_NONE,
|
|
|
|
B_HTTP_AUTHENTICATION_ALGORITHM_MD5,
|
|
|
|
B_HTTP_AUTHENTICATION_ALGORITHM_MD5_SESS
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum BHttpAuthenticationQop {
|
|
|
|
B_HTTP_QOP_NONE,
|
|
|
|
B_HTTP_QOP_AUTH,
|
|
|
|
B_HTTP_QOP_AUTHINT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BHttpAuthentication {
|
|
|
|
public:
|
|
|
|
BHttpAuthentication();
|
|
|
|
BHttpAuthentication(const BString& username,
|
|
|
|
const BString& password);
|
2016-05-13 23:49:52 +03:00
|
|
|
BHttpAuthentication(
|
|
|
|
const BHttpAuthentication& other);
|
|
|
|
BHttpAuthentication& operator=(
|
|
|
|
const BHttpAuthentication& other);
|
|
|
|
|
2010-10-27 18:03:31 +04:00
|
|
|
// Field modification
|
|
|
|
void SetUserName(const BString& username);
|
|
|
|
void SetPassword(const BString& password);
|
|
|
|
void SetMethod(
|
|
|
|
BHttpAuthenticationMethod type);
|
|
|
|
status_t Initialize(const BString& wwwAuthenticate);
|
2016-05-13 23:49:52 +03:00
|
|
|
|
2010-10-27 18:03:31 +04:00
|
|
|
// Field access
|
|
|
|
const BString& UserName() const;
|
|
|
|
const BString& Password() const;
|
|
|
|
BHttpAuthenticationMethod Method() const;
|
2016-05-13 23:49:52 +03:00
|
|
|
|
|
|
|
BString Authorization(const BUrl& url,
|
2010-10-27 18:03:31 +04:00
|
|
|
const BString& method) const;
|
2016-05-13 23:49:52 +03:00
|
|
|
|
2010-10-27 18:03:31 +04:00
|
|
|
// Base64 encoding
|
|
|
|
// TODO: Move to a common place. We may have multiple implementations
|
|
|
|
// in the Haiku tree...
|
|
|
|
static BString Base64Encode(const BString& string);
|
|
|
|
static BString Base64Decode(const BString& string);
|
2016-05-13 23:49:52 +03:00
|
|
|
|
|
|
|
|
2010-10-27 18:03:31 +04:00
|
|
|
private:
|
|
|
|
BString _DigestResponse(const BString& uri,
|
|
|
|
const BString& method) const;
|
|
|
|
// TODO: Rename these? _H seems to return a hash value,
|
|
|
|
// _KD returns a hash value of the "data" prepended by
|
|
|
|
// the "secret" string...
|
|
|
|
BString _H(const BString& value) const;
|
2016-05-13 23:49:52 +03:00
|
|
|
BString _KD(const BString& secret,
|
2010-10-27 18:03:31 +04:00
|
|
|
const BString& data) const;
|
2016-05-13 23:49:52 +03:00
|
|
|
|
2010-10-27 18:03:31 +04:00
|
|
|
private:
|
|
|
|
BHttpAuthenticationMethod fAuthenticationMethod;
|
|
|
|
BString fUserName;
|
|
|
|
BString fPassword;
|
2016-05-13 23:49:52 +03:00
|
|
|
|
2010-10-27 18:03:31 +04:00
|
|
|
BString fRealm;
|
|
|
|
BString fDigestNonce;
|
|
|
|
mutable BString fDigestCnonce;
|
|
|
|
mutable int fDigestNc;
|
|
|
|
BString fDigestOpaque;
|
|
|
|
bool fDigestStale;
|
|
|
|
BHttpAuthenticationAlgorithm fDigestAlgorithm;
|
|
|
|
BHttpAuthenticationQop fDigestQop;
|
2016-05-13 23:49:52 +03:00
|
|
|
|
2010-10-27 18:03:31 +04:00
|
|
|
BString fAuthorizationString;
|
2014-06-11 16:11:01 +04:00
|
|
|
|
|
|
|
mutable BLocker fLock;
|
2010-10-27 18:03:31 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _B_HTTP_AUTHENTICATION_H_
|