From b1b32d354d7751bfff6910d1f8fb3c9050b9545c Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 18 Feb 2021 11:49:17 -0400 Subject: [PATCH] fix: TLS verification --- src/status/libstatus/stickers.nim | 5 +++-- src/status/wallet.nim | 5 +++-- src/status/wallet/balance_manager.nim | 5 +++-- src/status/wallet/collectibles.nim | 11 +++++++---- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/status/libstatus/stickers.nim b/src/status/libstatus/stickers.nim index fd10a06732..2aba83304a 100644 --- a/src/status/libstatus/stickers.nim +++ b/src/status/libstatus/stickers.nim @@ -1,6 +1,6 @@ import ./core as status, ./types, ./eth/contracts, ./settings, ./edn_helpers import - json, json_serialization, tables, chronicles, sequtils, httpclient, + json, json_serialization, tables, chronicles, sequtils, httpclient, net, stint, libp2p/[multihash, multicodec, cid], web3/[ethtypes, conversions] from strutils import parseHexInt, parseInt from nimcrypto import fromHex @@ -115,7 +115,8 @@ proc getPackData*(id: Stuint[256]): StickerPack = # an IPFS identifier. Once decoded, download the content from IPFS. This content # is in EDN format, ie https://ipfs.infura.io/ipfs/QmWVVLwVKCwkVNjYJrRzQWREVvEk917PhbHYAUhA1gECTM # and it also needs to be decoded in to a nim type - var client = newHttpClient() + let secureSSLContext = newContext() + let client = newHttpClient(sslContext = secureSSLContext) let contentHash = contracts.toHex(packData.contentHash) let url = "https://ipfs.infura.io/ipfs/" & decodeContentHash(contentHash) var ednMeta = client.getContent(url) diff --git a/src/status/wallet.nim b/src/status/wallet.nim index 9f8ad40c5c..7f1908e927 100644 --- a/src/status/wallet.nim +++ b/src/status/wallet.nim @@ -1,4 +1,4 @@ -import json, strformat, strutils, chronicles, sequtils, httpclient, tables +import json, strformat, strutils, chronicles, sequtils, httpclient, tables, net import json_serialization, stint from web3/ethtypes import Address, EthSend, Quantity from web3/conversions import `$` @@ -340,7 +340,8 @@ proc getGasPricePredictions*(self: WalletModel): GasPricePrediction = return GasPricePrediction(safeLow: 1.0, standard: 2.0, fast: 3.0, fastest: 4.0) try: let url: string = fmt"https://etherchain.org/api/gasPriceOracle" - let client = newHttpClient() + let secureSSLContext = newContext() + let client = newHttpClient(sslContext = secureSSLContext) client.headers = newHttpHeaders({ "Content-Type": "application/json" }) let response = client.request(url) result = Json.decode(response.body, GasPricePrediction) diff --git a/src/status/wallet/balance_manager.nim b/src/status/wallet/balance_manager.nim index 351a0a19fa..6a83d7f742 100644 --- a/src/status/wallet/balance_manager.nim +++ b/src/status/wallet/balance_manager.nim @@ -1,4 +1,4 @@ -import strformat, strutils, stint, httpclient, json, chronicles +import strformat, strutils, stint, httpclient, json, chronicles, net import ../libstatus/wallet as status_wallet import ../libstatus/tokens as status_tokens import ../libstatus/types as status_types @@ -23,7 +23,8 @@ var balanceManager = newBalanceManager() proc getPrice(crypto: string, fiat: string): string = try: let url: string = fmt"https://min-api.cryptocompare.com/data/price?fsym={crypto}&tsyms={fiat}" - let client = newHttpClient() + let secureSSLContext = newContext() + let client = newHttpClient(sslContext = secureSSLContext) client.headers = newHttpHeaders({ "Content-Type": "application/json" }) let response = client.request(url) diff --git a/src/status/wallet/collectibles.nim b/src/status/wallet/collectibles.nim index 57f214d2a3..821a3f91bc 100644 --- a/src/status/wallet/collectibles.nim +++ b/src/status/wallet/collectibles.nim @@ -1,4 +1,4 @@ -import strformat, httpclient, json, chronicles, sequtils, strutils, tables, sugar +import strformat, httpclient, json, chronicles, sequtils, strutils, tables, sugar, net import ../libstatus/core as status import ../libstatus/eth/contracts as contracts import ../libstatus/stickers as status_stickers @@ -69,7 +69,8 @@ proc getCryptoKittiesBatch*(address: Address, offset: int = 0): seq[Collectible] cryptokitties = @[] # TODO handle testnet -- does this API exist in testnet?? let url: string = fmt"https://api.cryptokitties.co/kitties?limit=20&offset={$offset}&owner_wallet_address={$address}&parents=false" - let client = newHttpClient() + let secureSSLContext = newContext() + let client = newHttpClient(sslContext = secureSSLContext) client.headers = newHttpHeaders({ "Content-Type": "application/json" }) let response = client.request(url) @@ -130,7 +131,8 @@ proc getEthermons*(address: Address): string = let tokensJoined = strutils.join(tokens, ",") let url = fmt"https://www.ethermon.io/api/monster/get_data?monster_ids={tokensJoined}" - let client = newHttpClient() + let secureSSLContext = newContext() + let client = newHttpClient(sslContext = secureSSLContext) client.headers = newHttpHeaders({ "Content-Type": "application/json" }) let response = client.request(url) @@ -173,7 +175,8 @@ proc getKudos*(address: Address): string = if (url == ""): return $(%*kudos) - let client = newHttpClient() + let secureSSLContext = newContext() + let client = newHttpClient(sslContext = secureSSLContext) client.headers = newHttpHeaders({ "Content-Type": "application/json" }) let response = client.request(url)