aboutsummaryrefslogtreecommitdiff
path: root/potpourri/cross_certify.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2014-04-10 22:56:47 +0000
committerRob Austein <sra@hactrn.net>2014-04-10 22:56:47 +0000
commit45b95aaadc861b0e682373164fe18fa0c5ed2b2e (patch)
tree6e415c4dd6b78e84a58ae0038ab9847fb69feafc /potpourri/cross_certify.py
parent5e0d1807ca7b049bde262a529443924adfd903e6 (diff)
parentb7459d825cfadb9db265ed1b3bd0c10682464767 (diff)
Merge tk685 branch back to trunk. This completes the move of the rpki
libraries and rpki.POW module from the rpki-ca package to the rpki-rp package. Closes #685, closes #633. svn path=/trunk/; revision=5784
Diffstat (limited to 'potpourri/cross_certify.py')
-rw-r--r--potpourri/cross_certify.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/potpourri/cross_certify.py b/potpourri/cross_certify.py
new file mode 100644
index 00000000..fab7743b
--- /dev/null
+++ b/potpourri/cross_certify.py
@@ -0,0 +1,74 @@
+# $Id$
+#
+# Copyright (C) 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.
+
+"""
+Cross-certification tool to issue a new certificate based on an old
+one that was issued by somebody else. The point of the exercise is to
+end up with a valid certificate in our own BPKI which has the same
+subject name and subject public key as the one we're replacing.
+"""
+
+import os
+import sys
+import time
+import argparse
+import rpki.x509
+import rpki.sundial
+
+os.environ["TZ"] = "UTC"
+time.tzset()
+
+parser = argparse.ArgumentParser(description = __doc__)
+parser.add_argument("-i", "--in", required = True, dest = "input",
+ type = lambda s: rpki.x509.X509(Auto_file = s),
+ help = "input certificate")
+parser.add_argument("-c", "--ca", required = True,
+ type = lambda s: rpki.x509.X509(Auto_file = s),
+ help = "issuing certificate")
+parser.add_argument("-k", "--key", required = True,
+ type = lambda s: rpki.x509.RSA(Auto_file = s),
+ help = "private key of issuing certificate")
+parser.add_argument("-s", "--serial", required = True,
+ help = "serial number file")
+parser.add_argument("-o", "--out",
+ help = "output filename")
+parser.add_argument("-l", "--lifetime",
+ type = rpki.sundial.timedelta, default = "30d",
+ help = "lifetime of generated certificate")
+args = parser.parse_args()
+
+now = rpki.sundial.now()
+notAfter = now + args.lifetime
+
+try:
+ with open(args.serial, "r") as f:
+ serial = int(f.read().splitlines()[0], 16)
+except IOError:
+ serial = 1
+
+cert = args.ca.cross_certify(args.key, args.input, serial, notAfter, now)
+
+with open(args.serial, "w") as f:
+ f.write("%02x\n" % (serial + 1))
+
+if args.out is None:
+ sys.stdout.write(cert.get_PEM())
+else:
+ with open(args.out, "w") as f:
+ f.write(cert.get_PEM())
>251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398