Skip to content

Commit

Permalink
https://telecominfraproject.atlassian.net/browse/WIFI-7831
Browse files Browse the repository at this point in the history
Signed-off-by: stephb9959 <[email protected]>
  • Loading branch information
stephb9959 committed Sep 12, 2023
1 parent 1952813 commit cb7ad59
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/OpenRoamin_GlobalReach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,36 +51,26 @@ namespace OpenWifi {
auto BearerToken = MakeToken(GlobalReachAccountId);
Poco::URI URI{"https://config.openro.am/v1/radsec/issue"};
std::string Path(URI.getPathAndQuery());
std::cout << __LINE__ << std::endl;
Poco::Net::HTTPRequest Request(Poco::Net::HTTPRequest::HTTP_POST, Path,
Poco::Net::HTTPMessage::HTTP_1_1);
std::cout << __LINE__ << std::endl;

Request.add("Authorization", "Bearer " + BearerToken);
std::cout << __LINE__ << std::endl;

Poco::Net::HTTPSClientSession Session(URI.getHost(), URI.getPort());
Session.setTimeout(Poco::Timespan(10000, 10000));
std::cout << __LINE__ << std::endl;
Poco::JSON::Object CertRequestBody;
CertRequestBody.set("name", Name);
CertRequestBody.set("csr", CSR);
std::cout << __LINE__ << std::endl;

std::ostringstream os;
std::cout << __LINE__ << std::endl;
CertRequestBody.stringify(os);
Request.setContentType("application/json");
Request.setContentLength((long) os.str().size());

std::cout << __LINE__ << std::endl;
auto &Body = Session.sendRequest(Request);
Body << os.str();

std::cout << __LINE__ << std::endl;
Poco::Net::HTTPResponse Response;
std::istream &is = Session.receiveResponse(Response);
std::cout << __LINE__ << std::endl;
if (Response.getStatus() == Poco::Net::HTTPResponse::HTTP_OK) {
Poco::JSON::Parser P;
auto Result = P.parse(is).extract<Poco::JSON::Object::Ptr>();
Expand All @@ -90,7 +80,6 @@ namespace OpenWifi {
NewCertificate.certificateChain = Result->get("certificate_chain").toString();
NewCertificate.certificateId = Result->get("certificate_id").toString();
NewCertificate.expiresAt = Result->get("expires_at");
std::cout << __LINE__ << std::endl;
return true;
}
Poco::JSON::Parser P;
Expand All @@ -108,6 +97,7 @@ namespace OpenWifi {
const std::string &GlobalReachAccountId,
std::string &CertificateId,
ProvObjects::GLBLRCertificateInfo &NewCertificate) {
std::cout << __LINE__ << ":" << GlobalReachAccountId << std::endl;

try {
Poco::URI URI{fmt::format("https://config.openro.am/v1/radsec/cert/{}", CertificateId)};
Expand Down Expand Up @@ -153,20 +143,18 @@ namespace OpenWifi {
token.setType("JWT");
token.setAlgorithm("ES256");
token.setIssuedAt(std::time(nullptr));
std::cout << __LINE__ << ":" << GlobalReachAccountId << std::endl;

token.payload().set("iss", GlobalReachAccountId);
token.payload().set("iat", (unsigned long) std::time(nullptr));

Poco::SharedPtr<Poco::Crypto::ECKey> Key;
auto KeyHash = Utils::ComputeHash(PrivateKey);
auto KeyHint = PrivateKeys_.find(GlobalReachAccountId);
DBGLINE
if (KeyHint != PrivateKeys_.end() && KeyHint->second.first == KeyHash) {
DBGLINE
Key = KeyHint->second.second;
} else {
if (PrivateKey.empty()) {
DBGLINE
return "";
}
Poco::TemporaryFile F;
Expand All @@ -177,7 +165,6 @@ namespace OpenWifi {
new Poco::Crypto::ECKey("", F.path(), ""));
Key = NewKey;
PrivateKeys_[GlobalReachAccountId] = std::make_pair(KeyHash, NewKey);
DBGLINE
}

Poco::JWT::Signer Signer;
Expand Down

0 comments on commit cb7ad59

Please sign in to comment.