Skip to content

Commit

Permalink
Hashit - 17803 - Initial updates for fedramp compliance | Updated SDK…
Browse files Browse the repository at this point in the history
… to the latest version (#2847) (#2861)
  • Loading branch information
igorski-r7 authored Oct 15, 2024
1 parent 7e53d75 commit ae5b385
Show file tree
Hide file tree
Showing 21 changed files with 263 additions and 128 deletions.
12 changes: 6 additions & 6 deletions plugins/hashit/.CHECKSUM
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"spec": "4b2e7fb4e53fbb4058959bf1c21c0336",
"manifest": "2266fae404b187ccd184de5013286d78",
"setup": "d5b8763431696ffa240187e6650c3053",
"spec": "d74a532ec96208983185cdbd72be210d",
"manifest": "d063ac941d7bac907db3d5f42ec47c99",
"setup": "9e913725f17cc07c7831d7dc287c075e",
"schemas": [
{
"identifier": "bytes/schema.py",
"hash": "d8126ff2762dc3e4346b1d8b5dcdb97f"
"hash": "12d95875327550a29b6e95c5d79bbe04"
},
{
"identifier": "string/schema.py",
"hash": "dd15df8e8b56733279a2af04b8177cd6"
"hash": "66fa6e6c7596988cd7d1ef22d69bc70f"
},
{
"identifier": "connection/schema.py",
"hash": "da5382221ca2a33a2f854e17b068d502"
"hash": "bd524b567f9638ba1c6f7e0c9e45ff2e"
}
]
}
20 changes: 11 additions & 9 deletions plugins/hashit/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
FROM rapid7/insightconnect-python-3-38-slim-plugin:4
# Add any custom package dependencies here
# NOTE: Add pip packages to requirements.txt
FROM --platform=linux/amd64 rapid7/insightconnect-python-3-slim-plugin:6.1.3

# End package dependencies
LABEL organization=rapid7
LABEL sdk=python

# Add source code
WORKDIR /python/src

ADD ./plugin.spec.yaml /plugin.spec.yaml
ADD . /python/src
ADD ./requirements.txt /python/src/requirements.txt

# Install pip dependencies
RUN if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

# Install plugin
ADD . /python/src

RUN python setup.py build && python setup.py install

ENTRYPOINT ["/usr/local/bin/icon_hashit"]
# User to run plugin code. The two supported users are: root, nobody
USER nobody

ENTRYPOINT ["/usr/local/bin/icon_hashit"]
46 changes: 30 additions & 16 deletions plugins/hashit/bin/icon_hashit
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
#!/usr/bin/env python
# GENERATED BY KOMAND SDK - DO NOT EDIT
import insightconnect_plugin_runtime
from icon_hashit import connection, actions, triggers

# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
import os
import json
from sys import argv

Name = "HashIt"
Vendor = "rapid7"
Version = "2.0.4"
Version = "2.0.5"
Description = "Generate Common Hashes from a File or String"


class ICONHashit(insightconnect_plugin_runtime.Plugin):
def __init__(self):
super(self.__class__, self).__init__(
name=Name,
vendor=Vendor,
def main():
if 'http' in argv:
if os.environ.get("GUNICORN_CONFIG_FILE"):
with open(os.environ.get("GUNICORN_CONFIG_FILE")) as gf:
gunicorn_cfg = json.load(gf)
if gunicorn_cfg.get("worker_class", "sync") == "gevent":
from gevent import monkey
monkey.patch_all()
elif 'gevent' in argv:
from gevent import monkey
monkey.patch_all()

import insightconnect_plugin_runtime
from icon_hashit import connection, actions, triggers, tasks

class ICONHashit(insightconnect_plugin_runtime.Plugin):
def __init__(self):
super(self.__class__, self).__init__(
name=Name,
vendor=Vendor,
version=Version,
description=Description,
connection=connection.Connection()
)
self.add_action(actions.Bytes())

self.add_action(actions.String())
)
self.add_action(actions.String())

self.add_action(actions.Bytes())



def main():
"""Run plugin"""
cli = insightconnect_plugin_runtime.CLI(ICONHashit())
cli.run()
Expand Down
86 changes: 46 additions & 40 deletions plugins/hashit/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,34 @@ The HashIt plugin will generate common hashes from a file or string. Supported h
* Generate a hash from a provided text string input

# Requirements

*This plugin does not contain any requirements.*

_This plugin does not contain any requirements._
# Supported Product Versions

* 2024-10-08

# Documentation

## Setup

_This plugin does not contain a connection._
*This plugin does not contain a connection.*

## Technical Details

### Actions


#### Hash Bytes

This action is used to return the supported hashes for a file type.
This action is used to generate hashes from file bytes

##### Input

|Name|Type|Default|Required|Description|Enum|Example|
|----|----|-------|--------|-----------|----|-------|
|bytes|bytes|None|True|Base64 encoded file bytes to hash|None|aGVsbG8gd29ybGQ=|

|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip|
| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- |
|bytes|bytes|None|True|Base64 encoded file bytes to hash|None|aGVsbG8gd29ybGQ=|None|None|
Example input:

```
Expand All @@ -46,36 +51,34 @@ Example input:

##### Output

|Name|Type|Required|Description|
|----|----|--------|-----------|
|md5|string|False|MD5 hash|
|sha1|string|False|SHA1 hash|
|sha256|string|False|SHA256 hash|
|sha512|string|False|SHA512 hash|

|Name|Type|Required|Description|Example|
| :--- | :--- | :--- | :--- | :--- |
|md5|string|False|MD5 hash|098f6bcd4621d373cade4e832627b4f6|
|sha1|string|False|SHA1 hash|a94a8fe5ccb19ba61c4c0873d391e987982fbbd3|
|sha256|string|False|SHA256 hash|9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08|
|sha512|string|False|SHA512 hash|ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff|
Example output:

```
{
"md5": "098f6bcd4621d373cade4e832627b4f6",
"sha1": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
"sha256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
"sha512": "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff"
}
```

#### Hash String

This action is used to return the supported hashes for a string.
This action is used to generate hashes from text

##### Input

|Name|Type|Default|Required|Description|Enum|Example|
|----|----|-------|--------|-----------|----|-------|
|string|string|None|True|String of text to hash|None|hello world|

|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip|
| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- |
|string|string|None|True|String of text to hash|None|hello world|None|None|
Example input:

```
Expand All @@ -86,40 +89,41 @@ Example input:

##### Output

|Name|Type|Required|Description|
|----|----|--------|-----------|
|md5|string|False|MD5 hash|
|sha1|string|False|SHA1 hash|
|sha256|string|False|SHA256 hash|
|sha512|string|False|SHA512 hash|

|Name|Type|Required|Description|Example|
| :--- | :--- | :--- | :--- | :--- |
|md5|string|False|MD5 hash|098f6bcd4621d373cade4e832627b4f6|
|sha1|string|False|SHA1 hash|a94a8fe5ccb19ba61c4c0873d391e987982fbbd3|
|sha256|string|False|SHA256 hash|9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08|
|sha512|string|False|SHA512 hash|ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff|
Example output:

```
{
"md5": "098f6bcd4621d373cade4e832627b4f6",
"sha1": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
"sha256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
"sha512": "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff"
}
```

### Triggers

*This plugin does not contain any triggers.*
### Tasks

*This plugin does not contain any tasks.*

_This plugin does not contain any triggers._

### Custom Output Types

_This plugin does not contain any custom output types._
### Custom Types

*This plugin does not contain any custom output types.*

## Troubleshooting

_This plugin does not contain any troubleshooting information._
*This plugin does not contain a troubleshooting.*

# Version History

* 2.0.5 - Initial updates for fedramp compliance | Updated SDK to the latest version
* 2.0.4 - Update to v4 Python plugin runtime
* 2.0.3 - Change docker image from `komand/python-pypy3-plugin:2` to `komand/python-3-37-slim-plugin:3` to reduce plugin image size | Use input and output constants | Remove test from actions
* 2.0.2 - New spec and help.md format for the Extension Library
Expand All @@ -132,6 +136,8 @@ _This plugin does not contain any troubleshooting information._

# Links

* [Hashlib](https://docs.python.org/3.4/library/hashlib.html)

## References

* [Hashlib](https://docs.python.org/3.4/library/hashlib.html)
* [Hashlib](https://docs.python.org/3.4/library/hashlib.html)
7 changes: 5 additions & 2 deletions plugins/hashit/icon_hashit/actions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# GENERATED BY KOMAND SDK - DO NOT EDIT
from .bytes.action import Bytes
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT

from .string.action import String

from .bytes.action import Bytes

2 changes: 1 addition & 1 deletion plugins/hashit/icon_hashit/actions/bytes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# GENERATED BY KOMAND SDK - DO NOT EDIT
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
from .action import Bytes
19 changes: 8 additions & 11 deletions plugins/hashit/icon_hashit/actions/bytes/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ def __init__(self):
)

def run(self, params={}):
raw = base64.standard_b64decode(params[Input.BYTES])
md5 = hashlib.md5(raw).hexdigest() # nosec
sha1 = hashlib.sha1(raw).hexdigest() # nosec
sha256 = hashlib.sha256(raw).hexdigest()
sha512 = hashlib.sha512(raw).hexdigest()
# START INPUT BINDING - DO NOT REMOVE - ANY INPUTS BELOW WILL UPDATE WITH YOUR PLUGIN SPEC AFTER REGENERATION
input_bytes = base64.standard_b64decode(params.get(Input.BYTES, ""))
# END INPUT BINDING - DO NOT REMOVE

hashes = {
Output.MD5: md5,
Output.SHA1: sha1,
Output.SHA256: sha256,
Output.SHA512: sha512,
return {
Output.MD5: hashlib.md5(input_bytes).hexdigest(), # nosec
Output.SHA1: hashlib.sha1(input_bytes).hexdigest(), # nosec
Output.SHA256: hashlib.sha256(input_bytes).hexdigest(),
Output.SHA512: hashlib.sha512(input_bytes).hexdigest(),
}
return hashes
19 changes: 10 additions & 9 deletions plugins/hashit/icon_hashit/actions/bytes/schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GENERATED BY KOMAND SDK - DO NOT EDIT
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
import insightconnect_plugin_runtime
import json

Expand All @@ -9,33 +9,33 @@ class Component:

class Input:
BYTES = "bytes"


class Output:
MD5 = "md5"
SHA1 = "sha1"
SHA256 = "sha256"
SHA512 = "sha512"


class BytesInput(insightconnect_plugin_runtime.Input):
schema = json.loads("""
schema = json.loads(r"""
{
"type": "object",
"title": "Variables",
"properties": {
"bytes": {
"type": "string",
"title": "Bytes",
"format": "bytes",
"displayType": "bytes",
"description": "Base64 encoded file bytes to hash",
"format": "bytes",
"order": 1
}
},
"required": [
"bytes"
]
],
"definitions": {}
}
""")

Expand All @@ -44,7 +44,7 @@ def __init__(self):


class BytesOutput(insightconnect_plugin_runtime.Output):
schema = json.loads("""
schema = json.loads(r"""
{
"type": "object",
"title": "Variables",
Expand Down Expand Up @@ -73,7 +73,8 @@ class BytesOutput(insightconnect_plugin_runtime.Output):
"description": "SHA512 hash",
"order": 4
}
}
},
"definitions": {}
}
""")

Expand Down
2 changes: 1 addition & 1 deletion plugins/hashit/icon_hashit/actions/string/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# GENERATED BY KOMAND SDK - DO NOT EDIT
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
from .action import String
Loading

0 comments on commit ae5b385

Please sign in to comment.