splunksecrets 1.0.0__tar.gz โ 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- splunksecrets-1.1.0/.github/workflows/publish.yml +52 -0
- splunksecrets-1.1.0/.github/workflows/tests.yml +41 -0
- splunksecrets-1.1.0/.gitignore +72 -0
- splunksecrets-1.1.0/Justfile +28 -0
- splunksecrets-1.1.0/PKG-INFO +10 -0
- splunksecrets-1.0.0/PKG-INFO โ splunksecrets-1.1.0/README.rst +46 -35
- splunksecrets-1.1.0/pyproject.toml +34 -0
- splunksecrets-1.1.0/splunksecrets/__init__.py +19 -0
- splunksecrets-1.1.0/splunksecrets/cli.py +264 -0
- splunksecrets-1.1.0/splunksecrets/dbconnect.py +156 -0
- splunksecrets-1.1.0/splunksecrets/phantom.py +99 -0
- splunksecrets-1.1.0/splunksecrets/splunk.py +131 -0
- splunksecrets-1.1.0/tests/__init__.py +0 -0
- splunksecrets-1.1.0/tests/test_splunksecrets.py +314 -0
- splunksecrets-1.1.0/uv.lock +485 -0
- splunksecrets-1.0.0/README.rst +0 -257
- splunksecrets-1.0.0/setup.cfg +0 -4
- splunksecrets-1.0.0/setup.py +0 -37
- splunksecrets-1.0.0/splunksecrets.egg-info/PKG-INFO +0 -268
- splunksecrets-1.0.0/splunksecrets.egg-info/SOURCES.txt +0 -9
- splunksecrets-1.0.0/splunksecrets.egg-info/dependency_links.txt +0 -1
- splunksecrets-1.0.0/splunksecrets.egg-info/entry_points.txt +0 -2
- splunksecrets-1.0.0/splunksecrets.egg-info/requires.txt +0 -4
- splunksecrets-1.0.0/splunksecrets.egg-info/top_level.txt +0 -1
- splunksecrets-1.0.0/splunksecrets.py +0 -466
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
name: Publish Python ๐ distribution ๐ฆ to PyPI
|
|
2
|
+
|
|
3
|
+
on: push
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
name: Build distribution ๐ฆ
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
with:
|
|
13
|
+
persist-credentials: false
|
|
14
|
+
- name: Set up Python
|
|
15
|
+
uses: actions/setup-python@v5
|
|
16
|
+
with:
|
|
17
|
+
python-version: "3.x"
|
|
18
|
+
- name: Install pypa/build
|
|
19
|
+
run: >-
|
|
20
|
+
python3 -m
|
|
21
|
+
pip install
|
|
22
|
+
build
|
|
23
|
+
--user
|
|
24
|
+
- name: Build a binary wheel and a source tarball
|
|
25
|
+
run: python3 -m build
|
|
26
|
+
- name: Store the distribution packages
|
|
27
|
+
uses: actions/upload-artifact@v4
|
|
28
|
+
with:
|
|
29
|
+
name: python-package-distributions
|
|
30
|
+
path: dist/
|
|
31
|
+
|
|
32
|
+
publish-to-pypi:
|
|
33
|
+
name: >-
|
|
34
|
+
Publish Python ๐ distribution ๐ฆ to PyPI
|
|
35
|
+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
|
|
36
|
+
needs:
|
|
37
|
+
- build
|
|
38
|
+
runs-on: ubuntu-latest
|
|
39
|
+
environment:
|
|
40
|
+
name: pypi
|
|
41
|
+
url: https://pypi.org/p/splunksecrets
|
|
42
|
+
permissions:
|
|
43
|
+
id-token: write
|
|
44
|
+
|
|
45
|
+
steps:
|
|
46
|
+
- name: Download all the dists
|
|
47
|
+
uses: actions/download-artifact@v4
|
|
48
|
+
with:
|
|
49
|
+
name: python-package-distributions
|
|
50
|
+
path: dist/
|
|
51
|
+
- name: Publish distribution ๐ฆ to PyPI
|
|
52
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- "*"
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- master
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
main-lint-test:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
strategy:
|
|
16
|
+
matrix:
|
|
17
|
+
python-version:
|
|
18
|
+
- "3.9"
|
|
19
|
+
- "3.10"
|
|
20
|
+
- "3.11"
|
|
21
|
+
- "3.12"
|
|
22
|
+
- "3.13"
|
|
23
|
+
|
|
24
|
+
steps:
|
|
25
|
+
- name: ๐๏ธ Checkout
|
|
26
|
+
uses: actions/checkout@v4
|
|
27
|
+
|
|
28
|
+
- name: ๐ฆ Install uv
|
|
29
|
+
uses: astral-sh/setup-uv@v5
|
|
30
|
+
|
|
31
|
+
- name: ๐ Set up Python
|
|
32
|
+
uses: actions/setup-python@v5
|
|
33
|
+
|
|
34
|
+
- name: ๐ Install just
|
|
35
|
+
uses: extractions/setup-just@v2
|
|
36
|
+
|
|
37
|
+
- name: ๐ฆพ Install the project
|
|
38
|
+
run: just dev-sync
|
|
39
|
+
|
|
40
|
+
- name: ๐
๐งช Format, Lint and test
|
|
41
|
+
run: just validate
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
|
|
5
|
+
# C extensions
|
|
6
|
+
*.so
|
|
7
|
+
|
|
8
|
+
# Distribution / packaging
|
|
9
|
+
.Python
|
|
10
|
+
env/
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
lib/
|
|
17
|
+
lib64/
|
|
18
|
+
parts/
|
|
19
|
+
sdist/
|
|
20
|
+
var/
|
|
21
|
+
*.egg-info/
|
|
22
|
+
.installed.cfg
|
|
23
|
+
*.egg
|
|
24
|
+
.python-version
|
|
25
|
+
|
|
26
|
+
# PyInstaller
|
|
27
|
+
# Usually these files are written by a python script from a template
|
|
28
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
29
|
+
*.manifest
|
|
30
|
+
*.spec
|
|
31
|
+
|
|
32
|
+
# Installer logs
|
|
33
|
+
pip-log.txt
|
|
34
|
+
pip-delete-this-directory.txt
|
|
35
|
+
|
|
36
|
+
# Unit test / coverage reports
|
|
37
|
+
htmlcov/
|
|
38
|
+
.tox/
|
|
39
|
+
.coverage
|
|
40
|
+
.coverage_data
|
|
41
|
+
.cache
|
|
42
|
+
nosetests.xml
|
|
43
|
+
coverage.xml
|
|
44
|
+
|
|
45
|
+
# Translations
|
|
46
|
+
*.mo
|
|
47
|
+
*.pot
|
|
48
|
+
|
|
49
|
+
# Django stuff:
|
|
50
|
+
*.log
|
|
51
|
+
|
|
52
|
+
# Sphinx documentation
|
|
53
|
+
docs/_build/
|
|
54
|
+
|
|
55
|
+
# PyBuilder
|
|
56
|
+
target/
|
|
57
|
+
|
|
58
|
+
#Vim
|
|
59
|
+
*.swp
|
|
60
|
+
|
|
61
|
+
# Divshot
|
|
62
|
+
.divshot-cache/
|
|
63
|
+
.venv
|
|
64
|
+
splunk.secret
|
|
65
|
+
.vscode/**
|
|
66
|
+
.pytest_cache/**
|
|
67
|
+
.venv-py27
|
|
68
|
+
secret.gh*
|
|
69
|
+
test_phantom_private_key.pem
|
|
70
|
+
test_phantom_secret_key.py
|
|
71
|
+
test_splunk.secret
|
|
72
|
+
test_identity.dat
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# https://github.com/casey/just
|
|
2
|
+
|
|
3
|
+
dev-sync:
|
|
4
|
+
uv sync --all-extras --cache-dir .uv_cache
|
|
5
|
+
|
|
6
|
+
prod-sync:
|
|
7
|
+
uv sync --all-extras --no-dev --cache-dir .uv_cache
|
|
8
|
+
|
|
9
|
+
install-hooks:
|
|
10
|
+
uv run pre-commit install
|
|
11
|
+
|
|
12
|
+
format:
|
|
13
|
+
uv run ruff format
|
|
14
|
+
|
|
15
|
+
lint:
|
|
16
|
+
uv run ruff check --fix
|
|
17
|
+
test:
|
|
18
|
+
uv run pytest --verbose --color=yes tests
|
|
19
|
+
|
|
20
|
+
validate: format lint test
|
|
21
|
+
|
|
22
|
+
dockerize:
|
|
23
|
+
docker build -t python-repo-template .
|
|
24
|
+
|
|
25
|
+
# Use it like:
|
|
26
|
+
# just run 10
|
|
27
|
+
run number:
|
|
28
|
+
uv run main.py --number {{number}}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: splunksecrets
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Command-line tools for working with secrets for Splunk products
|
|
5
|
+
Author: Steve McMaster, Cameron Schmidt
|
|
6
|
+
Maintainer: Cameron Schmidt
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Requires-Dist: click>=8.0.0
|
|
9
|
+
Requires-Dist: cryptography>=43
|
|
10
|
+
Requires-Dist: pcrypt
|
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: splunksecrets
|
|
3
|
-
Version: 1.0.0
|
|
4
|
-
Summary: splunksecrets - Encrypt / Decrypt Splunk encrypted passwords
|
|
5
|
-
Author: Hurricane Labs
|
|
6
|
-
Author-email: splunk-app@hurricanelabs.com
|
|
7
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
-
Classifier: Programming Language :: Python :: 2
|
|
9
|
-
Classifier: Programming Language :: Python :: 3
|
|
10
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
-
|
|
12
1
|
splunksecrets - Encrypt and Decrypt Splunk Passwords
|
|
13
2
|
====================================================
|
|
14
3
|
|
|
15
|
-
|Build Status|
|
|
4
|
+
|Build Status|
|
|
16
5
|
|
|
17
6
|
``splunksecrets`` is a tool for working with Splunk secrets offline. It
|
|
18
7
|
currently supports encryption and decryption of passwords, but in the
|
|
@@ -24,18 +13,19 @@ infrastructure).
|
|
|
24
13
|
Installation
|
|
25
14
|
------------
|
|
26
15
|
|
|
27
|
-
|
|
16
|
+
You can install ``splunksecrets`` using ``uv``:
|
|
28
17
|
|
|
29
18
|
::
|
|
30
19
|
|
|
31
|
-
|
|
20
|
+
uv tool install splunksecrets
|
|
21
|
+
|
|
32
22
|
|
|
33
|
-
Or
|
|
34
|
-
github:
|
|
23
|
+
Or with pip:
|
|
35
24
|
|
|
36
25
|
::
|
|
37
26
|
|
|
38
|
-
|
|
27
|
+
python -m pip install splunksecrets
|
|
28
|
+
|
|
39
29
|
|
|
40
30
|
Usage
|
|
41
31
|
-----
|
|
@@ -51,15 +41,16 @@ operaton
|
|
|
51
41
|
--help Show this message and exit.
|
|
52
42
|
|
|
53
43
|
Commands:
|
|
54
|
-
dbconnect-decrypt
|
|
55
|
-
dbconnect-encrypt
|
|
56
|
-
|
|
57
|
-
phantom-
|
|
58
|
-
|
|
59
|
-
splunk-
|
|
60
|
-
splunk-
|
|
61
|
-
splunk-
|
|
62
|
-
splunk-legacy-
|
|
44
|
+
dbconnect-decrypt Decrypt password used for dbconnect identity
|
|
45
|
+
dbconnect-encrypt Encrypt password used for dbconnect identity
|
|
46
|
+
dbconnect-legacy-encrypt Encrypt password used for dbconnect identity using legacy algorithm
|
|
47
|
+
phantom-decrypt Decrypt password used for Phantom asset
|
|
48
|
+
phantom-encrypt Encrypt password used for Phantom asset
|
|
49
|
+
splunk-decrypt Decrypt password using Splunk 7.2 algorithm
|
|
50
|
+
splunk-encrypt Encrypt password using Splunk 7.2 algorithm
|
|
51
|
+
splunk-hash-passwd Generate password hash for use in...
|
|
52
|
+
splunk-legacy-decrypt Decrypt password using legacy Splunk algorithm...
|
|
53
|
+
splunk-legacy-encrypt Encrypt password using legacy Splunk algorithm...
|
|
63
54
|
|
|
64
55
|
You can find details of the usage of each subcommand by running the command
|
|
65
56
|
followed by ``--help``.
|
|
@@ -109,7 +100,8 @@ for AES256-GCM, with a 16-byte randomly generated initialization vector.
|
|
|
109
100
|
The encryption produces both the ciphertext as well as a "tag" that is
|
|
110
101
|
used as part of integrity verification. The iv, ciphertext, and tag (in
|
|
111
102
|
that order) are concatenated, base64-encoded, and prepended with ``$7$``
|
|
112
|
-
to produce the encrypted password seen in the configuration files.
|
|
103
|
+
to produce the encrypted password seen in the configuration files. If
|
|
104
|
+
the key is less than 254-bytes it is padded with null bytes.
|
|
113
105
|
|
|
114
106
|
Phantom
|
|
115
107
|
~~~~~~~
|
|
@@ -127,10 +119,12 @@ the key for the AES encryption. A SHA1 hash is generated using the
|
|
|
127
119
|
the initialization vector (``iv``) for the AES encryption. The password
|
|
128
120
|
to be encrypted is padded using PKCS7 padding prior to encryption.
|
|
129
121
|
|
|
130
|
-
DBConnect
|
|
122
|
+
DBConnect pre ~3.12
|
|
131
123
|
~~~~~~~~~
|
|
132
124
|
|
|
133
|
-
DBConnect
|
|
125
|
+
DBConnect used to encrypt passwords using the OpenSSL ``aes-256-cbc`` command.
|
|
126
|
+
This changed somewhere around 3.12 though I haven't bothered to find the exact
|
|
127
|
+
version where the change was made.
|
|
134
128
|
This encryption is fairly straightforward, and is documented in
|
|
135
129
|
``dbxcrypto.py`` included with DBConnect. The key and IV are derived from
|
|
136
130
|
the secret (stored in ``$SPLUNK_HOMEetc/apps/splunk_app_db_connect/certs/identity.dat``)
|
|
@@ -139,6 +133,14 @@ concatenated together with the salt (``Salted__`` + salt + ciphertext) and
|
|
|
139
133
|
encoded using Base64. The password to be encrypted is padded using PKCS7
|
|
140
134
|
padding prior to encryption.
|
|
141
135
|
|
|
136
|
+
DBConnect post ~3.12
|
|
137
|
+
~~~~~~~~~~~~~~~~~~~~
|
|
138
|
+
|
|
139
|
+
DBConnect now encrypts passwords using AES GCM with no padding.
|
|
140
|
+
A random 16-byte salt is generated as well as a random 12-byte IV. The key is derived
|
|
141
|
+
from the salt and the secret (stored in ``$SPLUNK_HOMEetc/apps/splunk_app_db_connect/certs/identity.dat``)
|
|
142
|
+
using Scrypt. The final output is ``salt`` + ``iv`` + ``ciphertext``.
|
|
143
|
+
|
|
142
144
|
Known Issues
|
|
143
145
|
------------
|
|
144
146
|
|
|
@@ -152,9 +154,20 @@ Known Issues
|
|
|
152
154
|
|
|
153
155
|
Version History
|
|
154
156
|
---------------
|
|
157
|
+
Version 1.1.0 (2025-06-05)
|
|
158
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
159
|
+
- Added support for encryption/decryption of DBConnect credentials using newer algorithm
|
|
160
|
+
- Bumps minimum Python version to 3.9
|
|
161
|
+
- Refactored code into multiple files
|
|
162
|
+
- Switched from setup.py to pyproject.toml
|
|
163
|
+
- Removed ``six`` dependency used for Python 2 compatibility
|
|
155
164
|
|
|
165
|
+
Version 1.0.1
|
|
166
|
+
~~~~~~~~~~~~~~
|
|
167
|
+
- Short secrets are padded in the same way Splunk itself does it. Thanks to
|
|
168
|
+
Matt Anderson for this contribution.
|
|
156
169
|
|
|
157
|
-
Version 1.0.
|
|
170
|
+
Version 1.0.0 (2021-06-07)
|
|
158
171
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
159
172
|
- Updated CLI command docstrings for proper help output
|
|
160
173
|
- Add initial support for encryption/decrypt of Splunk DBConnect credentials
|
|
@@ -170,8 +183,8 @@ Version 1.0.0rc1 (2021-05-19)
|
|
|
170
183
|
|
|
171
184
|
Version 0.5.1 (2022-06-29)
|
|
172
185
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
173
|
-
- Allow passing the splunk secret itself as an environment variable
|
|
174
|
-
~ provided by chutzimir
|
|
186
|
+
- Allow passing the splunk secret itself as an environment variable
|
|
187
|
+
~ provided by chutzimir
|
|
175
188
|
|
|
176
189
|
|
|
177
190
|
Version 0.5.0 (2020-06-23)
|
|
@@ -241,7 +254,7 @@ License Info
|
|
|
241
254
|
|
|
242
255
|
The MIT License (MIT)
|
|
243
256
|
|
|
244
|
-
Copyright (c)
|
|
257
|
+
Copyright (c) 2025 Hurricane Labs LLC
|
|
245
258
|
|
|
246
259
|
Permission is hereby granted, free of charge, to any person obtaining a
|
|
247
260
|
copy of this software and associated documentation files (the
|
|
@@ -264,5 +277,3 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
264
277
|
|
|
265
278
|
.. |Build Status| image:: https://github.com/HurricaneLabs/splunksecrets/actions/workflows/tests.yml/badge.svg
|
|
266
279
|
:target: https://github.com/HurricaneLabs/splunksecrets/actions/workflows/tests.yml
|
|
267
|
-
.. |codecov.io| image:: https://codecov.io/gh/HurricaneLabs/splunksecrets/branch/master/graph/badge.svg
|
|
268
|
-
:target: https://codecov.io/gh/HurricaneLabs/splunksecrets
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "splunksecrets"
|
|
3
|
+
version = "1.1.0"
|
|
4
|
+
description = "Command-line tools for working with secrets for Splunk products"
|
|
5
|
+
requires-python = ">=3.9"
|
|
6
|
+
dependencies = [
|
|
7
|
+
"click>=8.0.0",
|
|
8
|
+
"cryptography>=43",
|
|
9
|
+
"pcrypt"
|
|
10
|
+
]
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "Steve McMaster"},
|
|
13
|
+
{name = "Cameron Schmidt"},
|
|
14
|
+
]
|
|
15
|
+
maintainers = [
|
|
16
|
+
{name = "Cameron Schmidt"}
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[build-system]
|
|
20
|
+
requires = ["hatchling"]
|
|
21
|
+
build-backend = "hatchling.build"
|
|
22
|
+
|
|
23
|
+
[project.scripts]
|
|
24
|
+
splunksecrets = "splunksecrets.cli:main"
|
|
25
|
+
|
|
26
|
+
[tool.hatch.build.targets.wheel]
|
|
27
|
+
packages = ["splunksecrets"]
|
|
28
|
+
|
|
29
|
+
[dependency-groups]
|
|
30
|
+
dev = [
|
|
31
|
+
"pre-commit>=4.1.0",
|
|
32
|
+
"pytest>=8.3.4",
|
|
33
|
+
"ruff>=0.9.5",
|
|
34
|
+
]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from .dbconnect import decrypt_dbconnect, encrypt_dbconnect, get_key_and_iv
|
|
2
|
+
from .splunk import decrypt, encrypt, encrypt_new
|
|
3
|
+
from .phantom import decrypt_phantom, encrypt_phantom, to_bytes
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"decrypt_dbconnect",
|
|
7
|
+
"encrypt_dbconnect",
|
|
8
|
+
"decrypt_splunk_legacy",
|
|
9
|
+
"decrypt_splunk",
|
|
10
|
+
"encrypt_splunk_legacy",
|
|
11
|
+
"encrypt_splunk",
|
|
12
|
+
"encrypt_new",
|
|
13
|
+
"decrypt",
|
|
14
|
+
"encrypt",
|
|
15
|
+
"get_key_and_iv",
|
|
16
|
+
"decrypt_phantom",
|
|
17
|
+
"encrypt_phantom",
|
|
18
|
+
"to_bytes",
|
|
19
|
+
]
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import click
|
|
2
|
+
import pcrypt
|
|
3
|
+
import re
|
|
4
|
+
from cryptography.hazmat.primitives import serialization
|
|
5
|
+
|
|
6
|
+
from .dbconnect import encrypt_dbconnect, decrypt_dbconnect
|
|
7
|
+
from .phantom import encrypt_phantom, decrypt_phantom
|
|
8
|
+
from .splunk import encrypt, encrypt_new, decrypt
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def __ensure_binary(ctx, param, value):
|
|
12
|
+
if value is None and not param.required:
|
|
13
|
+
return None
|
|
14
|
+
if isinstance(value, str):
|
|
15
|
+
value = value.encode()
|
|
16
|
+
return value
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def __ensure_int(ctx, param, value):
|
|
20
|
+
if value is None and not param.required:
|
|
21
|
+
return None
|
|
22
|
+
try:
|
|
23
|
+
return int(value)
|
|
24
|
+
except ValueError:
|
|
25
|
+
raise click.BadParameter(f"{param.name} should be int")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def __ensure_text(ctx, param, value):
|
|
29
|
+
if value is None and not param.required:
|
|
30
|
+
return None
|
|
31
|
+
if isinstance(value, bytes):
|
|
32
|
+
value = value.decode()
|
|
33
|
+
return value
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def __load_phantom_private_key(ctx, param, value):
|
|
37
|
+
if ctx.get_parameter_source(param.name).name != "ENVIRONMENT":
|
|
38
|
+
with open(value, "rb") as f:
|
|
39
|
+
value = f.read().strip()
|
|
40
|
+
|
|
41
|
+
# Validate the key loads
|
|
42
|
+
serialization.load_pem_private_key(value, password=None)
|
|
43
|
+
|
|
44
|
+
return value
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def __load_phantom_secret_key(ctx, param, value):
|
|
48
|
+
if ctx.get_parameter_source(param.name).name == "ENVIRONMENT":
|
|
49
|
+
return value
|
|
50
|
+
|
|
51
|
+
with open(value, "rb") as f:
|
|
52
|
+
value = f.read().strip()
|
|
53
|
+
m = re.search(
|
|
54
|
+
bytes(r"^SECRET_KEY = '(?P<secret_key>.+)'$"), value, flags=re.MULTILINE
|
|
55
|
+
)
|
|
56
|
+
if not m:
|
|
57
|
+
raise click.BadParameter("Malformed secret key file")
|
|
58
|
+
return m.groupdict()["secret_key"]
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def __load_splunk_secret(ctx, param, value):
|
|
62
|
+
if ctx.get_parameter_source(param.name).name != "ENVIRONMENT":
|
|
63
|
+
with open(value, "rb") as f:
|
|
64
|
+
value = f.read().strip()
|
|
65
|
+
elif isinstance(value, str):
|
|
66
|
+
value = bytes(value, encoding="utf-8")
|
|
67
|
+
|
|
68
|
+
return value.strip()
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@click.group()
|
|
72
|
+
def main():
|
|
73
|
+
pass
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@main.command("dbconnect-encrypt")
|
|
77
|
+
@click.option(
|
|
78
|
+
"-S",
|
|
79
|
+
"--secret",
|
|
80
|
+
required=True,
|
|
81
|
+
envvar="DBCONNECT_SECRET",
|
|
82
|
+
callback=__load_splunk_secret,
|
|
83
|
+
)
|
|
84
|
+
@click.option(
|
|
85
|
+
"--password",
|
|
86
|
+
envvar="PASSWORD",
|
|
87
|
+
prompt=True,
|
|
88
|
+
hide_input=True,
|
|
89
|
+
callback=__ensure_text,
|
|
90
|
+
)
|
|
91
|
+
def dbconnect_encrypt(secret, password):
|
|
92
|
+
"""Encrypt password used for dbconnect identity"""
|
|
93
|
+
click.echo(encrypt_dbconnect(secret, password))
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@main.command("dbconnect-decrypt")
|
|
97
|
+
@click.option(
|
|
98
|
+
"-S",
|
|
99
|
+
"--secret",
|
|
100
|
+
required=True,
|
|
101
|
+
envvar="DBCONNECT_SECRET",
|
|
102
|
+
callback=__load_splunk_secret,
|
|
103
|
+
)
|
|
104
|
+
@click.option("--ciphertext", envvar="PASSWORD", prompt=True, callback=__ensure_text)
|
|
105
|
+
def dbconnect_decrypt(secret, ciphertext):
|
|
106
|
+
"""Decrypt password used for dbconnect identity"""
|
|
107
|
+
click.echo(decrypt_dbconnect(secret, ciphertext))
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@main.command("phantom-encrypt")
|
|
111
|
+
@click.option(
|
|
112
|
+
"-P",
|
|
113
|
+
"--private-key",
|
|
114
|
+
required=True,
|
|
115
|
+
envvar="PHANTOM_PRIVATE_KEY",
|
|
116
|
+
callback=__load_phantom_private_key,
|
|
117
|
+
)
|
|
118
|
+
@click.option(
|
|
119
|
+
"-S",
|
|
120
|
+
"--secret-key",
|
|
121
|
+
required=True,
|
|
122
|
+
envvar="PHANTOM_SECRET_KEY",
|
|
123
|
+
callback=__load_phantom_secret_key,
|
|
124
|
+
)
|
|
125
|
+
@click.option(
|
|
126
|
+
"--password",
|
|
127
|
+
envvar="PASSWORD",
|
|
128
|
+
prompt=True,
|
|
129
|
+
hide_input=True,
|
|
130
|
+
callback=__ensure_text,
|
|
131
|
+
)
|
|
132
|
+
@click.option(
|
|
133
|
+
"-A", "--asset-id", envvar="PHANTOM_ASSET_ID", prompt=True, callback=__ensure_int
|
|
134
|
+
)
|
|
135
|
+
def phantom_encrypt(private_key, secret_key, password, asset_id):
|
|
136
|
+
"""Encrypt password used for Phantom asset"""
|
|
137
|
+
click.echo(encrypt_phantom(private_key, secret_key, password, asset_id))
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
@main.command("phantom-decrypt")
|
|
141
|
+
@click.option(
|
|
142
|
+
"-P",
|
|
143
|
+
"--private-key",
|
|
144
|
+
required=True,
|
|
145
|
+
envvar="PHANTOM_PRIVATE_KEY",
|
|
146
|
+
callback=__load_phantom_private_key,
|
|
147
|
+
)
|
|
148
|
+
@click.option(
|
|
149
|
+
"-S",
|
|
150
|
+
"--secret-key",
|
|
151
|
+
required=True,
|
|
152
|
+
envvar="PHANTOM_SECRET_KEY",
|
|
153
|
+
callback=__load_phantom_secret_key,
|
|
154
|
+
)
|
|
155
|
+
@click.option("--ciphertext", envvar="PASSWORD", prompt=True, callback=__ensure_text)
|
|
156
|
+
@click.option(
|
|
157
|
+
"-A", "--asset-id", envvar="PHANTOM_ASSET_ID", prompt=True, callback=__ensure_int
|
|
158
|
+
)
|
|
159
|
+
def phantom_decrypt(private_key, secret_key, ciphertext, asset_id):
|
|
160
|
+
"""Decrypt password used for Phantom asset"""
|
|
161
|
+
click.echo(decrypt_phantom(private_key, secret_key, ciphertext, asset_id))
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
@main.command("splunk-encrypt")
|
|
165
|
+
@click.option(
|
|
166
|
+
"-S",
|
|
167
|
+
"--splunk-secret",
|
|
168
|
+
required=True,
|
|
169
|
+
envvar="SPLUNK_SECRET",
|
|
170
|
+
callback=__load_splunk_secret,
|
|
171
|
+
)
|
|
172
|
+
@click.option("-I", "--iv", envvar="SPLUNK_IV", callback=__ensure_binary)
|
|
173
|
+
@click.option(
|
|
174
|
+
"--password",
|
|
175
|
+
envvar="PASSWORD",
|
|
176
|
+
prompt=True,
|
|
177
|
+
hide_input=True,
|
|
178
|
+
callback=__ensure_text,
|
|
179
|
+
)
|
|
180
|
+
def splunk_encrypt(splunk_secret, password, iv=None):
|
|
181
|
+
"""Encrypt password using Splunk 7.2 algorithm"""
|
|
182
|
+
click.echo(encrypt_new(splunk_secret, password, iv))
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
@main.command("splunk-decrypt")
|
|
186
|
+
@click.option(
|
|
187
|
+
"-S",
|
|
188
|
+
"--splunk-secret",
|
|
189
|
+
required=True,
|
|
190
|
+
envvar="SPLUNK_SECRET",
|
|
191
|
+
callback=__load_splunk_secret,
|
|
192
|
+
)
|
|
193
|
+
@click.option("--ciphertext", envvar="PASSWORD", prompt=True, callback=__ensure_text)
|
|
194
|
+
def splunk_decrypt(splunk_secret, ciphertext):
|
|
195
|
+
"""Decrypt password using Splunk 7.2 algorithm"""
|
|
196
|
+
click.echo(decrypt(splunk_secret, ciphertext))
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
@main.command("splunk-legacy-encrypt")
|
|
200
|
+
@click.option(
|
|
201
|
+
"-S",
|
|
202
|
+
"--splunk-secret",
|
|
203
|
+
required=True,
|
|
204
|
+
envvar="SPLUNK_SECRET",
|
|
205
|
+
callback=__load_splunk_secret,
|
|
206
|
+
)
|
|
207
|
+
@click.option(
|
|
208
|
+
"--password",
|
|
209
|
+
envvar="PASSWORD",
|
|
210
|
+
prompt=True,
|
|
211
|
+
hide_input=True,
|
|
212
|
+
callback=__ensure_text,
|
|
213
|
+
)
|
|
214
|
+
@click.option("--no-salt/--salt", default=False)
|
|
215
|
+
def splunk_legacy_encrypt(splunk_secret, password, no_salt):
|
|
216
|
+
"""Encrypt password using legacy Splunk algorithm (pre-7.2)"""
|
|
217
|
+
click.echo(encrypt(splunk_secret, password, no_salt))
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
@main.command("splunk-legacy-decrypt")
|
|
221
|
+
@click.option(
|
|
222
|
+
"-S",
|
|
223
|
+
"--splunk-secret",
|
|
224
|
+
required=True,
|
|
225
|
+
envvar="SPLUNK_SECRET",
|
|
226
|
+
callback=__load_splunk_secret,
|
|
227
|
+
)
|
|
228
|
+
@click.option("--ciphertext", envvar="PASSWORD", prompt=True, callback=__ensure_text)
|
|
229
|
+
@click.option("--no-salt/--salt/=", default=False)
|
|
230
|
+
def splunk_legacy_decrypt(splunk_secret, ciphertext, no_salt):
|
|
231
|
+
"""Decrypt password using legacy Splunk algorithm (pre-7.2)"""
|
|
232
|
+
click.echo(decrypt(splunk_secret, ciphertext, no_salt))
|
|
233
|
+
|
|
234
|
+
@main.command("dbconnect-legacy-encrypt")
|
|
235
|
+
@click.option(
|
|
236
|
+
"-S",
|
|
237
|
+
"--secret",
|
|
238
|
+
required=True,
|
|
239
|
+
envvar="DBCONNECT_SECRET",
|
|
240
|
+
callback=__load_splunk_secret,
|
|
241
|
+
)
|
|
242
|
+
@click.option(
|
|
243
|
+
"--password",
|
|
244
|
+
envvar="PASSWORD",
|
|
245
|
+
prompt=True,
|
|
246
|
+
hide_input=True,
|
|
247
|
+
callback=__ensure_text,
|
|
248
|
+
)
|
|
249
|
+
def dbconnect_legacy_encrypt(secret, password):
|
|
250
|
+
"""Encrypt password used for dbconnect identity using legacy algorithm"""
|
|
251
|
+
click.echo(encrypt_dbconnect(secret, password, legacy=True))
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
@main.command("splunk-hash-passwd")
|
|
255
|
+
@click.option(
|
|
256
|
+
"--password",
|
|
257
|
+
envvar="PASSWORD",
|
|
258
|
+
prompt=True,
|
|
259
|
+
hide_input=True,
|
|
260
|
+
callback=__ensure_text,
|
|
261
|
+
)
|
|
262
|
+
def splunk_hash_passwd(password):
|
|
263
|
+
"""Generate password hash for use in $SPLUNK_HOME/etc/passwd"""
|
|
264
|
+
click.echo(pcrypt.crypt(password))
|