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

#810 challenge 42: Created a settings.xml to connect to an imaginary Nexus repo #1034

Closed
Closed
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] authored Oct 17, 2023

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 1c61dc5a78c6c94a9ff686cddc89d106ece56b81
13 changes: 7 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -248,12 +248,13 @@
<artifactId>spotbugs-annotations</artifactId>
<version>4.7.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<version>2.7</version> <!-- Replace with the latest version available -->
</dependency>
<!-- <dependency>-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<version>2.7</version>
<!-- Replace with the latest version available -->
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.h2database</groupId>-->
<!-- <artifactId>h2</artifactId>-->
<!-- <version>2.1.214</version>-->
Original file line number Diff line number Diff line change
@@ -25,64 +25,64 @@
@Order(41)
public class Challenge41 extends Challenge {

private final Resource resource;
private final Resource resource;

public Challenge41(
ScoreCard scoreCard, @Value("classpath:maven/settings/settings.xml") Resource resource) {
super(scoreCard);
this.resource = resource;
}
public Challenge41(
ScoreCard scoreCard, @Value("classpath:maven/settings/settings.xml") Resource resource) {
super(scoreCard);
this.resource = resource;
}

@Override
public boolean canRunInCTFMode() {
return true;
}
@Override
public boolean canRunInCTFMode() {
return true;
}

@Override
public Spoiler spoiler() {
return new Spoiler(getSolution());
}
@Override
public Spoiler spoiler() {
return new Spoiler(getSolution());
}

@Override
public boolean answerCorrect(String answer) {
return getSolution().equals(answer);
}
@Override
public boolean answerCorrect(String answer) {
return getSolution().equals(answer);
}

/** {@inheritDoc} */
@Override
public int difficulty() {
return Difficulty.EASY;
}
/** {@inheritDoc} */
@Override
public int difficulty() {
return Difficulty.EASY;
}

/** {@inheritDoc} Cryptography based. */
@Override
public String getTech() {
return ChallengeTechnology.Tech.CRYPTOGRAPHY.id;
}
/** {@inheritDoc} Cryptography based. */
@Override
public String getTech() {
return ChallengeTechnology.Tech.CRYPTOGRAPHY.id;
}

@Override
public boolean isLimitedWhenOnlineHosted() {
return false;
}
@Override
public boolean isLimitedWhenOnlineHosted() {
return false;
}

@Override
public List<RuntimeEnvironment.Environment> supportedRuntimeEnvironments() {
return List.of(RuntimeEnvironment.Environment.DOCKER);
}
@Override
public List<RuntimeEnvironment.Environment> supportedRuntimeEnvironments() {
return List.of(RuntimeEnvironment.Environment.DOCKER);
}

private String getSolution() {
try {
String config = resource.getContentAsString(Charset.defaultCharset());
StringReader stringReader = new StringReader(config);
private String getSolution() {
try {
String config = resource.getContentAsString(Charset.defaultCharset());
StringReader stringReader = new StringReader(config);

XMLConfiguration xmlConfiguration = new XMLConfiguration();
xmlConfiguration.read(stringReader);
XMLConfiguration xmlConfiguration = new XMLConfiguration();
xmlConfiguration.read(stringReader);

// Retrieve the Nexus password
return xmlConfiguration.getString("nexus.password");
} catch (Exception e) {
log.warn("there was an exception with decrypting content in challenge41", e);
return "error_decryption";
}
// Retrieve the Nexus password
return xmlConfiguration.getString("nexus.password");
} catch (Exception e) {
log.warn("there was an exception with decrypting content in challenge41", e);
return "error_decryption";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.owasp.wrongsecrets.challenges.docker;

import static org.mockito.Mockito.when;

import java.io.IOException;
import java.nio.charset.Charset;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -9,11 +13,6 @@
import org.owasp.wrongsecrets.ScoreCard;
import org.springframework.core.io.Resource;

import java.io.IOException;
import java.nio.charset.Charset;

import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class Challenge41Test {
@Mock private ScoreCard scoreCard;
@@ -22,8 +21,9 @@ class Challenge41Test {

@BeforeEach
void setUp() throws IOException {
when(resource.getContentAsString(Charset.defaultCharset()))
.thenReturn("<root><nexus><username>test_user</username><password>test_password</password></nexus></root>");
when(resource.getContentAsString(Charset.defaultCharset()))
.thenReturn(
"<root><nexus><username>test_user</username><password>test_password</password></nexus></root>");
}

@Test