Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sample for signature cloudhub rest and added single line on sam… #111

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion python/flask/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ wheel>=0.31.1
docopt>=0.6.1
restpki-client>=1.1.1
pkiexpress>=1.10.0
amplia-client>=1.0.0
amplia-client>=1.0.0
cloudhub-client >= 1.0.1
1 change: 1 addition & 0 deletions python/flask/sample/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

def create_app():
app = Flask(__name__)
app.env = os.getenv('FLASK_ENV')

# Select configuration based on the application environment.
if app.env not in config:
Expand Down
4 changes: 4 additions & 0 deletions python/flask/sample/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class Config(object):
# Web PKI
# --------------------------------------------------------------------------
WEB_PKI_LICENSE = None
# --------------------------------------------------------------------------
# Cloudhub
# --------------------------------------------------------------------------
CLOUDHUB_API_KEY = 'mR1j0v7L12lBHnxpgxVkIdikCN9Gm89rn8I9qet3UHo='


class ProductionConfig(Config):
Expand Down
3 changes: 3 additions & 0 deletions python/flask/sample/templates/home/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
signPdfCloudOAuth: {
express: '/check-express/upload/pades-cloud-oauth'
},
signPdfCloudhubServer: {
restpki: 'check-rest-token/server-files/pades-signature-cloudhub/signPdf'
},
signXmlServer: {
restpki: '/check-rest-token/xml-signature'
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{% extends "layout.html" %}

{% block content %}

<h2 class="ls-title">PAdES Signature using cloud certificate with Cloudhub</h2>

{% if services.services|length > 0 %}
<h5 class="ls-subtitle">Trusted services were found with this CPF</h5>
<div class="ls-content">
<form id="oauthFlowForm" action="/pades-signature-cloudhub-rest/authorize/" method="POST">
<div class="form-group">
<div class="px-0">
<label for="serviceField">Choose your trust provider:</label>
<select id="serviceField" name="service" class="form-control col col-sm-2" >
{% for s in services.services %}
<option value="{{ s.auth_url }}">{{s.service_info.service_name}} ({{s.service_info.provider}})</option>
{% endfor %}
</select>
</div>
</div>
<button type="button" class="btn btn-primary" onclick="redirectUser()">
<i class="fas fa-file-signature"></i> Sign
</button>
</form>
</div>
{% else %}
<h5 class="ls-subtitle">No trusted services were found with this CPF</h5>
<div class="ls-content">
<p>Possible reasons include:
<ul>
<li>The given CPF does not exist on trusted services</li>
<li>The PKI Express was not correctly configured</li>
</ul>
</p>
<p>To configure the PKI Express you need to configure all providers by running the
following commands on the terminal: <br/>
<code>pkie config --set trustServices:{provider}:clientId={value}</code><br/>
<code>pkie config --set trustServices:{provider}:clientSecret={value}</code>
</p>
<p>For customized providers you neet to also configure the endpoint:<br/>
<code>pkie config --set trustServices:{provider}:endpoint={value}</code>
</p>
<p>The standard providers are:
<ul>
<li>BirdID (Soluti)</li>
<li>ViDaaS (VALID)</li>
<li>NeoID (SERPRO)</li>
<li>RemoteID (Certisign)</li>
<li>SafeID (Safeweb)</li>
</ul>
</p>
<button onclick="window.history.back()" class="btn btn-primary">Try Again</button>
</div>
{% endif %}

{% endblock %}

{% block scripts %}

<script fragment="scripts" type="text/javascript" inline="javascript">
function redirectUser() {
// Get redirect URL of the chosen provide.
var redirectUrl = $('#serviceField').val();
// Redirect user.
window.location = redirectUrl;
}
</script>

{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "layout.html" %}

{% block content %}

<h2 class="ls-title">PAdES Signature using cloud certificate with Cloudhub</h2>

<div class="ls-content">
<form id="selectFlowForm" action="/pades-signature-cloudhub-rest/discover/{{ request.view_args.get('file_id') }}" method="POST">
<div class="px-0 col col-sm-2">
<label for="cpfField">Inform your CPF:</label>
<input id="cpfField" class="form-control" type="text" name="cpf" placeholder="000.000.000-00" value="{{ cpf }}"/>
</div>

<button id="searchButton" type="submit" class="btn btn-primary mt-2">
<i class="fas fa-search"></i> Search
</button>

</form>
</div>

{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "layout.html" %}

{% block content %}

<h2 class="ls-title">PAdES Signature using cloud certificate with Cloudhub</h2>

<p>File signed successfully!</p>

<h3>Actions:</h3>
<ul>
<li><a href="/download/{{ signed_pdf }}">Download the signed file</a></li>
<li><a href="/printer-version-pades-rest/{{ signed_pdf }}">Download a printer-friendly version of the signed file</a></li>
<li><a href="/open-pades-rest/{{ signed_pdf }}">Open/validate the signed file</a></li>
<li><a href="/pades-signature-rest/{{ signed_pdf }}">Co-sign with another certificate</a></li>
</ul>

{% endblock %}
8 changes: 6 additions & 2 deletions python/flask/sample/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pkiexpress import TimestampAuthority
from restpki_client import RestPkiClient
from restpki_client import StandardSecurityContexts
from cloudhub_client import Configuration, SessionsApi, ApiClient


# region REST PKI
Expand Down Expand Up @@ -69,7 +70,11 @@ def get_security_context_id():
else:
# In production, accepting only certificates from ICP-Brasil
return StandardSecurityContexts.PKI_BRAZIL


def get_cloudhub_client_api():
configuration = Configuration()
configuration.api_key['X-Api-Key'] = current_app.config['CLOUDHUB_API_KEY']
return SessionsApi(ApiClient(configuration))
# endregion


Expand Down Expand Up @@ -141,7 +146,6 @@ def set_pki_defaults(operator):

# endregion


def format_date(date):
return date.strftime("%m-%d-%Y")

Expand Down
2 changes: 2 additions & 0 deletions python/flask/sample/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from .xml_nfe_signature_rest import blueprint as xml_nfe_signature_rest
from .xml_signature_rest import blueprint as xml_signature_rest
from .server_files import blueprint as server_files
from .pades_signature_cloudhub_rest import blueprint as pades_signature_cloudhub_rest

blueprints = {
authentication_express,
Expand All @@ -64,6 +65,7 @@
open_pades_rest,
pades_server_key_express,
pades_signature_express,
pades_signature_cloudhub_rest,
pades_signature_restpki,
pades_cloud_pwd_express,
pades_cloud_oauth_express,
Expand Down
Loading