Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First version of test server with implementation of code-based activation #44

Merged
merged 6 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions powerauth-test-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# PowerAuth Test Server

PowerAuth TestServer is deployed to simplify testing of PowerAuth backends. The REST API encapsulates PowerAuth actions which require cryptography with an embedded `powerauth-java-cmd-lib` library.

## Test Server Configuration

Test server runs by default with embedded H2 database. The database structure is created automatically on application startup.

Once the database is created, you can connect to it using following URL:

```properties
spring.datasource.url=jdbc:h2:file:~/powerauth-test;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE
```

The test server configuration is performed using following query:

```sql
insert into PA_TEST_CONFIG (APPLICATION_ID, APPLICATION_NAME, APPLICATION_KEY, APPLICATION_SECRET, MASTER_PUBLIC_KEY)
values (1, 'test-app', '66arXznJzaEs1k4cNfyWzA==', 'CNtWEvyDyJupKL9n07y+aA==', 'BLWJ8cTWx/LxU8dTC7CiNbWKXExRSG/yMKmR3Iw5ZhlPpMQ9qTvBWhY0DnkFr++53JPEwfJaW6zEdIEdq34z59E=');
```

The `APPLICATION_ID` value should correspond to the PowerAuth application identifier of the application used for testing.
You can obtain all the other values from PowerAuth Admin application.

## Create Activation

The activation needs to be at first initialized using one of the possible ways:
- creating the activation in PowerAuth Admin in the `Activations` tab
- calling the PowerAuth server POST `/rest/v3/activation/init` endpoint
- calling the PowerAuth cloud POST `/registration` or POST `/v2/registrations` endpoint

Once the activation is initialized, you can create the activation using following REST API call.

```shell
curl --request POST \
--url http://localhost:8080/powerauth-test-server/activation/create \
--header 'Content-Type: application/json' \
--data '{
"requestObject": {
"applicationId": "1",
"activationName": "test-activation",
"password": "1234",
"activationCode": "3A33O-3XMFZ-ORDKE-XJOYQ"
}
}'
```

The following request parameters are used:

| Parameter | Note |
|---|---|
| `applicationId` | PowerAuth application identifier |
| `activationName` | PowerAuth application name |
| `password` | PIN code for future signature verifications (knowledge factor) |
| `activationCode` | Activation code, created using the previous initialization request |

The response contains the `activationId` parameter which is the activation identifier:

```json
{
"status": "OK",
"responseObject": {
"activationId": "5df48d17-e477-467b-8b93-2d6a0185b642"
}
}
```

In order for the activation to become `ACTIVE`, the activation needs to be committed, unless auto-commit mode is enabled using one of the possible ways:
- committing the activation in PowerAuth Admin in the `Activations` tab
- calling the PowerAuth server POST `/rest/v3/activation/commit` endpoint
- calling the PowerAuth cloud POST `/registration` or POST `/v2/registrations` endpoint

# License

PowerAuth Test Server is licensed using GNU AGPLv3 license. Please consult us at [email protected] for the software use.
22 changes: 22 additions & 0 deletions powerauth-test-server/docs/sql/postgresql/create-schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CREATE TABLE pa_test_config
(
application_id INTEGER NOT NULL PRIMARY KEY, -- Application identifier
application_name VARCHAR(255) NOT NULL, -- Application name
application_key VARCHAR(255) NOT NULL, -- Application key
application_secret VARCHAR(255) NOT NULL, -- Application secret
master_public_key VARCHAR(255) NOT NULL -- Master public key in Base64 format
);

CREATE TABLE pa_test_status
(
activation_id VARCHAR(255) NOT NULL PRIMARY KEY, -- Activation identifier
server_public_key VARCHAR(255) NOT NULL, -- Server public key in Base64 format
counter INTEGER NOT NULL, -- Numeric counter
ctr_data VARCHAR(255) NOT NULL, -- Hashed counter data
encrypted_device_private_key VARCHAR(255) NOT NULL, -- Encrypted device private key in Base64 format
signature_biometry_key VARCHAR(255) NOT NULL, -- Signature biometry key in Base64 format
signature_knowledge_key_encrypted VARCHAR(255) NOT NULL, -- Encrypted signature knowledge key in Base64 format
signature_knowledge_key_salt VARCHAR(255) NOT NULL, -- Signature knowledge key in Base64 format
signature_possession_key VARCHAR(255) NOT NULL, -- Signature possession key in Base64 format
transport_master_key VARCHAR(255) NOT NULL -- Transport master key in Base64 format
);
163 changes: 163 additions & 0 deletions powerauth-test-server/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ PowerAuth Test Server
~ Copyright (C) 2022 Wultra s.r.o.
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Affero General Public License as published
~ by the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU Affero General Public License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>powerauth-test-server</artifactId>
<groupId>io.getlime.security</groupId>
<version>1.3.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>powerauth-test-server</name>
<description>Test server which exposes REST API for easier testing of PowerAuth backends</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<inceptionYear>2022</inceptionYear>
<url>http://powerauth.com/</url>

<organization>
<name>Wultra s.r.o.</name>
<url>http://wultra.com</url>
</organization>

<licenses>
<license>
<name>GNU Affero General Public License v3.0</name>
<url>https://www.gnu.org/licenses/agpl-3.0.en.html</url>
</license>
</licenses>

<developers>
<developer>
<name>Roman Strobl</name>
<email>[email protected]</email>
<roles>
<role>developer</role>
</roles>
</developer>
</developers>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven-war-plugin.version>3.3.1</maven-war-plugin.version>
</properties>

<dependencies>
<!-- Spring Dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<artifactId>log4j-to-slf4j</artifactId>
<groupId>org.apache.logging.log4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<!-- Set scope of tomcat-embed-websocket to provided to avoid startup errors on WildFly -->
<dependency>
<artifactId>tomcat-embed-websocket</artifactId>
<groupId>org.apache.tomcat.embed</groupId>
<scope>provided</scope>
</dependency>
<!-- Version 1.4.200 is used intentionally for compatibility with Data Grip -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
</dependency>

<!-- PowerAuth Dependencies -->
<dependency>
<groupId>io.getlime.security</groupId>
<artifactId>powerauth-java-cmd-lib</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>io.getlime.security</groupId>
<artifactId>powerauth-java-crypto</artifactId>
<version>1.2.0</version>
</dependency>

<!-- Other Dependencies -->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.13.2</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.70</version>
</dependency>

<!-- Documentation -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.6</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>build-info</id>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2022 Wultra s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.wultra.security.powerauth.app.testserver;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

import java.security.Security;

/**
* Spring Boot servlet initializer.
*
* @author Roman Strobl, [email protected]
*/
public class ServletInitializer extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
// Register BC provider
Security.addProvider(new BouncyCastleProvider());

return application.sources(TestServerApplication.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2022 Wultra s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.wultra.security.powerauth.app.testserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* Spring Boot application main class.
*
* @author Roman Strobl, [email protected]
*/
@SpringBootApplication
public class TestServerApplication {

public static void main(String[] args) {
SpringApplication.run(TestServerApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* PowerAuth test and related software components
* Copyright (C) 2022 Wultra s.r.o.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.wultra.security.powerauth.app.testserver.config;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
* Test server configuration.
*
* @author Roman Strobl, [email protected]
*/
@Configuration
@Data
@ComponentScan(basePackages = {"com.wultra.security", "io.getlime.security"})
public class TestServerConfiguration {

@Value("${powerauth.enrollment.service.url:http://localhost:8080/enrollment-server}")
private String enrollmentServiceUrl;

@Value("${powerauth.version}")
private String version;

}
Loading