Lemonldap-NG-Manager

 view release on metacpan or  search on metacpan

lib/Lemonldap/NG/Manager/Conf.pm  view on Meta::CPAN

        400 )
      if (@others);
    my $query = $req->jsonBodyToObj;

    my $keys = $self->_generateX509( $query->{password}, "RSA" );
    return $self->sendJSONresponse( $req, $keys );
}

sub newEcCertificate {
    my ( $self, $req, @others ) = @_;
    return $self->sendError( $req, 'There is no subkey for "newEcCertificate"',
        400 )
      if (@others);
    my $query = $req->jsonBodyToObj;

    my $keys = $self->_generateX509( $query->{password}, "EC" );
    return $self->sendJSONresponse( $req, $keys );
}

# 35 - New RSA key pair on demand
#      --------------------------

##@method public PSGI-JSON-response newRSAKey($req)
# Return a hashref containing private and public keys
# The posted data must contain a JSON object containing
# {"password":"newpassword"}
#
#@param $req Lemonldap::NG::Common::PSGI::Request object
#@return PSGI JSON response
sub newRSAKey {
    my ( $self, $req, @others ) = @_;
    return $self->sendError( $req, 'There is no subkey for "newRSAKey"', 400 )
      if (@others);

    my $key_size = $self->defaultNewKeySize;
    my $query    = $req->jsonBodyToObj;
    my $password = $query->{password};

    my $keys =
      Lemonldap::NG::Common::Util::Crypto::genRsaKey( $key_size, $password );

    return $self->sendJSONresponse( $req, $keys );
}

# 35 - New EC key pair on demand
#      --------------------------

##@method public PSGI-JSON-response newEcKeys($req)
# Return a hashref containing private and public keys
#
#@param $req Lemonldap::NG::Common::PSGI::Request object
#@return PSGI JSON response
sub newEcKeys {
    my ( $self, $req, @others ) = @_;

    my $keys = Lemonldap::NG::Common::Util::Crypto::genEcKey('prime256v1');
    return $self->sendJSONresponse( $req, $keys );
}

# This function does the dirty X509 work,
# mostly copied from IO::Socket::SSL::Utils
# and adapter to work on old platforms (CentOS7)

sub _generateX509 {
    my ( $self, $password, $type ) = @_;
    my $conf        = $self->confAcc->getConf();
    my $portal_uri  = new URI::URL( $conf->{portal} || "http://localhost" );
    my $portal_host = $portal_uri->host;

    if ($type eq "EC") {
    my $curve    = $self->defaultCurve;
    return Lemonldap::NG::Common::Util::Crypto::genEcCertKey( $curve,
        $password, $portal_host );
    } else {
    my $key_size    = $self->defaultNewKeySize;
    return Lemonldap::NG::Common::Util::Crypto::genCertKey( $key_size,
        $password, $portal_host );
    }
}

#      Sending a test Email
#      --------------------

##@method public PSGI-JSON-response sendTestMail($req)
# Sends a test email to the provided address
# The posted data must contain a JSON object containing
# {"dest":"target@example.com"}
#
#@param $req Lemonldap::NG::Common::PSGI::Request object
#@return PSGI JSON response
sub sendTestMail {
    my ( $self, $req, @others ) = @_;
    return $self->sendError( $req, 'There is no subkey for "sendTestMail"',
        400 )
      if (@others);
    my $dest = $req->jsonBodyToObj->{dest};
    unless ($dest) {
        $self->logger->debug("Missing dest parameter for sending test mail");
        return $self->sendJSONresponse(
            $req,
            {
                success => \0,
                error   => "You must provide an email address"
            }
        );
    }
    my $conf = $self->confAcc->getConf();

    # Try to send test Email
    $self->logger->info("Sending test email to $dest");
    eval {
        Lemonldap::NG::Common::EmailTransport::sendTestMail( $conf, $dest );
    };
    my $error   = $@;
    my $success = ( $error ? 0 : 1 );

    $self->logger->debug("Email was sent") unless $error;
    return $self->sendJSONresponse(
        $req,
        {
            success => \$success,



( run in 1.738 second using v1.01-cache-2.11-cpan-39bf76dae61 )