Commit 0486b553 authored by Gary Wong's avatar Gary Wong

Make credential IDs random, so that it will be very unlikely that two

independently generated credentials will collide.
parent 15152726
......@@ -513,9 +513,11 @@ sub Sign($$)
#
# Create a template xml file to sign.
#
my $id = sprintf( "%08X%08X", int( rand( 0x100000000 ) ),
int( rand( 0x100000000 ) ) );
my $template =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n".
"<credential xml:id=\"ref1\">\n".
"<credential xml:id=\"ref$id\">\n".
" <type>privilege</type>\n".
" <serial>$idx</serial>\n".
" <owner_gid>$owner_cert</owner_gid>\n".
......
......@@ -16,6 +16,7 @@
import datetime
import getopt
import os
import random
import re
import sys
import tempfile
......@@ -200,10 +201,13 @@ old = Lookup( doc.documentElement, "credential" )
c = doc.createElement( "credential" )
id = 1
while filter( lambda x: x.getAttribute( "xml:id" ) == "ref" + str( id ),
doc.getElementsByTagName( "credential" ) ):
id = id + 1
# I really want do loops in Python...
while True:
id = "ref" + '%016X' % random.getrandbits( 64 )
if not filter( lambda x: x.getAttribute( "xml:id" ) == "ref" + str( id ),
doc.getElementsByTagName( "credential" ) ):
break
c.setAttribute( "xml:id", "ref" + str( id ) )
c.appendChild( Lookup( old, "type" ).cloneNode( True ) )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment