<?xml version="1.0" encoding="UTF-8"?>
<!--
  Copyright (c) 2012 OpenDNSSEC AB (svb). All rights reserved.
  
  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:
  1. Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
     documentation and/or other materials provided with the distribution.
  
  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
-->
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  <start>
    <element name="EnforcerState">
      <element name="Zones">
        <oneOrMore>
          <ref name="zone"/>
        </oneOrMore>
      </element>
      <element name="KeyPairs">
        <oneOrMore>
          <ref name="keypair"/>
        </oneOrMore>
      </element>
    </element>
  </start>
  <!--
    create table zones(
      id            integer primary key autoincrement,    - - id
      name          varchar(300) not null ,  - - name of the parameter
      policy_id     mediumint not null,
      signconf      varchar(4096),  - - where is the signconf
      input         varchar(4096),  - - where is the input
      output        varchar(4096),  - - where is the output
      in_type       varchar(512),   - - input adapter type
      out_type      varchar(512),   - - output adapter type
      
      foreign key (policy_id) references policies (id)
    );
  -->
  <define name="zone">
    <element name="Zone">
      <!-- Name of zone -->
      <attribute name="name">
        <data type="string"/>
      </attribute>
      <element name="Keys">
        <oneOrMore>
          <ref name="key"/>
        </oneOrMore>
      </element>
      <optional>
        <element name="NSEC3">
          <element name="Salt">
            <data type="string"/>
          </element>
          <optional>
            <!-- when was the Salt generated -->
            <element name="Generated">
              <data type="dateTime"/>
            </element>
          </optional>
        </element>
      </optional>
    </element>
  </define>
  <!--
    create table dnsseckeys (
      id            integer primary key autoincrement,  - - unique id of the key
      keypair_id    smallint,
      zone_id        mediumint,
      keytype       smallint not null,             - - zsk or ksk (use code in dnskey record)
      state         tinyint,                      - - state of the key (defines valid fields)
      publish       varchar(64) null default null,  - - time when key published into the zone
      ready         varchar(64) null default null,  - - time when the key is ready for use
      active        varchar(64) null default null,  - - time when the key was made active
      retire        varchar(64) null default null,  - - time when the key retires
      dead          varchar(64) null default null,  - - time when key is slated for removal
    
    
      foreign key (zone_id) references zones (id),
      foreign key (keypair_id) references keypairs (id)
    );
  -->
  <define name="key">
    <element name="Key">
      <attribute name="id">
        <data type="string"/>
      </attribute>
      <!-- reference to KeyPair@id -->
      <element name="KeyPairId">
        <data type="string"/>
      </element>
      <element name="Type">
        <choice>
          <value>KSK</value>
          <value>ZSK</value>
          <value>CSK</value>
        </choice>
      </element>
      <optional>
        <element name="Standby">
          <empty/>
        </element>
      </optional>
      <optional>
        <element name="Publish">
          <choice>
            <data type="dateTime"/>
            <empty/>
          </choice>
        </element>
      </optional>
      <optional>
        <element name="Ready">
          <choice>
            <data type="dateTime"/>
            <empty/>
          </choice>
        </element>
      </optional>
      <optional>
        <element name="Active">
          <choice>
            <data type="dateTime"/>
            <empty/>
          </choice>
        </element>
      </optional>
      <optional>
        <element name="Retire">
          <choice>
            <data type="dateTime"/>
            <empty/>
          </choice>
        </element>
      </optional>
      <optional>
        <element name="Dead">
          <choice>
            <data type="dateTime"/>
            <empty/>
          </choice>
        </element>
      </optional>
    </element>
  </define>
  <!--
    create table keypairs(
      id     integer primary key autoincrement,
      HSMkey_id  varchar(255) not null,
      algorithm     tinyint not null,             - - algorithm code
      size          smallint,
      securitymodule_id          tinyint,                      - - where the key is stored
      generate      varchar(64) null default null,  - - time key inserted into database
      policy_id        mediumint,
      compromisedflag tinyint,
      publickey     varchar(1024),                - - public key data
      pre_backup    varchar(64) null default null,  - - time when backup was started
      backup        varchar(64) null default null,  - - time when backup was finished
      fixedDate     tinyint default 0,            - - Set to 1 to stop dates from being set according to the policy timings        
      
      foreign key (securitymodule_id) references securitymodules (id),
      foreign key (policy_id) references policies (id)
    );
  -->
  <define name="keypair">
    <element name="KeyPair">
      <attribute name="id">
        <data type="string"/>
      </attribute>
      <element name="Algorithm">
        <data type="nonNegativeInteger"/>
      </element>
      <element name="Size">
        <data type="nonNegativeInteger"/>
      </element>
      <!-- where to locate the key; HSM and CKA_ID -->
      <element name="Repository">
        <data type="string"/>
      </element>
      <element name="Locator">
        <data type="string"/>
      </element>
      <optional>
        <!-- under what policy was the key pair generated (if applicable) -->
        <element name="Policy">
          <data type="string"/>
        </element>
      </optional>
      <optional>
        <!-- when was the key originally generated -->
        <element name="Generated">
          <data type="dateTime"/>
        </element>
      </optional>
      <optional>
        <!-- when was the key last backed up -->
        <element name="LastBackup">
          <data type="dateTime"/>
        </element>
      </optional>
      <optional>
        <!-- is the key compromised? -->
        <element name="Compromised">
          <empty/>
        </element>
      </optional>
    </element>
  </define>
</grammar>
