Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #123 from felleslosninger/cleanup-and-javadoc
Browse files Browse the repository at this point in the history
Javadoc and clean-up
  • Loading branch information
eschoien authored Aug 5, 2021
2 parents 44a639a + 8cc28d5 commit 5787e27
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@ public String getKey(@PathVariable String id) {
}
}


/**
* Route that receives a public key of a given user
* @param body = the public key as a PEM string
* @param userID = the ID of the user as a string
* @return a response entity that the key was added, abd a HttpStatus.OK
*/
@PostMapping(value = "vdr/postKey")
ResponseEntity<String> postKeyToVDR(@RequestBody String body, @RequestParam(value="userID")String userID) {
System.out.println("something is working");
System.out.println(body);
fileHandler.addPublicKey(userID, vdrService.PEMtoRSAConverter(body));
return new ResponseEntity<>("Hello overlord", HttpStatus.OK);
return new ResponseEntity<>("public key received", HttpStatus.OK);
}

@GetMapping("/vdr/getTypes/{issuer}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.digdir.issuer.storage.FileHandler;
import com.digdir.issuer.util.KeyGenerator;
import com.digdir.issuer.util.*;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.digdir.issuer.storage.FileHandler;
import com.digdir.issuer.util.KeyGenerator;
import com.digdir.issuer.util.*;

import java.security.NoSuchAlgorithmException;
import java.security.interfaces.RSAPrivateKey;
Expand Down Expand Up @@ -70,10 +70,6 @@ public JwtVP(String walletId, String ... VCs) {

}

public String getToken() {
return this.token;
}

public String[] getVCs() {
return this.VCs;
}
Expand Down
4 changes: 2 additions & 2 deletions issuer/src/main/java/com/digdir/issuer/credentials/VC.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public VC(String type, Map<String, Object> credentialSubject){
}

/**
* Construct VC-object with already known type.
* Construct VC-object of type "VerifiableCredential.
* @param credentialSubject Subject of the VC
*/
public VC(Map<String, Object> credentialSubject){
Expand All @@ -35,7 +35,7 @@ public VC(Map<String, Object> credentialSubject){
}

/**
* Method creates VC as Map and put's context, type and credentialsubject into VC-Map.
* Method creates VC as Map and put's context, type and credentialSubject into VC-Map.
* @return VC as Map
*/
public Map<String, Object> getVCMap(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.auth0.jwt.interfaces.DecodedJWT;
import com.digdir.issuer.credentials.Jwt;
import com.digdir.issuer.credentials.JwtVerifier;
import com.digdir.issuer.credentials.*;
import com.digdir.issuer.storage.FileHandler;
import com.digdir.issuer.storage.JwtTypeHandler;
import net.glxn.qrgen.javase.QRCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Objects;

/**
* Class as Repository for handle operations with files.
* Class as Repository for handling public keys in file.
*/
@Repository
public class FileHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@
import java.util.HashMap;
import java.util.List;


/**
* Class that reads from file the available issuers and their available VC-types
*/
public class IssuerTypesHandler {

private static String path = "src/main/resources/IssuerTypes.json"; //change this path to issuer/src/main/resources/IssuerTypes.json if there is a problem with the path.


public IssuerTypesHandler() {
}


public static void main(String[] args) {
IssuerTypesHandler ith = new IssuerTypesHandler();
System.out.println(ith.getAllIssuers());
}

/**
* Loads from file the VC types that the given issuer can construct
* @param issuer = the issuer
* @return a list of the VC types
*/
public List<String> getTypesWithIssuer(String issuer){
try {
InputStream inputStream = new FileInputStream(path);
Expand All @@ -41,6 +45,11 @@ public List<String> getTypesWithIssuer(String issuer){
}
}


/**
* Loads from file all the available issuers
* @return a list of the issuers
*/
public List<String> getAllIssuers(){
List<String> allIssuers = new ArrayList<>();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class PrivateKeysFileHandler {
* Retrives existing map of PK's in file and appends PK.
*
* @param id id for identifying a public key to it's owner in VDR.
* @param pk Public key to be saved to VDR.
* @param pk Private key to be saved to VDR.
*/
public void addPrivateKey(String id, PrivateKey pk){
HashMap<String, PrivateKey> map = loadFromFile();
Expand All @@ -37,11 +37,11 @@ public void addPrivateKey(String id, PrivateKey pk){
}

/**
* Method for retrieving a public key from VDR(PublicKeyFile.json)
* Method for retrieving a public key from PrivateKeys.json
* @param id id for public key to retrive
* @return Public Key with id as specified, if existing.
*/
public PrivateKey getPublicKey(String id){
public PrivateKey getPrivateKey(String id){
if (!Objects.requireNonNull(loadFromFile()).containsKey(id)) {
throw new IllegalArgumentException("No such id");
}
Expand All @@ -50,7 +50,7 @@ public PrivateKey getPublicKey(String id){


/**
* Method for saving HashMap of id and PublicKey to file.
* Method for saving HashMap of id and private key to file.
* @param privateKeyHashMap HashMap to save.
*/
private void saveToFile(HashMap<String, PrivateKey> privateKeyHashMap) {
Expand Down Expand Up @@ -82,8 +82,8 @@ private void saveToFile(HashMap<String, PrivateKey> privateKeyHashMap) {


/**
* Loads existing HashMap of id and PublicKey from PublicKeyFile.json
* @return HashMap of id and PublicKey
* Loads existing HashMap of id and private key from PrivateKeys.json
* @return HashMap of id and private key
*/
private HashMap<String, PrivateKey> loadFromFile() {
try {
Expand All @@ -96,7 +96,7 @@ private HashMap<String, PrivateKey> loadFromFile() {
try {
privateKeyMap.put(key, KeyFactory.getInstance("RSA").generatePrivate(new X509EncodedKeySpec((Base64.getDecoder().decode(value)))));
} catch (InvalidKeySpecException | NoSuchAlgorithmException invalidKeySpecException) {
System.out.println("Problem in Filehandler. Cant load from file. ");
System.out.println("Cant load from file. ");
}
});
return privateKeyMap;
Expand All @@ -109,8 +109,8 @@ private HashMap<String, PrivateKey> loadFromFile() {
}

/**
* Method for removing a public key from VDR(PublicKeyFile.json) with specific id.
* @param id id for publuc key to remove
* Method for removing a private key from PrivateKeys.json with specific id.
* @param id id for public key to remove
*/
public void removeKeyByID(String id) {
if(!loadFromFile().containsKey(id)) {
Expand All @@ -131,13 +131,7 @@ public static void main(String[] args) throws NoSuchAlgorithmException {
fileHandler.addPublicKey("BasePublic", keyGenerator.getPublicKey());
}

// Used in test: -----------------------------------------------------------------------
public String getPublicKeyAsString(String id){
PrivateKey pk = getPublicKey(id);
byte[] jsonPk = pk.getEncoded();
Gson gson = new Gson();
return gson.toJson(jsonPk);
}

public void setPath(String path){
this.path = path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ public class VerifyController {
private final VerifyService verifyService = new VerifyService();


@GetMapping("/api/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
return String.format("Hello %s!", name);
}

/**
* Route that receives and verifies a jwt token
* @param token = the jwt token to send
Expand Down Expand Up @@ -46,9 +41,7 @@ public boolean checkVerify(@RequestParam(value = "id") String id) {
@CrossOrigin(origins = "http://localhost:3000")
@PostMapping("/api/sendUserID")
public ResponseEntity<String> sendUserID(@RequestBody String id) {
UserIdHandler idH = new UserIdHandler();
idH.addUserId(id, false);
return new ResponseEntity<>("user added", HttpStatus.OK);
return verifyService.sendUserID(id);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public boolean checkVerify(String id) {
return uih.getIsUserVerified(id);
}

public ResponseEntity<String> sendUserID(String id) {
UserIdHandler idH = new UserIdHandler();
idH.addUserId(id, false);
return new ResponseEntity<>("user added", HttpStatus.OK);
}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,33 +101,9 @@ public String getJwt(String type) {
public static void main(String[] args) throws Exception {


// Requester r = new Requester("http://localhost:8083/api/key/");
Requester r2 = new Requester("http://localhost:8083/vdr/key/");
System.out.println(r2.getKeyByID("GrunnID-portalen.no063b9967-fa86-4168-a142-67beeb0f539e"));

// System.out.println(r.getKeyByID("testIss2575273c-c1ff-446c-9d8c-6504af46bd14"));
/*
VCJson vcJson = r2.getCredentialFromIssuer();
System.out.println(vcJson.getIssuerID());
PublicKey key = r.getKeyByID(vcJson.getIssuerID());
System.out.println(key);
SignatureVerifier sv = new SignatureVerifier();
Gson gson = new Gson();
byte[] bytes = gson.fromJson(vcJson.getSignature(), byte[].class);
System.out.println(bytes);
boolean verify = sv.verifySignature(vcJson.getPayload(), bytes, key);
System.out.println(verify);
*/


// System.out.println(sv.decryptSignature((byte[]) list.get(2), new KeyGenerator().getPublicKey(), credential));

}


Expand Down

0 comments on commit 5787e27

Please sign in to comment.