-
Notifications
You must be signed in to change notification settings - Fork 789
Secrets Cleanup: L, M and O #3001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,15 +31,11 @@ | |
DISPLAY_RATE = 1 # screen refresh rate | ||
#------------------------------------------------------------------------- | ||
|
||
# Get secrets from a secrets.py file | ||
# Get totp_keys from a totp_keys.py file | ||
try: | ||
from secrets import secrets | ||
totp_keys = secrets["totp_keys"] | ||
from totp_keys import totp_keys | ||
except ImportError: | ||
print("Secrets are kept in secrets.py, please add them there!") | ||
raise | ||
except KeyError: | ||
print("TOTP info not found in secrets.py.") | ||
print("TOTP info not found in totp_keys.py, please add them there!") | ||
raise | ||
|
||
# set board to use PCF8523 as its RTC | ||
|
@@ -80,7 +76,9 @@ | |
rtc_time.anchor_point = (0.0, 0.5) | ||
rtc_time.anchored_position = (0, 59) | ||
|
||
progress_bar = HorizontalProgressBar((68, 46), (55, 17), bar_color=0xFFFFFF, min_value=0, max_value=30) | ||
progress_bar = HorizontalProgressBar( | ||
(68, 46), (55, 17), bar_color=0xFFFFFF, min_value=0, max_value=30 | ||
) | ||
|
||
splash = displayio.Group() | ||
splash.append(name) | ||
|
@@ -172,15 +170,15 @@ def generate_otp(int_input, secret_key, digits=6): | |
int_to_bytestring(int_input)).digest() | ||
) | ||
offset = hmac_hash[-1] & 0xf | ||
code = ((hmac_hash[offset] & 0x7f) << 24 | | ||
(hmac_hash[offset + 1] & 0xff) << 16 | | ||
(hmac_hash[offset + 2] & 0xff) << 8 | | ||
(hmac_hash[offset + 3] & 0xff)) | ||
str_code = str(code % 10 ** digits) | ||
while len(str_code) < digits: | ||
str_code = '0' + str_code | ||
otp_code = ((hmac_hash[offset] & 0x7f) << 24 | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reuse of |
||
(hmac_hash[offset + 1] & 0xff) << 16 | | ||
(hmac_hash[offset + 2] & 0xff) << 8 | | ||
(hmac_hash[offset + 3] & 0xff)) | ||
str_otp_code = str(otp_code % 10 ** digits) | ||
while len(str_otp_code) < digits: | ||
str_otp_code = '0' + str_otp_code | ||
|
||
return str_code | ||
return str_otp_code | ||
|
||
#------------------------------------------------------------------------- | ||
# M A C R O P A D S E T U P | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# SPDX-FileCopyrightText: 2021 Carter Nelson for Adafruit Industries | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed and updated from secrets.py per conversation on Discord |
||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
# This file contains totp codes! | ||
# If you put them in the code you risk committing that info or sharing it | ||
|
||
# tuples of name, key, color | ||
totp_keys = [ | ||
("Github", "JBSWY3DPEHPK3PXP", 0x8732A8), | ||
("Discord", "JBSWY3DPEHPK3PXQ", 0x32A89E), | ||
("Slack", "JBSWY5DZEHPK3PXR", 0xFC861E), | ||
("Basecamp", "JBSWY6DZEHPK3PXS", 0x55C24C), | ||
("Gmail", "JBSWY7DZEHPK3PXT", 0x3029FF), | ||
None, | ||
None, # must have 12 entires | ||
None, # set None for unused keys | ||
None, | ||
("Hello Kitty", "JBSWY7DZEHPK3PXU", 0xED164F), | ||
None, | ||
None, | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
# SPDX-FileCopyrightText: 2021 Brent Rubell, written for Adafruit Industries | ||
# | ||
# SPDX-License-Identifier: Unlicense | ||
|
||
from os import getenv | ||
from adafruit_oauth2 import OAuth2 | ||
from adafruit_display_text.label import Label | ||
from adafruit_bitmap_font import bitmap_font | ||
from adafruit_magtag.magtag import Graphics, Network | ||
from adafruit_display_shapes.rect import Rect | ||
|
||
# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and | ||
# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other | ||
# source control. | ||
# pylint: disable=no-name-in-module,wrong-import-order | ||
try: | ||
from secrets import secrets | ||
except ImportError: | ||
print("Credentials and tokens are kept in secrets.py, please add them there!") | ||
raise | ||
# Get WiFi details, ensure these are setup in settings.toml | ||
ssid = getenv("CIRCUITPY_WIFI_SSID") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. many |
||
password = getenv("CIRCUITPY_WIFI_PASSWORD") | ||
|
||
if None in [ssid, password]: | ||
raise RuntimeError( | ||
"WiFi settings are kept in settings.toml, " | ||
"please add them there. The settings file must contain " | ||
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " | ||
"at a minimum." | ||
) | ||
|
||
network = Network() | ||
network.connect() | ||
|
@@ -57,8 +61,8 @@ | |
# Initialize an OAuth2 object | ||
google_auth = OAuth2( | ||
network.requests, | ||
secrets["google_client_id"], | ||
secrets["google_client_secret"], | ||
getenv("google_client_id"), | ||
getenv("google_client_secret"), | ||
scopes, | ||
) | ||
|
||
|
@@ -90,16 +94,16 @@ | |
raise RuntimeError("Timed out waiting for browser response!") | ||
|
||
print("Successfully Authenticated with Google!") | ||
print("Add the following lines to your secrets.py file:") | ||
print("\t'google_access_token' " + ":" + " '%s'," % google_auth.access_token) | ||
print("\t'google_refresh_token' " + ":" + " '%s'" % google_auth.refresh_token) | ||
print("Add the following lines to your settings.toml file:") | ||
print(f'google_access_token="{google_auth.access_token}"') | ||
print(f'google_refresh_token="{google_auth.refresh_token}"') | ||
|
||
graphics.splash.pop() | ||
graphics.splash.pop() | ||
graphics.splash.pop() | ||
|
||
label_overview_text.text = "Successfully Authenticated!" | ||
label_verification_url.text = ( | ||
"Check the REPL for tokens to add\n\tto your secrets.py file" | ||
"Check the REPL for tokens to add\n\tto your settings.toml file" | ||
) | ||
display.refresh() |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# SPDX-FileCopyrightText: 2020 Eva Herrada for Adafruit Industries | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
# This file is where you keep private settings, passwords, and tokens! | ||
# If you put them in the code you risk committing that info or sharing it | ||
|
||
CIRCUITPY_WIFI_SSID="your-wifi-ssid" | ||
CIRCUITPY_WIFI_PASSWORD="your-wifi-password" | ||
ADAFRUIT_AIO_USERNAME="my_username" | ||
ADAFRUIT_AIO_KEY="my_key" | ||
timezone="America/New_York" # http://worldtimeapi.org/timezones | ||
openweather_token="my_openweather_token" | ||
openweather_location="New York City, US" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
linting