Hi All,

    I have downloaded the win32 version of OpenSSL and installed on my local
machine .and executed standard client server application.
    Now I want to make changes to this application,so can anybody tell me
how can i make changes in this sample application so that it 
    prints all test performed in the background link SSL Protocol version
,version negotiation ,cipher suite listing and negotiation  between 
   client and server.I also want to know that how can i check that my
machine supports HTTPS or not.    
    Can anybody tell me where i can get the definitions of all used function
specially SSLv2_method() , SSLv3_method().
    For further clarification i am also attaching the sample 
    code that i am using for testing SSL.
    
    
    SERVER Code :
    ----------------
    #include "..\lib_openssl\common.h"
    #include <process.h>
     
    #define CERTFILE "server.pem"
    SSL_CTX *setup_server_ctx(void)
    {
        SSL_CTX *ctx;
    
        ctx = SSL_CTX_new(SSLv3_method());
        if (SSL_CTX_use_certificate_chain_file(ctx, CERTFILE) != 1)
            int_error("Error loading certificate from file");
        if (SSL_CTX_use_PrivateKey_file(ctx, CERTFILE, SSL_FILETYPE_PEM) !=
1)
            int_error("Error loading private key from file");
        return ctx;
    }
    
    int do_server_loop(SSL *ssl)
    {
        int  err, nread;
        char buf[80];
     
        do
        {
            for (nread = 0;  nread < sizeof(buf);  nread += err)
            {
                err = SSL_read(ssl, buf + nread, sizeof(buf) - nread);
                if (err <= 0)
                    break;
            }
            fprintf(stdout, "%s", buf);
        }
        while (err > 0);
        return (SSL_get_shutdown(ssl) & SSL_RECEIVED_SHUTDOWN) ? 1 : 0;
    }
     
    void THREAD_CC server_thread(void *arg)
    {
        SSL *ssl = (SSL *)arg;
    
    #ifndef WIN32
        pthread_detach(pthread_self(  ));
    #endif
        if (SSL_accept(ssl) <= 0)
            int_error("Error accepting SSL connection");
        fprintf(stderr, "SSL Connection opened\n");
        if (do_server_loop(ssl))
            SSL_shutdown(ssl);
        else
            SSL_clear(ssl);
        fprintf(stderr, "SSL Connection closed\n");
        SSL_free(ssl);
    
        ERR_remove_state(0);
    
    #ifdef WIN32
        _endthread(  );
    #endif
    }
     
    int main(int argc, char *argv[])
    {
        BIO         *acc, *client;
        SSL         *ssl;
        SSL_CTX     *ctx;
        THREAD_TYPE tid;
     
        init_OpenSSL(  );
        seed_prng(  );
    
        ctx = setup_server_ctx(  );
    
        acc = BIO_new_accept(PORT);
        if (!acc)
            int_error("Error creating server socket");
     
        if (BIO_do_accept(acc) <= 0)
            int_error("Error binding server socket");
     
        for (;;)
        {
            if (BIO_do_accept(acc) <= 0)
                int_error("Error accepting connection");
     
            client = BIO_pop(acc);
            if (!(ssl = SSL_new(ctx)))
                int_error("Error creating SSL context");
                
                
    
            SSL_set_bio(ssl, client, client);
            THREAD_CREATE(tid, (void *)server_thread, ssl);
        }
        
        SSL_CTX_free(ctx);
        BIO_free(acc);
        return 0;
    }
    

    Client Code
    ---------------
    #include "..\lib_openssl\common.h"
     
    #define CERTFILE "client.pem"
    
    SSL_CTX *setup_client_ctx(void)
    {
        SSL_CTX *ctx;
        
        ctx = SSL_CTX_new(SSLv23_method(  ));
        if (SSL_CTX_use_certificate_chain_file(ctx, CERTFILE) != 1)
            int_error("Error loading certificate from file");
        if (SSL_CTX_use_PrivateKey_file(ctx, CERTFILE, SSL_FILETYPE_PEM) !=
1)
            int_error("Error loading private key from file");  
        return ctx;
    }
    
    int do_client_loop(SSL *ssl)
    {
        int  err, nwritten;
        char buf[80];
     
        for (;;)
        {
            if (!fgets(buf, sizeof(buf), stdin))
                break;
            for (nwritten = 0;  nwritten < sizeof(buf);  nwritten += err)
            {
                err = SSL_write(ssl, buf + nwritten, sizeof(buf) -
nwritten);
                if (err <= 0)
                    return 0;
            }
        }
        return 1;
    }
     
    int main(int argc, char *argv[])
    {
        BIO     *conn;
        SSL     *ssl;
        SSL_CTX *ctx;
    
        init_OpenSSL(  );
        seed_prng(  );
    
        ctx = setup_client_ctx(  );
    
        conn = BIO_new_connect(SERVER ":" PORT);
        if (!conn)
            int_error("Error creating connection BIO");
     
        if (BIO_do_connect(conn) <= 0)
            int_error("Error connecting to remote machine");
     
        if (!(ssl = SSL_new(ctx)))
            int_error("Error creating an SSL context");
        
        printf("Version  = %d\n",SSL_version(ssl) );
        
        getchar();
        SSL_set_bio(ssl, conn, conn);
        if (SSL_connect(ssl) <= 0)
            int_error("Error connecting SSL object");
    
        fprintf(stderr, "SSL Connection opened\n");
        if (do_client_loop(ssl))
            SSL_shutdown(ssl);
        else
            SSL_clear(ssl);
        fprintf(stderr, "SSL Connection closed\n");
    
        SSL_free(ssl);
        SSL_CTX_free(ctx);
        return 0;
    }
    

-- 
View this message in context: 
http://www.nabble.com/unable-to-find-the-definations-of-functions-and-how-to-work-out-with-thi-tf2303476.html#a6402574
Sent from the OpenSSL - Dev mailing list archive at Nabble.com.

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [email protected]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to