XRootD
XrdCryptosslRSA Class Reference

#include <XrdCryptosslRSA.hh>

+ Inheritance diagram for XrdCryptosslRSA:
+ Collaboration diagram for XrdCryptosslRSA:

Public Member Functions

 XrdCryptosslRSA (const char *pub, int lpub=0)
 
 XrdCryptosslRSA (const XrdCryptosslRSA &r)
 
 XrdCryptosslRSA (EVP_PKEY *key, bool check=1)
 
 XrdCryptosslRSA (int bits=XrdCryptoMinRSABits, int exp=XrdCryptoDefRSAExp)
 
virtual ~XrdCryptosslRSA ()
 
int DecryptPrivate (const char *in, int lin, char *out, int lout)
 
int DecryptPublic (const char *in, int lin, char *out, int lout)
 
void Dump ()
 
int EncryptPrivate (const char *in, int lin, char *out, int lout)
 
int EncryptPublic (const char *in, int lin, char *out, int lout)
 
int ExportPrivate (char *out, int lout)
 
int ExportPublic (char *out, int lout)
 
int GetOutlen (int lin)
 
int GetPrilen ()
 
int GetPublen ()
 
int ImportPrivate (const char *in, int lin)
 
int ImportPublic (const char *in, int lin)
 
XrdCryptoRSAdata Opaque ()
 
- Public Member Functions inherited from XrdCryptoRSA
 XrdCryptoRSA ()
 
virtual ~XrdCryptoRSA ()
 
int DecryptPrivate (XrdSutBucket &buck)
 
int DecryptPublic (XrdSutBucket &buck)
 
int EncryptPrivate (XrdSutBucket &buck)
 
int EncryptPublic (XrdSutBucket &buck)
 
int ExportPrivate (XrdOucString &exp)
 
int ExportPublic (XrdOucString &exp)
 
bool IsValid ()
 
const char * Status (ERSAStatus t=kInvalid) const
 

Additional Inherited Members

- Public Types inherited from XrdCryptoRSA
enum  ERSAStatus {
  kInvalid = 0 ,
  kPublic = 1 ,
  kComplete = 2
}
 
- Public Attributes inherited from XrdCryptoRSA
ERSAStatus status
 

Detailed Description

Definition at line 46 of file XrdCryptosslRSA.hh.

Constructor & Destructor Documentation

◆ XrdCryptosslRSA() [1/4]

XrdCryptosslRSA::XrdCryptosslRSA ( int  bits = XrdCryptoMinRSABits,
int  exp = XrdCryptoDefRSAExp 
)

Definition at line 87 of file XrdCryptosslRSA.cc.

88 {
89  // Constructor
90  // Generate a RSA asymmetric key pair
91  // Length will be 'bits' bits (min 2048, default 2048), public
92  // exponent `pubex` (default 65537).
93  EPNAME("RSA::XrdCryptosslRSA");
94 
95  publen = -1;
96  prilen = -1;
97 
98  // Minimum is XrdCryptoMinRSABits
99  bits = (bits >= XrdCryptoMinRSABits) ? bits : XrdCryptoDefRSABits;
100 
101  // If pubex is not odd, use default
102  if (!(exp & 1))
103  exp = XrdCryptoDefRSAExp; // 65537 (0x10001)
104 
105  DEBUG("bits: "<<bits<<", exp: "<<exp);
106 
107  // Try Key Generation
108  BIGNUM *e = BN_new();
109  if (!e) {
110  DEBUG("cannot allocate new exponent");
111  return;
112  }
113 
114  BN_set_word(e, exp);
115 
116  EVP_PKEY_CTX *pkctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, 0);
117  EVP_PKEY_keygen_init(pkctx);
118  EVP_PKEY_CTX_set_rsa_keygen_bits(pkctx, bits);
119 #if OPENSSL_VERSION_NUMBER >= 0x30000000L
120  EVP_PKEY_CTX_set1_rsa_keygen_pubexp(pkctx, e);
121  BN_free(e);
122 #else
123  EVP_PKEY_CTX_set_rsa_keygen_pubexp(pkctx, e);
124 #endif
125  EVP_PKEY_keygen(pkctx, &fEVP);
126  EVP_PKEY_CTX_free(pkctx);
127 
128  // Update status flag
129  if (fEVP) {
130  if (XrdCheckRSA(fEVP) == 1) {
131  status = kComplete;
132  DEBUG("basic length: "<<EVP_PKEY_size(fEVP)<<" bytes");
133  } else {
134  DEBUG("WARNING: generated key is invalid");
135  // Generated an invalid key: cleanup
136  EVP_PKEY_free(fEVP);
137  fEVP = 0;
138  }
139  }
140 }
#define DEBUG(x)
Definition: XrdBwmTrace.hh:54
#define EPNAME(x)
Definition: XrdBwmTrace.hh:56
#define XrdCryptoMinRSABits
Definition: XrdCryptoAux.hh:52
#define XrdCryptoDefRSAExp
Definition: XrdCryptoAux.hh:54
#define XrdCryptoDefRSABits
Definition: XrdCryptoAux.hh:53
static int XrdCheckRSA(EVP_PKEY *pkey)
ERSAStatus status
Definition: XrdCryptoRSA.hh:58

References DEBUG, EPNAME, XrdCryptoRSA::kComplete, XrdCryptoRSA::status, XrdCheckRSA(), XrdCryptoDefRSABits, XrdCryptoDefRSAExp, and XrdCryptoMinRSABits.

+ Here is the call graph for this function:

◆ XrdCryptosslRSA() [2/4]

XrdCryptosslRSA::XrdCryptosslRSA ( const char *  pub,
int  lpub = 0 
)

Definition at line 143 of file XrdCryptosslRSA.cc.

144 {
145  // Constructor
146  // Allocate a RSA key pair and fill the public part importing
147  // from string representation (pub) to internal representation.
148  // If lpub>0 use the first lpub bytes; otherwise use strlen(pub)
149  // bytes.
150 
151  fEVP = 0;
152  publen = -1;
153  prilen = -1;
154 
155  // Import key
156  ImportPublic(pub,lpub);
157 }
int ImportPublic(const char *in, int lin)

References ImportPublic().

+ Here is the call graph for this function:

◆ XrdCryptosslRSA() [3/4]

XrdCryptosslRSA::XrdCryptosslRSA ( EVP_PKEY *  key,
bool  check = 1 
)

Definition at line 160 of file XrdCryptosslRSA.cc.

161 {
162  // Constructor to import existing key
163  EPNAME("RSA::XrdCryptosslRSA_key");
164 
165  fEVP = 0;
166  publen = -1;
167  prilen = -1;
168 
169  // Create container, first
170  if (!key) {
171  DEBUG("no input key");
172  return;
173  }
174 
175  if (check) {
176  // Check consistency
177  if (XrdCheckRSA(key) == 1) {
178  fEVP = key;
179  // Update status
180  status = kComplete;
181  } else {
182  DEBUG("key contains inconsistent information");
183  }
184  } else {
185  // Accept in any case (for incomplete keys)
186  fEVP = key;
187  // Update status
188  status = kPublic;
189  }
190 }

References DEBUG, EPNAME, XrdCryptoRSA::kComplete, XrdCryptoRSA::kPublic, XrdCryptoRSA::status, and XrdCheckRSA().

+ Here is the call graph for this function:

◆ XrdCryptosslRSA() [4/4]

XrdCryptosslRSA::XrdCryptosslRSA ( const XrdCryptosslRSA r)

Definition at line 194 of file XrdCryptosslRSA.cc.

194  : XrdCryptoRSA()
195 {
196  // Copy Constructor
197  EPNAME("RSA::XrdCryptosslRSA_copy");
198 
199  fEVP = 0;
200  publen = -1;
201  prilen = -1;
202 
203  if (!r.fEVP) {
204  DEBUG("input key is empty");
205  return;
206  }
207 
208  // If the given key is set, copy it via a bio
209 #if OPENSSL_VERSION_NUMBER >= 0x30000000L
210  BIGNUM *d = BN_new();
211  bool publiconly =
212  (EVP_PKEY_get_bn_param(r.fEVP, OSSL_PKEY_PARAM_RSA_D, &d) != 1);
213  BN_free(d);
214 #else
215  const BIGNUM *d = 0;
216  RSA_get0_key(EVP_PKEY_get0_RSA(r.fEVP), 0, 0, &d);
217  bool publiconly = (d == 0);
218 #endif
219  //
220  // Bio for exporting the pub key
221  BIO *bcpy = BIO_new(BIO_s_mem());
222  if (bcpy) {
223  bool ok;
224  if (publiconly) {
225  // Write kref public key to BIO
226  ok = (PEM_write_bio_PUBKEY(bcpy, r.fEVP) != 0);
227  } else {
228  // Write kref private key to BIO
229  ok = (PEM_write_bio_PrivateKey(bcpy,r.fEVP,0,0,0,0,0) != 0);
230  }
231  if (ok) {
232  if (publiconly) {
233  // Read public key from BIO
234  if ((fEVP = PEM_read_bio_PUBKEY(bcpy, 0, 0, 0))) {
235  status = kPublic;
236  }
237  } else {
238  if ((fEVP = PEM_read_bio_PrivateKey(bcpy,0,0,0))) {
239  // Check consistency only if original was not marked complete
240  if (r.status == kComplete || XrdCheckRSA(fEVP) == 1) {
241  // Update status
242  status = kComplete;
243  }
244  }
245  }
246  }
247  // Cleanup bio
248  BIO_free(bcpy);
249  }
250 }
static void RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
static RSA * EVP_PKEY_get0_RSA(EVP_PKEY *pkey)

References DEBUG, EPNAME, EVP_PKEY_get0_RSA(), XrdCryptoRSA::kComplete, XrdCryptoRSA::kPublic, RSA_get0_key(), XrdCryptoRSA::status, and XrdCheckRSA().

+ Here is the call graph for this function:

◆ ~XrdCryptosslRSA()

XrdCryptosslRSA::~XrdCryptosslRSA ( )
virtual

Definition at line 253 of file XrdCryptosslRSA.cc.

254 {
255  // Destructor
256  // Destroy the RSA asymmetric key pair
257 
258  if (fEVP)
259  EVP_PKEY_free(fEVP);
260  fEVP = 0;
261 }

Member Function Documentation

◆ DecryptPrivate()

int XrdCryptosslRSA::DecryptPrivate ( const char *  in,
int  lin,
char *  out,
int  lout 
)
virtual

Reimplemented from XrdCryptoRSA.

Definition at line 607 of file XrdCryptosslRSA.cc.

608 {
609  // Decrypt lin bytes at 'in' using the internal private key
610  // The output buffer 'out' is allocated by the caller for max lout bytes.
611  // The number of meaningful bytes in out is returned in case of success
612  // (never larger that loutmax); -1 in case of error.
613  EPNAME("RSA::DecryptPrivate");
614 
615  // Make sure we got something to decrypt
616  if (!in || lin <= 0) {
617  DEBUG("input buffer undefined");
618  return -1;
619  }
620 
621  // Make sure we got a buffer where to write
622  if (!out || loutmax <= 0) {
623  DEBUG("output buffer undefined");
624  return -1;
625  }
626 
627  size_t lout = 0;
628  size_t len = lin;
629  size_t lcmax = EVP_PKEY_size(fEVP);
630  int kk = 0;
631  int ke = 0;
632 
633  //
634  // Private decoding ...
635  EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(fEVP, 0);
636  EVP_PKEY_decrypt_init(ctx);
637  EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING);
638  while (len > 0 && ke <= int(loutmax - lout)) {
639  lout = loutmax - ke;
640  if (EVP_PKEY_decrypt(ctx, (unsigned char *)&out[ke], &lout,
641  (unsigned char *)&in[kk], lcmax) <= 0) {
642  EVP_PKEY_CTX_free(ctx);
643  char serr[120];
644  ERR_error_string(ERR_get_error(), serr);
645  DEBUG("error: " <<serr);
646  return -1;
647  }
648  kk += lcmax;
649  len -= lcmax;
650  ke += lout;
651  }
652  EVP_PKEY_CTX_free(ctx);
653  if (len > 0 && ke > int(loutmax - lout))
654  PRINT("buffer truncated");
655  lout = ke;
656 
657  return lout;
658 }
#define PRINT(y)

References DEBUG, EPNAME, and PRINT.

◆ DecryptPublic()

int XrdCryptosslRSA::DecryptPublic ( const char *  in,
int  lin,
char *  out,
int  lout 
)
virtual

Reimplemented from XrdCryptoRSA.

Definition at line 661 of file XrdCryptosslRSA.cc.

662 {
663  // Decrypt lin bytes at 'in' using the internal public key
664  // The output buffer 'out' is allocated by the caller for max lout bytes.
665  // The number of meaningful bytes in out is returned in case of success
666  // (never larger that loutmax); -1 in case of error.
667  EPNAME("RSA::DecryptPublic");
668 
669  // Make sure we got something to decrypt
670  if (!in || lin <= 0) {
671  DEBUG("input buffer undefined");
672  return -1;
673  }
674 
675  // Make sure we got a buffer where to write
676  if (!out || loutmax <= 0) {
677  DEBUG("output buffer undefined");
678  return -1;
679  }
680 
681  size_t lout = 0;
682  size_t len = lin;
683  size_t lcmax = EVP_PKEY_size(fEVP);
684  int kk = 0;
685  int ke = 0;
686 
687  //
688  // Private decoding ...
689  EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(fEVP, 0);
690  EVP_PKEY_verify_recover_init(ctx);
691  EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING);
692  while (len > 0 && ke <= int(loutmax - lout)) {
693  lout = loutmax - ke;
694  if (EVP_PKEY_verify_recover(ctx, (unsigned char *)&out[ke], &lout,
695  (unsigned char *)&in[kk], lcmax) <= 0) {
696  EVP_PKEY_CTX_free(ctx);
697  char serr[120];
698  ERR_error_string(ERR_get_error(), serr);
699  PRINT("error: " <<serr);
700  return -1;
701  }
702  kk += lcmax;
703  len -= lcmax;
704  ke += lout;
705  }
706  EVP_PKEY_CTX_free(ctx);
707  if (len > 0 && ke > int(loutmax - lout))
708  PRINT("buffer truncated");
709  lout = ke;
710 
711  return lout;
712 }

References DEBUG, EPNAME, and PRINT.

◆ Dump()

void XrdCryptosslRSA::Dump ( )
virtual

Reimplemented from XrdCryptoRSA.

Definition at line 349 of file XrdCryptosslRSA.cc.

350 {
351  // Dump some info about the key
352  EPNAME("RSA::Dump");
353 
354  DEBUG("---------------------------------------");
355  DEBUG("address: "<<this);
356  if (IsValid()) {
357  char *btmp = new char[GetPublen()+1];
358  if (btmp) {
359  ExportPublic(btmp,GetPublen()+1);
360  DEBUG("export pub key:"<<std::endl<<btmp);
361  delete[] btmp;
362  } else {
363  DEBUG("cannot allocate memory for public key");
364  }
365  } else {
366  DEBUG("key is invalid");
367  }
368  DEBUG("---------------------------------------");
369 }
bool IsValid()
Definition: XrdCryptoRSA.hh:69
int ExportPublic(char *out, int lout)

References DEBUG, EPNAME, ExportPublic(), GetPublen(), and XrdCryptoRSA::IsValid().

+ Here is the call graph for this function:

◆ EncryptPrivate()

int XrdCryptosslRSA::EncryptPrivate ( const char *  in,
int  lin,
char *  out,
int  lout 
)
virtual

Reimplemented from XrdCryptoRSA.

Definition at line 497 of file XrdCryptosslRSA.cc.

498 {
499  // Encrypt lin bytes at 'in' using the internal private key.
500  // The output buffer 'out' is allocated by the caller for max lout bytes.
501  // The number of meaningful bytes in out is returned in case of success
502  // (never larger that loutmax); -1 in case of error.
503  EPNAME("RSA::EncryptPrivate");
504 
505  // Make sure we got something to encrypt
506  if (!in || lin <= 0) {
507  DEBUG("input buffer undefined");
508  return -1;
509  }
510 
511  // Make sure we got a buffer where to write
512  if (!out || loutmax <= 0) {
513  DEBUG("output buffer undefined");
514  return -1;
515  }
516 
517  //
518  // Private encoding ...
519  size_t lcmax = EVP_PKEY_size(fEVP) - 11; // Magic number (= 2*sha1_outlen + 2)
520  size_t lout = 0;
521  size_t len = lin;
522  int kk = 0;
523  int ke = 0;
524 
525  EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(fEVP, 0);
526  EVP_PKEY_sign_init(ctx);
527  EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING);
528  while (len > 0 && ke <= int(loutmax - lout)) {
529  size_t lc = (len > lcmax) ? lcmax : len;
530  lout = loutmax - ke;
531  if (EVP_PKEY_sign(ctx, (unsigned char *)&out[ke], &lout,
532  (unsigned char *)&in[kk], lc) <= 0) {
533  EVP_PKEY_CTX_free(ctx);
534  char serr[120];
535  ERR_error_string(ERR_get_error(), serr);
536  DEBUG("error: " <<serr);
537  return -1;
538  }
539  kk += lc;
540  ke += lout;
541  len -= lc;
542  }
543  EVP_PKEY_CTX_free(ctx);
544  if (len > 0 && ke > int(loutmax - lout))
545  DEBUG("buffer truncated");
546  lout = ke;
547 
548  return lout;
549 }

References DEBUG, and EPNAME.

◆ EncryptPublic()

int XrdCryptosslRSA::EncryptPublic ( const char *  in,
int  lin,
char *  out,
int  lout 
)
virtual

Reimplemented from XrdCryptoRSA.

Definition at line 552 of file XrdCryptosslRSA.cc.

553 {
554  // Encrypt lin bytes at 'in' using the internal public key.
555  // The output buffer 'out' is allocated by the caller for max lout bytes.
556  // The number of meaningful bytes in out is returned in case of success
557  // (never larger that loutmax); -1 in case of error.
558  EPNAME("RSA::EncryptPublic");
559 
560  // Make sure we got something to encrypt
561  if (!in || lin <= 0) {
562  DEBUG("input buffer undefined");
563  return -1;
564  }
565 
566  // Make sure we got a buffer where to write
567  if (!out || loutmax <= 0) {
568  DEBUG("output buffer undefined");
569  return -1;
570  }
571 
572  //
573  // Public encoding ...
574  size_t lcmax = EVP_PKEY_size(fEVP) - 42; // Magic number (= 2*sha1_outlen + 2)
575  size_t lout = 0;
576  size_t len = lin;
577  int kk = 0;
578  int ke = 0;
579 
580  EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(fEVP, 0);
581  EVP_PKEY_encrypt_init(ctx);
582  EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING);
583  while (len > 0 && ke <= int(loutmax - lout)) {
584  size_t lc = (len > lcmax) ? lcmax : len;
585  lout = loutmax - ke;
586  if (EVP_PKEY_encrypt(ctx, (unsigned char *)&out[ke], &lout,
587  (unsigned char *)&in[kk], lc) <= 0) {
588  EVP_PKEY_CTX_free(ctx);
589  char serr[120];
590  ERR_error_string(ERR_get_error(), serr);
591  DEBUG("error: " <<serr);
592  return -1;
593  }
594  kk += lc;
595  ke += lout;
596  len -= lc;
597  }
598  EVP_PKEY_CTX_free(ctx);
599  if (len > 0 && ke > int(loutmax - lout))
600  DEBUG("buffer truncated");
601  lout = ke;
602 
603  return lout;
604 }

References DEBUG, and EPNAME.

◆ ExportPrivate()

int XrdCryptosslRSA::ExportPrivate ( char *  out,
int  lout 
)
virtual

Reimplemented from XrdCryptoRSA.

Definition at line 452 of file XrdCryptosslRSA.cc.

453 {
454  // Export the private key into buffer out. The length of the buffer should be
455  // at least GetPrilen()+1 bytes. The buffer out must be passed-by and it
456  // responsability-of the caller.
457  // Return 0 in case of success, -1 in case of failure
458  EPNAME("RSA::ExportPrivate");
459 
460  // Make sure we have a valid key
461  if (!IsValid()) {
462  DEBUG("key not valid");
463  return -1;
464  }
465 
466  // Check output buffer
467  if (!out) {
468  DEBUG("output buffer undefined!");
469  return -1;
470  }
471 
472  // Bio for exporting the pub key
473  BIO *bkey = BIO_new(BIO_s_mem());
474 
475  // Write public key to BIO
476  PEM_write_bio_PrivateKey(bkey,fEVP,0,0,0,0,0);
477 
478  // data length
479  char *cbio = 0;
480  int lbio = (int) BIO_get_mem_data(bkey, &cbio);
481  if (lbio <= 0 || !cbio) {
482  DEBUG("problems attaching to BIO content");
483  return -1;
484  }
485 
486  // Read key from BIO to buf
487  memcpy(out, cbio, lbio);
488  // Null terminate
489  out[lbio] = 0;
490  DEBUG("("<<lbio<<" bytes) "<< std::endl <<out);
491  BIO_free(bkey);
492 
493  return 0;
494 }

References DEBUG, EPNAME, and XrdCryptoRSA::IsValid().

+ Here is the call graph for this function:

◆ ExportPublic()

int XrdCryptosslRSA::ExportPublic ( char *  out,
int  lout 
)
virtual

Reimplemented from XrdCryptoRSA.

Definition at line 389 of file XrdCryptosslRSA.cc.

390 {
391  // Export the public key into buffer out. The length of the buffer should be
392  // at least GetPublen()+1 bytes. The buffer out must be passed-by and it
393  // responsability-of the caller.
394  // Return 0 in case of success, -1 in case of failure
395  EPNAME("RSA::ExportPublic");
396 
397  // Make sure we have a valid key
398  if (!IsValid()) {
399  DEBUG("key not valid");
400  return -1;
401  }
402 
403  // Check output buffer
404  if (!out) {
405  DEBUG("output buffer undefined!");
406  return -1;
407  }
408 
409  // Bio for exporting the pub key
410  BIO *bkey = BIO_new(BIO_s_mem());
411 
412  // Write public key to BIO
413  PEM_write_bio_PUBKEY(bkey,fEVP);
414 
415  // data length
416  char *cbio = 0;
417  int lbio = (int) BIO_get_mem_data(bkey, &cbio);
418  if (lbio <= 0 || !cbio) {
419  DEBUG("problems attaching to BIO content");
420  return -1;
421  }
422 
423  // Read key from BIO to buf
424  memcpy(out, cbio, lbio);
425  // Null terminate
426  out[lbio] = 0;
427  DEBUG("("<<lbio<<" bytes) "<< std::endl <<out);
428  BIO_free(bkey);
429 
430  return 0;
431 }

References DEBUG, EPNAME, and XrdCryptoRSA::IsValid().

Referenced by Dump().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetOutlen()

int XrdCryptosslRSA::GetOutlen ( int  lin)
virtual

Reimplemented from XrdCryptoRSA.

Definition at line 264 of file XrdCryptosslRSA.cc.

265 {
266  // Get minimal length of output buffer
267 
268  int lcmax = EVP_PKEY_size(fEVP) - 42;
269 
270  return ((lin / lcmax) + 1) * EVP_PKEY_size(fEVP);
271 }

◆ GetPrilen()

int XrdCryptosslRSA::GetPrilen ( )
virtual

Reimplemented from XrdCryptoRSA.

Definition at line 434 of file XrdCryptosslRSA.cc.

435 {
436  // Minimum length of export format of private key
437 
438  if (prilen < 0) {
439  // Bio for exporting the private key
440  BIO *bkey = BIO_new(BIO_s_mem());
441  // Write public key to BIO
442  PEM_write_bio_PrivateKey(bkey,fEVP,0,0,0,0,0);
443  // data length
444  char *cbio = 0;
445  prilen = (int) BIO_get_mem_data(bkey, &cbio);
446  BIO_free(bkey);
447  }
448  return prilen;
449 }

◆ GetPublen()

int XrdCryptosslRSA::GetPublen ( )
virtual

Reimplemented from XrdCryptoRSA.

Definition at line 372 of file XrdCryptosslRSA.cc.

373 {
374  // Minimum length of export format of public key
375 
376  if (publen < 0) {
377  // Bio for exporting the pub key
378  BIO *bkey = BIO_new(BIO_s_mem());
379  // Write public key to BIO
380  PEM_write_bio_PUBKEY(bkey,fEVP);
381  // data length
382  char *cbio = 0;
383  publen = (int) BIO_get_mem_data(bkey, &cbio);
384  BIO_free(bkey);
385  }
386  return publen;
387 }

Referenced by Dump().

+ Here is the caller graph for this function:

◆ ImportPrivate()

int XrdCryptosslRSA::ImportPrivate ( const char *  in,
int  lin 
)
virtual

Reimplemented from XrdCryptoRSA.

Definition at line 314 of file XrdCryptosslRSA.cc.

315 {
316  // Import a private key
317  // Fill the private part importing from string representation (pub) to
318  // internal representation.
319  // If lpub>0 use the first lpub bytes; otherwise use strlen(pub)
320  // bytes.
321  // Return 0 in case of success, -1 in case of failure
322 
323  if (!fEVP)
324  return -1;
325 
326  int rc = -1;
327  prilen = -1;
328 
329  // Bio for exporting the pub key
330  BIO *bpri = BIO_new(BIO_s_mem());
331 
332  // Check length
333  lpri = (lpri <= 0) ? strlen(pri) : lpri;
334 
335  // Write key from private export to BIO
336  BIO_write(bpri,(void *)pri,lpri);
337 
338  // Read private key from BIO
339  if (PEM_read_bio_PrivateKey(bpri, &fEVP, 0, 0)) {
340  // Update status
341  status = kComplete;
342  rc = 0;
343  }
344  BIO_free(bpri);
345  return rc;
346 }

References XrdCryptoRSA::kComplete, and XrdCryptoRSA::status.

◆ ImportPublic()

int XrdCryptosslRSA::ImportPublic ( const char *  in,
int  lin 
)
virtual

Reimplemented from XrdCryptoRSA.

Definition at line 274 of file XrdCryptosslRSA.cc.

275 {
276  // Import a public key
277  // Allocate a RSA key pair and fill the public part importing
278  // from string representation (pub) to internal representation.
279  // If lpub>0 use the first lpub bytes; otherwise use strlen(pub)
280  // bytes.
281  // Return 0 in case of success, -1 in case of failure
282 
283  int rc = -1;
284  if (fEVP)
285  EVP_PKEY_free(fEVP);
286  fEVP = 0;
287  publen = -1;
288  prilen = -1;
289 
290  // Temporary key
291  EVP_PKEY *keytmp = 0;
292 
293  // Bio for exporting the pub key
294  BIO *bpub = BIO_new(BIO_s_mem());
295 
296  // Check length
297  lpub = (lpub <= 0) ? strlen(pub) : lpub;
298 
299  // Write key from pubexport to BIO
300  BIO_write(bpub,(void *)pub,lpub);
301 
302  // Read pub key from BIO
303  if ((keytmp = PEM_read_bio_PUBKEY(bpub, 0, 0, 0))) {
304  fEVP = keytmp;
305  // Update status
306  status = kPublic;
307  rc = 0;
308  }
309  BIO_free(bpub);
310  return rc;
311 }

References XrdCryptoRSA::kPublic, and XrdCryptoRSA::status.

Referenced by XrdCryptosslRSA().

+ Here is the caller graph for this function:

◆ Opaque()

XrdCryptoRSAdata XrdCryptosslRSA::Opaque ( )
inlinevirtual

Reimplemented from XrdCryptoRSA.

Definition at line 61 of file XrdCryptosslRSA.hh.

61 { return fEVP; }

The documentation for this class was generated from the following files: