Skip to content

Commit e3eef09

Browse files
authored
Merge pull request #4165 from StackStorm/move_from_keyczar_to_cryptography_py3
Move from keyczar to cryptography library for symmetric encryption / decryption
2 parents 4cb8e6a + 5955e5c commit e3eef09

File tree

17 files changed

+632
-39
lines changed

17 files changed

+632
-39
lines changed

conf/st2.conf.sample

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ action_executions_output_ttl = 7
155155
collection_interval = 600
156156

157157
[keyvalue]
158-
# Location of the symmetric encryption key for encrypting values in kvstore. This key should be in JSON and should've been generated using keyczar.
158+
# Location of the symmetric encryption key for encrypting values in kvstore. This key should be in JSON and should've been generated using st2-generate-symmetric-crypto-key tool.
159159
encryption_key_path =
160160
# Allow encryption of values in key value stored qualified as "secret".
161161
enable_encryption = True

contrib/runners/python_runner/tests/unit/test_pythonrunner.py

-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import six
2323
import mock
24-
import unittest2
2524
from oslo_config import cfg
2625

2726
from python_runner import python_runner
@@ -200,7 +199,6 @@ def test_simple_action_no_status_backward_compatibility(self):
200199
self.assertTrue(output is not None)
201200
self.assertEqual(output['result'], [1, 2])
202201

203-
@unittest2.skipIf(six.PY3, 'keyczar doesn\'t work under Python 3')
204202
def test_simple_action_config_value_provided_overriden_in_datastore(self):
205203
pack = 'dummy_pack_5'
206204
user = 'joe'

fixed-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ stevedore==1.28.0
3434
paramiko==2.4.1
3535
networkx==1.11
3636
python-keyczar==0.716
37+
cryptography==2.2.2
3738
retrying==1.3.3
3839
# Note: We use latest version of virtualenv which uses pip 9.0
3940
virtualenv==15.1.0

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ RandomWords
33
apscheduler==3.5.1
44
argcomplete
55
bcrypt
6+
cryptography==2.2.2
67
eventlet==0.23.0
78
flex==6.13.1
89
git+https://github.com/Kami/logshipper.git@stackstorm_patched#egg=logshipper
@@ -37,7 +38,6 @@ python-dateutil
3738
python-editor==1.0.3
3839
python-gnupg==0.4.2
3940
python-json-logger
40-
python-keyczar==0.716
4141
python-statsd==2.1.0
4242
pytz==2018.4
4343
pyyaml<4.0,>=3.12

st2common/bin/st2-generate-symmetric-crypto-key

+23-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1-
#!/usr/bin/env python2.7
1+
#!/usr/bin/env python
2+
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
217

318
import argparse
419
import os
520
import sys
621

7-
from keyczar.keys import AesKey
22+
from st2common.util.crypto import AESKey
823

924

1025
def main(key_path, force=False):
26+
key_path = os.path.abspath(key_path)
1127
base_path = os.path.dirname(key_path)
28+
1229
if not os.access(base_path, os.W_OK):
1330
print('ERROR: You do not have sufficient permissions to write to path: %s.' % key_path)
1431
print('Try setting up permissions correctly and then run this tool.')
@@ -23,9 +40,11 @@ def main(key_path, force=False):
2340

2441
print('WARNING: Rewriting existing key with new key!')
2542

43+
# Explicitly chose large key size
44+
aes_key = AESKey.generate(key_size=256)
45+
2646
with open(key_path, 'w') as key_file:
27-
k = AesKey.Generate()
28-
key_file.write(str(k))
47+
key_file.write(aes_key.to_json())
2948
key_file.flush()
3049

3150
msg = ('Key written to %s. ' % key_path + 'Secure the permissions so only StackStorm API ' +

st2common/in-requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ oslo.config
1313
paramiko
1414
pyyaml
1515
pymongo
16-
python-keyczar
16+
cryptography
1717
requests
1818
retrying
1919
semver

st2common/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Don't edit this file. It's generated automatically!
22
apscheduler==3.5.1
3+
cryptography==2.2.2
34
eventlet==0.23.0
45
flex==6.13.1
56
greenlet==0.4.13
@@ -15,7 +16,6 @@ paramiko==2.4.1
1516
prometheus_client==0.1.1
1617
pymongo==3.6.1
1718
python-dateutil
18-
python-keyczar==0.716
1919
python-statsd==2.1.0
2020
pyyaml<4.0,>=3.12
2121
requests[security]<2.15,>=2.14.1

st2common/st2common/config.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ def register_opts(ignore_errors=False):
273273
cfg.StrOpt(
274274
'encryption_key_path', default='',
275275
help='Location of the symmetric encryption key for encrypting values in kvstore. '
276-
'This key should be in JSON and should\'ve been generated using keyczar.')
276+
'This key should be in JSON and should\'ve been generated using '
277+
'st2-generate-symmetric-crypto-key tool.')
277278
]
278279

279280
do_register_opts(keyvalue_opts, group='keyvalue')

0 commit comments

Comments
 (0)