Commit be916e97 authored by Patrik Dufresne's avatar Patrik Dufresne

Fix some validation.

parent d0abff7a
......@@ -25,9 +25,7 @@ import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.PublicKey;
import java.security.Security;
import java.security.Signature;
import java.security.SignatureException;
import java.security.spec.InvalidKeySpecException;
......@@ -169,10 +167,6 @@ public class EncryptionManager {
throw new UnsupportedOperationException("Can't sign when the private key is not available.");
}
for (Provider p : Security.getProviders()) {
System.out.println(p.getName());
}
// Initialize the signing algorithm with our private key
Signature rsaSignature = Signature.getInstance("SHA1withRSA");
rsaSignature.initSign(privateKey);
......
......@@ -70,6 +70,9 @@ public class LicenseManager {
// Validate each license file.
LicenseException lastException = null;
for (File f : files) {
if (!f.exists()) {
continue;
}
License license;
try {
license = licenseManager.readLicenseFile(f);
......@@ -171,8 +174,15 @@ public class LicenseManager {
* @throws ClassNotFoundException
* if the implementation of {@link License} stored in the file
* can't be found
* @throws LicenseException
*/
public License readLicenseFile(File file) throws IOException, InvalidKeyException, NoSuchAlgorithmException, SignatureException, ClassNotFoundException {
public License readLicenseFile(File file)
throws IOException,
InvalidKeyException,
NoSuchAlgorithmException,
SignatureException,
ClassNotFoundException,
LicenseException {
String base64Signature = null;
// Read the license file as a property file.
......@@ -189,7 +199,7 @@ public class LicenseManager {
}
// Check if the signature is available.
if (base64Signature == null) {
throw new SignatureException("No signature was found");
throw new LicenseException("No signature was found");
}
byte[] sig = Base64.decode(base64Signature.getBytes());
......@@ -198,7 +208,7 @@ public class LicenseManager {
// Validate the signature
if (!encryptionManager.verify(data, sig)) {
return null;
throw new LicenseException("invalid license signature");
}
return lic;
......
......@@ -88,6 +88,7 @@ public class LicenseManagerTest {
* @throws NoSuchAlgorithmException
* @throws InvalidKeyException
* @throws ClassNotFoundException
* @throws LicenseException
*/
@Test
public void readLicense_WithValidFile_ReadLicense()
......@@ -95,7 +96,8 @@ public class LicenseManagerTest {
NoSuchAlgorithmException,
SignatureException,
IOException,
ClassNotFoundException {
ClassNotFoundException,
LicenseException {
License license = new License();
File file = new File("unittest2.lic");
manager.writeLicense(license, file);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment