Protocol-ACME

 view release on metacpan or  search on metacpan

lib/Protocol/ACME.pm  view on Meta::CPAN

      _throw( "account_key file $key does not exist" );
    }
  }
  elsif( ref $key eq "SCALAR" )
  {
    $args{buffer} = $$key;
  }
  else
  {
    @args{ keys %$key } = values %$key;
  }

  if ( $args{filename} )
  {
    $args{buffer} = _slurp( $args{filename} );
    if ( ! $args{buffer} )
    {
      _throw( "Could not load the account key from file $args{filename}: $!" );
    }
  }

  if ( ! $args{buffer} )
  {
    _throw( "Either an account key buffer or filename must be passed into account_key" );
  }

  if ( ! $args{format} )
  {
    $args{format} = Protocol::ACME::Utils::looks_like_pem( $args{buffer} ) ? "PEM" : "DER";
  }

  my $keystring = $args{buffer};
  # TODO: This should detect/handle PKCS8-formatted private keys as well.
  if ( $args{format} eq "DER" )
  {
    $keystring = Crypt::Format::der2pem( $keystring, "RSA PRIVATE KEY" );
  }

  if ( exists $self->{openssl} )
  {
    require Protocol::ACME::Key;
    $key = Protocol::ACME::Key->new( keystring => $keystring,
                                     openssl   => $self->{openssl} );
  }
  else
  {
    eval
    {
      require Crypt::OpenSSL::RSA;
      require Crypt::OpenSSL::Bignum;
    };
    if ( $@ )
    {
      die "Invoked usage requires Crypt::OpenSSL::RSA and Crypt::OpenSSL::Bignum. " .
      "To avoid these dependencies use the openssl parameter when creating the " .
      "Protocol::ACME object.  This will use a native openssl binary instead.";
    }

    eval
    {
      $key = Crypt::OpenSSL::RSA->new_private_key($keystring);
    };
    if ( $@ )
    {
      _throw( "Error creating a key structure from the account key" );
    }
  }

  if ( ! $key )
  {
    _throw( "Could not load account key into key structure" );
  }

  $key->use_sha256_hash();

  $self->{key}->{key} = $key;

  my ( $n_b64, $e_b64 ) = map { encode_base64url(_bigint_to_binary($_)) } $key->get_key_parameters();
  $self->{key}->{n} = $n_b64;
  $self->{key}->{e} = $e_b64;

  $self->{log}->debug( "Private key loaded" );

}




sub directory
{
  my $self = shift;

  my $resp = $self->_request_get( $self->{links}->{directory} );



  if ( $resp->{status} != 200 )
  {
    _throw( detail => "Failed to fetch the directory for $self->{host}", resp => $resp );
  }

  my $data = _decode_json( $resp->{content} );

  if ( ! $self->{version} )
  {
    if ( exists $data->{'new-reg'} )
    {
      $self->{version} = 1;
    }
    elsif ( exists $data->{newNonce} )
    {
      $self->{version} = 2;
    }
    else
    {
      _throw( detail => "Unable to determine the ACME endpoint version" );
    }
  }

  if ( $self->{version} == 1 )
  {

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.711 second using v1.00-cache-2.02-grep-82fe00e-cpan-2cc899e4a130 )