| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.ksb.security.service.impl; |
| 17 | |
|
| 18 | |
import java.io.IOException; |
| 19 | |
import java.security.GeneralSecurityException; |
| 20 | |
import java.security.KeyException; |
| 21 | |
import java.security.PublicKey; |
| 22 | |
import java.security.Signature; |
| 23 | |
import java.security.cert.Certificate; |
| 24 | |
import java.security.cert.CertificateException; |
| 25 | |
|
| 26 | |
import org.kuali.rice.core.resourceloader.GlobalResourceLoader; |
| 27 | |
import org.kuali.rice.ksb.security.admin.service.JavaSecurityManagementService; |
| 28 | |
import org.kuali.rice.ksb.security.service.DigitalSignatureService; |
| 29 | |
import org.kuali.rice.ksb.util.KSBConstants; |
| 30 | |
|
| 31 | 0 | public class DigitalSignatureServiceImpl implements DigitalSignatureService { |
| 32 | |
|
| 33 | |
public Signature getSignatureForSigning() throws IOException, GeneralSecurityException { |
| 34 | 0 | Signature signature = getSignature(); |
| 35 | 0 | signature.initSign(getJavaSecurityManagementService().getModulePrivateKey()); |
| 36 | 0 | return signature; |
| 37 | |
} |
| 38 | |
|
| 39 | |
public Signature getSignatureForVerification(String verificationAlias) throws IOException, GeneralSecurityException { |
| 40 | 0 | Certificate cert = getJavaSecurityManagementService().getCertificate(verificationAlias); |
| 41 | 0 | return getSignatureForVerification(cert); |
| 42 | |
} |
| 43 | |
|
| 44 | |
public Signature getSignatureForVerification(Certificate certificate) throws IOException, GeneralSecurityException { |
| 45 | 0 | if (certificate == null) { |
| 46 | 0 | throw new CertificateException("Could not find certificate"); |
| 47 | |
} |
| 48 | 0 | PublicKey publicKey = certificate.getPublicKey(); |
| 49 | 0 | if (publicKey == null) { |
| 50 | 0 | throw new KeyException("Could not find the public key from valid certificate"); |
| 51 | |
} |
| 52 | 0 | Signature signature = getSignature(); |
| 53 | 0 | signature.initVerify(publicKey); |
| 54 | 0 | return signature; |
| 55 | |
} |
| 56 | |
|
| 57 | |
protected Signature getSignature() throws GeneralSecurityException { |
| 58 | 0 | return Signature.getInstance(getJavaSecurityManagementService().getModuleSignatureAlgorithm()); |
| 59 | |
} |
| 60 | |
|
| 61 | |
protected JavaSecurityManagementService getJavaSecurityManagementService() { |
| 62 | 0 | return (JavaSecurityManagementService)GlobalResourceLoader.getService(KSBConstants.ServiceNames.JAVA_SECURITY_MANAGEMENT_SERVICE); |
| 63 | |
} |
| 64 | |
|
| 65 | |
|
| 66 | |
} |