Search in sources :

Example 1 with BinaryStringEncoder

use of org.xwiki.crypto.BinaryStringEncoder in project xwiki-platform by xwiki.

the class X509KeyWikiStoreTest method setUp.

@Before
public void setUp() throws Exception {
    EntityReferenceProvider valueProvider = mock(EntityReferenceProvider.class);
    when(valueProvider.getDefaultReference(EntityType.WIKI)).thenReturn(WIKI_REFERENCE);
    when(valueProvider.getDefaultReference(EntityType.SPACE)).thenReturn(SPACE_REFERENCE);
    when(valueProvider.getDefaultReference(EntityType.DOCUMENT)).thenReturn(DOCUMENT_REFERENCE);
    mocker.registerComponent(EntityReferenceProvider.class, "current", valueProvider);
    Provider<XWikiContext> xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    xcontext = mock(XWikiContext.class);
    when(xcontextProvider.get()).thenReturn(xcontext);
    xwiki = mock(com.xpn.xwiki.XWiki.class);
    when(xcontext.getWiki()).thenReturn(xwiki);
    BinaryStringEncoder encoder = mocker.getInstance(BinaryStringEncoder.class, "Base64");
    when(encoder.encode(PRIVATEKEY, 64)).thenReturn(ENCODED_PRIVATEKEY);
    when(encoder.decode(ENCODED_PRIVATEKEY)).thenReturn(PRIVATEKEY);
    when(encoder.encode(ENCRYPTED_PRIVATEKEY, 64)).thenReturn(ENCODED_ENCRYPTED_PRIVATEKEY);
    when(encoder.decode(ENCODED_ENCRYPTED_PRIVATEKEY)).thenReturn(ENCRYPTED_PRIVATEKEY);
    when(encoder.encode(CERTIFICATE, 64)).thenReturn(ENCODED_CERTIFICATE);
    when(encoder.decode(ENCODED_CERTIFICATE)).thenReturn(CERTIFICATE);
    when(encoder.encode(SUBJECT_KEYID)).thenReturn(ENCODED_SUBJECTKEYID);
    when(encoder.decode(ENCODED_SUBJECTKEYID)).thenReturn(SUBJECT_KEYID);
    privateKey = mock(PrivateKeyParameters.class);
    when(privateKey.getEncoded()).thenReturn(PRIVATEKEY);
    AsymmetricKeyFactory keyFactory = mocker.getInstance(AsymmetricKeyFactory.class);
    when(keyFactory.fromPKCS8(PRIVATEKEY)).thenReturn(privateKey);
    PrivateKeyPasswordBasedEncryptor encryptor = mocker.getInstance(PrivateKeyPasswordBasedEncryptor.class);
    when(encryptor.encrypt(PASSWORD, privateKey)).thenReturn(ENCRYPTED_PRIVATEKEY);
    when(encryptor.decrypt(PASSWORD, ENCRYPTED_PRIVATEKEY)).thenReturn(privateKey);
    certificate = mock(X509CertifiedPublicKey.class);
    when(certificate.getSerialNumber()).thenReturn(SERIAL);
    when(certificate.getIssuer()).thenReturn(new DistinguishedName(ISSUER));
    when(certificate.getSubject()).thenReturn(new DistinguishedName(SUBJECT));
    when(certificate.getEncoded()).thenReturn(CERTIFICATE);
    CertificateFactory certificateFactory = mocker.getInstance(CertificateFactory.class, "X509");
    when(certificateFactory.decode(CERTIFICATE)).thenReturn(certificate);
    X509Extensions extensions = mock(X509Extensions.class);
    when(certificate.getExtensions()).thenReturn(extensions);
    when(extensions.getSubjectKeyIdentifier()).thenReturn(SUBJECT_KEYID);
    when(certificate.getSubjectKeyIdentifier()).thenReturn(SUBJECT_KEYID);
    keyPair = new CertifiedKeyPair(privateKey, certificate);
    QueryManager queryManager = mocker.getInstance(QueryManager.class);
    query = mock(Query.class);
    when(query.bindValue(any(String.class), any())).thenReturn(query);
    when(query.setWiki(WIKI)).thenReturn(query);
    when(queryManager.createQuery(any(String.class), any(String.class))).thenReturn(query);
    store = mocker.getComponentUnderTest();
}
Also used : BinaryStringEncoder(org.xwiki.crypto.BinaryStringEncoder) Query(org.xwiki.query.Query) DistinguishedName(org.xwiki.crypto.pkix.params.x509certificate.DistinguishedName) PrivateKeyParameters(org.xwiki.crypto.params.cipher.asymmetric.PrivateKeyParameters) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) X509Extensions(org.xwiki.crypto.pkix.params.x509certificate.extension.X509Extensions) CertificateFactory(org.xwiki.crypto.pkix.CertificateFactory) AsymmetricKeyFactory(org.xwiki.crypto.AsymmetricKeyFactory) EntityReferenceProvider(org.xwiki.model.reference.EntityReferenceProvider) X509CertifiedPublicKey(org.xwiki.crypto.pkix.params.x509certificate.X509CertifiedPublicKey) QueryManager(org.xwiki.query.QueryManager) PrivateKeyPasswordBasedEncryptor(org.xwiki.crypto.password.PrivateKeyPasswordBasedEncryptor) CertifiedKeyPair(org.xwiki.crypto.pkix.params.CertifiedKeyPair) Before(org.junit.Before)

Example 2 with BinaryStringEncoder

use of org.xwiki.crypto.BinaryStringEncoder in project xwiki-platform by xwiki.

the class DefaultSignatureStoreTest method setUp.

@Before
public void setUp() throws Exception {
    EntityReferenceProvider valueProvider = mock(EntityReferenceProvider.class);
    when(valueProvider.getDefaultReference(EntityType.WIKI)).thenReturn(WIKI_REFERENCE);
    when(valueProvider.getDefaultReference(EntityType.SPACE)).thenReturn(SPACE_REFERENCE);
    when(valueProvider.getDefaultReference(EntityType.DOCUMENT)).thenReturn(DOCUMENT_REFERENCE);
    this.mocker.registerComponent(EntityReferenceProvider.class, "current", valueProvider);
    Provider<XWikiContext> xcontextProvider = this.mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    this.xcontext = mock(XWikiContext.class);
    when(xcontextProvider.get()).thenReturn(this.xcontext);
    this.xwiki = mock(com.xpn.xwiki.XWiki.class);
    when(this.xcontext.getWiki()).thenReturn(this.xwiki);
    BinaryStringEncoder encoder = this.mocker.getInstance(BinaryStringEncoder.class, "Base64");
    when(encoder.encode(SIGNATURE, 64)).thenReturn(ENCODED_SIGNATURE);
    when(encoder.decode(ENCODED_SIGNATURE)).thenReturn(SIGNATURE);
    this.store = this.mocker.getComponentUnderTest();
}
Also used : BinaryStringEncoder(org.xwiki.crypto.BinaryStringEncoder) EntityReferenceProvider(org.xwiki.model.reference.EntityReferenceProvider) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) Before(org.junit.Before)

Example 3 with BinaryStringEncoder

use of org.xwiki.crypto.BinaryStringEncoder in project xwiki-platform by xwiki.

the class SignedMacroBlockReferenceResolverTest method setUp.

@Before
public void setUp() throws Exception {
    DigestFactory digestFactory = mocker.getInstance(DigestFactory.class, "SHA-1");
    BinaryStringEncoder encoder = mocker.getInstance(BinaryStringEncoder.class, "Base64");
    dumper = mocker.getInstance(BlockDumper.class, "macro");
    Digest digest = mock(Digest.class);
    stream = new ByteArrayOutputStream();
    when(digest.getOutputStream()).thenReturn(stream);
    when(digest.digest()).thenReturn(DIGEST_BLOCK);
    when(digestFactory.getInstance()).thenReturn(digest);
    when(encoder.encode(DIGEST_BLOCK)).thenReturn(ENCODED);
}
Also used : BinaryStringEncoder(org.xwiki.crypto.BinaryStringEncoder) DigestFactory(org.xwiki.crypto.DigestFactory) BlockDumper(org.xwiki.rendering.signature.internal.BlockDumper) Digest(org.xwiki.crypto.Digest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Before(org.junit.Before)

Example 4 with BinaryStringEncoder

use of org.xwiki.crypto.BinaryStringEncoder in project xwiki-platform by xwiki.

the class X509CertificateWikiStoreTest method mockMultiCertsQuery.

private CertifiedPublicKey[] mockMultiCertsQuery() throws Exception {
    CertifiedPublicKey[] certs = new CertifiedPublicKey[2];
    byte[] cert2 = "certificate2".getBytes();
    String encodedCert2 = "encoded_certificate2";
    certs[0] = getMockedCertificate(true);
    certs[1] = getMockedCertificate(false);
    CertificateFactory factory = this.mocker.getInstance(CertificateFactory.class, "X509");
    when(factory.decode(CERTIFICATE)).thenReturn(certs[0]);
    when(factory.decode(cert2)).thenReturn(certs[1]);
    BinaryStringEncoder encoder = this.mocker.getInstance(BinaryStringEncoder.class, "Base64");
    when(encoder.encode(cert2, 64)).thenReturn(encodedCert2);
    when(encoder.decode(encodedCert2)).thenReturn(cert2);
    when(this.query.<String>execute()).thenReturn(Arrays.asList(ENCODED_CERTIFICATE, encodedCert2));
    return certs;
}
Also used : BinaryStringEncoder(org.xwiki.crypto.BinaryStringEncoder) CertifiedPublicKey(org.xwiki.crypto.pkix.params.CertifiedPublicKey) X509CertifiedPublicKey(org.xwiki.crypto.pkix.params.x509certificate.X509CertifiedPublicKey) CertificateFactory(org.xwiki.crypto.pkix.CertificateFactory)

Example 5 with BinaryStringEncoder

use of org.xwiki.crypto.BinaryStringEncoder in project xwiki-platform by xwiki.

the class X509CertificateWikiStoreTest method setUp.

@Before
public void setUp() throws Exception {
    EntityReferenceProvider valueProvider = mock(EntityReferenceProvider.class);
    when(valueProvider.getDefaultReference(EntityType.WIKI)).thenReturn(WIKI_REFERENCE);
    when(valueProvider.getDefaultReference(EntityType.SPACE)).thenReturn(SPACE_REFERENCE);
    when(valueProvider.getDefaultReference(EntityType.DOCUMENT)).thenReturn(DOCUMENT_REFERENCE);
    mocker.registerComponent(EntityReferenceProvider.class, "current", valueProvider);
    Provider<XWikiContext> xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    xcontext = mock(XWikiContext.class);
    when(xcontextProvider.get()).thenReturn(xcontext);
    xwiki = mock(com.xpn.xwiki.XWiki.class);
    when(xcontext.getWiki()).thenReturn(xwiki);
    BinaryStringEncoder encoder = mocker.getInstance(BinaryStringEncoder.class, "Base64");
    when(encoder.encode(CERTIFICATE, 64)).thenReturn(ENCODED_CERTIFICATE);
    when(encoder.decode(ENCODED_CERTIFICATE)).thenReturn(CERTIFICATE);
    when(encoder.encode(SUBJECT_KEYID)).thenReturn(ENCODED_SUBJECTKEYID);
    when(encoder.decode(ENCODED_SUBJECTKEYID)).thenReturn(SUBJECT_KEYID);
    QueryManager queryManager = mocker.getInstance(QueryManager.class);
    query = mock(Query.class);
    when(query.bindValue(any(String.class), any())).thenReturn(query);
    when(query.setWiki(WIKI)).thenReturn(query);
    when(queryManager.createQuery(any(String.class), any(String.class))).thenReturn(query);
    store = mocker.getComponentUnderTest();
}
Also used : BinaryStringEncoder(org.xwiki.crypto.BinaryStringEncoder) EntityReferenceProvider(org.xwiki.model.reference.EntityReferenceProvider) AbstractX509StoreQuery(org.xwiki.crypto.store.wiki.internal.query.AbstractX509StoreQuery) Query(org.xwiki.query.Query) AbstractX509IssuerAndSerialQuery(org.xwiki.crypto.store.wiki.internal.query.AbstractX509IssuerAndSerialQuery) AbstractX509SubjectQuery(org.xwiki.crypto.store.wiki.internal.query.AbstractX509SubjectQuery) AbstractX509KeyIdentifierQuery(org.xwiki.crypto.store.wiki.internal.query.AbstractX509KeyIdentifierQuery) QueryManager(org.xwiki.query.QueryManager) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) Before(org.junit.Before)

Aggregations

BinaryStringEncoder (org.xwiki.crypto.BinaryStringEncoder)5 Before (org.junit.Before)4 XWiki (com.xpn.xwiki.XWiki)3 XWikiContext (com.xpn.xwiki.XWikiContext)3 EntityReferenceProvider (org.xwiki.model.reference.EntityReferenceProvider)3 CertificateFactory (org.xwiki.crypto.pkix.CertificateFactory)2 X509CertifiedPublicKey (org.xwiki.crypto.pkix.params.x509certificate.X509CertifiedPublicKey)2 Query (org.xwiki.query.Query)2 QueryManager (org.xwiki.query.QueryManager)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 AsymmetricKeyFactory (org.xwiki.crypto.AsymmetricKeyFactory)1 Digest (org.xwiki.crypto.Digest)1 DigestFactory (org.xwiki.crypto.DigestFactory)1 PrivateKeyParameters (org.xwiki.crypto.params.cipher.asymmetric.PrivateKeyParameters)1 PrivateKeyPasswordBasedEncryptor (org.xwiki.crypto.password.PrivateKeyPasswordBasedEncryptor)1 CertifiedKeyPair (org.xwiki.crypto.pkix.params.CertifiedKeyPair)1 CertifiedPublicKey (org.xwiki.crypto.pkix.params.CertifiedPublicKey)1 DistinguishedName (org.xwiki.crypto.pkix.params.x509certificate.DistinguishedName)1 X509Extensions (org.xwiki.crypto.pkix.params.x509certificate.extension.X509Extensions)1 AbstractX509IssuerAndSerialQuery (org.xwiki.crypto.store.wiki.internal.query.AbstractX509IssuerAndSerialQuery)1