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

Vilde fix #117

Merged
merged 6 commits into from
Aug 4, 2021
Merged
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
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
package com.digdir.issuer.controller;

import com.digdir.issuer.service.VcService;
import net.glxn.qrgen.core.image.ImageType;
import net.glxn.qrgen.javase.QRCode;
import org.apache.commons.io.IOUtils;
import org.apache.coyote.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;

/**
* Controller for BaseVC-operations
Expand All @@ -47,12 +35,6 @@ public ResponseEntity<byte[]> getProtectedPage(@AuthenticationPrincipal OidcUser
String QR_TEXT = vcService.getBaseVC(principal);
byte[] qrImage = vcService.generateByteArray(QR_TEXT);
return ResponseEntity.ok().contentType(MediaType.IMAGE_PNG).body(qrImage);
/*
public String getProtectedPage(@AuthenticationPrincipal OidcUser principal, Model model) throws Exception {
System.out.println(principal.getIdToken().getTokenValue());
return vcService.getBaseVC(principal);
}
*/
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class IssuerController {
* Route that handles issuance of certain VC, it requires a valid baseVC to be input
*
* @param type Type of credential, that is checked in the "database" if the type exists
* @param baseVC The VC gotten from the baseId issuer by logging in through id-porten.
* @param baseVC The VC gotten from the baseId issuer by logging in through ID-porten.
* @param issuer The issuer, if valid issuer exists.
* @return A VC in the format of a JWT, this is signed with issuer public key and can be verified by verifier by getting that key from the VDR
*/
Expand All @@ -40,7 +40,7 @@ public String getVC2(@RequestParam(value = "type", defaultValue = "defaultType")
}

/**
* Endpoint that returns all types one can get from an issuer, atm ther is only one issuer...but you get the point
* Endpoint that returns all types one can get from an issuer, atm there is only one issuer...but you get the point
* @return returns all types from this issuer
*/
@GetMapping("/api/types")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.Base64;
import java.util.Collection;

Expand Down Expand Up @@ -44,14 +42,6 @@ public String getKey(@PathVariable String id) {
}
}

@Deprecated
@GetMapping("/vdr/postKeyOld")
public String postKey(@RequestParam(value = "id") String id, @RequestParam(value="key") String key) throws InvalidKeySpecException, NoSuchAlgorithmException {
fileHandler.addPublicKey(id, vdrService.pemToKey(key));
return "ok";
}


@PostMapping(value = "vdr/postKey")
ResponseEntity<String> postKeyToVDR(@RequestBody String body, @RequestParam(value="userID")String userID) {
System.out.println("something is working");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.digdir.issuer.credentials;



import java.util.HashMap;
import java.util.Map;

Expand Down
16 changes: 0 additions & 16 deletions issuer/src/main/java/com/digdir/issuer/service/VDRService.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,4 @@ public RSAPublicKey PEMtoRSAConverter(String publicKeyInPEMFormat) {
return rsaPublicKey;
}



//
@Deprecated
public RSAPublicKey pemToKey(String key) throws InvalidKeySpecException, NoSuchAlgorithmException {
String publicKeyPEM = key;
publicKeyPEM = publicKeyPEM.replace(" ", "+");
publicKeyPEM = publicKeyPEM.replace("-----BEGIN+PUBLIC+KEY-----", "");
publicKeyPEM = publicKeyPEM.replace("-----END+PUBLIC+KEY-----", "");
byte[] encoded = Base64.decodeBase64(publicKeyPEM);
KeyFactory kf = KeyFactory.getInstance("RSA");
RSAPublicKey pubKey = (RSAPublicKey) kf.generatePublic(new X509EncodedKeySpec(encoded));
System.out.println(pubKey);
return pubKey;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ private void saveToFile(HashMap<String, PublicKey> publicKeyMap) {

HashMap<String, String> map = new HashMap<>();
publicKeyMap.forEach((key, value) -> map.put(key, Base64.getEncoder().encodeToString(value.getEncoded())));
//publicKeyMap.forEach((key, value) -> map.put(key, value.getEncoded()));

String javaObjectString = gson.toJson(map); // converts to json

Expand Down Expand Up @@ -104,7 +103,6 @@ private HashMap<String, PublicKey> loadFromFile() {
HashMap<String, PublicKey> publicKeyMap = new HashMap<>();
mapFromFile.forEach((key, value) -> {
try {
//publicKeyMap.put(key, KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(value.getBytes(StandardCharsets.UTF_8))));
publicKeyMap.put(key, KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.getDecoder().decode(value))));
} catch (InvalidKeySpecException | NoSuchAlgorithmException invalidKeySpecException) {
System.out.println("Problem in Filehandler. Cant load from file. ");
Expand Down Expand Up @@ -133,8 +131,6 @@ public void removeKeyByID(String id) {

}



// Used in test: -----------------------------------------------------------------------
public String getPublicKeyAsString(String id){
PublicKey pk = getPublicKey(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ private void saveToFile(HashMap<String, PrivateKey> privateKeyHashMap) {

HashMap<String, String> map = new HashMap<>();
privateKeyHashMap.forEach((key, value) -> map.put(key, Base64.getEncoder().encodeToString(value.getEncoded())));
//publicKeyMap.forEach((key, value) -> map.put(key, value.getEncoded()));

String javaObjectString = gson.toJson(map); // converts to json

Expand Down Expand Up @@ -95,7 +94,6 @@ private HashMap<String, PrivateKey> loadFromFile() {
HashMap<String, PrivateKey> privateKeyMap = new HashMap<>();
mapFromFile.forEach((key, value) -> {
try {
//publicKeyMap.put(key, KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(value.getBytes(StandardCharsets.UTF_8))));
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. ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@
@RestController
public class SpringbootVerifierApp {



public static void main(String[] args) {
SpringApplication.run(SpringbootVerifierApp.class, args);
}






}

Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
package com.example.verifier.controller;

import com.example.verifier.service.VerifyService;
import com.example.verifier.verification.JwtVerifier;
import com.example.verifier.verification.UserIdHandler;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.lang.constant.Constable;

@RestController
@CrossOrigin(origins = "*", allowedHeaders = "*")

public class VerifyController {




private final VerifyService verifyService = new VerifyService();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,6 @@ public void removeKeyByID(String id) {

public static void main(String[] args) throws NoSuchAlgorithmException {
KeyPairGenerator kpg1 = KeyPairGenerator.getInstance("RSA");
/*
HashMap<String, PublicKey> map = new HashMap<>();
map.put("id1", kpg1.generateKeyPair().getPublic());
map.put("id2", kpg1.generateKeyPair().getPublic());

*/

FileHandler fh = new FileHandler();
HashMap<String, PublicKey> map;
map = fh.loadFromFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.lang.reflect.Array;

@Service
public class VerifyService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.verifier.verification;

import com.google.gson.Gson;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -67,10 +66,7 @@ public PublicKey getKeyByID(String id) {
final HttpResponse<String> response = HttpClient.newBuilder().build().send(request,
HttpResponse.BodyHandlers.ofString());
final String responseString = response.body();
System.out.println("getKeyByID() response: " + responseString);
// Gson gson = new Gson();
// byte[] bytes = gson.fromJson(responseString, byte[].class);

System.out.println("getKeyByID() response: " + responseString);

publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.getDecoder().decode(responseString)));
System.out.println(Base64.getEncoder().encodeToString(publicKey.getEncoded()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,11 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.function.BiConsumer;
import java.util.function.BooleanSupplier;


/**
Expand Down Expand Up @@ -76,7 +66,7 @@ public HashMap<String, Boolean> loadFromFile() {

/**
* Saves to file a hashmap that maps userIDs to corresponding boolean values
* @param publicKeyMap = the map to save to file
* @param userIDMap = the map to save to file
*/
private void saveToFile(HashMap<String, Boolean> userIDMap) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
C:\Users\camp-vtk\IdeaProjects\digdir-camp-2021-VC\verifier\src\main\java\com\example\verifier\SpringbootVerifierApp.java
C:\Users\camp-vtk\IdeaProjects\digdir-camp-2021-VC\verifier\src\main\java\com\example\verifier\service\VerifyService.java
C:\Users\camp-vtk\IdeaProjects\digdir-camp-2021-VC\verifier\src\main\java\com\example\verifier\copied\FileHandler.java
C:\Users\camp-vtk\IdeaProjects\digdir-camp-2021-VC\verifier\src\main\java\com\example\verifier\copied\JwtVP.java
C:\Users\camp-vtk\IdeaProjects\digdir-camp-2021-VC\verifier\src\main\java\com\example\verifier\copied\CredentialSubject.java
C:\Users\camp-vtk\IdeaProjects\digdir-camp-2021-VC\verifier\src\main\java\com\example\verifier\verification\UserIdHandler.java
C:\Users\camp-vtk\IdeaProjects\digdir-camp-2021-VC\verifier\src\main\java\com\example\verifier\controller\VerifyController.java
C:\Users\camp-vtk\IdeaProjects\digdir-camp-2021-VC\verifier\src\main\java\com\example\verifier\verification\JwtVerifier.java
C:\Users\camp-vtk\IdeaProjects\digdir-camp-2021-VC\verifier\src\main\java\com\example\verifier\verification\JwtTypeHandler.java
C:\Users\camp-vtk\IdeaProjects\digdir-camp-2021-VC\verifier\src\main\java\com\example\verifier\copied\VC.java
C:\Users\camp-vtk\IdeaProjects\digdir-camp-2021-VC\verifier\src\main\java\com\example\verifier\copied\Jwt.java
C:\Users\camp-vtk\IdeaProjects\digdir-camp-2021-VC\verifier\src\main\java\com\example\verifier\copied\KeyGenerator.java
C:\Users\camp-vtk\IdeaProjects\digdir-camp-2021-VC\verifier\src\main\java\com\example\verifier\verification\Requester.java
19 changes: 1 addition & 18 deletions wallet/wallet-app/components/frames/Access.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable no-alert */
import Icon from 'react-native-vector-icons/Ionicons';
import React, { useEffect, useRef, useState } from 'react';
import { SafeAreaView, StatusBar, Text, TouchableOpacity, Vibration } from 'react-native';
import { SafeAreaView, StatusBar, Text, Vibration } from 'react-native';
import ReactNativePinView from 'react-native-pin-view';
import { useDispatch } from 'react-redux';
import AsyncStorage from '@react-native-async-storage/async-storage';
Expand All @@ -22,7 +22,6 @@ export default function Access() {
const [text, setText] = useState('');

const dispatch = useDispatch();
// const { signedIn } = useSelector((state) => state.signedInStatus);

const isFocused = useIsFocused();

Expand Down Expand Up @@ -159,22 +158,6 @@ export default function Access() {
}
/>
</SafeAreaView>
{/*
<TouchableOpacity
style={{
borderRadius: 4,
backgroundColor: 'rgb(30,46,60)',
alignItems: 'center',
width: 150,
marginBottom: 10,
marginLeft: 10,
}}
onPress={() => AsyncStorage.removeItem('pin') && checkHasPin() && alert('Personlig kode slettet')}>
<Text style={{ color: 'white' }}>Slett personlig kode</Text>
</TouchableOpacity>
*/}
</>
);
}

// "SLETT PERSONLIG KODE" SKAL IKKE MED TIL SLUTT, DEN ER DER BARE I TILFELLE VI GLEMMER KODEN VÅR, ELLER NOE LIGNENDE
21 changes: 2 additions & 19 deletions wallet/wallet-app/components/frames/ActivityFrame.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { useState } from 'react';
import { View, Button, StyleSheet, Alert } from 'react-native';
import { View, StyleSheet, Alert } from 'react-native';
import SafeAreaView from 'react-native-safe-area-view';
import { useDispatch, useSelector } from 'react-redux';
import { BarCodeScanner } from 'expo-barcode-scanner';
import jwtDecode from 'jwt-decode';
import { useNavigation } from '@react-navigation/native';
import { Text } from 'react-native-ui-lib';
import Icon from 'react-native-vector-icons/FontAwesome';
Expand Down Expand Up @@ -45,7 +44,7 @@ export default function ActivityFrame() {
return verified;
}

const handleBarCodeScanned = async ({ type, data }) => {
const handleBarCodeScanned = async ({ data }) => {
setScanned(true);
const verifier = data.split('|')[0];
const vc = data.split('|')[1];
Expand Down Expand Up @@ -74,21 +73,6 @@ export default function ActivityFrame() {

return (
<SafeAreaView style={styles.container}>
{/* {cred.length > 0 ? (
cred.map((credential) => (
<View>
<Button
title={`Send bevis ${credential.type} til tjeneste X`}
color="#f1940f"
onPress={() => sendPresentation([credential], verifier, userID)}
/>

<Text>Du har {status ? 'nå' : 'ikke'} delt beviset</Text>
</View>
))
) : (
<Text>Du har ingen bevis</Text>
)} */}
<View
style={{
display: 'flex',
Expand All @@ -99,7 +83,6 @@ export default function ActivityFrame() {
<Icon name="question-circle" size={25} color="rgb(30,46,60)" />
<Text text60 style={{ marginLeft: 10 }}>
Skann QR-kode til tjeneste

</Text>
</View>

Expand Down
4 changes: 1 addition & 3 deletions wallet/wallet-app/components/frames/Onboarding.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ export default function Onboarding() {
})();
}, []);

const handleBarCodeScanned = async ({ type, data }) => {
const handleBarCodeScanned = async ({ data }) => {
setLoading(true);
setScanned(true);
// alert(`Bar code with type ${type} and data ${data} has been scanned!`);

const baseId = jwtDecode(data);
const types = baseId.vc.type;

Expand Down
Loading