aboutsummaryrefslogtreecommitdiff
path: root/openssl/trunk/demos/bio/saccept.c
diff options
context:
space:
mode:
Diffstat (limited to 'openssl/trunk/demos/bio/saccept.c')
0 files changed, 0 insertions, 0 deletions
-10-18 23:53:23 +0000 committer Rob Austein <sra@hactrn.net> 2012-10-18 23:53:23 +0000 pylint' href='/sra/rpki.net/commit/rpkid/tests/testpoke.py?id=c4be735c645bdbcb86b2448899a3aa664d5e97df'>c4be735c
94bad6e5













a5845a3a











3f68e5c9

7476eb0d
3f68e5c9
94bad6e5
f49a0a66
3f68e5c9
1a623c6e








6d7cbc19
1a623c6e
55769ccf

1a623c6e

f7279fd3
1a623c6e


7cd197b5
6d7cbc19
1a623c6e


8542127f

6d7cbc19
6d7cbc19

1a623c6e
















3f68e5c9

88953a01
89e42691
88953a01







3f68e5c9
e970e3b6



444389ab
b7f3aa93
444389ab
aedaacf9
444389ab

aedaacf9
444389ab
2053fd91

cd006f96
125c61b4
b3a4636d

cd006f96
94bad6e5
b7f3aa93
94bad6e5
444389ab
b7f3aa93
3031f6ec

3f68e5c9

04b3090b
3f68e5c9

1a623c6e

1a623c6e
b22f2d2a




04b3090b
3f68e5c9

34aafaf8


04b3090b
3f68e5c9


c4be735c
72e42a65
086026a1
dba89077
04b3090b


f7599643
04b3090b


aedaacf9

2053fd91


b3a4636d

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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174




                                                                         

                                                            
                                              
                                             
 
                                                                         


    
                                                             













                                                                                  











                                                                           

   
                                  
                                                                  
                                              
                                                    
 








                           
             
 

                                                                                           

                                 
                             


                                
                              
                


          

                         
         

                          
















                                                        

             
                                     
            







                                                                                   
                         



                                              
                                                                         
 
                  
                             

                                                 
                                                               
                                      

                                    
                                            
           

                        
 
                                          
 
                   
                         
                                        

                        

              
                                        

               

                                                                           
                                      




                                                                
                      

                


                                      
                      


                                                                         
                                                               
                           
                                     
 


                                                       
                                                  


                                                          

                         


                              

                    
"""
Trivial RPKI up-down protocol client, for testing.

Configuration file is YAML to be compatable with APNIC rpki_poke.pl tool.

Usage: python testpoke.py [ { -y | --yaml }    configfile ]
                          [ { -r | --request } requestname ]
                          [ { -d | --debug } ]
                          [ { -h | --help } ]

Default configuration file is testpoke.yaml, override with --yaml option.

$Id$

Copyright (C) 2010--2012  Internet Systems Consortium ("ISC")

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS.  IN NO EVENT SHALL ISC 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.

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 notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND ARIN DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS.  IN NO EVENT SHALL 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.
"""

import os, time, getopt, sys, yaml
import rpki.resource_set, rpki.up_down, rpki.left_right, rpki.x509
import rpki.http, rpki.config, rpki.exceptions
import rpki.relaxng, rpki.oids, rpki.log, rpki.async

os.environ["TZ"] = "UTC"
time.tzset()

def usage(code):
  print __doc__
  sys.exit(code)

yaml_file = "testpoke.yaml"
yaml_cmd = None
debug = False

opts, argv = getopt.getopt(sys.argv[1:], "y:r:h?d", ["yaml=", "request=", "help", "debug"])
for o, a in opts:
  if o in ("-h", "--help", "-?"):
    usage(0)
  elif o in ("-y", "--yaml"):
    yaml_file = a
  elif o in ("-r", "--request"):
    yaml_cmd = a
  elif o in ("-d", "--debug"):
    debug = True
if argv:
  usage(1)

rpki.log.init("testpoke")

if debug:
  rpki.log.set_trace(True)

f = open(yaml_file)
yaml_data = yaml.load(f)
f.close()

if yaml_cmd is None and len(yaml_data["requests"]) == 1:
  yaml_cmd = yaml_data["requests"].keys()[0]

if yaml_cmd is None:
  usage(1)

yaml_req = yaml_data["requests"][yaml_cmd]

def get_PEM(name, cls, y = yaml_data):
  if name in y:
    return cls(PEM = y[name])
  if name + "-file" in y:
    return cls(PEM_file = y[name + "-file"])
  return None

def get_PEM_chain(name, cert = None):
  chain = []
  if cert is not None:
    chain.append(cert)
  if name in yaml_data:
    chain.extend([rpki.x509.X509(PEM = x) for x in yaml_data[name]])
  elif name + "-file" in yaml_data:
    chain.extend([rpki.x509.X509(PEM_file = x) for x in yaml_data[name + "-file"]])
  return chain

def query_up_down(q_pdu):
  q_msg = rpki.up_down.message_pdu.make_query(
    payload = q_pdu,
    sender = yaml_data["sender-id"],
    recipient = yaml_data["recipient-id"])
  q_der = rpki.up_down.cms_msg().wrap(q_msg, cms_key, cms_certs, cms_crl)

  def done(r_der):
    global last_cms_timestamp
    r_cms = rpki.up_down.cms_msg(DER = r_der)
    r_msg = r_cms.unwrap([cms_ta] + cms_ca_certs)
    last_cms_timestamp = r_cms.check_replay(last_cms_timestamp)
    print r_cms.pretty_print_content()
    try:
      r_msg.payload.check_response()
    except (rpki.async.ExitNow, SystemExit):
      raise
    except Exception, e:
      fail(e)

  rpki.http.want_persistent_client = False

  rpki.http.client(
    msg          = q_der,
    url          = yaml_data["posturl"],
    callback     = done,
    errback      = fail)

def do_list():
  query_up_down(rpki.up_down.list_pdu())

def do_issue():
  q_pdu = rpki.up_down.issue_pdu()
  req_key = get_PEM("cert-request-key", rpki.x509.RSA, yaml_req) or cms_key
  q_pdu.class_name = yaml_req["class"]
  q_pdu.pkcs10 = rpki.x509.PKCS10.create(
    keypair = req_key,
    is_ca = True,
    caRepository = yaml_req["sia"][0],
    rpkiManifest = yaml_req["sia"][0] + req_key.gSKI() + ".mft")
  query_up_down(q_pdu)

def do_revoke():
  q_pdu = rpki.up_down.revoke_pdu()
  q_pdu.class_name = yaml_req["class"]
  q_pdu.ski = yaml_req["ski"]
  query_up_down(q_pdu)

dispatch = { "list" : do_list, "issue" : do_issue, "revoke" : do_revoke }

def fail(e):                            # pylint: disable=W0621
  rpki.log.traceback(debug)
  sys.exit("Testpoke failed: %s" % e)

cms_ta         = get_PEM("cms-ca-cert", rpki.x509.X509)
cms_cert       = get_PEM("cms-cert", rpki.x509.X509)
cms_key        = get_PEM("cms-key", rpki.x509.RSA)
cms_crl        = get_PEM("cms-crl", rpki.x509.CRL)
cms_certs      = get_PEM_chain("cms-cert-chain", cms_cert)
cms_ca_certs   = get_PEM_chain("cms-ca-certs")

last_cms_timestamp = None

try:
  dispatch[yaml_req["type"]]()
  rpki.async.event_loop()
except Exception, e:
  fail(e)