Beispiel #1
0
	def authenticate(self, device_token):
		req = HTTPRequest.post("/1.0.0/application/token")
		req.form["grantType"] = "public_client"
		req.form["assertion"] = device_token
		
		response = self.request(req, False, True)
		self.access_token = response.json["tokenType"] + " " + response.json["accessToken"]
		return response.json
Beispiel #2
0
    def auth_system(self, title_id, title_version, device_token):
        req = HTTPRequest.post("/v3/application_auth_token")
        req.form["application_id"] = "%016x" % title_id
        req.form["application_version"] = "%08x" % title_version
        req.form["device_auth_token"] = device_token
        req.form["media_type"] = "SYSTEM"

        response = self.request(req, True)
        return response.json
Beispiel #3
0
	def login(self, id, password, app_token=None):
		req = HTTPRequest.post("/1.0.0/login")
		req.form["id"] = id
		req.form["password"] = password
		if app_token:
			req.form["appAuthNToken"] = app_token
			
		response = self.request(req, self.access_token, True)
		self.login_token = response.json["tokenType"] + " " + response.json["accessToken"]
		return response.json
Beispiel #4
0
    def send_request(self, protocol, method, body):
        call_id = self.call_id
        self.call_id += 1

        message = service.RMCMessage.request(self.settings, protocol, method,
                                             call_id, body)

        data = message.encode()

        key1 = bytes.fromhex(self.access_key).ljust(8, b"\0")
        key2 = self.key_derivation.derive_key(self.password.encode(), self.pid)

        signature1 = hmac.new(key1, data, hashlib.md5).hexdigest()
        signature2 = hmac.new(key2, data, hashlib.md5).hexdigest()

        random = secrets.token_hex(8).upper()

        req = HTTPRequest.post("https://%s/hpp/" % self.host())
        req.headers["Host"] = self.host()
        req.headers["pid"] = str(self.pid)
        req.headers["version"] = self.nex_version
        req.headers["token"] = "normaltoken"
        req.headers["signature1"] = signature1.upper()
        req.headers["signature2"] = signature2.upper()
        req.headers["Content-Type"] = "multipart/form-data"
        req.headers["Content-Length"] = 0
        req.boundary = "--------BOUNDARY--------" + random
        req.files["file"] = data

        response = self.client.request(req, True)
        if response.status != 200:
            raise ValueError("Hpp request failed with status %i" %
                             response.status)

        stream = streams.StreamIn(response.body, self.settings)
        if stream.u32() != stream.available():
            raise ValueError("Hpp response has unexpected size")

        success = stream.bool()
        if not success:
            error = stream.u32()
            if call_id != stream.u32():
                raise ValueError("Hpp error response has unexpected call id")
            if not stream.eof():
                raise ValueError("Hpp error response is bigger than expected")
            raise common.RMCError(error)

        if call_id != stream.u32():
            raise ValueError("Hpp response has unexpected call id")
        method_id = stream.u32()
        if method_id != method | 0x8000:
            raise ValueError("Hpp response has unexpected method id")
        return stream.readall()
Beispiel #5
0
	def login(self, username, password, password_type=None):
		req = HTTPRequest.post("/v1/api/oauth20/access_token/generate")
		self.prepare(req, cert=self.device_cert)
		
		req.form["grant_type"] = "password"
		req.form["user_id"] = util.urlencode(username)
		req.form["password"] = util.urlencode(password)
		if password_type is not None:
			req.form["password_type"] = password_type
		
		response = self.request(req)
		self.auth_token = "Bearer " + response["access_token"]["token"].value
Beispiel #6
0
    def device_token(self):
        challenge = self.challenge()

        data = b64decode(challenge["data"])

        req = HTTPRequest.post("/v6/device_auth_token")
        req.form["challenge"] = challenge["challenge"]
        req.form["client_id"] = "%016x" % self.client_id
        if self.region == 2:
            req.form["ist"] = "true"
        else:
            req.form["ist"] = "false"
        req.form["key_generation"] = self.key_generation
        req.form["system_version"] = self.system_digest
        req.form["mac"] = self.calculate_mac(req.form.encode(), data)

        response = self.request(req)
        return response.json
Beispiel #7
0
	def auth_digital(self, title_id, title_version, device_token, ticket):
		self.verify_ticket(ticket, title_id)
		
		plain_key = get_random_bytes(16)
		
		aes = AES.new(plain_key, AES.MODE_CBC, iv=bytes(16))
		encrypted_ticket = aes.encrypt(pad(ticket, 16))
		
		rsa_key = RSA.construct((RSA_MODULUS, RSA_EXPONENT))
		rsa = PKCS1_OAEP.new(rsa_key, SHA256)
		encrypted_key = rsa.encrypt(plain_key)
	
		req = HTTPRequest.post("/v3/application_auth_token")
		req.form["application_id"] = "%016x" %title_id
		req.form["application_version"] = "%08x" %title_version
		req.form["device_auth_token"] = device_token
		req.form["media_type"] = "DIGITAL"
		
		req.form["cert"] = b64encode(encrypted_ticket)
		req.form["cert_key"] = b64encode(encrypted_key)
	
		response = self.request(req, True)
		return response.json
Beispiel #8
0
	def register(self):
		req = HTTPRequest.post("/1.0.0/users")
		response = self.request(req, self.access_token, False)
		return response.json
Beispiel #9
0
    def challenge(self):
        req = HTTPRequest.post("/v6/challenge")
        req.form["key_generation"] = self.key_generation

        response = self.request(req)
        return response.json