コード例 #1
0
ファイル: CompatTest.py プロジェクト: morristech/TACKpy
    def test_Compat(self):
        assert (isinstance(a2b_hex("00"), bytearray))
        assert (a2b_hex("0102cdef") == bytearray([0x01, 0x02, 0xcd, 0xef]))
        assert (a2b_hex("0102CDEF") == bytearray([0x01, 0x02, 0xcd, 0xef]))
        try:
            assert (a2b_hex("c0102cdef") == bytearray([0x01, 0x02, 0xcd,
                                                       0xef]))
            assert False
        except SyntaxError:
            pass
        try:
            assert (a2b_hex("xx0102cdef") == bytearray(
                [0x01, 0x02, 0xcd, 0xef]))
            assert False
        except SyntaxError:
            pass

        assert (isinstance(a2b_base64("0000"), bytearray))
        assert (a2b_base64("Zm9vYg==") == bytearray(b"foob"))

        assert (b2a_hex(bytearray([0x01, 0x02, 0xcd, 0xef])) == "0102cdef")
        assert (b2a_hex(bytearray([0x00])) == "00")
        assert (b2a_hex(bytearray([0xFF])) == "ff")

        assert (b2a_base64(bytearray(b"foob")) == "Zm9vYg==\n")
        assert (b2a_base64(bytearray(b"fooba")) == "Zm9vYmE=\n")
        assert (b2a_base64(bytearray(b"foobar")) == "Zm9vYmFy\n")

        assert (bytesToStrAscii(bytearray(b"abcd123")) == "abcd123")
コード例 #2
0
ファイル: StructuresTest.py プロジェクト: morristech/TACKpy
    def test_Tack(self):
        s = """
-----BEGIN TACK-----
TAmsAZIpzR+MYwQrsujLhesvpu3dRc5ROhfgySqUVkU1p1hdXo+PwQrmaQo9B9+o
hecRrWElh3yThwgYQRgbSwAAAY0cQDHeDLGfKtuw0c17GzHvjuPrWbdEWa75S0gL
7u64XGTJQUtzAwXIWOkQEQ0BRUlbzcGEa9a1PBhjmmWFNF+kGAswhLnXc5qL4y/Z
PDUV0rzIIYjXP58T5pphGKRgLlK3Aw==
-----END TACK-----"""

        t = Tack().createFromPem(s)

        assert (t.public_key.getRawKey() == a2b_hex(
            "4c09ac019229cd1f8c63042bb2e8"
            "cb85eb2fa6eddd45ce513a17e0c9"
            "2a94564535a7585d5e8f8fc10ae6"
            "690a3d07dfa885e711ad6125877c"
            "9387081841181b4b"))
        assert (Time.posixTimeToStr(t.expiration * 60) == "2019-06-25T22:24Z")
        assert (t.generation == 0)
        assert (t.target_hash == a2b_hex(
            "31de0cb19f2adbb0d1cd7b1b31ef8ee3eb59b74459aef94b480beeeeb85c64c9")
                )
        assert (t.signature == a2b_hex("414b730305c858e910110d0145495"
                                       "bcdc1846bd6b53c18639a6585345f"
                                       "a4180b3084b9d7739a8be32fd93c3"
                                       "515d2bcc82188d73f9f13e69a6118"
                                       "a4602e52b703"))
コード例 #3
0
ファイル: CompatTest.py プロジェクト: kilink/TACKpy
    def test_Compat(self):
        assert(isinstance(a2b_hex("00"), bytearray))
        assert(a2b_hex("0102cdef") == bytearray([0x01,0x02,0xcd,0xef]))
        assert(a2b_hex("0102CDEF") == bytearray([0x01,0x02,0xcd,0xef]))
        try:
            assert(a2b_hex("c0102cdef") == bytearray([0x01,0x02,0xcd,0xef]))
            assert False
        except SyntaxError:
            pass
        try:
            assert(a2b_hex("xx0102cdef") == bytearray([0x01,0x02,0xcd,0xef]))
            assert False
        except SyntaxError:
            pass

        assert(isinstance(a2b_base64("0000"), bytearray))
        assert(a2b_base64("Zm9vYg==") == bytearray(b"foob"))

        assert(b2a_hex(bytearray([0x01,0x02,0xcd,0xef])) == "0102cdef")
        assert(b2a_hex(bytearray([0x00])) == "00")
        assert(b2a_hex(bytearray([0xFF])) == "ff")

        assert(b2a_base64(bytearray(b"foob")) == "Zm9vYg==\n")
        assert(b2a_base64(bytearray(b"fooba")) == "Zm9vYmE=\n")
        assert(b2a_base64(bytearray(b"foobar")) == "Zm9vYmFy\n")

        assert(bytesToStrAscii(bytearray(b"abcd123")) == "abcd123")
コード例 #4
0
ファイル: CryptoTest.py プロジェクト: morristech/TACKpy
    def test_AES(self):
        key = a2b_hex("c286696d887c9aa0611bbb3e2025a45a")
        IV = a2b_hex("562e17996d093d28ddb3ba695a2e6f58")
        plaintext = a2b_hex("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f")
        ciphertext = a2b_hex("d296cd94c2cccf8a3a863028b5e1dc0a7586602d253cfff91b8266bea6d61ab1")

        assert(AES(key, IV).encrypt(plaintext) == ciphertext)
        assert(AES(key, IV).decrypt(ciphertext) == plaintext)
コード例 #5
0
ファイル: PythonCrypto_Test.py プロジェクト: altoplano/TACKpy
    def test_PythonAES(self):
        key = a2b_hex("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4")
        IV = a2b_hex("000102030405060708090A0B0C0D0E0F")
        plaintext = a2b_hex("6bc1bee22e409f96e93d7e117393172a")
        ciphertext = a2b_hex("f58c4c04d6e5f1ba779eabfb5f7bfbd6")

        assert(Python_AES(key, IV).encrypt(plaintext) == ciphertext)
        assert(Python_AES(key, IV).decrypt(ciphertext) == plaintext)
コード例 #6
0
    def test_PythonAES(self):
        key = a2b_hex(
            "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4")
        IV = a2b_hex("000102030405060708090A0B0C0D0E0F")
        plaintext = a2b_hex("6bc1bee22e409f96e93d7e117393172a")
        ciphertext = a2b_hex("f58c4c04d6e5f1ba779eabfb5f7bfbd6")

        assert (Python_AES(key, IV).encrypt(plaintext) == ciphertext)
        assert (Python_AES(key, IV).decrypt(ciphertext) == plaintext)
コード例 #7
0
    def test_Certificate(self):
        s = """
-----BEGIN CERTIFICATE-----
MIIFSzCCBDOgAwIBAgIHJ6JvWHUrOTANBgkqhkiG9w0BAQUFADCByjELMAkGA1UE
BhMCVVMxEDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxGjAY
BgNVBAoTEUdvRGFkZHkuY29tLCBJbmMuMTMwMQYDVQQLEypodHRwOi8vY2VydGlm
aWNhdGVzLmdvZGFkZHkuY29tL3JlcG9zaXRvcnkxMDAuBgNVBAMTJ0dvIERhZGR5
IFNlY3VyZSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTERMA8GA1UEBRMI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znMCEGA1UdEQQaMBiCCyoudHJldnAubmV0ggl0cmV2cC5uZXQwHQYD
VR0OBBYEFCYv4a9+enZGS27wqAv+TPfJOOb7MA0GCSqGSIb3DQEBBQUAA4IBAQA+
2OKO77vpwKtoKddDtamBokiVhHrfw0c7ALGysOXtss1CKV2WgH4FdNuh9pFkVZB2
mKZ7keS7EMW11OzgBR3pRRk0AkNYtDsOJEXA2+1NLFgrtdujHrDX4WIoi9MGbqB5
TfK08XufM7OP3yXDLtMxyUtyjprFhdxPE+9p/GJ0IVdZrMmzYTjyCOO8+okY9zAQ
RVUKuxd+eEaH3BpPAau4MP2n24gy6WEsJ2auB81ee9fDnx/tfKPqvyuc4r4/Z4aL
5CvQvlPHaG/TTXXNh3pZFl3d/J5/76ZfeQzQtZ+dCrE4a4601Q4hBBXEq5gQfaof
H4yTGzfDv+JLIICAIcCs
-----END CERTIFICATE-----"""
        sslc = TlsCertificate.createFromPem(s)
        assert (sslc.key_sha256 == a2b_hex(
            "ffd30bcb84dbbc211a510875694354c58863d84fb7fc5853dfe36f4be2eb2e50")
                )
        assert (sslc.cert_sha256 == a2b_hex(
            "1a50e3de3a153f33b314b67c1aacc2f59fc99c49b8449c33dcc3665663e2bff1")
                )
        assert (Time.posixTimeToStr(sslc.notAfter,
                                    True) == "2012-07-08T00:19:57Z")

        # Write to binary and re-parse it, then check again
        b = sslc.serialize()
        sslc2 = TlsCertificate(b)
        assert (sslc2.key_sha256 == a2b_hex(
            "ffd30bcb84dbbc211a510875694354c58863d84fb7fc5853dfe36f4be2eb2e50")
                )
        assert (sslc2.cert_sha256 == a2b_hex(
            "1a50e3de3a153f33b314b67c1aacc2f59fc99c49b8449c33dcc3665663e2bff1")
                )
        assert (Time.posixTimeToStr(sslc2.notAfter,
                                    True) == "2012-07-08T00:19:57Z")

        return 1
コード例 #8
0
 def create(self, tackExt=None):
     self.tackExt = tackExt
     self.preExtBytes = a2b_hex(
         "a003020102020100300d06092a864886f70d0101050500300f310d300b06035504031"
         "3045441434b301e170d3031303730353138303534385a170d34343037303431383035"
         "34385a300f310d300b060355040313045441434b301f300d06092a864886f70d01010"
         "10500030e00300b0204010203050203010001")
     # Below is BasicConstraints, saving space by omitting
     #self.extBytes = binascii.a2b_hex(\
     #"300c0603551d13040530030101ff")
     self.extBytes = bytearray()
     self.postExtBytes = a2b_hex("300d06092a864886f70d01010505000303003993")
コード例 #9
0
ファイル: ECPrivateKey.py プロジェクト: kilink/TACKpy
    def _constructEcFromRawKeys(self, rawPrivateKey, rawPublicKey):
        assert(len(rawPrivateKey) == 32)
        assert(len(rawPublicKey) == 64)
        bytes1 = a2b_hex("02010104")
        bytes2 = a2b_hex("a00a06082a8648ce3d030107a14403420004")
        rawPrivateKey = toAsn1IntBytes(rawPrivateKey)
        b = bytes1 + asn1Length(len(rawPrivateKey)) + rawPrivateKey +\
            bytes2 + rawPublicKey
        b = bytearray([0x30]) + asn1Length(len(b)) + b
        pemPrivKeyBytes = PEMEncoder(b).getEncoded("EC PRIVATE KEY")

        return EC.load_key_bio(BIO.MemoryBuffer(pemPrivKeyBytes))
コード例 #10
0
    def _constructEcFromRawKeys(self, rawPrivateKey, rawPublicKey):
        assert (len(rawPrivateKey) == 32)
        assert (len(rawPublicKey) == 64)
        bytes1 = a2b_hex("02010104")
        bytes2 = a2b_hex("a00a06082a8648ce3d030107a14403420004")
        rawPrivateKey = toAsn1IntBytes(rawPrivateKey)
        b = bytes1 + asn1Length(len(rawPrivateKey)) + rawPrivateKey +\
            bytes2 + rawPublicKey
        b = bytearray([0x30]) + asn1Length(len(b)) + b
        pemPrivKeyBytes = PEMEncoder(b).getEncoded("EC PRIVATE KEY")

        return EC.load_key_bio(BIO.MemoryBuffer(pemPrivKeyBytes))
コード例 #11
0
ファイル: TlsCertificate.py プロジェクト: kilink/TACKpy
 def create(self, tackExt = None):
     self.tackExt = tackExt
     self.preExtBytes = a2b_hex(
         "a003020102020100300d06092a864886f70d0101050500300f310d300b06035504031"
         "3045441434b301e170d3031303730353138303534385a170d34343037303431383035"
         "34385a300f310d300b060355040313045441434b301f300d06092a864886f70d01010"
         "10500030e00300b0204010203050203010001")
     # Below is BasicConstraints, saving space by omitting
     #self.extBytes = binascii.a2b_hex(\
     #"300c0603551d13040530030101ff")
     self.extBytes = bytearray()
     self.postExtBytes = a2b_hex(
         "300d06092a864886f70d01010505000303003993")
コード例 #12
0
ファイル: ECPublicKey.py プロジェクト: kilink/TACKpy
    def _constructEcFromRawKey(self, rawPublicKey):
        assert(len(rawPublicKey) == 64)
        bytes1         = a2b_hex("3059301306072a8648ce3d020106082a8648ce3d03010703420004")
        asn1KeyBytes   = bytes1 + rawPublicKey
        pemPubKeyBytes = PEMEncoder(asn1KeyBytes).getEncoded("PUBLIC KEY")

        return EC.load_pub_key_bio(BIO.MemoryBuffer(pemPubKeyBytes))
コード例 #13
0
    def create(cls, tackExt=None):
        tlsCert = cls()
        tlsCert.tackExt = tackExt
        tlsCert.preExtBytes = a2b_hex(
            "a003020102020100300d06092a864886f70d0101050500300f310d300b06035504031"
            "3045441434b301e170d3031303730353138303534385a170d34343037303431383035"
            "34385a300f310d300b060355040313045441434b301f300d06092a864886f70d01010"
            "10500030e00300b0204010203050203010001")
        # Below is BasicConstraints, saving space by omitting
        #self.extBytes = binascii.a2b_hex(\
        #"300c0603551d13040530030101ff")
        tlsCert.extBytes = bytearray()
        tlsCert.postExtBytes = a2b_hex(
            "300d06092a864886f70d01010505000303003993")

        # Parse the cert to populate its key_sha256, cert_sha256, and notAfter
        return cls(tlsCert.serialize())
コード例 #14
0
ファイル: TlsCertificate.py プロジェクト: digideskio/tackpy
    def create(cls, tackExt = None):
        tlsCert = cls()
        tlsCert.tackExt = tackExt
        tlsCert.preExtBytes = a2b_hex(
            "a003020102020100300d06092a864886f70d0101050500300f310d300b06035504031"
            "3045441434b301e170d3031303730353138303534385a170d34343037303431383035"
            "34385a300f310d300b060355040313045441434b301f300d06092a864886f70d01010"
            "10500030e00300b0204010203050203010001")
        # Below is BasicConstraints, saving space by omitting
        #self.extBytes = binascii.a2b_hex(\
        #"300c0603551d13040530030101ff")
        tlsCert.extBytes = bytearray()
        tlsCert.postExtBytes = a2b_hex(
            "300d06092a864886f70d01010505000303003993")

        # Parse the cert to populate its key_sha256, cert_sha256, and notAfter
        return cls(tlsCert.serialize())
コード例 #15
0
ファイル: Certificate_Test.py プロジェクト: altoplano/TACKpy
    def test_Certificate(self):
        s = """
-----BEGIN CERTIFICATE-----
MIIFSzCCBDOgAwIBAgIHJ6JvWHUrOTANBgkqhkiG9w0BAQUFADCByjELMAkGA1UE
BhMCVVMxEDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxGjAY
BgNVBAoTEUdvRGFkZHkuY29tLCBJbmMuMTMwMQYDVQQLEypodHRwOi8vY2VydGlm
aWNhdGVzLmdvZGFkZHkuY29tL3JlcG9zaXRvcnkxMDAuBgNVBAMTJ0dvIERhZGR5
IFNlY3VyZSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTERMA8GA1UEBRMIMDc5Njky
ODcwHhcNMTEwNzA4MDAxOTU3WhcNMTIwNzA4MDAxOTU3WjBPMRQwEgYDVQQKFAsq
LnRyZXZwLm5ldDEhMB8GA1UECxMYRG9tYWluIENvbnRyb2wgVmFsaWRhdGVkMRQw
EgYDVQQDFAsqLnRyZXZwLm5ldDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
ggEBAMgawQKi4zY4TTz1RNL7klt/ibvjG+jGqBYlc6qjUiTQORD3fUrdAF83Alav
JiC3rrwfvarL8KpPn7zQQOOk+APwzFxn0sVphDvAN8E7xI/cC7es08EYA9/DDN7r
VTe/wvbs77CL5AniRSJyAP5puvSUHgixingTgYmnkIgC+3ZFqyfz2uenxvkPkoUT
QEBkm2uEcBOwBMXAih1fdsuhEiJ9qpmejpIEvxLIDoMnCWTPs897zhwr3epQkn5g
lKQ9H+FnEo5Jf8YBM4YhAzwG/8pyfc8NtOHafKUb5PhSIC7Vy7N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slc.key_sha256 == a2b_hex("ffd30bcb84dbbc211a510875694354c58863d84fb7fc5853dfe36f4be2eb2e50"))
        assert(sslc.cert_sha256 == a2b_hex("1a50e3de3a153f33b314b67c1aacc2f59fc99c49b8449c33dcc3665663e2bff1"))
        assert(Time.posixTimeToStr(sslc.notAfter, True) == "2012-07-08T00:19:57Z")
        
        # Write to binary and re-parse it, then check again
        b = sslc.serialize()
        sslc2 = TlsCertificate(b)
        assert(sslc2.key_sha256 == a2b_hex("ffd30bcb84dbbc211a510875694354c58863d84fb7fc5853dfe36f4be2eb2e50"))
        assert(sslc2.cert_sha256 == a2b_hex("1a50e3de3a153f33b314b67c1aacc2f59fc99c49b8449c33dcc3665663e2bff1"))
        assert(Time.posixTimeToStr(sslc2.notAfter, True) == "2012-07-08T00:19:57Z")
        
        return 1
コード例 #16
0
    def _constructEcFromRawKey(self, rawPublicKey):
        assert (len(rawPublicKey) == 64)
        bytes1 = a2b_hex(
            "3059301306072a8648ce3d020106082a8648ce3d03010703420004")
        asn1KeyBytes = bytes1 + rawPublicKey
        pemPubKeyBytes = PEMEncoder(asn1KeyBytes).getEncoded("PUBLIC KEY")

        return EC.load_pub_key_bio(BIO.MemoryBuffer(pemPubKeyBytes))
コード例 #17
0
ファイル: StructuresTest.py プロジェクト: kilink/TACKpy
 def test_KeyFile(self):
     s = """
 -----BEGIN TACK PRIVATE KEY-----
 AQAAIAAjOxiOdpiMo5qWidXwBTqJHxW5X1zRDBOA4ldqqFuKOSh6JJdrbXk1WsMN
 X/gyaVuHMBhC/g/rjtu/EnmIHoUuT9348iXeeROaLVRPdNqwr+5KEfjtTY7uXA6Q
 mhRUn+XmDePKRucRHYkcQaFPnzglrQ120Dh6aXD4PbtJMWajJtzTMvtEo9pNZhoM
 QTNZNoM=
 -----END TACK PRIVATE KEY-----"""
     publicKey = a2b_hex("87301842fe0feb8edbbf1279881e852e"
                         "4fddf8f225de79139a2d544f74dab0af"
                         "ee4a11f8ed4d8eee5c0e909a14549fe5"
                         "e60de3ca46e7111d891c41a14f9f3825")
     privateKey = a2b_hex("fc815de8b1de13a436e9cd69742cbf2c"
                          "d4c1c9bb33e023401d9291cf2781b754")
     kf = TackKeyFile.createFromPem(s, "asdf")
     assert(kf.getPublicKey().getRawKey() == publicKey)
     assert(kf.getPrivateKey().getRawKey() == privateKey)
     kf2 = TackKeyFile.createFromPem(kf.serializeAsPem(), "asdf")
     assert(kf2.getPublicKey().getRawKey() == publicKey)
     assert(kf2.getPrivateKey().getRawKey() == privateKey)
     kf3 = TackKeyFile.createRandom("123")
     kf4 = TackKeyFile.createFromPem(kf3.serializeAsPem(), "123")
     assert(kf3.getPublicKey().getRawKey() == kf4.getPublicKey().getRawKey())
コード例 #18
0
 def test_KeyFile(self):
     s = """
 -----BEGIN TACK PRIVATE KEY-----
 AQAAIAAjOxiOdpiMo5qWidXwBTqJHxW5X1zRDBOA4ldqqFuKOSh6JJdrbXk1WsMN
 X/gyaVuHMBhC/g/rjtu/EnmIHoUuT9348iXeeROaLVRPdNqwr+5KEfjtTY7uXA6Q
 mhRUn+XmDePKRucRHYkcQaFPnzglrQ120Dh6aXD4PbtJMWajJtzTMvtEo9pNZhoM
 QTNZNoM=
 -----END TACK PRIVATE KEY-----"""
     publicKey = a2b_hex("87301842fe0feb8edbbf1279881e852e"
                         "4fddf8f225de79139a2d544f74dab0af"
                         "ee4a11f8ed4d8eee5c0e909a14549fe5"
                         "e60de3ca46e7111d891c41a14f9f3825")
     privateKey = a2b_hex("fc815de8b1de13a436e9cd69742cbf2c"
                          "d4c1c9bb33e023401d9291cf2781b754")
     kf = TackKeyFile.createFromPem(s, "asdf")
     assert(kf.getPublicKey().getRawKey() == publicKey)
     assert(kf.getPrivateKey().getRawKey() == privateKey)
     kf2 = TackKeyFile.createFromPem(kf.serializeAsPem(), "asdf")
     assert(kf2.getPublicKey().getRawKey() == publicKey)
     assert(kf2.getPrivateKey().getRawKey() == privateKey)
     public_key, private_key = ECGenerator.generateECKeyPair()
     kf3  = TackKeyFile.create(public_key, private_key, "123")
     kf4 = TackKeyFile.createFromPem(kf3.serializeAsPem(), "123")
     assert(kf3.getPublicKey().getRawKey() == kf4.getPublicKey().getRawKey())
コード例 #19
0
ファイル: Structures_Test.py プロジェクト: digideskio/tackpy
    def test_Tack(self):
        s = """
-----BEGIN TACK-----
TAmsAZIpzR+MYwQrsujLhesvpu3dRc5ROhfgySqUVkU1p1hdXo+PwQrmaQo9B9+o
hecRrWElh3yThwgYQRgbSwAAAY0cQDHeDLGfKtuw0c17GzHvjuPrWbdEWa75S0gL
7u64XGTJQUtzAwXIWOkQEQ0BRUlbzcGEa9a1PBhjmmWFNF+kGAswhLnXc5qL4y/Z
PDUV0rzIIYjXP58T5pphGKRgLlK3Aw==
-----END TACK-----"""

        t = Tack().createFromPem(s)

        assert(t.public_key.getRawKey() == a2b_hex("4c09ac019229cd1f8c63042bb2e8"
                                       "cb85eb2fa6eddd45ce513a17e0c9"
                                       "2a94564535a7585d5e8f8fc10ae6"
                                       "690a3d07dfa885e711ad6125877c"
                                       "9387081841181b4b"))
        assert(Time.posixTimeToStr(t.expiration*60) == "2019-06-25T22:24Z")
        assert(t.generation == 0)
        assert(t.target_hash == a2b_hex("31de0cb19f2adbb0d1cd7b1b31ef8ee3eb59b74459aef94b480beeeeb85c64c9"))
        assert(t.signature == a2b_hex("414b730305c858e910110d0145495"
                                      "bcdc1846bd6b53c18639a6585345f"
                                      "a4180b3084b9d7739a8be32fd93c3"
                                      "515d2bcc82188d73f9f13e69a6118"
                                      "a4602e52b703"))
コード例 #20
0
ファイル: StructuresTest.py プロジェクト: morristech/TACKpy
    def test_BreakSig(self):
        s = """
-----BEGIN TACK BREAK SIG-----
TAmsAZIpzR+MYwQrsujLhesvpu3dRc5ROhfgySqUVkU1p1hdXo+PwQrmaQo9B9+o
hecRrWElh3yThwgYQRgbS0HynTQCmrY48oJsQtarSMoxnRNYHaaYOXwu9+4ur8mX
wjKhIA9fXWNxuP73ZoicU+qC4bZjMN+WKuy7k8bSQZY=
-----END TACK BREAK SIG-----"""

        tbs = TackBreakSig.createFromPem(s)
        assert (tbs.getTackId() == "nkufh.czttd.5cmlw.7cxtv.k6srn")
        assert (tbs.signature == a2b_hex("41f29d34029ab638f2826c42d6a"
                                         "b48ca319d13581da698397c2ef7"
                                         "ee2eafc997c232a1200f5f5d637"
                                         "1b8fef766889c53ea82e1b66330"
                                         "df962aecbb93c6d24196"))
コード例 #21
0
ファイル: Structures_Test.py プロジェクト: altoplano/TACKpy
    def test_BreakSig(self):
        s = """
-----BEGIN TACK BREAK SIG-----
TAmsAZIpzR+MYwQrsujLhesvpu3dRc5ROhfgySqUVkU1p1hdXo+PwQrmaQo9B9+o
hecRrWElh3yThwgYQRgbS0HynTQCmrY48oJsQtarSMoxnRNYHaaYOXwu9+4ur8mX
wjKhIA9fXWNxuP73ZoicU+qC4bZjMN+WKuy7k8bSQZY=
-----END TACK BREAK SIG-----"""

        tbs = TackBreakSig.createFromPem(s)
        assert(tbs.getTackId() == "nkufh.czttd.5cmlw.7cxtv.k6srn")
        assert(tbs.signature == a2b_hex("41f29d34029ab638f2826c42d6a"
                                        "b48ca319d13581da698397c2ef7"
                                        "ee2eafc997c232a1200f5f5d637"
                                        "1b8fef766889c53ea82e1b66330"
                                        "df962aecbb93c6d24196"))