[freeside-commits] freeside/FS/FS svc_cert.pm,1.1,1.2
Ivan,,,
ivan at wavetail.420.am
Sat Nov 6 22:30:14 PDT 2010
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv31979/FS/FS
Modified Files:
svc_cert.pm
Log Message:
certificates ala communigate, RT#7515
Index: svc_cert.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_cert.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- svc_cert.pm 7 Nov 2010 00:56:34 -0000 1.1
+++ svc_cert.pm 7 Nov 2010 05:30:11 -0000 1.2
@@ -79,9 +79,9 @@
country
-=item contact
+=item cert_contact
-contact
+contact email
=back
@@ -124,7 +124,7 @@
'city' => { label=>'City', %dis, },
'state' => { label=>'State', %dis, },
'country' => { label=>'Country', %dis, },
- 'cert_contact' => { label=>'Contact', %dis, },
+ 'cert_contact' => { label=>'Contact email', %dis, },
#'another_field' => {
# 'label' => 'Description',
@@ -213,7 +213,7 @@
|| $self->ut_textn('city')
|| $self->ut_textn('state')
|| $self->ut_textn('country') #XXX char(2) or NULL
- || $self->ut_textn('contact')
+ || $self->ut_textn('cert_contact')
;
return $error if $error;
@@ -271,14 +271,23 @@
);
}
-sub generate_csr {
+sub _file {
my $self = shift;
- my $in = $self->privatekey;
+ my $field = shift;
my $dir = $FS::UID::conf_dir. "/cache.". $FS::UID::datasrc; #XXX actual cache dir
my $fh = new File::Temp(
- TEMPLATE => 'certkey.'. '.XXXXXXXX',
+ TEMPLATE => 'cert.'. '.XXXXXXXX',
DIR => $dir,
) or die "can't open temp file: $!\n";
+ print $fh $self->$field;
+ close $fh;
+ $fh;
+}
+
+sub generate_csr {
+ my $self = shift;
+
+ my $fh = $self->_file('privatekey');
run( [qw( openssl req -new -key ), $fh->filename, '-subj', $self->subj ],
'>pipe'=>\*OUT, '2>'=>'/dev/null'
@@ -289,6 +298,59 @@
$self->csr($csr);
}
+#sub check_csr {
+# my $self = shift;
+#}
+
+sub generate_selfsigned {
+ my $self = shift;
+
+ my $days = 730;
+
+ my $key = $self->_file('privatekey');
+ my $csr = $self->_file('csr');
+
+ run( [qw( openssl req -x509 -nodes ),
+ '-days' => $days,
+ '-key' => $key->filename,
+ '-in' => $csr->filename,
+ ],
+ '>pipe'=>\*OUT, '2>'=>'/dev/null'
+ )
+ or die "error running openssl: $!";
+ #XXX error checking
+ my $csr = join('', <OUT>);
+ $self->certificate($csr);
+}
+
+#openssl x509 -in cert -noout -subject -issuer -dates -serial
+#subject= /CN=cn.example.com/ST=AK/O=Tofuy/OU=Soybean dept./C=US/L=Tofutown
+#issuer= /CN=cn.example.com/ST=AK/O=Tofuy/OU=Soybean dept./C=US/L=Tofutown
+#notBefore=Nov 7 05:07:42 2010 GMT
+#notAfter=Nov 6 05:07:42 2012 GMT
+#serial=B1DBF1A799EF207B
+
+sub check_certificate {
+ my $self = shift;
+
+ my $in = $self->certificate;
+ run( [qw( openssl x509 -noout -subject -issuer -dates -serial )],
+ '<'=>\$in,
+ '>pipe'=>\*OUT, '2>'=>'/dev/null'
+ )
+ or die "error running openssl: $!";
+ #XXX error checking
+
+ my %hash = ();
+ while (<OUT>) {
+ warn $_;
+ /^\s*(\w+)=\s*(.*)\s*$/ or next;
+ $hash{$1} = $2;
+ }
+
+ %hash;
+}
+
=back
=head1 BUGS
More information about the freeside-commits
mailing list