blob: 29d53d29cf8df099614165ffe0140ebaa99b4f86 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
package pl.edu.mimuw.cloudatlas.agent;
import org.junit.Test;
import pl.edu.mimuw.cloudatlas.querysigner.KeyUtils;
import pl.edu.mimuw.cloudatlas.querysigner.QueryData;
import pl.edu.mimuw.cloudatlas.querysigner.QuerySigner;
import pl.edu.mimuw.cloudatlas.querysigner.QuerySignerApiImplementation;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
public class QuerySignerApiImplementationTest {
@Test
public void testQueryInstallVerification() {
QuerySignerApiImplementation queryApi;
try {
String publicKeyFile = "build/tmp/query_signer.pub";
String privateKeyFile = "build/tmp/query_signer";
PublicKey publicKey = KeyUtils.getPublicKey(publicKeyFile);
PrivateKey privateKey = KeyUtils.getPrivateKey(privateKeyFile);
queryApi = new QuerySignerApiImplementation(publicKey, privateKey);
QueryData signedQuery = queryApi.signInstallQuery("&a", "SELECT 1 AS ONE");
QuerySignerApiImplementation.validateInstallQuery("&a", signedQuery, publicKey);
} catch (IOException | NoSuchPaddingException | NoSuchAlgorithmException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException | QuerySigner.InvalidQueryException e) {
e.printStackTrace();
}
}
@Test
public void testQueryUninstallVerification() {
QuerySignerApiImplementation queryApi;
try {
String publicKeyFile = "build/tmp/query_signer.pub";
String privateKeyFile = "build/tmp/query_signer";
PublicKey publicKey = KeyUtils.getPublicKey(publicKeyFile);
PrivateKey privateKey = KeyUtils.getPrivateKey(privateKeyFile);
queryApi = new QuerySignerApiImplementation(publicKey, privateKey);
QueryData signedQuery = queryApi.signUninstallQuery("&a");
QuerySignerApiImplementation.validateUninstallQuery("&a", signedQuery, publicKey);
} catch (IOException | NoSuchPaddingException | NoSuchAlgorithmException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException | QuerySigner.InvalidQueryException e) {
e.printStackTrace();
}
}
}
|