forked from apache/camel-k
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import camelk.DeterministicDecryption; | ||
import org.apache.camel.builder.RouteBuilder; | ||
|
||
public class FoobarDecryption extends RouteBuilder { | ||
|
||
private static final byte[] FOOBAR_ENCRYPTED = new byte[]{1, 104, -61, 45, -19, 59, 76, 38, 35, 97, 56, 49, -79, 79, 74, -79, -2, -42, -89, 76, -111, -3, -27, -102, 43, -94, 50}; | ||
|
||
@Override | ||
public void configure() throws Exception { | ||
from("timer:tick") | ||
.setBody(constant(FOOBAR_ENCRYPTED)) | ||
.bean(DeterministicDecryption.class, "decrypt(${body})") | ||
.log("${body}"); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.apache.camel.k.external</groupId> | ||
<artifactId>sample-decryption</artifactId> | ||
<version>1.0</version> | ||
|
||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.crypto.tink</groupId> | ||
<artifactId>tink</artifactId> | ||
<version>1.6.1</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
32 changes: 32 additions & 0 deletions
32
e2e/registry/files/src/main/java/camelk/DeterministicDecryption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package camelk; | ||
|
||
import java.io.IOException; | ||
import java.security.GeneralSecurityException; | ||
import com.google.crypto.tink.CleartextKeysetHandle; | ||
import com.google.crypto.tink.DeterministicAead; | ||
import com.google.crypto.tink.JsonKeysetReader; | ||
import com.google.crypto.tink.KeysetHandle; | ||
import com.google.crypto.tink.aead.AeadConfig; | ||
import com.google.crypto.tink.config.TinkConfig; | ||
|
||
public class DeterministicDecryption { | ||
|
||
private static final String KEYSET = "{\"primaryKeyId\":1757621741,\"key\":[{\"keyData\":{\"typeUrl\":\"type.googleapis.com/google.crypto.tink.AesSivKey\",\"value\":\"EkC4wjyYD7TPwkpxWFwkCrMmkOkpS2wdEwAchBW9INoJvmZHxBysCT0y6tfcW0RXeVWqMYqpuHfV/Np387MQcvme\",\"keyMaterialType\":\"SYMMETRIC\"},\"status\":\"ENABLED\",\"keyId\":1757621741,\"outputPrefixType\":\"TINK\"}]}"; | ||
|
||
|
||
public static String decrypt(byte[] encrypted) throws GeneralSecurityException, IOException { | ||
AeadConfig.register(); | ||
TinkConfig.register(); | ||
|
||
KeysetHandle keysetHandle = CleartextKeysetHandle.read( | ||
JsonKeysetReader.withString(KEYSET)); | ||
|
||
// Get the primitive. | ||
DeterministicAead daead = | ||
keysetHandle.getPrimitive(DeterministicAead.class); | ||
|
||
// deterministically decrypt a ciphertext. | ||
return new String(daead.decryptDeterministically(encrypted, null)); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//go:build integration | ||
// +build integration | ||
|
||
// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration" | ||
|
||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package service_binding | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
"github.com/stretchr/testify/assert" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
|
||
. "github.com/apache/camel-k/e2e/support" | ||
v1 "github.com/apache/camel-k/pkg/apis/camel/v1" | ||
) | ||
|
||
func TestImageRegistryIsAMavenRepository(t *testing.T) { | ||
WithNewTestNamespace(t, func(ns string) { | ||
Expect(Kamel("install", "-n", ns).Execute()).To(Succeed()) | ||
|
||
// Create integration that should decrypt foobar and log it | ||
name := "foobar-decryption" | ||
jar, err := filepath.Abs("files/sample-decryption-1.0.jar") | ||
assert.Nil(t, err) | ||
pom, err := filepath.Abs("files/sample-decryption-1.0.pom") | ||
assert.Nil(t, err) | ||
|
||
Expect(Kamel("run", "files/FoobarDecryption.java", | ||
"--name", name, | ||
"-d", fmt.Sprintf("file://%s", jar), | ||
"-d", fmt.Sprintf("file://%s", pom), | ||
"-n", ns, | ||
).Execute()).To(Succeed()) | ||
|
||
Eventually(IntegrationPodPhase(ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) | ||
Eventually(IntegrationCondition(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) | ||
Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("foobar")) | ||
|
||
// Clean up | ||
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) | ||
}) | ||
} |