00001 """ROA (Route Origin Authorization). 00002 00003 At the moment this is just the ASN.1 encoder. 00004 00005 This corresponds to draft-ietf-sidr-roa-format, which is a work in 00006 progress, so this may need updating later. 00007 00008 $Id: roa.py 1873 2008-06-12 02:49:41Z sra $ 00009 00010 Copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN") 00011 00012 Permission to use, copy, modify, and distribute this software for any 00013 purpose with or without fee is hereby granted, provided that the above 00014 copyright notice and this permission notice appear in all copies. 00015 00016 THE SOFTWARE IS PROVIDED "AS IS" AND ARIN DISCLAIMS ALL WARRANTIES WITH 00017 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 00018 AND FITNESS. IN NO EVENT SHALL ARIN BE LIABLE FOR ANY SPECIAL, DIRECT, 00019 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 00020 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 00021 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00022 PERFORMANCE OF THIS SOFTWARE. 00023 00024 draft-ietf-sidr-roa-format-02 2.1.3.2 specifies: 00025 00026 RouteOriginAttestation ::= SEQUENCE { 00027 version [0] INTEGER DEFAULT 0, 00028 asID ASID, 00029 exactMatch BOOLEAN, 00030 ipAddrBlocks ROAIPAddrBlocks } 00031 00032 ASID ::= INTEGER 00033 00034 ROAIPAddrBlocks ::= SEQUENCE of ROAIPAddressFamily 00035 00036 ROAIPAddressFamily ::= SEQUENCE { 00037 addressFamily OCTET STRING (SIZE (2..3)), 00038 addresses SEQUENCE OF IPAddress } 00039 00040 IPAddress ::= BIT STRING 00041 00042 ... but we now implement the new format that will supposedly appear 00043 in the upcoming draft-ietf-sidr-roa-format-03: 00044 00045 RouteOriginAttestation ::= SEQUENCE { 00046 version [0] INTEGER DEFAULT 0, 00047 asID ASID, 00048 ipAddrBlocks SEQUENCE OF ROAIPAddressFamily } 00049 00050 ASID ::= INTEGER 00051 00052 ROAIPAddressFamily ::= SEQUENCE { 00053 addressFamily OCTET STRING (SIZE (2..3)), 00054 addresses SEQUENCE OF ROAIPAddress } 00055 00056 ROAIPAddress ::= { 00057 address IPAddress, 00058 maxLength INTEGER OPTIONAL } 00059 00060 IPAddress ::= BIT STRING 00061 """ 00062 00063 from POW._der import * 00064 00065 class ROAIPAddress(Sequence): 00066 def __init__(self, optional=0, default=''): 00067 self.address = BitString() 00068 self.maxLength = Integer(1) 00069 contents = [ self.address, self.maxLength ] 00070 Sequence.__init__(self, contents, optional, default) 00071 00072 class ROAIPAddresses(SequenceOf): 00073 def __init__(self, optional=0, default=''): 00074 SequenceOf.__init__(self, ROAIPAddress, optional, default) 00075 00076 class ROAIPAddressFamily(Sequence): 00077 def __init__(self, optional=0, default=''): 00078 self.addressFamily = OctetString() 00079 self.addresses = ROAIPAddresses() 00080 contents = [ self.addressFamily, self.addresses ] 00081 Sequence.__init__(self, contents, optional, default) 00082 00083 class ROAIPAddressFamilies(SequenceOf): 00084 def __init__(self, optional=0, default=''): 00085 SequenceOf.__init__(self, ROAIPAddressFamily, optional, default) 00086 00087 class RouteOriginAttestation(Sequence): 00088 def __init__(self, optional=0, default=''): 00089 self.version = Integer() 00090 self.explicitVersion = Explicit(CLASS_CONTEXT, FORM_CONSTRUCTED, 0, self.version, 0, 'oAMCAQA=') 00091 self.asID = Integer() 00092 self.ipAddrBlocks = ROAIPAddressFamilies() 00093 contents = [ self.explicitVersion, self.asID, self.ipAddrBlocks ] 00094 Sequence.__init__(self, contents, optional, default)