#include <DigestAuthentication.hh>
Public Member Functions | |
| Authenticator () | |
| Authenticator (char const *username, char const *password, Boolean passwordIsMD5=False) | |
| 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 37 of file DigestAuthentication.cpp.
References assign(), fPasswordIsMD5, nonce(), password(), realm(), and username().
00037 { 00038 assign(orig.realm(), orig.nonce(), orig.username(), orig.password(), orig.fPasswordIsMD5); 00039 }
| Authenticator::~Authenticator | ( | ) | [virtual] |
Definition at line 51 of file DigestAuthentication.cpp.
References reset().
00051 { 00052 reset(); 00053 }
| Authenticator & Authenticator::operator= | ( | const Authenticator & | rightSide | ) |
Definition at line 41 of file DigestAuthentication.cpp.
References assign(), fPasswordIsMD5, nonce(), password(), realm(), reset(), and username().
00041 { 00042 if (&rightSide != this) { 00043 reset(); 00044 assign(rightSide.realm(), rightSide.nonce(), 00045 rightSide.username(), rightSide.password(), rightSide.fPasswordIsMD5); 00046 } 00047 00048 return *this; 00049 }
| void Authenticator::reset | ( | ) |
Definition at line 55 of file DigestAuthentication.cpp.
References resetRealmAndNonce(), and resetUsernameAndPassword().
Referenced by SIPClient::invite1(), operator=(), SIPClient::reset(), RTSPClient::reset(), and ~Authenticator().
00055 { 00056 resetRealmAndNonce(); 00057 resetUsernameAndPassword(); 00058 }
| void Authenticator::setRealmAndNonce | ( | char const * | realm, | |
| char const * | nonce | |||
| ) |
Definition at line 60 of file DigestAuthentication.cpp.
References assignRealmAndNonce(), and resetRealmAndNonce().
Referenced by SIPClient::getResponseCode(), and RTSPClient::handleAuthenticationFailure().
00060 { 00061 resetRealmAndNonce(); 00062 assignRealmAndNonce(realm, nonce); 00063 }
| void Authenticator::setRealmAndRandomNonce | ( | char const * | realm | ) |
Definition at line 65 of file DigestAuthentication.cpp.
References assignRealmAndNonce(), NULL, our_MD5Data(), and resetRealmAndNonce().
00065 { 00066 resetRealmAndNonce(); 00067 00068 // Construct data to seed the random nonce: 00069 struct { 00070 struct timeval timestamp; 00071 unsigned counter; 00072 } seedData; 00073 gettimeofday(&seedData.timestamp, NULL); 00074 static unsigned counter = 0; 00075 seedData.counter = ++counter; 00076 00077 // Use MD5 to compute a 'random' nonce from this seed data: 00078 char nonceBuf[33]; 00079 our_MD5Data((unsigned char*)(&seedData), sizeof seedData, nonceBuf); 00080 00081 assignRealmAndNonce(realm, nonceBuf); 00082 }
| void Authenticator::setUsernameAndPassword | ( | char const * | username, | |
| char const * | password, | |||
| Boolean | passwordIsMD5 = False | |||
| ) |
Definition at line 84 of file DigestAuthentication.cpp.
References assignUsernameAndPassword(), and resetUsernameAndPassword().
Referenced by RTSPClient::openConnection(), and DarwinInjector::setDestination().
00086 { 00087 resetUsernameAndPassword(); 00088 assignUsernameAndPassword(username, password, passwordIsMD5); 00089 }
| char const* Authenticator::realm | ( | ) | const [inline] |
Definition at line 51 of file DigestAuthentication.hh.
References fRealm.
Referenced by Authenticator(), computeDigestResponse(), SIPClient::createAuthenticatorString(), RTSPClient::createAuthenticatorString(), RTSPClient::handleAuthenticationFailure(), SIPClient::inviteWithPassword(), and operator=().
00051 { return fRealm; }
| char const* Authenticator::nonce | ( | ) | const [inline] |
Definition at line 52 of file DigestAuthentication.hh.
References fNonce.
Referenced by Authenticator(), computeDigestResponse(), SIPClient::createAuthenticatorString(), RTSPClient::createAuthenticatorString(), SIPClient::inviteWithPassword(), and operator=().
00052 { return fNonce; }
| char const* Authenticator::username | ( | ) | const [inline] |
Definition at line 53 of file DigestAuthentication.hh.
References fUsername.
Referenced by Authenticator(), computeDigestResponse(), SIPClient::createAuthenticatorString(), RTSPClient::createAuthenticatorString(), getSDPDescription(), RTSPClient::handleAuthenticationFailure(), and operator=().
00053 { return fUsername; }
| char const* Authenticator::password | ( | ) | const [inline] |
Definition at line 54 of file DigestAuthentication.hh.
References fPassword.
Referenced by Authenticator(), computeDigestResponse(), SIPClient::createAuthenticatorString(), RTSPClient::createAuthenticatorString(), getSDPDescription(), RTSPClient::handleAuthenticationFailure(), and operator=().
00054 { return fPassword; }
| char const * Authenticator::computeDigestResponse | ( | char const * | cmd, | |
| char const * | url | |||
| ) | const |
Definition at line 91 of file DigestAuthentication.cpp.
References fPasswordIsMD5, nonce(), NULL, our_MD5Data(), password(), realm(), and username().
Referenced by SIPClient::createAuthenticatorString(), and RTSPClient::createAuthenticatorString().
00092 { 00093 // The "response" field is computed as: 00094 // md5(md5(<username>:<realm>:<password>):<nonce>:md5(<cmd>:<url>)) 00095 // or, if "fPasswordIsMD5" is True: 00096 // md5(<password>:<nonce>:md5(<cmd>:<url>)) 00097 char ha1Buf[33]; 00098 if (fPasswordIsMD5) { 00099 strncpy(ha1Buf, password(), 32); 00100 ha1Buf[32] = '\0'; // just in case 00101 } else { 00102 unsigned const ha1DataLen = strlen(username()) + 1 00103 + strlen(realm()) + 1 + strlen(password()); 00104 unsigned char* ha1Data = new unsigned char[ha1DataLen+1]; 00105 sprintf((char*)ha1Data, "%s:%s:%s", username(), realm(), password()); 00106 our_MD5Data(ha1Data, ha1DataLen, ha1Buf); 00107 delete[] ha1Data; 00108 } 00109 00110 unsigned const ha2DataLen = strlen(cmd) + 1 + strlen(url); 00111 unsigned char* ha2Data = new unsigned char[ha2DataLen+1]; 00112 sprintf((char*)ha2Data, "%s:%s", cmd, url); 00113 char ha2Buf[33]; 00114 our_MD5Data(ha2Data, ha2DataLen, ha2Buf); 00115 delete[] ha2Data; 00116 00117 unsigned const digestDataLen 00118 = 32 + 1 + strlen(nonce()) + 1 + 32; 00119 unsigned char* digestData = new unsigned char[digestDataLen+1]; 00120 sprintf((char*)digestData, "%s:%s:%s", 00121 ha1Buf, nonce(), ha2Buf); 00122 char const* result = our_MD5Data(digestData, digestDataLen, NULL); 00123 delete[] digestData; 00124 return result; 00125 }
| void Authenticator::reclaimDigestResponse | ( | char const * | responseStr | ) | const |
Definition at line 127 of file DigestAuthentication.cpp.
Referenced by SIPClient::createAuthenticatorString(), and RTSPClient::createAuthenticatorString().
| void Authenticator::resetRealmAndNonce | ( | ) | [private] |
Definition at line 131 of file DigestAuthentication.cpp.
References fNonce, fRealm, and NULL.
Referenced by reset(), setRealmAndNonce(), and setRealmAndRandomNonce().
| void Authenticator::resetUsernameAndPassword | ( | ) | [private] |
Definition at line 136 of file DigestAuthentication.cpp.
References False, fPassword, fPasswordIsMD5, fUsername, and NULL.
Referenced by reset(), and setUsernameAndPassword().
00136 { 00137 delete[] fUsername; fUsername = NULL; 00138 delete[] fPassword; fPassword = NULL; 00139 fPasswordIsMD5 = False; 00140 }
| void Authenticator::assignRealmAndNonce | ( | char const * | realm, | |
| char const * | nonce | |||
| ) | [private] |
Definition at line 142 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 147 of file DigestAuthentication.cpp.
References fPassword, fPasswordIsMD5, fUsername, and strDup().
Referenced by assign(), and setUsernameAndPassword().
00147 { 00148 fUsername = strDup(username); 00149 fPassword = strDup(password); 00150 fPasswordIsMD5 = passwordIsMD5; 00151 }
| void Authenticator::assign | ( | char const * | realm, | |
| char const * | nonce, | |||
| char const * | username, | |||
| char const * | password, | |||
| Boolean | passwordIsMD5 | |||
| ) | [private] |
Definition at line 153 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 68 of file DigestAuthentication.hh.
Referenced by assignRealmAndNonce(), realm(), and resetRealmAndNonce().
char* Authenticator::fNonce [private] |
Definition at line 68 of file DigestAuthentication.hh.
Referenced by assignRealmAndNonce(), nonce(), and resetRealmAndNonce().
char* Authenticator::fUsername [private] |
Definition at line 69 of file DigestAuthentication.hh.
Referenced by assignUsernameAndPassword(), resetUsernameAndPassword(), and username().
char* Authenticator::fPassword [private] |
Definition at line 69 of file DigestAuthentication.hh.
Referenced by assignUsernameAndPassword(), password(), and resetUsernameAndPassword().
Boolean Authenticator::fPasswordIsMD5 [private] |
Definition at line 70 of file DigestAuthentication.hh.
Referenced by assignUsernameAndPassword(), Authenticator(), computeDigestResponse(), operator=(), and resetUsernameAndPassword().
1.5.2