<div class="bs-sidebar col-sm-3 " data-ng-include data-src="'partials/realm-menu.html'"></div>
<div id="content-area" class="col-sm-9" role="main">
    <kc-navigation-application></kc-navigation-application>
    <div id="content">
        <ol class="breadcrumb" data-ng-hide="create">
            <li><a href="#/realms/{{realm.realm}}/applications">Applications</a></li>
            <li><a href="#/realms/{{realm.realm}}/applications/{{application.id}}">{{application.name}}</a></li>
            <li class="active">Keys</li>
        </ol>
        <h2><span>{{application.name}}</span> Key Pair and Certificate <span tooltip-placement="right" tooltip="Application's key pair and certificate.  Used for more confidential interaction between application and auth server." class="fa fa-info-circle"></span></h2>
        <form class="form-horizontal" name="keyForm" novalidate kc-read-only="!access.manageRealm">
            <fieldset>
                <legend collapsed><span class="text">Import Keys and Cert</span> <span tooltip-placement="right" tooltip="Upload the client's key pair and cert." class="fa fa-info-circle"></span></legend>
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="uploadKeyFormat">Archive Format</label>
                    <div class="col-sm-6">
                        <div class="select-kc">
                            <select id="uploadKeyFormat"
                                    ng-model="uploadKeyFormat"
                                    ng-options="f for f in keyFormats">
                            </select>
                        </div>
                    </div>
                    <span tooltip-placement="right" tooltip="Java keystore or PKCS12 archive format." class="fa fa-info-circle"></span>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="uploadKeyAlias">Key Alias</label>
                    <div class="col-sm-4">
                        <input class="form-control" type="text" id="uploadKeyAlias" name="uploadKeyAlias" data-ng-model="uploadKeyAlias" autofocus required>
                    </div>
                    <span tooltip-placement="right" tooltip="Archive alias for your private key and certificate." class="fa fa-info-circle"></span>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="keyPassword">Key Password</label>
                    <div class="col-sm-4">
                        <input class="form-control" type="password" id="uploadKeyPassword" name="uploadKeyPassword" data-ng-model="uploadKeyPassword" autofocus required>
                    </div>
                    <span tooltip-placement="right" tooltip="Password to access the private key in the archive" class="fa fa-info-circle"></span>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="uploadStorePassword">Store Password</label>
                    <div class="col-sm-4">
                        <input class="form-control" type="password" id="uploadStorePassword" name="uploadStorePassword" data-ng-model="uploadStorePassword" autofocus required>
                    </div>
                    <span tooltip-placement="right" tooltip="Password to access the archive itself" class="fa fa-info-circle"></span>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">Upload Keys </label>
                    <div class="col-sm-4">
                        <div class="controls kc-button-input-file" data-ng-show="!files || files.length == 0">
                            <a href="#" class="btn btn-default"><span class="kc-icon-upload">Icon: Upload</span>Choose a File...</a>
                            <input id="import-file" type="file" class="transparent" ng-file-select="onFileSelect($files)">
                        </div>
                        <span class="kc-uploaded-file" data-ng-show="files.length > 0">
                            {{files[0].name}}
                        </span>
                    </div>
                </div>
                <div class="pull-right form-actions" data-ng-show="files.length > 0">
                    <button type="submit" data-ng-click="clearFileSelect()" class="btn btn-lg btn-default">Cancel</button>
                    <button type="submit" data-ng-click="uploadFile()" class="btn btn-lg btn-primary">Upload</button>
                </div>
            </fieldset>
            <fieldset class="form-group col-sm-10" data-ng-hide="!keyInfo.privateKey">
                <legend collapsed><span class="text">Download Keys and Cert</span>  <span tooltip-placement="right" tooltip="Client key pair, cert, and realm certificate will be stuffed into a PKCS12 or Java keystore that you can use in your applications." class="fa fa-info-circle"></span></legend>
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="downloadKeyFormat">Archive Format</label>
                    <div class="col-sm-6">
                        <div class="select-kc">
                            <select id="downloadKeyFormat"
                                    ng-model="jks.format"
                                    ng-options="f for f in keyFormats">
                            </select>
                        </div>
                    </div>
                    <span tooltip-placement="right" tooltip="Java keystore or PKCS12 archive format." class="fa fa-info-circle"></span>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="keyAlias">Key Alias</label>
                    <div class="col-sm-4">
                        <input class="form-control" type="text" id="keyAlias" name="keyAlias" data-ng-model="jks.keyAlias" autofocus required>
                    </div>
                    <span tooltip-placement="right" tooltip="Archive alias for your private key and certificate." class="fa fa-info-circle"></span>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="keyPassword">Key Password</label>
                    <div class="col-sm-4">
                        <input class="form-control" type="password" id="keyPassword" name="keyPassword" data-ng-model="jks.keyPassword" autofocus required>
                    </div>
                    <span tooltip-placement="right" tooltip="Password to access the private key in the archive" class="fa fa-info-circle"></span>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="realmAlias">Realm Certificate Alias</label>
                    <div class="col-sm-4">
                        <input class="form-control" type="text" id="realmAlias" name="realmAlias" data-ng-model="jks.realmAlias" autofocus required>
                    </div>
                    <span tooltip-placement="right" tooltip="Realm certificate is stored in archive too.  This is the alias to it." class="fa fa-info-circle"></span>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="storePassword">Store Password</label>
                    <div class="col-sm-4">
                        <input class="form-control" type="password" id="storePassword" name="storePassword" data-ng-model="jks.storePassword" autofocus required>
                    </div>
                    <span tooltip-placement="right" tooltip="Password to access the archive itself" class="fa fa-info-circle"></span>
               </div>
                <div class="form-group" data-ng-show="access.manageRealm">
                    <div class="pull-right">
                        <button class="btn btn-primary" type="submit" data-ng-click="downloadJKS()">Download</button>
                    </div>
                </div>
            </fieldset>
            <fieldset class="form-group col-sm-10">
                <legend><span class="text">Keys and Certificate</span>  <span tooltip-placement="right" tooltip="Keys and cert in PEM format." class="fa fa-info-circle"></span></legend>
                <div class="form-group" data-ng-hide="!keyInfo.privateKey">
                    <label class="col-sm-2 control-label" for="publicKey">Private key</label>

                    <div class="col-sm-10">
                        <textarea type="text" id="Private" name="publicKey" class="form-control" rows="5"
                                  kc-select-action="click" readonly>{{keyInfo.privateKey}}</textarea>
                    </div>
                </div>
                <div class="form-group" data-ng-hide="!keyInfo.privateKey">
                    <label class="col-sm-2 control-label" for="publicKey">Public key</label>

                    <div class="col-sm-10">
                        <textarea type="text" id="publicKey" name="publicKey" class="form-control" rows="5"
                                  kc-select-action="click" readonly>{{keyInfo.publicKey}}</textarea>
                    </div>
                </div>
                <div class="form-group" data-ng-hide="!keyInfo.privateKey">
                    <label class="col-sm-2 control-label" for="publicKey">Certificate</label>

                    <div class="col-sm-10">
                        <textarea type="text" id="certificate" name="certificate" class="form-control" rows="5"
                                  kc-select-action="click" readonly>{{keyInfo.certificate}}</textarea>
                    </div>
                </div>
                <div class="form-group" data-ng-show="access.manageRealm">
                    <div class="pull-right">
                        <button class="btn btn-primary" type="submit" data-ng-click="generate()">Generate new keys</button>
                    </div>
                </div>
            </fieldset>
        </form>
    </div>
</div>