signit.pl revision 2210853d176a7da9835ef47df74fd66c3c1a3e55
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# ident "%Z%%M% %I% %E% SMI"
#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# signit [-q] [-i dir][-o dir] [-l user]
#
# Client program for use with code signing server.
# Reads a list of signing credential names and file pathnames
# from standard input. Each file is read from the input directory,
# sent to the signing server, signed with the specified credential,
# and written to the output directory.
#
# Options:
# -q quiet operation: avoid printing files successfully signed
# -i dir input directory (defaults to current dir)
# -o dir output directory (defautls to input dir)
# -l user user account on signing server (defaults to current user)
#
# The CODESIGN_SERVER environment variable can be used to
# specify the hostname or IP address of the signing server
# (defaults to quill.sfbay).
use strict;
use Cwd;
#
# Global variables
#
my $Server; # Signing server hostname
my $Quiet; # Suppress printing each file successfully signed
my ($pid); # Process id for ssh client
my @cred_rules; # Array of path prefixes and credentials to use
#
# Main program
#
# Get command-line arguments
if (!getopts("i:o:c:l:q")) {
die "Usage: $0 [-i dir] [-o dir] [-l user]\n";
}
# Ignore SIGPIPE to allow proper error messages
# Create ssh connection to server
my(@args);
if (defined($opt_l)) {
}
die "ERROR Connection to server $Server failed\n";
# Sign each file with the specified credential
chdir($Indir);
while (<>) {
}
exit($Warnings > 0);
#
# END()
#
# Clean up after normal or abnormal exit.
#
sub END {
my $old_status = $?;
$? = 0;
close(SRV_IN);
close(SRV_OUT);
if ($?) {
print STDERR "ERROR Connection to server $Server failed\n";
$? = 1;
}
$? = $old_status if ($? == 0);
}
#
# debug(msg)
#
# Print debug message to standard error.
#
sub debug {
print STDERR "### @_";
}
#
# check_response(str)
#
# Validate response from server. Print messages for warnings or errors,
# and exit in the case of an error. If the response indicates a successful
# signing operation, return the size of the output data.
#
sub check_response {
my ($str) = @_;
return ($1);
}
return (0);
}
$Warnings++;
return (-1);
}
exit(1);
}
else {
exit(1);
}
}
#
# sign_file(credential, filename)
#
# Send the file to the server for signing. Package the file into a
# ZIP archive, send to the server, and extract the ZIP archive that
# is returned. The input ZIP archive always contains a single file,
# but the returned archive may contain one or more files.
#
sub sign_file {
$path =~ s:^\./::g; # remove leading "./"
if ($size > 0) {
$Warnings++;
} else {
print "$cred\t$path\n" unless $Quiet;
}
}
}
#
# sendfile(file, args)
#
# Send a ZIP archive file to the signing server. This involves
# sending a SIGN command with the given arguments, followed by
# the contents of the archive itself.
#
sub sendfile {
print SRV_IN "SIGN $size $args\n";
if (!open(F, "<$file")) {
print STDERR "$file: $!\n";
return (0);
}
close(F);
print STDERR "Can't send to server: $!\n";
return (0);
}
return (1);
}
#
# recvfile(file, size)
#
# Receive a ZIP archive from the signing server. The caller
# provides the size argument previously obtained from the
# server response.
#
sub recvfile {
my $bytes;
print STDERR "Can't read from server: $!\n";
return (0);
}
if (!open(F, ">$file")) {
print STDERR "$file: $!\n";
return (0);
}
close(F);
return (1);
}