Skip to content

Commit

Permalink
Linting all files
Browse files Browse the repository at this point in the history
  • Loading branch information
ineiti committed Aug 28, 2020
1 parent 141ca8d commit 073f77e
Show file tree
Hide file tree
Showing 106 changed files with 10,428 additions and 9,383 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: pre-commit

on:
pull_request:
push:
branches: [develop]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/setup-java@v1
with:
java-version: '11'
- uses: pre-commit/[email protected]
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/c4dt/google-style-precommit-hook
rev: v1.0
hooks:
- id: google-style-java
44 changes: 20 additions & 24 deletions GenerateKeyPair.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
/**
* This file only serves as an example on how to get keys in the right encoding.
* This outputs the keys in the PKCS8 format for the private key and the X509 format for the publickey
*
* DO NOT USE THEM IN PRODUCTION UNLESS THE KEYSPECS ARE OK FOR YOU
* This file only serves as an example on how to get keys in the right encoding. This outputs the
* keys in the PKCS8 format for the private key and the X509 format for the publickey
*
* <p>DO NOT USE THEM IN PRODUCTION UNLESS THE KEYSPECS ARE OK FOR YOU
*/
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Security;
import java.util.Base64;

import java.security.Security;
public class GenerateKeyPair {
public static void main(String[] args) throws Exception {
Security.setProperty("crypto.policy", "unlimited");
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
KeyPair pair = generator.genKeyPair();
PrivateKey privateKey = pair.getPrivate();
PublicKey publicKey = pair.getPublic();
FileOutputStream outputStream = new FileOutputStream("generated_pub.pem");
outputStream.write(Base64.getEncoder().encode(publicKey.getEncoded()));
outputStream.close();

public class GenerateKeyPair{
public static void main(String[] args) throws Exception {
Security.setProperty("crypto.policy", "unlimited");
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
KeyPair pair = generator.genKeyPair();
PrivateKey privateKey = pair.getPrivate();
PublicKey publicKey = pair.getPublic();
FileOutputStream outputStream = new FileOutputStream("generated_pub.pem");
outputStream.write(Base64.getEncoder().encode(publicKey.getEncoded()));
outputStream.close();

outputStream = new FileOutputStream("generated_private.pem");
outputStream.write(Base64.getEncoder().encode(privateKey.getEncoded()));
outputStream.close();
}
}
outputStream = new FileOutputStream("generated_private.pem");
outputStream.write(Base64.getEncoder().encode(privateKey.getEncoded()));
outputStream.close();
}
}
82 changes: 37 additions & 45 deletions GenerateKeyPairEC.java
Original file line number Diff line number Diff line change
@@ -1,59 +1,51 @@
/**
* This file only serves as an example on how to get keys in the right encoding.
* In order to use it you need BouncyCastle on the classpath!
*
* DO NOT USE THEM IN PRODUCTION UNLESS THE KEYSPECS ARE OK FOR YOU
* This file only serves as an example on how to get keys in the right encoding. In order to use it
* you need BouncyCastle on the classpath!
*
* <p>DO NOT USE THEM IN PRODUCTION UNLESS THE KEYSPECS ARE OK FOR YOU
*/
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.Key;
import java.io.StringWriter;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Base64;
import java.security.spec.ECGenParameterSpec;
import java.io.StringWriter;

import java.security.Security;
import java.security.spec.ECGenParameterSpec;
import java.util.Base64;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.io.pem.PemWriter;
import org.bouncycastle.util.io.pem.PemObject;
import org.bouncycastle.util.io.pem.PemWriter;

public class GenerateKeyPairEC {
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
Security.setProperty("crypto.policy", "unlimited");
KeyPairGenerator generator = KeyPairGenerator.getInstance("ECDSA", "BC");
ECGenParameterSpec spec = new ECGenParameterSpec("secp256r1");
generator.initialize(spec);
KeyPair pair = generator.genKeyPair();
PrivateKey privateKey = pair.getPrivate();
PublicKey publicKey = pair.getPublic();

public class GenerateKeyPairEC{
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
Security.setProperty("crypto.policy", "unlimited");
KeyPairGenerator generator = KeyPairGenerator.getInstance("ECDSA", "BC");
ECGenParameterSpec spec = new ECGenParameterSpec("secp256r1");
generator.initialize(spec);
KeyPair pair = generator.genKeyPair();
PrivateKey privateKey = pair.getPrivate();
PublicKey publicKey = pair.getPublic();
StringWriter privateKeyWriter = new StringWriter();
PemWriter privateKeyPemWriter = new PemWriter(privateKeyWriter);
privateKeyPemWriter.writeObject(new PemObject("PRIVATE KEY", privateKey.getEncoded()));
privateKeyPemWriter.flush();
privateKeyPemWriter.close();

StringWriter privateKeyWriter = new StringWriter();
PemWriter privateKeyPemWriter = new PemWriter(privateKeyWriter);
privateKeyPemWriter.writeObject(new PemObject("PRIVATE KEY", privateKey.getEncoded()));
privateKeyPemWriter.flush();
privateKeyPemWriter.close();
StringWriter publicKeyWriter = new StringWriter();
PemWriter publicKeyPemWriter = new PemWriter(publicKeyWriter);
publicKeyPemWriter.writeObject(new PemObject("PUBLIC KEY", publicKey.getEncoded()));
publicKeyPemWriter.flush();
publicKeyPemWriter.close();

StringWriter publicKeyWriter = new StringWriter();
PemWriter publicKeyPemWriter = new PemWriter(publicKeyWriter);
publicKeyPemWriter.writeObject(new PemObject("PUBLIC KEY", publicKey.getEncoded()));
publicKeyPemWriter.flush();
publicKeyPemWriter.close();
FileOutputStream outputStream = new FileOutputStream("generated_pub.pem");
outputStream.write(Base64.getEncoder().encode(publicKeyWriter.toString().getBytes()));
outputStream.close();

FileOutputStream outputStream = new FileOutputStream("generated_pub.pem");
outputStream.write(Base64.getEncoder().encode(
publicKeyWriter.toString().getBytes()
));
outputStream.close();

outputStream = new FileOutputStream("generated_private.pem");
outputStream.write(Base64.getEncoder().encode(
privateKeyWriter.toString().getBytes()
));
outputStream.close();
}
}
outputStream = new FileOutputStream("generated_private.pem");
outputStream.write(Base64.getEncoder().encode(privateKeyWriter.toString().getBytes()));
outputStream.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,51 @@

import java.time.Duration;
import java.util.List;

import org.dpppt.backend.sdk.model.Exposee;

public interface DPPPTDataService {

/**
* Upserts (Update or Inserts) the given exposee
*
* @param exposee the exposee to upsert
* @param appSource the app name
*/
void upsertExposee(Exposee exposee, String appSource);

/**
* Upserts (Update or Inserts) the given exposees (if keys cannot be derived from one master key)
*
* @param exposees the list of exposees to upsert
* @param appSource the app name
*/
void upsertExposees(List<Exposee> exposees, String appSource);

/**
* Returns the maximum id of the stored exposed entries fo the given batch.
*
* @param batchReleaseTime in milliseconds since the start of the Unix Epoch, must be a multiple of
* @param releaseBucketDuration in milliseconds
* @return the maximum id of the stored exposed entries fo the given batch
*/
int getMaxExposedIdForBatchReleaseTime(long batchReleaseTime, long releaseBucketDuration);

/**
* Returns all exposees for the given batch.
*
* @param batchReleaseTime in milliseconds since the start of the Unix Epoch, must be a multiple of
* @param releaseBucketDuration in milliseconds
* @return all exposees for the given batch
*/
List<Exposee> getSortedExposedForBatchReleaseTime(long batchReleaseTime, long releaseBucketDuration);

/**
* deletes entries older than retentionperiod
*
* @param retentionPeriod duration of retention period for exposed keys
*/
void cleanDB(Duration retentionPeriod);

/**
* Upserts (Update or Inserts) the given exposee
*
* @param exposee the exposee to upsert
* @param appSource the app name
*/
void upsertExposee(Exposee exposee, String appSource);

/**
* Upserts (Update or Inserts) the given exposees (if keys cannot be derived from one master key)
*
* @param exposees the list of exposees to upsert
* @param appSource the app name
*/
void upsertExposees(List<Exposee> exposees, String appSource);

/**
* Returns the maximum id of the stored exposed entries fo the given batch.
*
* @param batchReleaseTime in milliseconds since the start of the Unix Epoch, must be a multiple
* of
* @param releaseBucketDuration in milliseconds
* @return the maximum id of the stored exposed entries fo the given batch
*/
int getMaxExposedIdForBatchReleaseTime(long batchReleaseTime, long releaseBucketDuration);

/**
* Returns all exposees for the given batch.
*
* @param batchReleaseTime in milliseconds since the start of the Unix Epoch, must be a multiple
* of
* @param releaseBucketDuration in milliseconds
* @return all exposees for the given batch
*/
List<Exposee> getSortedExposedForBatchReleaseTime(
long batchReleaseTime, long releaseBucketDuration);

/**
* deletes entries older than retentionperiod
*
* @param retentionPeriod duration of retention period for exposed keys
*/
void cleanDB(Duration retentionPeriod);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@

import java.sql.ResultSet;
import java.sql.SQLException;

import org.dpppt.backend.sdk.model.Exposee;
import org.springframework.jdbc.core.RowMapper;

public class ExposeeRowMapper implements RowMapper<Exposee> {
@Override
public Exposee mapRow(ResultSet rs, int rowNum) throws SQLException {
Exposee exposee = new Exposee();
exposee.setKey(rs.getString("key"));
exposee.setId(rs.getInt("pk_exposed_id"));
exposee.setKeyDate(rs.getTimestamp("key_date").getTime());
return exposee;
}
}
@Override
public Exposee mapRow(ResultSet rs, int rowNum) throws SQLException {
Exposee exposee = new Exposee();
exposee.setKey(rs.getString("key"));
exposee.setId(rs.getInt("pk_exposed_id"));
exposee.setKeyDate(rs.getTimestamp("key_date").getTime());
return exposee;
}
}
Loading

0 comments on commit 073f77e

Please sign in to comment.