1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# $Id$
#
# Copyright (C) 2013--2014 Dragon Research Labs ("DRL")
# Portions copyright (C) 2009--2012 Internet Systems Consortium ("ISC")
# Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN")
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notices and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND DRL, ISC, AND ARIN DISCLAIM ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DRL,
# ISC, OR ARIN BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""
RPKI publication protocol.
"""
import os
import errno
import logging
import rpki.resource_set
import rpki.x509
import rpki.sql
import rpki.exceptions
import rpki.xml_utils
import rpki.http
import rpki.up_down
import rpki.relaxng
import rpki.sundial
import rpki.log
from lxml.etree import Element, SubElement
logger = logging.getLogger(__name__)
nsmap = rpki.relaxng.publication.nsmap
version = rpki.relaxng.publication.version
tag_msg = rpki.relaxng.publication.xmlns + "msg"
tag_list = rpki.relaxng.publication.xmlns + "list"
tag_publish = rpki.relaxng.publication.xmlns + "publish"
tag_withdraw = rpki.relaxng.publication.xmlns + "withdraw"
tag_report_error = rpki.relaxng.publication.xmlns + "report_error"
def raise_if_error(pdu):
"""
Raise an appropriate error if this is a <report_error/> PDU.
As a convience, this will also accept a <msg/> PDU and raise an
appropriate error if it contains any <report_error/> PDUs.
"""
if pdu.tag == tag_report_error:
code = pdu.get("error_code")
logger.debug("<report_error/> code %r", code)
e = getattr(rpki.exceptions, code, None)
if e is not None and issubclass(e, rpki.exceptions.RPKI_Exception):
raise e(pdu.text)
else:
raise rpki.exceptions.BadPublicationReply("Unexpected response from pubd: %r, %r" % (code, pdu))
if pdu.tag == tag_msg:
for p in pdu:
raise_if_error(p)
class cms_msg_no_sax(rpki.x509.XML_CMS_object):
"""
Class to hold a CMS-signed publication PDU.
Name is a transition kludge: once we ditch SAX, this will become cms_msg.
"""
encoding = "us-ascii"
schema = rpki.relaxng.publication
|