Utility functions for XrdHTTP.
More...
#include <cstring>
#include <openssl/hmac.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <pthread.h>
#include <memory>
#include <vector>
#include <algorithm>
#include "XProtocol/XPtypes.hh"
#include "XrdSec/XrdSecEntity.hh"
#include "sys/param.h"
#include "XrdOuc/XrdOucString.hh"
Go to the source code of this file.
|
void | calcHashes (char *hash, const char *fn, kXR_int16 request, XrdSecEntity *secent, time_t tim, const char *key) |
|
static int | char_to_int (int c) |
|
int | compareHash (const char *h1, const char *h2) |
|
char * | escapeXML (const char *str) |
|
bool | Fromhexdigest (const unsigned char *input, int length, unsigned char *out) |
|
static void | HMAC_CTX_free (HMAC_CTX *ctx) |
|
static HMAC_CTX * | HMAC_CTX_new () |
|
std::string | itos (long i) |
|
char * | mystrchrnul (const char *s, int c) |
|
int | parseURL (char *url, char *host, int &port, char **path) |
|
char * | quote (const char *str) |
|
void | Tobase64 (const unsigned char *input, int length, char *out) |
|
char * | unquote (char *str) |
|
Utility functions for XrdHTTP.
- Author
- Fabrizio Furano
- Date
- April 2013
Definition in file XrdHttpUtils.cc.
◆ calcHashes()
void calcHashes |
( |
char * |
hash, |
|
|
const char * |
fn, |
|
|
kXR_int16 |
request, |
|
|
XrdSecEntity * |
secent, |
|
|
time_t |
tim, |
|
|
const char * |
key |
|
) |
| |
Definition at line 219 of file XrdHttpUtils.cc.
233 #if OPENSSL_VERSION_NUMBER >= 0x30000000L
241 unsigned char mdbuf[EVP_MAX_MD_SIZE];
255 if (!fn || !secent) {
259 #if OPENSSL_VERSION_NUMBER >= 0x30000000L
261 mac = EVP_MAC_fetch(0,
"sha256", 0);
262 ctx = EVP_MAC_CTX_new(mac);
269 EVP_MAC_init(ctx, (
const unsigned char *) key, strlen(key), 0);
273 EVP_MAC_update(ctx, (
const unsigned char *) fn,
276 EVP_MAC_update(ctx, (
const unsigned char *) &request,
280 EVP_MAC_update(ctx, (
const unsigned char *) secent->
name,
281 strlen(secent->
name) + 1);
284 EVP_MAC_update(ctx, (
const unsigned char *) secent->
vorg,
285 strlen(secent->
vorg) + 1);
288 EVP_MAC_update(ctx, (
const unsigned char *) secent->
host,
289 strlen(secent->
host) + 1);
292 EVP_MAC_update(ctx, (
const unsigned char *) secent->
moninfo,
295 localtime_r(&tim, &tms);
296 strftime(buf,
sizeof (buf),
"%s", &tms);
297 EVP_MAC_update(ctx, (
const unsigned char *) buf,
300 EVP_MAC_final(ctx, mdbuf, &len, EVP_MAX_MD_SIZE);
302 EVP_MAC_CTX_free(ctx);
315 HMAC_Init_ex(ctx, (
const void *) key, strlen(key), EVP_sha256(), 0);
319 HMAC_Update(ctx, (
const unsigned char *) fn,
322 HMAC_Update(ctx, (
const unsigned char *) &request,
326 HMAC_Update(ctx, (
const unsigned char *) secent->
name,
327 strlen(secent->
name) + 1);
330 HMAC_Update(ctx, (
const unsigned char *) secent->
vorg,
331 strlen(secent->
vorg) + 1);
334 HMAC_Update(ctx, (
const unsigned char *) secent->
host,
335 strlen(secent->
host) + 1);
338 HMAC_Update(ctx, (
const unsigned char *) secent->
moninfo,
341 localtime_r(&tim, &tms);
342 strftime(buf,
sizeof (buf),
"%s", &tms);
343 HMAC_Update(ctx, (
const unsigned char *) buf,
346 HMAC_Final(ctx, mdbuf, &len);
void Tobase64(const unsigned char *input, int length, char *out)
static void HMAC_CTX_free(HMAC_CTX *ctx)
static HMAC_CTX * HMAC_CTX_new()
char * vorg
Entity's virtual organization(s)
char * name
Entity's name.
char * moninfo
Information for monitoring.
char * host
Entity's host name dnr dependent.
References HMAC_CTX_free(), HMAC_CTX_new(), XrdSecEntity::host, XrdSecEntity::moninfo, XrdSecEntity::name, Tobase64(), and XrdSecEntity::vorg.
Referenced by XrdHttpProtocol::Process(), and XrdHttpReq::Redir().
◆ char_to_int()
static int char_to_int |
( |
int |
c | ) |
|
|
static |
◆ compareHash()
int compareHash |
( |
const char * |
h1, |
|
|
const char * |
h2 |
|
) |
| |
◆ escapeXML()
char* escapeXML |
( |
const char * |
str | ) |
|
Definition at line 458 of file XrdHttpUtils.cc.
460 char *r = (
char *) malloc(l*6 + 1);
464 for (i = 0; i < l; i++) {
469 strcpy(r + j,
""");
473 strcpy(r + j,
"&");
477 strcpy(r + j,
"<");
481 strcpy(r + j,
">");
485 strcpy(r + j,
"'");
Referenced by XrdHttpReq::Error().
◆ Fromhexdigest()
bool Fromhexdigest |
( |
const unsigned char * |
input, |
|
|
int |
length, |
|
|
unsigned char * |
out |
|
) |
| |
Definition at line 169 of file XrdHttpUtils.cc.
170 for (
int idx=0; idx < length; idx += 2) {
173 if ((upper < 0) || (lower < 0)) {
176 out[idx/2] = (upper << 4) + lower;
static int char_to_int(int c)
References char_to_int().
◆ HMAC_CTX_free()
static void HMAC_CTX_free |
( |
HMAC_CTX * |
ctx | ) |
|
|
static |
◆ HMAC_CTX_new()
static HMAC_CTX* HMAC_CTX_new |
( |
| ) |
|
|
static |
Definition at line 59 of file XrdHttpUtils.cc.
60 HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_malloc(
sizeof(HMAC_CTX));
61 if (ctx) HMAC_CTX_init(ctx);
Referenced by calcHashes().
◆ itos()
std::string itos |
( |
long |
i | ) |
|
◆ mystrchrnul()
char* mystrchrnul |
( |
const char * |
s, |
|
|
int |
c |
|
) |
| |
Definition at line 193 of file XrdHttpUtils.cc.
194 char *ptr = strchr((
char *)s, c);
197 return strchr((
char *)s,
'\0');
◆ parseURL()
int parseURL |
( |
char * |
url, |
|
|
char * |
host, |
|
|
int & |
port, |
|
|
char ** |
path |
|
) |
| |
Definition at line 77 of file XrdHttpUtils.cc.
83 char *p = strstr(url,
"//");
90 char *p2 = strchr(p,
'/');
96 int l = std::min((
int)(p2 - p), (
int)
sizeof (buf));
101 p = strchr(buf,
':');
103 int l = std::min((
int)(p - buf), (
int)
sizeof (buf));
104 strncpy(host, buf, l);
Referenced by XrdHttpReq::ProcessHTTPReq().
◆ quote()
char* quote |
( |
const char * |
str | ) |
|
Definition at line 399 of file XrdHttpUtils.cc.
401 char *r = (
char *) malloc(l*3 + 1);
405 for (i = 0; i < l; i++) {
410 strcpy(r + j,
"%20");
414 strcpy(r + j,
"%5B");
418 strcpy(r + j,
"%5D");
422 strcpy(r + j,
"%3A");
430 strcpy(r + j,
"%23");
434 strcpy(r + j,
"%0A");
438 strcpy(r + j,
"%0D");
442 strcpy(r + j,
"%3D");
Referenced by encode_raw().
◆ Tobase64()
void Tobase64 |
( |
const unsigned char * |
input, |
|
|
int |
length, |
|
|
char * |
out |
|
) |
| |
Definition at line 121 of file XrdHttpUtils.cc.
129 b64 = BIO_new(BIO_f_base64());
131 bmem = BIO_new(BIO_s_mem());
133 BIO_write(b64, input, length);
135 if (BIO_flush(b64) <= 0) {
140 BIO_get_mem_ptr(b64, &bptr);
143 memcpy(out, bptr->data, bptr->length);
144 out[bptr->length] =
'\0';
void BIO_set_flags(BIO *bio, int flags)
References BIO_set_flags().
Referenced by calcHashes().
◆ unquote()
char* unquote |
( |
char * |
str | ) |
|
Definition at line 370 of file XrdHttpUtils.cc.
372 char *r = (
char *) malloc(l + 1);
376 for (i = 0; i < l; i++) {
379 char savec = str[i + 3];
382 r[j] = strtol(str + i + 1, 0, 16);
386 }
else r[j] = str[i];
Referenced by decode_raw().