Search in sources :

Example 1 with CertifiedPublicKey

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

the class X509KeyWikiStoreTest method retrieveEncryptedPrivateKeyFromDocument.

@Test
public void retrieveEncryptedPrivateKeyFromDocument() 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_ENCRYPTED_PRIVATEKEY);
    CertifiedKeyPair keyPair = store.retrieve(DOC_STORE_REF, PASSWORD);
    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)

Example 2 with CertifiedPublicKey

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

the class X509KeyWikiStoreTest method retrieveEncryptedPrivateKeyFromSpace.

@Test
public void retrieveEncryptedPrivateKeyFromSpace() throws Exception {
    XWikiDocument storeDoc = mock(XWikiDocument.class);
    when(xwiki.getDocument(new DocumentReference(WIKI, SPACE, ENCODED_SUBJECTKEYID), xcontext)).thenReturn(storeDoc);
    BaseObject pkObj = mock(BaseObject.class);
    when(storeDoc.getXObject(X509KeyWikiStore.PRIVATEKEYCLASS)).thenReturn(pkObj);
    when(pkObj.getLargeStringValue(X509KeyWikiStore.PRIVATEKEYCLASS_PROP_KEY)).thenReturn(ENCODED_ENCRYPTED_PRIVATEKEY);
    when(query.<Object[]>execute()).thenReturn(Collections.singletonList(new Object[] { "space." + ENCODED_SUBJECTKEYID, 0 }));
    CertifiedKeyPair keyPair = store.retrieve(SPACE_STORE_REF, certificate, PASSWORD);
    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) BaseObject(com.xpn.xwiki.objects.BaseObject) 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)

Example 3 with CertifiedPublicKey

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

the class X509KeyWikiStoreTest method retrievePrivateKeyFromSpace.

@Test
public void retrievePrivateKeyFromSpace() throws Exception {
    XWikiDocument storeDoc = mock(XWikiDocument.class);
    when(xwiki.getDocument(new DocumentReference(WIKI, SPACE, ENCODED_SUBJECTKEYID), xcontext)).thenReturn(storeDoc);
    BaseObject pkObj = mock(BaseObject.class);
    when(storeDoc.getXObject(X509KeyWikiStore.PRIVATEKEYCLASS)).thenReturn(pkObj);
    when(pkObj.getLargeStringValue(X509KeyWikiStore.PRIVATEKEYCLASS_PROP_KEY)).thenReturn(ENCODED_PRIVATEKEY);
    when(query.<Object[]>execute()).thenReturn(Collections.singletonList(new Object[] { "space." + ENCODED_SUBJECTKEYID, 0 }));
    CertifiedKeyPair keyPair = store.retrieve(SPACE_STORE_REF, certificate);
    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) BaseObject(com.xpn.xwiki.objects.BaseObject) 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)

Example 4 with CertifiedPublicKey

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

the class X509CertificateWikiStoreTest method testRetrievingCertificateUsingKeyIdFromSpace.

@Test
public void testRetrievingCertificateUsingKeyIdFromSpace() throws Exception {
    CertifiedPublicKey certificate = mockSingleCertQuery();
    assertThat(this.store.getCertificateProvider(SPACE_STORE_REF).getCertificate(SUBJECT_KEYID), equalTo(certificate));
    verify(this.query).bindValue(BIND_KEYID, ENCODED_SUBJECTKEYID);
    verify(this.query, times(3)).bindValue(BIND_STORE, SPACE);
}
Also used : CertifiedPublicKey(org.xwiki.crypto.pkix.params.CertifiedPublicKey) X509CertifiedPublicKey(org.xwiki.crypto.pkix.params.x509certificate.X509CertifiedPublicKey) Test(org.junit.Test)

Example 5 with CertifiedPublicKey

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

the class X509CertificateWikiStoreTest method testRetrievingCertificateUsingKeyIdFromDocument.

@Test
public void testRetrievingCertificateUsingKeyIdFromDocument() throws Exception {
    CertifiedPublicKey certificate = mockSingleCertQuery();
    assertThat(this.store.getCertificateProvider(DOC_STORE_REF).getCertificate(SUBJECT_KEYID), equalTo(certificate));
    verify(this.query).bindValue(BIND_KEYID, ENCODED_SUBJECTKEYID);
    verify(this.query, times(3)).bindValue(BIND_STORE, FULLNAME);
}
Also used : CertifiedPublicKey(org.xwiki.crypto.pkix.params.CertifiedPublicKey) X509CertifiedPublicKey(org.xwiki.crypto.pkix.params.x509certificate.X509CertifiedPublicKey) 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