aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rpki/pubd.py65
-rw-r--r--rpki/publication.py2
-rw-r--r--rpki/relaxng.py2
-rw-r--r--rpki/sql_schemas.py2
-rw-r--r--schemas/relaxng/publication.rng2
5 files changed, 67 insertions, 6 deletions
diff --git a/rpki/pubd.py b/rpki/pubd.py
index 0ee4d38c..8f5b2605 100644
--- a/rpki/pubd.py
+++ b/rpki/pubd.py
@@ -110,6 +110,7 @@ class main(object):
self.publication_multimodule = self.cfg.getboolean("publication-multimodule", False)
self.rrdp_expiration_interval = rpki.sundial.timedelta.parse(self.cfg.get("rrdp-expiration-interval", "6h"))
+ self.rrdp_uri_base = self.cfg.get("rrdp-uri-base")
self.rrdp_publication_base = self.cfg.get("rrdp-publication-base", "rrdp-publication/")
self.session = session_obj.fetch(self)
@@ -227,7 +228,7 @@ class session_obj(rpki.sql.sql_persistent):
def new_snapshot(self):
return snapshot_obj.create(self)
- def add_snapshot(self, new_snapshot):
+ def activate_snapshot(self, new_snapshot):
now = rpki.sundial.now()
old_snapshot = self.current_snapshot
if old_snapshot is not None:
@@ -242,6 +243,66 @@ class session_obj(rpki.sql.sql_persistent):
(self.session_id, rpki.sundial.now())):
snapshot.sql_delete()
+ def write_notification(self):
+ """
+ Write current notification file to disk.
+ """
+
+ serial = self.current_shapshot.serial
+ fn = "%s/notification.xml" % self.uuid
+
+ xml = Element(rrdp_namespace + "notification",
+ version = rrdp_version,
+ session_id = uuid,
+ serial = serial)
+
+ SubElement(xml, rrdp_namespace + "snapshot",
+ uri = "%s/%s/snapshot/%d.xml" % (self.rrdp_uri_base, self.uuid, serial),
+ hash = um_where_do_we_store_this)
+
+ for delta in some_sql_query_here():
+ SubElement(xml, rrdp_namespace + "delta",
+ from = delta.from_serial,
+ to = delta.to_serial,
+ uri = delta.uri,
+ hash = delta.hash)
+
+ rpki.relaxng.rrdp.assertValid(xml)
+ tn = os.path.join(self.rrdp_publication_base, fn + ".%s.tmp" % os.getpid())
+ if not os.path.isdir(os.path.dirname(tn)):
+ os.makedirs(os.path.dirname(tn))
+ ElementTree(xml).write(tn)
+ os.rename(tn, os.path.join(self.rrdp_publication_base, fn))
+
+
+ def write_snapshot(self):
+ """
+ Write current RRDP snapshot to disk.
+ """
+
+ serial = self.current_shapshot.serial
+ fn = "%s/snapshot/%d.xml" % (self.uuid, serial)
+
+ if os.path.exists(os.path.join(self.rrdp_publication_base, fn)):
+ logger.warning("Snapshot %s already exists, this is suprising, not regenerating")
+ return
+
+ xml = Element(rrdp_namespace + "snapshot", version = rrdp_version, session_id = uuid, serial = serial)
+
+ for obj in object_obj.sql_fetch_where(self.gctx, "session_id = %s AND withdrawn_snapshot_id IS NULL",
+ (self.session_id,)):
+ se = SubElement(xml, rrdp_namespace + "publish", uri = obj.uri)
+ se.text = "\n" + obj.get_Base64()
+ se.tail = "\n"
+
+ rpki.relaxng.rrdp.assertValid(xml)
+
+ tn = os.path.join(self.rrdp_publication_base, fn + ".%s.tmp" % os.getpid())
+ if not os.path.isdir(os.path.dirname(tn)):
+ os.makedirs(os.path.dirname(tn))
+ ElementTree(xml).write(tn)
+ os.rename(tn, os.path.join(self.rrdp_publication_base, fn))
+
class snapshot_obj(rpki.sql.sql_persistent):
"""
@@ -341,7 +402,7 @@ class object_obj(rpki.sql.sql_persistent):
self.gctx = snapshot.gctx
self.uri = uri
self.payload = obj
- self.hash = rpki.x509.sha256(obj.get_Base64()).encode("hex")
+ self.hash = rpki.x509.sha256(obj.get_DER()).encode("hex")
logger.debug("Computed hash %s of %r", self.hash, obj)
self.published_snapshot_id = snapshot.snapshot_id
self.withdrawn_snapshot_id = None
diff --git a/rpki/publication.py b/rpki/publication.py
index ec088a46..c09f4895 100644
--- a/rpki/publication.py
+++ b/rpki/publication.py
@@ -286,7 +286,7 @@ class msg(rpki.xml_utils.msg, publication_namespace):
fail(e)
def done():
- gctx.session.add_snapshot(snapshot)
+ gctx.session.activate_snapshot(snapshot)
cb(r_msg)
rpki.async.iterator(self, loop, done)
diff --git a/rpki/relaxng.py b/rpki/relaxng.py
index 93ac16fe..5e86df7c 100644
--- a/rpki/relaxng.py
+++ b/rpki/relaxng.py
@@ -1763,7 +1763,7 @@ publication_control = lxml.etree.RelaxNG(lxml.etree.fromstring(r'''<?xml version
## Parsed RelaxNG publication schema
publication = lxml.etree.RelaxNG(lxml.etree.fromstring(r'''<?xml version="1.0" encoding="UTF-8"?>
<!--
- $Id: publication.rnc 5888 2014-07-09 05:39:54Z sra $
+ $Id: publication.rnc 5896 2014-07-15 19:34:32Z sra $
RelaxNG schema for RPKI publication protocol, from current I-D.
diff --git a/rpki/sql_schemas.py b/rpki/sql_schemas.py
index b28c8231..93909c02 100644
--- a/rpki/sql_schemas.py
+++ b/rpki/sql_schemas.py
@@ -245,7 +245,7 @@ CREATE TABLE ee_cert (
## @var pubd
## SQL schema pubd
-pubd = '''-- $Id: pubd.sql 5887 2014-07-07 23:13:35Z sra $
+pubd = '''-- $Id: pubd.sql 5896 2014-07-15 19:34:32Z sra $
-- Copyright (C) 2012--2014 Dragon Research Labs ("DRL")
-- Portions copyright (C) 2009--2010 Internet Systems Consortium ("ISC")
diff --git a/schemas/relaxng/publication.rng b/schemas/relaxng/publication.rng
index 39d78c00..5e72407e 100644
--- a/schemas/relaxng/publication.rng
+++ b/schemas/relaxng/publication.rng
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- $Id: publication.rnc 5888 2014-07-09 05:39:54Z sra $
+ $Id: publication.rnc 5896 2014-07-15 19:34:32Z sra $
RelaxNG schema for RPKI publication protocol, from current I-D.