Clover Coverage Report - ksb-test 2.0.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
18   68   1   18
0   32   0.06   1
1     1  
1    
 
  DigitalSignatureTest       Line # 30 18 0% 1 19 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2006-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16   
17    package org.kuali.rice.ksb.messaging;
18   
19    import org.junit.Test;
20    import org.kuali.rice.core.api.config.property.Config;
21    import org.kuali.rice.core.api.config.property.ConfigContext;
22    import org.kuali.rice.ksb.test.KSBTestCase;
23   
24    import java.io.FileInputStream;
25    import java.security.KeyStore;
26    import java.security.PrivateKey;
27    import java.security.PublicKey;
28    import java.security.Signature;
29   
 
30    public class DigitalSignatureTest extends KSBTestCase {
31   
32   
33    /**
34    * This method tests the existing rice keystore file
35    *
36    * @throws Exception
37    */
 
38  0 toggle @Test public void testSigning() throws Exception {
39   
40  0 Config config = ConfigContext.getCurrentContextConfig();
41    // config.parseConfig();
42    //
43  0 Signature rsa = Signature.getInstance("SHA1withRSA");
44  0 String keystoreLocation = config.getKeystoreFile();
45  0 String keystoreAlias = config.getKeystoreAlias();
46  0 String keystorePassword = config.getKeystorePassword();
47  0 KeyStore keystore = KeyStore.getInstance("JKS");
48  0 keystore.load(new FileInputStream(keystoreLocation), keystorePassword.toCharArray());
49  0 PrivateKey privateKey = (PrivateKey)keystore.getKey(keystoreAlias, keystorePassword.toCharArray());
50   
51  0 rsa.initSign(privateKey);
52   
53  0 String imLovinIt = "Ba-da-ba-ba-baa, I'm lovin' it!";
54  0 rsa.update(imLovinIt.getBytes());
55   
56  0 byte[] sigToVerify = rsa.sign();
57   
58   
59  0 PublicKey publicKey = keystore.getCertificate(keystoreAlias).getPublicKey();
60  0 Signature verifySig = Signature.getInstance("SHA1withRSA");
61  0 verifySig.initVerify(publicKey);
62  0 verifySig.update(imLovinIt.getBytes());
63  0 boolean verifies = verifySig.verify(sigToVerify);
64  0 System.out.println("signature verifies: " + verifies);
65   
66    }
67   
68    }