Summary: Never really liked this code. Before this change, calls to connect were blocking. Because of this, we had to make use of promises and a bit of really not that good-looking code. So, this change makes connect non-blocking meaning that we make full use of our event handler. These changes contain: - CSR is not getting generated after each failed attempt. - Connect is no longer blocking. - Do not report events via the handler when explicitly disconnecting. Reviewed By: jknoxville Differential Revision: D46853228 fbshipit-source-id: 00e6a9c7c039a756175fe14982959e078d92bacb
76 lines
2.0 KiB
C++
76 lines
2.0 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <folly/Optional.h>
|
|
#include <folly/dynamic.h>
|
|
#include <string>
|
|
#include "FlipperCertificateExchangeMedium.h"
|
|
#include "FlipperInitConfig.h"
|
|
|
|
namespace facebook {
|
|
namespace flipper {
|
|
|
|
class ConnectionContextStore {
|
|
public:
|
|
enum StoreItem {
|
|
CSR,
|
|
FLIPPER_CA,
|
|
CLIENT_CERT,
|
|
PRIVATE_KEY,
|
|
CERTIFICATE,
|
|
CONNECTION_CONFIG,
|
|
};
|
|
ConnectionContextStore(DeviceData deviceData);
|
|
bool hasRequiredFiles();
|
|
std::string getCertificateSigningRequest();
|
|
std::string getCertificateDirectoryPath();
|
|
std::string getCACertificatePath();
|
|
std::string getDeviceId();
|
|
std::string getPath(StoreItem storeItem);
|
|
/**
|
|
* Get medium over which the certificate was received.
|
|
*/
|
|
folly::Optional<FlipperCertificateExchangeMedium> getLastKnownMedium();
|
|
void storeConnectionConfig(folly::dynamic& config);
|
|
/**
|
|
* Reset state just removes all certificate exchange related files stored on
|
|
* the client. These are:
|
|
* - Certificate Sign Request (CSR)
|
|
* - CA Certificate
|
|
* - Server Certificate
|
|
* - Client Certificate
|
|
* - Client Key
|
|
* - Configuration file (includes device identifier)
|
|
*/
|
|
bool resetState();
|
|
|
|
/** Convert and save to disk the existing certificate to PKCS #12 format.
|
|
* @return Returns a pair where `first` contains the certificate file path and
|
|
* `second` contains the certificate export password. If there's an error, the
|
|
* pair will contain both empty strings.
|
|
*/
|
|
std::pair<std::string, std::string> getCertificate();
|
|
|
|
/** Is there a CSR present.
|
|
*/
|
|
bool hasCertificateSigningRequest() const;
|
|
/** Is there a client certificate present.
|
|
*/
|
|
bool hasClientCertificate() const;
|
|
|
|
private:
|
|
DeviceData deviceData_;
|
|
std::string csr_ = "";
|
|
|
|
std::string absoluteFilePath(const char* filename) const;
|
|
};
|
|
|
|
} // namespace flipper
|
|
} // namespace facebook
|