From eb344e69a5613e27b1a2907f2bcab0f8367a6bde Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 29 Sep 2014 18:15:09 +0200 Subject: Moved classes for asymmetric encryption to master-sync-shared --- .../imagemaster/util/AsymMessageVerifier.java | 66 ---------------------- .../org/openslx/imagemaster/util/ByteArray.java | 13 ----- 2 files changed, 79 deletions(-) delete mode 100644 src/main/java/org/openslx/imagemaster/util/AsymMessageVerifier.java delete mode 100644 src/main/java/org/openslx/imagemaster/util/ByteArray.java diff --git a/src/main/java/org/openslx/imagemaster/util/AsymMessageVerifier.java b/src/main/java/org/openslx/imagemaster/util/AsymMessageVerifier.java deleted file mode 100644 index e7e6be4..0000000 --- a/src/main/java/org/openslx/imagemaster/util/AsymMessageVerifier.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.openslx.imagemaster.util; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.security.InvalidKeyException; -import java.security.KeyFactory; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.PublicKey; -import java.security.Signature; -import java.security.SignatureException; -import java.security.UnrecoverableKeyException; -import java.security.cert.CertificateException; -import java.security.spec.X509EncodedKeySpec; - -import org.openslx.imagemaster.db.DbSatellite; - -public class AsymMessageVerifier -{ - - private PublicKey key; - - /** - * Load the key - * @param organization the organization to verify - * @throws Exception - * @throws NoSuchAlgorithmException - * @throws CertificateException - * @throws FileNotFoundException - * @throws IOException - * @throws KeyStoreException - * @throws UnrecoverableKeyException - */ - public AsymMessageVerifier(String organization) throws Exception - { - byte[] b = DbSatellite.getKeyfromOrganization( organization ); - - if (b == null) throw new Exception("Organization not found."); - - KeyFactory kf = KeyFactory.getInstance( "RSA" ); - X509EncodedKeySpec keySpec = new X509EncodedKeySpec(b); - key = kf.generatePublic(keySpec); - } - - /** - * Verify an encrypted message. - * - * @param messageDigest The signed message from hs/uni server - * @param expectedCleartext The message that was sent before - * @return Whether the message could be verfied or not - * @throws NoSuchAlgorithmException - * @throws InvalidKeyException - * @throws SignatureException - * @throws UnrecoverableKeyException - * @throws KeyStoreException - */ - public boolean verifyMessage( byte[] messageDigest, byte[] expectedCleartext ) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException, UnrecoverableKeyException, KeyStoreException - { - // verify message - Signature signature = Signature.getInstance( "SHA256WITHRSA" ); - signature.initVerify( key ); - signature.update( expectedCleartext ); - return signature.verify( messageDigest ); - } - -} diff --git a/src/main/java/org/openslx/imagemaster/util/ByteArray.java b/src/main/java/org/openslx/imagemaster/util/ByteArray.java deleted file mode 100644 index 71244a9..0000000 --- a/src/main/java/org/openslx/imagemaster/util/ByteArray.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.openslx.imagemaster.util; - - -public class ByteArray -{ - - public final byte[] array; - - public ByteArray(byte[] array) - { - this.array = array; - } -} \ No newline at end of file -- cgit v1.2.3-55-g7522