Friday, January 15, 2021

sample application in C++ with lib boringssl


BoringSSL is a fork of OpenSSL that is designed to meet Google's needs. The maintainers provide a branch(master-with-bazel) with BUILD, turning it into an external bazel dependency. However, it's still one step away from a runnable main function.


Below is my scaffold.

WORKSPACE

workspace(name = "boringsslapp")

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "boringssl",
commit = "bdbe37905216bea8dd4d0fdee93f6ee415d3aa15",
remote = "https://boringssl.googlesource.com/boringssl",
)

source/main.cc

#include "external/boringssl/src/include/openssl/bio.h"
#include "external/boringssl/src/include/openssl/err.h"
#include "external/boringssl/src/include/openssl/ssl.h"

int main(int argc, char **argv) {
SSL_CTX *ctx = SSL_CTX_new(TLS_method());
SSL *ssl = SSL_new(ctx);
std::cout << "Hello, boringssl " << ssl << std::endl;
SSL_free(ssl);
SSL_CTX_free(ctx);
return 0;
}

source/BUILD

cc_binary(
name = "main",
srcs = ["main.cc"],
deps = [
"@boringssl//:crypto",
"@boringssl//:ssl",
],
)

$ bazel run //source:main
Hello, boringssl 0x562960bbbbe8

No comments:

Post a Comment