Skip to content

Commit

Permalink
cryptossl/rsa: fix signatures of Export methods
Browse files Browse the repository at this point in the history
This is a partial revert back of commit
    0421bc6
fixing the problem in a different way, without breaking interfaces.

Should restore proper behaviour when XrdSecGSIDELEGPROXY is set to 2.
  • Loading branch information
gganis committed May 16, 2018
1 parent 0601508 commit e781366
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
40 changes: 18 additions & 22 deletions src/XrdCrypto/XrdCryptosslRSA.cc
Expand Up @@ -361,11 +361,11 @@ int XrdCryptosslRSA::GetPublen()
return publen;
}
//_____________________________________________________________________________
int XrdCryptosslRSA::ExportPublic(char *&out, int)
int XrdCryptosslRSA::ExportPublic(char *out, int)
{
// Export the public key into buffer out. The length of the buffer should be
// at least GetPublen()+1 bytes. If out=0 the buffer is m-allocated internally
// and should be freed by the caller.
// at least GetPublen()+1 bytes. The buffer out must be passed-by and it
// responsability-of the caller.
// Return 0 in case of success, -1 in case of failure
EPNAME("RSA::ExportPublic");

Expand All @@ -375,6 +375,12 @@ int XrdCryptosslRSA::ExportPublic(char *&out, int)
return -1;
}

// Check output buffer
if (!out) {
DEBUG("output buffer undefined!");
return -1;
}

// Bio for exporting the pub key
BIO *bkey = BIO_new(BIO_s_mem());

Expand All @@ -389,14 +395,6 @@ int XrdCryptosslRSA::ExportPublic(char *&out, int)
return -1;
}

// Check output buffer
if (!out) {
out = (char *) malloc(lbio+1);
if (!out) {
DEBUG("problems allocating output buffer");
return -1;
}
}
// Read key from BIO to buf
memcpy(out, cbio, lbio);
// Null terminate
Expand Down Expand Up @@ -426,11 +424,11 @@ int XrdCryptosslRSA::GetPrilen()
}

//_____________________________________________________________________________
int XrdCryptosslRSA::ExportPrivate(char *&out, int)
int XrdCryptosslRSA::ExportPrivate(char *out, int)
{
// Export the private key into buffer out. The length of the buffer should be
// at least GetPrilen()+1 bytes. If out=0 the buffer is m-allocated internally
// and should be freed by the caller.
// at least GetPrilen()+1 bytes. The buffer out must be passed-by and it
// responsability-of the caller.
// Return 0 in case of success, -1 in case of failure
EPNAME("RSA::ExportPrivate");

Expand All @@ -440,6 +438,12 @@ int XrdCryptosslRSA::ExportPrivate(char *&out, int)
return -1;
}

// Check output buffer
if (!out) {
DEBUG("output buffer undefined!");
return -1;
}

// Bio for exporting the pub key
BIO *bkey = BIO_new(BIO_s_mem());

Expand All @@ -454,14 +458,6 @@ int XrdCryptosslRSA::ExportPrivate(char *&out, int)
return -1;
}

// Check output buffer
if (!out) {
out = (char *) malloc(lbio+1);
if (!out) {
DEBUG("problems allocating output buffer");
return -1;
}
}
// Read key from BIO to buf
memcpy(out, cbio, lbio);
// Null terminate
Expand Down
4 changes: 2 additions & 2 deletions src/XrdCrypto/XrdCryptosslRSA.hh
Expand Up @@ -70,9 +70,9 @@ public:

// Import / Export methods
int ImportPublic(const char *in, int lin);
int ExportPublic(char *&out, int lout);
int ExportPublic(char *out, int lout);
int ImportPrivate(const char *in, int lin);
int ExportPrivate(char *&out, int lout);
int ExportPrivate(char *out, int lout);

// Encryption / Decryption methods
int EncryptPrivate(const char *in, int lin, char *out, int lout);
Expand Down

0 comments on commit e781366

Please sign in to comment.