""" URLResolver Addon for Kodi Copyright (C) 2016 t0mm0, tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . """ import re import urllib2 import json import hashlib import time from urlresolver import common from urlresolver.resolver import UrlResolver, ResolverError try: from crypto.keyedHash.hmacHash import HMAC_SHA1 from crypto.common import xor except ImportError: HMAC_SHA1 = None from math import ceil from struct import pack import binascii def pbkdf2(password, salt, iterations, keySize, PRF=HMAC_SHA1): """ Create key of size keySize from password and salt """ if len(password)>63: raise 'Password too long for pbkdf2' #if len(password)<8 : raise 'Password too short for pbkdf2' if (keySize > 10000): # spec says >4294967295L*digestSize raise 'keySize too long for PBKDF2' prf = PRF(key=password) # HMAC_SHA1 numBlocks = int(ceil(1.*keySize/prf.digest_size)) # ceiling function key = '' for block in range(1,numBlocks+1): # Calculate F(P, salt, iterations, i) F = prf(salt+pack('>i',block)) # i is packed into 4 big-endian bytes U = prf(salt+pack('>i',block)) # i is packed into 4 big-endian bytes for count in range(2,iterations+1): U = prf(U) F = xor(F,U) key = key + F return key[:keySize] def dot11PassPhraseToPSK(passPhrase,ssid): """ The 802.11 TGi recommended pass-phrase-to-preshared-key mapping. This function simply uses pbkdf2 with interations=4096 and keySize=32 """ assert(7' % (cls.__name__)) xml.append('' % (cls.__name__)) xml.append('' % (cls.__name__)) return xml @classmethod def isUniversal(self): return True