def add_post(self, post: Post) -> None: """ Before a post is added to the profile, it should be encrypted. Remember to take advantage of the code that is already written in the parent class. """ entry = post.get_entry() encrypted_entry = self.nacl_profile_encrypt(entry) post.set_entry(encrypted_entry) super().add_post(post)
def load_profile(self, path: str) -> None: """ Since the DS Server is now making use of encryption keys rather than username/password attributes, you will need to add support for storing a keypair in a dsu file. The best way to do this is to override the load_profile module and add any new attributes you wish to support. """ p = Path(path) if os.path.exists(p) and p.suffix == '.dsu': try: f = open(p, 'r') obj = json.load(f) self.username = obj['username'] self.password = obj['password'] self.dsuserver = obj['dsuserver'] self.bio = obj['bio'] self.import_keypair(obj['keypair']) for post_obj in obj['_posts']: post = Post(post_obj['entry'], post_obj['timestamp']) self._posts.append(post) f.close() except Exception as ex: raise DsuProfileError(ex) else: raise DsuFileError()
def _insert_post_tree(self, id, post: Post): # entry = post.get_entry() title = post.get_title() # Since we don't have a title, we will use the first 24 characters of a # post entry as the identifier in the post_tree widget. if len(title) > 25: title = title[:24] + "..." self.posts_tree.insert('', id, id, text=title)
def add_post(self, post: Post) -> Post: """ Before a post is added to the profile, it should be encrypted. Remember to take advantage of the code that is already written in the parent class. :return the post after encryption """ entry = post.get_entry() encrypted_entry = self.nacl_profile_encrypt(entry) post.set_entry(encrypted_entry) title = post.get_title() encrypted_title = self.nacl_profile_encrypt(title) post.set_title(encrypted_title) super().add_post(post) return post
def add_post_process(self): """ Adds the text currently in the entry_editor widget to the active DSU file. :return: """ from a5 import posts_transclude if self._profile_filename is None: self.footer.set_status('Create/Open a DSU file first!', color='red', change_back=True) else: post = Post() title = 'TYPE TITLE HERE' entry = 'TYPE ENTRY HERE' post.set_entry(entry) post.set_title(title) self._current_profile.add_post(post) self._current_profile = posts_transclude(self._current_profile) self._current_profile.save_profile(self._profile_filename) self.body.set_posts(self._current_profile.get_posts()) self.body.set_text_entry("") self.footer.set_status('Post added!', 'green', change_back=True)
# otherwise it's an empty string. if token != '': if send_type == 'p': post(sock, message, np) print_ok(done) elif send_type == 'b': _bio(sock, bio, np) print_ok(done) elif send_type == 'pb': post(sock, message, np) _bio(sock, bio, np) print_ok(done) else: print_error("Please provide a valid send type.\n" "Upload failed.") if __name__ == '__main__': np = NaClProfile.NaClProfile() kp = np.generate_keypair() sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((str(HOST), PORT)) username = '******' pwd = 'ffyuanda123' join(sock, username, pwd, np.public_key) from Profile import Post test_post = Post() test_post.set_entry('a4 test') post(sock, [test_post], np) _bio(sock, 'a4 test bio', np)
np = NaClProfile() kp = np.generate_keypair() print(np.public_key) print(np.private_key) print(np.keypair) # Test encryption with 3rd party public key ds_pubkey = "jIqYIh2EDibk84rTp0yJcghTPxMWjtrt5NW4yPZk3Cw=" ee = np.encrypt_entry("Encrypted Message for DS Server", ds_pubkey) print(ee) # print(np.nacl_profile_decrypt(ee, ds_pubkey)) np.private_key = "jIqYIh2EDibk84rTp0yJcghTPxMWjtrt5NW4yPZk3Cw=" # Add a post to the profile and check that it is decrypted. np.add_post(Post("Hello Salted World!")) p_list = np.get_posts() print(p_list[0].get_entry()) # Save the profile path = "C:\\Users\\ThinkPad\\Desktop\\test\\mark.dsu" np.save_profile(path) print("Open DSU file to check if message is encrypted.") input("Press Enter to Continue") # Create a new NaClProfile object and load the dsu file. np2 = NaClProfile() np2.load_profile(path) # print('np2 keypair:', np2.keypair, len(np2.keypair)) # Import the keys