Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
fc59173
check if shared_ciphers() is None before logging
kevinAlbs Jun 23, 2023
1a0f63a
add original
locula Jun 14, 2023
5f34bae
Do not leak database connections
dutow Apr 12, 2023
f0a44b2
Fix pykmip client error with server_correlation_value issue
xlitao Apr 28, 2023
0b63de9
Fix test_mac_with_cryptographic_failure unit test.
arp102 Aug 8, 2023
111f1e5
Run travis.yml workflow
justin-h-loi Jul 31, 2023
4c65eb8
Changing file path of .travis workflow
justin-h-loi Aug 1, 2023
142ee4f
Added converted git action version of travis.yml
justin-h-loi Aug 1, 2023
4698649
.travis.yml build fix
justin-h-loi Aug 1, 2023
a7d035e
Directory fix in .travis.yml action
justin-h-loi Aug 1, 2023
2eb3f78
Permissions fix in .travis.yml action
justin-h-loi Aug 1, 2023
fd25dda
Setup virtualenv inside builds in .travis.yml action
justin-h-loi Aug 1, 2023
059e8c4
Add missing virtualenv install for builds in .travis.yml action
justin-h-loi Aug 1, 2023
01b3e54
Backtrack to try using sudo instead for setup in .travis.yml action
justin-h-loi Aug 1, 2023
7339254
File permissions for run.sh in .travis.yml action
justin-h-loi Aug 1, 2023
4041e77
Folder permissions for run.sh in .travis.yml action
justin-h-loi Aug 1, 2023
8692e34
Remove setup.py in .travis setup
justin-h-loi Aug 1, 2023
ec5f138
code reduction
justin-h-loi Aug 1, 2023
77620f3
Changing ubuntu image versions
justin-h-loi Aug 1, 2023
8f681ba
Changing python versions
justin-h-loi Aug 1, 2023
5fbf13f
Adding test number conditions
justin-h-loi Aug 1, 2023
19c57b2
Reformat test number conditions
justin-h-loi Aug 1, 2023
f7043f7
test number conditions
justin-h-loi Aug 1, 2023
11db2e5
test number conditions
justin-h-loi Aug 1, 2023
66e7b33
test reduction
justin-h-loi Aug 1, 2023
0fd1e1f
Remove old installs and attempt at doc test fix
justin-h-loi Aug 8, 2023
a102151
tox passenv change
justin-h-loi Aug 8, 2023
bfa3c01
Extending flake8 test max line length
justin-h-loi Aug 8, 2023
084fbcd
Make unit tests use default config
justin-h-loi Aug 15, 2023
ff69f85
pep8 fixes
justin-h-loi Aug 15, 2023
483fc6c
alternate config unit test fix
justin-h-loi Aug 15, 2023
ab580ee
Adding integration tests to git actions
justin-h-loi Aug 22, 2023
7299fa7
Removing setup.py install for test
justin-h-loi Aug 22, 2023
0cf89eb
Readding setup.py and adding permissions to /usr/local/lib/
justin-h-loi Aug 22, 2023
6130e18
Update git actions to node16 runtime
justin-h-loi Aug 22, 2023
8783e88
Adding ubuntu20 and extra python versions to git actions
justin-h-loi Aug 22, 2023
d275a68
(tox.ini): Forgot to add python versions to tox envlist
justin-h-loi Aug 22, 2023
8800e0b
Test fix
justin-h-loi Aug 22, 2023
4f8b316
Fix to include integration tests for py builds
justin-h-loi Aug 22, 2023
e9a63e2
Actions file name change and fixes
justin-h-loi Aug 29, 2023
a664187
Fix code syntax and docs
justin-h-loi Aug 29, 2023
400c29b
Removing bandit/pyaml version requirements
justin-h-loi Aug 29, 2023
cae5747
Update CI configuration.
arp102 Sep 12, 2023
4d3b5a5
Fix compatibility with cryptography >= 42.0.0
kajinamit Mar 28, 2024
64e4f18
Rely on close() to close sockets and stop using shutdown()
ShaneHarvey Aug 19, 2022
cb11131
Update supported python versions
kajinamit Mar 29, 2024
feec443
Remove deprecation warning in old python versions
kajinamit Apr 2, 2024
9d5b287
Revert "Rely on close() to close sockets and stop using shutdown()"
arp102 Jul 26, 2024
6cd44b5
Ignore ENOTCONN during shutdown
tipabu Jan 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: tox

on:
push:
branches: [ master ]
pull_request:

jobs:
tox-test:
strategy:
matrix:
os: [ubuntu-latest]
python:
- {version: '3.8', env: py38}
- {version: '3.9', env: py39}
- {version: '3.10', env: py310}
- {version: '3.11', env: py311}
test_mode: [0, 1]
runs-on: ${{ matrix.os }}
env:
TOXENV: ${{ matrix.python.env }}
RUN_INTEGRATION_TESTS: ${{ matrix.test_mode }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python.version }}
- run: pip install tox
- run: pip install codecov
- run: pip install slugs
- run: python3 setup.py install
- run: ./.travis/run.sh
- run: codecov
tox-other:
strategy:
matrix:
os: [ubuntu-latest]
python: ['3.8', '3.9', '3.10', '3.11']
test: [pep8, bandit, docs]
runs-on: ${{ matrix.os }}
env:
TOXENV: ${{ matrix.test }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- run: pip install tox
- run: pip install bandit
if: ${{ matrix.test == 'bandit' }}
- run: tox
4 changes: 4 additions & 0 deletions .travis/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
set -e
set -x

pkill -f run_server.py || true
sleep 1

if [[ "${RUN_INTEGRATION_TESTS}" == "1" ]]; then
sudo mkdir -p /etc/pykmip/certs
sudo mkdir -p /etc/pykmip/policies
Expand All @@ -14,6 +17,7 @@ if [[ "${RUN_INTEGRATION_TESTS}" == "1" ]]; then
sudo cp ./.travis/policy.json /etc/pykmip/policies/policy.json
sudo mkdir -p /var/log/pykmip
sudo chmod 777 /var/log/pykmip
sudo chmod -R 777 /etc/pykmip/
python3 ./bin/run_server.py &
tox -e integration -- --config client
elif [[ "${RUN_INTEGRATION_TESTS}" == "2" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = 'en'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
21 changes: 0 additions & 21 deletions kmip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

import os
import re
import sys
import warnings

from kmip.core import enums
from kmip.pie import client
Expand Down Expand Up @@ -46,22 +44,3 @@
'objects',
'services'
]


if sys.version_info[:2] == (2, 7):
warnings.warn(
(
"PyKMIP will drop support for Python 2.7 in a future release. "
"Please upgrade to a newer version of Python (3.5+ preferred)."
),
PendingDeprecationWarning
)

if sys.version_info[:2] == (3, 4):
warnings.warn(
(
"PyKMIP will drop support for Python 3.4 in a future release. "
"Please upgrade to a newer version of Python (3.5+ preferred)."
),
PendingDeprecationWarning
)
2 changes: 2 additions & 0 deletions kmip/core/factories/attribute_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ def create_attribute_value(self, name, value):
return primitives.Boolean(value, enums.Tags.NEVER_EXTRACTABLE)
elif name is enums.AttributeType.CUSTOM_ATTRIBUTE:
return attributes.CustomAttribute(value)
elif name is enums.AttributeType.ORIGINAL_CREATION_DATE:
return primitives.DateTime(value, enums.Tags.ORIGINAL_CREATION_DATE)
else:
if not isinstance(name, str):
raise ValueError('Unrecognized attribute type: '
Expand Down
7 changes: 7 additions & 0 deletions kmip/core/messages/contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,13 @@ def __init__(self):
super(MessageExtension, self).__init__(enums.Tags.MESSAGE_EXTENSION)


# 6.19
class ServerCorrelationValue(TextString):
def __init__(self, value=None):
super(ServerCorrelationValue, self).__init__(
value, enums.Tags.SERVER_CORRELATION_VALUE)


# 9.1.3.2.2
class KeyCompressionType(Enumeration):

Expand Down
8 changes: 7 additions & 1 deletion kmip/core/messages/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,14 @@ def __init__(self,
protocol_version=None,
time_stamp=None,
batch_count=None,
server_hashed_password=None):
server_hashed_password=None,
server_correlation_value=None):
super(ResponseHeader, self).__init__(tag=Tags.RESPONSE_HEADER)
self.protocol_version = protocol_version
self.time_stamp = time_stamp
self.batch_count = batch_count
self.server_hashed_password = server_hashed_password
self.server_correlation_value = server_correlation_value

self.validate()

Expand Down Expand Up @@ -204,6 +206,10 @@ def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
server_hashed_password.read(tstream, kmip_version=kmip_version)
self._server_hashed_password = server_hashed_password

if self.is_tag_next(enums.Tags.SERVER_CORRELATION_VALUE, tstream):
self.server_correlation_value = contents.ServerCorrelationValue()
self.server_correlation_value.read(tstream, kmip_version=kmip_version)

self.batch_count = contents.BatchCount()
self.batch_count.read(tstream, kmip_version=kmip_version)

Expand Down
4 changes: 2 additions & 2 deletions kmip/services/server/auth/slugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def authenticate(self,
)

try:
response = requests.get(self.users_url.format(user_id))
response = requests.get(self.users_url.format(user_id), timeout=10)
except Exception:
raise exceptions.ConfigurationError(
"A connection could not be established using the SLUGS URL."
Expand All @@ -98,7 +98,7 @@ def authenticate(self,
"Unrecognized user ID: {}".format(user_id)
)

response = requests.get(self.groups_url.format(user_id))
response = requests.get(self.groups_url.format(user_id), timeout=10)
if response.status_code == 404:
raise exceptions.PermissionDenied(
"Group information could not be retrieved for user ID: "
Expand Down
27 changes: 17 additions & 10 deletions kmip/services/server/crypto/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,7 @@ def mac(self, algorithm, key, data):
)
cipher_algorithm = self._symmetric_key_algorithms.get(algorithm)
try:
# ARC4 and IDEA algorithms will raise exception as CMAC
# requires block ciphers
# ARC4 and other non-block cipher algorithm will raise TypeError
c = cmac.CMAC(cipher_algorithm(key), backend=default_backend())
c.update(data)
mac_data = c.finalize()
Expand Down Expand Up @@ -585,13 +584,17 @@ def _encrypt_asymmetric(self,
"encryption.".format(padding_method)
)

backend = default_backend()

try:
public_key = backend.load_der_public_key(encryption_key)
public_key = serialization.load_der_public_key(
encryption_key,
backend=default_backend()
)
except Exception:
try:
public_key = backend.load_pem_public_key(encryption_key)
public_key = serialization.load_pem_public_key(
encryption_key,
backend=default_backend()
)
except Exception:
raise exceptions.CryptographicFailure(
"The public key bytes could not be loaded."
Expand Down Expand Up @@ -1434,8 +1437,6 @@ def verify_signature(self,
loaded, or when the signature verification process fails
unexpectedly.
"""
backend = default_backend()

hash_algorithm = None
dsa_hash_algorithm = None
dsa_signing_algorithm = None
Expand Down Expand Up @@ -1489,10 +1490,16 @@ def verify_signature(self,
)

try:
public_key = backend.load_der_public_key(signing_key)
public_key = serialization.load_der_public_key(
signing_key,
backend=default_backend()
)
except Exception:
try:
public_key = backend.load_pem_public_key(signing_key)
public_key = serialization.load_pem_public_key(
signing_key,
backend=default_backend()
)
except Exception:
raise exceptions.CryptographicFailure(
"The signing key bytes could not be loaded."
Expand Down
131 changes: 66 additions & 65 deletions kmip/services/server/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,80 +355,81 @@ def build_error_response(self, version, reason, message):
def _process_batch(self, request_batch, batch_handling, batch_order):
response_batch = list()

self._data_session = self._data_store_session_factory()
with self._data_store_session_factory() as session:
self._data_session = session

for batch_item in request_batch:
error_occurred = False
for batch_item in request_batch:
error_occurred = False

response_payload = None
result_status = None
result_reason = None
result_message = None
response_payload = None
result_status = None
result_reason = None
result_message = None

operation = batch_item.operation
request_payload = batch_item.request_payload
operation = batch_item.operation
request_payload = batch_item.request_payload

# Process batch item ID.
if len(request_batch) > 1:
if not batch_item.unique_batch_item_id:
raise exceptions.InvalidMessage(
"Batch item ID is undefined."
# Process batch item ID.
if len(request_batch) > 1:
if not batch_item.unique_batch_item_id:
raise exceptions.InvalidMessage(
"Batch item ID is undefined."
)

# Process batch message extension.
# TODO (peterhamilton) Add support for message extension handling.
# 1. Extract the vendor identification and criticality indicator.
# 2. If the indicator is True, raise an error.
# 3. If the indicator is False, ignore the extension.

# Process batch payload.
try:
response_payload = self._process_operation(
operation.value,
request_payload
)

# Process batch message extension.
# TODO (peterhamilton) Add support for message extension handling.
# 1. Extract the vendor identification and criticality indicator.
# 2. If the indicator is True, raise an error.
# 3. If the indicator is False, ignore the extension.

# Process batch payload.
try:
response_payload = self._process_operation(
operation.value,
request_payload
)
result_status = enums.ResultStatus.SUCCESS
except exceptions.KmipError as e:
error_occurred = True
result_status = e.status
result_reason = e.reason
result_message = str(e)
except Exception as e:
self._logger.warning(
"Error occurred while processing operation."
)
self._logger.exception(e)

result_status = enums.ResultStatus.SUCCESS
except exceptions.KmipError as e:
error_occurred = True
result_status = e.status
result_reason = e.reason
result_message = str(e)
except Exception as e:
self._logger.warning(
"Error occurred while processing operation."
)
self._logger.exception(e)

error_occurred = True
result_status = enums.ResultStatus.OPERATION_FAILED
result_reason = enums.ResultReason.GENERAL_FAILURE
result_message = (
"Operation failed. See the server logs for more "
"information."
error_occurred = True
result_status = enums.ResultStatus.OPERATION_FAILED
result_reason = enums.ResultReason.GENERAL_FAILURE
result_message = (
"Operation failed. See the server logs for more "
"information."
)

# Compose operation result.
result_status = contents.ResultStatus(result_status)
if result_reason:
result_reason = contents.ResultReason(result_reason)
if result_message:
result_message = contents.ResultMessage(result_message)

batch_item = messages.ResponseBatchItem(
operation=batch_item.operation,
unique_batch_item_id=batch_item.unique_batch_item_id,
result_status=result_status,
result_reason=result_reason,
result_message=result_message,
response_payload=response_payload
)
response_batch.append(batch_item)

# Compose operation result.
result_status = contents.ResultStatus(result_status)
if result_reason:
result_reason = contents.ResultReason(result_reason)
if result_message:
result_message = contents.ResultMessage(result_message)

batch_item = messages.ResponseBatchItem(
operation=batch_item.operation,
unique_batch_item_id=batch_item.unique_batch_item_id,
result_status=result_status,
result_reason=result_reason,
result_message=result_message,
response_payload=response_payload
)
response_batch.append(batch_item)

# Handle batch error if necessary.
if error_occurred:
if batch_handling == enums.BatchErrorContinuationOption.STOP:
break
# Handle batch error if necessary.
if error_occurred:
if batch_handling == enums.BatchErrorContinuationOption.STOP:
break

return response_batch

Expand Down
Loading
Loading