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

Chore/gradle update #33

Merged
merged 23 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
21edd41
feat: enable auto update build config vs code
bobhageman Aug 23, 2023
7a42379
refactor: update gradle and dependencies, merge irma_server_common in…
bobhageman Aug 24, 2023
ba8ce45
chore: remove unused class
bobhageman Aug 28, 2023
5917342
improve: return 500 when sending mail fails
bobhageman Aug 28, 2023
353e484
feat: dockerize app for easier development
bobhageman Aug 29, 2023
f218521
fix: corrupt multipart mailbody
bobhageman Aug 29, 2023
98254a2
security: prevent log injection and long overflow
bobhageman Aug 29, 2023
df01067
fix: convert boxed variable to primitive
bobhageman Aug 29, 2023
ef5f718
security: uncontrolled data used in path expression
bobhageman Aug 29, 2023
b850186
fix: typo
bobhageman Aug 29, 2023
9d705a3
improve: remove superfluous default command
bobhageman Aug 29, 2023
5c8e2d6
improve: use ip address as env var, prevent naming clash
bobhageman Aug 30, 2023
590f20e
improve: update documentation and fix typo's
bobhageman Aug 30, 2023
5e0ca44
fix: allow web.xml
bobhageman Aug 30, 2023
59e0a39
chore: revive custom clients functionality
bobhageman Aug 31, 2023
171298a
feat: implement ratelimiting
bobhageman Aug 31, 2023
1161e6f
feat: show ratelimiting errors in ui
bobhageman Aug 31, 2023
bf65c51
improve: remove ip ratelimiting, set limits more tolerable
bobhageman Sep 6, 2023
9b30f65
chore: remove unused parameter
bobhageman Sep 6, 2023
f5933b0
update to 7.6.2 released june 2023
sanderhollaar Sep 6, 2023
65c38d1
s/email/e-mail/
sanderhollaar Sep 6, 2023
1a0ca47
s/email/e-mail/
sanderhollaar Sep 6, 2023
958a946
Merge pull request #34 from privacybydesign/security/ratelimiting
bobhageman Sep 6, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ webapp/build
.settings/
bin/
artifacts/
.DS_Store

!src/main/webapp/WEB-INF
src/main/webapp/*
Expand Down
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"java.compile.nullAnalysis.mode": "automatic",
"java.configuration.updateBuildConfiguration": "automatic"
}
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

FROM yarnpkg/node-yarn:latest as webappbuild

ARG LANGUAGE=en

# Build the webapp
COPY ./webapp/ /webapp/
WORKDIR /webapp
RUN yarn install && ./build.sh ${LANGUAGE}

FROM gradle:7.6-jdk11 as javabuild

# Build the java app
COPY ./ /app/
WORKDIR /app
RUN gradle build

FROM tomee:9.0-jre11

# Copy the webapp to the webapps directory
COPY --from=webappbuild /webapp/build/ /usr/local/tomee/webapps/ROOT/

# Copy the war file to the webapps directory
COPY --from=javabuild /app/build/libs/irma_email_issuer-1.1.0.war /usr/local/tomee/webapps/

EXPOSE 8080

CMD ["catalina.sh", "run"]
64 changes: 58 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,68 @@

# Email server
# irma_email_issuer

Add an email address for use in your [Yivi app](https://github.com/privacybydesign/irma_mobile).
ivard marked this conversation as resolved.
Show resolved Hide resolved

## Running (development)
The easiest way to run the irma_email_issuer for development purposes is via Docker.

## Setting up the server
### Configuration
Various configuration files, keys and settings need to be in place to be able to build and run the apps.

1. To generate the required keys for the issuer, run:
```bash
$ utils/keygen.sh ./src/main/resources/sk ./src/main/resources/pk
```

2. Create the Java app configuration:
Copy the file `src/main/resources/config.sample.json` to `src/main/resources/main/config.json`.

4. Update docker-compose.yml with your local IP address:
Set the `- "--url=http://ip-address:8088"` parameter inside `docker-compose.yml` to match the IP address of your development machine. For example:
```yml
entrypoint:
- "--url=http://192.168.1.105:8088"
```
Note: do not use `127.0.0.1` or `0.0.0.0` as IP addresses as this will result in the app not being able to find the issuer.

### Run
Use docker-compose to spin up the containers:
```bash
$ docker-compose up
```

By default, docker-compose caches docker images, so on a second run the previous built images will be used. A fresh build can be enforced using the --build flag.
```bash
$ docker-compose up --build
```

## Manual

Using this construction you need to run the irma server and

1. Generate JWT keys for the issuer
```bash
./utils/keygen.sh ./src/main/resources/sk ./src/main/resources/pk
$ utils/keygen.sh ./src/main/resources/sk ./src/main/resources/pk
```

2. Copy the file `src/main/resources/config.sample.json` to
`build/resources/main/config.json` and modify it.
3. Run `gradle appRun` in the root directory of this project.
4. Navigate to `http://localhost:8080/irma_email_issuer/api/hello`
`src/main/resources/main/config.json` and modify it.
todo: voorbeeld

3. Build the webapp
```bash
$ cd webapp && yarn install && yarn build en && cd ../
```
If you want to build another language, for example Dutch, change `build en` to `build nl`.

4. Copy the file `webapp/config.example.js` to `webapp/build/assets/config.js` and modify it

5. Run `gradle appRun` in the root directory of this project.

To open the webapp navigate to `http://localhost:8080`. The API is accessible via `http://localhost:8080/irma_email_issuer/api`

## Test
You can run the tests, defined in `src/test/java/foundation/privacybydesign/email`, using the following command:
```bash
$ gradle test
```
36 changes: 21 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ group 'foundation.privacybydesign.email'
version '1.1.0'

apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty'
apply plugin: 'org.gretty'

sourceCompatibility = 1.7
sourceCompatibility = 11

buildscript {
repositories {
Expand All @@ -13,32 +13,38 @@ buildscript {
}
}
dependencies {
classpath "gradle.plugin.org.akhikhl.gretty:gretty:1.4.2"
classpath "org.gretty:gretty:4.0.3"
}
}

repositories {
mavenLocal()
maven {
url "https://credentials.github.io/repos/maven2/"
}
mavenCentral()
}

dependencies {
compile 'org.glassfish.jersey.core:jersey-server:2.25'
compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.25'
compile 'ch.qos.logback:logback-classic:1.1.7'
compile 'com.sun.mail:javax.mail:1.5.6'

compile 'org.irmacard.api:irma_api_common:1.2.2'
compile 'foundation.privacybydesign.common:irma_server_common:0.3.2'

testCompile group: 'junit', name: 'junit', version: '4.12'
implementation 'org.glassfish.jersey.core:jersey-server:3.0.0'
implementation 'org.glassfish.jersey.containers:jersey-container-servlet:3.0.0'
implementation 'org.glassfish.jersey.inject:jersey-hk2:3.0.0'
implementation 'ch.qos.logback:logback-classic:1.1.7'
implementation 'com.sun.mail:jakarta.mail:2.0.1'
implementation 'jakarta.ws.rs:jakarta.ws.rs-api:3.1.0'

implementation 'io.jsonwebtoken:jjwt:0.9.1'
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'org.apache.commons:commons-lang3:3.7'
implementation 'org.bouncycastle:bcpkix-jdk15on:1.70'
implementation 'org.bouncycastle:bcprov-jdk15on:1.67'
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:3.0.1'

implementation 'org.irmacard.api:irma_api_common:2.0.0'

testImplementation group: 'junit', name: 'junit', version: '4.13.1'
}

gretty {
contextConfigFile = file('src/main/resources/jetty-env.xml')
scanInterval = 10
inplaceMode = "hard"
extraResourceBase 'webapp/build'
}
63 changes: 63 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
version: "3.8"
name: irma_email_issuer

services:
# Irma issuer service
irmaserver:
image: ghcr.io/privacybydesign/irma:v0.13.2
container_name: irma_server
ivard marked this conversation as resolved.
Show resolved Hide resolved
working_dir: /irmago
ports:
- 8088:8088
expose:
- 8088
networks:
- irma-net
entrypoint:
- "irma"
- "server"
- "--no-auth=false"
- "--requestors={\"irma_email_issuer\":{\"auth_method\":\"publickey\",\"key_file\": \"/config/pk.pem\"} }"
- "--port=8088"
- "--jwt-privkey-file=/config/sk.pem"
- "--url=http://ip-address:8088" # Your localhost IP-address here. This is required for the app to be able to connect to the issuer
ivard marked this conversation as resolved.
Show resolved Hide resolved
volumes:
- ./src/main/resources/:/config/

# Mailhog service
mailhog:
image: mailhog/mailhog
networks:
# We use a localhost alias such that the test configuration also works for users who run it without Docker.
irma-net:
aliases:
- mailhog.localhost
ports:
- 1025:1025
- 8025:8025 # Port of the web interface

# Service that runs the SMS issuer webapp and api
irma_email_issuer:
platform: linux/x86_64
build:
context: .
dockerfile: Dockerfile
container_name: irma_email_issuer
volumes:
# Make keys and config files available for Java app
- ./src/resources/main/:/config/
# Make config.js available for webapp
- ./webapp/config.example.js:/usr/local/tomee/webapps/ROOT/assets/config.js:ro"
ports:
- 8080:8080
expose:
- 8080
networks:
- irma-net

# Docker Desktop for MacOS does not support exposing ports when using host networking. Therefore,
# we have to use bridge networking and expose the ports manually.
# https://github.com/docker/for-mac/issues/1031
networks:
irma-net:
driver: bridge
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 0 additions & 2 deletions src/main/java/foundation/privacybydesign/email/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.HashMap;

public class Client {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package foundation.privacybydesign.email;

import foundation.privacybydesign.common.BaseConfiguration;
import foundation.privacybydesign.email.common.BaseConfiguration;
import io.jsonwebtoken.SignatureAlgorithm;
import org.irmacard.api.common.util.GsonUtil;
import org.slf4j.Logger;
Expand All @@ -12,7 +12,7 @@
import java.util.HashMap;
import java.util.Map;

public class EmailConfiguration extends BaseConfiguration {
public class EmailConfiguration extends BaseConfiguration<EmailConfiguration> {
private static Logger logger = LoggerFactory.getLogger(Client.class);

static EmailConfiguration instance;
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/foundation/privacybydesign/email/EmailProvider.java

This file was deleted.

17 changes: 10 additions & 7 deletions src/main/java/foundation/privacybydesign/email/EmailRestApi.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package foundation.privacybydesign.email;

import foundation.privacybydesign.common.email.EmailTokens;
import foundation.privacybydesign.common.filters.RateLimit;
import org.irmacard.api.common.ApiClient;
import org.irmacard.api.common.CredentialRequest;
import org.irmacard.api.common.issuing.IdentityProviderRequest;
Expand All @@ -10,10 +8,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.mail.internet.AddressException;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import jakarta.mail.internet.AddressException;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -79,6 +77,9 @@ public Response sendEmail(@FormParam("email") String email,
} catch (UnsupportedEncodingException e) {
logger.error("Invalid return URL: {}: {}", client.getReturnURL(), e.getMessage());
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (Exception e) {
logger.error("Sending mail failed:\n{}", e.getMessage());
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
return Response.status(Response.Status.OK).entity(OK_RESPONSE).build();
}
Expand All @@ -93,7 +94,6 @@ public Response sendEmail(@FormParam("email") String email,
@POST
@Path("/send-email-token")
@Produces(MediaType.TEXT_PLAIN)
@RateLimit
public Response sendEmailToken(@FormParam("email") String emailAddress,
@FormParam("language") String language) {
EmailConfiguration conf = EmailConfiguration.getInstance();
Expand Down Expand Up @@ -128,6 +128,9 @@ public Response sendEmailToken(@FormParam("email") String emailAddress,
logger.error("Invalid address: {}", e.getMessage());
return Response.status(Response.Status.BAD_REQUEST).entity
(ERR_ADDRESS_MALFORMED).build();
} catch (Exception e) {
logger.error("Sending mail failed:\n{}", e.getMessage());
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
return Response.status(Response.Status.OK).entity
(OK_RESPONSE).build();
Expand Down
Loading
Loading