Code Monkey home page Code Monkey logo

Comments (6)

me-no-dev avatar me-no-dev commented on May 18, 2024

done :) cc4d1ac
give it a go ;)
BTW i'm looking into running axTLS async (no success yet)

from espasynctcp.

marvinroger avatar marvinroger commented on May 18, 2024

Fixed, thanks!
Oh you'll succeed, I am not worried. axTLS 2.0 brings TLS 1.2 moreover, so perfect timing. :)

from espasynctcp.

me-no-dev avatar me-no-dev commented on May 18, 2024

@marvinroger check this out: 110a997

client->connect(host, port, true) for SSL

from espasynctcp.

me-no-dev avatar me-no-dev commented on May 18, 2024

requires latest git of ESP8266 arduino

from espasynctcp.

me-no-dev avatar me-no-dev commented on May 18, 2024
#include <time.h>

extern "C" void system_set_os_print(uint8 onoff);
//call after wifi is up to set the time for ssl
bool initTime(){
  time_t rawtime;
  configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");
  uint8_t i = 0;
  system_set_os_print(0);
  while(time(&rawtime) == 0 && i++ < 100) delay(10);
  system_set_os_print(1);
  if(i==100){
    Serial.println("Time Init Failed");
    return false;
  }
  return true;
}

#include "include/ssl.h"
static AsyncClient * aClient = NULL;

const char *sslHost = "192.168.254.16";
const uint16_t sslPort = 443;

static void securePrintInfo(SSL *ssl){
  if(!ssl){
    return;
  }
  const char *common_name = ssl_get_cert_dn(ssl, SSL_X509_CERT_COMMON_NAME);
  if (common_name) {
    Serial.printf("COMMON NAME: %s\r\n", common_name);
  }

  Serial.printf("CIPHER: ");
  switch (ssl_get_cipher_id(ssl)){
    case SSL_AES128_SHA:
      Serial.printf("AES128-SHA");
      break;

    case SSL_AES256_SHA:
      Serial.printf("AES256-SHA");
      break;

    case SSL_RC4_128_SHA:
      Serial.printf("RC4-SHA");
      break;

    case SSL_RC4_128_MD5:
      Serial.printf("RC4-MD5");
      break;

    default:
      Serial.printf("Unknown - %d", ssl_get_cipher_id(ssl));
      break;
  }

  Serial.printf("\r\n");

  int i;
  const uint8_t *session_id = ssl_get_session_id(ssl);
  int sess_id_size = ssl_get_session_id_size(ssl);
  if (sess_id_size > 0){
    Serial.printf("SESSION: ");
    for (i = 0; i < sess_id_size; i++){
      Serial.printf("%02x", session_id[i]);
    }
    Serial.printf("\r\n");
  }
}

void runAsyncClient(){
  if(aClient)//client already exists
    return;

  aClient = new AsyncClient();
  if(!aClient)//could not allocate client
    return;

  aClient->onError([](void * arg, AsyncClient * client, int error){
    Serial.println("Connect Error");
    aClient = NULL;
    delete client;
  }, NULL);

  aClient->onConnect([](void * arg, AsyncClient * client){
    Serial.println("Connected");
    securePrintInfo(client->getSSL());
    aClient->onError(NULL, NULL);

    client->onDisconnect([](void * arg, AsyncClient * c){
      Serial.println("Disconnected");
      aClient = NULL;
      delete c;
    }, NULL);

    client->onData([](void * arg, AsyncClient * c, void * data, size_t len){
      Serial.print("\r\nData: ");
      Serial.println(len);
      uint8_t * d = (uint8_t*)data;
      for(size_t i=0; i<len;i++)
        Serial.write(d[i]);
    }, NULL);

    //send the request
    char m[256];
    sprintf(m, "GET /test.htm HTTP/1.0\r\nHost: %s\r\n\r\n", sslHost);
    int wrote = client->write(m, strlen(m));
    Serial.printf("Sent: %u => %d\r\n", strlen(m), wrote);
  }, NULL);

  if(!aClient->connect(sslHost, sslPort, true)){
    Serial.println("Connect Fail");
    AsyncClient * client = aClient;
    aClient = NULL;
    delete client;
  }
}

from espasynctcp.

marvinroger avatar marvinroger commented on May 18, 2024

Awesome! I will play with this as soon as I am back from vacation. Well done :)

from espasynctcp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.