Esempio n. 1
0
def update(fota_data):
    """
.. function:: update(document)

    Given a correct job :samp:`document`, performs the FOTA update by downloading the correct firmware from the signed S3 bucket url
    and checking if the download was correct against the firmware CRC. Return True if the process finishes correctly.
    
    """
    global next_bcaddr
    global bcsize
    # setup 
    awscert = __lookup(BALTIMORE_CYBERTRUST_ROOT)
    ctx = ssl.create_ssl_context(cacert=awscert,options=ssl.CERT_REQUIRED|ssl.SERVER_AUTH)
    record = fota.get_record()
    chunk = record[8]

    #prepare for FOTA
    next_bcaddr = fota.find_bytecode_slot()
    bcsize = fota_data["bc_size"]
    fota.erase_slot(next_bcaddr, bcsize)
    
    url = fota_data["bc_url"]
    rr = requests.get(url, ctx=ctx, stream_callback=_stream_cb, stream_chunk=chunk)
    if wsize!=bcsize:
        return False
    chk = fota.checksum_slot(next_bcaddr,bcsize)
    fota.close_slot(next_bcaddr)
    for i,b in enumerate(chk):
        k = int(fota_data["bc_crc"][i*2:i*2+2],16)
        if k!=b:
            print("Bad crc!")
            break

    return True
Esempio n. 2
0
    def __init__(self, device_id, device_type, organization, auth_token):
        self.ctx = ssl.create_ssl_context(
            options=ssl.CERT_NONE)  # TODO: add messaging.pem cert

        mqtt_id = 'd:' + organization + ':' + device_type + ':' + device_id
        endpoint = organization + '.messaging.internetofthings.ibmcloud.com'

        self.mqtt = WatsonMQTTClient(mqtt_id, endpoint, auth_token, self.ctx)

        # self.managed = False
        self._cmd_cbks = {}
Esempio n. 3
0
    def __init__(self, project_id, cloud_region, registry_id, device_id, pkey, timestamp_fn, token_lifetime=60, custom_jwt=None):
        self.ctx = ssl.create_ssl_context(options=ssl.SERVER_AUTH|ssl.CERT_NONE) # should add root...
        self.device_id = device_id
        self.project_id = project_id
        self.private_key = pkey
        self.timestamp_fn = timestamp_fn
        self.token_lifetime = token_lifetime
        mqtt_id = 'projects/' + project_id + '/locations/' + cloud_region + '/registries/' + registry_id +'/devices/' + device_id
        self.mqtt = GCMQTTClient(mqtt_id, 'mqtt.googleapis.com', self.ctx, self._create_jwt, self._connect_cb)

        self._config_cbk = None
        self._command_cbk = None

        if custom_jwt is not None:
            self._jwt_fn = custom_jwt
        else:
#-if GOOGLECLOUD_HWJWT
            raise Exception
#-else
            self._jwt_fn = jwt.encode
Esempio n. 4
0
    def __init__(self,
                 endpoint,
                 mqtt_id,
                 clicert,
                 pkey,
                 thingname=None,
                 cacert=None):
        global legacy_and_amazon_cas
        if cacert is None:
            cacert = legacy_and_amazon_cas
        else:
            legacy_and_amazon_cas = None
        self.ctx = ssl.create_ssl_context(cacert=cacert,
                                          clicert=clicert,
                                          pkey=pkey,
                                          options=ssl.CERT_REQUIRED
                                          | ssl.SERVER_AUTH)
        self.mqtt = AWSMQTTClient(mqtt_id, endpoint, self.ctx)
        self.thingname = (thingname or mqtt_id)

        self._shadow_cbk = None
        self._client_token = ''.join([str(xx) for xx in mcu.uid()])
Esempio n. 5
0
def discover(endpoint, thingname, clicert, pkey, cacert=None):
    """
================
Helper Functions
================

.. function:: discover(endpoint, thingname, clicert, pkey, cacert=None)

        :param endpoint: AWS server where to retrieve Greengrass core info
        :param thingname: AWS IoT Core or AWS Greengrass Device name
        :param clicert: client certificate
        :param pkey: client private key

    Discover info about own group Greengrass Core.
    Returns a :class:`DiscoveryInfo` object.

    """
    if cacert is None:
        cacert = __lookup(SSL_CACERT_VERISIGN_CLASS_3_PUBLIC_PRIMARY_CERTIFICATION_AUTHORITY___G5)
    ctx = ssl.create_ssl_context(cacert=cacert,clicert=clicert,pkey=pkey,options=ssl.CERT_REQUIRED|ssl.SERVER_AUTH)
    rr = requests.get('https://' + endpoint + ':8443/greengrass/discover/thing/' + thingname, ctx=ctx)
    return DiscoveryInfo(rr.json())
Esempio n. 6
0
    mcu.reset()


# FORTEBIT CLOUD
try:
    from fortebit.polaris import cloud
    # get access token
    device_token = cloud.getAccessToken(minfo[0], mcu.uid())
    # NOTE! Do not disclose security token in production builds
    print("Access Token:", device_token)

    print("Connecting to Fortebit Cloud...")
    # retrieve the CA certificate used to sign the howsmyssl.com certificate
    cacert = __lookup(SSL_CACERT_DST_ROOT_CA_X3)
    # create a SSL context to require server certificate verification
    ctx = ssl.create_ssl_context(cacert=cacert, options=ssl.CERT_REQUIRED | ssl.SERVER_AUTH)
    # NOTE: if the underlying SSL driver does not support certificate validation
    #       uncomment the following line!
    # ctx = None
    
    from fortebit.iot import iot
    from fortebit.iot import mqtt_client
    # from fortebit.iot import http_client
    # let's create a device passing the token and the type of client
    device = iot.Device(device_token, mqtt_client.MqttClient, ctx)  # use ctx for TLS
    # device = iot.Device(device_token, http_client.HttpClient, ctx)  # use ctx for TLS
    
    utils.client = device.client

    # connect the device
    if not device.connect():
Esempio n. 7
0
group.add_argument('--browser',
                   dest='alerts',
                   action='append_const',
                   const=('browser', ),
                   help='open the Passkey website in the default browser')
group.add_argument('--email',
                   dest='alerts',
                   action=EmailAction,
                   nargs=3,
                   metavar=('HOST', 'FROM', 'TO'),
                   help='send an e-mail')

args = parser.parse_args()
startUrl = "https://aws.passkey.com/reg/%s/null/null/1/0/null" % args.key

sslCtx = create_ssl_context()
if not args.ssl_cert_verify:
    sslCtx.check_hostname = False
    sslCtx.verify_mode = CERT_NONE

# Attempt to check the version against Github, but ignore it if it fails
# Only updating the version when a breaking bug is fixed (a crash or a failure to search correctly)
try:
    version = open(pathjoin(dirname(abspath(__file__)), 'version')).read()
    resp = urlopen(
        'https://raw.githubusercontent.com/mrozekma/gencon-hotel-check/master/version',
        context=sslCtx)
    if resp.getcode() == 200:
        head = resp.read()
        if version != head:
            print "Warning: This script is out-of-date. If you downloaded it via git, use 'git pull' to fetch the latest version. Otherwise, visit https://github.com/mrozekma/gencon-hotel-check"
Esempio n. 8
0
 def __init__(self, device_label, user_type, api_token):
     self.ctx = ssl.create_ssl_context(
         options=ssl.CERT_NONE)  # TODO: add root cert
     self.mqtt = UbiMQTTClient(device_label, user_type, api_token, self.ctx)
     self.device_label = device_label
     self._variables_cbks = {}
Esempio n. 9
0
from blockchain.ethereum import ethereum
from blockchain.ethereum import rpc

# WiFi drivers
from espressif.esp32net import esp32wifi as net_driver  # for ESP-32
# from broadcom.bcm43362 import bcm43362 as net_driver # for Particle Photon
from wireless import wifi

# SSL module for https
import ssl

# Configuration file
import config

# The SSL context is needed to validate https certificates
SSL_CTX = ssl.create_ssl_context(cacert=config.CA_CERT,
                                 options=ssl.CERT_REQUIRED | ssl.SERVER_AUTH)

try:
    streams.serial()

    # Connect to WiFi network
    net_driver.auto_init()
    print("Connecting to wifi")
    wifi.link(config.WIFI_SSID, wifi.WIFI_WPA2, config.WIFI_PASSWORD)
    print("Connected!")
    print("Asking ethereum...")

    # Init the RPC node
    eth = rpc.RPC(config.RPC_URL, ssl_ctx=SSL_CTX)

    # Get our current balance
Esempio n. 10
0
PRIVATE_KEY = '0x8f9f54b9c3c3dda778faf1e0d17b6dd477051b5decbd88057008b4fc268d9232'

# Usually, no edits below this line is needed
CA_CERT = """-----BEGIN CERTIFICATE-----
MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF
ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6
b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL
MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv
b3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALJ4gHHKeNXj
ca9HgFB0fW7Y14h29Jlo91ghYPl0hAEvrAIthtOgQ3pOsqTQNroBvo3bSMgHFzZM
9O6II8c+6zf1tRn4SWiw3te5djgdYZ6k/oI2peVKVuRF4fn9tBb6dNqcmzU5L/qw
IFAGbHrQgLKm+a/sRxmPUDgH3KKHOVj4utWp+UhnMJbulHheb4mjUcAwhmahRWa6
VOujw5H5SNz/0egwLX0tdHA114gk957EWW67c4cX8jJGKLhD+rcdqsq08p8kDi1L
93FcXmn/6pUCyziKrlA4b9v7LWIbxcceVOF34GfID5yHI9Y/QCB/IIDEgEw+OyQm
jgSubJrIqg0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC
AYYwHQYDVR0OBBYEFIQYzIU07LwMlJQuCFmcx7IQTgoIMA0GCSqGSIb3DQEBCwUA
A4IBAQCY8jdaQZChGsV2USggNiMOruYou6r4lK5IpDB/G/wkjUu0yKGX9rbxenDI
U5PMCCjjmCXPI6T53iHTfIUJrU6adTrCC2qJeHZERxhlbI1Bjjt/msv0tadQ1wUs
N+gDS63pYaACbvXy8MWy7Vu33PqUXHeeE6V/Uq2V8viTO96LXFvKWlJbYK8U90vv
o/ufQJVtMVT8QtPHRh8jrdkPSHCa2XV4cdFyQzR1bldZwgJcJmApzyMZFo6IQ6XU
5MsI+yMRQ+hDKXJioaldXgjUkK642M4UwtBV8ob2xJNDd2ZhwLnoQdeXeGADbkpy
rqXRfboQnoZsG4q5WTP468SQvvG5
-----END CERTIFICATE-----
\x00"""

# The SSL context is needed to validate https certificates
ethereum_ctx = ssl.create_ssl_context(cacert=CA_CERT,
                                      options=ssl.CERT_REQUIRED
                                      | ssl.SERVER_AUTH)
rpc = erpc.RPC(RPC_URL, ssl_ctx=ethereum_ctx)