CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
cond::auth::Cipher Class Reference

#include <Cipher.h>

Public Member Functions

std::string b64decrypt (const std::string &input)
 
std::string b64encrypt (const std::string &input)
 
 Cipher (const std::string &key)
 
std::string decrypt (const unsigned char *input, size_t inputSize)
 
size_t encrypt (const std::string &input, unsigned char *&output)
 
 ~Cipher ()
 

Private Member Functions

size_t bf_process_alloc (const unsigned char *input, size_t input_size, unsigned char *&output, bool decrypt=false)
 

Private Attributes

BLOWFISH_CTXm_ctx
 

Detailed Description

Definition at line 13 of file Cipher.h.

Constructor & Destructor Documentation

cond::auth::Cipher::Cipher ( const std::string &  key)
explicit

Definition at line 10 of file Cipher.cc.

References Blowfish_Init(), dqmdumpme::k, and m_ctx.

10  : m_ctx(new BLOWFISH_CTX) {
11  char* k = const_cast<char*>(key.c_str());
12  Blowfish_Init(m_ctx, reinterpret_cast<unsigned char*>(k), key.size());
13 }
void Blowfish_Init(BLOWFISH_CTX *ctx, unsigned char *key, int keyLen)
Definition: blowfish.cc:235
BLOWFISH_CTX * m_ctx
Definition: Cipher.h:34
cond::auth::Cipher::~Cipher ( )

Definition at line 15 of file Cipher.cc.

References m_ctx.

15 { delete m_ctx; }
BLOWFISH_CTX * m_ctx
Definition: Cipher.h:34

Member Function Documentation

std::string cond::auth::Cipher::b64decrypt ( const std::string &  input)

Definition at line 122 of file Cipher.cc.

References base64_decode_alloc, decrypt(), input, runTheMatrix::ret, AlCaHLTBitMon_QueryRunRegistry::string, and cond::throwException().

Referenced by cond::CredentialStore::exportAll(), cond::CredentialStore::importForPrincipal(), cond::CredentialStore::listConnections(), cond::CredentialStore::resetAdmin(), cond::CredentialStore::selectForUser(), cond::CredentialStore::setPermission(), cond::CredentialStore::startSession(), cond::updateConnectionData(), cond::CredentialStore::updatePrincipal(), and cond::updatePrincipalData().

122  {
123  if (b64in.empty())
124  return "";
125  char* input = nullptr;
126  size_t inputSize = 0;
127  if (!base64_decode_alloc(b64in.c_str(), b64in.size(), &input, &inputSize)) {
128  throwException("Input provided is not a valid base64 string.", "Cipher::b64decrypt");
129  }
130  std::string ret = decrypt(reinterpret_cast<const unsigned char*>(input), inputSize);
131  free(input);
132  return ret;
133 }
ret
prodAgent to be discontinued
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:18
static std::string const input
Definition: EdmProvDump.cc:48
#define base64_decode_alloc(in, inlen, out, outlen)
Definition: base64.h:54
std::string decrypt(const unsigned char *input, size_t inputSize)
Definition: Cipher.cc:79
std::string cond::auth::Cipher::b64encrypt ( const std::string &  input)

Definition at line 109 of file Cipher.cc.

References base64_encode_alloc(), bf_process_alloc(), MillePedeFileConverter_cfg::out, runTheMatrix::ret, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by cond::setPermissionData(), cond::updateConnectionData(), and cond::updatePrincipalData().

109  {
110  if (input.empty())
111  return "";
112  unsigned char* out = nullptr;
113  size_t outSize = bf_process_alloc(reinterpret_cast<const unsigned char*>(input.c_str()), input.size(), out, false);
114  char* b64out = nullptr;
115  size_t b64size = base64_encode_alloc(reinterpret_cast<const char*>(out), outSize, &b64out);
116  std::string ret(b64out, b64size);
117  free(out);
118  free(b64out);
119  return ret;
120 }
ret
prodAgent to be discontinued
static std::string const input
Definition: EdmProvDump.cc:48
size_t base64_encode_alloc(const char *in, size_t inlen, char **out)
Definition: base64.cc:100
size_t bf_process_alloc(const unsigned char *input, size_t input_size, unsigned char *&output, bool decrypt=false)
Definition: Cipher.cc:17
size_t cond::auth::Cipher::bf_process_alloc ( const unsigned char *  input,
size_t  input_size,
unsigned char *&  output,
bool  decrypt = false 
)
private

Definition at line 17 of file Cipher.cc.

References Blowfish_Decrypt(), Blowfish_Encrypt(), mps_fire::i, dqmiolumiharvest::j, dttmaxenums::L, m_ctx, EgHLTOffHistBins_cfi::nr, and dttmaxenums::R.

Referenced by b64encrypt(), decrypt(), and encrypt().

20  {
21  assert(input_size != 0);
22 
23  uInt32 L, R;
24  unsigned int j = sizeof(uInt32);
25 
26  unsigned int output_size = 0;
27 
28  if (!input_size) {
29  output = nullptr;
30  return 0;
31  }
32 
33  for (unsigned int i = 0; i < input_size; i += (j * 2)) {
34  output_size = i + 2 * j;
35  }
36  output = (unsigned char*)malloc(output_size);
37  memset(output, 0, output_size);
38 
39  for (unsigned int i = 0; i < input_size; i += (j * 2)) {
40  L = R = 0;
41  unsigned int nl = 0;
42  unsigned int nr = 0;
43  if (input_size > i + j) {
44  nl = j;
45  if (input_size > i + 2 * j) {
46  nr = j;
47  } else {
48  nr = input_size - i - j;
49  }
50  } else {
51  nl = input_size - i;
52  nr = 0;
53  }
54  if (nl)
55  memcpy(&L, input + i, nl);
56  if (nr)
57  memcpy(&R, input + i + j, nr);
58  if (!decrypt) {
59  Blowfish_Encrypt(m_ctx, &L, &R);
60  } else {
61  Blowfish_Decrypt(m_ctx, &L, &R);
62  }
63  memcpy(output + i, &L, j);
64  memcpy(output + i + j, &R, j);
65  }
66 
67  return output_size;
68 }
void Blowfish_Encrypt(BLOWFISH_CTX *ctx, uInt32 *xl, uInt32 *xr)
Definition: blowfish.cc:181
void Blowfish_Decrypt(BLOWFISH_CTX *ctx, uInt32 *xl, uInt32 *xr)
Definition: blowfish.cc:207
unsigned int uInt32
Definition: blowfish.h:25
static std::string const input
Definition: EdmProvDump.cc:48
std::string decrypt(const unsigned char *input, size_t inputSize)
Definition: Cipher.cc:79
BLOWFISH_CTX * m_ctx
Definition: Cipher.h:34
std::string cond::auth::Cipher::decrypt ( const unsigned char *  input,
size_t  inputSize 
)

Definition at line 79 of file Cipher.cc.

References bf_process_alloc(), mps_fire::i, MillePedeFileConverter_cfg::out, runTheMatrix::ret, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by b64decrypt(), and cond::auth::DecodingKey::init().

79  {
80  if (!inputSize)
81  return "";
82  unsigned char* out = nullptr;
83  size_t outSize = bf_process_alloc(input, inputSize, out, true);
84  size_t i = 0;
85  for (i = 0; i < outSize; i++) {
86  if (out[i] == 0)
87  break;
88  }
89 
90  char* sout = reinterpret_cast<char*>(out);
91  // the output can still contain one or more \0 chars...
92  //size_t soutSize = strlen( sout );
93  size_t soutSize = 0;
94  for (soutSize = 0; soutSize < outSize; soutSize++)
95  if (out[soutSize] == 0)
96  break;
97 
98  if (soutSize < outSize) {
99  outSize = soutSize;
100  }
101 
102  std::string ret("");
103  if (outSize)
104  ret = std::string(sout, outSize);
105  free(out);
106  return ret;
107 }
ret
prodAgent to be discontinued
static std::string const input
Definition: EdmProvDump.cc:48
size_t bf_process_alloc(const unsigned char *input, size_t input_size, unsigned char *&output, bool decrypt=false)
Definition: Cipher.cc:17
size_t cond::auth::Cipher::encrypt ( const std::string &  input,
unsigned char *&  output 
)

Definition at line 70 of file Cipher.cc.

References bf_process_alloc(), and convertSQLitetoXML_cfg::output.

Referenced by cond::auth::DecodingKey::flush().

70  {
71  if (input.empty()) {
72  output = nullptr;
73  return 0;
74  }
75  return bf_process_alloc(reinterpret_cast<const unsigned char*>(input.c_str()), input.size(), output, false);
76  ;
77 }
static std::string const input
Definition: EdmProvDump.cc:48
size_t bf_process_alloc(const unsigned char *input, size_t input_size, unsigned char *&output, bool decrypt=false)
Definition: Cipher.cc:17

Member Data Documentation

BLOWFISH_CTX* cond::auth::Cipher::m_ctx
private

Definition at line 34 of file Cipher.h.

Referenced by bf_process_alloc(), Cipher(), and ~Cipher().