{"action":"created","issue":{"url":"https://api.github.com/repos/bcurtu/django-sermepa/issues/3","labels_url":"https://api.github.com/repos/bcurtu/django-sermepa/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/bcurtu/django-sermepa/issues/3/comments","events_url":"https://api.github.com/repos/bcurtu/django-sermepa/issues/3/events","html_url":"https://github.com/bcurtu/django-sermepa/issues/3","id":114245335,"number":3,"title":"Compatibilidad con SHA256","user":{"login":"alvarovelezgalvez","id":2486011,"avatar_url":"https://avatars.githubusercontent.com/u/2486011?v=3","gravatar_id":"","url":"https://api.github.com/users/alvarovelezgalvez","html_url":"https://github.com/alvarovelezgalvez","followers_url":"https://api.github.com/users/alvarovelezgalvez/followers","following_url":"https://api.github.com/users/alvarovelezgalvez/following{/other_user}","gists_url":"https://api.github.com/users/alvarovelezgalvez/gists{/gist_id}","starred_url":"https://api.github.com/users/alvarovelezgalvez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alvarovelezgalvez/subscriptions","organizations_url":"https://api.github.com/users/alvarovelezgalvez/orgs","repos_url":"https://api.github.com/users/alvarovelezgalvez/repos","events_url":"https://api.github.com/users/alvarovelezgalvez/events{/privacy}","received_events_url":"https://api.github.com/users/alvarovelezgalvez/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":42,"created_at":"2015-10-30T10:46:03Z","updated_at":"2015-11-16T16:52:54Z","closed_at":null,"body":"Hola, \r\n\r\nde acuerdo con esta información de RedSys https://canales.redsys.es/canales/ayuda/migracionSHA256.html\r\na finales de noviembre dejaran de funcionar las firmas basadas en SHA1 y por tanto dejarán de funcionar las funciones que realizan la firma (y la librería en sí, que se basa en SHA1)\r\n\r\nHe realizado unas pruebas intentando migrar los ejemplos que ofrecen (en PHP) en su documentación, pero en todo caso sigo obteniendo un error 0042 (error de firma) al enviar el formulario a su entorno. (Las pruebas hechas contra el servidor de producción de Redsys desde el script de PHP funcionan porque ya he recibido la nueva clave 256 desde mi banco).\r\n\r\n\r\nEste sería el código que he empleado para probar:\r\n\r\n```python\r\n    from pyDes import triple_des, CBC, PAD_PKCS5\r\n    import hashlib, json, base64, hmac\r\n\r\n    \"\"\"\r\n        Datos fijos. \r\n    \"\"\" \r\n    Ds_SignatureVersion = 'HMAC_SHA256_V1'\r\n    new_256_key = 'aquiirialaclaveenviadaporlaentidadbancaria'\r\n    order = \"1234567890\"\r\n\r\n    \"\"\"\r\n        Creamos un json y los codificamos en base64 eliminando retornos de carro\r\n    \"\"\" \r\n    merchant_parameters = {}\r\n    merchant_parameters['DS_MERCHANT_AMOUNT'] = \"1000\"\r\n    merchant_parameters['DS_MERCHANT_ORDER'] = order\r\n    merchant_parameters['DS_MERCHANT_MERCHANTCODE'] = \"XXXXXXXXXX\"\r\n    merchant_parameters['DS_MERCHANT_CURRENCY'] = \"978\"\r\n    merchant_parameters['DS_MERCHANT_TRANSACTIONTYPE'] = \"0\"\r\n    merchant_parameters['DS_MERCHANT_TERMINAL'] = \"1\"\r\n    merchant_parameters['DS_MERCHANT_MERCHANTURL'] = \"http:\\\\test\\redsys\\callback_url\"\r\n    merchant_parameters['DS_MERCHANT_URLOK'] = \"http:\\\\test\\OK\"\r\n    merchant_parameters['DS_MERCHANT_URLKO'] = \"http:\\\\test\\OK\"\r\n    parameters = (json.dumps(merchant_parameters)).encode()\r\n    print '\\n\\n parameters --> %s' % parameters\r\n    Ds_MerchantParameters = ''.join(unicode(base64.encodestring(parameters), 'utf-8').splitlines())\r\n    print '\\n\\n Ds_MerchantParameters --> %s' % Ds_MerchantParameters\r\n\r\n\r\n    \"\"\"\r\n        Se genera una clave específica por operación. Para obtener la\r\n        clave derivada a utilizar en una operación se debe realizar un\r\n        cifrado 3DES entre la clave del comercio y el valor del número de\r\n        pedido de la operación (Ds_Merchant_Order).\r\n    \"\"\"\r\n    new_256_key_decoded  = base64.b64decode(new_256_key)\r\n    print 'new_256_key_decoded --> %s' % new_256_key_decoded\r\n    k = triple_des(new_256_key_decoded, CBC, \"\\0\\0\\0\\0\\0\\0\\0\\0\", pad=None,  padmode=PAD_PKCS5)\r\n    ciphertext  = k.encrypt(order)\r\n    print 'ciphertext --> %s' % ciphertext\r\n\r\n\r\n    \"\"\"\r\n        Se calcula el HMAC SHA256 del valor del parámetro\r\n        Ds_MerchantParameters y la clave obtenida en el paso anterior.\r\n        El resultado obtenido se codifica en BASE 64, y el resultado de la\r\n        codificación será el valor del parámetro Ds_Signature, tal y\r\n        como se puede observar en el ejemplo de formulario mostrado al\r\n        inicio del apartado 3.\r\n    \"\"\"\r\n    hmac_value = hmac.new(ciphertext, Ds_MerchantParameters, digestmod=hashlib.sha256).hexdigest()\r\n    print 'hmac_value --> %s' % hmac_value\r\n    Ds_Signature = base64.b64encode(hmac_value)\r\n    print 'Ds_Signature --> %s' % Ds_Signature\r\n\r\n\r\n    \"\"\"\r\n        Estos serían los tres parámetros a enviar a Redsys\r\n    \"\"\"\r\n    context['Ds_SignatureVersion'] = Ds_SignatureVersion\r\n    context['Ds_MerchantParameters'] = Ds_MerchantParameters\r\n    context['Ds_Signature'] = Ds_Signature\r\n```"},"comment":{"url":"https://api.github.com/repos/bcurtu/django-sermepa/issues/comments/157095375","html_url":"https://github.com/bcurtu/django-sermepa/issues/3#issuecomment-157095375","issue_url":"https://api.github.com/repos/bcurtu/django-sermepa/issues/3","id":157095375,"user":{"login":"bcurtu","id":178029,"avatar_url":"https://avatars.githubusercontent.com/u/178029?v=3","gravatar_id":"","url":"https://api.github.com/users/bcurtu","html_url":"https://github.com/bcurtu","followers_url":"https://api.github.com/users/bcurtu/followers","following_url":"https://api.github.com/users/bcurtu/following{/other_user}","gists_url":"https://api.github.com/users/bcurtu/gists{/gist_id}","starred_url":"https://api.github.com/users/bcurtu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcurtu/subscriptions","organizations_url":"https://api.github.com/users/bcurtu/orgs","repos_url":"https://api.github.com/users/bcurtu/repos","events_url":"https://api.github.com/users/bcurtu/events{/privacy}","received_events_url":"https://api.github.com/users/bcurtu/received_events","type":"User","site_admin":false},"created_at":"2015-11-16T16:52:54Z","updated_at":"2015-11-16T16:52:54Z","body":"Bravo!!!\n\nEl 16 de noviembre de 2015, 17:44, Álvaro <notifications@github.com>\nescribió:\n\n> Hola!\n>\n> FYI, esta mañana he aplicado la migración a la nueva firma en mi proyecto\n> en producción y todo está funcionando ok y sin incidencias (unas 40\n> compras, tanto en el terminal secure3D de Redsys como en el que no requiere\n> doble autenticación), así que todo parece estable...\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/bcurtu/django-sermepa/issues/3#issuecomment-157093037>\n> .\n>\n"}}