Skip to content

Commit 1c879e2

Browse files
committed
Fix a bug with revocation message decoding
This change fixes a bug with revocation message decoding that would cause client and server failures if the revocation message was included in a Revoke operation call. With this fix, the client can now send a revocation message with a Revoke request and the revocation will occur as expected. A ProxyKmipClient demo script for the Revoke operation has been included to help test Revoke functionality. Finally, an argument ordering bug with the original KMIPProxy demo Revoke script has also been fixed. Fixes #546
1 parent 5ac0c5d commit 1c879e2

File tree

3 files changed

+61
-6
lines changed

3 files changed

+61
-6
lines changed

kmip/core/objects.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from kmip.core.enums import AttributeType
2828
from kmip.core.enums import Tags
2929
from kmip.core.enums import Types
30-
from kmip.core.enums import RevocationReasonCode as RevocationReasonCodeEnum
3130
from kmip.core import exceptions
3231

3332
from kmip.core.misc import KeyFormatType
@@ -3529,9 +3528,9 @@ def __init__(self, value=None):
35293528
# 3.31, 9.1.3.2.19
35303529
class RevocationReasonCode(Enumeration):
35313530

3532-
def __init__(self, value=RevocationReasonCodeEnum.UNSPECIFIED):
3531+
def __init__(self, value=enums.RevocationReasonCode.UNSPECIFIED):
35333532
super(RevocationReasonCode, self).__init__(
3534-
RevocationReasonCodeEnum, value=value,
3533+
enums.RevocationReasonCode, value=value,
35353534
tag=Tags.REVOCATION_REASON_CODE)
35363535

35373536

@@ -3590,7 +3589,7 @@ def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
35903589
self.revocation_code.read(tstream, kmip_version=kmip_version)
35913590

35923591
if self.is_tag_next(Tags.REVOCATION_MESSAGE, tstream):
3593-
self.revocation_message = TextString()
3592+
self.revocation_message = TextString(tag=Tags.REVOCATION_MESSAGE)
35943593
self.revocation_message.read(tstream, kmip_version=kmip_version)
35953594

35963595
self.is_oversized(tstream)

kmip/demos/pie/revoke.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright (c) 2015 The Johns Hopkins University/Applied Physics Laboratory
2+
# All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
# not use this file except in compliance with the License. You may obtain
6+
# a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
16+
import logging
17+
import sys
18+
import time
19+
20+
from kmip.core import enums
21+
from kmip.demos import utils
22+
from kmip.pie import client
23+
24+
25+
if __name__ == '__main__':
26+
logger = utils.build_console_logger(logging.INFO)
27+
28+
# Build and parse arguments
29+
parser = utils.build_cli_parser(enums.Operation.REVOKE)
30+
opts, args = parser.parse_args(sys.argv[1:])
31+
32+
config = opts.config
33+
uid = opts.uuid
34+
35+
# Exit early if the UUID is not specified
36+
if uid is None:
37+
logger.error('No UUID provided, exiting early from demo')
38+
sys.exit()
39+
40+
# Build the client and connect to the server
41+
with client.ProxyKmipClient(
42+
config=config,
43+
config_file=opts.config_file
44+
) as client:
45+
try:
46+
client.revoke(
47+
enums.RevocationReasonCode.KEY_COMPROMISE,
48+
uid=uid,
49+
revocation_message="I want to revoke this secret.",
50+
compromise_occurrence_date=int(time.time())
51+
)
52+
logger.info(
53+
"Successfully revoked secret with ID: {0}".format(uid)
54+
)
55+
except Exception as e:
56+
logger.error(e)

kmip/demos/units/revoke.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
# License for the specific language governing permissions and limitations
1414
# under the License.
1515

16+
from kmip.core import enums
1617
from kmip.core.enums import Operation
1718
from kmip.core.enums import ResultStatus
18-
from kmip.core.enums import RevocationReasonCode
1919

2020
from kmip.demos import utils
2121

@@ -46,8 +46,8 @@
4646

4747
# Activate the object
4848
result = client.revoke(
49+
enums.RevocationReasonCode.KEY_COMPROMISE,
4950
uuid,
50-
RevocationReasonCode.UNSPECIFIED,
5151
'Demo revocation message')
5252
client.close()
5353

0 commit comments

Comments
 (0)