Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,25 @@
{
'targets': [
{
'target_name': 'testengine',
'type': 'none',
'includes': ['../common.gypi'],
'conditions': [
['OS=="mac" and '
'node_use_openssl=="true" and '
'node_shared=="false" and '
'node_shared_openssl=="false"', {
'type': 'shared_library',
'sources': [ 'testengine.cc' ],
'product_extension': 'engine',
'include_dirs': ['../../../deps/openssl/openssl/include'],
'link_settings': {
'libraries': [
'../../../../out/<(PRODUCT_DIR)/<(openssl_product)'
]
},
}],
]
}
]
}

View File

@ -0,0 +1,60 @@
'use strict';
const common = require('../../common');
const fixture = require('../../common/fixtures');
if (!common.hasCrypto)
common.skip('missing crypto');
const fs = require('fs');
const path = require('path');
const engine = path.join(__dirname,
`/build/${common.buildType}/testengine.engine`);
if (!fs.existsSync(engine))
common.skip('no client cert engine');
const assert = require('assert');
const https = require('https');
const agentKey = fs.readFileSync(fixture.path('/keys/agent1-key.pem'));
const agentCert = fs.readFileSync(fixture.path('/keys/agent1-cert.pem'));
const agentCa = fs.readFileSync(fixture.path('/keys/ca1-cert.pem'));
const serverOptions = {
key: agentKey,
cert: agentCert,
ca: agentCa,
requestCert: true,
rejectUnauthorized: true,
};
const server = https.createServer(serverOptions, common.mustCall((req, res) => {
res.writeHead(200);
res.end('hello world');
})).listen(0, common.localhostIPv4, common.mustCall(() => {
const clientOptions = {
method: 'GET',
host: common.localhostIPv4,
port: server.address().port,
path: '/test',
clientCertEngine: engine, // `engine` will provide key+cert
rejectUnauthorized: false, // Prevent failing on self-signed certificates
headers: {},
};
const req = https.request(clientOptions, common.mustCall((response) => {
let body = '';
response.setEncoding('utf8');
response.on('data', (chunk) => {
body += chunk;
});
response.on('end', common.mustCall(() => {
assert.strictEqual(body, 'hello world');
server.close();
}));
}));
req.end();
}));

View File

@ -0,0 +1,106 @@
#include <openssl/engine.h>
#include <openssl/pem.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <fstream>
#include <iterator>
#include <string>
#ifndef ENGINE_CMD_BASE
# error did not get engine.h
#endif
#define TEST_ENGINE_ID "testengine"
#define TEST_ENGINE_NAME "dummy test engine"
#define AGENT_KEY "test/fixtures/keys/agent1-key.pem"
#define AGENT_CERT "test/fixtures/keys/agent1-cert.pem"
#ifdef _WIN32
# define DEFAULT_VISIBILITY __declspec(dllexport)
#else
# define DEFAULT_VISIBILITY __attribute__((visibility("default")))
#endif
namespace {
int EngineInit(ENGINE* engine) {
return 1;
}
int EngineFinish(ENGINE* engine) {
return 1;
}
int EngineDestroy(ENGINE* engine) {
return 1;
}
std::string LoadFile(const char* filename) {
std::ifstream file(filename);
return std::string(std::istreambuf_iterator<char>(file),
std::istreambuf_iterator<char>());
}
int EngineLoadSSLClientCert(ENGINE* engine,
SSL* ssl,
STACK_OF(X509_NAME)* ca_dn,
X509** ppcert,
EVP_PKEY** ppkey,
STACK_OF(X509)** pother,
UI_METHOD* ui_method,
void* callback_data) {
if (ppcert != nullptr) {
std::string cert = LoadFile(AGENT_CERT);
if (cert.empty()) {
return 0;
}
BIO* bio = BIO_new_mem_buf(cert.data(), cert.size());
*ppcert = PEM_read_bio_X509(bio, nullptr, nullptr, nullptr);
BIO_vfree(bio);
if (*ppcert == nullptr) {
printf("Could not read certificate\n");
return 0;
}
}
if (ppkey != nullptr) {
std::string key = LoadFile(AGENT_KEY);
if (key.empty()) {
return 0;
}
BIO* bio = BIO_new_mem_buf(key.data(), key.size());
*ppkey = PEM_read_bio_PrivateKey(bio, nullptr, nullptr, nullptr);
BIO_vfree(bio);
if (*ppkey == nullptr) {
printf("Could not read private key\n");
return 0;
}
}
return 1;
}
int bind_fn(ENGINE* engine, const char* id) {
ENGINE_set_id(engine, TEST_ENGINE_ID);
ENGINE_set_name(engine, TEST_ENGINE_NAME);
ENGINE_set_init_function(engine, EngineInit);
ENGINE_set_finish_function(engine, EngineFinish);
ENGINE_set_destroy_function(engine, EngineDestroy);
ENGINE_set_load_ssl_client_cert_function(engine, EngineLoadSSLClientCert);
return 1;
}
extern "C" {
DEFAULT_VISIBILITY IMPLEMENT_DYNAMIC_CHECK_FN();
DEFAULT_VISIBILITY IMPLEMENT_DYNAMIC_BIND_FN(bind_fn);
}
} // anonymous namespace