#include <DigestAuthentication.hh>
Public Member Functions | |
| Authenticator () | |
| Authenticator (const Authenticator &orig) | |
| Authenticator & | operator= (const Authenticator &rightSide) |
| virtual | ~Authenticator () |
| void | reset () |
| void | setRealmAndNonce (char const *realm, char const *nonce) |
| void | setRealmAndRandomNonce (char const *realm) |
| void | setUsernameAndPassword (char const *username, char const *password, Boolean passwordIsMD5=False) |
| char const * | realm () const |
| char const * | nonce () const |
| char const * | username () const |
| char const * | password () const |
| char const * | computeDigestResponse (char const *cmd, char const *url) const |
| void | reclaimDigestResponse (char const *responseStr) const |
Private Member Functions | |
| void | resetRealmAndNonce () |
| void | resetUsernameAndPassword () |
| void | assignRealmAndNonce (char const *realm, char const *nonce) |
| void | assignUsernameAndPassword (char const *username, char const *password, Boolean passwordIsMD5) |
| void | assign (char const *realm, char const *nonce, char const *username, char const *password, Boolean passwordIsMD5) |
Private Attributes | |
| char * | fRealm |
| char * | fNonce |
| char * | fUsername |
| char * | fPassword |
| Boolean | fPasswordIsMD5 |
Definition at line 32 of file DigestAuthentication.hh.
| Authenticator::Authenticator | ( | ) |
| Authenticator::Authenticator | ( | const Authenticator & | orig | ) |
Definition at line 33 of file DigestAuthentication.cpp.
References assign(), fPasswordIsMD5, nonce(), password(), realm(), and username().
00033 { 00034 assign(orig.realm(), orig.nonce(), orig.username(), orig.password(), 00035 orig.fPasswordIsMD5); 00036 }
| Authenticator::~Authenticator | ( | ) | [virtual] |
Definition at line 48 of file DigestAuthentication.cpp.
References reset().
00048 { 00049 reset(); 00050 }
| Authenticator & Authenticator::operator= | ( | const Authenticator & | rightSide | ) |
Definition at line 38 of file DigestAuthentication.cpp.
References assign(), fPasswordIsMD5, nonce(), password(), realm(), reset(), and username().
00038 { 00039 if (&rightSide != this) { 00040 reset(); 00041 assign(rightSide.realm(), rightSide.nonce(), 00042 rightSide.username(), rightSide.password(), rightSide.fPasswordIsMD5); 00043 } 00044 00045 return *this; 00046 }
| void Authenticator::reset | ( | ) |
Definition at line 52 of file DigestAuthentication.cpp.
References resetRealmAndNonce(), and resetUsernameAndPassword().
Referenced by RTSPClient::announceSDPDescription(), RTSPClient::describeURL(), SIPClient::invite1(), operator=(), SIPClient::reset(), RTSPClient::reset(), and ~Authenticator().
00052 { 00053 resetRealmAndNonce(); 00054 resetUsernameAndPassword(); 00055 }
| void Authenticator::setRealmAndNonce | ( | char const * | realm, | |
| char const * | nonce | |||
| ) |
Definition at line 57 of file DigestAuthentication.cpp.
References assignRealmAndNonce(), and resetRealmAndNonce().
Referenced by RTSPClient::checkForAuthenticationFailure(), and SIPClient::getResponseCode().
00057 { 00058 resetRealmAndNonce(); 00059 assignRealmAndNonce(realm, nonce); 00060 }
| void Authenticator::setRealmAndRandomNonce | ( | char const * | realm | ) |
Definition at line 62 of file DigestAuthentication.cpp.
References assignRealmAndNonce(), NULL, our_MD5Data(), and resetRealmAndNonce().
00062 { 00063 resetRealmAndNonce(); 00064 00065 // Construct data to seed the random nonce: 00066 struct { 00067 struct timeval timestamp; 00068 unsigned counter; 00069 } seedData; 00070 gettimeofday(&seedData.timestamp, NULL); 00071 static unsigned counter = 0; 00072 seedData.counter = ++counter; 00073 00074 // Use MD5 to compute a 'random' nonce from this seed data: 00075 char nonceBuf[33]; 00076 our_MD5Data((unsigned char*)(&seedData), sizeof seedData, nonceBuf); 00077 00078 assignRealmAndNonce(realm, nonceBuf); 00079 }
| void Authenticator::setUsernameAndPassword | ( | char const * | username, | |
| char const * | password, | |||
| Boolean | passwordIsMD5 = False | |||
| ) |
Definition at line 81 of file DigestAuthentication.cpp.
References assignUsernameAndPassword(), and resetUsernameAndPassword().
Referenced by RTSPClient::announceWithPassword(), RTSPClient::describeWithPassword(), SIPClient::inviteWithPassword(), and RTSPClient::sendOptionsCmd().
00083 { 00084 resetUsernameAndPassword(); 00085 assignUsernameAndPassword(username, password, passwordIsMD5); 00086 }
| char const* Authenticator::realm | ( | ) | const [inline] |
Definition at line 49 of file DigestAuthentication.hh.
References fRealm.
Referenced by RTSPClient::announceWithPassword(), Authenticator(), computeDigestResponse(), SIPClient::createAuthenticatorString(), RTSPClient::createAuthenticatorString(), RTSPClient::describeWithPassword(), SIPClient::inviteWithPassword(), operator=(), and RTSPClient::sendOptionsCmd().
00049 { return fRealm; }
| char const* Authenticator::nonce | ( | ) | const [inline] |
Definition at line 50 of file DigestAuthentication.hh.
References fNonce.
Referenced by Authenticator(), computeDigestResponse(), SIPClient::createAuthenticatorString(), RTSPClient::createAuthenticatorString(), SIPClient::inviteWithPassword(), and operator=().
00050 { return fNonce; }
| char const* Authenticator::username | ( | ) | const [inline] |
Definition at line 51 of file DigestAuthentication.hh.
References fUsername.
Referenced by Authenticator(), computeDigestResponse(), SIPClient::createAuthenticatorString(), RTSPClient::createAuthenticatorString(), and operator=().
00051 { return fUsername; }
| char const* Authenticator::password | ( | ) | const [inline] |
Definition at line 52 of file DigestAuthentication.hh.
References fPassword.
Referenced by Authenticator(), computeDigestResponse(), SIPClient::createAuthenticatorString(), RTSPClient::createAuthenticatorString(), and operator=().
00052 { return fPassword; }
| char const * Authenticator::computeDigestResponse | ( | char const * | cmd, | |
| char const * | url | |||
| ) | const |
Definition at line 88 of file DigestAuthentication.cpp.
References fPasswordIsMD5, nonce(), NULL, our_MD5Data(), password(), realm(), and username().
Referenced by SIPClient::createAuthenticatorString(), and RTSPClient::createAuthenticatorString().
00089 { 00090 // The "response" field is computed as: 00091 // md5(md5(<username>:<realm>:<password>):<nonce>:md5(<cmd>:<url>)) 00092 // or, if "fPasswordIsMD5" is True: 00093 // md5(<password>:<nonce>:md5(<cmd>:<url>)) 00094 char ha1Buf[33]; 00095 if (fPasswordIsMD5) { 00096 strncpy(ha1Buf, password(), 32); 00097 ha1Buf[32] = '\0'; // just in case 00098 } else { 00099 unsigned const ha1DataLen = strlen(username()) + 1 00100 + strlen(realm()) + 1 + strlen(password()); 00101 unsigned char* ha1Data = new unsigned char[ha1DataLen+1]; 00102 sprintf((char*)ha1Data, "%s:%s:%s", username(), realm(), password()); 00103 our_MD5Data(ha1Data, ha1DataLen, ha1Buf); 00104 delete[] ha1Data; 00105 } 00106 00107 unsigned const ha2DataLen = strlen(cmd) + 1 + strlen(url); 00108 unsigned char* ha2Data = new unsigned char[ha2DataLen+1]; 00109 sprintf((char*)ha2Data, "%s:%s", cmd, url); 00110 char ha2Buf[33]; 00111 our_MD5Data(ha2Data, ha2DataLen, ha2Buf); 00112 delete[] ha2Data; 00113 00114 unsigned const digestDataLen 00115 = 32 + 1 + strlen(nonce()) + 1 + 32; 00116 unsigned char* digestData = new unsigned char[digestDataLen+1]; 00117 sprintf((char*)digestData, "%s:%s:%s", 00118 ha1Buf, nonce(), ha2Buf); 00119 char const* result = our_MD5Data(digestData, digestDataLen, NULL); 00120 delete[] digestData; 00121 return result; 00122 }
| void Authenticator::reclaimDigestResponse | ( | char const * | responseStr | ) | const |
Definition at line 124 of file DigestAuthentication.cpp.
Referenced by SIPClient::createAuthenticatorString(), and RTSPClient::createAuthenticatorString().
| void Authenticator::resetRealmAndNonce | ( | ) | [private] |
Definition at line 128 of file DigestAuthentication.cpp.
References fNonce, fRealm, and NULL.
Referenced by reset(), setRealmAndNonce(), and setRealmAndRandomNonce().
| void Authenticator::resetUsernameAndPassword | ( | ) | [private] |
Definition at line 133 of file DigestAuthentication.cpp.
References False, fPassword, fPasswordIsMD5, fUsername, and NULL.
Referenced by reset(), and setUsernameAndPassword().
00133 { 00134 delete[] fUsername; fUsername = NULL; 00135 delete[] fPassword; fPassword = NULL; 00136 fPasswordIsMD5 = False; 00137 }
| void Authenticator::assignRealmAndNonce | ( | char const * | realm, | |
| char const * | nonce | |||
| ) | [private] |
Definition at line 139 of file DigestAuthentication.cpp.
References fNonce, fRealm, and strDup().
Referenced by assign(), setRealmAndNonce(), and setRealmAndRandomNonce().
| void Authenticator::assignUsernameAndPassword | ( | char const * | username, | |
| char const * | password, | |||
| Boolean | passwordIsMD5 | |||
| ) | [private] |
Definition at line 145 of file DigestAuthentication.cpp.
References fPassword, fPasswordIsMD5, fUsername, and strDup().
Referenced by assign(), and setUsernameAndPassword().
00146 { 00147 fUsername = strDup(username); 00148 fPassword = strDup(password); 00149 fPasswordIsMD5 = passwordIsMD5; 00150 }
| void Authenticator::assign | ( | char const * | realm, | |
| char const * | nonce, | |||
| char const * | username, | |||
| char const * | password, | |||
| Boolean | passwordIsMD5 | |||
| ) | [private] |
Definition at line 152 of file DigestAuthentication.cpp.
References assignRealmAndNonce(), and assignUsernameAndPassword().
Referenced by Authenticator(), and operator=().
00154 { 00155 assignRealmAndNonce(realm, nonce); 00156 assignUsernameAndPassword(username, password, passwordIsMD5); 00157 }
char* Authenticator::fRealm [private] |
Definition at line 67 of file DigestAuthentication.hh.
Referenced by assignRealmAndNonce(), realm(), and resetRealmAndNonce().
char* Authenticator::fNonce [private] |
Definition at line 67 of file DigestAuthentication.hh.
Referenced by assignRealmAndNonce(), nonce(), and resetRealmAndNonce().
char* Authenticator::fUsername [private] |
Definition at line 68 of file DigestAuthentication.hh.
Referenced by assignUsernameAndPassword(), resetUsernameAndPassword(), and username().
char* Authenticator::fPassword [private] |
Definition at line 68 of file DigestAuthentication.hh.
Referenced by assignUsernameAndPassword(), password(), and resetUsernameAndPassword().
Boolean Authenticator::fPasswordIsMD5 [private] |
Definition at line 69 of file DigestAuthentication.hh.
Referenced by assignUsernameAndPassword(), Authenticator(), computeDigestResponse(), operator=(), and resetUsernameAndPassword().
1.5.2