Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
danibudi committed Aug 31, 2017
2 parents e365995 + d73e90e commit 1b539d0
Show file tree
Hide file tree
Showing 38 changed files with 407 additions and 161 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ __pycache__/
*.pyc
*.komodoproject
*htmlcov*
*.txt
_build
build
kount-*
Expand Down
4 changes: 3 additions & 1 deletion kount/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
# Copyright (C) 2017 Kount Inc. All Rights Reserved.

from __future__ import absolute_import, unicode_literals, division, print_function
from kount.version import VERSION

__author__ = "Kount SDK"
__version__ = "1.0.0"
__version__ = VERSION
__maintainer__ = "Kount SDK"
__email__ = "sdkadmin@kount.com"
__status__ = "Development"
3 changes: 2 additions & 1 deletion kount/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
from .ris_validator import RisValidator, RisValidationException
from .util.khash import Khash
from .settings import TIMEOUT, RAISE_ERRORS
from .version import VERSION


__author__ = "Kount SDK"
__version__ = "1.0.0"
__version__ = VERSION
__maintainer__ = "Kount SDK"
__email__ = "sdkadmin@kount.com"
__status__ = "Development"
Expand Down
3 changes: 2 additions & 1 deletion kount/inquiry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
from .util.cartitem import CartItem
from .util.address import Address
from .settings import SDK_VERSION
from .version import VERSION

__author__ = "Kount SDK"
__version__ = "1.0.0"
__version__ = VERSION
__maintainer__ = "Kount SDK"
__email__ = "sdkadmin@kount.com"
__status__ = "Development"
Expand Down
5 changes: 4 additions & 1 deletion kount/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
from .util.khash import Khash
from .ris_validator import RisException
from .settings import SDK_VERSION
from .version import VERSION

__author__ = "Kount SDK"
__version__ = "1.0.0"
__version__ = VERSION
__maintainer__ = "Kount SDK"
__email__ = "sdkadmin@kount.com"
__status__ = "Development"
Expand Down Expand Up @@ -265,6 +266,8 @@ def payment_set(self, payment):
" KHASH payment encoding disabled", str(nsae))
#Default to plain text payment tokens
self.params["PENC"] = ""
if Khash.khashed(payment.payment_token):
self.params["PENC"] = "KHASH"
self.params["PTOK"] = payment.payment_token
self.params["PTYP"] = payment.payment_type
self.params["LAST4"] = payment.last4
Expand Down
3 changes: 2 additions & 1 deletion kount/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
# Copyright (C) 2017 Kount Inc. All Rights Reserved.
from __future__ import absolute_import, unicode_literals, division, print_function
import logging
from .version import VERSION

__author__ = "Kount SDK"
__version__ = "1.0.0"
__version__ = VERSION
__maintainer__ = "Kount SDK"
__email__ = "sdkadmin@kount.com"
__status__ = "Development"
Expand Down
3 changes: 2 additions & 1 deletion kount/ris_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
from .util.cartitem import CartItem
from .util.validation_error import ValidationError
from .util.xml_rules import XML_DICT, REQUIRED, NOTREQUIRED
from .version import VERSION

logger = logging.getLogger('kount.request')

__author__ = "Kount SDK"
__version__ = "1.0.0"
__version__ = VERSION
__maintainer__ = "Kount SDK"
__email__ = "sdkadmin@kount.com"
__status__ = "Development"
Expand Down
20 changes: 11 additions & 9 deletions kount/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
# Copyright (C) 2017 Kount Inc. All Rights Reserved.
"settings"
from __future__ import absolute_import, unicode_literals, division, print_function
from kount.version import VERSION


__author__ = "Kount SDK"
__version__ = "1.0.0"
__version__ = VERSION
__maintainer__ = "Kount SDK"
__email__ = "sdkadmin@kount.com"
__status__ = "Development"
Expand All @@ -19,26 +20,27 @@
XML_DICT = 'xml_rules.py'
SDK_VERSION = "0695"

#~ raise errors or log them, excl. "ValueError: Configured SALT phrase is incorrect."
#~ raise errors or log them, excl. "ValueError: Configured configurationKey is incorrect."
#~ RAISE_ERRORS = False
RAISE_ERRORS = True


# request's timeout
TIMEOUT = 5

SALT = "fake salt"
#~ fake configuration key, replace with the valid one orovided by Kount
configurationKey = b"<+oue+DGm>F(&p)Ch4`2AU&;>AoD]4FCfN8Bl7Q+E-62?Df]K2/c"

#~ uncomment this if you'd like to get the SALT from the environment
#~ uncomment this if you'd like to get the configurationKey from the environment
#~ import os
#~ try:
#~ SALT = os.environ['K_SALT']
#~ configurationKey = os.environ['K_KEY']
#~ except KeyError:
#~ print("The default fake salt set. Required actual one from Kount")
#~ print("The default fake configurationKey set. Required actual one from Kount")

#~ put SALT in the local_settings.py and don't commit it
#~ comment this code if the SALT is an environment variable
#~ put configurationKey in the local_settings.py and don't commit it
#~ comment this code if the configurationKey is an environment variable
try:
from .local_settings import *
except ImportError as ie:
print("The default fake salt set. Required actual one from Kount. ", ie)
print("The default fake configurationKey set. Required actual one from Kount. ", ie)
4 changes: 3 additions & 1 deletion kount/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
# Copyright (C) 2017 Kount Inc. All Rights Reserved.

from __future__ import absolute_import, unicode_literals, division, print_function
from kount.version import VERSION

__author__ = "Kount SDK"
__version__ = "1.0.0"
__version__ = VERSION
__maintainer__ = "Kount SDK"
__email__ = "sdkadmin@kount.com"
__status__ = "Development"
4 changes: 3 additions & 1 deletion kount/util/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
"Address class - representing a street address"

from __future__ import absolute_import, unicode_literals, division, print_function
from kount.version import VERSION

__author__ = "Kount SDK"
__version__ = "1.0.0"
__version__ = VERSION
__maintainer__ = "Kount SDK"
__email__ = "sdkadmin@kount.com"
__status__ = "Development"
Expand Down
3 changes: 2 additions & 1 deletion kount/util/cartitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"CartItem class"

from __future__ import absolute_import, unicode_literals, division, print_function
from kount.version import VERSION

__author__ = "Kount SDK"
__version__ = "1.0.0"
__version__ = VERSION
__maintainer__ = "Kount SDK"
__email__ = "sdkadmin@kount.com"
__status__ = "Development"
Expand Down
30 changes: 18 additions & 12 deletions kount/util/khash.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
from __future__ import absolute_import, unicode_literals, division, print_function
import hashlib
import re
import base64
import logging
from string import digits, ascii_uppercase
from kount.settings import SALT
from resources.correct_salt_cryp import correct_salt_cryp
from kount.settings import configurationKey
from kount.version import VERSION
from resources.correct_key_cryp import correct_key_cryp
try:
from base64 import a85decode # python3.x.y
except ImportError:
from mom.codec.base85 import b85decode as a85decode # python2.7.13

__author__ = "Kount SDK"
__version__ = "1.0.0"
__version__ = VERSION
__maintainer__ = "Kount SDK"
__email__ = "sdkadmin@kount.com"
__status__ = "Development"
Expand Down Expand Up @@ -52,24 +58,24 @@ class Khash(object):
Uninstantiable class constructor.
Class for creating Kount RIS KHASH encoding payment tokens.
"""
iv = SALT
iv = a85decode(configurationKey)

@classmethod
def verify(cls):
current_crypted = hashlib.sha256(cls.salt.encode('utf-8')).hexdigest()
if current_crypted != correct_salt_cryp:
mesg = "Configured SALT phrase is incorrect."
current_crypted = hashlib.sha256(cls.configurationKey.encode('utf-8')).hexdigest()
if current_crypted != correct_key_cryp:
mesg = "Configured configurationKey is incorrect."
logger.error(mesg)
raise ValueError(mesg)
logger.info("Configured SALT phrase is correct.")
logger.info("Configured configurationKey is correct.")
return True

@classmethod
def set_iv(cls, iv):
"""
initialize the SALT phrase used in hashing operations.
Khash.set_salt(salt)"""
cls.salt = iv
initialize the configurationKey used in hashing operations.
Khash.set_iv(iv)"""
cls.configurationKey = iv.decode("utf-8")
cls.verify()

@classmethod
Expand Down Expand Up @@ -116,7 +122,7 @@ def hash(cls, plain_text):
hashed = []
plain_text_bytes = plain_text.encode('utf-8') #Python 3.x
sha1 = hashlib.sha1(plain_text_bytes + ".".encode('utf-8') +
cls.iv.encode('utf-8')).hexdigest()
cls.iv).hexdigest()
for i in range(0, loop_max, 2):
hashed.append(legal_chars[int(sha1[i: i+hex_chunk], 16)
% length])
Expand Down

0 comments on commit 1b539d0

Please sign in to comment.