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