コード例 #1
0
ファイル: packets.py プロジェクト: tengel/openpgp-pseudonyms
 def rep(self, passphrase=None, algorithm=crypto.SYMALGORITHM_AES256):
     passphrase = self.passphrase
     keydata = self.d.rep() + self.p.rep() + self.q.rep() + self.u.rep()
     s2kPart = '\x00'
     if passphrase is not None and len(passphrase) > 0:
         iv = crypto.randomBytes(crypto.SYMALGORITHM_BLOCKSIZE[algorithm])
         s2k = S2KElement()
         s2kPart = '\xfe' + chr(algorithm) + s2k.rep() + iv
         keydata += crypto.hash_sha1(keydata)
         keydata = crypto.encryptCFB(s2k.generateKey(passphrase, algorithm),
                                     keydata, iv, algorithm)
     else:
         keydata += '\x00\x00'
     data = (self.version.rep(1) + self.created.rep() + self.algorithm.rep(1) +
             self.n.rep() + self.e.rep() + s2kPart + keydata)
     return Packet.createHeader(self.TAG, len(data)) + data
コード例 #2
0
ファイル: blinding.py プロジェクト: tengel/openpgp-pseudonyms
def blind(publicKey, sigTime, data):
    keyID = publicKey.packets[TAG_PUBKEY].keyID()
    n = publicKey.packets[TAG_PUBKEY].n
    e = publicKey.packets[TAG_PUBKEY].e

    if sigTime is None:
        sigTime = _randomTime(publicKey.creationTime(), publicKey.expirationTime())

    sigPacket = _prepareSignature(crypto.HASH_SHA256, sigTime, keyID)
    sigdata = data + sigPacket.hashdata()
    plainhash = crypto.hash(sigdata, sigPacket.hashAlgorithm.value)
    codedhash = encoding.pkcs15(plainhash, n.bits(), sigPacket.hashAlgorithm.value)
    m = elements.ScalarElement(codedhash).value

    while True:
        r = elements.ScalarElement(crypto.randomBytes(n.octets())).value
        if r > 1 and r < n.value and crypto.gcd(n.value, r) == 1:
            break

    packet = packets.BlindMessagePacket()
    packet.m = elements.MPIElement(crypto.rsaBlind(m, r, e.value, n.value))
    return r, plainhash[0:2], sigTime, messages.BlindMessageMessage.fromPackets((packet,))
コード例 #3
0
ファイル: elements.py プロジェクト: tengel/openpgp-pseudonyms
 def __init__(self, s=None):
     if isinstance(s, basestring):
         s = io.BytesIO(s)
     if isinstance(s, io.BytesIO):
         self.specifier = ord(s.read(1))
         if self.specifier == 0:
             # Simple S2K
             raise Exception('not implemented')
         elif self.specifier == 1:
             # Salted S2K
             raise Exception('not implemented')
         elif self.specifier == 3:
             # Iterated and Salted S2K
             self.hashalgorithm = ord(s.read(1))
             self.salt = s.read(8)
             c = ord(s.read(1))
             self.count = (16 + (c & 15)) << ((c >> 4) + 6);
     if s is None:
         self.specifier = 3
         self.hashalgorithm = crypto.HASH_SHA1
         self.salt = crypto.randomBytes(8)
         self.count = 65536
コード例 #4
0
print '[+] Generating Master Key...'
MASTER_KEY = crypto.genOptimalKey()

print '[+] Creating "seeker" account...'

while True:
    password = getpass.getpass('Please enter "seeker" password: '******'Repeat: ')

    if password == password2:
        break

print '[+] Encrypting Master Key for "seeker"...'

KDFSalt = crypto.randomBytes(crypto.SALT_LENGTH)
keyFromPassword = crypto.keyFromText(password, KDFSalt)
EMK = crypto.encrypt(MASTER_KEY, keyFromPassword)

print '[+] Storing Master Key checksum...'
cksum = checksum(MASTER_KEY)
gc = GlobalConfig(key='master_key_checksum', value=cksum)
session.add(gc)

del MASTER_KEY

u = User(username='******',
         password=hashPassword(password),
         email='root@localhost',
         active=True,
         encrypted_master_key=EMK,
コード例 #5
0
 def testRandom(self):
     r1 = crypto.randomBytes(10)
     self.assertEqual(len(r1), 10)
     r2 = crypto.randomBytes(10)
     self.assertEqual(len(r2), 10)
     self.assertTrue(r1 != r2)
コード例 #6
0
ファイル: init.py プロジェクト: Nervous/certitude
print '[+] Generating Master Key...'
MASTER_KEY = crypto.genOptimalKey()

print '[+] Creating "seeker" account...'

while True:
    password = getpass.getpass('Please enter "seeker" password: '******'Repeat: ')

    if password==password2:
        break

print '[+] Encrypting Master Key for "seeker"...'

KDFSalt = crypto.randomBytes(crypto.SALT_LENGTH)
keyFromPassword = crypto.keyFromText(password, KDFSalt)
EMK = crypto.encrypt(MASTER_KEY, keyFromPassword)

print '[+] Storing Master Key checksum...'
cksum = checksum(MASTER_KEY)
gc = GlobalConfig(
            key = 'master_key_checksum',
            value = cksum
            )
session.add(gc)

del MASTER_KEY

u = User(
            username = '******',