added cryptotests
This commit is contained in:
parent
8022781a8f
commit
6dafcffd5a
@ -53,7 +53,7 @@ class OnionrCommunicate:
|
||||
highFailureRate = 10
|
||||
heartBeatTimer = 0
|
||||
heartBeatRate = 5
|
||||
pexTimer = 5 # How often we should check for new peers
|
||||
pexTimer = 10 # How often we should check for new peers
|
||||
pexCount = 0
|
||||
logger.debug('Communicator debugging enabled.')
|
||||
torID = open('data/hs/hostname').read()
|
||||
@ -223,7 +223,6 @@ class OnionrCommunicate:
|
||||
'''
|
||||
URL encodes the data
|
||||
'''
|
||||
|
||||
return urllib.parse.quote_plus(data)
|
||||
|
||||
def performGet(self, action, peer, data=None, skipHighFailureAddress=False, peerType='tor'):
|
||||
|
35
onionr/cryptotests.py
Executable file
35
onionr/cryptotests.py
Executable file
@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
'''
|
||||
Onionr - P2P Microblogging Platform & Social network
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import unittest, sys, os, core, onionrcrypto, logger
|
||||
|
||||
class OnionrCryptoTests(unittest.TestCase):
|
||||
def testSymmetric(self):
|
||||
dataString = "this is a secret message"
|
||||
dataBytes = dataString.encode()
|
||||
myCore = core.Core()
|
||||
crypto = onionrcrypto.OnionrCrypto(myCore)
|
||||
key = key = b"tttttttttttttttttttttttttttttttt"
|
||||
|
||||
logger.info("Encrypting: " + dataString)
|
||||
encrypted = crypto.symmetricEncrypt(dataString, key, returnEncoded=True)
|
||||
logger.info(encrypted)
|
||||
logger.info('Decrypting encrypted string:')
|
||||
decrypted = crypto.symmetricDecrypt(encrypted, key, encodedMessage=True)
|
||||
logger.info(decrypted)
|
||||
self.assertTrue(True)
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
@ -18,7 +18,7 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
# Misc functions that do not fit in the main api, but are useful
|
||||
import getpass, sys, requests, os, socket, hashlib, logger, sqlite3, config
|
||||
import getpass, sys, requests, os, socket, hashlib, logger, sqlite3, config, binascii
|
||||
import nacl.signing, nacl.encoding
|
||||
|
||||
if sys.version_info < (3, 6):
|
||||
@ -190,6 +190,8 @@ class OnionrUtils:
|
||||
nacl.signing.SigningKey(seed=key, encoder=nacl.encoding.Base32Encoder)
|
||||
except nacl.exceptions.ValueError:
|
||||
pass
|
||||
except binascii.Error:
|
||||
pass
|
||||
else:
|
||||
retVal = True
|
||||
return retVal
|
||||
|
Loading…
Reference in New Issue
Block a user