def parse(data): typeid, data = proto.unpack('!H', data) cls = pkTypes.get(typeid, None) if cls is None: raise NotImplementedError('unknown typeid %r' % typeid) logging.debug('Got key of type %r' % cls) return cls.parsePayload(data)
def proto_test(): WVPASSEQ(proto.EPERM, 0x30) WVPASS(proto._keyid('foo')) h1 = proto._hmac('foo', 'content') h1b = proto._hmac('foo', 'content2') h2 = proto._hmac('boo'*30, 'content') WVPASS(h1) WVPASS(h1b) WVPASS(h2) WVPASSNE(h1, h1b) WVPASSNE(h1, h2) WVPASSNE(h1b, h2) pkt = proto.pack('foo', 23, proto.Cmd.KeyGen, 'chunky') def kl(kid): WVPASSEQ(kid, proto._keyid('foo')) return 'foo' (key,serial,cmd,content) = proto.unpack(pkt, kl) WVPASSEQ(key, 'foo') WVPASSEQ(serial, 23) WVPASSEQ(cmd, proto.Cmd.KeyGen) WVPASSEQ(content, 'chunky') pkt = pkt[:-5] + chr(ord(pkt[-5]) ^ 1) + pkt[:-4] WVEXCEPT(proto.Error, proto.unpack, pkt, kl)
def checkPubkeyAuth(self, key, mackey, encsig): auth = AESCTR(key).decrypt(encsig) self.theirPubkey, auth = PK.parse(auth) receivedKeyid, auth = proto.unpack('!I', auth) if receivedKeyid == 0: raise InvalidParameterError authbuf = toMpi(self.gy) authbuf += toMpi(self.dh.pub) authbuf += self.theirPubkey.serializePublicKey() authbuf += struct.pack('!I', receivedKeyid) if self.theirPubkey.verify(SHA256HMAC(mackey, authbuf), auth) is False: raise InvalidParameterError self.theirKeyid = receivedKeyid
def fromMpi(data): size, data = proto.unpack('!I', data) return bytes_to_long(data[:size]), data[size:]