如何使OpenSSL使用http而不是https?

Rel*_*lla 2 c++ ssl https openssl http

所以我想要的很简单 - 我喜欢openSSL api.我找到了一些简单的代码来开始学习它.我是服务器创建的新手.我想知道 - 如何使用简单的http而不是https使OpenSSL工作?我的意思是我想提供相同的服务,能够在我需要时跳转到https但是没有保护它的http vercion.

我的意思是,只是说

 SSLServer server("cert", "pkey", 1420);

  // Set the thread function.
  server.SetPthread_F(conn_thread);
Run Code Online (Sandbox Code Playgroud)

我希望我可以为不受保护的http服务创建做同样的事情.

经过一些回答,我知道我将编辑主要问题:

如何保留/仅使用OpenSSL库的非阻塞TCP服务器部分?主要目标是使用小型且简单的跨平台使用TCP服务器,在此基础上实现http和http成本模拟的eezy

所以如果我们看一下例子:

#include <openssl/ssl.h>
#include <openssl/err.h>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "sslserver.h"

#define REPLY "<html><body>Metalshell.com OpenSSL Server</body></html>"
#define MAX_PACKET_SIZE 1024

// Called when a new connection is made.
void *conn_thread(void *ssl) {
  int fd = SSL_get_fd((SSL *)ssl);

  if(SSL_accept((SSL *)ssl) == -1) {
    ERR_print_errors_fp(stderr);
  } else {
    char cipdesc[128];
    SSL_CIPHER *sslciph = SSL_get_current_cipher((SSL *)ssl);

    cout << "Encryption Description:\n";
    cout << SSL_CIPHER_description(sslciph, cipdesc, sizeof(cipdesc)) << endl;

    char buff[MAX_PACKET_SIZE];
    // Wait for data to be sent.
    int bytes = SSL_read((SSL *)ssl, buff, sizeof(buff));
    buff[bytes] = '\0';

    // Show the browser request.
    cout << "Recieved: \n" << buff << endl;

    // Send the html reply.
    SSL_write((SSL *)ssl, REPLY, strlen(REPLY));
  }

  // Tell the client we are closing the connection.
  SSL_shutdown((SSL *)ssl);

  // We do not wait for a reply, just clear everything.
  SSL_free((SSL *)ssl);
  close(fd);

  cout << "Connection Closed\n";
  cout << "---------------------------------------------\n";

  pthread_exit(NULL);
}

int main() {
  SSLServer server("cert", "pkey", 1420);

  // Set the thread function.
  server.SetPthread_F(conn_thread);

  while(1) {
    /* Wait for 10 seconds, and if no one trys
     * to connect return back.  This allows us to do
     * other things while waiting.
     */
    server.CheckClients(10);
  }

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

什么应该更改为我们的服务器不仅接受所有连接ssl(如果可能,cout完整请求)并发送它们REPLY?

Que*_*tin 11

HTTPS 带SSL的简单HTTP(其实现是OpenSSL的重点).HTTPS中的S代表安全.

如果不需要SSL,请不要使用OpenSSL API.