Beispiel #1
0
    def __init__(self, data=None, password=None):
        if data is None:
            return

        TlsStructure.__init__(self, data)
        if len(data) != TackKeyFile.LENGTH:
            raise SyntaxError(
                "Key File is the wrong size. Is %s and should be %s." %
                (len(data), TackKeyFile.LENGTH))

        self.version = self.getInt(1)

        if self.version != 1:
            raise SyntaxError("Bad version in Key File")

        self.iter_count = self.getInt(4)
        self.salt = self.getBytes(16)
        self.ciphertext = self.getBytes(32)
        self.public_key = ECPublicKey.create(self.getBytes(64))
        self.mac = self.getBytes(32)

        if password is not None:
            rawPrivateKey = self._decrypt(password)
            self.private_key = ECPrivateKey.create(rawPrivateKey,
                                                   self.public_key.getRawKey())
Beispiel #2
0
 def getChild(self, which):
     p = TlsStructure(self.value)
     for x in range(which+1):
         if p.index == len(p.bytes):
             return None
         markIndex = p.index
         p.getInt(1) #skip Type
         length = self._getASN1Length(p)
         p.getBytes(length)
     return ASN1Parser(p.bytes[markIndex : p.index],
                       self.offset + self.headerLength + markIndex)
Beispiel #3
0
    def __init__(self, data=None):
        TlsStructure.__init__(self, data)
        if data is not None:
            self.tack           = self._parseTack()
            self.break_sigs     = self._parseBreakSigs()
            self.pin_activation = self.getInt(1)

            if self.pin_activation not in TackActivation.ALL:
                raise SyntaxError("Bad pin_activation value")

            if self.index != len(data):
                raise SyntaxError("Excess bytes in TACK_Extension")
Beispiel #4
0
    def __init__(self, data=None):
        if data is None:
            return

        TlsStructure.__init__(self, data)
        if len(data) != TackBreakSig.LENGTH:
            raise SyntaxError("Break signature is the wrong size. Is %s and should be %s." % (len(data), TackBreakSig.LENGTH))

        self.public_key = ECPublicKey.create(self.getBytes(64))
        self.signature  = self.getBytes(64)
            
        if not self.verifySignature():
            raise SyntaxError("TACK_Break_Sig has bad signature")
Beispiel #5
0
    def __init__(self, data=None):
        if data is None:
            return

        TlsStructure.__init__(self, data)
        self.tacks            = self._parseTacks()
        self.activation_flags = self.getInt(1)

        if self.activation_flags > 3:
            raise SyntaxError("Bad activation_flag value")

        if self.index != len(data):
            raise SyntaxError("Excess bytes in TACK_Extension")
Beispiel #6
0
    def __init__(self, data=None):
        if data is None:
            return

        TlsStructure.__init__(self, data)
        self.tacks = self._parseTacks()
        self.activation_flags = self.getInt(1)

        if self.activation_flags > 3:
            raise SyntaxError("Bad activation_flag value")

        if self.index != len(data):
            raise SyntaxError("Excess bytes in TACK_Extension")
Beispiel #7
0
    def __init__(self, data=None):
        TlsStructure.__init__(self, data)
        if data is not None:
            self.public_key     = ECPublicKey(self.getBytes(64))
            self.min_generation = self.getInt(1)
            self.generation     = self.getInt(1)
            self.expiration     = self.getInt(4)
            self.target_hash    = self.getBytes(32)
            self.signature      = self.getBytes(64)

            if not self._verifySignature():
                raise SyntaxError("Signature verification failure")
            if self.index != len(data):
                raise SyntaxError("Excess bytes in TACK")
Beispiel #8
0
    def __init__(self, data=None):
        TlsStructure.__init__(self, data)

        if data is not None and len(data) != TackBreakSig.LENGTH:
            raise SyntaxError("Break signature is the wrong size. Is %s and should be %s." % (len(data), TackBreakSig.LENGTH))

        if data is not None:
            self.public_key = ECPublicKey(self.getBytes(64))
            self.signature  = self.getBytes(64)

            if not self._verifySignature():
                raise SyntaxError("Signature verification failure")

            if self.index != len(data):
                raise SyntaxError("Excess bytes in TACK_Break_Sig")
Beispiel #9
0
    def __init__(self, bytes, offset=0):
        p = TlsStructure(bytes)
        self.type = p.getInt(1)  #skip Type

        #Get Length
        self.length = self._getASN1Length(p)

        # Header length is however many bytes read so far
        self.headerLength = p.index

        #Get Value
        self.value = p.getBytes(self.length)

        # This value tracks the offset of this TLV field
        # in some enclosing structure (ie an X.509 cert)
        self.offset = offset
Beispiel #10
0
    def __init__(self, bytes, offset = 0):
        p = TlsStructure(bytes)
        self.type = p.getInt(1) #skip Type

        #Get Length
        self.length = self._getASN1Length(p)
        
        # Header length is however many bytes read so far
        self.headerLength = p.index        

        #Get Value
        self.value = p.getBytes(self.length)
        
        # This value tracks the offset of this TLV field
        # in some enclosing structure (ie an X.509 cert) 
        self.offset = offset
Beispiel #11
0
    def __init__(self, data=None):
        TlsStructure.__init__(self, data)

        if data is not None and len(data) != TackBreakSig.LENGTH:
            raise SyntaxError(
                "Break signature is the wrong size. Is %s and should be %s." %
                (len(data), TackBreakSig.LENGTH))

        if data is not None:
            self.public_key = ECPublicKey(self.getBytes(64))
            self.signature = self.getBytes(64)

            if not self._verifySignature():
                raise SyntaxError("Signature verification failure")

            if self.index != len(data):
                raise SyntaxError("Excess bytes in TACK_Break_Sig")
Beispiel #12
0
    def __init__(self, data=None, password=None):
        TlsStructure.__init__(self, data)
        if data is not None:
            self.version = self.getInt(1)

            if self.version != 1:
                raise SyntaxError("Bad version in Secret File")

            self.password    = password
            self.iter_count  = self.getInt(4)
            self.salt        = self.getBytes(16)
            self.ciphertext  = self.getBytes(32)
            self.public_key  = ECPublicKey(self.getBytes(64))
            self.mac         = bytearray(self.getBytes(32))

            if self.password is not None:
                rawPrivateKey = self._decryptKey(password, self.salt, self.ciphertext,
                                                 self.iter_count, self.public_key, self.mac)
                self.private_key = ECPrivateKey(rawPrivateKey, self.public_key.getRawKey())
Beispiel #13
0
    def __init__(self, data=None):
        if data is None:
            return

        TlsStructure.__init__(self, data)
        if len(data) != Tack.LENGTH:
            raise SyntaxError("Tack is the wrong size. Is %s and should be %s" % (len(data), Tack.LENGTH))        

        self.public_key     = ECPublicKey.create(self.getBytes(64))
        self.min_generation = self.getInt(1)
        self.generation     = self.getInt(1)
        self.expiration     = self.getInt(4)
        self.target_hash    = self.getBytes(32)
        self.signature      = self.getBytes(64)

        if self.generation < self.min_generation:
            raise SyntaxError("Generation less than min_generation")
            
        if not self.verifySignature():
            raise SyntaxError("Tack has bad signature")
Beispiel #14
0
    def __init__(self, data=None, extenderFormat=False):
        if data is None:
            return

        TlsStructure.__init__(self, data)
        if extenderFormat:
            extensionType = self.getInt(2)
            if extensionType != 62208:
                raise SyntaxError("Bad TLS Extension type")
            extensionLen = self.getInt(2)
            
        self.tacks            = self._parseTacks()
        self.activation_flags = self.getInt(1)

        if self.activation_flags > 3:
            raise SyntaxError("Bad activation_flag value")

        if self.index != len(data):
            raise SyntaxError("Excess bytes in TACK_Extension")
        if extenderFormat and self.index != 4 + extensionLen:
            raise SyntaxError("Bad TLS Extension length: %d %d")
Beispiel #15
0
    def __init__(self, data=None, extenderFormat=False):
        if data is None:
            return

        TlsStructure.__init__(self, data)
        if extenderFormat:
            extensionType = self.getInt(2)
            if extensionType != 62208:
                raise SyntaxError("Bad TLS Extension type")
            extensionLen = self.getInt(2)

        self.tacks = self._parseTacks()
        self.activation_flags = self.getInt(1)

        if self.activation_flags > 3:
            raise SyntaxError("Bad activation_flag value")

        if self.index != len(data):
            raise SyntaxError("Excess bytes in TACK_Extension")
        if extenderFormat and self.index != 4 + extensionLen:
            raise SyntaxError("Bad TLS Extension length: %d %d")
Beispiel #16
0
    def __init__(self, data=None):
        if data is None:
            return

        TlsStructure.__init__(self, data)
        if len(data) != Tack.LENGTH:
            raise SyntaxError(
                "Tack is the wrong size. Is %s and should be %s" %
                (len(data), Tack.LENGTH))

        self.public_key = ECPublicKey.create(self.getBytes(64))
        self.min_generation = self.getInt(1)
        self.generation = self.getInt(1)
        self.expiration = self.getInt(4)
        self.target_hash = self.getBytes(32)
        self.signature = self.getBytes(64)

        if self.generation < self.min_generation:
            raise SyntaxError("Generation less than min_generation")

        if not self.verifySignature():
            raise SyntaxError("Tack has bad signature")
Beispiel #17
0
    def __init__(self, data=None, password=None):
        TlsStructure.__init__(self, data)
        if data is not None:
            self.version = self.getInt(1)

            if self.version != 1:
                raise SyntaxError("Bad version in Secret File")

            self.password = password
            self.iter_count = self.getInt(4)
            self.salt = self.getBytes(16)
            self.ciphertext = self.getBytes(32)
            self.public_key = ECPublicKey(self.getBytes(64))
            self.mac = bytearray(self.getBytes(32))

            if self.password is not None:
                rawPrivateKey = self._decryptKey(password, self.salt,
                                                 self.ciphertext,
                                                 self.iter_count,
                                                 self.public_key, self.mac)
                self.private_key = ECPrivateKey(rawPrivateKey,
                                                self.public_key.getRawKey())
Beispiel #18
0
    def __init__(self, data=None, password=None):
        if data is None:
            return
        
        TlsStructure.__init__(self, data)
        if len(data) != TackKeyFile.LENGTH:
            raise SyntaxError("Key File is the wrong size. Is %s and should be %s." % (len(data), TackKeyFile.LENGTH))
            
        self.version = self.getInt(1)

        if self.version != 1:
            raise SyntaxError("Bad version in Key File")

        self.iter_count  = self.getInt(4)
        self.salt        = self.getBytes(16)
        self.ciphertext  = self.getBytes(32)
        self.public_key  = ECPublicKey.create(self.getBytes(64))
        self.mac         = self.getBytes(32)

        if password is not None:
            rawPrivateKey = self._decrypt(password)
            self.private_key = ECPrivateKey.create(rawPrivateKey, self.public_key.getRawKey())
Beispiel #19
0
 def getChild(self, which):
     p = TlsStructure(self.value)
     for x in range(which + 1):
         if p.index == len(p.bytes):
             return None
         markIndex = p.index
         p.getInt(1)  #skip Type
         length = self._getASN1Length(p)
         p.getBytes(length)
     return ASN1Parser(p.bytes[markIndex:p.index],
                       self.offset + self.headerLength + markIndex)