Remove spaces from dockerbuild script
[aaf/authz.git] / auth / auth-certman / src / test / java / org / onap / aaf / auth / cm / test / JU_SignTest.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21
22 package org.onap.aaf.auth.cm.test;
23
24 import java.io.File;
25 import java.math.BigInteger;
26 import java.security.KeyPair;
27 import java.security.PrivateKey;
28 import java.security.PublicKey;
29 import java.security.cert.Certificate;
30 import java.security.cert.X509Certificate;
31 import java.security.interfaces.RSAPrivateKey;
32 import java.security.interfaces.RSAPublicKey;
33 import java.util.Collection;
34
35 import org.junit.AfterClass;
36 import org.junit.Assert;
37 import org.junit.Test;
38 import static org.junit.Assert.fail;
39 import org.onap.aaf.auth.env.AuthzEnv;
40 import org.onap.aaf.auth.env.AuthzTrans;
41 import org.onap.aaf.cadi.cm.Factory;
42
43 public class JU_SignTest {
44
45         @AfterClass
46         public static void tearDownAfterClass() throws Exception {
47         }
48
49         @Test
50         public void test() throws Exception {
51                 AuthzEnv env = new AuthzEnv();
52                 AuthzTrans trans = env.newTrans();
53                 KeyPair kpair = Factory.generateKeyPair(trans);
54                 PrivateKey privateKey = kpair.getPrivate();
55                 String privateString = Factory.toString(trans, privateKey);
56                 System.out.println("Private as base64 encoded as PKCS8 Spec");
57                 System.out.println(privateString);
58                 
59                 PublicKey publicKey = kpair.getPublic();
60                 String publicString = Factory.toString(trans, publicKey); 
61                 System.out.println("public as base64 encoded as PKCS8 Spec");
62                 System.out.println(publicString);
63                 
64                 byte data[] = "Sign this please.".getBytes();
65                 byte sig[] = Factory.sign(trans, data, privateKey);
66                 System.out.println("Signature");
67                 System.out.println(Factory.toSignatureString(sig));
68                 
69                 Assert.assertTrue(Factory.verify(trans, data, sig, publicKey));
70         }
71         
72 //      @Test
73 //      public void test2() throws Exception {
74 //              AuthzEnv env = new AuthzEnv();
75 //              AuthzTrans trans = env.newTrans();
76 //              File key = new File("/opt/app/aaf/common/com.att.aaf.key");
77 //              PrivateKey privKey = Factory.toPrivateKey(trans, key);
78 //              RSAPrivateKey rPrivKey = (RSAPrivateKey)privKey;
79 //              BigInteger privMod, pubMod;
80 //              System.out.println((privMod = rPrivKey.getModulus()).toString(16));
81 //              
82 //              byte data[] = "Sign this please.".getBytes();
83 //              byte sig[] = Factory.sign(trans, data, privKey);
84 //              System.out.println("Signature");
85 //              System.out.println(Factory.toSignatureString(sig));
86 //
87 //              
88 //              File crt = new File("/opt/app/aaf/common/com.att.aaf.crt");
89 //              Collection<? extends Certificate> x509s = Factory.toX509Certificate(trans, crt);
90 //              X509Certificate cert = null;
91 //              for(Certificate c : x509s) {
92 //                      cert = (X509Certificate)c;
93 //                      break;
94 //              }
95 //              PublicKey pubKey = cert.getPublicKey();
96 //              RSAPublicKey rPubKey = (RSAPublicKey)pubKey;
97 //      
98 //              System.out.println((pubMod = rPubKey.getModulus()).toString(16));
99 //
100 //              Assert.assertTrue(Factory.verify(trans, data, sig, pubKey));
101 //              Assert.assertEquals(privMod,pubMod);
102 //              
103 //      }
104
105         @Test                                           //TODO: Temporary fix AAF-111
106         public void netYetTested() {
107                 fail("Tests not yet implemented");
108         }
109 }