Skip to content

Instantly share code, notes, and snippets.

@elvinio
elvinio / openssl_cipher_suite
Created July 29, 2015 21:49
List of cipher suite in OpenSSL 1.0.1e-fips
> $ openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013
> $ openssl ciphers -v | column -t
ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=RSA Enc=AESGCM(256) Mac=AEAD
ECDHE-ECDSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESGCM(256) Mac=AEAD
ECDHE-RSA-AES256-SHA384 TLSv1.2 Kx=ECDH Au=RSA Enc=AES(256) Mac=SHA384
ECDHE-ECDSA-AES256-SHA384 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AES(256) Mac=SHA384
ECDHE-RSA-AES256-SHA SSLv3 Kx=ECDH Au=RSA Enc=AES(256) Mac=SHA1
ECDHE-ECDSA-AES256-SHA SSLv3 Kx=ECDH Au=ECDSA Enc=AES(256) Mac=SHA1
@elvinio
elvinio / multicast_std.cpp
Last active August 29, 2015 14:26
Example program on how to use standard C network library to subscribe to a multicast server.
#include <iostream>
#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
#define BUFFERSIZE 2048
int main(){
int sockDesc = 0;
@elvinio
elvinio / multicast_boost.cpp
Last active August 29, 2015 14:26
Example program on how to use Boost ASIO to subscribe to a multicast server.
#include <boost/asio.hpp>
#include <boost/exception/diagnostic_information.hpp>
#define BUFFERSIZE 2048
using boost::asio::ip::udp;
int main(){
boost::asio::io_service* io_service = nullptr;
boost::asio::ip::udp::socket* socket = nullptr;
@elvinio
elvinio / makefile.make
Created July 24, 2015 01:21
An example makefile
CC = g++ -c -g -Wall -I .
LINKER = g++
PLATFORMLINK = -lstdc++ -lpthread -ldl -lssl
OBJFILES = ${patsubst %.cpp,%.o,${wildcard *.cpp))
all:Program
%.o: $.cpp
$(CC) -o $@ $<
@elvinio
elvinio / tcp_poll.cpp
Created July 24, 2015 01:17
C++: how to poll the TCP socket to read and write data.
void poller(int socketIn, std::string srcIP, int port){
struct pollfd fds[2];
// Initialize the fds to 0
memset(fds, 0, sizeof(fds));
// Wait in ms before poll times out. -1 for infinite
int timeout = 15000;
fds[0].fd = socketIn;
@elvinio
elvinio / tcp_listen.cpp
Created July 24, 2015 01:14
Code shows how to listen on a tcp socket in C++ and accept a connection
static struct sockaddr_in sa;
int listenCount = 0;
static const MAX_FD = 2048;
static struct pollfd listenFds[MAX_FD];
int main(int argc, char** argv){
int timeout = 15000;
listenPort(16000);
while(1){
@elvinio
elvinio / tcp_connect.cpp
Last active August 29, 2015 14:25
Establishing a TCP connection
int connect(const std::string &host, const int port, const int timeout){
struct sockaddr_in sa = {0};
int socket;
// Create and populate the connect address structure
sa.sin_family = AF_INET;
// The htons() function converts the unsigned short integer hostshort
// from host byte order to network byte order
// On the i80x86 the host byte order is least significant byte first,
@elvinio
elvinio / openssl_convert
Created July 20, 2015 13:50
Convert certificate
# Convert .pfx, .p12 to .pem
openssl pkcs12 -in a.pfx -out a.pem -nodes
# Convert .p7b to .pem
openssl pkcs7 -inform der -in a.p7b -out a.pem
# Remove passphrase
openssl rsa -in a.pem -out b.pem
@elvinio
elvinio / stunnel.conf
Last active August 29, 2015 14:25
Stunnel configuration
client = yes
cert = /home/test/test.pem
debug = 7
pid = /home/test/pid
output = /home/test/log
;output = /dev/stdout
fips = no
socket = r:TCP_NODELAY=1
socket = l:TCP_NODELAY=1
sslVersion = TLSv1.1
@elvinio
elvinio / stunnel.success.log
Last active August 29, 2015 14:25
Stunnel log of a successful SSL connection
2015.07.20 06:33:46 LOG6[2700:...]: Initializing service [prices]
2015.07.20 06:33:46 LOG7[2700:...]: Certificate: /home/test/test.pem
2015.07.20 06:33:46 LOG7[2700:...]: Certificate loaded
2015.07.20 06:33:46 LOG7[2700:...]: Key file: /home/test/test.pem
2015.07.20 06:33:46 LOG7[2700:...]: Private key loaded
2015.07.20 06:33:46 LOG7[2700:...]: SSL options set: 0x00000004
2015.07.20 06:33:46 LOG5[2700:...]: Configuration successful
2015.07.20 06:33:46 LOG7[2700:...]: Service [barx_trades] (FD=12) bound to 0.0.0.0:8444
2015.07.20 06:33:46 LOG7[2700:...]: Service [prices] (FD=13) bound to 0.0.0.0:8443
2015.07.20 06:33:46 LOG7[2706:...]: Created pid file /home/test/pid