XRootD
XrdSecgsiRtag.hh File Reference
#include <cstring>
#include "XrdCrypto/XrdCryptoFactory.hh"
#include "XrdCrypto/XrdCryptoMsgDigest.hh"
+ Include dependency graph for XrdSecgsiRtag.hh:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define kXRSrtagCtx   "XRD-GSI-RTAG-v1"
 
#define kXRSrtagLen   8
 
#define kXRSrtagMD   "sha256"
 
#define kXRSrtagMDMax   64
 

Functions

int XrdSecgsiRtagDigest (XrdCryptoFactory *cf, const char *rtag, int len, char *out, int outmax)
 
bool XrdSecgsiRtagIsValid (const char *rtag, int len)
 

Macro Definition Documentation

◆ kXRSrtagCtx

#define kXRSrtagCtx   "XRD-GSI-RTAG-v1"

Definition at line 59 of file XrdSecgsiRtag.hh.

◆ kXRSrtagLen

#define kXRSrtagLen   8

Definition at line 55 of file XrdSecgsiRtag.hh.

◆ kXRSrtagMD

#define kXRSrtagMD   "sha256"

Definition at line 63 of file XrdSecgsiRtag.hh.

◆ kXRSrtagMDMax

#define kXRSrtagMDMax   64

Definition at line 67 of file XrdSecgsiRtag.hh.

Function Documentation

◆ XrdSecgsiRtagDigest()

int XrdSecgsiRtagDigest ( XrdCryptoFactory *  cf,
const char *  rtag,
int  len,
char *  out,
int  outmax 
)
inline

Definition at line 88 of file XrdSecgsiRtag.hh.

90 {
91  // Fill out with the context bound digest of rtag, that is
92  // SHA-256(kXRSrtagCtx || rtag). Return the number of bytes written,
93  // or -1 in case of error.
94 
95  if (!cf || !rtag || len <= 0 || !out) return -1;
96 
97  // The factory returns a valid and initialized digest, or null
99  if (!md) return -1;
100 
101  int lout = -1;
102 
103  if (md->Update(kXRSrtagCtx, (int)strlen(kXRSrtagCtx)) == 0 &&
104  md->Update(rtag, len) == 0 && md->Final() == 0 &&
105  md->Length() > 0 && md->Length() <= outmax) {
106  lout = md->Length();
107  memcpy(out, md->Buffer(), lout);
108  }
109 
110  delete md;
111 
112  return lout;
113 }
#define kXRSrtagMD
#define kXRSrtagCtx
virtual int Length() const
virtual char * Buffer() const
virtual XrdCryptoMsgDigest * MsgDigest(const char *dgst)
virtual int Update(const char *b, int l)

References XrdCryptoBasic::Buffer(), XrdCryptoMsgDigest::Final(), kXRSrtagCtx, kXRSrtagMD, XrdCryptoBasic::Length(), XrdCryptoFactory::MsgDigest(), and XrdCryptoMsgDigest::Update().

+ Here is the call graph for this function:

◆ XrdSecgsiRtagIsValid()

bool XrdSecgsiRtagIsValid ( const char *  rtag,
int  len 
)
inline

Definition at line 70 of file XrdSecgsiRtag.hh.

71 {
72  // Return true if rtag holds a well formed GSI random tag, that is
73  // exactly kXRSrtagLen characters in the set [a-zA-Z0-9./].
74 
75  if (!rtag || len != kXRSrtagLen) return false;
76 
77  for (int i = 0; i < len; i++) {
78  const char c = rtag[i];
79  if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
80  (c >= '0' && c <= '9') || c == '.' || c == '/') continue;
81  return false;
82  }
83 
84  return true;
85 }
#define kXRSrtagLen

References kXRSrtagLen.