Re: [openssl-users] error making Private RSA

2017-03-12 Thread william estrada
I have solved my create public RSA problem with this code:
  printf( "Method 1\n" );
  RSA* RSA1 = RSA_new();
  RSA* RSA2 = RSA_new();

  RSA2->n = RSA1->n = My_RSA->n;
  RSA2->e = RSA1->e = My_RSA->e;
  RSA2->d = RSA1->d = My_RSA->d;
  RSA2->p = RSA1->p = My_RSA->p;
  RSA2->q = RSA1->q = My_RSA->q;

  RC = PEM_write_bio_RSAPublicKey( bio, RSA1 ) ;
  printf( "%d RC: %d\n", __LINE__, RC );

  RC = PEM_write_bio_RSAPrivateKey( bio, RSA2,
NULL, NULL, 0, NULL, NULL ) ;
  printf( "%d RC: %d\n", __LINE__, RC );

  if( !RSA1 )
printf( RED
" ERROR: Could not load Public KEY!\n"
" PEM_read_bio_RSA_PUBKEY FAILED:\n %s\n" OFF,
ERR_error_string( ERR_get_error(), NULL ) ) ;

  else Check_Key( RSA1, ";" );

  if( !RSA2 )
printf( RED
" ERROR: Could not load Private KEY!\n"
" PEM_read_bio_RSA_PUBKEY FAILED:\n %s\n" OFF,
ERR_error_string( ERR_get_error(), NULL ) ) ;

  else Check_Key( RSA2, ";" );




-- 
William Estrada
Mt Umunhum, CA, USA, Earth
HTTP:// Mt-Umunhum-Wireless.net
Skype: MrUmunhum

-- 
William Estrada
Mt Umunhum, CA, USA, Earth
HTTP:// Mt-Umunhum-Wireless.net
Skype: MrUmunhum



-- 
William Estrada
Mt Umunhum, CA, USA, Earth
HTTP:// Mt-Umunhum-Wireless.net
Skype: MrUmunhum

-- 
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


Re: [openssl-users] error making Private RSA

2017-03-09 Thread william estrada
I have been tiring to keep my posting to a minim but I am not getting
across  what I am looking to
fix.   And I have been getting reports that my source code is not
viewable.  In my Apache logs I see that some people have be using the
wrong link, they are tiring to use
"http://mt-umunhum-wireless.net/mt-umunhum-wireless.net/Sources;
This is wrong! use:
"http://mt-umunhum-wireless.net/Sources/rsa;
or
"216.173.131.138/Sources/rsa"

The most recent attempt is the rsapost.c with the output rsapost.txt

What I am attempting to do is:
1) generate a RSA key pair, working but always the same keys.
2) remove the public key, working
3) create a RSA structure with the public key, 4 methods, all fail.
4) use the public key to encrypt a sting, don't get here.
5) use the RSA pair to decrypt the string.

The code is not clean but here it is:

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define OFF   "\x1B[0;0;0m"
#define DEFAULT   "\x1B[0;0;0m"
#define RED   "\x1B[1;31;40m"
#define BLUE  "\x1B[1;34;40m"
#define GREEN "\x1B[1;32;40m"
#define YELLOW"\x1B[1;33;40m"
#define CLEAR_EOL "\x1B[K"

void Dump( char *, int );
typedef unsigned char* UcharP;
typedef unsigned char  uchar;

#define Check_Key( Key, Action ) \
  if( RSA_check_key( Key ) != 1 )  { \
 printf( RED "%d %s Make Key Failed!\n" OFF, __LINE__, "(Key)" );\
 printf( RED "%s\n", \
 ERR_error_string( ERR_get_error(), NULL ) );\
 Action ;  } \
  else  {\
printf( BLUE "%d %s check key good\n" OFF , __LINE__, "Key" );  }

int main() {  // main()

  ERR_load_ERR_strings();

  RSA *My_RSA  = RSA_new();

  char Str[] = "1234567890";
  unsigned  char Out[1024];
  unsigned  char In[ 1024];
  int   RC, L, RSA_Len;

  unsigned long Error = ERR_get_error();
  char  *MSG  = ERR_error_string( Error, NULL);
  const  char *MSG2   = ERR_reason_error_string( Error );
  char  *ErrStr[100];

  BIGNUM *bne = BN_new();
  BN_set_word( bne, RSA_F4 );

  RC = RSA_generate_key_ex( My_RSA, 2048, bne, NULL );
  BN_free( bne );

  Check_Key( My_RSA, "return 1" );

  L = strlen( Str );
  printf ( BLUE "String: %s" OFF, Str );
  Dump( Str, L );

  RSA *Pub_RSA = RSA_new();

  // Extract Key from RSA Key pair
  BIO * Key_Bio = BIO_new( BIO_s_mem() );

  RC = PEM_write_bio_RSAPublicKey(  Key_Bio, My_RSA );

  printf( BLUE  "%d RC: %d\n" OFF, __LINE__ );

  size_t Key_Len = BIO_pending( Key_Bio   );
  char  *Key = malloc(  Key_Len + 1   );
  RC = BIO_read(Key_Bio, Key, Key_Len );
  Key[ Key_Len ] = '\0';

  printf( BLUE  "%d RC: %d, Len: %d\n" OFF, __LINE__, RC, Key_Len );

  // Let's see the data
  printf( BLUE  "\nKey type %s\n" OFF, "Public" );
  Dump( (char*) Key, -Key_Len );

  // Now try to fill in to RSA using the BIO method
  BIO* bio = BIO_new( BIO_s_mem() );
   bio = BIO_new_mem_buf( (void*)Key, -1 ) ;

  // Load the RSA key from the BIO
  printf( "Method 1\n" );
  RSA* RSA1 = NULL;
  RSA1 = PEM_read_bio_RSA_PUBKEY( bio, NULL, NULL, NULL ) ;
  if( !RSA1 )
printf( RED
" ERROR: Could not load PUBLIC KEY!\n"
" PEM_read_bio_RSA_PUBKEY FAILED:\n %s\n" OFF,
ERR_error_string( ERR_get_error(), NULL ) ) ;

  else Check_Key( RSA1, ";" );

  printf( "Method 2\n" );
  RSA *RSA2 = RSA_new();
  BIO_new_mem_buf( (void*)Key, -1 ) ;
  RC = PEM_write_bio_RSA_PUBKEY( bio, RSA2 ) ;
  if( !RSA2 )
printf( RED
" ERROR: Could not load PUBLIC KEY!\n"
" PEM_write_bio_RSA_PUBKEY FAILED:\n %s\n" OFF,
ERR_error_string( ERR_get_error(), NULL ) ) ;

  else Check_Key( RSA2, ";" );

  // Try Bio method 3
  printf( OFF "Method 3\n" );
  RSA *RSA3  = RSA_new();
  BIO* Pem = BIO_new( BIO_s_mem() );
  BIO_puts( Pem, Key );
  ERR_print_errors( Pem );

  if( RSA3 )  Check_Key( RSA3, ";" );

  RC = PEM_write_bio_RSA_PUBKEY(  Pem, RSA3 );
  printf( OFF "BIO RC: %d\n", RC );

  if( RSA3 )  Check_Key( RSA3, ";" );

  // Now try to fill in to RSA using the EVP method

  printf( OFF "Method 4\n" );

  RSA *RSA4  = RSA_new();

  EVP_PKEY* EVP_PEM_Key;

  EVP_PKEY* EVP_Pub_Key = d2i_PUBKEY_bio( Pem, NULL);

  ERR_print_errors( Pem );

  if( EVP_Pub_Key == NULL ) {
 Error = ERR_get_error( );
 MSG   = (char*) ERR_reason_error_string( Error );
 printf( RED "EVP Error: %s" OFF "\n", MSG );  }
  else {
 RSA4 = EVP_PKEY_get1_RSA( EVP_Pub_Key );  }

  Check_Key( RSA4, "return 1;" );

  while(1)  {
if( RSA1  &&  RSA_check_key( RSA1 ) == 1 )  {
   Pub_RSA = RSA1;break;  }
if( RSA2  &&  RSA_check_key( RSA2 ) == 1 )  {
   Pub_RSA = RSA2;break;  }
if( RSA3  &&  RSA_check_key( RSA3 ) 

Re: [openssl-users] error making Private RSA

2017-03-07 Thread Salz, Rich via openssl-users
> > My source can be viewed at: mt-umunhum-wireless.net/Sources/rsa/rsa.c

Gives a 403.

> > My main guess is that your allocation for the PEM buffer is too small
> > -- is key/key_len pointing to a static buffer?
> 
>  It points to a char string

Not sure what that means.  Please post your code here.  It should be something 
like
char key[2048];
int keylen = sizeof key;
 
-- 
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


Re: [openssl-users] error making Private RSA

2017-03-07 Thread william estrada

> Not sure this is the proper way to use this mailing system?
>
> My source can be viewed at: mt-umunhum-wireless.net/Sources/rsa/rsa.c
> What version of openssl?  I'm guessing 1.0.2.
>
> Put this line inyour code
>   ERR_load_ERR_strings();
> And youll get a more informative message.

  Did this and no improvement.
>
> I'm using: openssl version
> OpenSSL 1.0.1t  3 May 2016

openssl version
OpenSSL 1.0.2j-fips  26 Sep 2016

>
>
> My main guess is that your allocation for the PEM buffer is too small --
> is key/key_len pointing to a static buffer?

 It points to a char string

>
>
> --
> openssl-users mailing list
> To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users
>
>


-- 
William Estrada
Mt Umunhum, CA, USA, Earth
HTTP:// Mt-Umunhum-Wireless.net
Skype: MrUmunhum

-- 
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


[openssl-users] error making Private RSA

2017-03-04 Thread william estrada
Not sure this is the proper way to use this mailing system?

My source can be viewed at: mt-umunhum-wireless.net/Sources/rsa/rsa.c
What version of openssl?  I'm guessing 1.0.2.

Put this line inyour code
ERR_load_ERR_strings();
And youll get a more informative message.

I'm using: openssl version
OpenSSL 1.0.1t  3 May 2016


My main guess is that your allocation for the PEM buffer is too small --
is key/key_len pointing to a static buffer?


-- 
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


Re: [openssl-users] error making Private RSA

2017-03-02 Thread Salz, Rich via openssl-users
What version of openssl?  I'm guessing 1.0.2.

Put this line inyour code
ERR_load_ERR_strings();
And youll get a more informative message.   

My main guess is that your allocation for the PEM buffer is too small -- is 
key/key_len pointing to a static buffer? 
-- 
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


Re: [openssl-users] error making Private RSA

2017-03-02 Thread Matt Caswell


On 02/03/17 00:47, william estrada wrote:
> Hello group,
> I am attempting to create a Private RSA structure with the following code:
>  BIO*
>   PEM = BIO_new_mem_buf( Key, Key_Len );
> 
>   if( Type == 1 )
>  PEM_write_bio_RSAPrivateKey( PEM, RSA, NULL, NULL, 0, NULL, NULL );
>   else
>  PEM_write_bio_RSAPublicKey(  PEM, RSA );
> 
>   if( RSA_check_key( RSA ) != 1 )  {
> printf( RED "Make %s RSA Failed\n" OFF, Type==1?"Private":"Public" );
> int Error  = ERR_get_error();
> char *MSG  = ERR_error_string( Error, NULL);
> printf( "%s\n", MSG );  }
> 
> and I get this error:
> Make Private RSA Failed
> error:2007507E:lib(32):func(117):reason(126)
> Can anyone tell me what this error is and how to fix it?
> 
> 

$ openssl errstr 2007507E
error:2007507E:BIO routines:mem_write:write to read only BIO

BIO_new_mem_buf() gives you a read-only BIO. You probably want
BIO_new(BIO_s_mem()) instead.

See:

https://www.openssl.org/docs/man1.1.0/crypto/BIO_s_mem.html

Although, that error is coming from one of the PEM_write_bio_* calls
(which you are not checking the error return code of), so it doesn't
explain why RSA_check_key() fails. You don't show how you generate the
RSA structure to start with, so I guess you're not generating it properly.

Matt
-- 
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


[openssl-users] error making Private RSA

2017-03-01 Thread william estrada
Hello group,
I am attempting to create a Private RSA structure with the following code:
 BIO*
  PEM = BIO_new_mem_buf( Key, Key_Len );

  if( Type == 1 )
 PEM_write_bio_RSAPrivateKey( PEM, RSA, NULL, NULL, 0, NULL, NULL );
  else
 PEM_write_bio_RSAPublicKey(  PEM, RSA );

  if( RSA_check_key( RSA ) != 1 )  {
printf( RED "Make %s RSA Failed\n" OFF, Type==1?"Private":"Public" );
int Error  = ERR_get_error();
char *MSG  = ERR_error_string( Error, NULL);
printf( "%s\n", MSG );  }

and I get this error:
Make Private RSA Failed
error:2007507E:lib(32):func(117):reason(126)
Can anyone tell me what this error is and how to fix it?


-- 
William Estrada
Mt Umunhum, CA, USA, Earth
HTTP:// Mt-Umunhum-Wireless.net
Skype: MrUmunhum

-- 
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users