Modified credential parsing, adding extensions and signing to support the extensions.

parent 6f270600
......@@ -32,7 +32,7 @@ use Time::Local;
use overload ('""' => 'Stringify');
# Exported variables
use vars qw(@EXPORT_OK $LOCALSA_FLAG $LOCALCM_FLAG $LOCALMA_FLAG);
use vars qw(@EXPORT_OK $LOCALSA_FLAG $LOCALCM_FLAG $LOCALMA_FLAG $EXTENSIONS_NS EXTENSIONS_PREFIX);
# Configure variables
my $TB = "@prefix@";
......@@ -46,6 +46,11 @@ my $VERIFYCRED = "$TB/sbin/verifygenicred";
my $NFREE = "$TB/bin/nfree";
my $OPENSSL = "/usr/bin/openssl";
#Extensions namespace URI.
# TODO: pick the right NS URI, prefix and update here.
$EXTENSIONS_NS = "";
$EXTENSIONS_PREFIX = "";
# Signing flags
$LOCALSA_FLAG = 1;
$LOCALCM_FLAG = 2;
......@@ -123,7 +128,7 @@ sub Create($$$)
$self->{'owner_cert'} = $owner->GetCertificate();
$self->{'string'} = undef;
$self->{'capabilities'} = undef;
$self->{'extensions'} = XML::LibXML::NodeList->new();
$self->{'extensions'} = "<extensions></extensions>";
$self->{'idx'} = undef; # Only set when stored to DB.
bless($self, $class);
......@@ -177,16 +182,18 @@ sub AddCapability($$$)
}
#
# Add an entension. Key/Value pairs
#
sub AddExtension($$$)
# Add an extension. Each extension is an xml element.
# If the element is in a different namespace it has to be specified
# during element construction.
sub AddExtension($$)
{
my ($self, $key, $value) = @_;
my ($self, $elem) = @_;
return -1
if (!ref($self));
my $newNode = XML::LibXML::Element->new($key);
$newNode->appendText($value);
my $root = GeniXML::Parse($self->{'extensions'});
$root->appendChild($elem);
$self->{'extensions'} = GeniXML::Serialize($root);
return 0;
}
......@@ -260,8 +267,11 @@ sub CreateFromSigned($$;$)
my $root = $doc->documentElement();
# Dig out the extensions
my $extensions = GeniXML::FindNodes('//n:extensions/*', $root);
# now extensions is an xml element.
my ($extensions) = GeniXML::FindNodes('//n:extensions',
$root)->get_nodelist;
return undef
if (!defined($extensions));
# UUID of the credential.
my ($uuid_node) = $doc->getElementsByTagName("uuid");
return undef
......@@ -428,13 +438,7 @@ sub Sign($$)
}
$cap_xml .= "</privileges>\n";
if ($self->extensions()->size() > 0) {
$cap_xml .= "<extensions>\n";
foreach my $node ($self->extensions()->get_nodelist()) {
$cap_xml .= GeniXML::Serialize($node);
}
$cap_xml .= "</extensions>\n";
}
$cap_xml .= GeniXML::Serialize($self->{'extensions'});
# Every one gets a new unique index, which is used in the xml:id below.
my $idx = TBGetUniqueIndex('next_ticket', 1);
......
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