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

changes to have the email form in the docker image #52

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ COPY --from=webappbuild /www/ /usr/local/tomee/webapps/ROOT/

# Copy the war file to the webapps directory
COPY --from=javabuild /app/build/libs/irma_email_issuer.war /usr/local/tomee/webapps/
COPY ./src/main/resources/email-en.html /email-templates/email-en.html
COPY ./src/main/resources/email-nl.html /email-templates/email-nl.html


RUN mkdir /usr/local/keys

ENV IRMA_CONF="/config/"
ENV EMAIL_TEMPLATE_DIR="/email-templates/"
EXPOSE 8080

# Copy the config file to the webapp. This is done at runtime so that the config file can be mounted as a volume.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,26 @@
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;
import java.util.HashMap;
import java.nio.file.Path;

public class BaseConfiguration<T> {
// Override these in a static {} block
public static Class<? extends BaseConfiguration<?>> clazz;
public static Logger logger = LoggerFactory.getLogger(BaseConfiguration.class);
public static String configFileName = "config.json";
public static String filename = "config.json";
public static String environmentVarPrefix = "IRMA_CONF_";
public static String confDirEnvironmentVarName = "IRMA_CONF";
public static String emailTemplateDirVarName = "EMAIL_TEMPLATE_DIR";
public static String emailTemplateDir;
public static String confDirName;
public static String templatefDirName;
public static boolean printOnLoad = false;
public static boolean testing = false;

// Return this from a static getInstance()
public static BaseConfiguration<?> instance;
private static URI confPath;
private static URI templatePath;


public static void load() {
try {
String json = new String(getResource(configFileName));
String json = new String(getResource(filename));
instance = GsonUtil.getGson().fromJson(json, clazz);
logger.info("Using configuration directory: " + BaseConfiguration.getConfigurationDirectory().toString());
} catch (IOException|JsonSyntaxException e) {
Expand Down Expand Up @@ -73,32 +68,6 @@ public static byte[] getResource(String filename) throws IOException {
return convertStreamToByteArray(getResourceStream(filename), 2048);
}

public static FileInputStream getEmailTemplateStream(String filename) throws IOException {
validateFilename(filename);
Path resolvedPath = resolvePath(getTemplateDirectory(), filename);
logger.info("trying to load: " + resolvedPath.toString());
return new FileInputStream(resolvedPath.toFile());
}

private static void validateFilename(String filename) {
if (filename == null || filename.isEmpty() || filename.contains("..")) {
throw new IllegalArgumentException("Invalid filename: " + filename);
}
// Optional: Add further filename validation, such as allowed extensions
}

private static Path resolvePath(URI baseDirectory, String filename) {
Path resolvedPath = new File(baseDirectory).toPath().resolve(filename).normalize();
if (!resolvedPath.startsWith(new File(baseDirectory).toPath())) {
throw new SecurityException("Path traversal attempt detected for file: " + filename);
}
return resolvedPath;
}

public static byte[] getEmailTemplate(String filename) throws IOException {
return convertStreamToByteArray(getEmailTemplateStream(filename), 2048);
}

public static byte[] convertStreamToByteArray(InputStream stream, int size) throws IOException {
byte[] buffer = new byte[size];
ByteArrayOutputStream os = new ByteArrayOutputStream();
Expand Down Expand Up @@ -242,45 +211,12 @@ public static URI getEnvironmentVariableConfDir() throws URISyntaxException {
return pathToURI(envDir, true);
}

public static URI getEnvironmentVariableTemplateDir() throws URISyntaxException {
String envDir = System.getenv(emailTemplateDirVarName);
if (envDir == null || envDir.length() == 0)
return null;
return pathToURI(envDir, true);
}

public static URI getTemplateDirectory() throws IllegalStateException, IllegalArgumentException {
if (templatePath != null)
return templatePath;
try {
URI envCandidate = getEnvironmentVariableTemplateDir();
if (envCandidate != null) {
if (isEmailTemplateDirectory(envCandidate)) {
logger.info("Taking template directory specified by environment variable " + emailTemplateDirVarName);
templatePath = envCandidate;
return templatePath;
} else {
// If the user specified an incorrect path (s)he will want to know, so bail out here
throw new IllegalArgumentException("Specified path in " + emailTemplateDirVarName
+ " is not a valid configuration directory");
}
}
throw new IllegalStateException("No valid template directory found");
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
}

/**
* Returns true if the specified path is a valid configuration directory. A directory
* is considered a valid configuration directory if it contains a file called $filename.
*/
public static boolean isConfDirectory(URI candidate) {
return candidate != null && new File(candidate.resolve(configFileName)).isFile();
}

public static boolean isEmailTemplateDirectory(URI candidate) {
return candidate != null && new File(candidate.resolve("email-en.html")).isFile();
return candidate != null && new File(candidate.resolve(filename)).isFile();
}

/**
Expand All @@ -292,7 +228,7 @@ public static URI GetJavaResourcesDirectory() throws URISyntaxException {
// seems to be to ask for an existing file or directory within the resources. That is,
// BaseConfiguration.class.getClassLoader().getResource("/") or variants thereof
// give an incorrect path.
String testfile = BaseConfiguration.testing ? "config.test.json" : configFileName;
String testfile = BaseConfiguration.testing ? "config.test.json" : filename;
URL url = BaseConfiguration.class.getClassLoader().getResource(testfile);
if (url != null) // Construct an URI of the parent path
return pathToURI(new File(url.getPath()).getParent(), true);
Expand Down
97 changes: 97 additions & 0 deletions src/main/resources/assets/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
body {
margin: 0;
padding: 0;
min-height: 100%;
width: 100%;
}
.email-body {
background-color: #ffffff;
color: #b9113d;
font-family: Optima, Candara, "Noto Sans", source-sans-pro, sans-serif;
font-size: 16px;
font-weight: 400;
letter-spacing: 0.15008px;
line-height: 1.5;
padding: 32px 0;
}
.email-table {
margin: 0 auto;
max-width: 600px;
background-color: #ffffff;
border-radius: 0;
}
.email-header {
padding: 16px 24px;
}
.email-banner {
outline: none;
border: none;
text-decoration: none;
vertical-align: top;
display: inline-block;
max-width: 100%;
}
.email-title {
font-weight: bold;
margin: 0;
font-size: 24px;
padding: 16px 24px;
}
.email-text {
color: #a3244a;
font-size: 18px;
font-family: Optima, Candara, "Noto Sans", source-sans-pro, sans-serif;
font-weight: normal;
text-align: left;
padding: 16px 24px;
}
.email-button-container {
background-color: #ffffff;
text-align: center;
padding: 16px 24px;
}
.email-button {
color: #ffffff;
font-size: 16px;
font-family: Optima, Candara, "Noto Sans", source-sans-pro, sans-serif;
font-weight: bold;
background-color: #f4f1f1;
border-radius: 4px;
display: block;
padding: 16px 32px;
text-decoration: none;
background: #a3244a url('../img/button-primary.svg') no-repeat right;
}
.email-footer-text {
color: #a3244a;
font-size: 18px;
font-family: Optima, Candara, "Noto Sans", source-sans-pro, sans-serif;
font-weight: normal;
padding: 16px 24px;
}
.email-divider hr {
width: 100%;
border: none;
border-top: 3px solid #8b173a;
margin: 0;
}
.email-footer {
color: #a3244a;
font-size: 16px;
font-family: Optima, Candara, "Noto Sans", source-sans-pro, sans-serif;
font-weight: normal;
padding: 16px 24px;
display: flex;
flex-direction: column;
gap: 8px;
}
.email-footer p {
display: flex;
align-items: center;
gap: 8px;
margin: 0;
}
.email-footer .icon {
display: flex;
align-items: center;
}
12 changes: 12 additions & 0 deletions src/main/resources/assets/img/button-primary.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/assets/img/yivi-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 81 additions & 14 deletions src/main/resources/email-en.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,83 @@
<!doctype html>
<html>

<head>
<title>Add e-mail address to Yivi app</title>
<meta http-equiv="Content-Type" content="text/html charset=UTF-8" />
</head>

<body>
<p>Click the link to add the e-mail address to your Yivi app.</p>
<p>
<a href="%s">Add e-mail address to your Yivi app</a>
</p>
</body>

</html>
<head>
<link rel="stylesheet" href="./assets/css/style.css">
</head>
<body>
<div class="email-body">
<table class="email-table" align="center" role="presentation" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>
<div class="email-header">
<a href="yivi.app" target="_blank">
<img
alt="Yivi banner"
src="./assets/img/yivi-banner.png"
class="email-banner"
/>
</a>
</div>
<h2 class="email-title">Email Confirmation</h2>
<div class="email-text">
<p>Dear Yivi User,</p>
<p>
Thanks for trying out Yivi, your privacy-friendly identity
wallet!<br />Click the button below to verify and add your
email address to your Yivi app.
</p>
</div>
<div class="email-button-container">
<a href="%s" class="email-button" target="_blank">
Verify your email address
</a>
</div>
<div class="email-text">
If the button doesn&#x27;t work, you can also verify your email
by clicking the link below: <br />
<a href="%s" target="_blank">Verification link</a>
</div>
<div class="email-link"></div>
<div class="email-footer-text">
<p>
Didn&#39;t request this?<br />Ignore this email or contact us.
</p>
</div>
<div class="email-divider">
<hr />
</div>
<div class="email-footer">
<p>
<span class="icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16" fill="currentColor">
<path d="M12 2C8.1 2 5 5.1 5 9c0 3.5 3.6 6.9 6.6 9.7.2.2.4.3.6.3s.4-.1.6-.3C15.4 15.9 19 12.5 19 9c0-3.9-3.1-7-7-7zm0 11c-2.2 0-4-1.8-4-4s1.8-4 4-4 4 1.8 4 4-1.8 4-4 4z" />
<circle cx="12" cy="9" r="2.5" />
</svg>
</span>
Janssoniuslaan 80 | 3528 AJ Utrecht
</p>
<p>
<span class="icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16" fill="currentColor">
<path d="M6.62 10.79a15.49 15.49 0 0 0 6.59 6.59l2.2-2.2a1 1 0 0 1 1.06-.24c1.12.37 2.33.57 3.53.57a1 1 0 0 1 1 1v3.22a1 1 0 0 1-1 1A17.91 17.91 0 0 1 3 4a1 1 0 0 1 1-1h3.22a1 1 0 0 1 1 1c0 1.2.2 2.41.57 3.53a1 1 0 0 1-.24 1.06l-2.2 2.2z" />
</svg>
</span>
+31 (0)88 240 4200 
</p>
<p>
<span class="icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16" fill="currentColor">
<path d="M20 4H4C2.9 4 2 4.9 2 6v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 2v.01L12 11 4 6.01V6h16zM4 8.99L10.66 13c.36.21.77.32 1.17.32s.81-.11 1.17-.32L20 8.99V18H4V8.99z" />
</svg>
</span>
[email protected]
</p>

</div>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Loading
Loading