Пример #1
0
class DocumentTestCase(unittest.TestCase):
    def setUp(self):
        self.gpg = GPG()
        self.gpg.import_keys(PUB_KEY)

    def testGetCertificateID(self):
        "Test result value of document ID"
        source = DocumentSourceMock((200, CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE))
        document = Document(source)
        self.assertTrue(document.verify())
        self.assertEquals(document.get_id(), '64D0 F8CA 822B BDF0 FF59  42F6 A363 ED80 D8A5 CEFF')

    def testGetSignature(self):
        "Test result value of document signature"
        source = DocumentSourceMock((200, CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE))
        document = Document(source)
        self.assertTrue(document.verify())
        self.assertEquals(document.get_signature(), VALID_SIGNATURE)

    def testGetBody(self):
        "Test result value of document body"
        source = DocumentSourceMock((200, CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE))
        document = Document(source)
        self.assertTrue(document.verify())
        self.assertEquals(document.get_body(), VALID_BODY)

    def testGetRawData(self):
        "Test result value of document raw data"
        source = DocumentSourceMock((200, CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE))
        document = Document(source)
        self.assertTrue(document.verify())
        self.assertEquals(document.get_raw_data(), CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE)
Пример #2
0
 def verify(self):
     if self.data is None:
         return False
     if self.data[0] != 200:
         return None
     gpg = GPG()
     try:
         verified = gpg.verify(self.data[1])
     except Exception:
         return False
     return verified
Пример #3
0
class GPGTestCase(unittest.TestCase):
    def setUp(self):
        self.gpg = GPG()

    def testCorrectnessOfRFC1991LiteralDataPacket(self):
        "Test correctness of RFC1991 literal data packet generation"
        self.assertEquals(null_date(self.gpg.store(CERT).data), null_date(CERT_RFC1991_LITERAL_DATA_PACKET))
Пример #4
0
def make_document(data):
    """
    Make OpenPGP document containing one-pass signature packet,
    literal packet and binary signature packet

    See details in RFC4880
    """
    g = GPG()
    header = "%s%s" % (chr(144), chr(13)) #0x90 0x0D
    signature_packet = extract_signature_packet(extract_signature(data))
    body = strip_signature(data).rstrip()
    literal_packet = g.store(body).data
    one_pass_signature_packet = make_one_pass_signature_packet(signature_packet)
    return "%s%s%s%s" % (
        header,
        one_pass_signature_packet,
        literal_packet,
        signature_packet
    )
Пример #5
0
class DocumentVerificationTestCase(unittest.TestCase):

    def setUp(self):
        self.gpg = GPG()
        self.gpg.import_keys(PUB_KEY)

    def testCorrectCertificateWithValidSignature(self):
        "Test correct certificate with valid signature"
        source = DocumentSourceMock((200, CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE))
        document = Document(source)
        self.assertTrue(document.verify())

    def testCorrectCertificateWithInvalidSignature(self):
        "Test correct certificate with invalid signature"
        source = DocumentSourceMock((200, CORRECT_CERTIFICATE_WITH_INVALID_SIGNATURE))
        document = Document(source)
        self.assertFalse(document.verify())

    def testIncorrectCertificateWithValidSignature(self):
        "Test incorrect certificate with valid signature"
        source = DocumentSourceMock((200, INCORRECT_CERTIFICATE_WITH_VALID_SIGNATURE))
        document = Document(source)
        self.assertTrue(document.verify())
Пример #6
0
 def setUp(self):
     self.gpg = GPG()
     self.gpg.import_keys(PUB_KEY)
Пример #7
0
 def setUp(self):
     self.gpg = GPG()