Loading...
Searching...
No Matches
XrdSecztn Namespace Reference

## Functions

bool | isJWT (const char *)

## Function Documentation

## isJWT()

bool XrdSecztn::isJWT | ( | const char * | b64data | ) |

extern

Definition at line 142 of file XrdSecztn.cc.

{
size_t inBytes, outBytes;
const char *dot;
char *key, *outData, inData[1024];
// Skip over the header should it exist (sommetime it does sometimes not)
//
if (!strncmp(b64data, "Bearer%20", 9)) b64data += 9;
// We are only interested in the header which must appear first and be
// separated by a dot from subsequent tokens. If it does not have the
// dot then we assume it's not returnable. Otherwise truncate it at the dot.
//
if (!(dot = index(b64data, '.'))) return false;
// Copy out the token segment we wish to check. The JWT header can never be
// more than 1K long and that's being way generous.
//
inBytes = dot - b64data;
if (inBytes >= (int)sizeof(inData)) return false;
memcpy(inData, b64data, inBytes);
inData[inBytes] = 0;
// Allocate a buffer large enough to hold the result. Get it from the stack.
//
outBytes = DecodeBytesNeeded(inBytes);
outData = (char *)alloca(outBytes);
// If we can't decode what we have then indicate this is not returnable
//
if (DecodeUrl(inData, inBytes, outData, outBytes)) return false;
// The json object must start/end with a brace and must contain the key:value
// of '"typ":"JWT"', other elements may change but not this one.
//
if (outBytes <= 0 || *outData != '{' || outData[outBytes-1] != '}')
return false;
// Search for the key
//
if (!(key = strstr(outData, "\"typ\""))) return false;
// Subsequently there should be a colon or spaces but nothing more
//
key += 5;
while(*key == ' ') key++;
if (*key != ':') return false;
// There may be more spaces but anything else must be the expected value
//
key++;
while(*key == ' ') key++;
return strncmp(key, "\"JWT\"", 5) == 0;
}