Exemplo n.º 1
0
int main( int argc, char *argv[ ] )
{   
  rsa_key privkey;
  unsigned char *buffer;
  int buffer_length;

  if ( argc < 3 )
  {
    fprintf( stderr, "Usage: %s [-pem|-der] <rsa private key file> [password]\n", argv[ 0 ] );
    exit( 0 );
  }

  if ( !( buffer = load_file_into_memory( argv[ 2 ], &buffer_length ) ) )
  {
    perror( "Unable to load file" );
    exit( 1 );
  }

  if ( !strcmp( argv[ 1 ], "-pem" ) )
  {
    // XXX this overallocates a bit, since it sets aside space for markers, etc.
    unsigned char *pem_buffer = buffer;
    buffer = (unsigned char * ) malloc( buffer_length );
    buffer_length = pem_decode( pem_buffer, buffer ); 
    free( pem_buffer );
  } 
  
  if ( argc == 3 )
  {
    parse_private_key( &privkey, buffer, buffer_length );
  }
  else
  {
    parse_pkcs8_private_key( &privkey, buffer, buffer_length, argv[ 3] );
  }
  
  printf( "Modulus:" );
  show_hex( privkey.modulus->rep, privkey.modulus->size );
  printf( "Private Exponent:" );
  show_hex( privkey.exponent->rep, privkey.exponent->size );
  
  free( buffer );
  
  return 0;
} 
Exemplo n.º 2
0
double get_lunar_transit_time( const int year, const int month,
   const int day, const double latitude, const double longitude,
   const int time_zone, const int dst, const int real_transit)
{
   const long jd0 = dmy_to_day( day, month, year, 0);
   const long day_of_year = jd0 - dmy_to_day( 1, 1, year, 0);
   double jd = (double)jd0;
   static char *vsop_data = NULL;
   int dst_hours = (dst ? is_dst( 720, (int)day_of_year, year) : 0);

   if( !vsop_data)
      vsop_data = load_file_into_memory( "vsop.bin", NULL);
   if( !vsop_data)
      return( -2.);
   jd -= (double)time_zone / 24.;      /* convert local to UT */
   jd -= dst_hours / 24.;

   jd = look_for_transit_time( 10, jd,
            latitude * pi / 180., longitude * pi / 180.,
            vsop_data, real_transit);
   jd += (double)time_zone / 24.;      /* convert UT back to local */
   jd += dst_hours / 24.;
   return( jd - (double)jd0 + .5);
}
Exemplo n.º 3
0
/**
 * \main
 */
int main( const int argc, const char** argv )
{
    ( void ) argc;
    ( void ) argv;

    if( argc != 4 )
    {
        print_usage();
        exit( 1 );
    }

    wanted_event_t wanted_event         = WANT_READ;

    short cs                    = 0;

    CYASSL_CTX* cyaSSLContext   = 0;
    CYASSL*     cyaSSLObject    = 0;

    struct timeval timeout;
    memset( &timeout, 0, sizeof( struct timeval ) );

    int max_fd                  = 0;

    fd_set r_master_set, r_working_set, w_master_set, w_working_set;
    FD_ZERO( &r_master_set );
    FD_ZERO( &w_master_set );
    FD_ZERO( &r_working_set );
    FD_ZERO( &w_working_set );

    // --------------------------- initialization ---------------------------------

    Conn_t conn_desc;
    memset( &conn_desc, 0, sizeof( conn_desc ) );

    char resp[ 4096 ];
    memset( resp, 0, sizeof( resp ) );

    conn_desc.sock_fd = create_non_blocking_socket();
    if( conn_desc.sock_fd < 0 ) DIE( "Socket creation failed!", 0 );

    conn_desc.endpoint_addr.sin_family      = AF_INET;
    conn_desc.endpoint_addr.sin_addr.s_addr = inet_addr( argv[ 1 ] );
    conn_desc.endpoint_addr.sin_port        = htons( atoi( argv[ 2 ] ) );

    cyaSSLContext = init_cyaSSL();
    if( cyaSSLContext == 0 ) DIE( "CyaSSL initialization fault...", 0 );

    // disable verify cause no proper certificate
    CyaSSL_CTX_set_verify( cyaSSLContext, SSL_VERIFY_NONE, 0 );

    cyaSSLObject = create_cyassl_object( cyaSSLContext, &conn_desc );
    if( !cyaSSLObject ) DIE( "CyaSSLObject not created properly!", 0 );

    set_cyassl_flags( cyaSSLObject );

    max_fd = conn_desc.sock_fd;

    FD_SET( conn_desc.sock_fd, &r_master_set );
    FD_SET( conn_desc.sock_fd, &w_master_set );

    // five minutes timeout
    timeout.tv_sec  = 3 * 60;
    timeout.tv_usec = 0;

    // --------------------------- main non blocking event processing loop ---------------------------------

    size_t  data_size   = 0;
    char*   data        = load_file_into_memory( argv[ 3 ], &data_size );
    if( data == 0 ) DIE( "Could not load given file... \n", 0 );

    // almost endless loop
    for( ; ; )
    {
        debug_log( "main_handle..." );
        int ret = main_handle( &cs, cyaSSLObject, &conn_desc, data, data_size );
        debug_log( "main_handle done!" );

        if( ret == -1 ) DIE( "error on main_handle...", cyaSSLObject );
        if( ret ==  0 ) break;

        wanted_event = ret;

        memcpy( &r_working_set, &r_master_set, sizeof( fd_set ) );
        memcpy( &w_working_set, &w_master_set, sizeof( fd_set ) );

        debug_fmt( "select... [%d]", ( int ) wanted_event );

        int s_ret = select(
                  max_fd + 1
                , wanted_event == WANT_READ ? &r_working_set : NULL
                , wanted_event == WANT_WRITE ? &w_working_set : NULL
                , NULL
                , &timeout );

        debug_fmt( "select done [%d]", s_ret );

        if( s_ret < 0 )     DIE( "error on select...", cyaSSLObject );
        if( s_ret == 0 )    DIE( "timeout on select...", cyaSSLObject );
    }

    free( data );

    cyaSSLObject = closeSSL( cyaSSLObject, &conn_desc );
    CyaSSL_CTX_free( cyaSSLContext ); cyaSSLContext = 0;
    CyaSSL_Cleanup();

    assert( cyaSSLObject == 0 && "Must be null!" );
    assert( cyaSSLContext == 0 && "Must be null!" );

    return 0;
}