User Tools

Site Tools


Installation and Setup IoT_pki into existing django project

This assumes that you already have an existing django project to which you want to add PKI module.

If you want to create an empty django project to install PKI into, then:

Create Virtual Environment for Python3

mkdir virtualenv
cd virtualenv
python3 -m venv iotpki
source iotpki/bin/activate


Install Django and IoT-pki

pip install django
pip install django-IoT-pki

Create empty Django Project

django-admin startproject mytestpki

Create directory for logs (optional)

sudo mkdir /var/log/zibawa
sudo chmod 751 /var/log/zibawa
sudo chown -R zibawa:zibawa /var/log/zibawa

Create Super User

python createsuperuser

Add hostname to allowed hosts

ALLOWED_HOSTS = ['localhost','','','']

Add IoT_pki and rest_framework to Installed apps


Add the following settings to your if you dont have them already defined.

#redirects users to admin interface for login
#pki sends new certs to any user when defined in email request

#used to create and renew X509 certificates.  The certificate and key used at below location will be used to sign
#all certificates generated by PKI
     'use_ssl':True,#should always be True except for testing
     'verify_certs':False,#verify identity of server should be True except for testing
     'path_to_certstore':'/home/myCA/certs/',#requires trailing slash, place to keep CA certs
     'path_to_keystore':'/home/myCA/private/',#requires trailing slash. place to keep ca keys should be permission 400
     'auto_approve_requests':False,#should be FALSE (true will automatically approve all requests)

CERT_DEFAULTS={'country_name':"ES",#obligatory must be 2 letter country code 
               'valid_days':365,#validity of certificates generated must be integer not string

#used as part of PKI
    'PAGE_SIZE': 10

If you are installing IoT_pki as a stand alone from github, the below is not necessary, since you will install as part of the github package. However, if you are adding to an existing django project, you will need to include the following:

In your main you need to add the following (to use the Django Rest Framework)

from django.conf.urls import url
from django.contrib import admin

from django.conf.urls import include
from rest_framework import routers
from rest_framework.documentation import include_docs_urls
from IoT_pki import views

router = routers.DefaultRouter()

urlpatterns = [
    url(r'^IoT_pki/', include('IoT_pki.urls',namespace='IoT_pki')),
    url(r'^', include(router.urls)),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
    url(r'^docs/', include_docs_urls(title='zibawa_PKI'))

Perform Database Migration

Move into your project directory that should have been created just below where you are.

cd mytestpki
python migrate

Start the development server

python runserver
pki/installation_django.txt · Last modified: 2017/07/21 13:17 by matt