Skip to content

Commit

Permalink
Add tools for folding Base64-encoded embedded certificates so that th…
Browse files Browse the repository at this point in the history
…ey meet the MIME requirement of 64 characters per line.
  • Loading branch information
iay committed Jun 13, 2008
1 parent 1ff9200 commit bad2299
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
25 changes: 25 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
<property name="xalan.dir" value="xalan-j_2_6_0"/>
<property name="xml.dir" value="xml"/>

<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${lib.dir}/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>

<!--
The entities file contains the individual entity fragment files
concatenated together and enclosed in an <Entities> element.
Expand Down Expand Up @@ -401,6 +407,25 @@
x="extract_member_dates.xsl"/>
</target>

<!--
Utility to fold overlong embedded certificates.
-->
<target name="fold.embedded.certs">
<echo>Folding embedded certificates</echo>
<for param="file">
<path>
<fileset dir="${entities.dir}" includes="uk*.xml"/>
</path>
<sequential>
<exec executable="perl" dir="${entities.dir}">
<arg value="-i"/>
<arg value="${build.dir}/fold_cert.pl"/>
<arg value="@{file}"/>
</exec>
</sequential>
</for>
</target>

<!--
Extract embedded certificates
-->
Expand Down
32 changes: 32 additions & 0 deletions build/fold_cert.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/perl -w

#
# The input file is a fragment file that may or may not have one
# or more unfolded X.509 embedded certificates in it. Fold these
# to a max of 64 characters per Base64 line, but preserve
# XML indentation.
#

$max = 64; # max chars per line

while (<>) {
if (/^(\s*)\<ds:X509Certificate\>(.*)\<\/ds:X509Certificate\>\s*$/) {
$sp = $1;
$spp = "$1 "; # add four spaces
$cert = $2;
print "$sp<ds:X509Certificate>\n";
while (length($cert) != 0) {
$line = $cert;
if (length($line) > $max) {
$line = substr($line, 0, $max)
}
print "$spp$line\n";
substr($cert, 0, length($line)) = '';
}
print "$sp</ds:X509Certificate>\n";
} else {
print $_;
}
}

# end

0 comments on commit bad2299

Please sign in to comment.