Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenSSL PEM_write_bio_RSAPrivateKey #6655

Closed
p6rt opened this issue Dec 30, 2017 · 6 comments
Closed

OpenSSL PEM_write_bio_RSAPrivateKey #6655

p6rt opened this issue Dec 30, 2017 · 6 comments
Labels
NativeCall SEGV Segmentation fault, bus error, etc. severe A problem that is encountered frequently, or a problem that needs attention for other reasons

Comments

@p6rt
Copy link

p6rt commented Dec 30, 2017

Migrated from rt.perl.org#132668 (status was 'resolved')

Searchable as RT132668$

@p6rt
Copy link
Author

p6rt commented Dec 30, 2017

From @LLFourn

I was trying to add RSA key generation using nativecall and OpenSSL but
kept getting non-deterministic segfaults. golfed example​:

#nativessl.pl
use NativeCall;

sub gen-lib { $*VM.platform-library-name('ssl'.IO).Str }

sub RSA_new(-->OpaquePointer) is native(&gen-lib) {...}
sub RSA_generate_key_ex(OpaquePointer $rsa, int32 $bits, OpaquePointer $e,
OpaquePointer $cb --> OpaquePointer) is native(&gen-lib) {...}
sub BN_new(-->OpaquePointer) is native(&gen-lib) {...}
sub BN_set_word(OpaquePointer $bn, uint32 $e --> int32) is native(&gen-lib)
{...}
sub BIO_s_mem(-->OpaquePointer) is native(&gen-lib) {...}
sub PEM_write_bio_RSAPrivateKey(OpaquePointer $bio, OpaquePointer $rsa -->
int32) is native(&gen-lib){...}
sub BIO_new(OpaquePointer $method --> OpaquePointer) is
native(&gen-lib){...};

{
  my uint32 $bits = 2048;
  my $bne = BN_new();
  BN_set_word($bne, 3) || die;
  my $rsa = RSA_new();
  RSA_generate_key_ex($rsa, $bits, $bne, Nil) || die;
  my $bio = BIO_new(BIO_s_mem());
  PEM_write_bio_RSAPrivateKey($bio, $rsa);
}

bash-3.2$ while perl6 nativessl.pl; do echo "worked"; done
Segmentation fault​: 11
bash-3.2$ while perl6 nativessl.pl; do echo "worked"; done
worked
worked
worked
worked
worked
worked
Segmentation fault​: 11
bash-3.2$ while perl6 nativessl.pl; do echo "worked"; done
worked
worked
worked
worked
Segmentation fault​: 11
bash-3.2$

@p6rt
Copy link
Author

p6rt commented Mar 5, 2019

From @salortiz

The problem is the PEM_write_bio_RSAPrivateKey signature used in the NativeCall declaration, it missed five arguments.

From the manual​:

  int PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc,
  unsigned char *kstr, int klen,
  pem_password_cb *cb, void *u);

So when called it received random values.

My modernized example attached that succeds.

@p6rt
Copy link
Author

p6rt commented Mar 5, 2019

From @salortiz

nativessl.p6

@p6rt
Copy link
Author

p6rt commented Mar 5, 2019

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Mar 5, 2019

From @AlexDaniel

OK, so that's not an issue in Rakudo then. Closed.

On 2019-03-05 11​:16​:41, sortiz wrote​:

The problem is the PEM_write_bio_RSAPrivateKey signature used in the
NativeCall declaration, it missed five arguments.

From the manual​:

int PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER
*enc,
unsigned char *kstr, int
klen,
pem_password_cb *cb, void
*u);

So when called it received random values.

My modernized example attached that succeds.

@p6rt
Copy link
Author

p6rt commented Mar 5, 2019

@AlexDaniel - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Mar 5, 2019
@p6rt p6rt added NativeCall SEGV Segmentation fault, bus error, etc. severe A problem that is encountered frequently, or a problem that needs attention for other reasons labels Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NativeCall SEGV Segmentation fault, bus error, etc. severe A problem that is encountered frequently, or a problem that needs attention for other reasons
Projects
None yet
Development

No branches or pull requests

1 participant