certificateProvider
Summary: rename certificate provider Reviewed By: passy Differential Revision: D9871288 fbshipit-source-id: 001a61416af23d89e63374cccc3df256b55eb6d2
This commit is contained in:
committed by
Facebook Github Bot
parent
e9490ca3b4
commit
3e4c24d6fe
@@ -27,11 +27,11 @@ const serverCert = getFilePath('server.crt');
|
|||||||
|
|
||||||
// Device file paths
|
// Device file paths
|
||||||
const csrFileName = 'app.csr';
|
const csrFileName = 'app.csr';
|
||||||
const deviceCAcertFile = 'sonarCA.crt';
|
const deviceCAcertFile = 'flipperCA.crt';
|
||||||
const deviceClientCertFile = 'device.crt';
|
const deviceClientCertFile = 'device.crt';
|
||||||
|
|
||||||
const caSubject = '/C=US/ST=CA/L=Menlo Park/O=Sonar/CN=SonarCA';
|
const caSubject = '/C=US/ST=CA/L=Menlo Park/O=Flipper/CN=FlipperCA';
|
||||||
const serverSubject = '/C=US/ST=CA/L=Menlo Park/O=Sonar/CN=localhost';
|
const serverSubject = '/C=US/ST=CA/L=Menlo Park/O=Flipper/CN=localhost';
|
||||||
const minCertExpiryWindowSeconds = 24 * 60 * 60;
|
const minCertExpiryWindowSeconds = 24 * 60 * 60;
|
||||||
const appNotDebuggableRegex = /debuggable/;
|
const appNotDebuggableRegex = /debuggable/;
|
||||||
const allowedAppNameRegex = /^[a-zA-Z0-9.\-]+$/;
|
const allowedAppNameRegex = /^[a-zA-Z0-9.\-]+$/;
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
#include "ConnectionContextStore.h"
|
#include "ConnectionContextStore.h"
|
||||||
|
#include <folly/json.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
#include "CertificateUtils.h"
|
#include "CertificateUtils.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <folly/json.h>
|
|
||||||
|
|
||||||
using namespace facebook::sonar;
|
using namespace facebook::sonar;
|
||||||
|
|
||||||
static constexpr auto CSR_FILE_NAME = "app.csr";
|
static constexpr auto CSR_FILE_NAME = "app.csr";
|
||||||
static constexpr auto SONAR_CA_FILE_NAME = "sonarCA.crt";
|
static constexpr auto FLIPPER_CA_FILE_NAME = "flipperCA.crt";
|
||||||
static constexpr auto CLIENT_CERT_FILE_NAME = "device.crt";
|
static constexpr auto CLIENT_CERT_FILE_NAME = "device.crt";
|
||||||
static constexpr auto PRIVATE_KEY_FILE = "privateKey.pem";
|
static constexpr auto PRIVATE_KEY_FILE = "privateKey.pem";
|
||||||
static constexpr auto CONNECTION_CONFIG_FILE = "connection_config.json";
|
static constexpr auto CONNECTION_CONFIG_FILE = "connection_config.json";
|
||||||
@@ -18,10 +18,12 @@ bool fileExists(std::string fileName);
|
|||||||
std::string loadStringFromFile(std::string fileName);
|
std::string loadStringFromFile(std::string fileName);
|
||||||
void writeStringToFile(std::string content, std::string fileName);
|
void writeStringToFile(std::string content, std::string fileName);
|
||||||
|
|
||||||
ConnectionContextStore::ConnectionContextStore(DeviceData deviceData): deviceData_(deviceData) {}
|
ConnectionContextStore::ConnectionContextStore(DeviceData deviceData)
|
||||||
|
: deviceData_(deviceData) {}
|
||||||
|
|
||||||
bool ConnectionContextStore::hasRequiredFiles() {
|
bool ConnectionContextStore::hasRequiredFiles() {
|
||||||
std::string caCert = loadStringFromFile(absoluteFilePath(SONAR_CA_FILE_NAME));
|
std::string caCert =
|
||||||
|
loadStringFromFile(absoluteFilePath(FLIPPER_CA_FILE_NAME));
|
||||||
std::string clientCert =
|
std::string clientCert =
|
||||||
loadStringFromFile(absoluteFilePath(CLIENT_CERT_FILE_NAME));
|
loadStringFromFile(absoluteFilePath(CLIENT_CERT_FILE_NAME));
|
||||||
std::string privateKey =
|
std::string privateKey =
|
||||||
@@ -48,7 +50,7 @@ std::shared_ptr<SSLContext> ConnectionContextStore::getSSLContext() {
|
|||||||
std::shared_ptr<folly::SSLContext> sslContext =
|
std::shared_ptr<folly::SSLContext> sslContext =
|
||||||
std::make_shared<folly::SSLContext>();
|
std::make_shared<folly::SSLContext>();
|
||||||
sslContext->loadTrustedCertificates(
|
sslContext->loadTrustedCertificates(
|
||||||
absoluteFilePath(SONAR_CA_FILE_NAME).c_str());
|
absoluteFilePath(FLIPPER_CA_FILE_NAME).c_str());
|
||||||
sslContext->setVerificationOption(
|
sslContext->setVerificationOption(
|
||||||
folly::SSLContext::SSLVerifyPeerEnum::VERIFY);
|
folly::SSLContext::SSLVerifyPeerEnum::VERIFY);
|
||||||
sslContext->loadCertKeyPairFromFiles(
|
sslContext->loadCertKeyPairFromFiles(
|
||||||
@@ -65,9 +67,11 @@ std::string ConnectionContextStore::getDeviceId() {
|
|||||||
For backwards compatibility, when this isn't present, fall back to the
|
For backwards compatibility, when this isn't present, fall back to the
|
||||||
unreliable source. */
|
unreliable source. */
|
||||||
try {
|
try {
|
||||||
std::string config = loadStringFromFile(absoluteFilePath(CONNECTION_CONFIG_FILE));
|
std::string config =
|
||||||
|
loadStringFromFile(absoluteFilePath(CONNECTION_CONFIG_FILE));
|
||||||
auto maybeDeviceId = folly::parseJson(config)["deviceId"];
|
auto maybeDeviceId = folly::parseJson(config)["deviceId"];
|
||||||
return maybeDeviceId.isString() ? maybeDeviceId.getString() : deviceData_.deviceId;
|
return maybeDeviceId.isString() ? maybeDeviceId.getString()
|
||||||
|
: deviceData_.deviceId;
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
return deviceData_.deviceId;
|
return deviceData_.deviceId;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user