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 61 of file XrdSecgsiRtag.hh.

◆ kXRSrtagLen

#define kXRSrtagLen   8

Definition at line 57 of file XrdSecgsiRtag.hh.

◆ kXRSrtagMD

#define kXRSrtagMD   "sha256"

Definition at line 65 of file XrdSecgsiRtag.hh.

◆ kXRSrtagMDMax

#define kXRSrtagMDMax   64

Definition at line 69 of file XrdSecgsiRtag.hh.

Function Documentation

◆ XrdSecgsiRtagDigest()

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

Definition at line 87 of file XrdSecgsiRtag.hh.

89 {
90  // Fill out with the context bound digest of rtag, that is
91  // SHA-256(kXRSrtagCtx || rtag). Return the number of bytes written,
92  // or -1 in case of error.
93 
94  if (!cf || !rtag || len <= 0 || !out) return -1;
95 
96  // The factory returns a valid and initialized digest, or null
98  if (!md) return -1;
99 
100  int lout = -1;
101 
102  if (md->Update(kXRSrtagCtx, (int)strlen(kXRSrtagCtx)) == 0 &&
103  md->Update(rtag, len) == 0 && md->Final() == 0 &&
104  md->Length() > 0 && md->Length() <= outmax) {
105  lout = md->Length();
106  memcpy(out, md->Buffer(), lout);
107  }
108 
109  delete md;
110 
111  return lout;
112 }
#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 72 of file XrdSecgsiRtag.hh.

73 {
74  // Return true if rtag holds a well formed GSI random tag, that is
75  // exactly kXRSrtagLen bytes of 7-bit ASCII. The length is what keeps
76  // the signature safe; the byte range follows the known generators.
77 
78  if (!rtag || len != kXRSrtagLen) return false;
79 
80  for (int i = 0; i < len; i++)
81  if (static_cast<unsigned char>(rtag[i]) > 0x7f) return false;
82 
83  return true;
84 }
#define kXRSrtagLen

References kXRSrtagLen.