def acquireSignature(self, nym, auth): if self.caKey is None: raise Exception('no public key') r, hashTwo, sigTime, blinded = blinding.blind(self.caKey, None, nym) data, result = self._sendRequest(auth, blinded.rep()) if data is None or result != 'ok': return None, result blindSig = OpenPGP.messages.fromRadix64(data) sig = blinding.unblind(self.caKey, sigTime, r, hashTwo, blindSig) return sig, result
def testCASign(self): caConfig = blindca.Config() caConfig.secretKey = 'testdata/foo-bar.com_secret_openpgp.txt' caConfig.publicKey = 'testdata/foo-bar.com_public_openpgp.txt' ca = blindca.BlindCA(caConfig) publicKey = messages.fromRadix64( open('testdata/foo-bar.com_public_openpgp.txt', 'r').read()) data = 'The quick brown fox jumps over the lazy dog\n' r, hashtwo, sigTime, blinded = blinding.blind(publicKey, None, data) blindSig = ca.sign(blinded) sig = blinding.unblind(publicKey, sigTime, r, hashtwo, blindSig) self.assertTrue(verifySignature(data, sig, publicKey)) self.assertTrue(sigTime.value >= publicKey.creationTime().value) self.assertTrue(sigTime.value <= publicKey.expirationTime().value)
def testBlinding(self): secretKey = messages.fromRadix64( open('testdata/foo-bar.com_secret_openpgp.txt', 'r').read()) publicKey = messages.fromRadix64( open('testdata/foo-bar.com_public_openpgp.txt', 'r').read()) data = 'The quick brown fox jumps over the lazy dog\n' sigTime = elements.TimeElement.now() r, hashTwo, newSigTime, blinded = blinding.blind(publicKey, sigTime, data) self.assertEqual(sigTime.value, newSigTime.value) blindSig = crypto.rsaSign(blinded.packets[TAG_BLINDMSG].m.value, secretKey.packets[TAG_SECKEY].d.value, publicKey.packets[TAG_PUBKEY].n.value) packet = packets.BlindSignaturePacket() packet.s = elements.MPIElement(blindSig) message = messages.BlindSignatureMessage.fromPackets((packet,)) s = blinding.unblind(publicKey, sigTime, r, hashTwo, message) self.assertTrue(verifySignature(data, s, publicKey))
along with this program. If not, see <http://www.gnu.org/licenses/>. """ import sys from OpenPGP import * import blinding if len(sys.argv) != 3 and len(sys.argv) != 4: print >>sys.stderr, 'usage: blind.py <RANDOMFILE> <PUBKEYFILE> [<TIME>]' sys.exit(2) publicKey = messages.fromRadix64(open(sys.argv[2], 'r').read()) message = sys.stdin.read() if len(sys.argv) == 4: sigTime = elements.TimeElement(int(sys.argv[3])) else: sigTime = None r, hashtwo, sigTime, blinded = blinding.blind(publicKey, sigTime, message) randfile = open(sys.argv[1], 'w') randfile.write(elements.ScalarElement(r).rep().encode('hex') + '\n') randfile.write(hashtwo.encode('hex') + '\n') randfile.write('%d\n' % sigTime.value) randfile.close() #print >>sys.stderr, blinded print blinded.rep()