1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.crypto.signer.internal.factory; |
21 |
|
|
22 |
|
import org.xwiki.crypto.AsymmetricKeyFactory; |
23 |
|
import org.xwiki.crypto.BinaryStringEncoder; |
24 |
|
import org.xwiki.crypto.params.cipher.asymmetric.PrivateKeyParameters; |
25 |
|
import org.xwiki.crypto.params.cipher.asymmetric.PublicKeyParameters; |
26 |
|
import org.xwiki.crypto.signer.Signer; |
27 |
|
import org.xwiki.crypto.signer.SignerFactory; |
28 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
29 |
|
|
30 |
|
import static org.hamcrest.CoreMatchers.equalTo; |
31 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
32 |
|
import static org.junit.Assert.assertTrue; |
33 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
34 |
|
public abstract class AbstractRsaSignerFactoryTest |
35 |
|
{ |
36 |
|
private static final String PRIVATE_KEY = |
37 |
|
|
38 |
|
"MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDCmjim/3likJ4" |
39 |
|
+ "VF564UyygqPjIX/z090AImLl0fDLUkIyCVTSd18wJ3axr1qjLtSgNPWet0puSxO" |
40 |
|
+ "FH0AzFKRCJOjUkQRU8iAkz64MLAf9xrx4nBECciqeB941s01kLtG8C/UqC3O9Sw" |
41 |
|
+ "HSdhtUpUU8V/91SiD09yNJsnODi3WqM3oLg1QYzKhoaD2mVo2xJLQ/QXqr2XIc5" |
42 |
|
+ "i2Mlpfq6S5JNbFD/I+UFhBUlBNuDOEV7ttIt2eFMEUsfkCestGo0YoQYOpTLPcP" |
43 |
|
+ "GRS7MnSY1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Kar2kvaUswdPTC7pZoBso" |
58 |
|
+ "GB9+M6crXxdNwQKBgDUVMlGbYi1CTaYfonQyM+8IE7WnhXiatZ+ywKtH3MZmHOw" |
59 |
|
+ "wtzIigdfZC3cvvX7i4S73vztvjdtxSaODvmiobEukOF9sj8m+YQa7Pa1lWFML5x" |
60 |
|
+ "IIu2BhGS2ZCeXgMvKkoH0x9tWaUhGqD5zZmtiDrPs75CUQBypw7SDaBzwLnld9A" |
61 |
|
+ "oGBAPgUh90PvUzbVVkzpVCPI82cmOIVMI1rDE6uCeNzIlN6Xu80RimCSaaDsESi" |
62 |
|
+ "tBtoVWLRWWmuCINyqr6e9AdyvbvT6mQCjbn9+y7t6ZAhLaya5ZMUVEBLyLLqMzr" |
63 |
|
+ "y oi/huj7m4nV4kPZz9LKxDRu3r6o0Pah+daDsTxEYObtsKa7e"; |
64 |
|
|
65 |
|
private static final String PUBLIC_KEY = |
66 |
|
|
67 |
|
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwpo4pv95YpCeFReeuFM" |
68 |
|
+ "soKj4yF/89PdACJi5dHwy1JCMglU0ndfMCd2sa9aoy7UoDT1nrdKbksThR9AMxS" |
69 |
|
+ "kQiTo1JEEVPIgJM+uDCwH/ca8eJwRAnIqngfeNbNNZC7RvAv1KgtzvUsB0nYbVK" |
70 |
|
+ "VFPFf/dUog9PcjSbJzg4t1qjN6C4NUGMyoaGg9plaNsSS0P0F6q9lyHOYtjJaX6" |
71 |
|
+ "ukuSTWxQ/yPlBYQVJQTbgzhFe7bSLdnhTBFLH5AnrLRqNGKEGDqUyz3DxkUuzJ0" |
72 |
|
+ "mNQi1hlGKmjEp3rNJ0vJHtjzw+ENLLgGc+JrJ4Tbn2p7HLLTPLXDbbGReoY9Cb2" |
73 |
|
+ "2aJPPbMwIDAQAB"; |
74 |
|
|
75 |
|
private static final String TEXT = "Congress shall make no law respecting an establishment of religion, or " |
76 |
|
+ "prohibiting the free exercise thereof; or abridging the freedom of speech, " |
77 |
|
+ "or of the press; or the right of the people peaceably to assemble, and to " |
78 |
|
+ "petition the Government for a redress of grievances."; |
79 |
|
|
80 |
|
protected static PrivateKeyParameters privateKey; |
81 |
|
protected static PublicKeyParameters publicKey; |
82 |
|
protected static byte[] text; |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
84 |
26 |
public void setupTest(MockitoComponentMockingRule<SignerFactory> mocker) throws Exception... |
85 |
|
{ |
86 |
|
|
87 |
26 |
if (privateKey == null) { |
88 |
1 |
BinaryStringEncoder base64encoder = mocker.getInstance(BinaryStringEncoder.class, "Base64"); |
89 |
1 |
AsymmetricKeyFactory keyFactory = mocker.getInstance(AsymmetricKeyFactory.class, "RSA"); |
90 |
1 |
privateKey = keyFactory.fromPKCS8(base64encoder.decode(PRIVATE_KEY)); |
91 |
1 |
publicKey = keyFactory.fromX509(base64encoder.decode(PUBLIC_KEY)); |
92 |
1 |
text = TEXT.getBytes("UTF-8"); |
93 |
|
} |
94 |
|
} |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
96 |
23 |
protected void runTestSignatureVerification(Signer signer, Signer verifier) throws Exception... |
97 |
|
{ |
98 |
23 |
byte[] signature = signer.generate(text); |
99 |
|
|
100 |
23 |
assertThat(signer.getEncoded(), equalTo(verifier.getEncoded())); |
101 |
23 |
assertTrue(verifier.verify(signature, text)); |
102 |
|
} |
103 |
|
} |