| 1 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package Tiny::OpenSSL::Certificate; | ||||||||||
| 5 | |||||||||||
| 6 | # ABSTRACT: X509 Certificate Object. | ||||||||||
| 7 | 2 | our $VERSION = '0.1.2'; # VERSION | |||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use Types::Standard qw( InstanceOf ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 2 | ▶ | use Tiny::OpenSSL::Config qw($CONFIG); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 2 | ▶ | use Capture::Tiny qw( :all ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 2 | with 'Tiny::OpenSSL::Role::Entity'; | |||||||||
| 16 | |||||||||||
| 17 | 2 | has [qw(issuer subject)] => | |||||||||
| 18 | ( is => 'rw', isa => InstanceOf ['Tiny::OpenSSL::Subject'] ); | ||||||||||
| 19 | |||||||||||
| 20 | 2 | has key => ( is => 'rw', isa => InstanceOf ['Tiny::OpenSSL::Key'] ); | |||||||||
| 21 | |||||||||||
| 22 | sub self_sign { | ||||||||||
| 23 | |||||||||||
| 24 | 2 | ▶ | my $self = shift; | ||||||||
|
Subroutine
self_sign: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||
| 25 | 2 | my $csr = shift; | |||||||||
| 26 | |||||||||||
| 27 | 2 | ▶ | if ( !defined $csr ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 0 | croak 'csr is not defined'; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | my @args = ( | ||||||||||
| 32 | 'x509', '-req', '-days', $CONFIG->{ca}{days}, | ||||||||||
| 33 | 2 | '-in', $csr->file, '-signkey', $self->key->file, | |||||||||
| 34 | '-out', $self->file | ||||||||||
| 35 | ); | ||||||||||
| 36 | |||||||||||
| 37 | 2 | my $pass_file; | |||||||||
| 38 | |||||||||||
| 39 | 2 | ▶ | if ( $csr->key->password ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | |||||||||||
| 41 | 2 | $pass_file = Path::Tiny->tempfile; | |||||||||
| 42 | 2 | $pass_file->spew( $self->key->password ); | |||||||||
| 43 | |||||||||||
| 44 | 2 | push( @args, '-passin', sprintf( 'file:%s', $pass_file ) ); | |||||||||
| 45 | |||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | my ( $stdout, $stderr, $exit ) = capture { | ||||||||||
| 49 | 2 | ▶ | system( $CONFIG->{openssl}, @args ); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 50 | 2 | }; | |||||||||
| 51 | |||||||||||
| 52 | 2 | ▶ | if ( $exit != 0 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 0 | croak( sprintf( 'cannot sign certificate: %s', $stderr ) ); | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 2 | $self->issuer( $self->subject ); | |||||||||
| 57 | 2 | $self->ascii( $self->file->slurp ); | |||||||||
| 58 | |||||||||||
| 59 | 2 | return 1; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 2 | 1; | |||||||||
| 63 | |||||||||||
| 64 | __END__ | ||||||||||