Search in sources :

Example 11 with CertifiedPublicKey

use of org.xwiki.crypto.pkix.params.CertifiedPublicKey in project xwiki-platform by xwiki.

the class X509CertificateWikiStoreTest method mockSingleCertQuery.

private CertifiedPublicKey mockSingleCertQuery() throws Exception {
    CertifiedPublicKey certificate = getMockedCertificate(true);
    CertificateFactory factory = mocker.getInstance(CertificateFactory.class, "X509");
    when(factory.decode(CERTIFICATE)).thenReturn(certificate);
    when(query.<String>execute()).thenReturn(Collections.singletonList(ENCODED_CERTIFICATE));
    return certificate;
}
Also used : CertifiedPublicKey(org.xwiki.crypto.pkix.params.CertifiedPublicKey) X509CertifiedPublicKey(org.xwiki.crypto.pkix.params.x509certificate.X509CertifiedPublicKey) CertificateFactory(org.xwiki.crypto.pkix.CertificateFactory)

Example 12 with CertifiedPublicKey

use of org.xwiki.crypto.pkix.params.CertifiedPublicKey in project xwiki-platform by xwiki.

the class X509KeyWikiStoreTest method retrievePrivateKeyFromDocument.

@Test
public void retrievePrivateKeyFromDocument() throws Exception {
    XWikiDocument storeDoc = mock(XWikiDocument.class);
    when(xwiki.getDocument(new DocumentReference(WIKI, SPACE, DOCUMENT), xcontext)).thenReturn(storeDoc);
    BaseObject certObj = mock(BaseObject.class);
    when(storeDoc.getXObject(X509CertificateWikiStore.CERTIFICATECLASS)).thenReturn(certObj);
    when(certObj.getLargeStringValue(X509CertificateWikiStore.CERTIFICATECLASS_PROP_CERTIFICATE)).thenReturn(ENCODED_CERTIFICATE);
    BaseObject pkObj = mock(BaseObject.class);
    when(storeDoc.getXObject(X509KeyWikiStore.PRIVATEKEYCLASS)).thenReturn(pkObj);
    when(pkObj.getLargeStringValue(X509KeyWikiStore.PRIVATEKEYCLASS_PROP_KEY)).thenReturn(ENCODED_PRIVATEKEY);
    CertifiedKeyPair keyPair = store.retrieve(DOC_STORE_REF);
    assertThat(keyPair, notNullValue());
    assertThat(keyPair.getPrivateKey(), equalTo(privateKey));
    assertThat(keyPair.getCertificate(), equalTo((CertifiedPublicKey) certificate));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) CertifiedPublicKey(org.xwiki.crypto.pkix.params.CertifiedPublicKey) X509CertifiedPublicKey(org.xwiki.crypto.pkix.params.x509certificate.X509CertifiedPublicKey) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) CertifiedKeyPair(org.xwiki.crypto.pkix.params.CertifiedKeyPair) Test(org.junit.Test)

Aggregations

CertifiedPublicKey (org.xwiki.crypto.pkix.params.CertifiedPublicKey)12 X509CertifiedPublicKey (org.xwiki.crypto.pkix.params.x509certificate.X509CertifiedPublicKey)12 Test (org.junit.Test)8 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)4 BaseObject (com.xpn.xwiki.objects.BaseObject)4 CertifiedKeyPair (org.xwiki.crypto.pkix.params.CertifiedKeyPair)4 DocumentReference (org.xwiki.model.reference.DocumentReference)4 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)4 CertificateFactory (org.xwiki.crypto.pkix.CertificateFactory)2 DistinguishedName (org.xwiki.crypto.pkix.params.x509certificate.DistinguishedName)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 BinaryStringEncoder (org.xwiki.crypto.BinaryStringEncoder)1 CMSSignedDataGeneratorParameters (org.xwiki.crypto.signer.param.CMSSignedDataGeneratorParameters)1 CMSSignerInfo (org.xwiki.crypto.signer.param.CMSSignerInfo)1