2 * Copyright 2010-2014 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 #ifndef _B_HTTP_AUTHENTICATION_H_
6 #define _B_HTTP_AUTHENTICATION_H_
13 // HTTP authentication method
14 enum BHttpAuthenticationMethod
{
15 B_HTTP_AUTHENTICATION_NONE
= 0,
17 B_HTTP_AUTHENTICATION_BASIC
= 1,
18 // Basic base64 authentication method (unsecure)
19 B_HTTP_AUTHENTICATION_DIGEST
= 2,
20 // Digest authentication
21 B_HTTP_AUTHENTICATION_IE_DIGEST
= 4
22 // Slightly modified digest authentication to mimic old IE one
26 enum BHttpAuthenticationAlgorithm
{
27 B_HTTP_AUTHENTICATION_ALGORITHM_NONE
,
28 B_HTTP_AUTHENTICATION_ALGORITHM_MD5
,
29 B_HTTP_AUTHENTICATION_ALGORITHM_MD5_SESS
33 enum BHttpAuthenticationQop
{
40 class BHttpAuthentication
{
42 BHttpAuthentication();
43 BHttpAuthentication(const BString
& username
,
44 const BString
& password
);
46 const BHttpAuthentication
& other
);
47 BHttpAuthentication
& operator=(
48 const BHttpAuthentication
& other
);
51 void SetUserName(const BString
& username
);
52 void SetPassword(const BString
& password
);
54 BHttpAuthenticationMethod type
);
55 status_t
Initialize(const BString
& wwwAuthenticate
);
58 const BString
& UserName() const;
59 const BString
& Password() const;
60 BHttpAuthenticationMethod
Method() const;
62 BString
Authorization(const BUrl
& url
,
63 const BString
& method
) const;
66 // TODO: Move to a common place. We may have multiple implementations
67 // in the Haiku tree...
68 static BString
Base64Encode(const BString
& string
);
69 static BString
Base64Decode(const BString
& string
);
73 BString
_DigestResponse(const BString
& uri
,
74 const BString
& method
) const;
75 // TODO: Rename these? _H seems to return a hash value,
76 // _KD returns a hash value of the "data" prepended by
77 // the "secret" string...
78 BString
_H(const BString
& value
) const;
79 BString
_KD(const BString
& secret
,
80 const BString
& data
) const;
83 BHttpAuthenticationMethod fAuthenticationMethod
;
89 mutable BString fDigestCnonce
;
90 mutable int fDigestNc
;
91 BString fDigestOpaque
;
93 BHttpAuthenticationAlgorithm fDigestAlgorithm
;
94 BHttpAuthenticationQop fDigestQop
;
96 BString fAuthorizationString
;
98 mutable BLocker fLock
;
101 #endif // _B_HTTP_AUTHENTICATION_H_