Skip to content

Commit b3eff95

Browse files
committed
Kerberos support:
* Copy keyblock from credentials as fallback in the case if krb5_auth_con_getkey returns success but keyblock is null. * Add compile time definition KRB5_HAS_krb5_creds_keyblock. * Use krb5_data_copy instead of krb5_data_alloc() and memcpy() in KrbClient::Request(). * Include terminal null character when copying principal name to ensure that is always a null terminated string. * Remove unused include file. * Fix comments in meta server authentication configuration.
1 parent 0f7fd03 commit b3eff95

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

src/cc/krb/KfsKrb5.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ class KfsKrb5
110110
return EINVAL;
111111
}
112112
krb5_data theData = {0};
113-
krb5_error_code theRet = krb5_data_alloc(&theData, strlen(theStr));
113+
krb5_error_code theRet = krb5_data_copy(
114+
&theData, theStr, strlen(theStr) + 1);
114115
if (theRet) {
115116
return theRet;
116117
}
117-
memcpy(theData.data, theStr, theData.length);
118118
theRet = krb5_get_server_rcache(inCtx, &theData, inRCache);
119119
krb5_data_free(&theData);
120120
return theRet;

src/cc/krb/KrbClient.cc

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,31 @@ class KrbClient::Impl
161161
if (theCredsPtr) {
162162
mLastCredEndTime = theCredsPtr->times.endtime;
163163
}
164+
if (0 == mErrCode) {
165+
mErrCode = krb5_auth_con_getkey(mCtx, mAuthCtx, &mKeyBlockPtr);
166+
}
167+
#ifdef KRB5_HAS_krb5_creds_keyblock
168+
if (0 == mErrCode && ! mKeyBlockPtr) {
169+
mErrCode = krb5_copy_keyblock(
170+
mCtx, &theCredsPtr->keyblock, &mKeyBlockPtr);
171+
}
172+
#endif
164173
krb5_free_creds(mCtx, theCredsPtr);
165-
if (mErrCode != 0) {
174+
if (0 != mErrCode) {
166175
return ErrStr();
167176
}
168-
if ((mErrCode = krb5_auth_con_getkey(mCtx, mAuthCtx, &mKeyBlockPtr))) {
169-
return ErrStr();
177+
if (0 == mErrCode && ! mKeyBlockPtr) {
178+
mErrCode = EINVAL;
179+
return "no session key";
170180
}
171-
outDataPtr = (const char*)mOutBuf.data;
172-
outDataLen = (int)mOutBuf.length;
173181
outSessionKeyPtr = KfsKrb5::get_key_block_contents(mKeyBlockPtr);
174182
outSessionKeyLen = KfsKrb5::get_key_block_length(mKeyBlockPtr);
183+
if (! outSessionKeyPtr || outSessionKeyLen <= 0) {
184+
mErrCode = EINVAL;
185+
return "invalid empty session key";
186+
}
187+
outDataPtr = (const char*)mOutBuf.data;
188+
outDataLen = (int)mOutBuf.length;
175189
return 0;
176190
}
177191
const char* Reply(

src/cc/krb/krbtest_main.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
#include <time.h>
3636
#include <iostream>
37-
#include <vector>
3837
#include <string>
3938

4039
namespace

src/cc/meta/AuthContext.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,8 @@ class AuthContext::Impl
520520
// No replay detection is needed, as either AP_REP or TLS-PSK
521521
// are used. Both these mechanisms are sufficient to protect
522522
// against replay attack as both provide mutual authentication.
523-
// With no TLS once assume that party other than QFS protects
524-
// against replay, man-in-the-middle attacks etc.
523+
// With no TLS one assumes that the party other than QFS
524+
// protects against replay, man-in-the-middle attacks etc.
525525
theKrbServicePtr.reset(new KrbService());
526526
const char* theErrMsgPtr = theKrbServicePtr->Init(
527527
inParameters.getValue(

0 commit comments

Comments
 (0)