Skip to content

Commit

Permalink
Merge 30e70c8 into 2ba782c
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed Jul 11, 2021
2 parents 2ba782c + 30e70c8 commit c1c9c7d
Show file tree
Hide file tree
Showing 101 changed files with 4,843 additions and 1,295 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ allprojects {
apply plugin: 'checkstyle'

// For non-sop modules, enable android api compatibility check
if (!it.name.equals('pgpainless-sop')) {
if (it.name.equals('pgpainless-core') || it.name.equals('sop-java') || it.name.equals('pgpainless-sop')) {
// animalsniffer
apply plugin: 'ru.vyarus.animalsniffer'
dependencies {
Expand Down
File renamed without changes.
63 changes: 63 additions & 0 deletions pgpainless-cli/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
plugins {
id 'application'
}
def generatedVersionDir = "${buildDir}/generated-version"

sourceSets {
main {
output.dir(generatedVersionDir, builtBy: 'generateVersionProperties')
}
}

task generateVersionProperties {
doLast {
def propertiesFile = file "$generatedVersionDir/version.properties"
propertiesFile.parentFile.mkdirs()
propertiesFile.createNewFile()
// Instead of using a Properties object here, we directly write to the file
// since Properties adds a timestamp, ruining reproducibility
propertiesFile.write("version="+rootProject.version.toString())
}
}
processResources.dependsOn generateVersionProperties

dependencies {
implementation(project(":pgpainless-sop"))
implementation(project(":sop-java"))

implementation(project(":sop-java-picocli"))
implementation 'info.picocli:picocli:4.5.2'

testImplementation(project(":pgpainless-core"))

testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"

/*
implementation "org.bouncycastle:bcprov-debug-jdk15on:$bouncyCastleVersion"
/*/
implementation "org.bouncycastle:bcprov-jdk15on:$bouncyCastleVersion"
//*/
implementation "org.bouncycastle:bcpg-jdk15on:$bouncyCastleVersion"

// https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
}

mainClassName = 'org.pgpainless.cli.PGPainlessCLI'

jar {
manifest {
attributes 'Main-Class': "$mainClassName"
}

from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
} {
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
}
}

tasks."jar".dependsOn(":pgpainless-core:assemble")
File renamed without changes.
36 changes: 36 additions & 0 deletions pgpainless-cli/src/main/java/org/pgpainless/cli/PGPainlessCLI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2020 Paul Schaub.
*
* 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 org.pgpainless.cli;

import org.pgpainless.sop.SOPImpl;
import sop.cli.picocli.SopCLI;

public class PGPainlessCLI {

public PGPainlessCLI() {

}

public static void main(String[] args) {
int result = execute(args);
System.exit(result);
}

public static int execute(String... args) {
SopCLI.setSopInstance(new SOPImpl());
return SopCLI.execute(args);
}
}
22 changes: 22 additions & 0 deletions pgpainless-cli/src/main/java/org/pgpainless/cli/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2020 Paul Schaub.
*
* 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.
*/
/**
* PGPainless SOP implementing a Stateless OpenPGP Command Line Interface.
* @see <a href="https://tools.ietf.org/html/draft-dkg-openpgp-stateless-cli-01">
* Stateless OpenPGP Command Line Interface
* draft-dkg-openpgp-stateless-cli-01</a>
*/
package org.pgpainless.cli;
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.sop;
package org.pgpainless.cli;

import org.junit.jupiter.api.Test;
import picocli.CommandLine;

public class DummyTest {

@Test
public void dummyTest() {
new CommandLine(new PGPainlessCLI()).execute("generate-key", "Ed Snowden <citizen4@lavabit.com>");
PGPainlessCLI.execute("generate-key", "Ed Snowden <citizen4@lavabit.com>");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.sop;
package org.pgpainless.cli;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;
import picocli.CommandLine;

public class ExitCodeTest {

@Test
public void testUnknownCommand_69() {
assertEquals(69, new CommandLine(new PGPainlessCLI()).execute("generate-kex"));
assertEquals(69, PGPainlessCLI.execute("generate-kex"));
}

@Test
public void testCommandWithUnknownOption_37() {
assertEquals(37, new CommandLine(new PGPainlessCLI()).execute("generate-key", "-k", "\"k is unknown\""));
assertEquals(37, PGPainlessCLI.execute("generate-key", "-k", "\"k is unknown\""));
}

@Test
public void successfulVersion_0 () {
assertEquals(0, new CommandLine(new PGPainlessCLI()).execute("version"));
assertEquals(0, PGPainlessCLI.execute("version"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.sop;
package org.pgpainless.cli;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.sop.commands;
package org.pgpainless.cli.commands;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -35,8 +35,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.pgpainless.PGPainless;
import org.pgpainless.sop.PGPainlessCLI;
import picocli.CommandLine;
import org.pgpainless.cli.PGPainlessCLI;

public class ArmorTest {

Expand All @@ -61,7 +60,7 @@ public void armorSecretKey() throws IOException, PGPException, InvalidAlgorithmP
System.setIn(new ByteArrayInputStream(bytes));
ByteArrayOutputStream armorOut = new ByteArrayOutputStream();
System.setOut(new PrintStream(armorOut));
new CommandLine(new PGPainlessCLI()).execute("armor");
PGPainlessCLI.execute("armor");

PGPSecretKeyRing armored = PGPainless.readKeyRing().secretKeyRing(armorOut.toString());
assertArrayEquals(secretKey.getEncoded(), armored.getEncoded());
Expand All @@ -77,7 +76,7 @@ public void armorPublicKey() throws PGPException, InvalidAlgorithmParameterExcep
System.setIn(new ByteArrayInputStream(bytes));
ByteArrayOutputStream armorOut = new ByteArrayOutputStream();
System.setOut(new PrintStream(armorOut));
new CommandLine(new PGPainlessCLI()).execute("armor");
PGPainlessCLI.execute("armor");

PGPPublicKeyRing armored = PGPainless.readKeyRing().publicKeyRing(armorOut.toString());
assertArrayEquals(publicKey.getEncoded(), armored.getEncoded());
Expand All @@ -90,7 +89,7 @@ public void armorMessage() {
System.setIn(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)));
ByteArrayOutputStream armorOut = new ByteArrayOutputStream();
System.setOut(new PrintStream(armorOut));
new CommandLine(new PGPainlessCLI()).execute("armor");
PGPainlessCLI.execute("armor");

String armored = armorOut.toString();

Expand All @@ -110,7 +109,7 @@ public void doesNotNestArmorByDefault() {
System.setIn(new ByteArrayInputStream(armored.getBytes(StandardCharsets.UTF_8)));
ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));
new CommandLine(new PGPainlessCLI()).execute("armor");
PGPainlessCLI.execute("armor");

assertEquals(armored, out.toString());
}
Expand All @@ -127,7 +126,7 @@ public void testAllowNested() {
System.setIn(new ByteArrayInputStream(armored.getBytes(StandardCharsets.UTF_8)));
ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));
new CommandLine(new PGPainlessCLI()).execute("armor", "--allow-nested");
PGPainlessCLI.execute("armor", "--allow-nested");

assertNotEquals(armored, out.toString());
assertTrue(out.toString().contains(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.sop.commands;
package org.pgpainless.cli.commands;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -33,8 +33,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.pgpainless.PGPainless;
import org.pgpainless.sop.PGPainlessCLI;
import picocli.CommandLine;
import org.pgpainless.cli.PGPainlessCLI;

public class DearmorTest {

Expand All @@ -59,7 +58,7 @@ public void dearmorSecretKey() throws PGPException, InvalidAlgorithmParameterExc
System.setIn(new ByteArrayInputStream(armored.getBytes(StandardCharsets.UTF_8)));
ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));
new CommandLine(new PGPainlessCLI()).execute("dearmor");
PGPainlessCLI.execute("dearmor");

assertArrayEquals(secretKey.getEncoded(), out.toByteArray());
}
Expand All @@ -75,7 +74,7 @@ public void dearmorCertificate() throws PGPException, InvalidAlgorithmParameterE
System.setIn(new ByteArrayInputStream(armored.getBytes(StandardCharsets.UTF_8)));
ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));
new CommandLine(new PGPainlessCLI()).execute("dearmor");
PGPainlessCLI.execute("dearmor");

assertArrayEquals(certificate.getEncoded(), out.toByteArray());
}
Expand All @@ -92,7 +91,7 @@ public void dearmorMessage() {
System.setIn(new ByteArrayInputStream(armored.getBytes(StandardCharsets.UTF_8)));
ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));
new CommandLine(new PGPainlessCLI()).execute("dearmor");
PGPainlessCLI.execute("dearmor");

assertEquals("Hello, World\n", out.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.sop.commands;
package org.pgpainless.cli.commands;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -31,9 +31,8 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.pgpainless.sop.PGPainlessCLI;
import org.pgpainless.sop.TestUtils;
import picocli.CommandLine;
import org.pgpainless.cli.PGPainlessCLI;
import org.pgpainless.cli.TestUtils;

public class EncryptDecryptTest {

Expand Down Expand Up @@ -65,27 +64,27 @@ public void test() throws IOException {

OutputStream julietKeyOut = new FileOutputStream(julietKeyFile);
System.setOut(new PrintStream(julietKeyOut));
new CommandLine(new PGPainlessCLI()).execute("generate-key", "Juliet Capulet <juliet@capulet.lit>");
PGPainlessCLI.execute("generate-key", "Juliet Capulet <juliet@capulet.lit>");
julietKeyOut.close();

FileInputStream julietKeyIn = new FileInputStream(julietKeyFile);
System.setIn(julietKeyIn);
OutputStream julietCertOut = new FileOutputStream(julietCertFile);
System.setOut(new PrintStream(julietCertOut));
new CommandLine(new PGPainlessCLI()).execute("extract-cert");
PGPainlessCLI.execute("extract-cert");
julietKeyIn.close();
julietCertOut.close();

OutputStream romeoKeyOut = new FileOutputStream(romeoKeyFile);
System.setOut(new PrintStream(romeoKeyOut));
new CommandLine(new PGPainlessCLI()).execute("generate-key", "Romeo Montague <romeo@montague.lit>");
PGPainlessCLI.execute("generate-key", "Romeo Montague <romeo@montague.lit>");
romeoKeyOut.close();

FileInputStream romeoKeyIn = new FileInputStream(romeoKeyFile);
System.setIn(romeoKeyIn);
OutputStream romeoCertOut = new FileOutputStream(romeoCertFile);
System.setOut(new PrintStream(romeoCertOut));
new CommandLine(new PGPainlessCLI()).execute("extract-cert");
PGPainlessCLI.execute("extract-cert");
romeoKeyIn.close();
romeoCertOut.close();

Expand All @@ -94,7 +93,7 @@ public void test() throws IOException {
System.setIn(msgIn);
OutputStream msgAscOut = new FileOutputStream(msgAscFile);
System.setOut(new PrintStream(msgAscOut));
new CommandLine(new PGPainlessCLI()).execute("encrypt",
PGPainlessCLI.execute("encrypt",
"--sign-with", romeoKeyFile.getAbsolutePath(),
julietCertFile.getAbsolutePath());
msgAscOut.close();
Expand All @@ -107,7 +106,7 @@ public void test() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream pOut = new PrintStream(out);
System.setOut(pOut);
new CommandLine(new PGPainlessCLI()).execute("decrypt",
PGPainlessCLI.execute("decrypt",
"--verify-out", verifyFile.getAbsolutePath(),
"--verify-with", romeoCertFile.getAbsolutePath(),
julietKeyFile.getAbsolutePath());
Expand Down

0 comments on commit c1c9c7d

Please sign in to comment.