Clean on-device sonar dir between certificate exchanges
Summary: During certificate exchange, the mobile device creates a public/private key pair, and then requests a certificate from flipper to match it's public key. Flipper responds with the cert and it's written to the sonar dir along side the key pair files. If certificate exchange happens again for any reason, the mobile device will regenerate the key pair and request a new cert. If for any reason that cert never arrives, then the device is in a state where it has the new key pair, but the old certificate that doesn't match its new credentials. This would never work, but it means you get a strange SSL error because you're using inconsistent files. To improve error messaging, I'm making the client wipe all files before starting the certificate exchange step, so you should never get key/cert mismatches. Now the device can tell it doesn't have all the necessary files and won't even attempt to connect until it does. Reviewed By: passy Differential Revision: D13256369 fbshipit-source-id: 28f3cb5ba5938c17f01294683ba86c418f651376
This commit is contained in:
committed by
Facebook Github Bot
parent
fd022e3c73
commit
f15fe48fa9
@@ -1,13 +1,13 @@
|
|||||||
/*
|
/**
|
||||||
* Copyright (c) Facebook, Inc.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
* file in the root directory of this source tree.
|
* file in the root directory of this source tree.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
#include "ConnectionContextStore.h"
|
#include "ConnectionContextStore.h"
|
||||||
#include <folly/json.h>
|
#include <folly/json.h>
|
||||||
#include <folly/portability/SysStat.h>
|
#include <folly/portability/SysStat.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "CertificateUtils.h"
|
#include "CertificateUtils.h"
|
||||||
@@ -43,7 +43,7 @@ bool ConnectionContextStore::hasRequiredFiles() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string ConnectionContextStore::createCertificateSigningRequest() {
|
std::string ConnectionContextStore::createCertificateSigningRequest() {
|
||||||
ensureFlipperDirExists();
|
resetFlipperDir();
|
||||||
bool success = generateCertSigningRequest(
|
bool success = generateCertSigningRequest(
|
||||||
deviceData_.appId.c_str(),
|
deviceData_.appId.c_str(),
|
||||||
absoluteFilePath(CSR_FILE_NAME).c_str(),
|
absoluteFilePath(CSR_FILE_NAME).c_str(),
|
||||||
@@ -100,13 +100,20 @@ std::string ConnectionContextStore::getCertificateDirectoryPath() {
|
|||||||
return absoluteFilePath("");
|
return absoluteFilePath("");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConnectionContextStore::ensureFlipperDirExists() {
|
bool ConnectionContextStore::resetFlipperDir() {
|
||||||
std::string dirPath = absoluteFilePath("");
|
std::string dirPath = absoluteFilePath("");
|
||||||
struct stat info;
|
struct stat info;
|
||||||
if (stat(dirPath.c_str(), &info) != 0) {
|
if (stat(dirPath.c_str(), &info) != 0) {
|
||||||
int ret = mkdir(dirPath.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
|
int ret = mkdir(dirPath.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
|
||||||
return ret == 0;
|
return ret == 0;
|
||||||
} else if (info.st_mode & S_IFDIR) {
|
} else if (info.st_mode & S_IFDIR) {
|
||||||
|
for (auto file : {CSR_FILE_NAME,
|
||||||
|
FLIPPER_CA_FILE_NAME,
|
||||||
|
CLIENT_CERT_FILE_NAME,
|
||||||
|
PRIVATE_KEY_FILE,
|
||||||
|
CONNECTION_CONFIG_FILE}) {
|
||||||
|
std::remove(absoluteFilePath(file).c_str());
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
log("ERROR: Flipper path exists but is not a directory: " + dirPath);
|
log("ERROR: Flipper path exists but is not a directory: " + dirPath);
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) Facebook, Inc. and its 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
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -21,13 +27,12 @@ public:
|
|||||||
std::string getDeviceId();
|
std::string getDeviceId();
|
||||||
void storeConnectionConfig(folly::dynamic& config);
|
void storeConnectionConfig(folly::dynamic& config);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeviceData deviceData_;
|
DeviceData deviceData_;
|
||||||
|
|
||||||
std::string absoluteFilePath(const char* filename);
|
std::string absoluteFilePath(const char* filename);
|
||||||
bool ensureFlipperDirExists();
|
bool resetFlipperDir();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace flipper
|
} // namespace flipper
|
||||||
} //namespace facebook
|
} // namespace facebook
|
||||||
|
|||||||
Reference in New Issue
Block a user