Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8479211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:57:39+00:00 2026-06-10T18:57:39+00:00

I recently wanted to build my own client-server system by using BSD sockets. After

  • 0

I recently wanted to build my own client-server system by using BSD sockets. After some point I wanted to include SSL to encrypt the data transfer. I followed this tutorial and the code compiles fine with Xcode (added linker flags: -lssl -lcrypto), but I keep getting EXC_BAD_ACCESS all the time once the program reaches the SSL_CTX_use_certificate_file() call. You can see the used code below.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>

int main(int argc, const char * argv[])
{
    SSL_METHOD *method = NULL;
    SSL_CTX *ctx = NULL;
    OpenSSL_add_all_algorithms();
    SSL_load_error_strings();
    method = SSLv2_server_method();
    ctx = SSL_CTX_new(method);

    SSL_CTX_use_certificate_file(ctx, "/Users/steve/certificate.pem", SSL_FILETYPE_PEM);
    SSL_CTX_use_PrivateKey_file(ctx, "/Users/steve/key.pem", SSL_FILETYPE_PEM);

    printf("Hello, World!\n");
    return EXIT_SUCCESS;
}

If the program can’t find the certificate at the specified path it doesn’t crash but I wont have any SSL encryption of course. Could there be a problem with the certificate itself? I simply generated one with openssl by using the following commands:

# generate the key
$ openssl genrsa -out key.pem 1024

# generate request
$ openssl req -new -key key.pem -out request.pem
# fill in all the stuff ...

# generate certificate
$ openssl x509 -req -days 30 -in request.pem -signkey key.pem -out certificate.pem

Any idea?

Update: There actually are some warnings showing up when compiling with the OS X Deployment Target set to 10.7 or later, because all of this SSL stuff shows up as deprecated. Are there any recommended alternative practices to secure sockets with SSL?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:57:40+00:00Added an answer on June 10, 2026 at 6:57 pm

    The problem is that you need to call SSL_library_init, see the modification inside the code (It’s also a good practice to always handle errors from functions that we call :-):

    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <openssl/bio.h>
    #include <openssl/ssl.h>
    #include <openssl/err.h>
    
    int main(int argc, const char * argv[])
    {
        //SSL_METHOD *method = NULL;
        SSL_CTX *ctx = NULL;
        OpenSSL_add_all_algorithms();
        SSL_load_error_strings();
        //method = SSLv2_server_method();
        //ctx = SSL_CTX_new(method);
    
        /* Without this line you got an error when calling SSL_CTX_new */
        SSL_library_init();
        ctx = SSL_CTX_new(SSLv2_server_method());
        if(!ctx) 
        {
            fprintf (stderr, "SSL_CTX_new ERROR\n");
            ERR_print_errors_fp(stderr);
            return EXIT_FAILURE;
        }
    
        if (!SSL_CTX_use_certificate_file(ctx, "/Users/steve/certificate.pem", SSL_FILETYPE_PEM))
        {
            fprintf (stderr, "SSL_CTX_use_certificate_file ERROR\n");
            ERR_print_errors_fp(stderr);
    
            return EXIT_FAILURE;
        }
        SSL_CTX_use_PrivateKey_file(ctx, "/Users/steve/key.pem", SSL_FILETYPE_PEM);
    
        printf("Hello, World!\n");
        return EXIT_SUCCESS;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was using \documentclass{amsmath} for awhile with no issues, but I recently wanted to
I've read about Single-Page Applications recently and wanted to try one out. After watching
Recently I've wanted to do a number of things using CSS only to find
I recently downloaded Visual Studio 2010b2, and wanted to re-evaluate some of my questions
So I recently wanted to use the jQuery to do some browser detection and
I am creating a game. I have some UI with text. Recently we wanted
Recently I had a problem using (pipe |-) when I wanted to communicate between
Recently I wanted to try some of the new features in Scala 2.9 in
I've recently started learning HLSL after deciding that I wanted better lighting than what
I was recently requested by a client to build a website for their insurance

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.